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. 3
      src/components/modals/AddAccount/index.js
  3. 33
      src/internals/usb/wallet/scanAccountsOnDevice.js

22
src/components/modals/AddAccount/03-step-import.js

@ -1,29 +1,11 @@
// @flow // @flow
import React, { Fragment } from 'react' import React from 'react'
import styled from 'styled-components'
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 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 = { type Props = {
scannedAccounts: Account[], scannedAccounts: Account[],
selectedAccounts: Account[], selectedAccounts: Account[],

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

@ -196,13 +196,12 @@ class AddAccountModal extends PureComponent<Props, State> {
// add it to the reducer if needed, archived // add it to the reducer if needed, archived
if (!existingAccounts.find(a => a.id === account.id)) { if (!existingAccounts.find(a => a.id === account.id)) {
addAccount(account) addAccount(account)
}
this.setState(state => ({ this.setState(state => ({
scannedAccounts: [...state.scannedAccounts, account], scannedAccounts: [...state.scannedAccounts, account],
})) }))
} }
} }
}
handleChangeDevice = d => this.setState({ deviceSelected: d }) handleChangeDevice = d => this.setState({ deviceSelected: d })

33
src/internals/usb/wallet/scanAccountsOnDevice.js

@ -81,7 +81,9 @@ async function scanNextAccount(props) {
? await wallet.getAccount(accountIndex) ? await wallet.getAccount(accountIndex)
: await core.createAccount(wallet, hwApp) : await core.createAccount(wallet, hwApp)
if (!hasBeenScanned) {
await core.syncAccount(njsAccount) await core.syncAccount(njsAccount)
}
const query = njsAccount.queryOperations() const query = njsAccount.queryOperations()
const ops = await query.limit(OPS_LIMIT).execute() const ops = await query.limit(OPS_LIMIT).execute()
@ -93,18 +95,19 @@ async function scanNextAccount(props) {
currencyId, currencyId,
core, core,
hwApp, hwApp,
ops,
}) })
// trigger event
onAccountScanned(account)
accounts.push(account)
// returns if the current index points on an account with no ops // returns if the current index points on an account with no ops
if (ops.length === 0) { if (ops.length === 0) {
return accounts return accounts
} }
// trigger event
onAccountScanned(account)
accounts.push(account)
return scanNextAccount({ ...props, accountIndex: accountIndex + 1 }) return scanNextAccount({ ...props, accountIndex: accountIndex + 1 })
} }
@ -128,6 +131,7 @@ async function buildRawAccount({
// core, // core,
hwApp, hwApp,
accountIndex, accountIndex,
ops,
}: { }: {
njsAccount: NJSAccount, njsAccount: NJSAccount,
wallet: NJSWallet, wallet: NJSWallet,
@ -135,6 +139,7 @@ async function buildRawAccount({
accountIndex: number, accountIndex: number,
core: Object, core: Object,
hwApp: Object, hwApp: Object,
ops: NJSOperation[],
}) { }) {
const jsCurrency = getCryptoCurrencyById(currencyId) const jsCurrency = getCryptoCurrencyById(currencyId)
@ -168,6 +173,22 @@ async function buildRawAccount({
path: `${accountPath}/${i}'`, 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 = { const rawAccount: AccountRaw = {
id: xpub, id: xpub,
xpub, xpub,
@ -181,7 +202,7 @@ async function buildRawAccount({
archived: false, archived: false,
index: accountIndex, index: accountIndex,
balanceByDay: {}, balanceByDay: {},
operations: [], operations,
currencyId, currencyId,
unitMagnitude: jsCurrency.units[0].magnitude, unitMagnitude: jsCurrency.units[0].magnitude,
lastSyncDate: new Date().toISOString(), lastSyncDate: new Date().toISOString(),

Loading…
Cancel
Save