From 513c7d90ddeabe3d8e1052003e9a919939620b90 Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 27 Sep 2019 14:37:45 +0800 Subject: [PATCH 01/14] feat(neuron-ui): extend the width of tx type field to 70 px --- packages/neuron-ui/src/components/TransactionList/index.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/neuron-ui/src/components/TransactionList/index.tsx b/packages/neuron-ui/src/components/TransactionList/index.tsx index 066de40167..bff553535e 100644 --- a/packages/neuron-ui/src/components/TransactionList/index.tsx +++ b/packages/neuron-ui/src/components/TransactionList/index.tsx @@ -28,8 +28,6 @@ import { CONFIRMATION_THRESHOLD } from 'utils/const' const theme = getTheme() const { semanticColors } = theme -const MIN_CELL_WIDTH = 50 - interface FormatTransaction extends State.Transaction { date: string } @@ -82,8 +80,8 @@ const TransactionList = ({ name: t('history.type'), key: 'type', fieldName: 'type', - minWidth: MIN_CELL_WIDTH, - maxWidth: 50, + minWidth: 70, + maxWidth: 70, onRender: (item?: FormatTransaction) => { if (!item) { return null From 6b3952f07ea9b4eade41f350dcdb0285cacd453a Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 27 Sep 2019 15:39:52 +0800 Subject: [PATCH 02/14] feat: enable copy the mainnet addresses when it's not connected to the mainnet --- .../src/components/Addresses/index.tsx | 4 +++- .../neuron-wallet/src/controllers/app/index.ts | 1 + .../src/controllers/app/options.ts | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/neuron-ui/src/components/Addresses/index.tsx b/packages/neuron-ui/src/components/Addresses/index.tsx index 37be5124b0..ca19dc38d6 100644 --- a/packages/neuron-ui/src/components/Addresses/index.tsx +++ b/packages/neuron-ui/src/components/Addresses/index.tsx @@ -204,7 +204,9 @@ const Addresses = ({ : addr.address, }))} onItemContextMenu={item => { - if (!showMainnetAddress) { + if (showMainnetAddress) { + contextMenu({ type: 'copyMainnetAddress', id: item.identifier }) + } else { contextMenu({ type: 'addressList', id: item.identifier }) } }} diff --git a/packages/neuron-wallet/src/controllers/app/index.ts b/packages/neuron-wallet/src/controllers/app/index.ts index e56f17078d..7d823ec7af 100644 --- a/packages/neuron-wallet/src/controllers/app/index.ts +++ b/packages/neuron-wallet/src/controllers/app/index.ts @@ -158,6 +158,7 @@ export default class AppController { } const { id, type } = params switch (type) { + case 'copyMainnetAddress': case 'networkList': case 'walletList': case 'addressList': diff --git a/packages/neuron-wallet/src/controllers/app/options.ts b/packages/neuron-wallet/src/controllers/app/options.ts index 1d337d6b57..06f17c6009 100644 --- a/packages/neuron-wallet/src/controllers/app/options.ts +++ b/packages/neuron-wallet/src/controllers/app/options.ts @@ -1,5 +1,5 @@ import { MenuItemConstructorOptions, clipboard, dialog, MessageBoxReturnValue } from 'electron' -import { bech32Address } from '@nervosnetwork/ckb-sdk-utils' +import { bech32Address, AddressPrefix, AddressType } from '@nervosnetwork/ckb-sdk-utils' import WalletsService from 'services/wallets' import NetworksService from 'services/networks' @@ -19,6 +19,21 @@ const networksService = NetworksService.getInstance() export const contextMenuTemplate: { [key: string]: (id: string) => Promise } = { + copyMainnetAddress: async (identifier: string) => { + const address = bech32Address(identifier, { + prefix: AddressPrefix.Mainnet, + type: AddressType.HashIdx, + codeHashIndex: '0x00', + }) + return [ + { + label: i18n.t('contextMenu.copy-address'), + click: () => { + clipboard.writeText(address) + }, + }, + ] + }, networkList: async (id: string) => { const [network, currentNetworkID] = await Promise.all([ networksService.get(id).catch(() => null), From 04b11765691882238bbee563b213025d6e9c5168 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Fri, 27 Sep 2019 17:07:49 +0800 Subject: [PATCH 03/14] fix: change `hasData` to 0 in `output` --- packages/neuron-wallet/src/database/chain/ormconfig.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/neuron-wallet/src/database/chain/ormconfig.ts b/packages/neuron-wallet/src/database/chain/ormconfig.ts index af68e415ed..f054f9dc59 100644 --- a/packages/neuron-wallet/src/database/chain/ormconfig.ts +++ b/packages/neuron-wallet/src/database/chain/ormconfig.ts @@ -11,6 +11,7 @@ import Output from './entities/output' import SyncInfo from './entities/sync-info' import { InitMigration1566959757554 } from './migrations/1566959757554-InitMigration' import { AddTypeAndHasData1567144517514 } from './migrations/1567144517514-AddTypeAndHasData' +import { ChangeHasDataDefault1568621556467 } from './migrations/1568621556467-ChangeHasDataDefault' export const CONNECTION_NOT_FOUND_NAME = 'ConnectionNotFoundError' @@ -31,7 +32,7 @@ const connectOptions = async (genesisBlockHash: string): Promise Date: Sun, 29 Sep 2019 12:06:38 +0800 Subject: [PATCH 04/14] feat(neuron-ui): add a toggle of skip-data-and-type --- .../src/components/Addresses/index.tsx | 5 +++- .../src/components/GeneralSetting/index.tsx | 27 ++++++++++++++----- .../neuron-ui/src/containers/Navbar/index.tsx | 5 +++- packages/neuron-ui/src/locales/en.json | 1 + packages/neuron-ui/src/locales/zh.json | 1 + .../neuron-ui/src/services/remote/index.ts | 1 + .../src/services/remote/skipDataAndType.ts | 11 ++++++++ .../src/states/initStates/settings.ts | 5 +++- .../stateProvider/actionCreators/app.ts | 2 ++ .../stateProvider/actionCreators/index.ts | 3 +++ .../actionCreators/skipDataAndType.ts | 21 +++++++++++++++ .../src/states/stateProvider/reducer.ts | 25 +++++++++++++++-- packages/neuron-ui/src/types/App/index.d.ts | 5 +++- .../neuron-ui/src/types/Controller/index.d.ts | 1 + .../src/controllers/app/index.ts | 11 +++++--- .../neuron-wallet/src/controllers/index.ts | 2 ++ 16 files changed, 110 insertions(+), 16 deletions(-) create mode 100644 packages/neuron-ui/src/services/remote/skipDataAndType.ts create mode 100644 packages/neuron-ui/src/states/stateProvider/actionCreators/skipDataAndType.ts diff --git a/packages/neuron-ui/src/components/Addresses/index.tsx b/packages/neuron-ui/src/components/Addresses/index.tsx index ca19dc38d6..4302ba02b5 100644 --- a/packages/neuron-ui/src/components/Addresses/index.tsx +++ b/packages/neuron-ui/src/components/Addresses/index.tsx @@ -28,7 +28,10 @@ const Addresses = ({ }, wallet: { addresses = [], id: walletID }, chain: { networkID }, - settings: { showAddressBook = false, networks = [] }, + settings: { + general: { showAddressBook = false }, + networks = [], + }, history, dispatch, }: React.PropsWithoutRef) => { diff --git a/packages/neuron-ui/src/components/GeneralSetting/index.tsx b/packages/neuron-ui/src/components/GeneralSetting/index.tsx index bb82bc081b..3fc11cef16 100644 --- a/packages/neuron-ui/src/components/GeneralSetting/index.tsx +++ b/packages/neuron-ui/src/components/GeneralSetting/index.tsx @@ -1,15 +1,21 @@ -import React, { useCallback } from 'react' +import React, { useMemo } from 'react' import { Stack, Toggle } from 'office-ui-fabric-react' import { useTranslation } from 'react-i18next' import { StateWithDispatch } from 'states/stateProvider/reducer' -import { toggleAddressBook } from 'states/stateProvider/actionCreators' +import { toggleAddressBook, setSkipDataAndType } from 'states/stateProvider/actionCreators' -const GeneralSetting = ({ settings: { showAddressBook }, dispatch }: React.PropsWithoutRef) => { +const GeneralSetting = ({ + settings: { + general: { showAddressBook, skipDataAndType }, + }, + dispatch, +}: React.PropsWithoutRef) => { const [t] = useTranslation() - const onToggle = useCallback(() => { - dispatch(toggleAddressBook()) - }, [dispatch]) + const [onToggleAddressVisibility, onSetSkipDataAndType] = useMemo( + () => [() => dispatch(toggleAddressBook()), () => setSkipDataAndType(!skipDataAndType)(dispatch)], + [dispatch, skipDataAndType] + ) return ( + ) diff --git a/packages/neuron-ui/src/containers/Navbar/index.tsx b/packages/neuron-ui/src/containers/Navbar/index.tsx index a0ecd8a783..0cbf38b4e1 100644 --- a/packages/neuron-ui/src/containers/Navbar/index.tsx +++ b/packages/neuron-ui/src/containers/Navbar/index.tsx @@ -42,7 +42,10 @@ const Navbar = ({ }: React.PropsWithoutRef) => { const neuronWallet = useState() const { - settings: { wallets = [], showAddressBook = false }, + settings: { + wallets = [], + general: { showAddressBook = false }, + }, } = neuronWallet const [t] = useTranslation() diff --git a/packages/neuron-ui/src/locales/en.json b/packages/neuron-ui/src/locales/en.json index eac2b562a3..c64691cfe7 100644 --- a/packages/neuron-ui/src/locales/en.json +++ b/packages/neuron-ui/src/locales/en.json @@ -164,6 +164,7 @@ }, "general": { "display-address-book-in-the-navbar": "Show the address book", + "skip-data-and-type": "Skip the cells which contain data or type script", "show": "Show", "hide": "Hide" }, diff --git a/packages/neuron-ui/src/locales/zh.json b/packages/neuron-ui/src/locales/zh.json index 68bfad858c..9b8136feb8 100644 --- a/packages/neuron-ui/src/locales/zh.json +++ b/packages/neuron-ui/src/locales/zh.json @@ -164,6 +164,7 @@ }, "general": { "display-address-book-in-the-navbar": "显示地址簿", + "skip-data-and-type": "忽略包含 Data 或 Type Script 的 Cell", "show": "显示", "hide": "隐藏" }, diff --git a/packages/neuron-ui/src/services/remote/index.ts b/packages/neuron-ui/src/services/remote/index.ts index fff8b2c7ca..36802546db 100644 --- a/packages/neuron-ui/src/services/remote/index.ts +++ b/packages/neuron-ui/src/services/remote/index.ts @@ -2,6 +2,7 @@ export * from './app' export * from './wallets' export * from './networks' export * from './transactions' +export * from './skipDataAndType' export const getLocale = () => { if (!window.remote) { diff --git a/packages/neuron-ui/src/services/remote/skipDataAndType.ts b/packages/neuron-ui/src/services/remote/skipDataAndType.ts new file mode 100644 index 0000000000..bad9e87889 --- /dev/null +++ b/packages/neuron-ui/src/services/remote/skipDataAndType.ts @@ -0,0 +1,11 @@ +import { controllerMethodWrapper } from './controllerMethodWrapper' + +const CONTROLLER_NAME = 'skip-data-and-type' + +export const setSkipDataAndType = controllerMethodWrapper(CONTROLLER_NAME)( + (controller: any) => (params: Controller.SetSkipAndTypeParam) => { + return controller.update(params) + } +) + +export default { setSkipDataAndType } diff --git a/packages/neuron-ui/src/states/initStates/settings.ts b/packages/neuron-ui/src/states/initStates/settings.ts index 87865b4d89..27058778e5 100644 --- a/packages/neuron-ui/src/states/initStates/settings.ts +++ b/packages/neuron-ui/src/states/initStates/settings.ts @@ -1,7 +1,10 @@ import { addressBook, wallets, networks } from 'services/localCache' export const settingsState: State.Settings = { - showAddressBook: addressBook.isVisible(), + general: { + skipDataAndType: false, + showAddressBook: addressBook.isVisible(), + }, networks: networks.load(), wallets: wallets.load(), } diff --git a/packages/neuron-ui/src/states/stateProvider/actionCreators/app.ts b/packages/neuron-ui/src/states/stateProvider/actionCreators/app.ts index 8459153c57..a517ad397e 100644 --- a/packages/neuron-ui/src/states/stateProvider/actionCreators/app.ts +++ b/packages/neuron-ui/src/states/stateProvider/actionCreators/app.ts @@ -26,6 +26,7 @@ export const initAppState = () => (dispatch: StateDispatch, history: any) => { syncedBlockNumber = '', connectionStatus = false, codeHash = '', + skipDataAndType = false, } = res.result dispatch({ type: NeuronWalletActions.InitAppState, @@ -38,6 +39,7 @@ export const initAppState = () => (dispatch: StateDispatch, history: any) => { syncedBlockNumber, connectionStatus, codeHash, + skipDataAndType, }, }) if (!wallet) { diff --git a/packages/neuron-ui/src/states/stateProvider/actionCreators/index.ts b/packages/neuron-ui/src/states/stateProvider/actionCreators/index.ts index b1ea341f64..bb72ba1655 100644 --- a/packages/neuron-ui/src/states/stateProvider/actionCreators/index.ts +++ b/packages/neuron-ui/src/states/stateProvider/actionCreators/index.ts @@ -2,16 +2,19 @@ import app from './app' import wallets from './wallets' import transactions from './transactions' import settings from './settings' +import skipDataAndType from './skipDataAndType' export * from './app' export * from './wallets' export * from './transactions' export * from './settings' +export * from './skipDataAndType' export const actionCreators = { ...app, ...wallets, ...transactions, ...settings, + ...skipDataAndType, } export default actionCreators diff --git a/packages/neuron-ui/src/states/stateProvider/actionCreators/skipDataAndType.ts b/packages/neuron-ui/src/states/stateProvider/actionCreators/skipDataAndType.ts new file mode 100644 index 0000000000..712613d89f --- /dev/null +++ b/packages/neuron-ui/src/states/stateProvider/actionCreators/skipDataAndType.ts @@ -0,0 +1,21 @@ +import { setSkipDataAndType as setRemoteSkipDataAndType } from 'services/remote' +import { failureResToNotification } from 'utils/formatters' +import { StateDispatch, NeuronWalletActions } from '../reducer' +import { addNotification } from './app' + +export const setSkipDataAndType = (skip: Controller.SetSkipAndTypeParam) => (dispatch: StateDispatch) => { + setRemoteSkipDataAndType(skip).then(res => { + if (res.status === 1) { + dispatch({ + type: NeuronWalletActions.UpdateSkipDataAndType, + payload: res.result, + }) + } else { + addNotification(failureResToNotification(res))(dispatch) + } + }) +} + +export default { + setSkipDataAndType, +} diff --git a/packages/neuron-ui/src/states/stateProvider/reducer.ts b/packages/neuron-ui/src/states/stateProvider/reducer.ts index b5e3f86e45..9012980aed 100644 --- a/packages/neuron-ui/src/states/stateProvider/reducer.ts +++ b/packages/neuron-ui/src/states/stateProvider/reducer.ts @@ -18,6 +18,8 @@ export enum NeuronWalletActions { // Connection UpdateConnectionStatus = 'updateConnectionStatus', UpdateSyncedBlockNumber = 'updateSyncedBlockNumber', + // settings + UpdateSkipDataAndType = 'updateSkipDataAndType', } export enum AppActions { ToggleAddressBookVisibility = 'toggleAddressBookVisibility', @@ -77,6 +79,7 @@ export const reducer = ( syncedBlockNumber, connectionStatus, codeHash, + skipDataAndType, } = payload return { ...state, @@ -90,7 +93,10 @@ export const reducer = ( tipBlockNumber: syncedBlockNumber, }, settings: { - ...state.settings, + general: { + ...state.settings.general, + skipDataAndType, + }, networks, wallets, }, @@ -101,7 +107,22 @@ export const reducer = ( ...state, settings: { ...settings, - showAddressBook: !settings.showAddressBook, + general: { + ...settings.general, + showAddressBook: !settings.general.showAddressBook, + }, + }, + } + } + case NeuronWalletActions.UpdateSkipDataAndType: { + return { + ...state, + settings: { + ...settings, + general: { + ...settings.general, + skipDataAndType: payload, + }, }, } } diff --git a/packages/neuron-ui/src/types/App/index.d.ts b/packages/neuron-ui/src/types/App/index.d.ts index 44725f33ef..b38d199b9a 100644 --- a/packages/neuron-ui/src/types/App/index.d.ts +++ b/packages/neuron-ui/src/types/App/index.d.ts @@ -139,7 +139,10 @@ declare namespace State { } } interface Settings { - showAddressBook: boolean + general: { + skipDataAndType: boolean + showAddressBook: boolean + } networks: Network[] wallets: WalletIdentity[] } diff --git a/packages/neuron-ui/src/types/Controller/index.d.ts b/packages/neuron-ui/src/types/Controller/index.d.ts index a9756b785d..5f1f5ae489 100644 --- a/packages/neuron-ui/src/types/Controller/index.d.ts +++ b/packages/neuron-ui/src/types/Controller/index.d.ts @@ -70,4 +70,5 @@ declare namespace Controller { hash: string description: string } + type SetSkipAndTypeParam = boolean } diff --git a/packages/neuron-wallet/src/controllers/app/index.ts b/packages/neuron-wallet/src/controllers/app/index.ts index 7d823ec7af..b6bbc6789a 100644 --- a/packages/neuron-wallet/src/controllers/app/index.ts +++ b/packages/neuron-wallet/src/controllers/app/index.ts @@ -19,6 +19,7 @@ import WalletsService from 'services/wallets' import WalletsController from 'controllers/wallets' import SyncInfoController from 'controllers/sync-info' import UpdateController from 'controllers/update' +import SkipDataAndType from 'services/settings/skip-data-and-type' import { ResponseCode } from 'utils/const' import WindowManager from 'models/window-manager' @@ -63,7 +64,7 @@ export default class AppController { }, () => { resolve(false) - } + }, ) }), new Promise(resolve => { @@ -84,8 +85,8 @@ export default class AppController { } } return undefined - }) - ) + }), + ), ) const addresses: Controller.Address[] = await (currentWallet ? WalletsController.getAllAddresses(currentWallet.id).then(res => res.result) @@ -99,6 +100,9 @@ export default class AppController { walletID: currentWallet.id, }).then(res => res.result) : [] + + const skipDataAndType = SkipDataAndType.getInstance().get() + const initState = { currentWallet, wallets: [...wallets.map(({ name, id }, idx: number) => ({ id, name, minerAddress: minerAddresses[idx] }))], @@ -109,6 +113,7 @@ export default class AppController { syncedBlockNumber, connectionStatus, codeHash, + skipDataAndType, } return { status: ResponseCode.Success, result: initState } diff --git a/packages/neuron-wallet/src/controllers/index.ts b/packages/neuron-wallet/src/controllers/index.ts index 600f3d2981..847c7d5ccf 100644 --- a/packages/neuron-wallet/src/controllers/index.ts +++ b/packages/neuron-wallet/src/controllers/index.ts @@ -3,6 +3,7 @@ import NetworksController from './networks' import WalletsController from './wallets' import TransactionsController from './transactions' import SyncInfoController from './sync-info' +import SkipDataAndTypeController from './skip-data-and-type' export default { AppController, @@ -10,4 +11,5 @@ export default { WalletsController, TransactionsController, SyncInfoController, + SkipDataAndTypeController, } From a79b7804a58c7f544f48b1b92a493c4be581fdbc Mon Sep 17 00:00:00 2001 From: Keith Date: Sun, 29 Sep 2019 13:51:27 +0800 Subject: [PATCH 05/14] test(e2e): add tests of general settings --- packages/neuron-wallet/tests-e2e/main.test.ts | 7 ++++ .../tests-e2e/tests/generalSettings.ts | 40 +++++++++++++++++++ .../neuron-wallet/tests-e2e/tests/index.ts | 2 + 3 files changed, 49 insertions(+) create mode 100644 packages/neuron-wallet/tests-e2e/tests/generalSettings.ts diff --git a/packages/neuron-wallet/tests-e2e/main.test.ts b/packages/neuron-wallet/tests-e2e/main.test.ts index e6d0abe04a..8fec129977 100644 --- a/packages/neuron-wallet/tests-e2e/main.test.ts +++ b/packages/neuron-wallet/tests-e2e/main.test.ts @@ -45,3 +45,10 @@ describe('Test address book', () => { afterAll(() => app.stop()) tests.AddressBook(app) }) + +describe('Test general settings', () => { + let app = new Application() + beforeAll(() => app.start()) + afterAll(() => app.stop()) + tests.GeneralSettings(app) +}) diff --git a/packages/neuron-wallet/tests-e2e/tests/generalSettings.ts b/packages/neuron-wallet/tests-e2e/tests/generalSettings.ts new file mode 100644 index 0000000000..e2c9582416 --- /dev/null +++ b/packages/neuron-wallet/tests-e2e/tests/generalSettings.ts @@ -0,0 +1,40 @@ +import Application from '../application' + +/** + * 1. navigate to the general settings handleViewError + * 2. the toggle of address book and skip data and type script should be off + * 3. click on the toggles and their statuses should be updated + * 4. refresh the view and the statuses should be preserved + */ +export default (app: Application) => { + beforeAll(async () => { + app.clickMenu(['Electron', 'Preferences...']) + await app.waitUntilLoaded() + }) + + describe('Test general settings', () => { + app.test('Check the initialized statuses', async () => { + const { client } = app.spectron + const toggles = await client.$$('button[role=switch]') + expect(toggles).toHaveLength(2) + expect((await client.elementIdAttribute(toggles[0].value.ELEMENT, 'aria-checked')).value).toBe('false') + expect((await client.elementIdAttribute(toggles[1].value.ELEMENT, 'aria-checked')).value).toBe('true') + }) + + app.test('toggle AddressBook to true and SkipDataAndType to false', async () => { + const { client } = app.spectron + await app.waitUntilLoaded() + const toggles = await client.$$('button[role=switch]') + + toggles.forEach((_, idx) => { + client.elementIdClick(toggles[idx].value.ELEMENT) + }) + + await app.waitUntilLoaded() + expect((await client.elementIdAttribute(toggles[0].value.ELEMENT, 'aria-checked')).value).toBe('true') + expect((await client.elementIdAttribute(toggles[1].value.ELEMENT, 'aria-checked')).value).toBe('false') + }) + + test.skip('Toggle statuses should be preserved', async () => {}) + }) +} diff --git a/packages/neuron-wallet/tests-e2e/tests/index.ts b/packages/neuron-wallet/tests-e2e/tests/index.ts index b9b2a1193a..d434fd4d39 100644 --- a/packages/neuron-wallet/tests-e2e/tests/index.ts +++ b/packages/neuron-wallet/tests-e2e/tests/index.ts @@ -4,6 +4,7 @@ import Transaction from './transaction' import SendTransaction from './sendTransaction' import Notification from './notification' import AddressBook from './addressBook' +import GeneralSettings from './generalSettings' export default { Wallet, @@ -12,4 +13,5 @@ export default { SendTransaction, Notification, AddressBook, + GeneralSettings, } From ca38b4034ee1888717f2c10b8c23798b10d9a4d7 Mon Sep 17 00:00:00 2001 From: Chen Yu Date: Mon, 30 Sep 2019 10:24:53 +0800 Subject: [PATCH 06/14] feat(neuron-ui): update the view of transaction detail (#965) * feat(neuron-ui): update the view of transaction detail * Update packages/neuron-ui/src/locales/en.json Co-Authored-By: James Chen --- .../src/components/Addresses/index.tsx | 2 +- .../src/components/Transaction/index.tsx | 310 ++++++++++++------ .../components/Transaction/style.module.scss | 38 +++ packages/neuron-ui/src/locales/en.json | 13 +- packages/neuron-ui/src/locales/zh.json | 13 +- .../neuron-ui/src/services/remote/index.ts | 9 + .../neuron-ui/src/services/remote/networks.ts | 10 + .../neuron-ui/src/states/initStates/chain.ts | 2 + packages/neuron-ui/src/styles/index.scss | 9 +- packages/neuron-ui/src/theme.tsx | 2 + packages/neuron-ui/src/types/App/index.d.ts | 2 + .../src/controllers/transactions.ts | 26 +- 12 files changed, 314 insertions(+), 122 deletions(-) create mode 100644 packages/neuron-ui/src/components/Transaction/style.module.scss diff --git a/packages/neuron-ui/src/components/Addresses/index.tsx b/packages/neuron-ui/src/components/Addresses/index.tsx index 4302ba02b5..e37238c0f9 100644 --- a/packages/neuron-ui/src/components/Addresses/index.tsx +++ b/packages/neuron-ui/src/components/Addresses/index.tsx @@ -83,7 +83,7 @@ const Addresses = ({ maxWidth: 500, onRender: (item?: State.Address, _index?: number, column?: IColumn) => { if (item) { - if (column && (column.calculatedWidth || 0) < 400) { + if (column && (column.calculatedWidth || 0) < 420) { return (
( - - {item.lockHash || 'none'} - - ), - }, - { - key: 'outPointCell', - name: 'OutPoint Cell', - minWidth: 150, - onRender: (item: any) => { - const text = item.previousOutput ? `${item.previousOutput.txHash}[${item.previousOutput.index}]` : 'none' - return ( - - {text} - - ) - }, - }, - { - key: 'capacity', - name: 'Capacity', - minWidth: 200, - maxWidth: 250, - }, -].map( - (col): IColumn => ({ - ariaLabel: col.name, - fieldName: col.key, - ...col, - }) -) -const outputColumns: IColumn[] = [ - { - key: 'index', - name: 'Index', - minWidth: 80, - maxWidth: 150, - onRender: (item?: any | State.DetailedOutput) => { - if (item) { - return item.outPoint.index - } - return null - }, - }, - { - key: 'lockHash', - name: 'Lock Hash', - minWidth: 150, - }, - { - key: 'capacity', - name: 'Capacity', - minWidth: 200, - maxWidth: 250, - onRender: (output?: State.DetailedOutput) => { - if (output) { - return `${shannonToCKBFormatter(output.capacity)} CKB` - } - return null - }, - }, -].map(col => ({ - ariaLabel: col.name, - fieldName: col.key, - ...col, -})) - -const basicInfoColumns: IColumn[] = [ - { - key: 'label', - name: 'Label', - minWidth: 100, - maxWidth: 150, - }, - { - key: 'value', - name: 'value', - minWidth: 450, - }, -].map( - (col): IColumn => ({ - minWidth: MIN_CELL_WIDTH, - ariaLabel: col.name, - fieldName: col.key, - ...col, - }) -) const Transaction = () => { const [t] = useTranslation() const [transaction, setTransaction] = useState(transactionState) + const [addressPrefix, setAddressPrefix] = useState(ckbCore.utils.AddressPrefix.Mainnet) const [error, setError] = useState({ code: '', message: '' }) + + const inputColumns: IColumn[] = useMemo( + () => + [ + { + key: 'index', + name: t('transaction.index'), + minWidth: 60, + maxWidth: 60, + onRender: (_item?: any, index?: number) => { + if (undefined !== index) { + return index + } + return null + }, + }, + { + key: 'outPointCell', + name: 'OutPoint Cell', + minWidth: 150, + maxWidth: 600, + onRender: (item: any) => { + const text = item.previousOutput ? `${item.previousOutput.txHash}[${item.previousOutput.index}]` : 'none' + return ( + + {text} + + ) + }, + }, + { + key: 'capacity', + name: t('transaction.amount'), + minWidth: 100, + maxWidth: 250, + onRender: (input?: State.DetailedOutput) => { + if (input) { + return `${shannonToCKBFormatter(input.capacity)} CKB` + } + return null + }, + }, + ].map( + (col): IColumn => ({ + ariaLabel: col.name, + fieldName: col.key, + ...col, + }) + ), + [t] + ) + + const outputColumns: IColumn[] = useMemo( + () => + [ + { + key: 'index', + name: t('transaction.index'), + minWidth: 60, + maxWidth: 60, + onRender: (item?: any | State.DetailedOutput) => { + if (item) { + return item.outPoint.index + } + return null + }, + }, + { + key: 'address', + name: t('transaction.address'), + minWidth: 200, + maxWidth: 500, + onRender: (output?: State.DetailedOutput, _index?: number, column?: IColumn) => { + if (!output) { + return null + } + try { + const address = ckbCore.utils.bech32Address(output.lock.args[0], { + prefix: addressPrefix, + type: ckbCore.utils.AddressType.HashIdx, + codeHashIndex: '0x00', + }) + if (column && (column.calculatedWidth || 0) < 450) { + return ( +
+ {address.slice(0, -6)} + {address.slice(-6)} +
+ ) + } + return ( + + {address} + + ) + } catch { + return null + } + }, + }, + { + key: 'capacity', + name: t('transaction.amount'), + minWidth: 100, + maxWidth: 250, + onRender: (output?: State.DetailedOutput) => { + if (output) { + return `${shannonToCKBFormatter(output.capacity)} CKB` + } + return null + }, + }, + ].map(col => ({ + ariaLabel: col.name, + fieldName: col.key, + ...col, + })), + [addressPrefix, t] + ) + + const basicInfoColumns: IColumn[] = useMemo( + () => + [ + { + key: 'label', + name: 'label', + minWidth: 100, + maxWidth: 120, + }, + { + key: 'value', + name: 'value', + minWidth: 150, + }, + ].map( + (col): IColumn => ({ + minWidth: MIN_CELL_WIDTH, + ariaLabel: col.name, + fieldName: col.key, + ...col, + }) + ), + [] + ) + useEffect(() => { + Promise.all([getAllNetworks(), getCurrentNetworkID()]) + .then(([networksRes, idRes]) => { + if (networksRes.status === 1 && idRes.status === 1) { + const network = networksRes.result.find((n: any) => n.id === idRes.result) + if (!network) { + throw new Error('Cannot find current network in the network list') + } + + setAddressPrefix( + network.chain === process.env.REACT_APP_MAINNET_TAG + ? ckbCore.utils.AddressPrefix.Mainnet + : ckbCore.utils.AddressPrefix.Testnet + ) + } + }) + .catch(err => console.warn(err)) + const currentWallet = currentWalletCache.load() if (currentWallet) { const hash = window.location.href.split('/').pop() @@ -142,21 +220,26 @@ const Transaction = () => { }) }, []) + // TODO: add conditional branch on mainnet and testnet + const onExplorerBtnClick = useCallback(() => { + openExternal(`https://explorer.nervos.org/transaction/${transaction.hash}`) + }, [transaction.hash]) + const basicInfoItems = useMemo( () => [ - { label: t('history.transaction-hash'), value: transaction.hash || 'none' }, + { label: t('transaction.transaction-hash'), value: transaction.hash || 'none' }, { - label: t('history.date'), + label: t('transaction.block-number'), + value: localNumberFormatter(transaction.blockNumber) || 'none', + }, + { + label: t('transaction.date'), value: +(transaction.timestamp || transaction.createdAt) ? uniformTimeFormatter(+(transaction.timestamp || transaction.createdAt)) : 'none', }, { - label: t('history.blockNumber'), - value: localNumberFormatter(transaction.blockNumber) || 'none', - }, - { - label: t('history.amount'), + label: t('transaction.income'), value: `${shannonToCKBFormatter(transaction.value)} CKB`, }, ], @@ -185,10 +268,12 @@ const Transaction = () => { isHeaderVisible={false} /> - + - Inputs + {`${t('transaction.inputs')} (${transaction.inputs.length}/${localNumberFormatter( + transaction.inputsCount + )})`} { - Outputs + {`${t('transaction.outputs')} (${transaction.outputs.length}/${localNumberFormatter( + transaction.outputsCount + )})`} { /> + ) } diff --git a/packages/neuron-ui/src/components/Transaction/style.module.scss b/packages/neuron-ui/src/components/Transaction/style.module.scss new file mode 100644 index 0000000000..e99cb291dd --- /dev/null +++ b/packages/neuron-ui/src/components/Transaction/style.module.scss @@ -0,0 +1,38 @@ +.explorerNavButton { + position: fixed; + right: 10px; + bottom: 10px; + height: 30px; + width: 30px; + display: flex; + align-items: center; + justify-content: center; + overflow: hidden; + font-size: 12px; + color: #fff; + background: rgba(60, 198, 138, 0.8); + border: none; + border-radius: 15px; + transition: all 0.2s; + z-index: 1; + + span { + display: none; + } + + i { + display: flex; + } + + &:hover { + width: 100px; + + span { + display: flex; + } + + i { + display: none; + } + } +} diff --git a/packages/neuron-ui/src/locales/en.json b/packages/neuron-ui/src/locales/en.json index c64691cfe7..34c89e06a3 100644 --- a/packages/neuron-ui/src/locales/en.json +++ b/packages/neuron-ui/src/locales/en.json @@ -139,7 +139,18 @@ "confirming-with-count": "{{confirmations}} confirmations" }, "transaction": { - "goBack": "Go back" + "date": "Date", + "transaction-hash": "Transaction Hash", + "block-number": "Block Number", + "goBack": "Go back", + "index": "Index", + "address": "Address", + "income": "Income", + "amount": "Amount", + "inputs": "Inputs", + "outputs": "Outputs", + "view-in-explorer": "Explorer", + "view-in-explorer-button-title": "View on explorer" }, "addresses": { "addresses": "Addresses", diff --git a/packages/neuron-ui/src/locales/zh.json b/packages/neuron-ui/src/locales/zh.json index 9b8136feb8..5c18d9f008 100644 --- a/packages/neuron-ui/src/locales/zh.json +++ b/packages/neuron-ui/src/locales/zh.json @@ -139,7 +139,18 @@ "confirming-with-count": " 已确认 {{confirmations}} 次" }, "transaction": { - "goBack": "返回" + "date": "时间", + "transaction-hash": "交易哈希", + "block-number": "区块高度", + "goBack": "返回", + "index": "序号", + "address": "地址", + "income": "收入", + "amount": "数量", + "inputs": "输入", + "outputs": "输出", + "view-in-explorer": "浏览器", + "view-in-explorer-button-title": "浏览器中查看详情" }, "addresses": { "addresses": "地址", diff --git a/packages/neuron-ui/src/services/remote/index.ts b/packages/neuron-ui/src/services/remote/index.ts index 36802546db..c7e61bfd36 100644 --- a/packages/neuron-ui/src/services/remote/index.ts +++ b/packages/neuron-ui/src/services/remote/index.ts @@ -69,6 +69,14 @@ export const showOpenDialog = (opt: { title: string; message?: string; onUpload: ) } +export const openExternal = (url: string) => { + if (!window.remote) { + window.open(url) + } else { + window.remote.require('electron').shell.openExternal(url) + } +} + export default { getLocale, validateMnemonic, @@ -77,4 +85,5 @@ export default { showErrorMessage, showOpenDialog, getWinID, + openExternal, } diff --git a/packages/neuron-ui/src/services/remote/networks.ts b/packages/neuron-ui/src/services/remote/networks.ts index 5bcda628b9..5a11114318 100644 --- a/packages/neuron-ui/src/services/remote/networks.ts +++ b/packages/neuron-ui/src/services/remote/networks.ts @@ -18,8 +18,18 @@ export const updateNetwork = controllerMethodWrapper(CONTROLLER_NAME)( } ) +export const getAllNetworks = controllerMethodWrapper(CONTROLLER_NAME)(controller => () => { + return controller.getAll() +}) + +export const getCurrentNetworkID = controllerMethodWrapper(CONTROLLER_NAME)(controller => () => { + return controller.currentID() +}) + export default { createNetwork, updateNetwork, setCurrentNetowrk, + getAllNetworks, + getCurrentNetworkID, } diff --git a/packages/neuron-ui/src/states/initStates/chain.ts b/packages/neuron-ui/src/states/initStates/chain.ts index 742b0f6c47..8cd5609b48 100644 --- a/packages/neuron-ui/src/states/initStates/chain.ts +++ b/packages/neuron-ui/src/states/initStates/chain.ts @@ -11,7 +11,9 @@ export const transactionState: State.DetailedTransaction = { description: '', status: 'pending', inputs: [], + inputsCount: '0', outputs: [], + outputsCount: '0', deps: [], blockNumber: '', blockHash: '', diff --git a/packages/neuron-ui/src/styles/index.scss b/packages/neuron-ui/src/styles/index.scss index f3ca316e1d..5f0770add3 100755 --- a/packages/neuron-ui/src/styles/index.scss +++ b/packages/neuron-ui/src/styles/index.scss @@ -109,13 +109,14 @@ navbar { } } - .textOverflow { - overflow: hidden; - text-overflow: ellipsis; - } } +.textOverflow { + overflow: hidden; + text-overflow: ellipsis; +} + // hack fabric ui experimental pagination style .ms-Pagination-container { button[aria-selected=false] { diff --git a/packages/neuron-ui/src/theme.tsx b/packages/neuron-ui/src/theme.tsx index 15220aa1da..ef4c2b8897 100644 --- a/packages/neuron-ui/src/theme.tsx +++ b/packages/neuron-ui/src/theme.tsx @@ -9,6 +9,7 @@ import { Close as DismissIcon, Close as FailIcon, Copy as CopyIcon, + Domain as ExplorerIcon, Down as ArrowDownIcon, FormEdit as EditIcon, FormClose as ClearIcon, @@ -89,6 +90,7 @@ registerIcons({ Keystore: , Edit: , Settings: , + Explorer: , }, }) diff --git a/packages/neuron-ui/src/types/App/index.d.ts b/packages/neuron-ui/src/types/App/index.d.ts index b38d199b9a..a87047d0ba 100644 --- a/packages/neuron-ui/src/types/App/index.d.ts +++ b/packages/neuron-ui/src/types/App/index.d.ts @@ -38,7 +38,9 @@ declare namespace State { } | null } }[] + inputsCount: string outputs: DetailedOutput[] + outputsCount: string witnesses: string[] } interface Output { diff --git a/packages/neuron-wallet/src/controllers/transactions.ts b/packages/neuron-wallet/src/controllers/transactions.ts index d2c0b72c12..f5331fb22c 100644 --- a/packages/neuron-wallet/src/controllers/transactions.ts +++ b/packages/neuron-wallet/src/controllers/transactions.ts @@ -9,6 +9,8 @@ import { ResponseCode } from 'utils/const' import { TransactionNotFound, CurrentWalletNotSet, ServiceHasNoResponse } from 'exceptions' import LockUtils from 'models/lock-utils' +const CELL_COUNT_THRESHOLD = 10 + /** * @class TransactionsController * @description handle messages from transactions channel @@ -16,7 +18,7 @@ import LockUtils from 'models/lock-utils' export default class TransactionsController { @CatchControllerError public static async getAll( - params: TransactionsByLockHashesParam + params: TransactionsByLockHashesParam, ): Promise>> { const transactions = await TransactionsService.getAll(params) @@ -32,7 +34,7 @@ export default class TransactionsController { @CatchControllerError public static async getAllByKeywords( - params: Controller.Params.TransactionsByKeywords + params: Controller.Params.TransactionsByKeywords, ): Promise & Controller.Params.TransactionsByKeywords>> { const { pageNo = 1, pageSize = 15, keywords = '', walletID = '' } = params @@ -56,7 +58,7 @@ export default class TransactionsController { @CatchControllerError public static async getAllByAddresses( - params: Controller.Params.TransactionsByAddresses + params: Controller.Params.TransactionsByAddresses, ): Promise & Controller.Params.TransactionsByAddresses>> { const { pageNo, pageSize, addresses = '' } = params @@ -85,7 +87,10 @@ export default class TransactionsController { } @CatchControllerError - public static async get(walletID: string, hash: string): Promise> { + public static async get( + walletID: string, + hash: string, + ): Promise> { const transaction = await TransactionsService.get(hash) if (!transaction) { @@ -114,15 +119,20 @@ export default class TransactionsController { .reduce((result, c) => result + c, BigInt(0)) const value: bigint = outputCapacities - inputCapacities transaction.value = value.toString() + const inputsCount = transaction.inputs ? transaction.inputs.length.toString() : '0' + if (transaction.inputs) { + transaction.inputs = transaction.inputs.slice(0, CELL_COUNT_THRESHOLD) + } + const outputsCount = transaction.outputs ? transaction.outputs.length.toString() : '0' if (transaction.outputs) { - transaction.outputs = transaction - .outputs.sort((o1, o2) => +o1.outPoint!.index - +o2.outPoint!.index) - .slice(0, 200) + transaction.outputs = transaction.outputs + .sort((o1, o2) => +o1.outPoint!.index - +o2.outPoint!.index) + .slice(0, CELL_COUNT_THRESHOLD) } return { status: ResponseCode.Success, - result: transaction, + result: { ...transaction, outputsCount, inputsCount }, } } From 541ab94725e2e057d328c7bcd395b2dfc356e8ef Mon Sep 17 00:00:00 2001 From: Keith Date: Mon, 30 Sep 2019 13:08:04 +0800 Subject: [PATCH 07/14] fix(neuron-ui): fix the relationship between transaction price and speed --- .../components/TransactionFeePanel/index.tsx | 13 ++--- .../tests-e2e/tests/sendTransaction.ts | 48 ++++++++++++++++--- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/packages/neuron-ui/src/components/TransactionFeePanel/index.tsx b/packages/neuron-ui/src/components/TransactionFeePanel/index.tsx index 9c0ee89b1a..d7df103bc6 100644 --- a/packages/neuron-ui/src/components/TransactionFeePanel/index.tsx +++ b/packages/neuron-ui/src/components/TransactionFeePanel/index.tsx @@ -38,7 +38,7 @@ const TransactionFee: React.FunctionComponent = ({ const selectedSpeed = calculateSpeed(+price) return ( - + @@ -76,7 +76,7 @@ const TransactionFee: React.FunctionComponent = ({ - + {actionSpacer} @@ -90,10 +90,10 @@ const TransactionFee: React.FunctionComponent = ({ dropdownWidth={140} selectedKey={selectedSpeed} options={[ - { key: '0', text: 'immediately' }, - { key: '30', text: '~ 30s' }, - { key: '60', text: '~ 1min' }, - { key: '180', text: '~ 3min' }, + { key: '180', text: 'immediately' }, + { key: '60', text: '~ 30s' }, + { key: '30', text: '~ 1min' }, + { key: '0', text: '~ 3min' }, ]} onRenderCaretDown={() => { return @@ -103,6 +103,7 @@ const TransactionFee: React.FunctionComponent = ({ onPriceChange(e, item.key) } }} + aria-label="expected speed" /> diff --git a/packages/neuron-wallet/tests-e2e/tests/sendTransaction.ts b/packages/neuron-wallet/tests-e2e/tests/sendTransaction.ts index d03d1025e9..e179b240ce 100644 --- a/packages/neuron-wallet/tests-e2e/tests/sendTransaction.ts +++ b/packages/neuron-wallet/tests-e2e/tests/sendTransaction.ts @@ -25,7 +25,7 @@ export default (app: Application) => { await app.waitUntilLoaded() }) - afterEach(async() => { + afterEach(async () => { const { client } = app.spectron client.click('button[type=reset]') await client.waitUntilWindowLoaded() @@ -33,7 +33,7 @@ export default (app: Application) => { describe('Test address field boundary validation', () => { app.test('Invalid address should show alert', async () => { - const { client } = app.spectron + const { client } = app.spectron const invalidAddress = 'invalid-address' const inputs = await app.elements('input') client.elementIdValue(inputs.value[0].ELEMENT, invalidAddress) @@ -52,7 +52,6 @@ export default (app: Application) => { const errorMessage = await app.element('.ms-TextField-errorMessage') const msg = await client.elementIdText(errorMessage.value.ELEMENT) expect(msg.value).toBe('Address cannot be empty') - }) app.test('Valid address should not show alert', async () => { @@ -66,8 +65,6 @@ export default (app: Application) => { }) }) - - describe('Test amount field boundary validation', () => { const validAddress = 'ckt1qyq0cwanfaf2t2cwmuxd8ujv2ww6kjv7n53sfwv2l0' app.test('Amount 60.99999999 is too small, 61 CKB is required', async () => { @@ -110,5 +107,44 @@ export default (app: Application) => { expect(msg.value).toBe('Amount is not enough') }) }) -} + describe('Test the transaction fee operations', () => { + beforeAll(async () => { + const { client } = app.spectron + client.click('button[role=switch]') + await app.waitUntilLoaded() + }) + + app.test('default price should be 0 and default speed should be 3min', async () => { + const { client } = app.spectron + const transactionFeePanel = client.$('div[aria-label="transaction fee"]') + const [, priceField] = await transactionFeePanel.$$('input') + expect((await client.elementIdAttribute(priceField.value.ELEMENT, 'value')).value).toBe('0') + const speedDropdown = await client.$('div[role=listbox]') + expect((await client.elementIdAttribute(speedDropdown.value.ELEMENT, 'innerText')).value).toBe('~ 3min') + }) + + app.test('Change speed to immediately and the price should be 180', async () => { + const { client } = app.spectron + client.click('div[role=listbox]') + await app.waitUntilLoaded() + client.click('button[title=immediately]') + await app.waitUntilLoaded() + const transactionFeePanel = client.$('div[aria-label="transaction fee"]') + const [, priceField] = await transactionFeePanel.$$('input') + expect((await client.elementIdAttribute(priceField.value.ELEMENT, 'value')).value).toBe('180') + }) + + app.test('Change the price to 150 and the speed should switch to ~ 30s', async () => { + const { client } = app.spectron + const transactionFeePanel = client.$('div[aria-label="transaction fee"]') + const [, priceField] = await transactionFeePanel.$$('input') + client.elementIdClear(priceField.value.ELEMENT) + await app.waitUntilLoaded() + client.elementIdValue(priceField.value.ELEMENT, '150') + const speedDropdown = await client.$('div[role=listbox]') + + expect((await client.elementIdAttribute(speedDropdown.value.ELEMENT, 'innerText')).value).toBe('~ 30s') + }) + }) +} From e974a2146b2d439e103452dc535697a642714d05 Mon Sep 17 00:00:00 2001 From: Keith Date: Mon, 30 Sep 2019 13:52:34 +0800 Subject: [PATCH 08/14] fix(neuron-ui): show 0 confirmations if the real data is negative --- packages/neuron-ui/src/components/TransactionList/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/neuron-ui/src/components/TransactionList/index.tsx b/packages/neuron-ui/src/components/TransactionList/index.tsx index bff553535e..b3c34caf5c 100644 --- a/packages/neuron-ui/src/components/TransactionList/index.tsx +++ b/packages/neuron-ui/src/components/TransactionList/index.tsx @@ -133,7 +133,7 @@ const TransactionList = ({ const confirmationCount = 1 + +tipBlockNumber - +item.blockNumber if (confirmationCount < CONFIRMATION_THRESHOLD) { return t(`history.confirming-with-count`, { - confirmations: `${confirmationCount} / ${CONFIRMATION_THRESHOLD}`, + confirmations: `${Math.max(0, confirmationCount)} / ${CONFIRMATION_THRESHOLD}`, }) } const confirmations = localNumberFormatter(confirmationCount) From 160c8442249c3556587a6e749770f5a619e2ee96 Mon Sep 17 00:00:00 2001 From: Keith Date: Mon, 30 Sep 2019 14:18:39 +0800 Subject: [PATCH 09/14] fix(neuron-ui): add an auto match on speed of price from 20 to 40 --- .../neuron-ui/src/components/TransactionFeePanel/index.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/neuron-ui/src/components/TransactionFeePanel/index.tsx b/packages/neuron-ui/src/components/TransactionFeePanel/index.tsx index d7df103bc6..948b395ce2 100644 --- a/packages/neuron-ui/src/components/TransactionFeePanel/index.tsx +++ b/packages/neuron-ui/src/components/TransactionFeePanel/index.tsx @@ -16,6 +16,9 @@ const calculateSpeed = (price: number) => { if (price >= 40) { return '60' } + if (price >= 20) { + return '30' + } return '0' } From b6e30358be967ddbbb623e2aa28e2ae89c9d85ed Mon Sep 17 00:00:00 2001 From: classicalliu Date: Tue, 8 Oct 2019 01:18:14 +0800 Subject: [PATCH 10/14] feat: bump sdk to v0.22.0 --- packages/neuron-ui/package.json | 2 +- packages/neuron-wallet/package.json | 6 +-- .../database/chain/entities/transaction.ts | 4 +- packages/neuron-wallet/src/env.ts | 2 +- .../neuron-wallet/src/models/lock-utils.ts | 7 ++- packages/neuron-wallet/src/services/cells.ts | 2 +- .../src/services/tx/transaction-generator.ts | 4 +- .../src/services/tx/transaction-service.ts | 4 +- .../neuron-wallet/src/services/wallets.ts | 20 +++----- .../startup/sync-block-task/init-database.ts | 2 + .../neuron-wallet/src/types/cell-types.ts | 8 +-- .../tests/models/lock-utils.test.ts | 16 +++--- .../tests/services/cells.test.ts | 6 +-- .../tests/services/wallets.test.ts | 9 ++-- yarn.lock | 51 ++++++++----------- 15 files changed, 62 insertions(+), 81 deletions(-) diff --git a/packages/neuron-ui/package.json b/packages/neuron-ui/package.json index 7504478707..036dde0c9a 100644 --- a/packages/neuron-ui/package.json +++ b/packages/neuron-ui/package.json @@ -43,7 +43,7 @@ "last 2 chrome versions" ], "dependencies": { - "@nervosnetwork/ckb-sdk-core": "0.21.0", + "@nervosnetwork/ckb-sdk-core": "0.22.0", "@uifabric/experiments": "7.16.1", "@uifabric/styling": "7.6.2", "canvg": "2.0.0", diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index 5abac9a1ef..c2b4800eeb 100644 --- a/packages/neuron-wallet/package.json +++ b/packages/neuron-wallet/package.json @@ -34,8 +34,8 @@ ] }, "dependencies": { - "@nervosnetwork/ckb-sdk-core": "0.21.0", - "@nervosnetwork/ckb-sdk-utils": "0.21.0", + "@nervosnetwork/ckb-sdk-core": "0.22.0", + "@nervosnetwork/ckb-sdk-utils": "0.22.0", "bn.js": "4.11.8", "chalk": "2.4.2", "electron-log": "3.0.7", @@ -51,7 +51,7 @@ "uuid": "3.3.3" }, "devDependencies": { - "@nervosnetwork/ckb-types": "0.21.0", + "@nervosnetwork/ckb-types": "0.22.0", "@types/electron-devtools-installer": "2.2.0", "@types/elliptic": "6.4.9", "@types/sqlite3": "3.1.5", diff --git a/packages/neuron-wallet/src/database/chain/entities/transaction.ts b/packages/neuron-wallet/src/database/chain/entities/transaction.ts index ef3c763633..3cbcae9063 100644 --- a/packages/neuron-wallet/src/database/chain/entities/transaction.ts +++ b/packages/neuron-wallet/src/database/chain/entities/transaction.ts @@ -11,7 +11,7 @@ import { AfterRemove, } from 'typeorm' import { remote } from 'electron' -import { Witness, Transaction as TransactionInterface, TransactionStatus, CellDep } from 'types/cell-types' +import { Transaction as TransactionInterface, TransactionStatus, CellDep } from 'types/cell-types' import TxDbChangedSubject from 'models/subjects/tx-db-changed-subject' import InputEntity from './input' import OutputEntity from './output' @@ -47,7 +47,7 @@ export default class Transaction extends BaseEntity { @Column({ type: 'simple-json', }) - witnesses!: Witness[] + witnesses!: string[] @Column({ type: 'varchar', diff --git a/packages/neuron-wallet/src/env.ts b/packages/neuron-wallet/src/env.ts index 4e9b84fde9..7e4721adfe 100644 --- a/packages/neuron-wallet/src/env.ts +++ b/packages/neuron-wallet/src/env.ts @@ -50,7 +50,7 @@ const env: ENV = { name: 'Local', remote: 'http://localhost:8114', type: 1, - chain: 'ckb_devnet', + chain: 'ckb_dev', }, ], }, diff --git a/packages/neuron-wallet/src/models/lock-utils.ts b/packages/neuron-wallet/src/models/lock-utils.ts index 4c19809139..6ac0094768 100644 --- a/packages/neuron-wallet/src/models/lock-utils.ts +++ b/packages/neuron-wallet/src/models/lock-utils.ts @@ -85,7 +85,7 @@ export default class LockUtils { const lock: Script = { codeHash: systemScript.codeHash, - args: [LockUtils.addressToBlake160(address)], + args: LockUtils.addressToBlake160(address), hashType, } return lock @@ -113,7 +113,7 @@ export default class LockUtils { } static lockScriptToAddress(lock: Script): string { - const blake160: string = lock.args![0] + const blake160: string = lock.args! return this.blake160ToAddress(blake160) } @@ -127,8 +127,7 @@ export default class LockUtils { } static addressToBlake160(address: string): string { - const prefix = env.testnet ? core.utils.AddressPrefix.Testnet : core.utils.AddressPrefix.Mainnet - const result: string = core.utils.parseAddress(address, prefix, 'hex') as string + const result: string = core.utils.parseAddress(address, 'hex') as string const hrp: string = `0100` let blake160: string = result.slice(hrp.length + 2, result.length) if (!blake160.startsWith('0x')) { diff --git a/packages/neuron-wallet/src/services/cells.ts b/packages/neuron-wallet/src/services/cells.ts index 59ee071edf..0717f698ca 100644 --- a/packages/neuron-wallet/src/services/cells.ts +++ b/packages/neuron-wallet/src/services/cells.ts @@ -159,7 +159,7 @@ export default class CellsService { if (!args) { return undefined } - return args[0] + return args }) .filter(blake160 => !!blake160) as string[] diff --git a/packages/neuron-wallet/src/services/tx/transaction-generator.ts b/packages/neuron-wallet/src/services/tx/transaction-generator.ts index 8e26b7a891..d37bdad2d1 100644 --- a/packages/neuron-wallet/src/services/tx/transaction-generator.ts +++ b/packages/neuron-wallet/src/services/tx/transaction-generator.ts @@ -34,7 +34,7 @@ export class TransactionGenerator { data: '0x', lock: { codeHash, - args: [blake160], + args: blake160, hashType, }, } @@ -53,7 +53,7 @@ export class TransactionGenerator { data: '0x', lock: { codeHash, - args: [changeBlake160], + args: changeBlake160, hashType, }, } diff --git a/packages/neuron-wallet/src/services/tx/transaction-service.ts b/packages/neuron-wallet/src/services/tx/transaction-service.ts index ea608f3b84..ebe924e05c 100644 --- a/packages/neuron-wallet/src/services/tx/transaction-service.ts +++ b/packages/neuron-wallet/src/services/tx/transaction-service.ts @@ -269,11 +269,11 @@ export class TransactionsService { let outputBlake160s: string[] = [] if (tx.inputs) { inputBlake160s = tx.inputs - .map(input => input.lock && input.lock.args && input.lock.args[0]) + .map(input => input.lock && input.lock.args) .filter(blake160 => blake160) as string[] } if (tx.outputs) { - outputBlake160s = tx.outputs.map(output => output.lock.args![0]) + outputBlake160s = tx.outputs.map(output => output.lock.args!) } return [...new Set(inputBlake160s.concat(outputBlake160s))] } diff --git a/packages/neuron-wallet/src/services/wallets.ts b/packages/neuron-wallet/src/services/wallets.ts index 683e4f9410..d137e19cb8 100644 --- a/packages/neuron-wallet/src/services/wallets.ts +++ b/packages/neuron-wallet/src/services/wallets.ts @@ -4,7 +4,7 @@ import { AccountExtendedPublicKey, PathAndPrivateKey } from 'models/keys/key' import Keystore from 'models/keys/keystore' import Store from 'models/store' import LockUtils from 'models/lock-utils' -import { Witness, TransactionWithoutHash, Input } from 'types/cell-types' +import { TransactionWithoutHash, Input } from 'types/cell-types' import ConvertTo from 'types/convert-to' import Blake2b from 'utils/blake2b' import { WalletNotFound, IsRequired, UsedName } from 'exceptions' @@ -380,8 +380,8 @@ export default class WalletService { const paths = addressInfos.map(info => info.path) const pathAndPrivateKeys = this.getPrivateKeys(wallet, paths, password) - const witnesses: Witness[] = inputs!.map((input: Input) => { - const blake160: string = input.lock!.args![0] + const witnesses: string[] = inputs!.map((input: Input) => { + const blake160: string = input.lock!.args! const info = addressInfos.find(i => i.blake160 === blake160) const { path } = info! const pathAndPrivateKey = pathAndPrivateKeys.find(p => p.path === path) @@ -389,7 +389,7 @@ export default class WalletService { throw new Error('no private key found') } const { privateKey } = pathAndPrivateKey - const witness = this.signWitness({ data: [] }, privateKey, txHash) + const witness = this.signWitness('', privateKey, txHash) return witness }) @@ -443,19 +443,15 @@ export default class WalletService { return addr!.address } - public signWitness = (witness: Witness, privateKey: string, txHash: string): Witness => { + public signWitness = (witness: string, privateKey: string, txHash: string): string => { const addrObj = core.generateAddress(privateKey) - const oldData = witness.data + const oldData = witness const blake2b = new Blake2b() blake2b.update(txHash) - oldData.forEach(data => { - blake2b.update(data) - }) + blake2b.update(oldData) const message = blake2b.digest() const signature = addrObj.signRecoverable(message) - const newWitness: Witness = { - data: [signature], - } + const newWitness = signature return newWitness } diff --git a/packages/neuron-wallet/src/startup/sync-block-task/init-database.ts b/packages/neuron-wallet/src/startup/sync-block-task/init-database.ts index 93ea191d83..2728d9baae 100644 --- a/packages/neuron-wallet/src/startup/sync-block-task/init-database.ts +++ b/packages/neuron-wallet/src/startup/sync-block-task/init-database.ts @@ -2,6 +2,7 @@ import initConnection from 'database/chain/ormconfig' import Utils from 'services/sync/utils' import { updateMetaInfo, getMetaInfo } from 'database/chain/meta-info' import LockUtils from 'models/lock-utils' +import logger from 'utils/logger' import genesisBlockHash from './genesis' export const initDatabase = async () => { @@ -11,6 +12,7 @@ export const initDatabase = async () => { const systemScriptInfo = await LockUtils.systemScript() updateMetaInfo({ genesisBlockHash: hash, systemScriptInfo }) } catch (err) { + logger.debug('initDatabase error:', err) try { const metaInfo = getMetaInfo() await initConnection(metaInfo.genesisBlockHash) diff --git a/packages/neuron-wallet/src/types/cell-types.ts b/packages/neuron-wallet/src/types/cell-types.ts index ec440857de..150dec9946 100644 --- a/packages/neuron-wallet/src/types/cell-types.ts +++ b/packages/neuron-wallet/src/types/cell-types.ts @@ -45,7 +45,7 @@ export interface TransactionWithoutHash { value?: string blockNumber?: string blockHash?: string - witnesses?: Witness[] + witnesses?: string[] type?: string description?: string status?: TransactionStatus @@ -65,10 +65,6 @@ export interface Input { lock?: Script } -export interface Witness { - data: string[] -} - export interface Cell { capacity: string data?: string @@ -85,7 +81,7 @@ export interface OutPoint { } export interface Script { - args?: string[] + args?: string codeHash?: string | null hashType: ScriptHashType } diff --git a/packages/neuron-wallet/tests/models/lock-utils.test.ts b/packages/neuron-wallet/tests/models/lock-utils.test.ts index bd2fa60ea7..6f9e4ded1f 100644 --- a/packages/neuron-wallet/tests/models/lock-utils.test.ts +++ b/packages/neuron-wallet/tests/models/lock-utils.test.ts @@ -3,32 +3,32 @@ import LockUtils from '../../src/models/lock-utils' const systemScript = { outPoint: { - txHash: '0x74e34a76d68f5ed864c0ad139a82461ee809e981939cd9cfcd92ac0fdbb1114b', + txHash: '0xb815a396c5226009670e89ee514850dcde452bca746cdd6b41c104b50e559c70', index: '0', }, - codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2', + codeHash: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8', hashType: ScriptHashType.Type, } describe('LockUtils Test', () => { const bob = { lockScript: { - codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2', - args: ['0x36c329ed630d6ce750712a477543672adab57f4c'], + codeHash: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8', + args: '0x36c329ed630d6ce750712a477543672adab57f4c', hashType: ScriptHashType.Type, }, - lockHash: '0xecaeea8c8581d08a3b52980272001dbf203bc6fa2afcabe7cc90cc2afff488ba', + lockHash: '0x1f2615a8dde4e28ca736ff763c2078aff990043f4cbf09eb4b3a58a140a0862d', address: 'ckt1qyqrdsefa43s6m882pcj53m4gdnj4k440axqswmu83', blake160: '0x36c329ed630d6ce750712a477543672adab57f4c', } const alice = { lockScript: { - codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2', - args: ['0xe2193df51d78411601796b35b17b4f8f2cd85bd0'], + codeHash: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8', + args: '0xe2193df51d78411601796b35b17b4f8f2cd85bd0', hashType: ScriptHashType.Type, }, - lockHash: '0x489306d801d54bee2d8562ae20fdc53635b568f8107bddff15bb357f520cc02c', + lockHash: '0xa35eda3e71e86e4e22b7924012b6a6e90809dc7a68621d5f7a7c40eea01be45e', address: 'ckt1qyqwyxfa75whssgkq9ukkdd30d8c7txct0gqfvmy2v', blake160: '0xe2193df51d78411601796b35b17b4f8f2cd85bd0', } diff --git a/packages/neuron-wallet/tests/services/cells.test.ts b/packages/neuron-wallet/tests/services/cells.test.ts index 3040481e72..98a4676440 100644 --- a/packages/neuron-wallet/tests/services/cells.test.ts +++ b/packages/neuron-wallet/tests/services/cells.test.ts @@ -32,7 +32,7 @@ describe('CellsService', () => { const bob = { lockScript: { codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2', - args: ['0x36c329ed630d6ce750712a477543672adab57f4c'], + args: '0x36c329ed630d6ce750712a477543672adab57f4c', hashType: ScriptHashType.Type, }, lockHash: '0xecaeea8c8581d08a3b52980272001dbf203bc6fa2afcabe7cc90cc2afff488ba', @@ -43,7 +43,7 @@ describe('CellsService', () => { const alice = { lockScript: { codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2', - args: ['0xe2193df51d78411601796b35b17b4f8f2cd85bd0'], + args: '0xe2193df51d78411601796b35b17b4f8f2cd85bd0', hashType: ScriptHashType.Type, }, lockHash: '0x489306d801d54bee2d8562ae20fdc53635b568f8107bddff15bb357f520cc02c', @@ -85,7 +85,7 @@ describe('CellsService', () => { const typeScript: Script = { codeHash: randomHex(), - args: [], + args: '', hashType: ScriptHashType.Data, } diff --git a/packages/neuron-wallet/tests/services/wallets.test.ts b/packages/neuron-wallet/tests/services/wallets.test.ts index 28f7bbbe7d..69ce960a40 100644 --- a/packages/neuron-wallet/tests/services/wallets.test.ts +++ b/packages/neuron-wallet/tests/services/wallets.test.ts @@ -1,5 +1,4 @@ import WalletService, { WalletProperties } from '../../src/services/wallets' -import { Witness } from '../../src/types/cell-types' import Keystore from '../../src/models/keys/keystore' import Keychain from '../../src/models/keys/keychain' import { mnemonicToSeedSync } from '../../src/models/keys/mnemonic' @@ -175,17 +174,15 @@ describe('wallet service', () => { }) describe('sign witness', () => { - const witness: Witness = { data: [] } + const witness: string = '' const privateKey: string = '0xe79f3207ea4980b7fed79956d5934249ceac4751a4fae01a0f7c4a96884bc4e3' const txHash = '0x00f5f31941964004d665a8762df8eb4fab53b5ef8437b7d34a38e018b1409054' - const expectedData = [ - '0x99b79ff84dc39de16ec7ed2e9a2836a2560b95a71041ad3a6c00b2d31844db4c26b760918bbe08747ead167cccb35b1b9ba4db42896c19e412b885cd6589d41a00', - ] + const expectedData = '0x99b79ff84dc39de16ec7ed2e9a2836a2560b95a71041ad3a6c00b2d31844db4c26b760918bbe08747ead167cccb35b1b9ba4db42896c19e412b885cd6589d41a00' it('success', () => { const wallet = new WalletService() const newWitness = wallet.signWitness(witness, privateKey, txHash) - expect(newWitness.data).toEqual(expectedData) + expect(newWitness).toEqual(expectedData) }) }) diff --git a/yarn.lock b/yarn.lock index b23e07cdfd..42b67faf55 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2079,45 +2079,36 @@ call-me-maybe "^1.0.1" glob-to-regexp "^0.3.0" -"@nervosnetwork/ckb-sdk-address@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-address/-/ckb-sdk-address-0.21.0.tgz#bf78b3bcb84f80566d9167c5b38d9dac8b5eb81f" - integrity sha512-2sYFh38/DYHbb2OCvyTB3UGbrdbGU2qj47dQY82lsznDphblC6h/VLwISlaE/xQ04de/idb0Uc0fHVAqA4lkEg== +"@nervosnetwork/ckb-sdk-core@0.22.0": + version "0.22.0" + resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-core/-/ckb-sdk-core-0.22.0.tgz#dc4e93d425154e0dfeb40c08932095c0b99b8947" + integrity sha512-HKFFD4L3tK5yWsVSPn0t5qc+NZ35wmoEpd2q5wJtTt8rpLb0n1lJKKk8MQCRhWLR9a8UPskISrLDLyI2uQ7Q8Q== dependencies: - "@nervosnetwork/ckb-sdk-utils" "0.21.0" - "@nervosnetwork/ckb-types" "0.21.0" + "@nervosnetwork/ckb-sdk-rpc" "0.22.0" + "@nervosnetwork/ckb-sdk-utils" "0.22.0" + "@nervosnetwork/ckb-types" "0.22.0" -"@nervosnetwork/ckb-sdk-core@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-core/-/ckb-sdk-core-0.21.0.tgz#60d5bb5bb2c80b31a77c221ab06fded4d34b72c0" - integrity sha512-zS8vp01t5iYqXDsAjlhcdZafIXaYkJoYXSC1cnCh3dr23iaYuYjDz9/mbe2j/fZ4p46c1NSqQRpo4TGubhSm1g== +"@nervosnetwork/ckb-sdk-rpc@0.22.0": + version "0.22.0" + resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-rpc/-/ckb-sdk-rpc-0.22.0.tgz#f5a4b8459941fed110505b92fa94014d8853073b" + integrity sha512-auc2RqktbvQqyn8LcTnLVjgAMXIm1C0zLIHEEltngXQbZA5YeLXfJnC0RSSvpwloThgFpuKPvTy19b2/N9YzNg== dependencies: - "@nervosnetwork/ckb-sdk-address" "0.21.0" - "@nervosnetwork/ckb-sdk-rpc" "0.21.0" - "@nervosnetwork/ckb-sdk-utils" "0.21.0" - "@nervosnetwork/ckb-types" "0.21.0" - -"@nervosnetwork/ckb-sdk-rpc@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-rpc/-/ckb-sdk-rpc-0.21.0.tgz#4ff7d8e16b716c49ad5e9cc32868324921ba6b3b" - integrity sha512-0Dz871S9slwFPASs3Dz/07kkRK99T3uFo60zgyt1GSEmGoSREqXOwzaXbEU2lqPLvmFz1GP+T/mHt4TtIf7nWg== - dependencies: - "@nervosnetwork/ckb-sdk-utils" "0.21.0" + "@nervosnetwork/ckb-sdk-utils" "0.22.0" axios "0.19.0" -"@nervosnetwork/ckb-sdk-utils@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-utils/-/ckb-sdk-utils-0.21.0.tgz#461c9864d511bd4b9fb4469f4f0a35b4e631e589" - integrity sha512-MNMG1cx8w+qLrF1iKJLT8NgpZ+gaFrbvgtYF9SCqQiChqZI2iQyBdT7QyBQ/XPIRi5EKyEjyFH5+ofPwukWDFA== +"@nervosnetwork/ckb-sdk-utils@0.22.0": + version "0.22.0" + resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-utils/-/ckb-sdk-utils-0.22.0.tgz#94a0e03cec53ff6bfe4664e9afc4d84a0e01ee77" + integrity sha512-Rz6s9drKhBlZM1NVMpz5wP1WPMDOD6VIpwUpATF7zcpeyzMHJtFgZjGAOeDGuP1OMNZIQzUMW5v7RB3MpzXAQQ== dependencies: - "@nervosnetwork/ckb-types" "0.21.0" + "@nervosnetwork/ckb-types" "0.22.0" blake2b-wasm "1.1.7" elliptic "6.5.1" -"@nervosnetwork/ckb-types@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-types/-/ckb-types-0.21.0.tgz#20cfc81f2eef8c7baa36f0ada4f7642aee0eaf39" - integrity sha512-1VhtubsnTkY+rP+CiQ25nXoK+5SLWlf+aUsGJ7HhWhjP1gzlBJKXB3EAoa92FZzmfARJ7U3QKJoAEV4Bo6KXkQ== +"@nervosnetwork/ckb-types@0.22.0": + version "0.22.0" + resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-types/-/ckb-types-0.22.0.tgz#9191c3f1c8da4bc6c5f6a23910eee0c9ec8f267d" + integrity sha512-fA9QD851/PBhBEIWnh9N1S9p+ntEoMNw/GwpsLsL/LfXebzpWxrc10UJgTkOrJEz+Si1MSLz2SKGYGJKRrccTw== "@nodelib/fs.scandir@2.1.2": version "2.1.2" From 0a35d61bb0fbae67012ebcf74455e266a1517057 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Tue, 8 Oct 2019 12:00:27 +0800 Subject: [PATCH 11/14] fix: address balance error in indexer mode --- packages/neuron-wallet/src/services/indexer/queue.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/neuron-wallet/src/services/indexer/queue.ts b/packages/neuron-wallet/src/services/indexer/queue.ts index 6efeb113c4..d3045ef480 100644 --- a/packages/neuron-wallet/src/services/indexer/queue.ts +++ b/packages/neuron-wallet/src/services/indexer/queue.ts @@ -188,6 +188,8 @@ export default class IndexerQueue { blockHash: transactionWithStatus.txStatus.blockHash! } if (type === TxPointType.CreatedBy && this.latestCreatedBy.includes(txUniqueFlag)) { + const address = LockUtils.lockScriptToAddress(transaction.outputs![parseInt(txPoint.index, 16)].lock) + AddressesUsedSubject.getSubject().next([address]) return } From f87bb77edce3a65b89aee15ae0fb8595a8046b49 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Tue, 8 Oct 2019 15:41:14 +0800 Subject: [PATCH 12/14] chore: using sdk to sign witness --- packages/neuron-wallet/src/services/wallets.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/neuron-wallet/src/services/wallets.ts b/packages/neuron-wallet/src/services/wallets.ts index d137e19cb8..e6b475f018 100644 --- a/packages/neuron-wallet/src/services/wallets.ts +++ b/packages/neuron-wallet/src/services/wallets.ts @@ -6,7 +6,6 @@ import Store from 'models/store' import LockUtils from 'models/lock-utils' import { TransactionWithoutHash, Input } from 'types/cell-types' import ConvertTo from 'types/convert-to' -import Blake2b from 'utils/blake2b' import { WalletNotFound, IsRequired, UsedName } from 'exceptions' import { Address as AddressInterface } from 'database/address/dao' import Keychain from 'models/keys/keychain' @@ -444,15 +443,10 @@ export default class WalletService { } public signWitness = (witness: string, privateKey: string, txHash: string): string => { - const addrObj = core.generateAddress(privateKey) - const oldData = witness - const blake2b = new Blake2b() - blake2b.update(txHash) - blake2b.update(oldData) - const message = blake2b.digest() - const signature = addrObj.signRecoverable(message) - const newWitness = signature - return newWitness + return core.signWitnesses(privateKey)({ + transactionHash: txHash, + witnesses: [witness] + })[0] } // Derivate all child private keys for specified BIP44 paths. From 96247073a207fa14abeb6ca794c8b364d565aaf9 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 9 Oct 2019 14:47:59 +0900 Subject: [PATCH 13/14] chore: Bump to v0.22.0 --- 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 df03e68b47..1040bc9c04 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "packages": [ "packages/*" ], - "version": "0.21.0-beta.1", + "version": "0.22.0", "npmClient": "yarn", "useWorkspaces": true } diff --git a/package.json b/package.json index acaac74d0a..a6a61bd744 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "neuron", "productName": "Neuron", "description": "CKB Neuron Wallet", - "version": "0.21.0-beta.1", + "version": "0.22.0", "private": true, "author": { "name": "Nervos Core Dev", diff --git a/packages/neuron-ui/package.json b/packages/neuron-ui/package.json index 036dde0c9a..7811a5dd72 100644 --- a/packages/neuron-ui/package.json +++ b/packages/neuron-ui/package.json @@ -1,6 +1,6 @@ { "name": "neuron-ui", - "version": "0.21.0-beta.1", + "version": "0.22.0", "private": true, "author": { "name": "Nervos Core Dev", diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index c2b4800eeb..028537df98 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.21.0-beta.1", + "version": "0.22.0", "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.5", - "neuron-ui": "0.21.0-beta.1", + "neuron-ui": "0.22.0", "rimraf": "3.0.0", "spectron": "8.0.0", "ts-transformer-imports": "0.4.3", From e2dfb202ffcedd14b8a7cd36d3ef31fb84c76d82 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 9 Oct 2019 14:52:34 +0900 Subject: [PATCH 14/14] docs: Draft changelog for v0.22.0 --- CHANGELOG.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1edc449ce..ff257ff539 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,25 @@ +# [0.22.0](https://github.com/nervosnetwork/neuron/compare/v0.21.0-beta.1...v0.22.0) (2019-10-09) + + +### Bug Fixes + +* address balance error in indexer mode ([0a35d61](https://github.com/nervosnetwork/neuron/commit/0a35d61)) +* **neuron-ui:** add an auto match on speed of price from 20 to 40 ([160c844](https://github.com/nervosnetwork/neuron/commit/160c844)) +* **neuron-ui:** fix the relationship between transaction price and speed ([541ab94](https://github.com/nervosnetwork/neuron/commit/541ab94)) +* **neuron-ui:** show 0 confirmations if the real data is negative ([e974a21](https://github.com/nervosnetwork/neuron/commit/e974a21)) +* change `hasData` to 0 in `output` ([04b1176](https://github.com/nervosnetwork/neuron/commit/04b1176)) + + +### Features + +* bump sdk to v0.22.0 ([b6e3035](https://github.com/nervosnetwork/neuron/commit/b6e3035)) +* **neuron-ui:** add a toggle of skip-data-and-type ([9cb7c62](https://github.com/nervosnetwork/neuron/commit/9cb7c62)) +* **neuron-ui:** extend the width of tx type field to 70 px ([513c7d9](https://github.com/nervosnetwork/neuron/commit/513c7d9)) +* **neuron-ui:** update the view of transaction detail ([#965](https://github.com/nervosnetwork/neuron/issues/965)) ([ca38b40](https://github.com/nervosnetwork/neuron/commit/ca38b40)) +* enable copy the mainnet addresses when it's not connected to the mainnet ([6b3952f](https://github.com/nervosnetwork/neuron/commit/6b3952f)) + + + # [0.21.0-beta.1](https://github.com/nervosnetwork/neuron/compare/v0.21.0-beta.0...v0.21.0-beta.1) (2019-09-27)