Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/transaction-pay-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Sync transaction metadata when fiat payment is selected but no payment token is present ([#TBD](https://github.com/MetaMask/core/pull/TBD))

## [23.8.0]

### Changed
Expand Down
26 changes: 25 additions & 1 deletion packages/transaction-pay-controller/src/utils/quotes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ describe('Quotes Utils', () => {
expect(strategy.getQuotes).toHaveBeenCalled();
});

it('clears state if no payment token', async () => {
it('clears state if no payment token and no fiat payment', async () => {
await run({
transactionData: {
...TRANSACTION_DATA_MOCK,
Expand Down Expand Up @@ -772,6 +772,30 @@ describe('Quotes Utils', () => {
});
});

it('updates metrics in metadata for fiat payment with no payment token', async () => {
await run({
transactionData: {
...TRANSACTION_DATA_MOCK,
paymentToken: undefined,
fiatPayment: { selectedPaymentMethodId: 'card-123' },
},
});

const transactionMetaMock = {} as TransactionMeta;
updateTransactionMock.mock.calls[0][1](transactionMetaMock);

expect(transactionMetaMock).toMatchObject({
metamaskPay: {
bridgeFeeFiat: TOTALS_MOCK.fees.provider.usd,
chainId: undefined,
networkFeeFiat: TOTALS_MOCK.fees.sourceNetwork.estimate.usd,
targetFiat: TOTALS_MOCK.targetAmount.usd,
tokenAddress: undefined,
totalFiat: TOTALS_MOCK.total.usd,
},
});
});

it('uses provider fee directly as bridgeFeeFiat even when providerFiat breakdown exists', async () => {
calculateTotalsMock.mockReturnValue({
...TOTALS_MOCK,
Expand Down
10 changes: 7 additions & 3 deletions packages/transaction-pay-controller/src/utils/quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export async function updateQuotes(

syncTransaction({
batchTransactions,
selectedFiatPayment: fiatPayment?.selectedPaymentMethodId,
hasQuotes: quotes.length > 0,
isPostQuote,
messenger: messenger as never,
Expand Down Expand Up @@ -203,6 +204,7 @@ export async function updateQuotes(
* @param request.isPostQuote - Whether this is a post-quote flow.
* @param request.messenger - Messenger instance.
* @param request.paymentToken - Payment token (source for standard flows, destination for post-quote).
* @param request.selectedFiatPayment - Selected fiat payment method ID.
* @param request.totals - Calculated totals.
* @param request.transactionId - ID of the transaction to sync.
*/
Expand All @@ -212,18 +214,20 @@ function syncTransaction({
isPostQuote,
messenger,
paymentToken,
selectedFiatPayment,
totals,
transactionId,
}: {
batchTransactions: BatchTransaction[];
selectedFiatPayment?: string;
hasQuotes: boolean;
isPostQuote?: boolean;
messenger: TransactionPayControllerMessenger;
paymentToken: TransactionPaymentToken | undefined;
totals: TransactionPayTotals;
transactionId: string;
}): void {
if (!paymentToken) {
if (!paymentToken && !selectedFiatPayment) {
return;
}

Expand All @@ -247,11 +251,11 @@ function syncTransaction({

tx.metamaskPay = {
bridgeFeeFiat: totals.fees.provider.usd,
chainId: paymentToken.chainId,
chainId: paymentToken?.chainId,
isPostQuote,
networkFeeFiat: totals.fees.sourceNetwork.estimate.usd,
targetFiat: totals.targetAmount.usd,
tokenAddress: paymentToken.address,
tokenAddress: paymentToken?.address,
totalFiat: totals.total.usd,
};
},
Expand Down
Loading