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 type { Dispatch } from 'redux'
import { startSyncAccounts } from 'renderer/events'
function sortAccounts(accounts, orderAccounts) { function sortAccounts(accounts, orderAccounts) {
const [order, sort] = orderAccounts.split('|') 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 type { T } from 'types/common'
import { colors } from 'styles/theme' import { colors } from 'styles/theme'
import { runJob } from 'renderer/events'
import { getVisibleAccounts } from 'reducers/accounts' import { getVisibleAccounts } from 'reducers/accounts'
import { getCounterValueCode, localeSelector } from 'reducers/settings' import { getCounterValueCode, localeSelector } from 'reducers/settings'
@ -36,7 +35,6 @@ import AccountCard from './AccountCard'
import AccountsOrder from './AccountsOrder' import AccountsOrder from './AccountsOrder'
const mapStateToProps = state => ({ const mapStateToProps = state => ({
devices: state.devices,
accounts: getVisibleAccounts(state), accounts: getVisibleAccounts(state),
counterValue: getCounterValueCode(state), counterValue: getCounterValueCode(state),
locale: localeSelector(state), locale: localeSelector(state),
@ -133,55 +131,13 @@ class DashboardPage extends PureComponent<Props, State> {
_cacheBalance = null _cacheBalance = null
render() { render() {
const { push, accounts, t, counterValue, devices } = this.props const { push, accounts, t, counterValue } = this.props
const { accountsChunk, selectedTime, daysCount } = this.state const { accountsChunk, selectedTime, daysCount } = this.state
const timeFrame = this.handleGreeting() const timeFrame = this.handleGreeting()
const totalAccounts = accounts.length const totalAccounts = accounts.length
const { currentDevice } = devices
return ( return (
<Box flow={7}> <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 horizontal alignItems="flex-end">
<Box grow> <Box grow>
<Text color="dark" ff="Museo Sans" fontSize={7}> <Text color="dark" ff="Museo Sans" fontSize={7}>

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

@ -26,7 +26,7 @@ type Props = {
onAccountScanned: Function, onAccountScanned: Function,
} }
export default async function scanAccountsOnDevice(props: Props): AccountRaw[] { export default async function scanAccountsOnDevice(props: Props): Promise<AccountRaw[]> {
const { devicePath, currencyId, onAccountScanned } = props const { devicePath, currencyId, onAccountScanned } = props
// instanciate app on device // instanciate app on device
@ -134,11 +134,13 @@ async function buildRawAccount({
ops, ops,
}: { }: {
njsAccount: NJSAccount, njsAccount: NJSAccount,
// $FlowFixMe
wallet: NJSWallet, wallet: NJSWallet,
currencyId: string, currencyId: string,
accountIndex: number, accountIndex: number,
core: Object, core: Object,
hwApp: Object, hwApp: Object,
// $FlowFixMe
ops: NJSOperation[], ops: NJSOperation[],
}) { }) {
const jsCurrency = getCryptoCurrencyById(currencyId) const jsCurrency = getCryptoCurrencyById(currencyId)
@ -178,6 +180,7 @@ async function buildRawAccount({
return { return {
id: hash, id: hash,
hash, hash,
address: '',
senders: op.getSenders(), senders: op.getSenders(),
recipients: op.getRecipients(), recipients: op.getRecipients(),
// TODO: find why NJSAmount not working // TODO: find why NJSAmount not working
@ -217,8 +220,11 @@ async function buildRawAccount({
*/ */
function createXPUB(depth, fingerprint, childnum, chaincode, publicKey, network) { function createXPUB(depth, fingerprint, childnum, chaincode, publicKey, network) {
let xpub = toHexInt(network) let xpub = toHexInt(network)
// $FlowFixMe
xpub += padStart(depth.toString(16), 2, '0') xpub += padStart(depth.toString(16), 2, '0')
// $FlowFixMe
xpub += padStart(fingerprint.toString(16), 8, '0') xpub += padStart(fingerprint.toString(16), 8, '0')
// $FlowFixMe
xpub += padStart(childnum.toString(16), 8, '0') xpub += padStart(childnum.toString(16), 8, '0')
xpub += chaincode xpub += chaincode
xpub += publicKey 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 every from 'lodash/every'
import get from 'lodash/get' import get from 'lodash/get'
import reduce from 'lodash/reduce' 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' import type { State } from 'reducers'
@ -116,7 +116,10 @@ export function canCreateAccount(state: State): boolean {
} }
export function decodeAccount(account: AccountRaw): Account { 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 // Yeah. `any` should be `AccountRaw[]` but it can also be a map

Loading…
Cancel
Save