Browse Source

Libcore will now suggest new account to create

for now we do both for segwit & non segwit because some coin don't even have segwit
master
Gaëtan Renaudeau 7 years ago
parent
commit
9d5bbab53b
  1. 2
      package.json
  2. 4
      src/helpers/getAddressForCurrency/btc.js
  3. 5
      src/helpers/getAddressForCurrency/index.js
  4. 18
      src/internals/accounts/scanAccountsOnDevice.js
  5. 906
      yarn.lock

2
package.json

@ -41,7 +41,7 @@
"@ledgerhq/hw-app-xrp": "^4.12.0", "@ledgerhq/hw-app-xrp": "^4.12.0",
"@ledgerhq/hw-transport": "^4.12.0", "@ledgerhq/hw-transport": "^4.12.0",
"@ledgerhq/hw-transport-node-hid": "^4.12.0", "@ledgerhq/hw-transport-node-hid": "^4.12.0",
"@ledgerhq/ledger-core": "^1.2.0", "@ledgerhq/ledger-core": "^1.2.1",
"@ledgerhq/live-common": "^2.9.1", "@ledgerhq/live-common": "^2.9.1",
"axios": "^0.18.0", "axios": "^0.18.0",
"babel-runtime": "^6.26.0", "babel-runtime": "^6.26.0",

4
src/helpers/getAddressForCurrency/btc.js

@ -11,8 +11,8 @@ export default async (
segwit = true, segwit = true,
verify = false, verify = false,
}: { }: {
segwit: boolean, segwit?: boolean,
verify: boolean, verify?: boolean,
}, },
) => { ) => {
const btc = new Btc(transport) const btc = new Btc(transport)

5
src/helpers/getAddressForCurrency/index.js

@ -21,6 +21,11 @@ const all = {
bitcoin: btc, bitcoin: btc,
bitcoin_testnet: btc, bitcoin_testnet: btc,
zcash: btc,
bitcoin_cash: btc,
bitcoin_gold: btc,
zencash: btc,
ethereum, ethereum,
ethereum_testnet: ethereum, ethereum_testnet: ethereum,
ethereum_classic: ethereum, ethereum_classic: ethereum,

18
src/internals/accounts/scanAccountsOnDevice.js

@ -35,13 +35,13 @@ export default function scanAccountsOnDevice(props: Props): Promise<AccountRaw[]
} }
// scan segwit AND non-segwit accounts // scan segwit AND non-segwit accounts
const segwitAccounts = await scanAccountsOnDeviceBySegwit({ ...commonParams, isSegwit: true })
const nonSegwitAccounts = await scanAccountsOnDeviceBySegwit({ const nonSegwitAccounts = await scanAccountsOnDeviceBySegwit({
...commonParams, ...commonParams,
isSegwit: false, isSegwit: false,
}) })
const segwitAccounts = await scanAccountsOnDeviceBySegwit({ ...commonParams, isSegwit: true })
const accounts = [...segwitAccounts, ...nonSegwitAccounts] const accounts = [...nonSegwitAccounts, ...segwitAccounts]
return accounts return accounts
}) })
@ -154,16 +154,18 @@ async function scanNextAccount(props: {
ops, ops,
}) })
// returns if the current index points on an account with no ops const isEmpty = ops.length === 0
if (ops.length === 0) {
return accounts
}
// trigger event // trigger event
onAccountScanned(account) onAccountScanned(account)
accounts.push(account) accounts.push(account)
// returns if the current index points on an account with no ops
if (isEmpty) {
return accounts
}
return scanNextAccount({ ...props, accountIndex: accountIndex + 1 }) return scanNextAccount({ ...props, accountIndex: accountIndex + 1 })
} }
@ -259,7 +261,9 @@ async function buildAccountRaw({
id: xpub, // FIXME for account id you might want to prepend the crypto currency id to this because it's not gonna be unique. id: xpub, // FIXME for account id you might want to prepend the crypto currency id to this because it's not gonna be unique.
xpub, xpub,
path: walletPath, path: walletPath,
name: `Account ${accountIndex}${isSegwit ? ' (segwit)' : ''}`, // TODO: placeholder name? name: `${operations.length === 0 ? 'New ' : ''}Account ${accountIndex}${
isSegwit ? ' (segwit)' : ''
}`, // TODO: placeholder name?
isSegwit, isSegwit,
freshAddress, freshAddress,
freshAddressPath, freshAddressPath,

906
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save