Browse Source

Returns also transactions when scanning accounts

master
meriadec 7 years ago
parent
commit
4ea7bc951d
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 22
      src/components/modals/AddAccount/03-step-import.js
  2. 7
      src/components/modals/AddAccount/index.js
  3. 35
      src/internals/usb/wallet/scanAccountsOnDevice.js

22
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[],

7
src/components/modals/AddAccount/index.js

@ -196,11 +196,10 @@ class AddAccountModal extends PureComponent<Props, State> {
// 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],
}))
}
}

35
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(),

Loading…
Cancel
Save