From a4eb83d7b150a76c4739ab1fac77444c8cf7545b Mon Sep 17 00:00:00 2001 From: classicalliu Date: Thu, 18 Jul 2019 19:44:15 +0800 Subject: [PATCH 1/9] fix: first-not-match will retry all the time --- .../neuron-wallet/src/services/sync/queue.ts | 17 +++++++---------- .../neuron-wallet/src/services/transactions.ts | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/neuron-wallet/src/services/sync/queue.ts b/packages/neuron-wallet/src/services/sync/queue.ts index 5b41005a84..6c91cff0ab 100644 --- a/packages/neuron-wallet/src/services/sync/queue.ts +++ b/packages/neuron-wallet/src/services/sync/queue.ts @@ -4,6 +4,7 @@ import { Block, BlockHeader } from '../../types/cell-types' import RangeForCheck from './range-for-check' import BlockNumber from './block-number' import Utils from './utils' +import TransactionsService from '../transactions' export default class Queue { private q: any @@ -38,11 +39,6 @@ export default class Queue { this.q = async.queue(this.getWorker(), this.concurrent) } - private regenerateQueue = () => { - this.q.kill() - this.generateQueue() - } - public setLockHashes = (lockHashes: string[]): void => { this.lockHashes = lockHashes } @@ -102,13 +98,14 @@ export default class Queue { const checkResult = this.rangeForCheck.check(blockHeaders) if (!checkResult.success) { if (checkResult.type === 'first-not-match') { - // TODO: reset currentBlockNumber const range = await this.rangeForCheck.getRange() const rangeFirstBlockHeader: BlockHeader = range[0] - this.currentBlockNumber.updateCurrent(BigInt(rangeFirstBlockHeader.number)) - this.regenerateQueue() - this.startBlockNumber = await this.currentBlockNumber.getCurrent() - this.batchPush() + await this.currentBlockNumber.updateCurrent(BigInt(rangeFirstBlockHeader.number)) + await this.rangeForCheck.setRange([]) + await TransactionsService.deleteWhenFork(rangeFirstBlockHeader.number) + + // then throw an error for restart + throw new Error('chain forked and first not match') } else if (checkResult.type === 'block-headers-not-match') { // TODO: throw here and retry 5 times throw new Error('chain forked') diff --git a/packages/neuron-wallet/src/services/transactions.ts b/packages/neuron-wallet/src/services/transactions.ts index eac1a15f90..acc6a99055 100644 --- a/packages/neuron-wallet/src/services/transactions.ts +++ b/packages/neuron-wallet/src/services/transactions.ts @@ -453,6 +453,21 @@ export default class TransactionsService { .execute() } + public static deleteWhenFork = async (blockNumber: string) => { + const txs = await getConnection() + .getRepository(TransactionEntity) + .createQueryBuilder('tx') + .where( + 'CAST(tx.blockNumber AS UNSIGNED BIG INT) > CAST(:blockNumber AS UNSIGNED BIG INT) AND tx.status = :status', + { + blockNumber, + status: TransactionStatus.Success, + } + ) + .getMany() + return getConnection().manager.remove(txs) + } + // update previousOutput's status to 'dead' if found // calculate output lockHash, input lockHash and capacity // when send a transaction, use TxSaveType.Sent From d4c995b8bc7c3f2921e7f5fdb1e67504b376b0a9 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 19 Jul 2019 10:59:34 +0900 Subject: [PATCH 2/9] refactor: Localize overview buttons and move them to the right --- packages/neuron-ui/src/components/Overview/index.tsx | 9 +++++---- packages/neuron-ui/src/locales/en.json | 4 +++- packages/neuron-ui/src/locales/zh.json | 4 +++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/neuron-ui/src/components/Overview/index.tsx b/packages/neuron-ui/src/components/Overview/index.tsx index de51bc24c7..262bf51725 100644 --- a/packages/neuron-ui/src/components/Overview/index.tsx +++ b/packages/neuron-ui/src/components/Overview/index.tsx @@ -276,17 +276,17 @@ const Overview = ({ {name} - +
- Blockchain Status + {t('overview.blockchain-status')}
- Miner Info + {t('overview.miner-info')}
@@ -311,9 +311,10 @@ const Overview = ({
) : null} + {/* TODO: Implement this */} {minerInfoRef.current ? ( ) : null}
diff --git a/packages/neuron-ui/src/locales/en.json b/packages/neuron-ui/src/locales/en.json index 770fc178f7..1a40dac6b1 100644 --- a/packages/neuron-ui/src/locales/en.json +++ b/packages/neuron-ui/src/locales/en.json @@ -20,10 +20,12 @@ "datetime": "Date & Time", "status": "Status", "amount": "Amount", + "blockchain-status": "Blockchain Status", "chain-identity": "Chain Identity", "tip-block-number": "Block Number", "epoch": "Epoch", - "difficulty": "Difficulty" + "difficulty": "Difficulty", + "miner-info": "Miner Info" }, "wizard": { "welcome-to-nervos-neuron": "Welcome to Neuron", diff --git a/packages/neuron-ui/src/locales/zh.json b/packages/neuron-ui/src/locales/zh.json index 01a859392c..8379c69200 100644 --- a/packages/neuron-ui/src/locales/zh.json +++ b/packages/neuron-ui/src/locales/zh.json @@ -20,10 +20,12 @@ "datetime": "时间", "status": "状态", "amount": "金额", + "blockchain-status": "链状态", "chain-identity": "链的 ID", "tip-block-number": "区块高度", "epoch": "Epoch", - "difficulty": "难度" + "difficulty": "难度", + "miner-info": "挖矿信息" }, "wizard": { "welcome-to-nervos-ckb": "欢迎使用 Neuron", From 1e4ee92875e03bc5a7d879093d8bf9660f87beca Mon Sep 17 00:00:00 2001 From: classicalliu Date: Fri, 19 Jul 2019 11:10:05 +0800 Subject: [PATCH 3/9] fix: using regenerateQueue instead of throw --- .../neuron-wallet/src/services/sync/queue.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/neuron-wallet/src/services/sync/queue.ts b/packages/neuron-wallet/src/services/sync/queue.ts index 6c91cff0ab..5df04eb712 100644 --- a/packages/neuron-wallet/src/services/sync/queue.ts +++ b/packages/neuron-wallet/src/services/sync/queue.ts @@ -39,6 +39,12 @@ export default class Queue { this.q = async.queue(this.getWorker(), this.concurrent) } + private regenerateQueue = async () => { + this.kill() + await Utils.sleep(3000) + this.generateQueue() + } + public setLockHashes = (lockHashes: string[]): void => { this.lockHashes = lockHashes } @@ -80,7 +86,7 @@ export default class Queue { const blocks: Block[] = await this.getBlocksService.getRangeBlocks(blockNumbers) const blockHeaders: BlockHeader[] = blocks.map(block => block.header) - // TODO: 2. check blockHeaders + // 2. check blockHeaders await this.checkBlockHeader(blockHeaders) // 3. check and save @@ -103,11 +109,11 @@ export default class Queue { await this.currentBlockNumber.updateCurrent(BigInt(rangeFirstBlockHeader.number)) await this.rangeForCheck.setRange([]) await TransactionsService.deleteWhenFork(rangeFirstBlockHeader.number) - - // then throw an error for restart - throw new Error('chain forked and first not match') + await this.regenerateQueue() + this.startBlockNumber = await this.currentBlockNumber.getCurrent() + this.batchPush() } else if (checkResult.type === 'block-headers-not-match') { - // TODO: throw here and retry 5 times + // throw here and retry 5 times throw new Error('chain forked') } } From 2acc094e5656fbca9471e9b30fa64e7de3552348 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Fri, 19 Jul 2019 12:00:58 +0800 Subject: [PATCH 4/9] chore: bump electron and builder --- packages/neuron-wallet/package.json | 4 +- yarn.lock | 163 ++++++++++++---------------- 2 files changed, 72 insertions(+), 95 deletions(-) diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index ffd1a785ca..60cb972af9 100644 --- a/packages/neuron-wallet/package.json +++ b/packages/neuron-wallet/package.json @@ -55,8 +55,8 @@ "@types/sqlite3": "3.1.5", "@types/uuid": "3.4.4", "devtron": "1.4.0", - "electron": "5.0.6", - "electron-builder": "21.0.14", + "electron": "5.0.7", + "electron-builder": "21.1.1", "electron-devtools-installer": "2.2.4", "electron-notarize": "0.1.1", "lint-staged": "8.1.7", diff --git a/yarn.lock b/yarn.lock index b02b4754e0..652327258d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"7zip-bin@~4.1.0": - version "4.1.0" - resolved "https://registry.yarnpkg.com/7zip-bin/-/7zip-bin-4.1.0.tgz#33eff662a5c39c0c2061170cc003c5120743fff0" - integrity sha512-AsnBZN3a8/JcNt+KPkGGODaA4c7l3W5+WpeKgGSbstSLxqWtTXqd1ieJGBQ8IFCtRg8DmmKUcSkIkUc0A4p3YA== +"7zip-bin@~5.0.3": + version "5.0.3" + resolved "https://registry.yarnpkg.com/7zip-bin/-/7zip-bin-5.0.3.tgz#bc5b5532ecafd923a61f2fb097e3b108c0106a3f" + integrity sha512-GLyWIFBbGvpKPGo55JyRZAo4lVbnBiD52cKlw/0Vt+wnmKvWJkpZvsjVoaIolyBXDeAQKSicRtqFNPem9w0WYA== "7zip@0.0.6": version "0.0.6" @@ -3915,30 +3915,29 @@ anymatch@^2.0.0: micromatch "^3.1.4" normalize-path "^2.1.1" -app-builder-bin@3.2.2: - version "3.2.2" - resolved "https://registry.yarnpkg.com/app-builder-bin/-/app-builder-bin-3.2.2.tgz#e4d5a70b0d5d984c103f2e1fd5ee6b1f246266e2" - integrity sha512-mD3ipW4S1C6smJbJre2nlFfC2aqzGh97Q7d+KADwzK/lFj2SVYmUoyqN96pl0b64RyzquSzjhs+4azEFTnHr/w== +app-builder-bin@3.4.0: + version "3.4.0" + resolved "https://registry.yarnpkg.com/app-builder-bin/-/app-builder-bin-3.4.0.tgz#620d7f941dad157206c267bb0b437fee43889b33" + integrity sha512-ZyQqfFnyjAmXep29PmuMIu2KvGlfHiziz2/I38zOFe5kqnkMqeNNn/qmnwD6wdCKKeHqBuZtoWQnft8q0YyLpw== -app-builder-lib@21.0.14, app-builder-lib@~21.0.14: - version "21.0.14" - resolved "https://registry.yarnpkg.com/app-builder-lib/-/app-builder-lib-21.0.14.tgz#9295a96f782bd282d3185cd3494a910bed0dd6ed" - integrity sha512-GaHNbU7TwTAdiX40X71914Sa4IiQzbMs9NyKIMvdjlK/PlkcV3IDY6hr2tro83Za+gOKZ9Y5tGD2grqQYEQ6cg== +app-builder-lib@21.1.1, app-builder-lib@~21.1.1: + version "21.1.1" + resolved "https://registry.yarnpkg.com/app-builder-lib/-/app-builder-lib-21.1.1.tgz#ab30bcbcf61541e46d68912cc48c65a89169c2aa" + integrity sha512-nG5w9xjv4c16ki+pyBPqJvUCtQY97XQNsA4dEBryq6vClwDTkwKrl7aS0cXjo3dsWKsf/5EIcLrV0tfIiXUqJA== dependencies: - "7zip-bin" "~4.1.0" + "7zip-bin" "~5.0.3" async-exit-hook "^2.0.1" bluebird-lst "^1.0.9" - builder-util "21.0.14" + builder-util "21.1.1" builder-util-runtime "8.3.0" chromium-pickle-js "^0.2.0" debug "^4.1.1" ejs "^2.6.2" - electron-osx-sign "0.4.11" - electron-publish "21.0.14" + electron-publish "21.1.1" fs-extra "^8.1.0" hosted-git-info "^2.7.1" is-ci "^2.0.0" - isbinaryfile "^4.0.1" + isbinaryfile "^4.0.2" js-yaml "^3.13.1" lazy-val "^1.0.4" minimatch "^3.0.4" @@ -4734,7 +4733,7 @@ balanced-match@^1.0.0: resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= -base64-js@^1.0.2, base64-js@^1.2.3: +base64-js@^1.0.2: version "1.3.0" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.0.tgz#cab1e6118f051095e58b5281aea8c1cd22bfc0e3" integrity sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw== @@ -4808,7 +4807,7 @@ bluebird-lst@^1.0.9: dependencies: bluebird "^3.5.5" -bluebird@^3.3.5, bluebird@^3.5.0, bluebird@^3.5.1, bluebird@^3.5.3, bluebird@^3.5.5: +bluebird@^3.3.5, bluebird@^3.5.1, bluebird@^3.5.3, bluebird@^3.5.5: version "3.5.5" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.5.tgz#a8d0afd73251effbbd5fe384a77d73003c17a71f" integrity sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w== @@ -5078,14 +5077,14 @@ builder-util-runtime@8.3.0: debug "^4.1.1" sax "^1.2.4" -builder-util@21.0.14, builder-util@~21.0.14: - version "21.0.14" - resolved "https://registry.yarnpkg.com/builder-util/-/builder-util-21.0.14.tgz#5270508e19bcb08ee4acb46244dff8cb26b17098" - integrity sha512-IW3eoCETeDoolvOUMgw1HnU8wnIJBqgPrMSO4BNNZZTK3D9MylzkJsJJZkpRxE0Dn/+bgNh4TYihVPQdsXHbMg== +builder-util@21.1.1, builder-util@~21.1.1: + version "21.1.1" + resolved "https://registry.yarnpkg.com/builder-util/-/builder-util-21.1.1.tgz#45c0d0e1b51d1f85b835a1645f435722cbd9a1d6" + integrity sha512-+t6pbMo/COTYDfqfRDrWDi9tuPxBctb0S9PVt8Kgd+K0eqD1lvbF05rrkiQpXIrhb6cndXgcl3FG18Oqgy5YPg== dependencies: - "7zip-bin" "~4.1.0" + "7zip-bin" "~5.0.3" "@types/debug" "^4.1.4" - app-builder-bin "3.2.2" + app-builder-bin "3.4.0" bluebird-lst "^1.0.9" builder-util-runtime "8.3.0" chalk "^2.4.2" @@ -5731,11 +5730,6 @@ compare-func@^1.3.1: array-ify "^1.0.0" dot-prop "^3.0.0" -compare-version@^0.1.2: - version "0.1.2" - resolved "https://registry.yarnpkg.com/compare-version/-/compare-version-0.1.2.tgz#0162ec2d9351f5ddd59a9202cba935366a725080" - integrity sha1-AWLsLZNR9d3VmpICy6k1NmpyUIA= - component-emitter@^1.2.1: version "1.3.0" resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0" @@ -6845,14 +6839,14 @@ discontinuous-range@1.0.0: resolved "https://registry.yarnpkg.com/discontinuous-range/-/discontinuous-range-1.0.0.tgz#e38331f0844bba49b9a9cb71c771585aab1bc65a" integrity sha1-44Mx8IRLukm5qctxx3FYWqsbxlo= -dmg-builder@21.0.14: - version "21.0.14" - resolved "https://registry.yarnpkg.com/dmg-builder/-/dmg-builder-21.0.14.tgz#9d939deba426dba8ae4898cf4f0b5e722dabf33c" - integrity sha512-FkGcc0izFeFDXbdzeGTSE0skzAi04P1cTpSUIgJRW8NitY01bHYJyZP0jYtVizdWnlxj4cbL1Ek90Y7clgyBIw== +dmg-builder@21.1.1: + version "21.1.1" + resolved "https://registry.yarnpkg.com/dmg-builder/-/dmg-builder-21.1.1.tgz#a30b2c6fe305f38bbbd06ac2cc0682e5423f7e50" + integrity sha512-WsafJ+LkG20ddVfKfNlJC6AMRKTvLMJhAwAmBHzb+KWhMZVs9/3QY2yd2BIpvWYRfUD/lWd+LmclTNWw7540Cw== dependencies: - app-builder-lib "~21.0.14" + app-builder-lib "~21.1.1" bluebird-lst "^1.0.9" - builder-util "~21.0.14" + builder-util "~21.1.1" fs-extra "^8.1.0" iconv-lite "^0.5.0" js-yaml "^3.13.1" @@ -7059,24 +7053,24 @@ ejs@~2.5.6: resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.5.9.tgz#7ba254582a560d267437109a68354112475b0ce5" integrity sha512-GJCAeDBKfREgkBtgrYSf9hQy9kTb3helv0zGdzqhM7iAkW8FA/ZF97VQDbwFiwIT8MQLLOe5VlPZOEvZAqtUAQ== -electron-builder@21.0.14: - version "21.0.14" - resolved "https://registry.yarnpkg.com/electron-builder/-/electron-builder-21.0.14.tgz#12d99b5f51f73d10a6d95fcf167cdfa439dd2bd8" - integrity sha512-InHQg/pZMyzUtg2eulVP6XFC6iB8nra6aaQmUVS6Rk/rMTGsv+cazsFmGyg4k0JwY4Xl2rr/NPOSuiMF5swtpg== +electron-builder@21.1.1: + version "21.1.1" + resolved "https://registry.yarnpkg.com/electron-builder/-/electron-builder-21.1.1.tgz#eecfd9473ee9ab58fd445a0eb512aef759d509e6" + integrity sha512-4A3h0dhqSranoX7cM0eqkzABeHABH9Nch12003XIZ9MUPV4jL97nK5WBbbVG06qglYTV9x62XAqPPDS+KBOsEg== dependencies: - app-builder-lib "21.0.14" + app-builder-lib "21.1.1" bluebird-lst "^1.0.9" - builder-util "21.0.14" + builder-util "21.1.1" builder-util-runtime "8.3.0" chalk "^2.4.2" - dmg-builder "21.0.14" + dmg-builder "21.1.1" fs-extra "^8.1.0" is-ci "^2.0.0" lazy-val "^1.0.4" read-config-file "4.0.1" sanitize-filename "^1.6.1" update-notifier "^3.0.1" - yargs "^13.2.4" + yargs "^13.3.0" electron-chromedriver@^5.0.1: version "5.0.1" @@ -7119,25 +7113,13 @@ electron-notarize@0.1.1: debug "^4.1.1" fs-extra "^8.0.1" -electron-osx-sign@0.4.11: - version "0.4.11" - resolved "https://registry.yarnpkg.com/electron-osx-sign/-/electron-osx-sign-0.4.11.tgz#8377732fe7b207969f264b67582ee47029ce092f" - integrity sha512-VVd40nrnVqymvFrY9ZkOYgHJOvexHHYTR3di/SN+mjJ0OWhR1I8BRVj3U+Yamw6hnkZZNKZp52rqL5EFAAPFkQ== - dependencies: - bluebird "^3.5.0" - compare-version "^0.1.2" - debug "^2.6.8" - isbinaryfile "^3.0.2" - minimist "^1.2.0" - plist "^3.0.1" - -electron-publish@21.0.14: - version "21.0.14" - resolved "https://registry.yarnpkg.com/electron-publish/-/electron-publish-21.0.14.tgz#0ccc2e85ea941616cdef06b04ecccf3d01a2f0e3" - integrity sha512-yyjDgnd4TE01kigwjTaXmHFaPN6iS1HL7UBUfIbL8p97KCV0AMwZ+SiOQ/A3ezbLB71FnO/3HgacUSOTOzu/Ng== +electron-publish@21.1.1: + version "21.1.1" + resolved "https://registry.yarnpkg.com/electron-publish/-/electron-publish-21.1.1.tgz#00acce2c60b45c2696e05852717a2fa7e9110a00" + integrity sha512-cM5XLFolIB5NnVpBKewcUM3Ggg+wm+LeKRYHjcB9ri58cbPKxaN+fRUXAZs3m1U9t7SIgjZy83sUSi3asxMXgQ== dependencies: bluebird-lst "^1.0.9" - builder-util "~21.0.14" + builder-util "~21.1.1" builder-util-runtime "8.3.0" chalk "^2.4.2" fs-extra "^8.1.0" @@ -7157,10 +7139,10 @@ electron-window-state@5.0.3: jsonfile "^4.0.0" mkdirp "^0.5.1" -electron@5.0.6: - version "5.0.6" - resolved "https://registry.yarnpkg.com/electron/-/electron-5.0.6.tgz#e3ca4a58b5716fceef3fb64e1fd2222dd9c51de0" - integrity sha512-0L53lv26eDhaaNxL6DqXGQrQOEAYbrQg40stRSb2pzrY06kwPbABzXEiaCvEsBuKUQ+9OQBbVyyvXRbLJlun/A== +electron@5.0.7: + version "5.0.7" + resolved "https://registry.yarnpkg.com/electron/-/electron-5.0.7.tgz#a48fcbd13d30f16f7d7887908b68e52156e90259" + integrity sha512-OMMz8DhatxLuBFbnW7KYcAUjflGYFn0IQEtKR0iZhMAm89FgNOd9SVbxXWAGNxvRR6C0gORXwhTh6BCqqqcR6Q== dependencies: "@types/node" "^10.12.18" electron-download "^4.1.0" @@ -9870,17 +9852,10 @@ isarray@1.0.0, isarray@^1.0.0, isarray@~1.0.0: resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE= -isbinaryfile@^3.0.2: - version "3.0.3" - resolved "https://registry.yarnpkg.com/isbinaryfile/-/isbinaryfile-3.0.3.tgz#5d6def3edebf6e8ca8cae9c30183a804b5f8be80" - integrity sha512-8cJBL5tTd2OS0dM4jz07wQd5g0dCCqIhUxPIGtZfa5L6hWlvV5MHTITy/DBAsF+Oe2LS1X3krBUhNwaGUWpWxw== - dependencies: - buffer-alloc "^1.2.0" - -isbinaryfile@^4.0.1: - version "4.0.1" - resolved "https://registry.yarnpkg.com/isbinaryfile/-/isbinaryfile-4.0.1.tgz#85dadd12ba236c9225fdf4648d6069956eaba640" - integrity sha512-bvJxbNWm72dy/1+qeBm9F8wUM4siDnlzid7NN5Ib4nQcc0tNIx/YWgEih1ZRHXr8xVbpGk1ccLlA9gOSlyx3gw== +isbinaryfile@^4.0.2: + version "4.0.2" + resolved "https://registry.yarnpkg.com/isbinaryfile/-/isbinaryfile-4.0.2.tgz#bfc45642da645681c610cca831022e30af426488" + integrity sha512-C3FSxJdNrEr2F4z6uFtNzECDM5hXk+46fxaa+cwBe5/XrWSmzdG8DDgyjfX6/NRdBB21q2JXuRAzPCUs+fclnQ== isemail@3.x.x: version "3.2.0" @@ -12860,15 +12835,6 @@ please-upgrade-node@^3.0.2, please-upgrade-node@^3.1.1: dependencies: semver-compare "^1.0.0" -plist@^3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.1.tgz#a9b931d17c304e8912ef0ba3bdd6182baf2e1f8c" - integrity sha512-GpgvHHocGRyQm74b6FWEZZVRroHKE1I0/BTjAmySaohK+cUn+hZpbqXkc3KWgW3gQYkqcQej35FohcT0FRlkRQ== - dependencies: - base64-js "^1.2.3" - xmlbuilder "^9.0.7" - xmldom "0.1.x" - pn@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/pn/-/pn-1.1.0.tgz#e2f4cef0e219f463c179ab37463e4e1ecdccbafb" @@ -17767,7 +17733,7 @@ xml2js@^0.4.17: sax ">=0.6.0" xmlbuilder "~9.0.1" -xmlbuilder@^9.0.7, xmlbuilder@~9.0.1: +xmlbuilder@~9.0.1: version "9.0.7" resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-9.0.7.tgz#132ee63d2ec5565c557e20f4c22df9aca686b10d" integrity sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0= @@ -17777,11 +17743,6 @@ xmlchars@^1.3.1: resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-1.3.1.tgz#1dda035f833dbb4f86a0c28eaa6ca769214793cf" integrity sha512-tGkGJkN8XqCod7OT+EvGYK5Z4SfDQGD30zAa58OcnAa0RRWgzUEK72tkXhsX1FZd+rgnhRxFtmO+ihkp8LHSkw== -xmldom@0.1.x: - version "0.1.27" - resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.1.27.tgz#d501f97b3bdb403af8ef9ecc20573187aadac0e9" - integrity sha1-1QH5ezvbQDr4757MIFcxh6rawOk= - xregexp@4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/xregexp/-/xregexp-4.0.0.tgz#e698189de49dd2a18cc5687b05e17c8e43943020" @@ -17843,7 +17804,7 @@ yargs-parser@^11.1.1: camelcase "^5.0.0" decamelize "^1.2.0" -yargs-parser@^13.1.0: +yargs-parser@^13.1.0, yargs-parser@^13.1.1: version "13.1.1" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.1.tgz#d26058532aa06d365fe091f6a1fc06b2f7e5eca0" integrity sha512-oVAVsHz6uFrg3XQheFII8ESO2ssAf9luWuAd6Wexsu4F3OtIW0o8IribPXYrD4WC24LWtPrJlGy87y5udK+dxQ== @@ -17894,7 +17855,7 @@ yargs@^12.0.1, yargs@^12.0.2: y18n "^3.2.1 || ^4.0.0" yargs-parser "^11.1.1" -yargs@^13.0.0, yargs@^13.2.1, yargs@^13.2.4: +yargs@^13.0.0, yargs@^13.2.1: version "13.2.4" resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.2.4.tgz#0b562b794016eb9651b98bd37acf364aa5d6dc83" integrity sha512-HG/DWAJa1PAnHT9JAhNa8AbAv3FPaiLzioSjCcmuXXhP8MlpHO5vwls4g4j6n30Z74GVQj8Xa62dWVx1QCGklg== @@ -17911,6 +17872,22 @@ yargs@^13.0.0, yargs@^13.2.1, yargs@^13.2.4: y18n "^4.0.0" yargs-parser "^13.1.0" +yargs@^13.3.0: + version "13.3.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.3.0.tgz#4c657a55e07e5f2cf947f8a366567c04a0dedc83" + integrity sha512-2eehun/8ALW8TLoIl7MVaRUrg+yCnenu8B4kBlRxj3GJGDKU1Og7sMXPNm1BYyM1DOJmTZ4YeN/Nwxv+8XJsUA== + dependencies: + cliui "^5.0.0" + find-up "^3.0.0" + get-caller-file "^2.0.1" + require-directory "^2.1.1" + require-main-filename "^2.0.0" + set-blocking "^2.0.0" + string-width "^3.0.0" + which-module "^2.0.0" + y18n "^4.0.0" + yargs-parser "^13.1.1" + yargs@^7.0.0: version "7.1.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-7.1.0.tgz#6ba318eb16961727f5d284f8ea003e8d6154d0c8" From 284c4a6896dd8a258078c923300ae690561682f1 Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 19 Jul 2019 12:40:25 +0800 Subject: [PATCH 5/9] feat(neuron-ui): use empty keywords for searching on switching wallet --- .../neuron-ui/src/components/History/hooks.ts | 2 +- .../src/components/History/index.tsx | 9 +++++-- .../src/components/Receive/index.tsx | 2 +- .../neuron-ui/src/containers/Main/hooks.ts | 24 +++++++------------ .../neuron-ui/src/containers/Main/index.tsx | 13 +++++++--- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/packages/neuron-ui/src/components/History/hooks.ts b/packages/neuron-ui/src/components/History/hooks.ts index 16f7534a79..a8dff387a5 100644 --- a/packages/neuron-ui/src/components/History/hooks.ts +++ b/packages/neuron-ui/src/components/History/hooks.ts @@ -34,7 +34,7 @@ export const useSearch = (search: string = '', walletID: string = '', dispatch: dispatch(actionCreators.getTransactions({ ...params, keywords: params.keywords, walletID })) }, [search, walletID, dispatch]) - return { keywords, onKeywordsChange } + return { keywords, onKeywordsChange, setKeywords } } export default { diff --git a/packages/neuron-ui/src/components/History/index.tsx b/packages/neuron-ui/src/components/History/index.tsx index 65587610d9..72ace147d6 100644 --- a/packages/neuron-ui/src/components/History/index.tsx +++ b/packages/neuron-ui/src/components/History/index.tsx @@ -1,4 +1,4 @@ -import React, { useCallback } from 'react' +import React, { useCallback, useEffect } from 'react' import { RouteComponentProps } from 'react-router-dom' import { useTranslation } from 'react-i18next' import { Stack, SearchBox, getTheme } from 'office-ui-fabric-react' @@ -42,7 +42,12 @@ const History = ({ }: React.PropsWithoutRef) => { const [t] = useTranslation() - const { keywords, onKeywordsChange } = useSearch(search, id, dispatch) + const { keywords, onKeywordsChange, setKeywords } = useSearch(search, id, dispatch) + useEffect(() => { + if (id) { + setKeywords('') + } + }, [id, setKeywords]) const onSearch = useCallback(() => history.push(`${Routes.History}?keywords=${keywords}`), [history, keywords]) return ( diff --git a/packages/neuron-ui/src/components/Receive/index.tsx b/packages/neuron-ui/src/components/Receive/index.tsx index e5e27d3047..8da7f2166b 100644 --- a/packages/neuron-ui/src/components/Receive/index.tsx +++ b/packages/neuron-ui/src/components/Receive/index.tsx @@ -78,7 +78,7 @@ const Receive = ({ {t('receive.address-qrcode')} - + diff --git a/packages/neuron-ui/src/containers/Main/hooks.ts b/packages/neuron-ui/src/containers/Main/hooks.ts index 5780162996..b7a39dd958 100644 --- a/packages/neuron-ui/src/containers/Main/hooks.ts +++ b/packages/neuron-ui/src/containers/Main/hooks.ts @@ -484,12 +484,15 @@ export const useSyncChainData = ({ chainURL, dispatch }: { chainURL: string; dis export const useOnCurrentWalletChange = ({ walletID, - chain, + pageNo, + pageSize, dispatch, history, }: { walletID: string - chain: State.Chain + pageNo: number + pageSize: number + dispatch: StateDispatch history: any }) => { @@ -498,11 +501,10 @@ export const useOnCurrentWalletChange = ({ walletsCall.getAllAddresses(walletID) transactionsCall.getAllByKeywords({ walletID, - keywords: chain.transactions.keywords, - pageNo: chain.transactions.pageNo, - pageSize: chain.transactions.pageSize, + keywords: '', + pageNo, + pageSize, }) - transactionsCall.get(walletID, chain.transaction.hash) } else { history.push(`${Routes.WalletWizard}${WalletWizardPath.Welcome}`) dispatch({ @@ -510,15 +512,7 @@ export const useOnCurrentWalletChange = ({ payload: initStates.wallet, }) } - }, [ - walletID, - chain.transactions.pageNo, - chain.transactions.pageSize, - chain.transactions.keywords, - chain.transaction.hash, - dispatch, - history, - ]) + }, [walletID, pageNo, pageSize, dispatch, history]) } export default { diff --git a/packages/neuron-ui/src/containers/Main/index.tsx b/packages/neuron-ui/src/containers/Main/index.tsx index 60d273c60d..e7e2c7ce5c 100644 --- a/packages/neuron-ui/src/containers/Main/index.tsx +++ b/packages/neuron-ui/src/containers/Main/index.tsx @@ -108,7 +108,11 @@ const MainContent = ({ }: React.PropsWithoutRef<{ dispatch: StateDispatch } & RouteComponentProps>) => { const neuronWalletState = useState() const { - chain: { networkID }, + wallet: { id: walletID }, + chain: { + networkID, + transactions: { pageNo, pageSize }, + }, settings: { networks }, } = neuronWalletState const [, i18n] = useTranslation() @@ -129,12 +133,15 @@ const MainContent = ({ chainURL, dispatch, }) + useOnCurrentWalletChange({ - walletID: neuronWalletState.wallet.id, - chain: neuronWalletState.chain, + walletID, + pageNo, + pageSize, dispatch, history, }) + return ( <> {mainContents.map(container => ( From 9794da033eb75acc5fb866e5ba3b0ad06fda4cb0 Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 19 Jul 2019 12:58:39 +0800 Subject: [PATCH 6/9] feat(neuron-wallet): use sample time to limit current block number messages --- .../src/models/subjects/current-block-subject.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/neuron-wallet/src/models/subjects/current-block-subject.ts b/packages/neuron-wallet/src/models/subjects/current-block-subject.ts index 69e5107b9b..d2e653fc07 100644 --- a/packages/neuron-wallet/src/models/subjects/current-block-subject.ts +++ b/packages/neuron-wallet/src/models/subjects/current-block-subject.ts @@ -1,5 +1,5 @@ import { ReplaySubject } from 'rxjs' -import { debounceTime } from 'rxjs/operators' +import { sampleTime } from 'rxjs/operators' import windowManager from '../window-manager' import { Channel, ResponseCode } from '../../utils/const' @@ -16,7 +16,7 @@ export class CurrentBlockSubject { } static subscribe() { - CurrentBlockSubject.subject.pipe(debounceTime(500)).subscribe(({ blockNumber }) => { + CurrentBlockSubject.subject.pipe(sampleTime(500)).subscribe(({ blockNumber }) => { windowManager.broadcast(Channel.Chain, 'tipBlockNumber', { status: ResponseCode.Success, result: blockNumber, From 5cde976fa77fde5cc81ab022e4d377e271f57d27 Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 19 Jul 2019 13:04:46 +0800 Subject: [PATCH 7/9] feat(neuron-wallet): initialize the synced block number by the sync info controller --- .../neuron-wallet/src/controllers/app/index.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/neuron-wallet/src/controllers/app/index.ts b/packages/neuron-wallet/src/controllers/app/index.ts index 4965557955..3c79ddb643 100644 --- a/packages/neuron-wallet/src/controllers/app/index.ts +++ b/packages/neuron-wallet/src/controllers/app/index.ts @@ -9,6 +9,7 @@ import NetworksService from '../../services/networks' import WalletsService from '../../services/wallets' import NodeService from '../../services/node' import WalletsController from '../wallets' +import SyncInfoController from '../sync-info' import { Controller as ControllerDecorator } from '../../decorators' import { Channel, ResponseCode } from '../../utils/const' @@ -35,16 +36,14 @@ export default class AppController { walletsService.getAll(), networksService.getCurrentID(), networksService.getAll(), - new Promise(resolve => { - nodeService.tipNumberSubject.pipe(take(1)).subscribe( - tipNum => { - resolve(tipNum || '0') - }, - () => { - resolve('0') + SyncInfoController.currentBlockNumber() + .then(res => { + if (res.status) { + return res.result.currentBlockNumber } - ) - }), + return '0' + }) + .catch(() => '0'), new Promise(resolve => { nodeService.connectStatusSubject.pipe(take(1)).subscribe( status => { From ac554525b0fb689afb3938961f1dfd241a9de6b3 Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 19 Jul 2019 13:15:26 +0800 Subject: [PATCH 8/9] feat(neuron-wallet): send connection status to the neuron-ui periodically the interval keeps the same as that in the neuron-ui, namely 10s --- packages/neuron-wallet/src/services/node.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/neuron-wallet/src/services/node.ts b/packages/neuron-wallet/src/services/node.ts index 7ec9d6aa35..bd000178e7 100644 --- a/packages/neuron-wallet/src/services/node.ts +++ b/packages/neuron-wallet/src/services/node.ts @@ -1,6 +1,6 @@ import Core from '@nervosnetwork/ckb-sdk-core' import { interval, BehaviorSubject } from 'rxjs' -import { distinctUntilChanged, flatMap, delay, retry } from 'rxjs/operators' +import { distinctUntilChanged, sampleTime, flatMap, delay, retry } from 'rxjs/operators' import { ShouldBeTypeOf } from '../exceptions' import windowManager from '../models/window-manager' import { Channel, ResponseCode } from '../utils/const' @@ -28,7 +28,7 @@ class NodeService { } public syncConnectStatus = () => { - this.connectStatusSubject.pipe(distinctUntilChanged()).subscribe(connectStatus => { + this.connectStatusSubject.pipe(sampleTime(10000)).subscribe(connectStatus => { windowManager.broadcast(Channel.Chain, 'status', { status: ResponseCode.Success, result: connectStatus, From f8a9d84b2e3f6bf3ec509202ec6718bfe11d95a2 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 19 Jul 2019 14:27:00 +0900 Subject: [PATCH 9/9] chore: Pre-release v0.1.0-alpha.12 --- lerna.json | 2 +- package.json | 2 +- packages/neuron-ui/package.json | 2 +- packages/neuron-wallet/package.json | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lerna.json b/lerna.json index 7e6d00eea6..5ce258a91b 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "packages": [ "packages/*" ], - "version": "0.1.0-alpha.11", + "version": "0.1.0-alpha.12", "npmClient": "yarn", "useWorkspaces": true } diff --git a/package.json b/package.json index cfffce52f7..88c965bd62 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@nervosnetwork/neuron", "productName": "Neuron", "description": "CKB Neuron Wallet", - "version": "0.1.0-alpha.11", + "version": "0.1.0-alpha.12", "private": true, "author": { "name": "Nervos Core Dev", diff --git a/packages/neuron-ui/package.json b/packages/neuron-ui/package.json index 6fdbbdbcc3..4ac189ad9b 100644 --- a/packages/neuron-ui/package.json +++ b/packages/neuron-ui/package.json @@ -1,6 +1,6 @@ { "name": "@nervosnetwork/neuron-ui", - "version": "0.1.0-alpha.11", + "version": "0.1.0-alpha.12", "private": true, "author": { "name": "Nervos Core Dev", diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index 60cb972af9..e71bf02019 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.1.0-alpha.11", + "version": "0.1.0-alpha.12", "private": true, "author": { "name": "Nervos Core Dev", @@ -48,7 +48,7 @@ }, "devDependencies": { "@nervosnetwork/ckb-types": "0.15.1", - "@nervosnetwork/neuron-ui": "0.1.0-alpha.11", + "@nervosnetwork/neuron-ui": "0.1.0-alpha.12", "@types/async": "3.0.0", "@types/electron-devtools-installer": "2.2.0", "@types/elliptic": "6.4.8",