From 383db66481fe807f2482001d8a1e710b60bd22b7 Mon Sep 17 00:00:00 2001 From: Keith Date: Wed, 31 Jul 2019 10:17:59 +0800 Subject: [PATCH 01/14] feat(neuron-ui): double click on tx item shows its details --- packages/neuron-ui/src/components/TransactionList/index.tsx | 5 ++++- packages/neuron-ui/src/services/remote/app.ts | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/neuron-ui/src/components/TransactionList/index.tsx b/packages/neuron-ui/src/components/TransactionList/index.tsx index 3b757f5be6..12cf93e6a6 100644 --- a/packages/neuron-ui/src/components/TransactionList/index.tsx +++ b/packages/neuron-ui/src/components/TransactionList/index.tsx @@ -13,7 +13,7 @@ import { } from 'office-ui-fabric-react' import { StateDispatch } from 'states/stateProvider/reducer' -import { contextMenu } from 'services/remote' +import { contextMenu, showTransactionDetails } from 'services/remote' import { useLocalDescription } from 'utils/hooks' import { shannonToCKBFormatter, uniformTimeFormatter as timeFormatter, uniformTimeFormatter } from 'utils/formatters' @@ -203,6 +203,9 @@ const TransactionList = ({ onRenderHeader, }} checkboxVisibility={CheckboxVisibility.hidden} + onItemInvoked={item => { + showTransactionDetails(item.hash) + }} onItemContextMenu={item => { if (item) { contextMenu({ type: 'transactionList', id: item.hash }) diff --git a/packages/neuron-ui/src/services/remote/app.ts b/packages/neuron-ui/src/services/remote/app.ts index c3443322d9..d4b54a235f 100644 --- a/packages/neuron-ui/src/services/remote/app.ts +++ b/packages/neuron-ui/src/services/remote/app.ts @@ -12,8 +12,13 @@ export const contextMenu = controllerMethodWrapper(CONTROLLER_NAME)( controller => (params: { type: string; id: string }) => controller.contextMenu(params) ) +export const showTransactionDetails = controllerMethodWrapper(CONTROLLER_NAME)(controller => (hash: string) => + controller.showTransactionDetails(hash) +) + export default { getNeuronWalletState, handleViewError, contextMenu, + showTransactionDetails, } From 670165953cb5dfe194613eb47012c0d3cf2c3c11 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 31 Jul 2019 11:27:48 +0900 Subject: [PATCH 02/14] feat: Only bundle en and zh_CN language folders for mac --- packages/neuron-wallet/electron-builder.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/neuron-wallet/electron-builder.yml b/packages/neuron-wallet/electron-builder.yml index c25ae00356..c1f2baeb75 100644 --- a/packages/neuron-wallet/electron-builder.yml +++ b/packages/neuron-wallet/electron-builder.yml @@ -58,6 +58,7 @@ mac: gatekeeperAssess: false entitlements: assets/entitlements.plist entitlementsInherit: assets/entitlements.plist + electronLanguages: ["en", "zh", "zh_CN"] target: - dmg - zip From 0540057068a3770fdfb3f5b54597644cb42e0d72 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 31 Jul 2019 11:29:54 +0900 Subject: [PATCH 03/14] fix: Translation for installing update prompt message --- packages/neuron-wallet/src/locales/en.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/neuron-wallet/src/locales/en.ts b/packages/neuron-wallet/src/locales/en.ts index 4eec5bf42f..2ecbd3e306 100644 --- a/packages/neuron-wallet/src/locales/en.ts +++ b/packages/neuron-wallet/src/locales/en.ts @@ -138,8 +138,7 @@ export default { 'update-not-available': 'There are currently no updates available.', 'updates-found-do-you-want-to-update': 'An update is available, do you want to update now?', 'update-now': 'Update now', - 'updates-downloaded-about-to-quit-and-install': - 'Update downloaded. Neuron will quit and install the the update...', + 'updates-downloaded-about-to-quit-and-install': 'Update downloaded. Neuron will quit and install the update...', }, common: { yes: 'Yes', From 2afc7e7166e75bdd0edafb5422ec6b90a65607f9 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Wed, 31 Jul 2019 12:29:43 +0800 Subject: [PATCH 04/14] fix: connection not found when delete wallet --- .../src/database/chain/ormconfig.ts | 2 ++ .../neuron-wallet/src/listeners/tx-status.ts | 11 +++++++- .../src/services/tx/transaction-service.ts | 26 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/neuron-wallet/src/database/chain/ormconfig.ts b/packages/neuron-wallet/src/database/chain/ormconfig.ts index 8c1f67a3d8..3fa8910f78 100644 --- a/packages/neuron-wallet/src/database/chain/ormconfig.ts +++ b/packages/neuron-wallet/src/database/chain/ormconfig.ts @@ -13,6 +13,8 @@ import env from '../../env' import { InitMigration1561695143591 } from './migrations/1561695143591-InitMigration' import { AddStatusToTx1562038960990 } from './migrations/1562038960990-AddStatusToTx' +export const CONNECTION_NOT_FOUND_NAME = 'ConnectionNotFoundError' + const dbPath = (networkName: string): string => { const name = `cell-${networkName}.sqlite` return path.join(env.fileBasePath, 'cells', name) diff --git a/packages/neuron-wallet/src/listeners/tx-status.ts b/packages/neuron-wallet/src/listeners/tx-status.ts index 99e9b25ba6..864866b506 100644 --- a/packages/neuron-wallet/src/listeners/tx-status.ts +++ b/packages/neuron-wallet/src/listeners/tx-status.ts @@ -1,9 +1,11 @@ import { remote } from 'electron' import { interval } from 'rxjs' +import { getConnection } from 'typeorm' import { TransactionStatus } from '../types/cell-types' import LockUtils from '../models/lock-utils' import AddressesUsedSubject from '../models/subjects/addresses-used-subject' import { FailedTransaction } from '../services/tx' +import { CONNECTION_NOT_FOUND_NAME } from '../database/chain/ormconfig' const { nodeService } = remote.require('./startup/sync-block-task/params') @@ -47,7 +49,14 @@ const trackingStatus = async () => { export const register = () => { // every 5 seconds interval(5000).subscribe(async () => { - await trackingStatus() + try { + getConnection() + await trackingStatus() + } catch (err) { + if (err.name !== CONNECTION_NOT_FOUND_NAME) { + throw err + } + } }) } diff --git a/packages/neuron-wallet/src/services/tx/transaction-service.ts b/packages/neuron-wallet/src/services/tx/transaction-service.ts index 5ae994eed9..c47df5d2eb 100644 --- a/packages/neuron-wallet/src/services/tx/transaction-service.ts +++ b/packages/neuron-wallet/src/services/tx/transaction-service.ts @@ -3,6 +3,7 @@ import { pubkeyToAddress } from '@nervosnetwork/ckb-sdk-utils' import { Transaction, TransactionWithoutHash, TransactionStatus } from '../../types/cell-types' import TransactionEntity from '../../database/chain/entities/transaction' import LockUtils from '../../models/lock-utils' +import { CONNECTION_NOT_FOUND_NAME } from '../../database/chain/ormconfig' export interface TransactionsByAddressesParam { pageNo: number @@ -122,6 +123,20 @@ export class TransactionsService { params: TransactionsByLockHashesParam, searchValue: string = '' ): Promise> => { + try { + // if connection not found, may means no database to connection + // it will happend when first connection to database and no network. + getConnection() + } catch (err) { + if (err.name === CONNECTION_NOT_FOUND_NAME) { + return { + totalCount: 0, + items: [], + } + } + throw err + } + const skip = (params.pageNo - 1) * params.pageSize const type = TransactionsService.filterSearchType(searchValue) @@ -224,6 +239,17 @@ export class TransactionsService { } public static get = async (hash: string): Promise => { + try { + // if connection not found, may means no database to connection + // it will happend when first connection to database and no network. + getConnection() + } catch (err) { + if (err.name === CONNECTION_NOT_FOUND_NAME) { + return undefined + } + throw err + } + const tx = await getConnection() .getRepository(TransactionEntity) .findOne(hash, { relations: ['inputs', 'outputs'] }) From e00bbc642723db44c6fa84a5300cfb5b2c67c1a5 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Wed, 31 Jul 2019 12:48:49 +0800 Subject: [PATCH 05/14] chore: update comment --- .../neuron-wallet/src/services/tx/transaction-service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/neuron-wallet/src/services/tx/transaction-service.ts b/packages/neuron-wallet/src/services/tx/transaction-service.ts index c47df5d2eb..b7245aee78 100644 --- a/packages/neuron-wallet/src/services/tx/transaction-service.ts +++ b/packages/neuron-wallet/src/services/tx/transaction-service.ts @@ -124,8 +124,8 @@ export class TransactionsService { searchValue: string = '' ): Promise> => { try { - // if connection not found, may means no database to connection - // it will happend when first connection to database and no network. + // if connection not found, may means no database to connect + // it happened when no node connected and no previous database found. getConnection() } catch (err) { if (err.name === CONNECTION_NOT_FOUND_NAME) { @@ -240,8 +240,8 @@ export class TransactionsService { public static get = async (hash: string): Promise => { try { - // if connection not found, may means no database to connection - // it will happend when first connection to database and no network. + // if connection not found, may means no database to connect + // it happened when no node connected and no previous database found. getConnection() } catch (err) { if (err.name === CONNECTION_NOT_FOUND_NAME) { From 18e6afe4e8ee32b1021054d51891e30dee85d91d Mon Sep 17 00:00:00 2001 From: classicalliu Date: Wed, 31 Jul 2019 13:45:54 +0800 Subject: [PATCH 06/14] chore: update comment may means => which means --- packages/neuron-wallet/src/services/tx/transaction-service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/neuron-wallet/src/services/tx/transaction-service.ts b/packages/neuron-wallet/src/services/tx/transaction-service.ts index b7245aee78..b8a9c70a66 100644 --- a/packages/neuron-wallet/src/services/tx/transaction-service.ts +++ b/packages/neuron-wallet/src/services/tx/transaction-service.ts @@ -124,7 +124,7 @@ export class TransactionsService { searchValue: string = '' ): Promise> => { try { - // if connection not found, may means no database to connect + // if connection not found, which means no database to connect // it happened when no node connected and no previous database found. getConnection() } catch (err) { From e940fdf8a8a2c1a5898bcba8100d14848adf29b1 Mon Sep 17 00:00:00 2001 From: Keith Date: Wed, 31 Jul 2019 14:33:52 +0800 Subject: [PATCH 07/14] feat(neuron-ui): add the story of connection status component, and set the network name to 14px --- .../neuron-ui/src/containers/Footer/index.tsx | 11 ++- packages/neuron-ui/src/index.tsx | 71 +----------------- .../src/stories/NetworkStatus.stories.tsx | 31 ++++++++ packages/neuron-ui/src/stories/index.tsx | 7 +- packages/neuron-ui/src/utils/loadTheme.tsx | 75 +++++++++++++++++++ 5 files changed, 122 insertions(+), 73 deletions(-) create mode 100644 packages/neuron-ui/src/stories/NetworkStatus.stories.tsx create mode 100644 packages/neuron-ui/src/utils/loadTheme.tsx diff --git a/packages/neuron-ui/src/containers/Footer/index.tsx b/packages/neuron-ui/src/containers/Footer/index.tsx index 7380ae5b54..eba38d1329 100644 --- a/packages/neuron-ui/src/containers/Footer/index.tsx +++ b/packages/neuron-ui/src/containers/Footer/index.tsx @@ -57,7 +57,16 @@ export const NetworkStatus = ({ name, online }: { name: string; online: boolean iconName={online ? 'Connected' : 'Disconnected'} styles={{ root: { display: 'flex', alignItems: 'center' } }} /> - {name} + + {name} + ) } diff --git a/packages/neuron-ui/src/index.tsx b/packages/neuron-ui/src/index.tsx index 1cc1fd40e4..15f9436ffd 100755 --- a/packages/neuron-ui/src/index.tsx +++ b/packages/neuron-ui/src/index.tsx @@ -1,32 +1,10 @@ import React from 'react' import ReactDOM from 'react-dom' import { HashRouter as Router, Route } from 'react-router-dom' -import { loadTheme, getTheme } from 'office-ui-fabric-react' -import { - AddCircle as AddIcon, - Alert as AlertIcon, - Checkmark as SuccessIcon, - Close as DismissIcon, - Copy as CopyIcon, - Down as ArrowDownIcon, - FormClose as ClearIcon, - FormAdd as CreateIcon, - FormPreviousLink as LeaveIcon, - FormUp as ExpandIcon, - FormUpload as ImportIcon, - LinkBottom as LinkBottomIcon, - LinkDown as LinkDownIcon, - LinkTop as LinkTopIcon, - LinkUp as LinkUpIcon, - Nodes as ConnectedIcon, - Scan as ScanIcon, - Search as SearchIcon, - SubtractCircle as RemoveIcon, - Update as UpdateIcon, -} from 'grommet-icons' import 'styles/index.scss' import 'utils/i18n' +import 'utils/loadTheme' import * as serviceWorker from 'serviceWorker' import Navbar from 'containers/Navbar' @@ -35,53 +13,6 @@ import Main from 'containers/Main' import Footer from 'containers/Footer' import ErrorBoundary from 'components/ErrorBoundary' import withProviders from 'states/stateProvider' -import { registerIcons } from 'utils/icons' - -loadTheme({ - fonts: { - tiny: { fontSize: '11px' }, - xSmall: { fontSize: '12px' }, - small: { fontSize: '14px' }, - smallPlus: { fontSize: '15px' }, - medium: { fontSize: '16px' }, - mediumPlus: { fontSize: '17px' }, - large: { fontSize: '18px' }, - xLarge: { fontSize: '22px' }, - xxLarge: { fontSize: '28px' }, - superLarge: { fontSize: '42px' }, - mega: { fontSize: '72px' }, - }, -}) - -const theme = getTheme() -const { semanticColors } = theme - -registerIcons({ - icons: { - errorbadge: , - completed: , - MiniCopy: , - Search: , - FirstPage: , - LastPage: , - PrevPage: , - NextPage: , - ArrowDown: , - ChevronRightMed: , - Scan: , - Import: , - Create: , - Add: , - Remove: , - Copy: , - Clear: , - Dismiss: , - Leave: , - Connected: , - Disconnected: , - Updating: , - }, -}) export const containers: CustomRouter.Route[] = [ { diff --git a/packages/neuron-ui/src/stories/NetworkStatus.stories.tsx b/packages/neuron-ui/src/stories/NetworkStatus.stories.tsx new file mode 100644 index 0000000000..8403afdfda --- /dev/null +++ b/packages/neuron-ui/src/stories/NetworkStatus.stories.tsx @@ -0,0 +1,31 @@ +import React from 'react' +import { storiesOf } from '@storybook/react' +import { withKnobs, text, boolean } from '@storybook/addon-knobs' +import { NetworkStatus } from 'containers/Footer' + +const states = { + Online: { + name: 'network name', + online: true, + }, + Offline: { + name: 'network', + online: false, + }, +} + +const stories = storiesOf('Connection Status', module).addDecorator(withKnobs) + +Object.entries(states).forEach(([title, props]) => { + stories.add(title, () => { + return + }) +}) + +stories.add('With knobs', () => { + const props = { + name: text('Network name', 'network name'), + online: boolean('online', false), + } + return +}) diff --git a/packages/neuron-ui/src/stories/index.tsx b/packages/neuron-ui/src/stories/index.tsx index 1a4ceffd76..d2557a726c 100644 --- a/packages/neuron-ui/src/stories/index.tsx +++ b/packages/neuron-ui/src/stories/index.tsx @@ -1,3 +1,7 @@ +import 'styles/index.scss' +import './styles.scss' +import 'utils/i18n' +import 'utils/loadTheme' import './Overview.stories' import './Addresses.stories' import './History.stories' @@ -9,5 +13,4 @@ import './NetworkSetting.stories' import './PasswordRequest.stories' import './TransactionFeePanel.stories' import './SyncStatus.stories' -import 'styles/index.scss' -import './styles.scss' +import './NetworkStatus.stories' diff --git a/packages/neuron-ui/src/utils/loadTheme.tsx b/packages/neuron-ui/src/utils/loadTheme.tsx new file mode 100644 index 0000000000..41f631d063 --- /dev/null +++ b/packages/neuron-ui/src/utils/loadTheme.tsx @@ -0,0 +1,75 @@ +import React from 'react' +import { loadTheme, getTheme } from 'office-ui-fabric-react' + +import { + AddCircle as AddIcon, + Alert as AlertIcon, + Checkmark as SuccessIcon, + Close as DismissIcon, + Copy as CopyIcon, + Down as ArrowDownIcon, + FormClose as ClearIcon, + FormAdd as CreateIcon, + FormPreviousLink as LeaveIcon, + FormUp as ExpandIcon, + FormUpload as ImportIcon, + LinkBottom as LinkBottomIcon, + LinkDown as LinkDownIcon, + LinkTop as LinkTopIcon, + LinkUp as LinkUpIcon, + Nodes as ConnectedIcon, + Scan as ScanIcon, + Search as SearchIcon, + SubtractCircle as RemoveIcon, + Update as UpdateIcon, +} from 'grommet-icons' + +import { registerIcons } from 'utils/icons' + +loadTheme({ + fonts: { + tiny: { fontSize: '11px' }, + xSmall: { fontSize: '12px' }, + small: { fontSize: '14px' }, + smallPlus: { fontSize: '15px' }, + medium: { fontSize: '16px' }, + mediumPlus: { fontSize: '17px' }, + large: { fontSize: '18px' }, + xLarge: { fontSize: '22px' }, + xxLarge: { fontSize: '28px' }, + superLarge: { fontSize: '42px' }, + mega: { fontSize: '72px' }, + }, +}) + +const theme = getTheme() +const { semanticColors } = theme + +registerIcons({ + icons: { + errorbadge: , + completed: , + MiniCopy: , + Search: , + FirstPage: , + LastPage: , + PrevPage: , + NextPage: , + ArrowDown: , + ChevronRightMed: , + Scan: , + Import: , + Create: , + Add: , + Remove: , + Copy: , + Clear: , + Dismiss: , + Leave: , + Connected: , + Disconnected: , + Updating: , + }, +}) + +export default undefined From 2c45a0733494e93fb587bc4e41e182899734deab Mon Sep 17 00:00:00 2001 From: classicalliu Date: Wed, 31 Jul 2019 15:20:36 +0800 Subject: [PATCH 08/14] chore: update MIN_CELL_CAPACITY --- packages/neuron-wallet/src/services/cells.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/neuron-wallet/src/services/cells.ts b/packages/neuron-wallet/src/services/cells.ts index 3bc1404190..f3ea4e7552 100644 --- a/packages/neuron-wallet/src/services/cells.ts +++ b/packages/neuron-wallet/src/services/cells.ts @@ -4,7 +4,7 @@ import { Cell, OutPoint, Input } from '../types/cell-types' import { CapacityNotEnough } from '../exceptions' import { OutputStatus } from './tx/params' -export const MIN_CELL_CAPACITY = '6000000000' +export const MIN_CELL_CAPACITY = '6100000000' /* eslint @typescript-eslint/no-unused-vars: "warn" */ /* eslint no-await-in-loop: "warn" */ From 04ed41c3284bdbf6ca75fad19670752724eec28d Mon Sep 17 00:00:00 2001 From: classicalliu Date: Wed, 31 Jul 2019 17:57:50 +0800 Subject: [PATCH 09/14] refactor: clean and refactor queue --- .../src/services/sync/block-listener.ts | 18 +------ .../src/services/sync/queue-adapter.ts | 25 ++------- .../neuron-wallet/src/services/sync/queue.ts | 53 ++++++------------- .../src/services/sync/range-for-check.ts | 4 ++ .../neuron-wallet/src/services/sync/utils.ts | 11 ++-- 5 files changed, 31 insertions(+), 80 deletions(-) diff --git a/packages/neuron-wallet/src/services/sync/block-listener.ts b/packages/neuron-wallet/src/services/sync/block-listener.ts index e7babd3858..545b176aac 100644 --- a/packages/neuron-wallet/src/services/sync/block-listener.ts +++ b/packages/neuron-wallet/src/services/sync/block-listener.ts @@ -59,23 +59,8 @@ export default class BlockListener { this.queue = null } - public pause = () => { - if (!this.queue) { - return - } - this.queue.pause() - } - - public resume = () => { - if (!this.queue) { - return - } - - this.queue.resume() - } - public regenerate = async (): Promise => { - if (this.queue && this.queue.get().length() > 0) { + if (this.queue && this.queue.length() > 0) { return } @@ -83,7 +68,6 @@ export default class BlockListener { const startBlockNumber: string = (current + BigInt(1)).toString() const endBlockNumber: string = this.tipBlockNumber.toString() - // TODO: check this queue stopped this.generateQueue(startBlockNumber, endBlockNumber) } diff --git a/packages/neuron-wallet/src/services/sync/queue-adapter.ts b/packages/neuron-wallet/src/services/sync/queue-adapter.ts index 0b9e3432fe..77cd2a9fba 100644 --- a/packages/neuron-wallet/src/services/sync/queue-adapter.ts +++ b/packages/neuron-wallet/src/services/sync/queue-adapter.ts @@ -16,33 +16,16 @@ export default class QueueAdapter { } public kill = () => { - this.push = () => {} - this.pause() - this.remove(() => true) + this.push = (value: any) => value + this.clear() this.q.kill() } - public remove = (callback: any) => { - this.q.remove(callback) - } - - public removeAll = () => { - this.remove(() => true) - } - - public pause = () => { - this.q.pause() - } - - public resume = () => { - this.q.resume() + public clear = () => { + this.q.remove(() => true) } public length = (): number => { return this.q.length() } - - public drain = (callback: any) => { - this.q.drain(callback) - } } diff --git a/packages/neuron-wallet/src/services/sync/queue.ts b/packages/neuron-wallet/src/services/sync/queue.ts index c8df609f0f..9f9c139bc3 100644 --- a/packages/neuron-wallet/src/services/sync/queue.ts +++ b/packages/neuron-wallet/src/services/sync/queue.ts @@ -7,7 +7,7 @@ import QueueAdapter from './queue-adapter' import { TransactionPersistor } from '../tx' export default class Queue { - private q: any + private q: QueueAdapter private concurrent: number = 1 private lockHashes: string[] private getBlocksService: GetBlocks @@ -26,7 +26,7 @@ export default class Queue { currentBlockNumber: BlockNumber = new BlockNumber(), rangeForCheck: RangeForCheck = new RangeForCheck() ) { - this.generateQueue() + this.q = new QueueAdapter(this.getWorker(), this.concurrent) this.lockHashes = lockHashes this.getBlocksService = new GetBlocks() this.startBlockNumber = BigInt(startBlockNumber) @@ -35,14 +35,6 @@ export default class Queue { this.currentBlockNumber = currentBlockNumber } - private generateQueue = () => { - this.q = new QueueAdapter(this.getWorker(), this.concurrent) - } - - public cleanQueue = () => { - this.q.removeAll() - } - public setLockHashes = (lockHashes: string[]): void => { this.lockHashes = lockHashes } @@ -53,30 +45,28 @@ export default class Queue { await Utils.retry(this.retryTime, 0, async () => { await this.pipeline(task.blockNumbers) }) + await callback() } catch { - this.q.kill() - this.q.remove(() => true) + this.clear() } - await callback() } return worker } - public get = () => { - return this.q + public clear = () => { + this.q.clear() } - public pause = () => { - this.q.pause() + public get = () => { + return this.q } - public resume = () => { - this.q.resume() + public length = (): number => { + return this.q.length() } public kill = () => { this.q.kill() - this.q.removeAll() } public pipeline = async (blockNumbers: string[]) => { @@ -105,9 +95,9 @@ export default class Queue { const range = await this.rangeForCheck.getRange() const rangeFirstBlockHeader: BlockHeader = range[0] await this.currentBlockNumber.updateCurrent(BigInt(rangeFirstBlockHeader.number)) - await this.rangeForCheck.setRange([]) + await this.rangeForCheck.clearRange() await TransactionPersistor.deleteWhenFork(rangeFirstBlockHeader.number) - await this.cleanQueue() + await this.clear() this.startBlockNumber = await this.currentBlockNumber.getCurrent() this.batchPush() } else if (checkResult.type === 'block-headers-not-match') { @@ -122,9 +112,9 @@ export default class Queue { } public batchPush = (): void => { - const rangeArr = this.range(this.startBlockNumber, this.endBlockNumber) + const rangeArr = Utils.rangeForBigInt(this.startBlockNumber, this.endBlockNumber) - const slice = this.eachSlice(rangeArr, this.fetchSize) + const slice = Utils.eachSlice(rangeArr, this.fetchSize) slice.forEach(async arr => { await this.push(arr) @@ -139,7 +129,7 @@ export default class Queue { return } - this.q.removeAll() + this.clear() this.batchPush() } @@ -149,17 +139,4 @@ export default class Queue { } return this.batchPush() } - - private eachSlice = (array: any[], size: number) => { - const arr = [] - for (let i = 0, l = array.length; i < l; i += size) { - arr.push(array.slice(i, i + size)) - } - return arr - } - - private range = (startNumber: bigint, endNumber: bigint): bigint[] => { - const size = +(endNumber - startNumber + BigInt(1)).toString() - return [...Array(size).keys()].map(i => BigInt(i) + startNumber) - } } diff --git a/packages/neuron-wallet/src/services/sync/range-for-check.ts b/packages/neuron-wallet/src/services/sync/range-for-check.ts index a6081adcfe..00e2b6e40c 100644 --- a/packages/neuron-wallet/src/services/sync/range-for-check.ts +++ b/packages/neuron-wallet/src/services/sync/range-for-check.ts @@ -34,6 +34,10 @@ export default class RangeForCheck { this.range = range } + public clearRange = () => { + this.range = [] + } + public pushRange = (range: BlockHeader[]) => { if (range.length <= 0) { return diff --git a/packages/neuron-wallet/src/services/sync/utils.ts b/packages/neuron-wallet/src/services/sync/utils.ts index dc01d3b9b9..f52fd1d5b0 100644 --- a/packages/neuron-wallet/src/services/sync/utils.ts +++ b/packages/neuron-wallet/src/services/sync/utils.ts @@ -8,10 +8,13 @@ export default class Utils { } public static range = (startNumber: string, endNumber: string): string[] => { - const startNumberInt = BigInt(startNumber) - const endNumberInt = BigInt(endNumber) - const size = +(endNumberInt - startNumberInt + BigInt(1)).toString() - return [...Array(size).keys()].map(i => (BigInt(i) + startNumber).toString()) + const result = Utils.rangeForBigInt(BigInt(startNumber), BigInt(endNumber)) + return result.map(num => num.toString()) + } + + public static rangeForBigInt = (startNumber: bigint, endNumber: bigint): bigint[] => { + const size = +(endNumber - startNumber + BigInt(1)).toString() + return [...Array(size).keys()].map(i => BigInt(i) + startNumber) } public static sleep = (ms: number) => { From d720670370c8b257550c2124db7ea496a51b8e15 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Wed, 31 Jul 2019 19:15:21 +0800 Subject: [PATCH 10/14] chore: bigint for tipBlockNumber --- .../neuron-wallet/src/services/sync/block-listener.ts | 4 ++-- packages/neuron-wallet/src/services/sync/queue.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/neuron-wallet/src/services/sync/block-listener.ts b/packages/neuron-wallet/src/services/sync/block-listener.ts index 545b176aac..881b0d1e42 100644 --- a/packages/neuron-wallet/src/services/sync/block-listener.ts +++ b/packages/neuron-wallet/src/services/sync/block-listener.ts @@ -7,7 +7,7 @@ import Utils from './utils' export default class BlockListener { private lockHashes: string[] - private tipBlockNumber: number = -1 + private tipBlockNumber: bigint = BigInt(-1) private queue: Queue | undefined | null = undefined private rangeForCheck: RangeForCheck private currentBlockNumber: BlockNumber @@ -24,7 +24,7 @@ export default class BlockListener { this.tipNumberListener = tipNumberSubject.subscribe(async num => { if (num) { - this.tipBlockNumber = parseInt(num, 10) + this.tipBlockNumber = BigInt(num) } }) } diff --git a/packages/neuron-wallet/src/services/sync/queue.ts b/packages/neuron-wallet/src/services/sync/queue.ts index 9f9c139bc3..1941ce34c6 100644 --- a/packages/neuron-wallet/src/services/sync/queue.ts +++ b/packages/neuron-wallet/src/services/sync/queue.ts @@ -107,8 +107,8 @@ export default class Queue { } } - public push = async (blockNumbers: string[]): Promise => { - await this.q.push({ blockNumbers }) + public push = (blockNumbers: string[]): void => { + this.q.push({ blockNumbers }) } public batchPush = (): void => { @@ -116,8 +116,8 @@ export default class Queue { const slice = Utils.eachSlice(rangeArr, this.fetchSize) - slice.forEach(async arr => { - await this.push(arr) + slice.forEach(arr => { + this.push(arr) }) } From cb2ce9fa68821eafbcbb3acad920c657973688fa Mon Sep 17 00:00:00 2001 From: classicalliu Date: Wed, 31 Jul 2019 19:47:34 +0800 Subject: [PATCH 11/14] chore: wait for drain --- .../src/services/sync/block-listener.ts | 12 ++++++++++-- .../neuron-wallet/src/services/sync/queue-adapter.ts | 6 +++++- packages/neuron-wallet/src/services/sync/queue.ts | 4 ++++ .../src/startup/sync-block-task/task.ts | 7 +++---- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/neuron-wallet/src/services/sync/block-listener.ts b/packages/neuron-wallet/src/services/sync/block-listener.ts index 881b0d1e42..c492e42523 100644 --- a/packages/neuron-wallet/src/services/sync/block-listener.ts +++ b/packages/neuron-wallet/src/services/sync/block-listener.ts @@ -13,6 +13,7 @@ export default class BlockListener { private currentBlockNumber: BlockNumber private interval: number = 5000 private tipNumberListener: Subscription + private stopFlag = false constructor( lockHashes: string[], @@ -44,19 +45,26 @@ export default class BlockListener { if (restart) { await this.currentBlockNumber.updateCurrent(BigInt(0)) } - while (this.queue !== null) { + while (!this.stopFlag) { await this.regenerate() await Utils.sleep(this.interval) } } public stop = async () => { + this.stopFlag = true this.tipNumberListener.unsubscribe() if (!this.queue) { return } await this.queue.kill() - this.queue = null + } + + public drain = async () => { + if (this.queue) { + return this.queue.drain() + } + return undefined } public regenerate = async (): Promise => { diff --git a/packages/neuron-wallet/src/services/sync/queue-adapter.ts b/packages/neuron-wallet/src/services/sync/queue-adapter.ts index 77cd2a9fba..5ccbdbf0d9 100644 --- a/packages/neuron-wallet/src/services/sync/queue-adapter.ts +++ b/packages/neuron-wallet/src/services/sync/queue-adapter.ts @@ -3,7 +3,7 @@ import async from 'async' export default class QueueAdapter { private q: any - constructor(worker: async.AsyncWorker, concurrency?: number | undefined) { + constructor(worker: async.AsyncWorker, concurrency: number) { this.q = async.queue(worker, concurrency) } @@ -28,4 +28,8 @@ export default class QueueAdapter { public length = (): number => { return this.q.length() } + + public drain = async () => { + return this.q.drain() + } } diff --git a/packages/neuron-wallet/src/services/sync/queue.ts b/packages/neuron-wallet/src/services/sync/queue.ts index 1941ce34c6..6ac7072560 100644 --- a/packages/neuron-wallet/src/services/sync/queue.ts +++ b/packages/neuron-wallet/src/services/sync/queue.ts @@ -69,6 +69,10 @@ 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/startup/sync-block-task/task.ts b/packages/neuron-wallet/src/startup/sync-block-task/task.ts index c1499190d6..a8353af5b3 100644 --- a/packages/neuron-wallet/src/startup/sync-block-task/task.ts +++ b/packages/neuron-wallet/src/startup/sync-block-task/task.ts @@ -8,7 +8,6 @@ import BlockListener from '../../services/sync/block-listener' import { NetworkWithID } from '../../services/networks' import { initDatabase } from './init-database' import { register as registerTxStatusListener } from '../../listeners/tx-status' -import Utils from '../../services/sync/utils' import { register as registerAddressListener } from '../../listeners/address' @@ -57,6 +56,9 @@ export const switchNetwork = async () => { }) const regenerateListener = async () => { + await blockListener.stop() + // wait former queue to be drained + await blockListener.drain() const hashes: string[] = await loadAddressesAndConvert() blockListener = new BlockListener(hashes, nodeService.tipNumberSubject) await blockListener.start(true) @@ -64,9 +66,6 @@ export const switchNetwork = async () => { walletCreatedSubject.subscribe(async (type: string) => { if (type === 'import') { - await blockListener.stop() - // wait former queue to be drained - await Utils.sleep(3000) await regenerateListener() } }) From 711bef569b5ba8dc76605a0df404bc06c6c5ba5d Mon Sep 17 00:00:00 2001 From: classicalliu Date: Wed, 31 Jul 2019 20:45:28 +0800 Subject: [PATCH 12/14] chore: rename stopFlag --- packages/neuron-wallet/src/services/sync/block-listener.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/neuron-wallet/src/services/sync/block-listener.ts b/packages/neuron-wallet/src/services/sync/block-listener.ts index c492e42523..32d322ffbb 100644 --- a/packages/neuron-wallet/src/services/sync/block-listener.ts +++ b/packages/neuron-wallet/src/services/sync/block-listener.ts @@ -13,7 +13,7 @@ export default class BlockListener { private currentBlockNumber: BlockNumber private interval: number = 5000 private tipNumberListener: Subscription - private stopFlag = false + private stopped = false constructor( lockHashes: string[], @@ -45,14 +45,14 @@ export default class BlockListener { if (restart) { await this.currentBlockNumber.updateCurrent(BigInt(0)) } - while (!this.stopFlag) { + while (!this.stopped) { await this.regenerate() await Utils.sleep(this.interval) } } public stop = async () => { - this.stopFlag = true + this.stopped = true this.tipNumberListener.unsubscribe() if (!this.queue) { return From e1b31219d3ed3a2ece671bb887946545514f1507 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 1 Aug 2019 08:39:54 +0900 Subject: [PATCH 13/14] fix: Remove publisherName for win electron-builder configuration to solve invalid code sign issue when updating on Windows --- packages/neuron-wallet/electron-builder.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/neuron-wallet/electron-builder.yml b/packages/neuron-wallet/electron-builder.yml index c1f2baeb75..5996fd323b 100644 --- a/packages/neuron-wallet/electron-builder.yml +++ b/packages/neuron-wallet/electron-builder.yml @@ -44,7 +44,6 @@ dmg: win: artifactName: "${productName}-v${version}-${os}-${arch}-installer.${ext}" icon: assets/images/icon.ico - publisherName: Nervos Foundation target: - target: nsis arch: From 16f6332be8df7d9df8d526cd1f18507760d968a4 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 1 Aug 2019 08:50:38 +0900 Subject: [PATCH 14/14] chore: Bump to v0.17.0-alpha.3 --- CHANGELOG.md | 18 ++++++++++++++++++ lerna.json | 2 +- package.json | 2 +- packages/neuron-ui/package.json | 2 +- packages/neuron-wallet/package.json | 4 ++-- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f544b719d..04742de81d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,21 @@ +# [0.17.0-alpha.3](https://github.com/nervosnetwork/neuron/compare/v0.17.0-alpha.2...v0.17.0-alpha.3) (2019-08-01) + + +### Bug Fixes + +* connection not found when delete wallet ([2afc7e7](https://github.com/nervosnetwork/neuron/commit/2afc7e7)) +* Remove publisherName for win electron-builder configuration ([e1b3121](https://github.com/nervosnetwork/neuron/commit/e1b3121)) +* Translation for installing update prompt message ([0540057](https://github.com/nervosnetwork/neuron/commit/0540057)) + + +### Features + +* **neuron-ui:** add the story of connection status component, and set the network name to 14px ([e940fdf](https://github.com/nervosnetwork/neuron/commit/e940fdf)) +* Only bundle en and zh_CN language folders for mac ([6701659](https://github.com/nervosnetwork/neuron/commit/6701659)) +* **neuron-ui:** double click on tx item shows its details ([383db66](https://github.com/nervosnetwork/neuron/commit/383db66)) + + + # [0.17.0-alpha.2](https://github.com/nervosnetwork/neuron/compare/v0.17.0-alpha.1...v0.17.0-alpha.2) (2019-07-31) diff --git a/lerna.json b/lerna.json index 0713a99436..2f191eb7ee 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "packages": [ "packages/*" ], - "version": "0.17.0-alpha.2", + "version": "0.17.0-alpha.3", "npmClient": "yarn", "useWorkspaces": true } diff --git a/package.json b/package.json index 24e12fdb3b..29b77e23aa 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "neuron", "productName": "Neuron", "description": "CKB Neuron Wallet", - "version": "0.17.0-alpha.2", + "version": "0.17.0-alpha.3", "private": true, "author": { "name": "Nervos Core Dev", diff --git a/packages/neuron-ui/package.json b/packages/neuron-ui/package.json index ab479b2c47..5fa29bc50d 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.2", + "version": "0.17.0-alpha.3", "private": true, "author": { "name": "Nervos Core Dev", diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index ef7b6e7751..17aa2c52f3 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.2", + "version": "0.17.0-alpha.3", "private": true, "author": { "name": "Nervos Core Dev", @@ -64,7 +64,7 @@ "electron-devtools-installer": "2.2.4", "electron-notarize": "0.1.1", "lint-staged": "9.2.0", - "neuron-ui": "0.17.0-alpha.2", + "neuron-ui": "0.17.0-alpha.3", "rimraf": "2.6.3", "spectron": "7.0.0" }