diff --git a/packages/bridge-status-controller/CHANGELOG.md b/packages/bridge-status-controller/CHANGELOG.md index 5a129a2af15..44269fc81b5 100644 --- a/packages/bridge-status-controller/CHANGELOG.md +++ b/packages/bridge-status-controller/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump `@metamask/controller-utils` to `^11.10.0` ([#5935](https://github.com/MetaMask/core/pull/5935)) - Bump `@metamask/transaction-controller` to `^57.3.0` ([#5954](https://github.com/MetaMask/core/pull/5954)) +### Fixed + +- Properly prompt for confirmation on Ledger on Mobile for bridge transactions ([#5931](https://github.com/MetaMask/core/pull/5931)) + ## [29.1.0] ### Added diff --git a/packages/bridge-status-controller/src/bridge-status-controller.ts b/packages/bridge-status-controller/src/bridge-status-controller.ts index 0e731717485..65ad55c4957 100644 --- a/packages/bridge-status-controller/src/bridge-status-controller.ts +++ b/packages/bridge-status-controller/src/bridge-status-controller.ts @@ -15,6 +15,7 @@ import { getActionType, formatChainIdToCaip, isCrossChain, + isHardwareWallet, } from '@metamask/bridge-controller'; import type { TraceCallback } from '@metamask/controller-utils'; import { toHex } from '@metamask/controller-utils'; @@ -40,15 +41,15 @@ import { REFRESH_INTERVAL_MS, TraceName, } from './constants'; -import { type BridgeStatusControllerMessenger } from './types'; import type { BridgeStatusControllerState, StartPollingForBridgeTxStatusArgsSerialized, FetchFunction, - BridgeClientId, SolanaTransactionMeta, BridgeHistoryItem, } from './types'; +import { type BridgeStatusControllerMessenger } from './types'; +import { BridgeClientId } from './types'; import { fetchBridgeTxStatus, getStatusRequestWithSrcTxHash, @@ -597,6 +598,7 @@ export class BridgeStatusController extends StaticIntervalPollingController & QuoteMetadata, + requireApproval = false, ): Promise => { const { approval } = quoteResponse; @@ -604,13 +606,14 @@ export class BridgeStatusController extends StaticIntervalPollingController { await this.#handleUSDTAllowanceReset(quoteResponse); - const approvalTxMeta = await this.#handleEvmTransaction( - isBridgeTx + const approvalTxMeta = await this.#handleEvmTransaction({ + transactionType: isBridgeTx ? TransactionType.bridgeApproval : TransactionType.swapApproval, - approval, + trade: approval, quoteResponse, - ); + requireApproval, + }); if (!approvalTxMeta) { throw new Error( 'Failed to submit bridge tx: approval txMeta is undefined', @@ -638,39 +641,58 @@ export class BridgeStatusController extends StaticIntervalPollingController & QuoteMetadata, - approvalTxId?: string, - ) => { - return await this.#handleEvmTransaction( - isBridgeTx ? TransactionType.bridge : TransactionType.swap, + readonly #handleEvmSmartTransaction = async ({ + isBridgeTx, + trade, + quoteResponse, + approvalTxId, + requireApproval = false, + }: { + isBridgeTx: boolean; + trade: TxData; + quoteResponse: Omit & QuoteMetadata; + approvalTxId?: string; + requireApproval?: boolean; + }) => { + return await this.#handleEvmTransaction({ + transactionType: isBridgeTx + ? TransactionType.bridge + : TransactionType.swap, trade, quoteResponse, approvalTxId, - false, // Set to false to indicate we don't want to wait for hash - ); + shouldWaitForHash: false, // Set to false to indicate we don't want to wait for hash + requireApproval, + }); }; /** * Submits an EVM transaction to the TransactionController * - * @param transactionType - The type of transaction to submit - * @param trade - The trade data to confirm - * @param quoteResponse - The quote response - * @param quoteResponse.quote - The quote - * @param approvalTxId - The tx id of the approval tx - * @param shouldWaitForHash - Whether to wait for the hash of the transaction + * @param params - The parameters for the transaction + * @param params.transactionType - The type of transaction to submit + * @param params.trade - The trade data to confirm + * @param params.quoteResponse - The quote response + * @param params.approvalTxId - The tx id of the approval tx + * @param params.shouldWaitForHash - Whether to wait for the hash of the transaction + * @param params.requireApproval - Whether to require approval for the transaction * @returns The transaction meta */ - readonly #handleEvmTransaction = async ( - transactionType: TransactionType, - trade: TxData, - quoteResponse: Omit & QuoteMetadata, - approvalTxId?: string, + readonly #handleEvmTransaction = async ({ + transactionType, + trade, + quoteResponse, + approvalTxId, shouldWaitForHash = true, - ): Promise => { + requireApproval = false, + }: { + transactionType: TransactionType; + trade: TxData; + quoteResponse: Omit & QuoteMetadata; + approvalTxId?: string; + shouldWaitForHash?: boolean; + requireApproval?: boolean; + }): Promise => { const actionId = generateActionId().toString(); const selectedAccount = this.messagingSystem.call( @@ -691,7 +713,7 @@ export class BridgeStatusController extends StaticIntervalPollingController & QuoteMetadata, isStxEnabledOnClient: boolean, - ) => { + ): Promise> => { let txMeta: (TransactionMeta & Partial) | undefined; const isBridgeTx = isCrossChain( @@ -858,10 +880,17 @@ export class BridgeStatusController extends StaticIntervalPollingController - await this.#handleEvmSmartTransaction( + await this.#handleEvmSmartTransaction({ isBridgeTx, - quoteResponse.trade as TxData, + trade: quoteResponse.trade as TxData, quoteResponse, approvalTxId, - ), + requireApproval, + }), ); } else { txMeta = await this.#trace( @@ -897,12 +927,13 @@ export class BridgeStatusController extends StaticIntervalPollingController - await this.#handleEvmTransaction( - TransactionType.bridge, - quoteResponse.trade as TxData, + await this.#handleEvmTransaction({ + transactionType: TransactionType.bridge, + trade: quoteResponse.trade as TxData, quoteResponse, approvalTxId, - ), + requireApproval, + }), ); } }