From a4799dba433f80712037e86defe7c4a8d3312026 Mon Sep 17 00:00:00 2001 From: meriadec Date: Sat, 12 May 2018 18:05:47 +0200 Subject: [PATCH] Upd README, change rootPath to walletPath & add isSegwit in account --- README.md | 4 +- src/components/ReceiveBox.js | 2 +- src/internals/accounts/index.js | 13 +++++- .../accounts/scanAccountsOnDevice.js | 45 ++++++++++--------- src/renderer/events.js | 4 +- 5 files changed, 40 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 1c22f810..a024deb4 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ yarn # ENV VARIABLES # ------------- -# Where errors will be tracked -SENTRY_URL=http://... +# Where errors will be tracked (you may not want to edit this line) +# SENTRY_URL= # OPTIONAL ENV VARIABLES # ---------------------- diff --git a/src/components/ReceiveBox.js b/src/components/ReceiveBox.js index d0fb9340..b9f9656a 100644 --- a/src/components/ReceiveBox.js +++ b/src/components/ReceiveBox.js @@ -115,7 +115,7 @@ class ReceiveBox extends PureComponent { if (currentDevice !== null) { sendEvent('usb', 'wallet.verifyAddress', { pathDevice: currentDevice.path, - path: `${account.rootPath}${account.path}`, + path: `${account.walletPath}${account.path}`, }) this.setState({ diff --git a/src/internals/accounts/index.js b/src/internals/accounts/index.js index 2d3837e7..8ec8433b 100644 --- a/src/internals/accounts/index.js +++ b/src/internals/accounts/index.js @@ -32,7 +32,7 @@ export default { }) send('accounts.scanAccountsOnDevice.success', accounts) } catch (err) { - send('accounts.scanAccountsOnDevice.fail', err) + send('accounts.scanAccountsOnDevice.fail', formatErr(err)) } }, @@ -67,3 +67,14 @@ export default { } }, } + +// TODO: move this to a helper +function formatErr(err) { + if (err instanceof Error) { + return err.message || err.code + } + if (typeof err === 'string') { + return err + } + return 'unknown error' +} diff --git a/src/internals/accounts/scanAccountsOnDevice.js b/src/internals/accounts/scanAccountsOnDevice.js index 156e48b6..526bdddd 100644 --- a/src/internals/accounts/scanAccountsOnDevice.js +++ b/src/internals/accounts/scanAccountsOnDevice.js @@ -119,6 +119,7 @@ async function scanNextAccount(props) { const account = await buildRawAccount({ njsAccount, + isSegwit, accountIndex, wallet, currencyId, @@ -162,14 +163,16 @@ async function getOrCreateWallet(WALLET_IDENTIFIER, currencyId, isSegwit) { async function buildRawAccount({ njsAccount, + isSegwit, wallet, currencyId, - // core, + core, hwApp, accountIndex, ops, }: { njsAccount: NJSAccount, + isSegwit: boolean, // $FlowFixMe wallet: NJSWallet, currencyId: string, @@ -179,13 +182,13 @@ async function buildRawAccount({ // $FlowFixMe ops: NJSOperation[], }) { - // const njsBalanceHistory = await njsAccount.getBalanceHistory( - // new Date('2018-05-01').toISOString(), - // new Date('2018-06-01').toISOString(), - // core.TIME_PERIODS.DAY, - // ) + const njsBalanceHistory = await njsAccount.getBalanceHistory( + new Date('2018-05-01').toISOString(), + new Date('2018-06-01').toISOString(), + core.TIME_PERIODS.DAY, + ) - // const balanceHistory = njsBalanceHistory.map(njsAmount => njsAmount.toLong()) + const balanceHistory = njsBalanceHistory.map(njsAmount => njsAmount.toLong()) const njsBalance = await njsAccount.getBalance() const balance = njsBalance.toLong() @@ -198,23 +201,20 @@ async function buildRawAccount({ console.log(`so, the account path is ${accountPath}`) - const VERIFY = false - const isSegwit = true + const isVerify = false const { publicKey, chainCode, bitcoinAddress } = await hwApp.getWalletPublicKey( accountPath, - VERIFY, + isVerify, isSegwit, ) - // TODO: wtf is happening? - // - // const nativeDerivationPath = core.createDerivationPath(accountPath) - // const depth = nativeDerivationPath.getDepth() - const depth = 'depth' - // const childNum = nativeDerivationPath.getChildNum(accountIndex) - const childNum = 'childNum' - // const fingerprint = core.createBtcFingerprint(publicKey) - const fingerprint = 'fingerprint' + const nativeDerivationPath = core.createDerivationPath(accountPath) + const depth = nativeDerivationPath.getDepth() + // const depth = 'depth' + const childNum = nativeDerivationPath.getChildNum(accountIndex) + // const childNum = 'childNum' + const fingerprint = core.createBtcFingerprint(publicKey) + // const fingerprint = 'fingerprint' const { bitcoinLikeNetworkParameters } = wallet.getCurrency() const network = Buffer.from(bitcoinLikeNetworkParameters.XPUBVersion).readUIntBE(0, 4) @@ -250,10 +250,11 @@ async function buildRawAccount({ const rawAccount: AccountRaw = { id: xpub, xpub, - path: accountPath, // TODO: this should be called `accountPath` in Account/AccountRaw types - rootPath: walletPath, // TODO: this should be `walletPath` in Account/AccountRaw types + path: accountPath, + walletPath, name: `Account ${accountIndex}`, // TODO: placeholder name? - address: bitcoinAddress, // TODO: discuss about the utility of storing it here + isSegwit, + address: bitcoinAddress, addresses, balance, blockHeight, diff --git a/src/renderer/events.js b/src/renderer/events.js index 0a702eed..9c5445c1 100644 --- a/src/renderer/events.js +++ b/src/renderer/events.js @@ -167,13 +167,13 @@ export function startSyncAccounts(accounts: Account[]) { syncAccountsInProgress = true sendEvent('accounts', 'sync', { accounts: accounts.map(account => { - const { id, currency, rootPath, addresses, index, operations } = account + const { id, currency, walletPath, addresses, index, operations } = account return { id, currencyId: currency.id, allAddresses: addresses, currentIndex: index, - rootPath, + walletPath, operations, } }),