Browse Source

Upd README, change rootPath to walletPath & add isSegwit in account

master
meriadec 7 years ago
parent
commit
a4799dba43
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 4
      README.md
  2. 2
      src/components/ReceiveBox.js
  3. 13
      src/internals/accounts/index.js
  4. 45
      src/internals/accounts/scanAccountsOnDevice.js
  5. 4
      src/renderer/events.js

4
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
# ----------------------

2
src/components/ReceiveBox.js

@ -115,7 +115,7 @@ class ReceiveBox extends PureComponent<Props, State> {
if (currentDevice !== null) {
sendEvent('usb', 'wallet.verifyAddress', {
pathDevice: currentDevice.path,
path: `${account.rootPath}${account.path}`,
path: `${account.walletPath}${account.path}`,
})
this.setState({

13
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'
}

45
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,

4
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,
}
}),

Loading…
Cancel
Save