Skip to content

Commit 479a9ac

Browse files
committed
chore: rename
rename rename wip fix: merge conflict
1 parent 4077bfa commit 479a9ac

File tree

6 files changed

+35
-33
lines changed

6 files changed

+35
-33
lines changed

packages/bridge-status-controller/src/bridge-status-controller.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
844844
*
845845
* @param accountAddress - The address of the account to submit the transaction for
846846
* @param quoteResponse - The quote response
847-
* @param isStxEnabledOnClient - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension
847+
* @param isStxEnabled - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension
848848
* @param quotesReceivedContext - The context for the QuotesReceived event
849849
* @param location - The entry point from which the user initiated the swap or bridge (e.g. Main View, Token View, Trending Explore)
850850
* @param abTests - Legacy A/B test context for `ab_tests` (backward compatibility)
@@ -855,7 +855,7 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
855855
submitTx = async (
856856
accountAddress: string,
857857
quoteResponse: QuoteResponse<Trade, Trade> & QuoteMetadata,
858-
isStxEnabledOnClient: boolean,
858+
isStxEnabled: boolean,
859859
quotesReceivedContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived],
860860
location: MetaMetricsSwapsEventSource = MetaMetricsSwapsEventSource.MainView,
861861
abTests?: Record<string, string>,
@@ -889,7 +889,7 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
889889

890890
const preConfirmationProperties = getPreConfirmationPropertiesFromQuote(
891891
quoteResponse,
892-
isStxEnabledOnClient,
892+
isStxEnabled,
893893
isHardwareAccount,
894894
location,
895895
abTests,
@@ -907,7 +907,7 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
907907
preConfirmationProperties,
908908
);
909909
return await this.#trace(
910-
getTraceParams(quoteResponse, isStxEnabledOnClient),
910+
getTraceParams(quoteResponse, isStxEnabled),
911911
async () => {
912912
/**
913913
* Check if the account is an EIP-7702 delegated account.
@@ -926,7 +926,7 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
926926

927927
const params: SubmitStrategyParams = {
928928
quoteResponse,
929-
isStxEnabledOnClient,
929+
isStxEnabledOnClient: isStxEnabled,
930930
isDelegatedAccount,
931931
messenger: this.messenger,
932932
selectedAccount,
@@ -956,7 +956,7 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
956956
...payload,
957957
quoteResponse,
958958
accountAddress: selectedAccount.address,
959-
isStxEnabled: isStxEnabledOnClient,
959+
isStxEnabled,
960960
startTime,
961961
location,
962962
abTests,
@@ -1009,7 +1009,7 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
10091009
* @param params.location - The entry point from which the user initiated the swap or bridge
10101010
* @param params.abTests - Legacy A/B test context for `ab_tests` (backward compatibility)
10111011
* @param params.activeAbTests - New A/B test context for `active_ab_tests` (migration target). Attributes events to specific experiments.
1012-
* @param params.isStxEnabledOnClient - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension
1012+
* @param params.isStxEnabled - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension
10131013
* @param params.quotesReceivedContext - The context for the QuotesReceived event
10141014
* @returns A lightweight TransactionMeta-like object for history linking
10151015
* @throws An error if intent or transaction submission fails before they get published
@@ -1020,7 +1020,7 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
10201020
location?: MetaMetricsSwapsEventSource;
10211021
abTests?: Record<string, string>;
10221022
activeAbTests?: { key: string; value: string }[];
1023-
isStxEnabledOnClient?: boolean;
1023+
isStxEnabled?: boolean;
10241024
quotesReceivedContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived];
10251025
}): Promise<Pick<TransactionMeta, 'id' | 'chainId' | 'type' | 'status'>> => {
10261026
const {
@@ -1029,15 +1029,15 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
10291029
location,
10301030
abTests,
10311031
activeAbTests,
1032-
isStxEnabledOnClient,
1032+
isStxEnabled = false,
10331033
quotesReceivedContext,
10341034
} = params;
10351035

10361036
// TODO add metrics context
10371037
return await this.submitTx(
10381038
accountAddress,
10391039
quoteResponse,
1040-
Boolean(isStxEnabledOnClient),
1040+
isStxEnabled,
10411041
quotesReceivedContext,
10421042
location,
10431043
abTests,
@@ -1078,13 +1078,15 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
10781078
const resolvedActiveAbTests =
10791079
eventProperties?.active_ab_tests ?? historyActiveAbTests;
10801080

1081+
const location =
1082+
(txMetaId
1083+
? this.state.txHistory?.[txMetaId]?.location
1084+
: eventProperties?.location) ?? MetaMetricsSwapsEventSource.MainView;
1085+
10811086
const baseProperties = {
10821087
action_type: MetricsActionType.SWAPBRIDGE_V1,
1083-
location:
1084-
eventProperties?.location ??
1085-
(txMetaId ? this.state.txHistory?.[txMetaId]?.location : undefined) ??
1086-
MetaMetricsSwapsEventSource.MainView,
10871088
...(eventProperties ?? {}),
1089+
location,
10881090
...(resolvedAbTests &&
10891091
Object.keys(resolvedAbTests).length > 0 && {
10901092
ab_tests: resolvedAbTests,

packages/bridge-status-controller/src/strategy/batch-strategy.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isEvmTxData } from '@metamask/bridge-controller';
1+
import { TxData } from '@metamask/bridge-controller';
22

33
import type { SubmitStrategyParams, SubmitStepResult } from './types';
44
import {
@@ -13,7 +13,7 @@ import {
1313
* @yields The approvalMeta and tradeMeta for the batched transaction
1414
*/
1515
export async function* submitBatchHandler(
16-
args: SubmitStrategyParams,
16+
args: SubmitStrategyParams<TxData>,
1717
): AsyncGenerator<SubmitStepResult, void, void> {
1818
const {
1919
requireApproval,
@@ -22,19 +22,11 @@ export async function* submitBatchHandler(
2222
isBridgeTx,
2323
addTransactionBatchFn,
2424
} = args;
25-
if (!isEvmTxData(quoteResponse.trade)) {
26-
throw new Error(
27-
'Failed to submit cross-chain swap transaction: trade is not an EVM transaction',
28-
);
29-
}
3025
const transactionParams = await getAddTransactionBatchParams({
3126
messenger,
3227
isBridgeTx,
3328
resetApproval: quoteResponse.resetApproval,
34-
approval:
35-
quoteResponse.approval && isEvmTxData(quoteResponse.approval)
36-
? quoteResponse.approval
37-
: undefined,
29+
approval: quoteResponse.approval,
3830
trade: quoteResponse.trade,
3931
quoteResponse,
4032
requireApproval,

packages/bridge-status-controller/src/strategy/evm-strategy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,15 @@ export async function* submitEvmHandler(
105105
return await handleEvmApprovals(args);
106106
},
107107
);
108+
108109
// Delay after approval
109-
await handleMobileHardwareWalletDelay(requireApproval);
110110
if (approvalTxId) {
111111
await handleApprovalDelay(quoteResponse.quote.srcChainId);
112+
}
113+
// Hardware-wallet delay first (Ledger second-prompt spacing), then wait for
114+
// on-chain approval confirmation so swap gas estimation runs after allowance is set.
115+
await handleMobileHardwareWalletDelay(requireApproval);
116+
if (requireApproval && approvalTxId) {
112117
await waitForTxConfirmation(args.messenger, approvalTxId);
113118
}
114119

packages/bridge-status-controller/src/strategy/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
22
/* eslint-disable @typescript-eslint/explicit-function-return-type */
3-
import { isNonEvmChainId } from '@metamask/bridge-controller';
3+
import { isEvmTxData, isNonEvmChainId } from '@metamask/bridge-controller';
44

55
import { submitBatchHandler } from './batch-strategy';
66
import { submitEvmHandler as defaultSubmitHandler } from './evm-strategy';
@@ -25,9 +25,11 @@ const SUBMIT_STRATEGY_REGISTRY: SubmitStrategy[] = [
2525
const { quoteResponse, isStxEnabledOnClient, isDelegatedAccount } =
2626
params;
2727
return (
28-
isStxEnabledOnClient ||
29-
quoteResponse.quote.gasIncluded7702 ||
30-
isDelegatedAccount
28+
(isStxEnabledOnClient ||
29+
quoteResponse.quote.gasIncluded7702 ||
30+
isDelegatedAccount) &&
31+
isEvmTxData(quoteResponse.trade) &&
32+
(quoteResponse.approval ? isEvmTxData(quoteResponse.approval) : true)
3133
);
3234
},
3335
execute: submitBatchHandler,

packages/bridge-status-controller/src/strategy/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
BridgeClientId,
44
QuoteMetadata,
55
QuoteResponse,
6+
Trade,
67
} from '@metamask/bridge-controller';
78
import type { TraceCallback } from '@metamask/controller-utils';
89
import type {
@@ -55,13 +56,13 @@ export type SubmitStepResult =
5556
/**
5657
* The parameters for the submission flow
5758
*/
58-
export type SubmitStrategyParams = {
59+
export type SubmitStrategyParams<TradeType extends Trade = Trade> = {
5960
addTransactionBatchFn: TransactionController['addTransactionBatch'];
6061
isBridgeTx: boolean;
6162
isDelegatedAccount: boolean;
6263
isStxEnabledOnClient: boolean;
6364
messenger: BridgeStatusControllerMessenger;
64-
quoteResponse: QuoteResponse & QuoteMetadata;
65+
quoteResponse: QuoteResponse<TradeType, TradeType> & QuoteMetadata;
6566
requireApproval: boolean;
6667
selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string];
6768
traceFn: TraceCallback;

packages/bridge-status-controller/src/utils/metrics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export const getPreConfirmationPropertiesFromQuote = (
185185
quoteResponse: QuoteResponse & Partial<QuoteMetadata>,
186186
isStxEnabledOnClient: boolean,
187187
isHardwareAccount: boolean,
188-
location: MetaMetricsSwapsEventSource = MetaMetricsSwapsEventSource.MainView,
188+
location?: MetaMetricsSwapsEventSource,
189189
abTests?: Record<string, string>,
190190
activeAbTests?: { key: string; value: string }[],
191191
) => {

0 commit comments

Comments
 (0)