From 82906be335df45c053a0cb7de42f2920f5412f1b Mon Sep 17 00:00:00 2001 From: meriadec Date: Tue, 22 May 2018 15:22:03 +0200 Subject: [PATCH] Enforce flow in scanAccountsOnDevice --- .../accounts/scanAccountsOnDevice.js | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/internals/accounts/scanAccountsOnDevice.js b/src/internals/accounts/scanAccountsOnDevice.js index d0e7245c..3dbbed7b 100644 --- a/src/internals/accounts/scanAccountsOnDevice.js +++ b/src/internals/accounts/scanAccountsOnDevice.js @@ -56,7 +56,7 @@ export async function getWalletIdentifier({ isSegwit: boolean, currencyId: string, devicePath: string, -}) { +}): Promise { const isVerify = false const deviceIdentifiers = await hwApp.getWalletPublicKey(devicePath, isVerify, isSegwit) const { publicKey } = deviceIdentifiers @@ -70,7 +70,13 @@ async function scanAccountsOnDeviceBySegwit({ onAccountScanned, devicePath, isSegwit, -}) { +}: { + hwApp: Object, + currencyId: string, + onAccountScanned: AccountRaw => void, + devicePath: string, + isSegwit: boolean, +}): Promise { // compute wallet identifier const WALLET_IDENTIFIER = await getWalletIdentifier({ hwApp, isSegwit, currencyId, devicePath }) @@ -94,7 +100,17 @@ async function scanAccountsOnDeviceBySegwit({ 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 { const { wallet, hwApp, @@ -150,7 +166,11 @@ async function scanNextAccount(props) { 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 const core = require('init-ledger-core')() try { @@ -190,7 +210,7 @@ async function buildAccountRaw({ hwApp: Object, // $FlowFixMe ops: NJSOperation[], -}) { +}): Promise { const balanceByDay = ops.length ? await getBalanceByDaySinceOperation({ njsAccount, @@ -309,7 +329,7 @@ async function getBalanceByDaySinceOperation({ return res } -function areSameDay(date1, date2) { +function areSameDay(date1: Date, date2: Date): boolean { return ( date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() &&