Skip to content
Draft
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/bridge-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]

### Added

- Export `isTronChainId` from the package entrypoint ([#7697](https://github.com/MetaMask/core/pull/7697))

## [64.7.0]

### Changed
Expand Down
1 change: 1 addition & 0 deletions packages/bridge-controller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export {
isNativeAddress,
isSolanaChainId,
isBitcoinChainId,
isTronChainId,
isNonEvmChainId,
getNativeAssetForChainId,
getDefaultBridgeControllerState,
Expand Down
4 changes: 4 additions & 0 deletions packages/bridge-status-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/bridge-controller` from `^64.5.1` to `^64.7.0` ([#7667](https://github.com/MetaMask/core/pull/7667), [#7672](https://github.com/MetaMask/core/pull/7672), [#7694](https://github.com/MetaMask/core/pull/7694))

### Fixed

- Fix Tron same-chain swap polling and Completed event tracking ([#7697](https://github.com/MetaMask/core/pull/7697))

## [64.4.3]

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4609,13 +4609,6 @@ Array [
"snapId": "npm:@metamask/tron-snap",
},
],
Array [
"AccountsController:getAccountByAddress",
"TRX123...",
],
Array [
"TransactionController:getState",
],
]
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2275,8 +2275,8 @@ describe('BridgeStatusController', () => {

expect(mockMessengerCall.mock.calls).toMatchSnapshot();
expect(result).toMatchSnapshot();
// Swaps don't start polling (only bridges do)
expect(startPollingForBridgeTxStatusSpy).toHaveBeenCalledTimes(0);
// Tron swaps start polling for async settlement
expect(startPollingForBridgeTxStatusSpy).toHaveBeenCalledTimes(1);
expect(controller.state.txHistory[result.id]).toMatchSnapshot();
});

Expand Down
44 changes: 26 additions & 18 deletions packages/bridge-status-controller/src/bridge-status-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
UnifiedSwapBridgeEventName,
formatChainIdToCaip,
isCrossChain,
isTronChainId,
isEvmTxData,
isHardwareWallet,
MetricsActionType,
Expand Down Expand Up @@ -362,13 +363,8 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
}
});

// Restart polling if it was stopped and this is a bridge transaction
const isBridgeTx = isCrossChain(
historyItem.quote.srcChainId,
historyItem.quote.destChainId,
);

if (isBridgeTx) {
// Restart polling if it was stopped and this tx still needs status updates
if (this.#shouldPollHistoryItem(historyItem, targetTxMetaId)) {
// Check if polling was stopped (no active polling token)
const existingPollingToken =
this.#pollingTokensByTxMetaId[targetTxMetaId];
Expand Down Expand Up @@ -412,13 +408,9 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
this.#pollingTokensByTxMetaId[historyItem.txMetaId];
return !pollingToken;
})
// Swap txs don't need to have their statuses polled
// Only restart polling for items that still require status updates
.filter((historyItem) => {
const isBridgeTx = isCrossChain(
historyItem.quote.srcChainId,
historyItem.quote.destChainId,
);
return isBridgeTx;
return this.#shouldPollHistoryItem(historyItem, historyItem.txMetaId);
});

incompleteHistoryItems.forEach((historyItem) => {
Expand Down Expand Up @@ -507,16 +499,30 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
if (!txHistoryItem) {
return;
}
const { quote } = txHistoryItem;
const isIntent = txId.startsWith('intent:');
const isBridgeTx = isCrossChain(quote.srcChainId, quote.destChainId);
if (isBridgeTx || isIntent) {
if (this.#shouldPollHistoryItem(txHistoryItem, txId)) {
this.#pollingTokensByTxMetaId[txId] = this.startPolling({
bridgeTxMetaId: txId,
});
}
};

readonly #shouldPollHistoryItem = (
historyItem: BridgeHistoryItem,
txMetaId: string,
): boolean => {
const isIntent = txMetaId.startsWith('intent:');
const isBridgeTx = isCrossChain(
historyItem.quote.srcChainId,
historyItem.quote.destChainId,
);

// Tron same-chain swaps use async settlement and need polling
const isTronSameChainSwap =
!isBridgeTx && !isIntent && isTronChainId(historyItem.quote.srcChainId);

return isBridgeTx || isIntent || isTronSameChainSwap;
};

/**
* @deprecated For EVM/Solana swap/bridge txs we add tx to history in submitTx()
* For Solana swap/bridge we start polling in submitTx()
Expand Down Expand Up @@ -1390,6 +1396,8 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
quoteResponse.quote.srcChainId,
quoteResponse.quote.destChainId,
);
const isTronSameChainSwap =
!isBridgeTx && isTronChainId(quoteResponse.quote.srcChainId);

// Submit non-EVM tx (Solana, BTC, Tron)
if (isNonEvmChainId(quoteResponse.quote.srcChainId)) {
Expand Down Expand Up @@ -1570,7 +1578,7 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
// Start polling for bridge tx status
this.#startPollingForTxId(txMeta.id);
// Track non-EVM Swap completed event
if (!isBridgeTx) {
if (!isBridgeTx && !isTronSameChainSwap) {
this.#trackUnifiedSwapBridgeEvent(
UnifiedSwapBridgeEventName.Completed,
txMeta.id,
Expand Down