Browse Source

Fix getAddress

master
Gaëtan Renaudeau 7 years ago
parent
commit
21ceb2b0a9
  1. 3
      src/commands/getAddress.js
  2. 4
      src/commands/isCurrencyAppOpened.js
  3. 3
      src/helpers/getAddressForCurrency/btc.js
  4. 3
      src/helpers/getAddressForCurrency/ethereum.js
  5. 17
      src/helpers/getAddressForCurrency/index.js
  6. 3
      src/helpers/getAddressForCurrency/ripple.js

3
src/commands/getAddress.js

@ -1,5 +1,6 @@
// @flow // @flow
import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/helpers/currencies'
import { createCommand, Command } from 'helpers/ipc' import { createCommand, Command } from 'helpers/ipc'
import { fromPromise } from 'rxjs/observable/fromPromise' import { fromPromise } from 'rxjs/observable/fromPromise'
import { withDevice } from 'helpers/deviceAccess' import { withDevice } from 'helpers/deviceAccess'
@ -24,7 +25,7 @@ const cmd: Command<Input, Result> = createCommand(
({ currencyId, devicePath, path, ...options }) => ({ currencyId, devicePath, path, ...options }) =>
fromPromise( fromPromise(
withDevice(devicePath)(transport => withDevice(devicePath)(transport =>
getAddressForCurrency(currencyId)(transport, currencyId, path, options), getAddressForCurrency(transport, getCryptoCurrencyById(currencyId), path, options),
), ),
), ),
) )

4
src/commands/isCurrencyAppOpened.js

@ -26,9 +26,9 @@ const cmd: Command<Input, Result> = createCommand(
// First, we check if the app can derivates on the currency // First, we check if the app can derivates on the currency
try { try {
await getAddress(currencyId)( await getAddress(
transport, transport,
currencyId, currency,
standardDerivation({ currency, segwit: false, x: 0 }), standardDerivation({ currency, segwit: false, x: 0 }),
{ segwit: false }, { segwit: false },
) )

3
src/helpers/getAddressForCurrency/btc.js

@ -1,11 +1,12 @@
// @flow // @flow
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types'
import Btc from '@ledgerhq/hw-app-btc' import Btc from '@ledgerhq/hw-app-btc'
import type Transport from '@ledgerhq/hw-transport' import type Transport from '@ledgerhq/hw-transport'
export default async ( export default async (
transport: Transport<*>, transport: Transport<*>,
currencyId: string, currency: CryptoCurrency,
path: string, path: string,
{ {
segwit = true, segwit = true,

3
src/helpers/getAddressForCurrency/ethereum.js

@ -1,12 +1,13 @@
// @flow // @flow
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types'
import Eth from '@ledgerhq/hw-app-eth' import Eth from '@ledgerhq/hw-app-eth'
import type Transport from '@ledgerhq/hw-transport' import type Transport from '@ledgerhq/hw-transport'
import eip55 from 'eip55' import eip55 from 'eip55'
export default async ( export default async (
transport: Transport<*>, transport: Transport<*>,
currencyId: string, currency: CryptoCurrency,
path: string, path: string,
{ verify = false }: *, { verify = false }: *,
) => { ) => {

17
src/helpers/getAddressForCurrency/index.js

@ -1,5 +1,6 @@
// @flow // @flow
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types'
import invariant from 'invariant' import invariant from 'invariant'
import type Transport from '@ledgerhq/hw-transport' import type Transport from '@ledgerhq/hw-transport'
import bitcoin from './btc' import bitcoin from './btc'
@ -8,7 +9,7 @@ import ripple from './ripple'
type Resolver = ( type Resolver = (
transport: Transport<*>, transport: Transport<*>,
currencyId: string, currency: CryptoCurrency,
path: string, path: string,
options: { options: {
segwit?: boolean, segwit?: boolean,
@ -16,18 +17,16 @@ type Resolver = (
}, },
) => Promise<{ address: string, path: string, publicKey: string }> ) => Promise<{ address: string, path: string, publicKey: string }>
type Module = (currencyId: string) => Resolver const perFamily: { [_: string]: Resolver } = {
const perFamily = {
bitcoin, bitcoin,
ethereum, ethereum,
ripple, ripple,
} }
const getAddressForCurrency: Module = (currencyId: string) => { const proxy: Resolver = (transport, currency, path, options) => {
const getAddress = perFamily[currencyId] const getAddress = perFamily[currency.family]
invariant(getAddress, `getAddress not implemented for ${currencyId}`) invariant(getAddress, `getAddress not implemented for ${currency.id}`)
return getAddress return getAddress(transport, currency, path, options)
} }
export default getAddressForCurrency export default proxy

3
src/helpers/getAddressForCurrency/ripple.js

@ -2,10 +2,11 @@
import Xrp from '@ledgerhq/hw-app-xrp' import Xrp from '@ledgerhq/hw-app-xrp'
import type Transport from '@ledgerhq/hw-transport' import type Transport from '@ledgerhq/hw-transport'
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types'
export default async ( export default async (
transport: Transport<*>, transport: Transport<*>,
currencyId: string, currency: CryptoCurrency,
path: string, path: string,
{ verify = false }: *, { verify = false }: *,
) => { ) => {

Loading…
Cancel
Save