Skip to content

Commit

Permalink
move editTransaction logic from LLC to coin-evm
Browse files Browse the repository at this point in the history
  • Loading branch information
chabroA committed Oct 23, 2023
1 parent 8515d2a commit 5bb7c4e
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {
getEditTransactionStatus,
hasMinimumFundsToCancel,
hasMinimumFundsToSpeedUp,
isTransactionConfirmed,
} from "@ledgerhq/coin-evm/editTransaction/index";
import { fromTransactionRaw } from "@ledgerhq/coin-evm/transaction";
import { Transaction, TransactionRaw } from "@ledgerhq/coin-evm/types/index";
import { UserRefusedOnDevice } from "@ledgerhq/errors";
import { getAccountCurrency } from "@ledgerhq/live-common/account/helpers";
import { addPendingOperation, getMainAccount } from "@ledgerhq/live-common/account/index";
import { SyncSkipUnderPriority } from "@ledgerhq/live-common/bridge/react/index";
import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction";
import {
getEditTransactionStatus,
hasMinimumFundsToCancel,
hasMinimumFundsToSpeedUp,
isTransactionConfirmed,
} from "@ledgerhq/live-common/families/evm/editTransaction/index";
import { Device } from "@ledgerhq/live-common/hw/actions/types";
import { isNftTransaction } from "@ledgerhq/live-common/nft/index";
import { isOldestPendingOperation } from "@ledgerhq/live-common/operation";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getFormattedFeeFields } from "@ledgerhq/coin-evm/editTransaction/index";
import { getMainAccount } from "@ledgerhq/live-common/account/index";
import { getFormattedFeeFields } from "@ledgerhq/live-common/families/evm/editTransaction/index";
import React, { Fragment, memo } from "react";
import { Trans } from "react-i18next";
import { useSelector } from "react-redux";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getEditTransactionPatch } from "@ledgerhq/coin-evm/editTransaction/index";
import { Transaction as EvmTransaction } from "@ledgerhq/coin-evm/types/index";
import { getMainAccount } from "@ledgerhq/live-common/account/index";
import { getAccountBridge } from "@ledgerhq/live-common/bridge/index";
import { getEditTransactionPatch } from "@ledgerhq/live-common/families/evm/editTransaction/index";
import { Flex } from "@ledgerhq/react-ui";
import { AccountBridge } from "@ledgerhq/types-live";
import invariant from "invariant";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isStrategyDisabled } from "@ledgerhq/coin-evm/editTransaction/index";
import { getEstimatedFees } from "@ledgerhq/coin-evm/logic";
import { getTypedTransaction } from "@ledgerhq/coin-evm/transaction";
import {
Expand All @@ -6,7 +7,6 @@ import {
Strategy,
} from "@ledgerhq/coin-evm/types/index";
import { getAccountCurrency, getAccountUnit } from "@ledgerhq/live-common/account/index";
import { isStrategyDisabled } from "@ledgerhq/live-common/families/evm/editTransaction/index";
import { Account } from "@ledgerhq/types-live";
import React, { memo, useMemo } from "react";
import { Trans } from "react-i18next";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getFormattedFeeFields } from "@ledgerhq/coin-evm/editTransaction/index";
import { fromTransactionRaw } from "@ledgerhq/coin-evm/transaction";
import { TransactionRaw } from "@ledgerhq/coin-evm/types/index";
import { getMainAccount } from "@ledgerhq/live-common/account/index";
import { getFormattedFeeFields } from "@ledgerhq/live-common/families/evm/editTransaction/index";
import { log } from "@ledgerhq/logs";
import { Alert, Flex } from "@ledgerhq/native-ui";
import type { Account, AccountLike, TransactionCommonRaw } from "@ledgerhq/types-live";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* with some changes to make it work with our custom flow
*/

import { getEditTransactionStatus } from "@ledgerhq/coin-evm/editTransaction/index";
import { Transaction as EvmTransaction } from "@ledgerhq/coin-evm/types/index";
import { isCurrencySupported } from "@ledgerhq/coin-framework/currencies/index";
import { NotEnoughGas } from "@ledgerhq/errors";
import { getAccountCurrency, getMainAccount } from "@ledgerhq/live-common/account/index";
import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction";
import { getEditTransactionStatus } from "@ledgerhq/live-common/families/evm/editTransaction/index";
import { isNftTransaction } from "@ledgerhq/live-common/nft/index";
import { fromTransactionRaw } from "@ledgerhq/live-common/transaction/index";
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
hasMinimumFundsToCancel,
hasMinimumFundsToSpeedUp,
isTransactionConfirmed,
} from "@ledgerhq/live-common/families/evm/editTransaction/index";
} from "@ledgerhq/coin-evm/editTransaction/index";
import { fromTransactionRaw } from "@ledgerhq/live-common/transaction/index";
import { getEnv } from "@ledgerhq/live-env";
import { log } from "@ledgerhq/logs";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isStrategyDisabled } from "@ledgerhq/coin-evm/editTransaction/index";
import { getEstimatedFees } from "@ledgerhq/coin-evm/logic";
import { getTypedTransaction } from "@ledgerhq/coin-evm/transaction";
import type { FeeData, GasOptions, Strategy, Transaction } from "@ledgerhq/coin-evm/types/index";
import { getFeesCurrency, getFeesUnit, getMainAccount } from "@ledgerhq/live-common/account/index";
import { isStrategyDisabled } from "@ledgerhq/live-common/families/evm/editTransaction/index";
import type { Account, AccountLike } from "@ledgerhq/types-live";
import { useTheme } from "@react-navigation/native";
import BigNumber from "bignumber.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { makeAccount } from "@ledgerhq/coin-evm/__tests__/fixtures/common.fixtures";
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
import BigNumber from "bignumber.js";
import { getGasTracker } from "../../../api/gasTracker/index";
import { getEditTransactionPatch } from "../../../editTransaction/getEditTransactionPatch";
import {
getMinEip1559Fees,
getMinLegacyFees,
} from "../../../editTransaction/getMinEditTransactionFees";
import { makeAccount } from "../../fixtures/common.fixtures";
import {
eip1559Tx,
erc1155Transaction,
legacyTx,
nftEip1559tx,
nftLegacyTx,
tokenTransaction,
} from "@ledgerhq/coin-evm/__tests__/fixtures/transaction.fixtures";
import { getGasTracker } from "@ledgerhq/coin-evm/api/gasTracker/index";
import { getMinEip1559Fees, getMinLegacyFees } from "@ledgerhq/coin-evm/getMinEditTransactionFees";
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
import BigNumber from "bignumber.js";
import { getEditTransactionPatch } from "./getEditTransactionPatch";
} from "../../fixtures/transaction.fixtures";

jest.mock("@ledgerhq/coin-evm/api/gasTracker/index");
const mockedGetGasTracker = jest.mocked(getGasTracker, true);
jest.mock("../../../api/gasTracker/index");
const mockedGetGasTracker = jest.mocked(getGasTracker);

jest.mock("@ledgerhq/coin-evm/getMinEditTransactionFees");
const mockedGetMinLegacyFees = jest.mocked(getMinLegacyFees, true);
const mockedGetMinEip1559Fees = jest.mocked(getMinEip1559Fees, true);
jest.mock("../../../editTransaction/getMinEditTransactionFees");
const mockedGetMinLegacyFees = jest.mocked(getMinLegacyFees);
const mockedGetMinEip1559Fees = jest.mocked(getMinEip1559Fees);

const mockedGetGasOptions = jest.fn();

Expand Down Expand Up @@ -239,6 +242,7 @@ describe.each(["speedup", "cancel"])("with editType %s", editType => {
describe.each([{ cond: "<" }, { cond: ">" }, { cond: "==" }])(
"with gasOptionFast $cond minFees",
({ cond }) => {
// @ts-expect-error using quick test utils (not typed to handle any "number")
const { gasOptions, minFees } = gasOptionFastAndMinFeesByTypeAndTest[txType][cond];

beforeEach(() => {
Expand All @@ -264,6 +268,7 @@ describe.each(["speedup", "cancel"])("with editType %s", editType => {
it.each([{ mode: "coin" }, { mode: "erc20" }, { mode: "erc721" }, { mode: "erc1155" }])(
"should return the expected patch for $mode transaction",
async ({ mode }) => {
// @ts-expect-error using quick test utils (not typed to handle any "number")
const transaction = txByTypeAndMode[txType][mode];

const patch = await getEditTransactionPatch({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BigNumber from "bignumber.js";
import { isStrategyDisabled } from "./isStrategyDisabled";
import { isStrategyDisabled } from "../../../editTransaction/isStrategyDisabled";

describe("isStrategyDisabled", () => {
describe("EIP1559 transaction (type 2)", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { getGasTracker } from "@ledgerhq/coin-evm/api/gasTracker/index";
import { getMinEip1559Fees, getMinLegacyFees } from "@ledgerhq/coin-evm/getMinEditTransactionFees";
import type { Account } from "@ledgerhq/types-live";
import { BigNumber } from "bignumber.js";
import invariant from "invariant";
import { getGasTracker } from "..//api/gasTracker/index";
import type {
EditType,
EvmTransactionEIP1559,
EvmTransactionLegacy,
GasOptions,
Transaction,
} from "@ledgerhq/coin-evm/types/index";
import type { Account } from "@ledgerhq/types-live";
import { BigNumber } from "bignumber.js";
import invariant from "invariant";
} from "..//types/index";
import { getMinEip1559Fees, getMinLegacyFees } from "./getMinEditTransactionFees";

/**
* Can't easily and properly use generics with Partial to avoid type casting
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getEstimatedFees } from "@ledgerhq/coin-evm/logic";
import type { Transaction } from "@ledgerhq/coin-evm/types/index";
import { getAccountUnit } from "@ledgerhq/coin-framework/account/index";
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
import type { Account } from "@ledgerhq/types-live";
import { BigNumber } from "bignumber.js";
import { getEstimatedFees } from "../logic";
import type { Transaction } from "../types/index";

/**
* Used to display the pending transaction (the original transaction being sped
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getEnv } from "@ledgerhq/live-env";
import { BigNumber } from "bignumber.js";
import type { Transaction } from "./types/transaction";
import type { Transaction } from "../types/transaction";

/**
* Returns the minimum fees values to update a legacy transaction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getEstimatedFees } from "@ledgerhq/coin-evm/logic";
import type { Transaction } from "@ledgerhq/coin-evm/types/index";
import { getEnv } from "@ledgerhq/live-env";
import type { Account, AccountLike } from "@ledgerhq/types-live";
import { BigNumber } from "bignumber.js";
import { getEstimatedFees } from "../logic";
import type { Transaction } from "../types/index";

export const hasMinimumFundsToCancel = ({
mainAccount,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getMinFees } from "@ledgerhq/coin-evm/getMinEditTransactionFees";
import { getEditTransactionStatus } from "@ledgerhq/coin-evm/getTransactionStatus";
import { getEditTransactionStatus } from "../getTransactionStatus";
import { getEditTransactionPatch } from "./getEditTransactionPatch";
import { getFormattedFeeFields } from "./getFormattedFeeFields";
import { getMinFees } from "./getMinEditTransactionFees";
import { hasMinimumFundsToCancel, hasMinimumFundsToSpeedUp } from "./hasMinimumFunds";
import { isStrategyDisabled } from "./isStrategyDisabled";
import { isTransactionConfirmed } from "./isTransactionConfirmed";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getMinFees } from "@ledgerhq/coin-evm/getMinEditTransactionFees";
import type { FeeData, Transaction } from "@ledgerhq/coin-evm/types/index";
import type { FeeData, Transaction } from "../types/index";
import { getMinFees } from "./getMinEditTransactionFees";

/**
* A strategy is disabled if it's fees are lower than the minimum fees
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getNodeApi } from "@ledgerhq/coin-evm/api/node/index";
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
import { getNodeApi } from "../api/node/index";

/**
* Check if a transaction has been confirmed on the network
Expand Down
2 changes: 1 addition & 1 deletion libs/coin-evm/src/getTransactionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Account, AccountBridge, SubAccount, TransactionStatusCommon } from "@le
import BigNumber from "bignumber.js";
import { ethers } from "ethers";
import { NotEnoughNftOwned, NotOwnedNft, QuantityNeedsToBePositive } from "./errors";
import { getMinEip1559Fees, getMinLegacyFees } from "./getMinEditTransactionFees";
import { getMinEip1559Fees, getMinLegacyFees } from "./editTransaction/getMinEditTransactionFees";
import { eip1559TransactionHasFees, getEstimatedFees, legacyTransactionHasFees } from "./logic";
import { DEFAULT_GAS_LIMIT } from "./transaction";
import {
Expand Down

0 comments on commit 5bb7c4e

Please sign in to comment.