Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Fixes usage of findTokenByAddressInCurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
gre committed Aug 17, 2021
1 parent 5c58f7d commit 04bae3d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
28 changes: 19 additions & 9 deletions src/families/ethereum/modules/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@ import eip55 from "eip55";
import { BigNumber } from "bignumber.js";
import type { ModeModule } from "../types";
import { AmountRequired } from "@ledgerhq/errors";
import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets";
import { inferTokenAccount, validateRecipient } from "../transaction";
import { getAccountCurrency, getAccountUnit } from "../../../account";
import {
findTokenByAddress,
findTokenById,
formatCurrencyUnit,
} from "../../../currencies";
getAccountCurrency,
getAccountUnit,
getMainAccount,
} from "../../../account";
import { findTokenById, formatCurrencyUnit } from "../../../currencies";
import { getAccountCapabilities } from "../../../compound/logic";
import { CompoundLowerAllowanceOfActiveAccountError } from "../../../errors";
import { DeviceTransactionField } from "../../../transaction";

const infinite = new BigNumber(2).pow(256).minus(1);

function contractField(transaction) {
const recipientToken = findTokenByAddress(transaction.recipient);
function contractField(transaction, currency) {
const recipientToken = findTokenByAddressInCurrency(
transaction.recipient,
currency.id
);
const maybeCompoundToken = findTokenById(recipientToken?.compoundFor || "");
return {
type: "text",
Expand Down Expand Up @@ -101,7 +106,7 @@ const erc20approve: ModeModule = {
};
},

fillDeviceTransactionConfig({ transaction, account }, fields) {
fillDeviceTransactionConfig({ transaction, account, parentAccount }, fields) {
fields.push({
type: "text",
label: "Type",
Expand All @@ -122,7 +127,12 @@ const erc20approve: ModeModule = {
});
}

fields.push(contractField(transaction) as DeviceTransactionField);
fields.push(
contractField(
transaction,
getMainAccount(account, parentAccount).currency
) as DeviceTransactionField
);
},

fillOptimisticOperation(_account, _transaction, operation) {
Expand Down
13 changes: 7 additions & 6 deletions src/families/ethereum/synchronisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ import {
inferSubOperations,
emptyHistoryCache,
} from "../../account";
import {
findTokenByAddress,
listTokensForCryptoCurrency,
} from "../../currencies";
import { listTokensForCryptoCurrency } from "../../currencies";
import type { Operation, TokenAccount, Account } from "../../types";
import { API, apiForCurrency, Tx } from "../../api/Ethereum";
import { digestTokenAccounts, prepareTokenAccounts } from "./modules";
import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets";
export const getAccountShape: GetAccountShape = async (
infoInput,
{ blacklistedTokenIds }
Expand Down Expand Up @@ -177,7 +175,7 @@ const safeEncodeEIP55 = (addr) => {

// in case of a SELF send, 2 ops are returned.
const txToOps =
({ address, id }) =>
({ address, id, currency }) =>
(tx: Tx): Operation[] => {
// workaround bugs in our explorer that don't treat partial/optimistic operation really well
if (!tx.gas_used) return [];
Expand Down Expand Up @@ -249,7 +247,10 @@ const txToOps =
return [];
}

const token = findTokenByAddress(event.contract);
const token = findTokenByAddressInCurrency(
event.contract,
currency.id
);
if (!token) return [];
const accountId = encodeTokenAccountId(id, token);
const value = event.count;
Expand Down

0 comments on commit 04bae3d

Please sign in to comment.