From e8c93bbe9ad47c3cbbba6bda669a528b0b6b7ded Mon Sep 17 00:00:00 2001 From: Keith Date: Wed, 5 Jun 2019 15:42:14 +0800 Subject: [PATCH] refactor(neuron-ui): clean todo in neuron-ui remove unnecessary todo, and add some exception handlers. --- .../neuron-ui/src/components/Receive/index.tsx | 1 - .../neuron-ui/src/components/Transaction/index.tsx | 1 - .../src/components/WalletEditor/index.tsx | 14 +++++++++++--- .../src/components/WalletWizard/index.tsx | 6 ++++-- .../MainContent/actionCreators/networks.ts | 1 - .../neuron-ui/src/containers/Providers/hooks.ts | 8 +++----- packages/neuron-ui/src/locales/en.json | 3 ++- packages/neuron-ui/src/locales/zh.json | 3 ++- packages/neuron-ui/src/utils/validators.ts | 4 ++-- 9 files changed, 24 insertions(+), 17 deletions(-) diff --git a/packages/neuron-ui/src/components/Receive/index.tsx b/packages/neuron-ui/src/components/Receive/index.tsx index 119721c5ef..4930dd058e 100644 --- a/packages/neuron-ui/src/components/Receive/index.tsx +++ b/packages/neuron-ui/src/components/Receive/index.tsx @@ -42,7 +42,6 @@ const Receive = (props: React.PropsWithoutRef{t('receive.address-not-found')} } diff --git a/packages/neuron-ui/src/components/Transaction/index.tsx b/packages/neuron-ui/src/components/Transaction/index.tsx index ba2b8f0d67..2cc62e7d10 100644 --- a/packages/neuron-ui/src/components/Transaction/index.tsx +++ b/packages/neuron-ui/src/components/Transaction/index.tsx @@ -17,7 +17,6 @@ const Transaction = (props: React.PropsWithoutRef { - // TODO: verify hash dispatch(actionCreators.getTransaction(match.params.hash)) return () => { providerDispatch({ diff --git a/packages/neuron-ui/src/components/WalletEditor/index.tsx b/packages/neuron-ui/src/components/WalletEditor/index.tsx index 5a12702f55..ed909c1592 100644 --- a/packages/neuron-ui/src/components/WalletEditor/index.tsx +++ b/packages/neuron-ui/src/components/WalletEditor/index.tsx @@ -3,9 +3,10 @@ import { actionCreators } from 'containers/MainContent/reducer' import React, { useCallback, useEffect, useMemo } from 'react' import { Button, Card, Form } from 'react-bootstrap' import { useTranslation } from 'react-i18next' -import { RouteComponentProps } from 'react-router-dom' +import { RouteComponentProps, Link } from 'react-router-dom' import { useNeuronWallet } from 'utils/hooks' import InlineInput, { InputProps } from 'widgets/InlineInput' +import { Routes } from 'utils/const' import { useAreParamsValid, useInputs, useToggleDialog, useWalletEditor } from './hooks' export default ({ @@ -22,8 +23,15 @@ export default ({ const wallet = useMemo(() => wallets.find(w => w.id === id), [id, wallets]) if (!wallet) { - // TODO: Better error handling - throw new Error('Wallet not found') + const label = `${t('siderbar.settings')}-${t('settings.setting-tabs.wallets')}` + return ( +
+

{t('messages.wallet-is-not-found')}

+ + {label} + +
+ ) } const editor = useWalletEditor() diff --git a/packages/neuron-ui/src/components/WalletWizard/index.tsx b/packages/neuron-ui/src/components/WalletWizard/index.tsx index f8bfbd1b07..f8902ff941 100644 --- a/packages/neuron-ui/src/components/WalletWizard/index.tsx +++ b/packages/neuron-ui/src/components/WalletWizard/index.tsx @@ -83,8 +83,10 @@ const Mnemonic = ({ payload: res, }) }) - // TODO: Better Error Handle - .catch(err => console.error(err)) + .catch(err => { + console.error(err) + history.goBack() + }) } else { dispatch({ type: 'imported', diff --git a/packages/neuron-ui/src/containers/MainContent/actionCreators/networks.ts b/packages/neuron-ui/src/containers/MainContent/actionCreators/networks.ts index d3cda52dd0..38b0fb5304 100644 --- a/packages/neuron-ui/src/containers/MainContent/actionCreators/networks.ts +++ b/packages/neuron-ui/src/containers/MainContent/actionCreators/networks.ts @@ -90,7 +90,6 @@ export default { } }, setNetwork: (id: string) => { - // TODO: verification networksCall.activate(id) return { type: MainActions.Networks, diff --git a/packages/neuron-ui/src/containers/Providers/hooks.ts b/packages/neuron-ui/src/containers/Providers/hooks.ts index 79f46b3555..acd6863a6d 100644 --- a/packages/neuron-ui/src/containers/Providers/hooks.ts +++ b/packages/neuron-ui/src/containers/Providers/hooks.ts @@ -31,8 +31,10 @@ export const useChannelListeners = (i18n: any, chain: any, dispatch: React.Dispa }) } } else { - // TODO: better prompt + /* eslint-disable no-alert */ + // TODO: better prompt, prd required window.alert(i18n.t('messages.failed-to-initiate,-please-reopen-Neuron')) + /* eslint-enable no-alert */ window.close() } }, @@ -49,8 +51,6 @@ export const useChannelListeners = (i18n: any, chain: any, dispatch: React.Dispa break } } - } else { - // TODO: handle error } }) @@ -75,8 +75,6 @@ export const useChannelListeners = (i18n: any, chain: any, dispatch: React.Dispa break } } - } else { - // TODO: handle error } }) diff --git a/packages/neuron-ui/src/locales/en.json b/packages/neuron-ui/src/locales/en.json index 74713ca8e8..757fd32971 100644 --- a/packages/neuron-ui/src/locales/en.json +++ b/packages/neuron-ui/src/locales/en.json @@ -124,7 +124,8 @@ "wallet-imported-successfully": "{{name}} imported successfully", "wallet-created-successfully": "{{name}} created successfully", "wallet-updated-successfully": "{{name}} updated successfully", - "protocol-is-required": "Protocol is required" + "protocol-is-required": "Protocol is required", + "wallet-is-not-found": "Wallet is not found" } } } diff --git a/packages/neuron-ui/src/locales/zh.json b/packages/neuron-ui/src/locales/zh.json index 6a0ba7ef3b..c39119694d 100644 --- a/packages/neuron-ui/src/locales/zh.json +++ b/packages/neuron-ui/src/locales/zh.json @@ -117,7 +117,8 @@ "wallet-imported-successfully": "{{name}} 导入成功", "wallet-created-successfully": "{{name}} 创建成功", "wallet-updated-successfully": "{{name}} 更新成功", - "protocol-is-required": "请指定 URL 协议" + "protocol-is-required": "请指定 URL 协议", + "wallet-is-not-found": "未找到钱包" } } } diff --git a/packages/neuron-ui/src/utils/validators.ts b/packages/neuron-ui/src/utils/validators.ts index baefa5903b..1404cc0ae6 100644 --- a/packages/neuron-ui/src/utils/validators.ts +++ b/packages/neuron-ui/src/utils/validators.ts @@ -1,8 +1,8 @@ import { ADDRESS_LENGTH, MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH } from './const' export const verifyAddress = (address: string): boolean => { - // TODO: verify address - return address.replace(/^0x/, '').length === ADDRESS_LENGTH + // TODO: verify address, prd required + return address.length === ADDRESS_LENGTH } export const verifyWalletSubmission = ({ password,