diff --git a/packages/transaction-pay-controller/CHANGELOG.md b/packages/transaction-pay-controller/CHANGELOG.md index 86b9cb40baa..904b34f0358 100644 --- a/packages/transaction-pay-controller/CHANGELOG.md +++ b/packages/transaction-pay-controller/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix relay quote `user` field for post-quote same-chain same-token transfers with an account override ([#9187](https://github.com/MetaMask/core/pull/9187)) + ## [23.10.0] ### Fixed diff --git a/packages/transaction-pay-controller/src/strategy/relay/relay-quotes.test.ts b/packages/transaction-pay-controller/src/strategy/relay/relay-quotes.test.ts index 2485154ce6d..f0342488b10 100644 --- a/packages/transaction-pay-controller/src/strategy/relay/relay-quotes.test.ts +++ b/packages/transaction-pay-controller/src/strategy/relay/relay-quotes.test.ts @@ -1411,6 +1411,45 @@ describe('Relay Quotes Utils', () => { expect(body.user).toBe(txParamsFrom); }); + it('keeps user as from when same token and chain with accountOverride and isPostQuote', async () => { + const txParamsFrom = '0xOriginalSender000000000000000000000000' as Hex; + const accountOverride = + '0xOverrideAccount0000000000000000000000000' as Hex; + const tokenAddress = '0xTokenAddress00000000000000000000000000' as Hex; + const chainId = '0x89' as Hex; + + successfulFetchMock.mockResolvedValue({ + ok: true, + json: async () => QUOTE_MOCK, + } as never); + + await getRelayQuotes({ + accountSupports7702: true, + messenger, + requests: [ + { + ...QUOTE_REQUEST_MOCK, + from: accountOverride, + isPostQuote: true, + sourceChainId: chainId, + sourceTokenAddress: tokenAddress, + targetChainId: chainId, + targetTokenAddress: tokenAddress, + }, + ], + transaction: { + ...TRANSACTION_META_MOCK, + txParams: { from: txParamsFrom }, + } as TransactionMeta, + }); + + const body = JSON.parse( + successfulFetchMock.mock.calls[0][1]?.body as string, + ); + + expect(body.user).toBe(accountOverride); + }); + it('keeps user as from when same token and chain with accountOverride but recipient differs', async () => { const txParamsFrom = '0xOriginalSender000000000000000000000000' as Hex; const accountOverride = diff --git a/packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts b/packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts index 48af7c57f3c..0f38149afa6 100644 --- a/packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts +++ b/packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts @@ -1221,7 +1221,8 @@ function getQuoteUser( return isSameSourceAndTarget && hasAccountOverride && - isRecipientAccountOverride + isRecipientAccountOverride && + !request.isPostQuote ? txParamsFrom : from; }