diff --git a/packages/neuron-ui/src/components/WalletWizard/index.tsx b/packages/neuron-ui/src/components/WalletWizard/index.tsx index a71ccdefab..ca6e7e533d 100644 --- a/packages/neuron-ui/src/components/WalletWizard/index.tsx +++ b/packages/neuron-ui/src/components/WalletWizard/index.tsx @@ -8,6 +8,7 @@ import withWizard, { WizardElementProps, WithWizardState } from 'components/with import { MnemonicAction, BUTTON_GAP } from 'utils/const' import { verifyWalletSubmission } from 'utils/validators' import { helpersCall, walletsCall } from 'services/UILayer' +import { validateMnemonic, showErrorMessage } from 'services/remote' import { registerIcons, buttonGrommetIconStyles } from 'utils/icons' export enum WalletWizardPath { @@ -138,13 +139,18 @@ const Mnemonic = ({ if (isCreate) { history.push(`${rootPath}${WalletWizardPath.Mnemonic}/${MnemonicAction.Verify}`) } else { - history.push( - `${rootPath}${WalletWizardPath.Submission}/${ - type === MnemonicAction.Verify ? MnemonicAction.Create : MnemonicAction.Import - }` - ) + const isMnemonicValid = validateMnemonic(imported) + if (isMnemonicValid) { + history.push( + `${rootPath}${WalletWizardPath.Submission}/${ + type === MnemonicAction.Verify ? MnemonicAction.Create : MnemonicAction.Import + }` + ) + } else { + showErrorMessage(t('messages.error'), t('messages.invalid-mnemonic')) + } } - }, [isCreate, history, rootPath, type]) + }, [isCreate, history, rootPath, type, imported, t]) return ( diff --git a/packages/neuron-ui/src/locales/en.json b/packages/neuron-ui/src/locales/en.json index a0cc4358ed..770fc178f7 100644 --- a/packages/neuron-ui/src/locales/en.json +++ b/packages/neuron-ui/src/locales/en.json @@ -205,7 +205,9 @@ "wallet-created-successfully": "{{name}} created successfully", "wallet-updated-successfully": "{{name}} updated successfully", "wallet-not-found": "Wallet not found", - "no-transactions": "No transactions" + "no-transactions": "No transactions", + "error": "Error", + "invalid-mnemonic": "Invalid mnemonic words" }, "sync": { "syncing": "Syncing", diff --git a/packages/neuron-ui/src/locales/zh.json b/packages/neuron-ui/src/locales/zh.json index 17f09ca628..01a859392c 100644 --- a/packages/neuron-ui/src/locales/zh.json +++ b/packages/neuron-ui/src/locales/zh.json @@ -205,7 +205,9 @@ "wallet-created-successfully": "{{name}} 创建成功", "wallet-updated-successfully": "{{name}} 更新成功", "wallet-not-found": "未找到钱包", - "no-transactions": "没有交易" + "no-transactions": "没有交易", + "error": "错误", + "invalid-mnemonic": "助记词不合法" }, "sync": { "syncing": "同步中", diff --git a/packages/neuron-ui/src/services/remote.ts b/packages/neuron-ui/src/services/remote.ts new file mode 100644 index 0000000000..2e2dd2e9c4 --- /dev/null +++ b/packages/neuron-ui/src/services/remote.ts @@ -0,0 +1,32 @@ +export const validateMnemonic = (mnemonic: string): boolean => { + if (!window.remote) { + console.warn('remote is not supported') + return true + } + const { validateMnemonic: remoteValidateMnemonic } = window.remote.require('./models/keys/mnemonic') + return remoteValidateMnemonic(mnemonic) +} + +export const showMessage = (options: any, callback: Function) => { + if (!window.remote) { + console.warn('remote is not supported') + window.alert(options.message) + } else { + window.remote.require('electron').dialog.showMessageBox(options, callback) + } +} + +export const showErrorMessage = (title: string, content: string) => { + if (!window.remote) { + console.warn('remote is not supported') + window.alert(`${title}: ${content}`) + } else { + window.remote.require('electron').dialog.showErrorBox(title, content) + } +} + +export default { + validateMnemonic, + showMessage, + showErrorMessage, +} diff --git a/packages/neuron-ui/src/types/global/index.d.ts b/packages/neuron-ui/src/types/global/index.d.ts index fe2d5e238f..fb2cbeca70 100644 --- a/packages/neuron-ui/src/types/global/index.d.ts +++ b/packages/neuron-ui/src/types/global/index.d.ts @@ -1,6 +1,12 @@ declare interface Window { clipboard: any - remote: any + remote: { + getCurrentWebContents: Function + getCurrentWindow: Function + getGlobal: (name: string) => any + require: (module: string) => any + process?: any + } require: any bridge: any nativeImage: any diff --git a/packages/neuron-wallet/src/startup/preload.ts b/packages/neuron-wallet/src/startup/preload.ts index c4c3549ea4..7dd1a43602 100644 --- a/packages/neuron-wallet/src/startup/preload.ts +++ b/packages/neuron-wallet/src/startup/preload.ts @@ -1,10 +1,11 @@ -import { ipcRenderer, clipboard, nativeImage } from 'electron' +import { remote, ipcRenderer, clipboard, nativeImage } from 'electron' declare global { interface Window { bridge: any clipboard: Electron.Clipboard nativeImage: any + remote: Electron.Remote } } @@ -34,3 +35,4 @@ if (process.env.NODE_ENV === 'development') { window.clipboard = clipboard window.bridge = window.bridge || bridge window.nativeImage = nativeImage +window.remote = remote