diff --git a/src/components/modals/AddAccount/03-step-import.js b/src/components/modals/AddAccount/03-step-import.js index c42428a4..ac635649 100644 --- a/src/components/modals/AddAccount/03-step-import.js +++ b/src/components/modals/AddAccount/03-step-import.js @@ -1,29 +1,11 @@ // @flow -import React, { Fragment } from 'react' -import styled from 'styled-components' +import React from 'react' -import type { CryptoCurrency, Account } from '@ledgerhq/live-common/lib/types' +import type { Account } from '@ledgerhq/live-common/lib/types' import Box from 'components/base/Box' -import AccountCard from 'components/DashboardPage/AccountCard' - -const AccountsContainer = styled(Box).attrs({ - horizontal: true, - m: -2, -})` - flex-wrap: wrap; -` -const AccountItemWrapper = styled(Box).attrs({ - p: 2, -})` - width: 50%; -` -const AccountItem = styled(AccountCard)` - ${p => p.selected && `box-shadow: inset 0 0 0 1px ${p.theme.colors.wallet};`}; -` - type Props = { scannedAccounts: Account[], selectedAccounts: Account[], diff --git a/src/components/modals/AddAccount/index.js b/src/components/modals/AddAccount/index.js index c612d2f1..0e39e527 100644 --- a/src/components/modals/AddAccount/index.js +++ b/src/components/modals/AddAccount/index.js @@ -196,11 +196,10 @@ class AddAccountModal extends PureComponent { // add it to the reducer if needed, archived if (!existingAccounts.find(a => a.id === account.id)) { addAccount(account) + this.setState(state => ({ + scannedAccounts: [...state.scannedAccounts, account], + })) } - - this.setState(state => ({ - scannedAccounts: [...state.scannedAccounts, account], - })) } } diff --git a/src/internals/usb/wallet/scanAccountsOnDevice.js b/src/internals/usb/wallet/scanAccountsOnDevice.js index e593fafa..83a84e08 100644 --- a/src/internals/usb/wallet/scanAccountsOnDevice.js +++ b/src/internals/usb/wallet/scanAccountsOnDevice.js @@ -81,7 +81,9 @@ async function scanNextAccount(props) { ? await wallet.getAccount(accountIndex) : await core.createAccount(wallet, hwApp) - await core.syncAccount(njsAccount) + if (!hasBeenScanned) { + await core.syncAccount(njsAccount) + } const query = njsAccount.queryOperations() const ops = await query.limit(OPS_LIMIT).execute() @@ -93,18 +95,19 @@ async function scanNextAccount(props) { currencyId, core, hwApp, + ops, }) - // trigger event - onAccountScanned(account) - - accounts.push(account) - // returns if the current index points on an account with no ops if (ops.length === 0) { return accounts } + // trigger event + onAccountScanned(account) + + accounts.push(account) + return scanNextAccount({ ...props, accountIndex: accountIndex + 1 }) } @@ -128,6 +131,7 @@ async function buildRawAccount({ // core, hwApp, accountIndex, + ops, }: { njsAccount: NJSAccount, wallet: NJSWallet, @@ -135,6 +139,7 @@ async function buildRawAccount({ accountIndex: number, core: Object, hwApp: Object, + ops: NJSOperation[], }) { const jsCurrency = getCryptoCurrencyById(currencyId) @@ -168,6 +173,22 @@ async function buildRawAccount({ path: `${accountPath}/${i}'`, })) + const operations = ops.map(op => { + const hash = op.getUid() + return { + id: hash, + hash, + senders: op.getSenders(), + recipients: op.getRecipients(), + // TODO: find why NJSAmount not working + // amount: op.getAmount().toInt(), + amount: 0, + blockHeight: op.getBlockHeight(), + accountId: xpub, + date: op.getDate().toISOString(), + } + }) + const rawAccount: AccountRaw = { id: xpub, xpub, @@ -181,7 +202,7 @@ async function buildRawAccount({ archived: false, index: accountIndex, balanceByDay: {}, - operations: [], + operations, currencyId, unitMagnitude: jsCurrency.units[0].magnitude, lastSyncDate: new Date().toISOString(),