Browse Source

drop getWalletIdentifier & replace by encodeWalletName

master
Gaëtan Renaudeau 7 years ago
parent
commit
de572e843c
  1. 38
      src/helpers/libcore.js

38
src/helpers/libcore.js

@ -34,10 +34,9 @@ export function scanAccountsOnDevice(props: Props): Promise<AccountRaw[]> {
const commonParams = { const commonParams = {
core, core,
hwApp,
currencyId, currencyId,
onAccountScanned, onAccountScanned,
devicePath, hwApp,
} }
let allAccounts = [] let allAccounts = []
@ -62,22 +61,16 @@ export function scanAccountsOnDevice(props: Props): Promise<AccountRaw[]> {
}) })
} }
export async function getWalletIdentifier({ function encodeWalletName({
hwApp, publicKey,
isSegwit,
currencyId, currencyId,
devicePath, isSegwit,
}: { }: {
hwApp: Object, publicKey: string,
isSegwit: boolean,
currencyId: string, currencyId: string,
devicePath: string, isSegwit: boolean,
}): Promise<string> { }) {
const isVerify = false return `${publicKey}__${currencyId}${isSegwit ? '_segwit' : ''}`
const deviceIdentifiers = await hwApp.getWalletPublicKey(devicePath, isVerify, isSegwit)
const { publicKey } = deviceIdentifiers
const WALLET_IDENTIFIER = `${publicKey}__${currencyId}${isSegwit ? '_segwit' : ''}`
return WALLET_IDENTIFIER
} }
async function scanAccountsOnDeviceBySegwit({ async function scanAccountsOnDeviceBySegwit({
@ -85,7 +78,6 @@ async function scanAccountsOnDeviceBySegwit({
hwApp, hwApp,
currencyId, currencyId,
onAccountScanned, onAccountScanned,
devicePath,
isSegwit, isSegwit,
showNewAccount, showNewAccount,
}: { }: {
@ -93,15 +85,19 @@ async function scanAccountsOnDeviceBySegwit({
hwApp: Object, hwApp: Object,
currencyId: string, currencyId: string,
onAccountScanned: AccountRaw => void, onAccountScanned: AccountRaw => void,
devicePath: string, isSegwit: boolean, // FIXME all segwit to change to 'purpose'
isSegwit: boolean,
showNewAccount: boolean, showNewAccount: boolean,
}): Promise<AccountRaw[]> { }): Promise<AccountRaw[]> {
// compute wallet identifier const { coinType } = getCryptoCurrencyById(currencyId)
const WALLET_IDENTIFIER = await getWalletIdentifier({ hwApp, isSegwit, currencyId, devicePath }) const { publicKey } = await hwApp.getWalletPublicKey(
`${isSegwit ? '49' : '44'}'/${coinType}'`,
false,
isSegwit,
)
const walletName = encodeWalletName({ publicKey, currencyId, isSegwit })
// retrieve or create the wallet // retrieve or create the wallet
const wallet = await getOrCreateWallet(core, WALLET_IDENTIFIER, currencyId, isSegwit) const wallet = await getOrCreateWallet(core, walletName, currencyId, isSegwit)
const accountsCount = await wallet.getAccountCount() const accountsCount = await wallet.getAccountCount()
// recursively scan all accounts on device on the given app // recursively scan all accounts on device on the given app

Loading…
Cancel
Save