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
import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/helpers/currencies'
import { createCommand, Command } from 'helpers/ipc'
import { fromPromise } from 'rxjs/observable/fromPromise'
import { withDevice } from 'helpers/deviceAccess'
@ -24,7 +25,7 @@ const cmd: Command<Input, Result> = createCommand(
({ currencyId, devicePath, path, ...options }) =>
fromPromise(
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
try {
await getAddress(currencyId)(
await getAddress(
transport,
currencyId,
currency,
standardDerivation({ currency, segwit: false, x: 0 }),
{ segwit: false },
)

3
src/helpers/getAddressForCurrency/btc.js

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

3
src/helpers/getAddressForCurrency/ethereum.js

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

17
src/helpers/getAddressForCurrency/index.js

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

Loading…
Cancel
Save