Browse Source

Enforce flow in scanAccountsOnDevice

master
meriadec 7 years ago
parent
commit
82906be335
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 32
      src/internals/accounts/scanAccountsOnDevice.js

32
src/internals/accounts/scanAccountsOnDevice.js

@ -56,7 +56,7 @@ export async function getWalletIdentifier({
isSegwit: boolean, isSegwit: boolean,
currencyId: string, currencyId: string,
devicePath: string, devicePath: string,
}) { }): Promise<string> {
const isVerify = false const isVerify = false
const deviceIdentifiers = await hwApp.getWalletPublicKey(devicePath, isVerify, isSegwit) const deviceIdentifiers = await hwApp.getWalletPublicKey(devicePath, isVerify, isSegwit)
const { publicKey } = deviceIdentifiers const { publicKey } = deviceIdentifiers
@ -70,7 +70,13 @@ async function scanAccountsOnDeviceBySegwit({
onAccountScanned, onAccountScanned,
devicePath, devicePath,
isSegwit, isSegwit,
}) { }: {
hwApp: Object,
currencyId: string,
onAccountScanned: AccountRaw => void,
devicePath: string,
isSegwit: boolean,
}): Promise<AccountRaw[]> {
// compute wallet identifier // compute wallet identifier
const WALLET_IDENTIFIER = await getWalletIdentifier({ hwApp, isSegwit, currencyId, devicePath }) const WALLET_IDENTIFIER = await getWalletIdentifier({ hwApp, isSegwit, currencyId, devicePath })
@ -94,7 +100,17 @@ async function scanAccountsOnDeviceBySegwit({
return accounts return accounts
} }
async function scanNextAccount(props) { async function scanNextAccount(props: {
// $FlowFixMe
wallet: NJSWallet,
hwApp: Object,
currencyId: string,
accountsCount: number,
accountIndex: number,
accounts: AccountRaw[],
onAccountScanned: AccountRaw => void,
isSegwit: boolean,
}): Promise<AccountRaw[]> {
const { const {
wallet, wallet,
hwApp, hwApp,
@ -150,7 +166,11 @@ async function scanNextAccount(props) {
return scanNextAccount({ ...props, accountIndex: accountIndex + 1 }) return scanNextAccount({ ...props, accountIndex: accountIndex + 1 })
} }
async function getOrCreateWallet(WALLET_IDENTIFIER, currencyId, isSegwit) { async function getOrCreateWallet(
WALLET_IDENTIFIER: string,
currencyId: string,
isSegwit: boolean,
): NJSWallet {
// TODO: investigate why importing it on file scope causes trouble // TODO: investigate why importing it on file scope causes trouble
const core = require('init-ledger-core')() const core = require('init-ledger-core')()
try { try {
@ -190,7 +210,7 @@ async function buildAccountRaw({
hwApp: Object, hwApp: Object,
// $FlowFixMe // $FlowFixMe
ops: NJSOperation[], ops: NJSOperation[],
}) { }): Promise<AccountRaw> {
const balanceByDay = ops.length const balanceByDay = ops.length
? await getBalanceByDaySinceOperation({ ? await getBalanceByDaySinceOperation({
njsAccount, njsAccount,
@ -309,7 +329,7 @@ async function getBalanceByDaySinceOperation({
return res return res
} }
function areSameDay(date1, date2) { function areSameDay(date1: Date, date2: Date): boolean {
return ( return (
date1.getFullYear() === date2.getFullYear() && date1.getFullYear() === date2.getFullYear() &&
date1.getMonth() === date2.getMonth() && date1.getMonth() === date2.getMonth() &&

Loading…
Cancel
Save