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

- Bump `@metamask/assets-controllers` from `^104.0.0` to `^104.1.0` ([#8509](https://github.com/MetaMask/core/pull/8509))

### Fixed

- Route Across status polling through the configured Across API base and support `depositTxnRef`/`fillTxnRef` for Across status responses ([#8512](https://github.com/MetaMask/core/pull/8512))

## [19.2.1]

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('Across Submit', () => {
transactionMeta: TRANSACTION_META_MOCK,
});
successfulFetchMock.mockResolvedValue({
json: async () => ({ status: 'pending' }),
json: async () => ({ status: 'success' }),
} as Response);
});

Expand Down Expand Up @@ -576,7 +576,7 @@ describe('Across Submit', () => {
);
});

it('polls Across status endpoint when quote includes a deposit id', async () => {
it('polls Across status endpoint with depositTxnRef from the source tx hash', async () => {
const confirmedTransaction = {
id: 'new-tx',
chainId: '0x1',
Expand Down Expand Up @@ -633,12 +633,58 @@ describe('Across Submit', () => {
});

expect(successfulFetchMock).toHaveBeenCalledWith(
expect.stringContaining('/deposit/status?'),
expect.stringContaining('/deposit/status?depositTxnRef=0xconfirmed'),
expect.objectContaining({ method: 'GET' }),
);
expect(result.transactionHash).toBe('0xtarget');
});

it('uses the configured proxy for approvals and deposit status polling', async () => {
const proxyApiBase = 'https://intents.dev-api.cx.metamask.io/across';

getRemoteFeatureFlagControllerStateMock.mockReturnValue({
...getDefaultRemoteFeatureFlagControllerState(),
remoteFeatureFlags: {
confirmations_pay: {
payStrategies: {
across: {
apiBase: proxyApiBase,
},
},
},
},
});

setupConfirmedSubmission();

successfulFetchMock
.mockResolvedValueOnce({
json: async () => ({
...QUOTE_MOCK.original.quote,
}),
} as Response)
.mockResolvedValueOnce({
json: async () => ({
destinationTxHash: '0xtarget',
status: 'success',
}),
} as Response);

const result = await submitAcrossQuotes({
messenger,
quotes: [buildDepositQuote()],
transaction: TRANSACTION_META_MOCK,
isSmartTransaction: jest.fn(),
});

const [statusUrl, statusOptions] = successfulFetchMock.mock.calls[1];
expect(statusUrl).toStrictEqual(
expect.stringContaining(`${proxyApiBase}/deposit/status?`),
);
expect(statusOptions).toMatchObject({ method: 'GET' });
expect(result.transactionHash).toBe('0xtarget');
});

it('throws when Across status endpoint reports failure', async () => {
const confirmedTransaction = {
id: 'new-tx',
Expand Down Expand Up @@ -747,6 +793,25 @@ describe('Across Submit', () => {
expect(result.transactionHash).toBe('0xfill');
});

it('returns fill txn ref when destination hash is missing', async () => {
setupConfirmedSubmission();
successfulFetchMock.mockResolvedValueOnce({
json: async () => ({
fillTxnRef: '0xfillref',
status: 'filled',
}),
} as Response);

const result = await submitAcrossQuotes({
messenger,
quotes: [buildDepositQuote()],
transaction: TRANSACTION_META_MOCK,
isSmartTransaction: jest.fn(),
});

expect(result.transactionHash).toBe('0xfillref');
});

it('returns tx hash when destination and fill hashes are missing', async () => {
setupConfirmedSubmission();
successfulFetchMock.mockResolvedValueOnce({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,34 +242,30 @@ async function submitTransactions(
? getTransaction(transactionIds.slice(-1)[0], messenger)?.hash
: undefined;

return await waitForAcrossCompletion(
quote.original,
hash as Hex | undefined,
messenger,
);
return await waitForAcrossCompletion(hash as Hex | undefined, messenger);
}

type AcrossStatusResponse = {
depositId?: number | string;
depositTxnRef?: Hex;
status?: string;
destinationTxHash?: Hex;
fillTxnRef?: Hex;
fillTxHash?: Hex;
txHash?: Hex;
};

async function waitForAcrossCompletion(
quote: AcrossQuote,
transactionHash: Hex | undefined,
messenger: TransactionPayControllerMessenger,
): Promise<Hex | undefined> {
if (!transactionHash || !quote.quote.id) {
if (!transactionHash) {
return transactionHash;
}

const config = getPayStrategiesConfig(messenger);
const params = new URLSearchParams({
depositId: quote.quote.id,
originChainId: String(quote.quote.swapTx.chainId),
txHash: transactionHash,
depositTxnRef: transactionHash,
});
const url = `${config.across.apiBase}/deposit/status?${params.toString()}`;

Expand Down Expand Up @@ -314,6 +310,7 @@ async function waitForAcrossCompletion(
) {
return (
status.destinationTxHash ??
status.fillTxnRef ??
status.fillTxHash ??
status.txHash ??
transactionHash
Expand Down
Loading