Skip to content

fix: use networkClientId if included in transaction #30758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 5, 2025
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
5 changes: 1 addition & 4 deletions app/scripts/controllers/bridge/bridge-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,7 @@ describe('BridgeController', function () {
expect(bridgeController.state.bridgeState).toEqual(
expect.objectContaining({
quoteRequest: { ...quoteRequest, insufficientBal: false },
quotes: [
...mockBridgeQuotesNativeErc20Eth,
...mockBridgeQuotesNativeErc20Eth,
],
quotes: [],
quotesLoadingStatus: 2,
quoteFetchError: 'Network error',
quotesRefreshCount: 3,
Expand Down
1 change: 1 addition & 0 deletions app/scripts/controllers/bridge/bridge-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ export default class BridgeController extends StaticIntervalPollingController<Br
this.update((_state) => {
_state.bridgeState = {
...bridgeState,
quotes: DEFAULT_BRIDGE_STATE.quotes,
quoteFetchError:
error instanceof Error ? error.message : 'Unknown error',
quotesLoadingStatus: RequestStatus.ERROR,
Expand Down
4 changes: 3 additions & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5376,7 +5376,9 @@ export default class MetamaskController extends EventEmitter {
internalAccounts: this.accountsController.listAccounts(),
dappRequest,
networkClientId:
dappRequest?.networkClientId ?? this.#getGlobalNetworkClientId(),
dappRequest?.networkClientId ??
transactionOptions?.networkClientId ??
this.#getGlobalNetworkClientId(),
selectedAccount: this.accountsController.getAccountByAddress(
transactionParams.from,
),
Expand Down
12 changes: 12 additions & 0 deletions ui/pages/bridge/hooks/useHandleTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
getMemoizedUnapprovedTemplatedConfirmations,
getMemoizedUnapprovedConfirmations,
getSelectedInternalAccount,
getNetworkConfigurationIdByChainId,
} from '../../../selectors';
import {
CONFIRM_TRANSACTION_ROUTE,
Expand All @@ -49,6 +50,10 @@ export default function useHandleTx() {
const networkGasFeeEstimates = useSelector(getGasFeeEstimates);
const shouldUseSmartTransaction = useSelector(getIsSmartTransaction);

const networkConfigurationIds = useSelector(
getNetworkConfigurationIdByChainId,
);

const handleEvmTx = async ({
txType,
txParams,
Expand Down Expand Up @@ -84,18 +89,25 @@ export default function useHandleTx() {
maxPriorityFeePerGas,
};

const networkClientId =
networkConfigurationIds[
hexChainId as keyof typeof networkConfigurationIds
];

// For the bridge tx only
// Need access to the txMeta.id right away so we can track it in BridgeStatusController,
// so we call addTransaction instead of addTransactionAndWaitForPublish
// if it's an STX, addTransactionAndWaitForPublish blocks until there is a txHash
let txMeta: TransactionMeta;
if (txType === TransactionType.bridge && shouldUseSmartTransaction) {
txMeta = await addTransaction(finalTxParams, {
networkClientId,
requireApproval: false,
type: txType,
});
} else {
txMeta = await addTransactionAndWaitForPublish(finalTxParams, {
networkClientId,
requireApproval: false,
type: txType,
});
Expand Down
3 changes: 3 additions & 0 deletions ui/pages/bridge/hooks/useSubmitBridgeTransaction.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ describe('ui/pages/bridge/hooks/useSubmitBridgeTransaction', () => {
value: '0x00',
},
{
networkClientId: expect.any(String),
requireApproval: false,
type: 'bridge',
},
Expand Down Expand Up @@ -218,6 +219,7 @@ describe('ui/pages/bridge/hooks/useSubmitBridgeTransaction', () => {
value: '0x00',
},
{
networkClientId: expect.any(String),
requireApproval: false,
type: 'bridgeApproval',
},
Expand All @@ -236,6 +238,7 @@ describe('ui/pages/bridge/hooks/useSubmitBridgeTransaction', () => {
value: '0x00',
},
{
networkClientId: expect.any(String),
requireApproval: false,
type: 'bridge',
},
Expand Down
4 changes: 4 additions & 0 deletions ui/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,7 @@ export function addTransactionAndRouteToConfirmationPage(
* @param options.swaps.hasApproveTx - Whether the swap required an approval transaction.
* @param options.swaps.meta - Additional transaction metadata required by swaps.
* @param options.type
* @param options.networkClientId - The network client id to use for the transaction.
* @returns
*/
export async function addTransactionAndWaitForPublish(
Expand All @@ -1043,6 +1044,7 @@ export async function addTransactionAndWaitForPublish(
requireApproval?: boolean;
swaps?: { hasApproveTx?: boolean; meta?: Record<string, unknown> };
type?: TransactionType;
networkClientId?: string;
},
): Promise<TransactionMeta> {
log.debug('background.addTransactionAndWaitForPublish');
Expand Down Expand Up @@ -1075,6 +1077,7 @@ export async function addTransactionAndWaitForPublish(
* @param options.swaps.hasApproveTx - Whether the swap required an approval transaction.
* @param options.swaps.meta - Additional transaction metadata required by swaps.
* @param options.type
* @param options.networkClientId - The network client id to use for the transaction.
* @returns
*/
export async function addTransaction(
Expand All @@ -1084,6 +1087,7 @@ export async function addTransaction(
requireApproval?: boolean;
swaps?: { hasApproveTx?: boolean; meta?: Record<string, unknown> };
type?: TransactionType;
networkClientId?: string;
},
): Promise<TransactionMeta> {
log.debug('background.addTransaction');
Expand Down
Loading