Skip to content

Commit

Permalink
Merge branch 'main' into fix/font-size-update
Browse files Browse the repository at this point in the history
  • Loading branch information
georgewrmarshall authored Jan 28, 2025
2 parents 9197918 + 2cf7e67 commit 6597673
Show file tree
Hide file tree
Showing 88 changed files with 2,747 additions and 1,324 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
diff --git a/lib/message/EIP712/index.js b/lib/message/EIP712/index.js
index 5443ac06d4ef29028e3acce98210949da2ef9263..57ec8615340a9285290ad5d2c2522ed19af2d0fc 100644
index a5c677ebf53ab6c22987cebf1c92b21c6245b5db..f5a5580df74100d5e1725bb783038c4c60ae1dbc 100644
--- a/lib/message/EIP712/index.js
+++ b/lib/message/EIP712/index.js
@@ -28,8 +28,8 @@ const ethers_1 = require("ethers");
const axios_1 = __importDefault(require("axios"));
const sha224_1 = __importDefault(require("crypto-js/sha224"));
@@ -29,8 +29,8 @@ const sha224_1 = __importDefault(require("crypto-js/sha224"));
const live_env_1 = require("@ledgerhq/live-env");
const constants_1 = require("@ethersproject/constants");
const hash_1 = require("@ethersproject/hash");
-const eip712_1 = __importDefault(require("@ledgerhq/cryptoassets-evm-signatures/data/eip712"));
-const eip712_v2_1 = __importDefault(require("@ledgerhq/cryptoassets-evm-signatures/data/eip712_v2"));
+const eip712_1 = __importDefault(require("@ledgerhq/cryptoassets-evm-signatures/lib/data/eip712"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/lib/modules/EIP712/index.js b/lib/modules/EIP712/index.js
index bbca23c9a596b2b300aca0f323bad277a4190def..c85cb18c3d6ff049c442d358b4d834c04a49951f 100644
index 24251b4584b04fd138b8892f027ccad60b14fc9e..4b99b94cf2327042b53687b4e2b076bd0cb8fba1 100644
--- a/lib/modules/EIP712/index.js
+++ b/lib/modules/EIP712/index.js
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
Expand All @@ -12,7 +12,7 @@ index bbca23c9a596b2b300aca0f323bad277a4190def..c85cb18c3d6ff049c442d358b4d834c0
const utils_1 = require("../../utils");
const loadConfig_1 = require("../../services/ledger/loadConfig");
diff --git a/lib/modules/EIP712/utils.js b/lib/modules/EIP712/utils.js
index 4f09ea8a24ae4f175f1a4d2d40999d36ffa2a915..1cc7de0d5ffd2b980741ad6d85a75792085c031b 100644
index 4f09ea8a24ae4f175f1a4d2d40999d36ffa2a915..38225b98bc124d8648d1ff110570293f165bd2a6 100644
--- a/lib/modules/EIP712/utils.js
+++ b/lib/modules/EIP712/utils.js
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Expand All @@ -25,7 +25,7 @@ index 4f09ea8a24ae4f175f1a4d2d40999d36ffa2a915..1cc7de0d5ffd2b980741ad6d85a75792
/**
* @ignore for the README
diff --git a/lib/services/ledger/erc20.js b/lib/services/ledger/erc20.js
index 8fdedf8037b2684ab6d48fd279a0c014b074b676..c10cea22504a4d3cd72bfac51463e5664639d20e 100644
index 8fdedf8037b2684ab6d48fd279a0c014b074b676..90ce6589407c1b8719550c21251f3f247fcef085 100644
--- a/lib/services/ledger/erc20.js
+++ b/lib/services/ledger/erc20.js
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
Expand All @@ -38,26 +38,26 @@ index 8fdedf8037b2684ab6d48fd279a0c014b074b676..c10cea22504a4d3cd72bfac51463e566
const asContractAddress = (addr) => {
const a = addr.toLowerCase();
diff --git a/lib/services/ledger/index.js b/lib/services/ledger/index.js
index 8385537236dfc98902376b29f712e9f7b605091a..6641b951b0c7e477fe5622c724ee22b9e5272213 100644
index 86db9973e63e1ac7c0e7f67e53ca8f05aa809805..29ebceeab40cdad75092d8af747d770411f8a605 100644
--- a/lib/services/ledger/index.js
+++ b/lib/services/ledger/index.js
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
// This implements the resolution of a Transaction using Ledger's own API
const logs_1 = require("@ledgerhq/logs");
const transactions_1 = require("@ethersproject/transactions");
const abi_1 = require("@ethersproject/abi");
const logs_1 = require("@ledgerhq/logs");
-const index_1 = require("@ledgerhq/domain-service/signers/index");
+const index_1 = require("@ledgerhq/domain-service/lib/signers/index");
const constants_1 = require("../../modules/Uniswap/constants");
const erc20_1 = require("./erc20");
const contracts_1 = require("./contracts");
const nfts_1 = require("./nfts");
const Uniswap_1 = require("../../modules/Uniswap");
diff --git a/lib/utils.js b/lib/utils.js
index 027089bf09c047b34af79e3dea253d5335d336f3..1c5da628db47a33099532973de9ea634a1ee65df 100644
index 6c5f58439116b2c6b5844f5e17d0eb876a436f41..e719e9840d33721ef79bb12232991621c828b501 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -2,7 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeResolutions = exports.nftSelectors = exports.tokenSelectors = exports.intAsHexBytes = exports.decodeTxInfo = exports.maybeHexBuffer = exports.hexBuffer = exports.splitPath = exports.padHexString = exports.ERC1155_CLEAR_SIGNED_SELECTORS = exports.ERC721_CLEAR_SIGNED_SELECTORS = exports.ERC20_CLEAR_SIGNED_SELECTORS = void 0;
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.safeChunkTransaction = exports.getV = exports.getChainIdAsUint32 = exports.getParity = exports.mergeResolutions = exports.nftSelectors = exports.tokenSelectors = exports.intAsHexBytes = exports.maybeHexBuffer = exports.hexBuffer = exports.splitPath = exports.padHexString = exports.ERC1155_CLEAR_SIGNED_SELECTORS = exports.ERC721_CLEAR_SIGNED_SELECTORS = exports.ERC20_CLEAR_SIGNED_SELECTORS = void 0;
const bignumber_js_1 = require("bignumber.js");
const rlp = __importStar(require("@ethersproject/rlp"));
-const index_1 = require("@ledgerhq/evm-tools/selectors/index");
+const index_1 = require("@ledgerhq/evm-tools/lib/selectors/index");
Object.defineProperty(exports, "ERC20_CLEAR_SIGNED_SELECTORS", { enumerable: true, get: function () { return index_1.ERC20_CLEAR_SIGNED_SELECTORS; } });
Expand Down
7 changes: 7 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ exports[`BridgeStatusController constructor rehydrates the tx history state 1`]
"bridgeTxMetaId1": {
"account": "0xaccount1",
"estimatedProcessingTimeInSeconds": 15,
"hasApprovalTx": false,
"initialDestAssetBalance": undefined,
"pricingData": {
"amountSent": "1.234",
"amountSentInUsd": undefined,
"quotedGasInUsd": undefined,
"quotedReturnInUsd": undefined,
},
"quote": {
"bridgeId": "lifi",
Expand Down Expand Up @@ -114,9 +118,13 @@ exports[`BridgeStatusController startPollingForBridgeTxStatus sets the inital tx
"bridgeTxMetaId1": {
"account": "0xaccount1",
"estimatedProcessingTimeInSeconds": 15,
"hasApprovalTx": false,
"initialDestAssetBalance": undefined,
"pricingData": {
"amountSent": "1.234",
"amountSentInUsd": undefined,
"quotedGasInUsd": undefined,
"quotedReturnInUsd": undefined,
},
"quote": {
"bridgeId": "lifi",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ describe('BridgeStatusController', () => {
it('stops polling when the status response is complete', async () => {
// Setup
jest.useFakeTimers();
jest
.spyOn(Date, 'now')
.mockImplementation(
() =>
MockTxHistory.getComplete().bridgeTxMetaId1.completionTime ?? 10,
);
const bridgeStatusController = new BridgeStatusController({
messenger: getMessengerMock(),
});
Expand Down Expand Up @@ -184,6 +190,8 @@ describe('BridgeStatusController', () => {
expect(bridgeStatusController.state.bridgeStatusState.txHistory).toEqual(
MockTxHistory.getComplete(),
);

jest.restoreAllMocks();
});
});
describe('resetState', () => {
Expand Down
41 changes: 33 additions & 8 deletions app/scripts/controllers/bridge-status/bridge-status-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ export default class BridgeStatusController extends StaticIntervalPollingControl
slippagePercentage,
pricingData: {
amountSent: quoteResponse.sentAmount.amount,
amountSentInUsd: quoteResponse.sentAmount.usd ?? undefined,
quotedGasInUsd: quoteResponse.gasFee.usd ?? undefined,
quotedReturnInUsd: quoteResponse.toTokenAmount.usd ?? undefined,
},
initialDestAssetBalance,
targetContractAddress,
Expand All @@ -186,6 +189,7 @@ export default class BridgeStatusController extends StaticIntervalPollingControl
txHash: statusRequest.srcTxHash,
},
},
hasApprovalTx: Boolean(quoteResponse.approval),
};
this.update((_state) => {
_state.bridgeStatusState = {
Expand Down Expand Up @@ -235,30 +239,51 @@ export default class BridgeStatusController extends StaticIntervalPollingControl
srcTxHash,
);
const status = await fetchBridgeTxStatus(statusRequest);
const newBridgeHistoryItem = {
...historyItem,
status,
completionTime:
status.status === StatusTypes.COMPLETE ||
status.status === StatusTypes.FAILED
? Date.now()
: undefined, // TODO make this more accurate by looking up dest txHash block time
};

// No need to purge these on network change or account change, TransactionController does not purge either.
// TODO In theory we can skip checking status if it's not the current account/network
// we need to keep track of the account that this is associated with as well so that we don't show it in Activity list for other accounts
// First stab at this will not stop polling when you are on a different account
this.update((_state) => {
const bridgeHistoryItem =
_state.bridgeStatusState.txHistory[bridgeTxMetaId];

_state.bridgeStatusState = {
...bridgeStatusState,
txHistory: {
...bridgeStatusState.txHistory,
[bridgeTxMetaId]: {
...bridgeHistoryItem,
status,
},
[bridgeTxMetaId]: newBridgeHistoryItem,
},
};
});

const pollingToken = this.#pollingTokensByTxMetaId[bridgeTxMetaId];
if (status.status === StatusTypes.COMPLETE && pollingToken) {

if (
(status.status === StatusTypes.COMPLETE ||
status.status === StatusTypes.FAILED) &&
pollingToken
) {
this.stopPollingByPollingToken(pollingToken);

if (status.status === StatusTypes.COMPLETE) {
this.messagingSystem.publish(
`${BRIDGE_STATUS_CONTROLLER_NAME}:bridgeTransactionComplete`,
{ bridgeHistoryItem: newBridgeHistoryItem },
);
}
if (status.status === StatusTypes.FAILED) {
this.messagingSystem.publish(
`${BRIDGE_STATUS_CONTROLLER_NAME}:bridgeTransactionFailed`,
{ bridgeHistoryItem: newBridgeHistoryItem },
);
}
}
} catch (e) {
console.log('Failed to fetch bridge tx status', e);
Expand Down
36 changes: 30 additions & 6 deletions app/scripts/controllers/bridge-status/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
StatusTypes,
ActionTypes,
StartPollingForBridgeTxStatusArgsSerialized,
BridgeHistoryItem,
} from '../../../../shared/types/bridge-status';

export const MockStatusResponse = {
Expand Down Expand Up @@ -236,7 +237,14 @@ export const getMockStartPollingForBridgeTxStatusArgs = ({
},
approval: null,
estimatedProcessingTimeInSeconds: 15,
sentAmount: { amount: '1.234', valueInCurrency: null },
sentAmount: { amount: '1.234', valueInCurrency: null, usd: null },
toTokenAmount: { amount: '1.234', valueInCurrency: null, usd: null },
totalNetworkFee: { amount: '1.234', valueInCurrency: null, usd: null },
totalMaxNetworkFee: { amount: '1.234', valueInCurrency: null, usd: null },
gasFee: { amount: '1.234', valueInCurrency: null, usd: null },
adjustedReturn: { valueInCurrency: null, usd: null },
swapRate: '1.234',
cost: { valueInCurrency: null, usd: null },
},
startTime: 1729964825189,
slippagePercentage: 0,
Expand All @@ -250,7 +258,7 @@ export const MockTxHistory = {
account = '0xaccount1',
srcChainId = 42161,
destChainId = 10,
} = {}) => ({
} = {}): Record<string, BridgeHistoryItem> => ({
[txMetaId]: {
txMetaId,
quote: getMockQuote({ srcChainId, destChainId }),
Expand All @@ -261,14 +269,18 @@ export const MockTxHistory = {
targetContractAddress: '0x23981fC34e69eeDFE2BD9a0a9fCb0719Fe09DbFC',
initialDestAssetBalance: undefined,
pricingData: { amountSent: '1.234' },
status: MockStatusResponse.getPending({
srcChainId,
}),
hasApprovalTx: false,
},
}),
getInit: ({
txMetaId = 'bridgeTxMetaId1',
account = '0xaccount1',
srcChainId = 42161,
destChainId = 10,
} = {}) => ({
} = {}): Record<string, BridgeHistoryItem> => ({
[txMetaId]: {
txMetaId,
quote: getMockQuote({ srcChainId, destChainId }),
Expand All @@ -279,6 +291,10 @@ export const MockTxHistory = {
targetContractAddress: '0x23981fC34e69eeDFE2BD9a0a9fCb0719Fe09DbFC',
initialDestAssetBalance: undefined,
pricingData: { amountSent: '1.234' },
status: MockStatusResponse.getPending({
srcChainId,
}),
hasApprovalTx: false,
},
}),
getPending: ({
Expand All @@ -287,7 +303,7 @@ export const MockTxHistory = {
account = '0xaccount1',
srcChainId = 42161,
destChainId = 10,
} = {}) => ({
} = {}): Record<string, BridgeHistoryItem> => ({
[txMetaId]: {
txMetaId,
quote: getMockQuote({ srcChainId, destChainId }),
Expand All @@ -302,6 +318,7 @@ export const MockTxHistory = {
targetContractAddress: '0x23981fC34e69eeDFE2BD9a0a9fCb0719Fe09DbFC',
initialDestAssetBalance: undefined,
pricingData: { amountSent: '1.234' },
hasApprovalTx: false,
},
}),
getComplete: ({
Expand All @@ -310,18 +327,25 @@ export const MockTxHistory = {
account = '0xaccount1',
srcChainId = 42161,
destChainId = 10,
} = {}) => ({
} = {}): Record<string, BridgeHistoryItem> => ({
[txMetaId]: {
txMetaId,
quote: getMockQuote({ srcChainId, destChainId }),
startTime: 1729964825189,
completionTime: 1736277625746,
estimatedProcessingTimeInSeconds: 15,
slippagePercentage: 0,
account,
status: MockStatusResponse.getComplete({ srcTxHash }),
targetContractAddress: '0x23981fC34e69eeDFE2BD9a0a9fCb0719Fe09DbFC',
initialDestAssetBalance: undefined,
pricingData: { amountSent: '1.234' },
pricingData: {
amountSent: '1.234',
amountSentInUsd: undefined,
quotedGasInUsd: undefined,
quotedReturnInUsd: undefined,
},
hasApprovalTx: false,
},
}),
};
20 changes: 19 additions & 1 deletion app/scripts/controllers/bridge-status/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import {
import { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller';
import { TransactionControllerGetStateAction } from '@metamask/transaction-controller';
import {
BridgeHistoryItem,
BridgeStatusAction,
BridgeStatusControllerState,
} from '../../../../shared/types/bridge-status';
import { BRIDGE_STATUS_CONTROLLER_NAME } from './constants';
import BridgeStatusController from './bridge-status-controller';

// Actions
type BridgeStatusControllerAction<
FunctionName extends keyof BridgeStatusController,
> = {
Expand All @@ -33,11 +35,27 @@ type BridgeStatusControllerActions =
BridgeStatusControllerState
>;

type BridgeStatusControllerEvents = ControllerStateChangeEvent<
// Events
export type BridgeStatusControllerStateChangeEvent = ControllerStateChangeEvent<
typeof BRIDGE_STATUS_CONTROLLER_NAME,
BridgeStatusControllerState
>;

export type BridgeStatusControllerBridgeTransactionCompleteEvent = {
type: `${typeof BRIDGE_STATUS_CONTROLLER_NAME}:bridgeTransactionComplete`;
payload: [{ bridgeHistoryItem: BridgeHistoryItem }];
};

export type BridgeStatusControllerBridgeTransactionFailedEvent = {
type: `${typeof BRIDGE_STATUS_CONTROLLER_NAME}:bridgeTransactionFailed`;
payload: [{ bridgeHistoryItem: BridgeHistoryItem }];
};

type BridgeStatusControllerEvents =
| BridgeStatusControllerStateChangeEvent
| BridgeStatusControllerBridgeTransactionCompleteEvent
| BridgeStatusControllerBridgeTransactionFailedEvent;

/**
* The external actions available to the BridgeStatusController.
*/
Expand Down
Loading

0 comments on commit 6597673

Please sign in to comment.