Skip to content
Merged
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
1 change: 1 addition & 0 deletions packages/transaction-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Export `getEffectiveRecipient` utility that returns the actual recipient of a transaction, decoding it from calldata for ERC-20/ERC-721/ERC-1155 token transfer methods where `txParams.to` is the token contract ([#9699](https://github.com/MetaMask/core/pull/9699))
- Add optional `strategy` field to `MetamaskPayMetadata` to persist the MetaMask Pay strategy used to fund the transaction ([#9733](https://github.com/MetaMask/core/pull/9733))

## [69.3.0]

Expand Down
3 changes: 3 additions & 0 deletions packages/transaction-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2176,6 +2176,9 @@ export type MetamaskPayMetadata = {
/** Source chain transaction hash if no local transaction. */
sourceHash?: Hex;

/** Pay strategy used to fund the transaction (e.g. "relay", "fiat"). */
strategy?: string;

/** Total amount of target token provided in fiat currency. */
targetFiat?: string;

Expand Down
1 change: 1 addition & 0 deletions packages/transaction-pay-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Add `atomic` field on `TransactionConfig` / `TransactionData` for a generic non-atomic post-Relay flow: when `atomic` is `false`, Relay bridges to an internally derived recipient (`getPaymentOverrideData` recipient for post-quote flows, otherwise the transaction's own `from`) and the second leg is submitted separately after completion, replacing the removed `relay-post-ma-vault` module ([#9497](https://github.com/MetaMask/core/pull/9497))
- Persist the quote strategy in the transaction's `metamaskPay.strategy` metadata so clients can derive pay metrics after `transactionData` is gone (e.g. after a restart) ([#9733](https://github.com/MetaMask/core/pull/9733))

### Changed

Expand Down
15 changes: 15 additions & 0 deletions packages/transaction-pay-controller/src/utils/quotes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,13 +908,27 @@ describe('Quotes Utils', () => {
bridgeFeeFiat: TOTALS_MOCK.fees.provider.usd,
chainId: TRANSACTION_DATA_MOCK.paymentToken?.chainId,
networkFeeFiat: TOTALS_MOCK.fees.sourceNetwork.estimate.usd,
strategy: TransactionPayStrategy.Across,
targetFiat: TOTALS_MOCK.targetAmount.usd,
tokenAddress: TRANSACTION_DATA_MOCK.paymentToken?.address,
totalFiat: TOTALS_MOCK.total.usd,
},
});
});

it('does not persist strategy in metadata when there are no executable quotes', async () => {
getQuotesMock.mockResolvedValue([
{ ...QUOTE_MOCK, strategy: TransactionPayStrategy.None },
]);

await run();

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

expect(transactionMetaMock.metamaskPay?.strategy).toBeUndefined();
});

it('updates metrics in metadata for fiat payment with no payment token', async () => {
await run({
transactionData: {
Expand All @@ -932,6 +946,7 @@ describe('Quotes Utils', () => {
bridgeFeeFiat: TOTALS_MOCK.fees.provider.usd,
chainId: undefined,
networkFeeFiat: TOTALS_MOCK.fees.sourceNetwork.estimate.usd,
strategy: TransactionPayStrategy.Across,
targetFiat: TOTALS_MOCK.targetAmount.usd,
tokenAddress: undefined,
totalFiat: TOTALS_MOCK.total.usd,
Expand Down
5 changes: 5 additions & 0 deletions packages/transaction-pay-controller/src/utils/quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export async function updateQuotes(
isPostQuote,
messenger: messenger as never,
paymentToken,
strategy: executableQuotes[0]?.strategy,
totals,
transactionId,
});
Expand Down Expand Up @@ -222,6 +223,7 @@ export async function updateQuotes(
* @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.strategy - Strategy of the executable quotes.
* @param request.totals - Calculated totals.
* @param request.transactionId - ID of the transaction to sync.
*/
Expand All @@ -232,6 +234,7 @@ function syncTransaction({
messenger,
paymentToken,
selectedFiatPayment,
strategy,
totals,
transactionId,
}: {
Expand All @@ -241,6 +244,7 @@ function syncTransaction({
isPostQuote?: boolean;
messenger: TransactionPayControllerMessenger;
paymentToken: TransactionPaymentToken | undefined;
strategy?: TransactionPayStrategy;
totals: TransactionPayTotals;
transactionId: string;
}): void {
Expand Down Expand Up @@ -278,6 +282,7 @@ function syncTransaction({
chainId: paymentToken?.chainId,
isPostQuote,
networkFeeFiat: totals.fees.sourceNetwork.estimate.usd,
strategy,
targetFiat: totals.targetAmount.usd,
tokenAddress: paymentToken?.address,
totalFiat: totals.total.usd,
Expand Down