Browse Source

Flow & pal

master
meriadec 7 years ago
parent
commit
17a7f314a7
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 2
      src/actions/accounts.js
  2. 46
      src/components/DashboardPage/index.js
  3. 8
      src/internals/usb/wallet/scanAccountsOnDevice.js
  4. 7
      src/reducers/accounts.js

2
src/actions/accounts.js

@ -7,8 +7,6 @@ import db from 'helpers/db'
import type { Dispatch } from 'redux'
import { startSyncAccounts } from 'renderer/events'
function sortAccounts(accounts, orderAccounts) {
const [order, sort] = orderAccounts.split('|')

46
src/components/DashboardPage/index.js

@ -17,7 +17,6 @@ import type { Account } from '@ledgerhq/live-common/lib/types'
import type { T } from 'types/common'
import { colors } from 'styles/theme'
import { runJob } from 'renderer/events'
import { getVisibleAccounts } from 'reducers/accounts'
import { getCounterValueCode, localeSelector } from 'reducers/settings'
@ -36,7 +35,6 @@ import AccountCard from './AccountCard'
import AccountsOrder from './AccountsOrder'
const mapStateToProps = state => ({
devices: state.devices,
accounts: getVisibleAccounts(state),
counterValue: getCounterValueCode(state),
locale: localeSelector(state),
@ -133,55 +131,13 @@ class DashboardPage extends PureComponent<Props, State> {
_cacheBalance = null
render() {
const { push, accounts, t, counterValue, devices } = this.props
const { push, accounts, t, counterValue } = this.props
const { accountsChunk, selectedTime, daysCount } = this.state
const timeFrame = this.handleGreeting()
const totalAccounts = accounts.length
const { currentDevice } = devices
return (
<Box flow={7}>
{currentDevice && (
<Box p={8}>
<button
onClick={async () => {
const freshAddress = await runJob({
channel: 'usb',
job: 'wallet.getFreshReceiveAddress',
successResponse: 'wallet.getFreshReceiveAddress.success',
errorResponse: 'wallet.getFreshReceiveAddress.fail',
data: {
accountIndex: accounts[0].index,
currencyId: 'bitcoin_testnet',
},
})
console.log(freshAddress)
}}
>
{'get fresh address'}
</button>
{currentDevice.path}
<button
onClick={async () => {
const accounts = await runJob({
channel: 'usb',
job: 'wallet.scanAccountsOnDevice',
successResponse: 'wallet.scanAccountsOnDevice.success',
errorResponse: 'wallet.scanAccountsOnDevice.fail',
data: {
devicePath: currentDevice.path,
currencyId: 'bitcoin_testnet',
},
})
console.log(accounts)
}}
>
{'scan accounts on device'}
</button>
</Box>
)}
<Box horizontal alignItems="flex-end">
<Box grow>
<Text color="dark" ff="Museo Sans" fontSize={7}>

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

@ -26,7 +26,7 @@ type Props = {
onAccountScanned: Function,
}
export default async function scanAccountsOnDevice(props: Props): AccountRaw[] {
export default async function scanAccountsOnDevice(props: Props): Promise<AccountRaw[]> {
const { devicePath, currencyId, onAccountScanned } = props
// instanciate app on device
@ -134,11 +134,13 @@ async function buildRawAccount({
ops,
}: {
njsAccount: NJSAccount,
// $FlowFixMe
wallet: NJSWallet,
currencyId: string,
accountIndex: number,
core: Object,
hwApp: Object,
// $FlowFixMe
ops: NJSOperation[],
}) {
const jsCurrency = getCryptoCurrencyById(currencyId)
@ -178,6 +180,7 @@ async function buildRawAccount({
return {
id: hash,
hash,
address: '',
senders: op.getSenders(),
recipients: op.getRecipients(),
// TODO: find why NJSAmount not working
@ -217,8 +220,11 @@ async function buildRawAccount({
*/
function createXPUB(depth, fingerprint, childnum, chaincode, publicKey, network) {
let xpub = toHexInt(network)
// $FlowFixMe
xpub += padStart(depth.toString(16), 2, '0')
// $FlowFixMe
xpub += padStart(fingerprint.toString(16), 8, '0')
// $FlowFixMe
xpub += padStart(childnum.toString(16), 8, '0')
xpub += chaincode
xpub += publicKey

7
src/reducers/accounts.js

@ -7,7 +7,7 @@ import { createAccountModel } from '@ledgerhq/live-common/lib/models/account'
import every from 'lodash/every'
import get from 'lodash/get'
import reduce from 'lodash/reduce'
import type { Account } from '@ledgerhq/live-common/lib/types'
import type { Account, AccountRaw } from '@ledgerhq/live-common/lib/types'
import type { State } from 'reducers'
@ -116,7 +116,10 @@ export function canCreateAccount(state: State): boolean {
}
export function decodeAccount(account: AccountRaw): Account {
return accountModel.decode({ data: account })
return accountModel.decode({
data: account,
version: 0, // TODO: should we keep v0 ?
})
}
// Yeah. `any` should be `AccountRaw[]` but it can also be a map

Loading…
Cancel
Save