Skip to content

Commit

Permalink
Switch BCH address formatting to cashaddr
Browse files Browse the repository at this point in the history
  • Loading branch information
gre committed Aug 13, 2020
1 parent 4cf45fc commit 8482385
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 252 deletions.
14 changes: 7 additions & 7 deletions package.json
Expand Up @@ -37,15 +37,15 @@
},
"dependencies": {
"@hot-loader/react-dom": "^16.13.0",
"@ledgerhq/devices": "^5.19.1",
"@ledgerhq/devices": "^5.22.0",
"@ledgerhq/electron-updater": "^4.2.2",
"@ledgerhq/errors": "^5.19.1",
"@ledgerhq/hw-transport": "^5.19.1",
"@ledgerhq/hw-transport-http": "^5.19.1",
"@ledgerhq/hw-transport-node-hid-singleton": "^5.20.0",
"@ledgerhq/errors": "^5.22.0",
"@ledgerhq/hw-transport": "^5.22.0",
"@ledgerhq/hw-transport-http": "^5.22.0",
"@ledgerhq/hw-transport-node-hid-singleton": "^5.22.0",
"@ledgerhq/ledger-core": "6.7.1",
"@ledgerhq/live-common": "^13.5.0",
"@ledgerhq/logs": "^5.19.1",
"@ledgerhq/live-common": "^13.7.2-cashaddr.5",
"@ledgerhq/logs": "^5.22.0",
"@tippyjs/react": "^4.0.2",
"@trust/keyto": "^1.0.1",
"animated": "^0.2.2",
Expand Down
35 changes: 0 additions & 35 deletions src/internal/commands/getAddress.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/internal/commands/index.js
Expand Up @@ -3,7 +3,6 @@ import firmwarePrepare from "./firmwarePrepare";
import firmwareMain from "./firmwareMain";
import firmwareRepair from "./firmwareRepair";
import flushDevice from "./flushDevice";
import getAddress from "./getAddress";
import getDeviceInfo from "./getDeviceInfo";
import getLatestFirmwareForDevice from "./getLatestFirmwareForDevice";
import libcoreGetVersion from "./libcoreGetVersion";
Expand All @@ -26,7 +25,6 @@ export const commandsById = {
firmwareMain,
firmwareRepair,
flushDevice,
getAddress,
getDeviceInfo,
getLatestFirmwareForDevice,
libcoreGetVersion,
Expand Down
14 changes: 14 additions & 0 deletions src/renderer/bridge/proxy-commands.js
Expand Up @@ -52,6 +52,19 @@ const cmdCurrencyScanAccounts = (o: {
.pipe(map(toScanAccountEventRaw));
};

const cmdAccountReceive = (o: {
account: AccountRaw,
arg: {
deviceId: string,
subAccountId?: string,
verify?: boolean,
},
}): Observable<{ address: string, path: string }> => {
const account = fromAccountRaw(o.account);
const bridge = bridgeImpl.getAccountBridge(account, null);
return bridge.receive(account, o.arg);
};

const cmdAccountSync = (o: {
account: AccountRaw,
syncConfig: SyncConfig,
Expand Down Expand Up @@ -125,6 +138,7 @@ const cmdAccountEstimateMaxSpendable = (o: {
export const commands = {
CurrencyPreload: cmdCurrencyPreload,
AccountSync: cmdAccountSync,
AccountReceive: cmdAccountReceive,
AccountGetTransactionStatus: cmdAccountGetTransactionStatus,
AccountPrepareTransaction: cmdAccountPrepareTransaction,
AccountSignOperation: cmdAccountSignOperation,
Expand Down
7 changes: 7 additions & 0 deletions src/renderer/bridge/proxy.js
Expand Up @@ -57,6 +57,12 @@ export const getAccountBridge = (
syncConfig,
}).pipe(map(raw => account => patchAccount(account, raw)));

const receive = (account, arg) =>
command("AccountReceive")({
account: toAccountRaw(account),
arg,
});

const createTransaction = a =>
bridgeImpl.getAccountBridge(account, parentAccount).createTransaction(a);

Expand Down Expand Up @@ -116,6 +122,7 @@ export const getAccountBridge = (
getTransactionStatus,
prepareTransaction,
sync,
receive,
signOperation,
broadcast,
estimateMaxSpendable,
Expand Down
17 changes: 2 additions & 15 deletions src/renderer/components/PerCurrencySelectAccount/state.js
Expand Up @@ -2,24 +2,11 @@

import { useState, useCallback, useMemo } from "react";
import type { Account, SubAccount } from "@ledgerhq/live-common/lib/types/account";
import { makeEmptyTokenAccount } from "@ledgerhq/live-common/lib/account";
import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/live-common/lib/types/currencies";
import { BigNumber } from "bignumber.js";

type CryptoOrTokenCurrency = TokenCurrency | CryptoCurrency;

const generateTokenAccount = (account: Account, currency: TokenCurrency): SubAccount => ({
type: "TokenAccount",
id: account.id + "+" + currency.contractAddress,
parentId: account.id,
token: currency,
balance: BigNumber(0),
operationsCount: 0,
creationDate: new Date(),
operations: [],
pendingOperations: [],
starred: false,
});

export type AccountTuple = {
account: ?Account,
subAccount: ?SubAccount,
Expand All @@ -40,7 +27,7 @@ function getAccountTuplesForCurrency(
(subAcc: SubAccount) =>
subAcc.type === "TokenAccount" && subAcc.token.id === currency.id,
)) ||
generateTokenAccount(account, currency),
makeEmptyTokenAccount(account, currency),
}));
}
return allAccounts
Expand Down
21 changes: 8 additions & 13 deletions src/renderer/modals/ExchangeDeviceConfirm/index.js
@@ -1,6 +1,7 @@
// @flow
import React, { useCallback, useEffect, useState } from "react";
import type { Account, AccountLike } from "@ledgerhq/live-common/lib/types";
import { getAccountBridge } from "@ledgerhq/live-common/lib/bridge";
import { getEnv } from "@ledgerhq/live-common/lib/env";
import { getAccountName, getMainAccount } from "@ledgerhq/live-common/lib/account";
import { createAction } from "@ledgerhq/live-common/lib/hw/actions/app";
Expand All @@ -9,7 +10,6 @@ import Modal from "~/renderer/components/Modal";
import ModalBody from "~/renderer/components/Modal/ModalBody";
import Box from "~/renderer/components/Box";
import { command } from "~/renderer/commands";
import { WrongDeviceForAccount } from "@ledgerhq/errors";
import { useSelector } from "react-redux";
import { getCurrentDevice } from "~/renderer/reducers/devices";
import Text from "~/renderer/components/Text";
Expand Down Expand Up @@ -64,18 +64,13 @@ const VerifyOnDevice = ({ mainAccount, onAddressVerified, device }: VerifyOnDevi
onAddressVerified(true);
}, 3000);
} else {
const { address } = await command("getAddress")({
derivationMode: mainAccount.derivationMode,
currencyId: mainAccount.currency.id,
devicePath: device.path,
path: mainAccount.freshAddressPath,
verify: true,
}).toPromise();
if (address !== mainAccount.freshAddress) {
throw new WrongDeviceForAccount(`WrongDeviceForAccount ${mainAccount.name}`, {
accountName: mainAccount.name,
});
}
await getAccountBridge(mainAccount)
.receive(mainAccount, {
deviceId: device.path,
verify: true,
})
.toPromise();

onAddressVerified(true);
}
} catch (err) {
Expand Down
22 changes: 8 additions & 14 deletions src/renderer/modals/Receive/steps/StepReceiveFunds.js
Expand Up @@ -2,11 +2,11 @@

import invariant from "invariant";
import React, { useEffect, useRef, useCallback, useState } from "react";
import { getAccountBridge } from "@ledgerhq/live-common/lib/bridge";
import { getMainAccount, getAccountName } from "@ledgerhq/live-common/lib/account";
import TrackPage from "~/renderer/analytics/TrackPage";
import { command } from "~/renderer/commands";
import ErrorDisplay from "~/renderer/components/ErrorDisplay";
import { DisconnectedDevice, WrongDeviceForAccount } from "@ledgerhq/errors";
import { DisconnectedDevice } from "@ledgerhq/errors";
import { Trans } from "react-i18next";
import styled from "styled-components";
import useTheme from "~/renderer/hooks/useTheme";
Expand Down Expand Up @@ -165,18 +165,12 @@ const StepReceiveFunds = ({
if (!device) {
throw new DisconnectedDevice();
}
const { address } = await command("getAddress")({
derivationMode: mainAccount.derivationMode,
currencyId: mainAccount.currency.id,
devicePath: device.path,
path: mainAccount.freshAddressPath,
verify: true,
}).toPromise();
if (address !== mainAccount.freshAddress) {
throw new WrongDeviceForAccount(`WrongDeviceForAccount ${mainAccount.name}`, {
accountName: mainAccount.name,
});
}
await getAccountBridge(mainAccount)
.receive(mainAccount, {
deviceId: device.path,
verify: true,
})
.toPromise();
onChangeAddressVerified(true);
transitionTo("receive");
}
Expand Down

0 comments on commit 8482385

Please sign in to comment.