From 29372db245748e4c27c78b4f4f3f87d439c951c3 Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 1 Aug 2019 16:07:57 +0800 Subject: [PATCH 01/14] feat(neuron-ui): add dynamic prmopt in wallet wizard --- .../src/components/WalletWizard/index.tsx | 36 +++++++++++-- packages/neuron-ui/src/locales/en.json | 5 +- packages/neuron-ui/src/locales/zh.json | 5 +- packages/neuron-ui/src/utils/loadTheme.tsx | 3 ++ packages/neuron-ui/src/utils/validators.ts | 52 ++++++++++++------- 5 files changed, 77 insertions(+), 24 deletions(-) diff --git a/packages/neuron-ui/src/components/WalletWizard/index.tsx b/packages/neuron-ui/src/components/WalletWizard/index.tsx index 865dbeb047..bbc71e8152 100644 --- a/packages/neuron-ui/src/components/WalletWizard/index.tsx +++ b/packages/neuron-ui/src/components/WalletWizard/index.tsx @@ -1,6 +1,16 @@ -import React, { useCallback, useEffect } from 'react' +import React, { useCallback, useEffect, useMemo } from 'react' import { useTranslation } from 'react-i18next' -import { Stack, Text, Label, Image, PrimaryButton, DefaultButton, TextField, FontSizes } from 'office-ui-fabric-react' +import { + Stack, + Icon, + Text, + Label, + Image, + PrimaryButton, + DefaultButton, + TextField, + FontSizes, +} from 'office-ui-fabric-react' import withWizard, { WizardElementProps, WithWizardState } from 'components/withWizard' import { generateMnemonic, validateMnemonic, showErrorMessage } from 'services/remote' @@ -8,7 +18,7 @@ import { createWalletWithMnemonic, importWalletWithMnemonic } from 'states/state import { Routes, MnemonicAction, BUTTON_GAP } from 'utils/const' import { buttonGrommetIconStyles } from 'utils/icons' -import { verifyWalletSubmission } from 'utils/validators' +import { verifyPasswordComplexity } from 'utils/validators' export enum WalletWizardPath { Welcome = '/welcome', @@ -243,7 +253,10 @@ const Submission = ({ } }, [type, name, password, imported, history, dispatch]) - const disableNext = !verifyWalletSubmission({ name, password, confirmPassword }) + const isNameUnused = useMemo(() => name && !wallets.find(w => w.name === name), [name, wallets]) + const isPwdComplex = useMemo(() => verifyPasswordComplexity(password) === true, [password]) + const isPwdSame = useMemo(() => password && password === confirmPassword, [password, confirmPassword]) + const disableNext = !(isNameUnused && isPwdComplex && isPwdSame) return ( @@ -261,6 +274,21 @@ const Submission = ({ ))} + + + {isNameUnused ? : } + {t('wizard.new-name')} + + + {isPwdComplex ? : } + {t('wizard.complex-password')} + + + {isPwdSame ? : } + {t('wizard.same-password')} + + + diff --git a/packages/neuron-ui/src/locales/en.json b/packages/neuron-ui/src/locales/en.json index 1bc9305d83..674cbfdd5d 100644 --- a/packages/neuron-ui/src/locales/en.json +++ b/packages/neuron-ui/src/locales/en.json @@ -47,7 +47,10 @@ "set-wallet-name": "Give your new wallet a name", "set-a-strong-password-to-protect-your-wallet": "Create a strong password to protect your wallet", "wallet-suffix": "Wallet {{suffix}}", - "write-down-seed": "Write down your wallet seed and save it in a safe place" + "write-down-seed": "Write down your wallet seed and save it in a safe place", + "new-name": "Use an unused name for the new wallet", + "complex-password": "The password is a string of 8 to 50 characters consisting of three types of characters: uppercase letters, lowercase letters, numbers, and special symbols, and must start with a letter or a number.", + "same-password": "Confirm the password" }, "detail": { "more-transactions": "More" diff --git a/packages/neuron-ui/src/locales/zh.json b/packages/neuron-ui/src/locales/zh.json index 6ddc2204e1..99ebf52282 100644 --- a/packages/neuron-ui/src/locales/zh.json +++ b/packages/neuron-ui/src/locales/zh.json @@ -47,7 +47,10 @@ "set-wallet-name": "为钱包设置名称", "set-a-strong-password-to-protect-your-wallet": "请设置一个强密码用于保护您的钱包", "wallet-suffix": "钱包 {{suffix}}", - "write-down-seed": "请记下您的助记词并保存到安全的地方" + "write-down-seed": "请记下您的助记词并保存到安全的地方", + "new-name": "输入新的钱包名称", + "complex-password": "密码为 8 至 50 位由大写字母、小写字母、数字、特殊符号中三类字符组成的字符串, 且必须以字母或者数字开头", + "same-password": "两次输入密码应一致" }, "detail": { "more-transactions": "更多交易记录" diff --git a/packages/neuron-ui/src/utils/loadTheme.tsx b/packages/neuron-ui/src/utils/loadTheme.tsx index e9f7b1e7eb..ff57ddb29d 100644 --- a/packages/neuron-ui/src/utils/loadTheme.tsx +++ b/packages/neuron-ui/src/utils/loadTheme.tsx @@ -22,6 +22,7 @@ import { Nodes as ConnectedIcon, Scan as ScanIcon, Search as SearchIcon, + StatusGood as MatchedIcon, SubtractCircle as RemoveIcon, Update as UpdateIcon, } from 'grommet-icons' @@ -73,6 +74,8 @@ registerIcons({ Disconnected: , Updating: , More: , + Matched: , + Unmatched: , }, }) diff --git a/packages/neuron-ui/src/utils/validators.ts b/packages/neuron-ui/src/utils/validators.ts index cce5985b4b..69e3c85fbd 100644 --- a/packages/neuron-ui/src/utils/validators.ts +++ b/packages/neuron-ui/src/utils/validators.ts @@ -4,30 +4,46 @@ export const verifyAddress = (address: string): boolean => { // TODO: verify address, prd required return address.length === ADDRESS_LENGTH } -export const verifyWalletSubmission = ({ - password, - confirmPassword, - name, -}: { - password: string - confirmPassword: string - name: string -}) => { - return ( - password && - name && - password === confirmPassword && - password.length >= MIN_PASSWORD_LENGTH && - password.length <= MAX_PASSWORD_LENGTH - ) -} export const verifyAmountRange = (amount: string) => { return +amount >= MIN_AMOUNT } +export const verifyPasswordComplexity = (password: string) => { + if (!password) { + return 'password-is-empty' + } + if (password.length < MIN_PASSWORD_LENGTH) { + return 'password-is-too-short' + } + if (password.length > MAX_PASSWORD_LENGTH) { + return 'password-is-too-long' + } + let complex = 0 + let reg = /\d/ + if (reg.test(password)) { + complex++ + } + reg = /[a-z]/ + if (reg.test(password)) { + complex++ + } + reg = /[A-Z]/ + if (reg.test(password)) { + complex++ + } + reg = /[^0-9a-zA-Z]/ + if (reg.test(password)) { + complex++ + } + if (complex < 3) { + return 'password-is-too-simple' + } + return true +} + export default { verifyAddress, - verifyWalletSubmission, verifyAmountRange, + verifyPasswordComplexity, } From e23d331399089202d165cae76c8cce47a9d51600 Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 1 Aug 2019 17:06:57 +0800 Subject: [PATCH 02/14] feat(neuron-ui): hide the top alert on removing the last error message from the notification panel --- packages/neuron-ui/src/states/stateProvider/reducer.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/neuron-ui/src/states/stateProvider/reducer.ts b/packages/neuron-ui/src/states/stateProvider/reducer.ts index 1547ce6a5c..ace3dc160c 100644 --- a/packages/neuron-ui/src/states/stateProvider/reducer.ts +++ b/packages/neuron-ui/src/states/stateProvider/reducer.ts @@ -424,6 +424,10 @@ export const reducer = ( }, notifications: app.notifications.filter(({ timestamp }) => timestamp !== payload), showAllNotifications: app.notifications.length > 1, + showTopAlert: + app.notifications.findIndex(message => message.timestamp === payload) === app.notifications.length - 1 + ? false + : app.showTopAlert, }, } } From 8fcf1841a76ddef80a2ddd80070325c04706f296 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 1 Aug 2019 18:24:12 +0900 Subject: [PATCH 03/14] feat: Configure dev-app-update.yml for electron-updater --- packages/neuron-wallet/dev-app-update.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/neuron-wallet/dev-app-update.yml b/packages/neuron-wallet/dev-app-update.yml index 6490e235d8..2c6316658a 100644 --- a/packages/neuron-wallet/dev-app-update.yml +++ b/packages/neuron-wallet/dev-app-update.yml @@ -1 +1,3 @@ -publish: github +provider: github +owner: nervosnetwork +repo: neuron From fa871362e7304dd91f9e783617edf77d7c227361 Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 1 Aug 2019 22:10:04 +0800 Subject: [PATCH 04/14] fix(neuron-wallet): fix the error comes with deleting all wallets Remove the obliteration of wallets.json --- packages/neuron-wallet/src/services/wallets.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/neuron-wallet/src/services/wallets.ts b/packages/neuron-wallet/src/services/wallets.ts index cae8cfd17d..9e05071c2a 100644 --- a/packages/neuron-wallet/src/services/wallets.ts +++ b/packages/neuron-wallet/src/services/wallets.ts @@ -245,8 +245,6 @@ export default class WalletService { if (currentID === id) { if (newWallets.length > 0) { this.setCurrent(newWallets[0].id) - } else { - this.listStore.clear() } } From cd638aa5c0aafe1bf42dfbd7add6fd7aa9d37a7d Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 2 Aug 2019 09:50:33 +0900 Subject: [PATCH 05/14] chore: Set publisher name explictly --- packages/neuron-wallet/electron-builder.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/neuron-wallet/electron-builder.yml b/packages/neuron-wallet/electron-builder.yml index 5996fd323b..13d28c51df 100644 --- a/packages/neuron-wallet/electron-builder.yml +++ b/packages/neuron-wallet/electron-builder.yml @@ -42,6 +42,8 @@ dmg: sign: false win: + publisherName: + - 杭州秘猿科技有限公司 artifactName: "${productName}-v${version}-${os}-${arch}-installer.${ext}" icon: assets/images/icon.ico target: From 994f8c903e20feeb6526963e047e5c6e0a25a535 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 2 Aug 2019 10:35:32 +0900 Subject: [PATCH 06/14] chore(deps): Bump sqlite3 to 4.0.9 --- packages/neuron-wallet/package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index 221e83b118..2493d4c9f3 100644 --- a/packages/neuron-wallet/package.json +++ b/packages/neuron-wallet/package.json @@ -46,7 +46,7 @@ "reflect-metadata": "0.1.13", "rxjs": "6.5.2", "sha3": "2.0.4", - "sqlite3": "4.0.8", + "sqlite3": "4.0.9", "typeorm": "0.2.18", "uuid": "3.3.2", "winston": "3.2.1" diff --git a/yarn.lock b/yarn.lock index 65f92c854c..a97ed3bb41 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15824,10 +15824,10 @@ sprintf-js@~1.0.2: resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw= -sqlite3@4.0.8: - version "4.0.8" - resolved "https://registry.yarnpkg.com/sqlite3/-/sqlite3-4.0.8.tgz#81ee60d54befaa52f5421fe6337050bd43d4bb95" - integrity sha512-kgwHu4j10KhpCHtx//dejd/tVQot7jc3sw+Sn0vMuKOw0X00Ckyg9VceKgzPyGmmz+zEoYue9tOLriWTvYy0ww== +sqlite3@4.0.9: + version "4.0.9" + resolved "https://registry.yarnpkg.com/sqlite3/-/sqlite3-4.0.9.tgz#cff74550fa5a1159956815400bdef69245557640" + integrity sha512-IkvzjmsWQl9BuBiM4xKpl5X8WCR4w0AeJHRdobCdXZ8dT/lNc1XS6WqvY35N6+YzIIgzSBeY5prdFObID9F9tA== dependencies: nan "^2.12.1" node-pre-gyp "^0.11.0" From bea4b20839a0a141e9abcd4bf6ad087e45c8466a Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 1 Aug 2019 16:31:48 +0800 Subject: [PATCH 07/14] feat(neuron-ui): navigate to the Overview view on wallet switching --- .../states/stateProvider/actionCreators/app.ts | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/packages/neuron-ui/src/states/stateProvider/actionCreators/app.ts b/packages/neuron-ui/src/states/stateProvider/actionCreators/app.ts index 681b15be3f..d0be8121d9 100644 --- a/packages/neuron-ui/src/states/stateProvider/actionCreators/app.ts +++ b/packages/neuron-ui/src/states/stateProvider/actionCreators/app.ts @@ -13,13 +13,6 @@ import { } from 'utils/localCache' export const initAppState = () => (dispatch: StateDispatch, history: any) => { - dispatch({ - type: AppActions.UpdateLoadings, - payload: { - addressList: true, - transactionList: true, - }, - }) getNeuronWalletState() .then(res => { if (res.status) { @@ -49,6 +42,8 @@ export const initAppState = () => (dispatch: StateDispatch, history: any) => { }) if (!wallet) { history.push(`${Routes.WalletWizard}${WalletWizardPath.Welcome}`) + } else { + history.push(Routes.Overview) } currentWalletCache.save(wallet) @@ -63,15 +58,6 @@ export const initAppState = () => (dispatch: StateDispatch, history: any) => { .catch(() => { history.push(`${Routes.WalletWizard}${WalletWizardPath.Welcome}`) }) - .finally(() => { - dispatch({ - type: AppActions.UpdateLoadings, - payload: { - addressList: false, - transactionList: false, - }, - }) - }) } export const addPopup = (text: string) => (dispatch: StateDispatch) => { From 5623f3bd4cd81efcc3337f7263ec53fdc0f76acb Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 1 Aug 2019 16:57:39 +0800 Subject: [PATCH 08/14] feat(neuron-ui): close the tx detail dialog on wallet switching --- packages/neuron-ui/src/components/Transaction/index.tsx | 7 +++++++ packages/neuron-ui/src/services/remote/app.ts | 5 +++++ packages/neuron-wallet/src/controllers/app/index.ts | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/packages/neuron-ui/src/components/Transaction/index.tsx b/packages/neuron-ui/src/components/Transaction/index.tsx index 1598899497..2758796a5f 100644 --- a/packages/neuron-ui/src/components/Transaction/index.tsx +++ b/packages/neuron-ui/src/components/Transaction/index.tsx @@ -3,6 +3,8 @@ import { RouteComponentProps } from 'react-router-dom' import { useTranslation } from 'react-i18next' import { Stack, DetailsList, Text, DetailsListLayoutMode, CheckboxVisibility, IColumn } from 'office-ui-fabric-react' +import { isMainWindow, getWinID } from 'services/remote' + import { AppActions, StateWithDispatch } from 'states/stateProvider/reducer' import { updateTransaction } from 'states/stateProvider/actionCreators' import chainState from 'states/initStates/chain' @@ -101,6 +103,11 @@ const Transaction = ({ dispatch, }: React.PropsWithoutRef>) => { const [t] = useTranslation() + useEffect(() => { + if ((walletID && !isMainWindow(getWinID())) || !walletID) { + window.close() + } + }, [walletID]) useEffect(() => { dispatch({ diff --git a/packages/neuron-ui/src/services/remote/app.ts b/packages/neuron-ui/src/services/remote/app.ts index d4b54a235f..315ae51784 100644 --- a/packages/neuron-ui/src/services/remote/app.ts +++ b/packages/neuron-ui/src/services/remote/app.ts @@ -16,9 +16,14 @@ export const showTransactionDetails = controllerMethodWrapper(CONTROLLER_NAME)(c controller.showTransactionDetails(hash) ) +export const isMainWindow = controllerMethodWrapper(CONTROLLER_NAME)(controller => (winID: number) => + controller.isMainWindow(winID) +) + export default { getNeuronWalletState, handleViewError, contextMenu, showTransactionDetails, + isMainWindow, } diff --git a/packages/neuron-wallet/src/controllers/app/index.ts b/packages/neuron-wallet/src/controllers/app/index.ts index 94da28687e..9bfbec16d7 100644 --- a/packages/neuron-wallet/src/controllers/app/index.ts +++ b/packages/neuron-wallet/src/controllers/app/index.ts @@ -94,6 +94,10 @@ export default class AppController { } } + public static isMainWindow = (winID: number) => { + return WindowManager.mainWindow && winID === WindowManager.mainWindow.id + } + public static showMessageBox( options: MessageBoxOptions, callback?: (response: number, checkboxChecked: boolean) => void From bd4c10903e64d43568cbdb71e9ca099643313728 Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 2 Aug 2019 10:12:56 +0800 Subject: [PATCH 09/14] feat(neuron-ui): handle current-wallet update and wallet-list update separately --- packages/neuron-ui/src/containers/Main/hooks.ts | 6 +++++- packages/neuron-ui/src/types/Subject/index.d.ts | 2 +- packages/neuron-wallet/src/main.ts | 4 ++-- packages/neuron-wallet/src/models/subjects/data-update.ts | 2 +- packages/neuron-wallet/src/models/window-manager.ts | 4 +++- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/neuron-ui/src/containers/Main/hooks.ts b/packages/neuron-ui/src/containers/Main/hooks.ts index 815bfaa7e4..b72e33bab4 100644 --- a/packages/neuron-ui/src/containers/Main/hooks.ts +++ b/packages/neuron-ui/src/containers/Main/hooks.ts @@ -154,7 +154,11 @@ export const useSubscription = ({ updateTransaction({ walletID, hash: txHash }) break } - case 'wallet': { + case 'current-wallet': { + updateCurrentWallet()(dispatch) + break + } + case 'wallets': { updateWalletList()(dispatch) updateCurrentWallet()(dispatch) break diff --git a/packages/neuron-ui/src/types/Subject/index.d.ts b/packages/neuron-ui/src/types/Subject/index.d.ts index 0e5d83bf29..f0c8e3f0fa 100644 --- a/packages/neuron-ui/src/types/Subject/index.d.ts +++ b/packages/neuron-ui/src/types/Subject/index.d.ts @@ -17,7 +17,7 @@ declare namespace Subject { } interface DataUpdateMetaInfo { walletID?: string - dataType: 'address' | 'transaction' | 'wallet' | 'network' + dataType: 'address' | 'transaction' | 'current-wallet' | 'wallets' | 'network' actionType: 'create' | 'update' | 'delete' } type NetworkList = State.Network[] diff --git a/packages/neuron-wallet/src/main.ts b/packages/neuron-wallet/src/main.ts index a91e495a1b..c84a8c6a79 100644 --- a/packages/neuron-wallet/src/main.ts +++ b/packages/neuron-wallet/src/main.ts @@ -40,14 +40,14 @@ app.on('ready', async () => { WalletListSubject.pipe(debounceTime(50)).subscribe(({ currentWallet = null, currentWalletList = [] }) => { const walletList = currentWalletList.map(({ id, name }) => ({ id, name })) const currentWalletId = currentWallet ? currentWallet.id : null - dataUpdateSubject.next({ dataType: 'wallet', actionType: 'update' }) + dataUpdateSubject.next({ dataType: 'wallets', actionType: 'update' }) updateApplicationMenu(walletList, currentWalletId) }) CurrentWalletSubject.pipe(debounceTime(50)).subscribe(async ({ currentWallet = null, walletList = [] }) => { updateApplicationMenu(walletList, currentWallet ? currentWallet.id : null) if (currentWallet) { - dataUpdateSubject.next({ dataType: 'wallet', actionType: 'update' }) + dataUpdateSubject.next({ dataType: 'current-wallet', actionType: 'update' }) } }) diff --git a/packages/neuron-wallet/src/models/subjects/data-update.ts b/packages/neuron-wallet/src/models/subjects/data-update.ts index 9c1fe34cbc..5dac3b27bc 100644 --- a/packages/neuron-wallet/src/models/subjects/data-update.ts +++ b/packages/neuron-wallet/src/models/subjects/data-update.ts @@ -2,7 +2,7 @@ import { Subject } from 'rxjs' import WindowManager from '../window-manager' export const DataUpdateSubject = new Subject<{ - dataType: 'address' | 'transaction' | 'wallet' | 'network' + dataType: 'address' | 'transaction' | 'wallets' | 'current-wallet' | 'network' actionType: 'create' | 'update' | 'delete' }>() diff --git a/packages/neuron-wallet/src/models/window-manager.ts b/packages/neuron-wallet/src/models/window-manager.ts index 61e9d8dda6..843bf91a5b 100644 --- a/packages/neuron-wallet/src/models/window-manager.ts +++ b/packages/neuron-wallet/src/models/window-manager.ts @@ -8,7 +8,9 @@ export default class WindowManager { } } - public static dataUpdated = (meta: { dataType: 'wallet' | 'address' | 'transaction' | 'network' }) => { + public static dataUpdated = (meta: { + dataType: 'current-wallet' | 'wallets' | 'address' | 'transaction' | 'network' + }) => { if (WindowManager.mainWindow) { WindowManager.mainWindow.webContents.send('data-updated', meta) } From 0a1c271414b23d753b54bf8d0eaf3fe08b0fd661 Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 2 Aug 2019 10:51:18 +0800 Subject: [PATCH 10/14] refactor(neuron-ui): update the i18n text of same-password --- packages/neuron-ui/src/locales/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/neuron-ui/src/locales/en.json b/packages/neuron-ui/src/locales/en.json index 674cbfdd5d..ce3a3f3502 100644 --- a/packages/neuron-ui/src/locales/en.json +++ b/packages/neuron-ui/src/locales/en.json @@ -50,7 +50,7 @@ "write-down-seed": "Write down your wallet seed and save it in a safe place", "new-name": "Use an unused name for the new wallet", "complex-password": "The password is a string of 8 to 50 characters consisting of three types of characters: uppercase letters, lowercase letters, numbers, and special symbols, and must start with a letter or a number.", - "same-password": "Confirm the password" + "same-password": "The password and confirm-password should be same" }, "detail": { "more-transactions": "More" From 6fd43225b6e9f72a4dda5f5084dbda0cf32684c3 Mon Sep 17 00:00:00 2001 From: Chen Yu Date: Fri, 2 Aug 2019 11:17:14 +0800 Subject: [PATCH 11/14] Update packages/neuron-ui/src/locales/en.json Co-Authored-By: CL --- packages/neuron-ui/src/locales/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/neuron-ui/src/locales/en.json b/packages/neuron-ui/src/locales/en.json index ce3a3f3502..23ffd82907 100644 --- a/packages/neuron-ui/src/locales/en.json +++ b/packages/neuron-ui/src/locales/en.json @@ -50,7 +50,7 @@ "write-down-seed": "Write down your wallet seed and save it in a safe place", "new-name": "Use an unused name for the new wallet", "complex-password": "The password is a string of 8 to 50 characters consisting of three types of characters: uppercase letters, lowercase letters, numbers, and special symbols, and must start with a letter or a number.", - "same-password": "The password and confirm-password should be same" + "same-password": "The password and confirm password should be same" }, "detail": { "more-transactions": "More" From 359536884fe0e893b17c92aa307b12a17dadbba0 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Fri, 2 Aug 2019 13:41:07 +0800 Subject: [PATCH 12/14] feat: using simple queue --- .../src/services/sync/block-listener.ts | 7 --- .../neuron-wallet/src/services/sync/queue.ts | 14 ++--- .../src/services/sync/simple-queue.ts | 60 +++++++++++++++++++ .../src/startup/sync-block-task/task.ts | 3 +- 4 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 packages/neuron-wallet/src/services/sync/simple-queue.ts diff --git a/packages/neuron-wallet/src/services/sync/block-listener.ts b/packages/neuron-wallet/src/services/sync/block-listener.ts index 32d322ffbb..9c83896aac 100644 --- a/packages/neuron-wallet/src/services/sync/block-listener.ts +++ b/packages/neuron-wallet/src/services/sync/block-listener.ts @@ -60,13 +60,6 @@ export default class BlockListener { await this.queue.kill() } - public drain = async () => { - if (this.queue) { - return this.queue.drain() - } - return undefined - } - public regenerate = async (): Promise => { if (this.queue && this.queue.length() > 0) { return diff --git a/packages/neuron-wallet/src/services/sync/queue.ts b/packages/neuron-wallet/src/services/sync/queue.ts index 6ac7072560..b1237d0c47 100644 --- a/packages/neuron-wallet/src/services/sync/queue.ts +++ b/packages/neuron-wallet/src/services/sync/queue.ts @@ -3,12 +3,11 @@ import { Block, BlockHeader } from '../../types/cell-types' import RangeForCheck from './range-for-check' import BlockNumber from './block-number' import Utils from './utils' -import QueueAdapter from './queue-adapter' +import SimpleQueue from './simple-queue' import { TransactionPersistor } from '../tx' export default class Queue { - private q: QueueAdapter - private concurrent: number = 1 + private q: SimpleQueue private lockHashes: string[] private getBlocksService: GetBlocks private startBlockNumber: bigint @@ -26,7 +25,7 @@ export default class Queue { currentBlockNumber: BlockNumber = new BlockNumber(), rangeForCheck: RangeForCheck = new RangeForCheck() ) { - this.q = new QueueAdapter(this.getWorker(), this.concurrent) + this.q = new SimpleQueue(this.getWorker()) this.lockHashes = lockHashes this.getBlocksService = new GetBlocks() this.startBlockNumber = BigInt(startBlockNumber) @@ -40,12 +39,11 @@ export default class Queue { } private getWorker = () => { - const worker = async (task: any, callback: any) => { + const worker = async (task: any) => { try { await Utils.retry(this.retryTime, 0, async () => { await this.pipeline(task.blockNumbers) }) - await callback() } catch { this.clear() } @@ -69,10 +67,6 @@ export default class Queue { this.q.kill() } - public drain = async () => { - return this.q.drain() - } - public pipeline = async (blockNumbers: string[]) => { // 1. get blocks const blocks: Block[] = await this.getBlocksService.getRangeBlocks(blockNumbers) diff --git a/packages/neuron-wallet/src/services/sync/simple-queue.ts b/packages/neuron-wallet/src/services/sync/simple-queue.ts new file mode 100644 index 0000000000..249ca4c145 --- /dev/null +++ b/packages/neuron-wallet/src/services/sync/simple-queue.ts @@ -0,0 +1,60 @@ +import Utils from './utils' + +export default class SimpleQueue { + private q: any[] = [] + private worker: any + private stopped = false + + constructor(worker: any, start: boolean = true) { + this.worker = worker + if (start) { + this.start() + } + } + + /* eslint no-await-in-loop: "off" */ + public start = async () => { + while (!this.stopped) { + const nextValue = this.shift() + if (nextValue) { + await this.worker(nextValue) + await this.yield() + } else { + await this.yield(50) + } + } + } + + private shift = () => { + return this.q.shift() + } + + public yield = async (millisecond: number = 1) => { + return Utils.sleep(millisecond) + } + + public push = (value: any) => { + this.q.push(value) + } + + public stop = () => { + this.stopped = true + + this.push = (value: any) => value + this.clear() + } + + public kill = () => { + this.stop() + } + + public clear = () => { + while (this.q.length) { + this.q.pop() + } + } + + public length = (): number => { + return this.q.length + } +} diff --git a/packages/neuron-wallet/src/startup/sync-block-task/task.ts b/packages/neuron-wallet/src/startup/sync-block-task/task.ts index a8353af5b3..5a23dd7323 100644 --- a/packages/neuron-wallet/src/startup/sync-block-task/task.ts +++ b/packages/neuron-wallet/src/startup/sync-block-task/task.ts @@ -7,6 +7,7 @@ import AddressesUsedSubject from '../../models/subjects/addresses-used-subject' import BlockListener from '../../services/sync/block-listener' import { NetworkWithID } from '../../services/networks' import { initDatabase } from './init-database' +import Utils from '../../services/sync/utils' import { register as registerTxStatusListener } from '../../listeners/tx-status' import { register as registerAddressListener } from '../../listeners/address' @@ -58,7 +59,7 @@ export const switchNetwork = async () => { const regenerateListener = async () => { await blockListener.stop() // wait former queue to be drained - await blockListener.drain() + await Utils.sleep(3000) const hashes: string[] = await loadAddressesAndConvert() blockListener = new BlockListener(hashes, nodeService.tipNumberSubject) await blockListener.start(true) From f31803980fb9a399d99251fa6dd13a1c3ff805f2 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Fri, 2 Aug 2019 13:43:13 +0800 Subject: [PATCH 13/14] chore: remove async --- packages/neuron-wallet/package.json | 2 -- .../src/services/sync/queue-adapter.ts | 35 ------------------- yarn.lock | 10 ------ 3 files changed, 47 deletions(-) delete mode 100644 packages/neuron-wallet/src/services/sync/queue-adapter.ts diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index 2493d4c9f3..2c5ccf515c 100644 --- a/packages/neuron-wallet/package.json +++ b/packages/neuron-wallet/package.json @@ -36,7 +36,6 @@ "dependencies": { "@nervosnetwork/ckb-sdk-core": "0.17.1", "@nervosnetwork/ckb-sdk-utils": "0.17.1", - "async": "3.0.1", "bn.js": "4.11.8", "chalk": "2.4.2", "electron-updater": "^4.1.2", @@ -53,7 +52,6 @@ }, "devDependencies": { "@nervosnetwork/ckb-types": "0.17.1", - "@types/async": "3.0.0", "@types/electron-devtools-installer": "2.2.0", "@types/elliptic": "6.4.8", "@types/sqlite3": "3.1.5", diff --git a/packages/neuron-wallet/src/services/sync/queue-adapter.ts b/packages/neuron-wallet/src/services/sync/queue-adapter.ts deleted file mode 100644 index 5ccbdbf0d9..0000000000 --- a/packages/neuron-wallet/src/services/sync/queue-adapter.ts +++ /dev/null @@ -1,35 +0,0 @@ -import async from 'async' - -export default class QueueAdapter { - private q: any - - constructor(worker: async.AsyncWorker, concurrency: number) { - this.q = async.queue(worker, concurrency) - } - - public push = (value: any) => { - this.innerPush(value) - } - - private innerPush = (value: any) => { - this.q.push(value) - } - - public kill = () => { - this.push = (value: any) => value - this.clear() - this.q.kill() - } - - public clear = () => { - this.q.remove(() => true) - } - - public length = (): number => { - return this.q.length() - } - - public drain = async () => { - return this.q.drain() - } -} diff --git a/yarn.lock b/yarn.lock index a97ed3bb41..f0e0b6f286 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2985,11 +2985,6 @@ dependencies: defer-to-connect "^1.0.1" -"@types/async@3.0.0": - version "3.0.0" - resolved "https://registry.yarnpkg.com/@types/async/-/async-3.0.0.tgz#d403560ee2aabccdb7936cb9a3fee5f147d626bd" - integrity sha512-DvEhEeG8ynipwkg7LtNHlO99+vEVbin+E+3YuzeJCM9TREewJ1B5fdZsQzykR7fKuh6rKh8mEir36zKd3uafOA== - "@types/babel__core@^7.1.0": version "7.1.2" resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.2.tgz#608c74f55928033fce18b99b213c16be4b3d114f" @@ -4271,11 +4266,6 @@ async-limiter@~1.0.0: resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8" integrity sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg== -async@3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/async/-/async-3.0.1.tgz#dfeb34657d1e63c94c0eee424297bf8a2c9a8182" - integrity sha512-ZswD8vwPtmBZzbn9xyi8XBQWXH3AvOQ43Za1KWYq7JeycrZuUYzx01KvHcVbXltjqH4y0MWrQ33008uLTqXuDw== - async@^1.5.2: version "1.5.2" resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a" From 88009ff32ce010b6ca74feca080b68cd680fd64b Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 2 Aug 2019 14:57:53 +0800 Subject: [PATCH 14/14] chore: Bump to v0.17.0-alpha.5 --- CHANGELOG.md | 35 +++++++++++++++++++++++++++++ lerna.json | 2 +- package.json | 2 +- packages/neuron-ui/package.json | 2 +- packages/neuron-wallet/package.json | 4 ++-- 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5548b17f7..5c350e2e3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,38 @@ +# [0.17.0-alpha.5](https://github.com/nervosnetwork/neuron/compare/v0.17.0-alpha.4...v0.17.0-alpha.5) (2019-08-02) + + +### Bug Fixes + +* **neuron-ui:** remove the quotation mark around error message ([5de8cba](https://github.com/nervosnetwork/neuron/commit/5de8cba)) +* **neuron-wallet:** fix the error comes with deleting all wallets ([fa87136](https://github.com/nervosnetwork/neuron/commit/fa87136)) + + +### Features + +* using simple queue ([3595368](https://github.com/nervosnetwork/neuron/commit/3595368)) +* **neuron-ui:** add basic style on the list header of transaction list ([3a7eeaf](https://github.com/nervosnetwork/neuron/commit/3a7eeaf)) +* **neuron-ui:** add check on current wallet id on leaving settings view ([b33a238](https://github.com/nervosnetwork/neuron/commit/b33a238)) +* **neuron-ui:** add CKB unit in the transaction fee field ([e6107e5](https://github.com/nervosnetwork/neuron/commit/e6107e5)) +* **neuron-ui:** add dynamic prmopt in wallet wizard ([29372db](https://github.com/nervosnetwork/neuron/commit/29372db)) +* **neuron-ui:** add notification panel ([f7984b0](https://github.com/nervosnetwork/neuron/commit/f7984b0)) +* **neuron-ui:** add popping messages on copying and updating ([cd7d7e5](https://github.com/nervosnetwork/neuron/commit/cd7d7e5)) +* **neuron-ui:** add the story of connection status component, and set the network name to 14px ([e940fdf](https://github.com/nervosnetwork/neuron/commit/e940fdf)) +* **neuron-ui:** append network ips to network names in networks setting ([427941b](https://github.com/nervosnetwork/neuron/commit/427941b)) +* **neuron-ui:** cache language configuration ([49e35c3](https://github.com/nervosnetwork/neuron/commit/49e35c3)) +* **neuron-ui:** calculate transaction fee with user-specified price ([9ce3174](https://github.com/nervosnetwork/neuron/commit/9ce3174)) +* **neuron-ui:** call generate mnemonic method from neuron-wallet in neuron-ui with remote module ([5a27c7b](https://github.com/nervosnetwork/neuron/commit/5a27c7b)) +* **neuron-ui:** call networks controller's methods by remote module ([c4bc431](https://github.com/nervosnetwork/neuron/commit/c4bc431)) +* **neuron-ui:** call transactions controller methods with remote module ([4751817](https://github.com/nervosnetwork/neuron/commit/4751817)) +* **neuron-ui:** close the tx detail dialog on wallet switching ([5623f3b](https://github.com/nervosnetwork/neuron/commit/5623f3b)) +* **neuron-ui:** display balance with thousandth delimiter ([07e4370](https://github.com/nervosnetwork/neuron/commit/07e4370)) +* **neuron-ui:** double click on tx item shows its details ([383db66](https://github.com/nervosnetwork/neuron/commit/383db66)) +* **neuron-ui:** handle current-wallet update and wallet-list update separately ([bd4c109](https://github.com/nervosnetwork/neuron/commit/bd4c109)) +* **neuron-ui:** navigate to the Overview view on wallet switching ([bea4b20](https://github.com/nervosnetwork/neuron/commit/bea4b20)) +* Configure dev-app-update.yml for electron-updater ([8fcf184](https://github.com/nervosnetwork/neuron/commit/8fcf184)) +* **neuron-ui:** hide the top alert on removing the last error message from the notification panel ([e23d331](https://github.com/nervosnetwork/neuron/commit/e23d331)) + + + # [0.17.0-alpha.4](https://github.com/nervosnetwork/neuron/compare/v0.17.0-alpha.3...v0.17.0-alpha.4) (2019-08-01) diff --git a/lerna.json b/lerna.json index 15d5e40eef..fb40695639 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "packages": [ "packages/*" ], - "version": "0.17.0-alpha.4", + "version": "0.17.0-alpha.5", "npmClient": "yarn", "useWorkspaces": true } diff --git a/package.json b/package.json index e467ae81ae..baa7bb5c41 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "neuron", "productName": "Neuron", "description": "CKB Neuron Wallet", - "version": "0.17.0-alpha.4", + "version": "0.17.0-alpha.5", "private": true, "author": { "name": "Nervos Core Dev", diff --git a/packages/neuron-ui/package.json b/packages/neuron-ui/package.json index bf664f0c0c..de8a385a0c 100644 --- a/packages/neuron-ui/package.json +++ b/packages/neuron-ui/package.json @@ -1,6 +1,6 @@ { "name": "neuron-ui", - "version": "0.17.0-alpha.4", + "version": "0.17.0-alpha.5", "private": true, "author": { "name": "Nervos Core Dev", diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index 2c5ccf515c..0b6a7e014c 100644 --- a/packages/neuron-wallet/package.json +++ b/packages/neuron-wallet/package.json @@ -3,7 +3,7 @@ "productName": "Neuron", "description": "CKB Neuron Wallet", "homepage": "https://www.nervos.org/", - "version": "0.17.0-alpha.4", + "version": "0.17.0-alpha.5", "private": true, "author": { "name": "Nervos Core Dev", @@ -62,7 +62,7 @@ "electron-devtools-installer": "2.2.4", "electron-notarize": "0.1.1", "lint-staged": "9.2.0", - "neuron-ui": "0.17.0-alpha.4", + "neuron-ui": "0.17.0-alpha.5", "rimraf": "2.6.3", "spectron": "7.0.0" }