diff --git a/src/commands/index.js b/src/commands/index.js index 6d7cb04b..91d0df7b 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -12,7 +12,6 @@ import installApp from 'commands/installApp' import installFinalFirmware from 'commands/installFinalFirmware' import installMcu from 'commands/installMcu' import installOsuFirmware from 'commands/installOsuFirmware' -import isCurrencyAppOpened from 'commands/isCurrencyAppOpened' import isDashboardOpen from 'commands/isDashboardOpen' import libcoreGetVersion from 'commands/libcoreGetVersion' import libcoreScanAccounts from 'commands/libcoreScanAccounts' @@ -37,7 +36,6 @@ const all: Array> = [ installFinalFirmware, installMcu, installOsuFirmware, - isCurrencyAppOpened, isDashboardOpen, libcoreGetVersion, libcoreScanAccounts, diff --git a/src/commands/isCurrencyAppOpened.js b/src/commands/isCurrencyAppOpened.js deleted file mode 100644 index 325bde88..00000000 --- a/src/commands/isCurrencyAppOpened.js +++ /dev/null @@ -1,53 +0,0 @@ -// @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' -import getBitcoinLikeInfo from 'helpers/devices/getBitcoinLikeInfo' -import getAddress from 'helpers/getAddressForCurrency' -import { standardDerivation } from 'helpers/derivations' - -type Input = { - devicePath: string, - currencyId: string, -} - -type Result = boolean - -const cmd: Command = createCommand( - 'isCurrencyAppOpened', - ({ devicePath, currencyId }) => - fromPromise( - withDevice(devicePath)(async transport => { - const currency = getCryptoCurrencyById(currencyId) - - // First, we check if the app can derivates on the currency - try { - await getAddress( - transport, - currency, - standardDerivation({ currency, segwit: false, x: 0 }), - { segwit: false }, - ) - - // then, just in case of BTC, we need to make sure we are on the correct BTC fork - const { bitcoinLikeInfo } = currency - if (bitcoinLikeInfo) { - const { P2SH, P2PKH } = await getBitcoinLikeInfo(transport) - return P2SH === bitcoinLikeInfo.P2SH && P2PKH === bitcoinLikeInfo.P2PKH - } - - // in case of ETH / XRP, the address derivation is enough - return true - } catch (e) { - // if anything failed, it does not pass - return false - } - }), - ), -) - -export default cmd diff --git a/src/components/DeviceConnect/index.js b/src/components/DeviceConnect/index.js index 882d745e..fc6a6af3 100644 --- a/src/components/DeviceConnect/index.js +++ b/src/components/DeviceConnect/index.js @@ -138,7 +138,6 @@ StepCheck.defaultProps = { } type Props = { - accountName: null | string, appOpened: null | 'success' | 'fail', genuineCheckStatus: null | 'success' | 'fail', withGenuineCheck: boolean, @@ -188,7 +187,6 @@ class DeviceConnect extends PureComponent { withGenuineCheck, appOpened, errorMessage, - accountName, currency, t, onChangeDevice, @@ -311,14 +309,7 @@ class DeviceConnect extends PureComponent { - {accountName ? ( - - {'You must use the device associated to the account '} - {accountName} - - ) : ( - String(errorMessage || '') - )} + {String(errorMessage || '')} ) : null} diff --git a/src/components/DeviceConnect/stories.js b/src/components/DeviceConnect/stories.js index 1032e803..f5b93dcb 100644 --- a/src/components/DeviceConnect/stories.js +++ b/src/components/DeviceConnect/stories.js @@ -2,7 +2,7 @@ import React from 'react' import { storiesOf } from '@storybook/react' -import { boolean, select, text } from '@storybook/addon-knobs' +import { select } from '@storybook/addon-knobs' import { action } from '@storybook/addon-actions' import { getCryptoCurrencyById, @@ -45,7 +45,6 @@ stories.add('DeviceConnect', () => ( {({ currency }) => ( { let isSuccess = true try { - if (account) { + if (account || currency) { + const cur = account ? account.currency : currency + invariant(cur, 'currency is available') const { address } = await getAddress .send({ devicePath: deviceSelected.path, - currencyId: account.currency.id, - path: account.freshAddressPath, - segwit: isSegwitAccount(account), + currencyId: cur.id, + path: account + ? account.freshAddressPath + : standardDerivation({ currency: cur, segwit: false, x: 0 }), + segwit: account ? isSegwitAccount(account) : false, }) .toPromise() - const { freshAddress } = account - if (account && freshAddress !== address) { - logger.warn({ freshAddress, address }) - throw new Error('Account address is different than device address') - } - } else if (currency) { - const pass = await isCurrencyAppOpened - .send({ - devicePath: deviceSelected.path, - currencyId: currency.id, + .catch(e => { + if ( + e && + (e.name === 'TransportStatusError' || + // we don't want these error to appear (caused by usb disconnect..) + e.message === 'could not read from HID device' || + e.message === 'Cannot write to HID device') + ) { + logger.log(e) + throw new Error(`You must open application ‘${cur.name}’ on the device`) + } + throw e }) - .toPromise() - if (!pass) { - throw new Error(`${currency.name} app is not opened on the device`) + + if (account) { + const { freshAddress } = account + if (account && freshAddress !== address) { + logger.warn({ freshAddress, address }) + throw new Error(`You must use the device associated to the account ‘${account.name}’`) + } } } else { + // FIXME REMOVE THIS ! should use EnsureDashboard dedicated component. const isDashboard = isDashboardOpen.send({ devicePath: deviceSelected.path }).toPromise() if (!isDashboard) { diff --git a/src/components/modals/Send/SendModalBody.js b/src/components/modals/Send/SendModalBody.js index c50cd67c..22207250 100644 --- a/src/components/modals/Send/SendModalBody.js +++ b/src/components/modals/Send/SendModalBody.js @@ -300,7 +300,6 @@ class SendModalBody extends PureComponent> { ( , @@ -18,5 +19,14 @@ export default async ( ) => { const btc = new Btc(transport) const { bitcoinAddress, publicKey } = await btc.getWalletPublicKey(path, verify, segwit) + + const { bitcoinLikeInfo } = currency + if (bitcoinLikeInfo) { + const { P2SH, P2PKH } = await getBitcoinLikeInfo(transport) + if (P2SH !== bitcoinLikeInfo.P2SH || P2PKH !== bitcoinLikeInfo.P2PKH) { + throw new Error(`You must open application ‘${currency.name}’ on the device`) + } + } + return { address: bitcoinAddress, path, publicKey } }