Skip to content

Commit 16f0679

Browse files
Merge branch 'main' into fix/remove-segmented-tab-on-confirm-import-token-page
2 parents 230a786 + 3db2064 commit 16f0679

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

shared/modules/selectors/index.test.ts

+23-2
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,35 @@ describe('Selectors', () => {
220220
);
221221

222222
jestIt(
223-
'returns false if feature flag is enabled, not a HW and is BSC network',
223+
'returns true if feature flag is enabled, not a HW and is BSC network with a default RPC URL',
224224
() => {
225225
const state = createSwapsMockStore();
226226
const newState = {
227227
...state,
228228
metamask: {
229229
...state.metamask,
230-
...mockNetworkState({ chainId: CHAIN_IDS.BSC }),
230+
...mockNetworkState({
231+
chainId: CHAIN_IDS.BSC,
232+
rpcUrl: 'https://bsc-dataseed.binance.org/',
233+
}),
234+
},
235+
};
236+
expect(getSmartTransactionsEnabled(newState)).toBe(true);
237+
},
238+
);
239+
240+
jestIt(
241+
'returns false if feature flag is enabled, not a HW and is BSC network with a non-default RPC URL',
242+
() => {
243+
const state = createSwapsMockStore();
244+
const newState = {
245+
...state,
246+
metamask: {
247+
...state.metamask,
248+
...mockNetworkState({
249+
chainId: CHAIN_IDS.BSC,
250+
rpcUrl: 'https://bsc-dataseed1.defibit.io/',
251+
}),
231252
},
232253
};
233254
expect(getSmartTransactionsEnabled(newState)).toBe(false);

shared/modules/selectors/smart-transactions.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,19 @@ export const getCurrentChainSupportsSmartTransactions = (
137137

138138
const getIsAllowedRpcUrlForSmartTransactions = (state: NetworkState) => {
139139
const chainId = getCurrentChainId(state);
140+
// Allow in non-production or if chain ID is on skip list.
140141
if (!isProduction() || SKIP_STX_RPC_URL_CHECK_CHAIN_IDS.includes(chainId)) {
141-
// Allow any STX RPC URL in development and testing environments or for specific chain IDs.
142142
return true;
143143
}
144-
const currentNetwork = getCurrentNetwork(state);
145-
if (!currentNetwork?.rpcUrl) {
144+
const rpcUrl = getCurrentNetwork(state)?.rpcUrl;
145+
if (!rpcUrl) {
146146
return false;
147147
}
148-
const rpcUrl = new URL(currentNetwork.rpcUrl);
149-
// Only allow STX in prod if an Infura RPC URL is being used.
150-
return rpcUrl?.hostname?.endsWith('.infura.io');
148+
const { hostname } = new URL(rpcUrl);
149+
if (!hostname) {
150+
return false;
151+
}
152+
return hostname.endsWith('.infura.io') || hostname.endsWith('.binance.org');
151153
};
152154

153155
export const getSmartTransactionsEnabled = (

0 commit comments

Comments
 (0)