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

- Fix Across deposit status polling to query `/deposit/status` with `depositTxnRef=<source transaction hash>` and return `fillTxnRef` when Across omits the destination hash ([#8489](https://github.com/MetaMask/core/pull/8489))

## [19.2.0]

### Changed
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,7 +633,7 @@ 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');
Expand Down Expand Up @@ -728,6 +728,25 @@ describe('Across Submit', () => {
}
});

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 fill tx hash when destination hash is missing', async () => {
setupConfirmedSubmission();
successfulFetchMock.mockResolvedValueOnce({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,34 +242,28 @@ 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 = {
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 @@ -313,6 +307,7 @@ async function waitForAcrossCompletion(
['completed', 'filled', 'success'].includes(normalizedStatus)
) {
return (
status.fillTxnRef ??
status.destinationTxHash ??
status.fillTxHash ??
status.txHash ??
Expand Down
Loading