Skip to content

Commit

Permalink
Bring in flashbots functionality for networks that support it (#5800)
Browse files Browse the repository at this point in the history
* progress on bringing back flashbots

* cleanup
  • Loading branch information
walmat authored Jun 1, 2024
1 parent d8f7fec commit c9a2e63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/__swaps__/screens/Swap/providers/swap-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ import { Navigation } from '@/navigation';
import { WrappedAlert as Alert } from '@/helpers/alert';
import Routes from '@/navigation/routesNames';
import { ethereumUtils } from '@/utils';
import { getCachedProviderForNetwork, isHardHat } from '@/handlers/web3';
import { getCachedProviderForNetwork, getFlashbotsProvider, isHardHat } from '@/handlers/web3';
import { loadWallet } from '@/model/wallet';
import { walletExecuteRap } from '@/raps/execute';
import { queryClient } from '@/react-query';
import { userAssetsQueryKey } from '@/resources/assets/UserAssetsQuery';
import { useAccountSettings } from '@/hooks';
import { getGasSettingsBySpeed, getSelectedGas } from '../hooks/useSelectedGas';
import { LegacyTransactionGasParamAmounts, TransactionGasParamAmounts } from '@/entities';
import { getNetworkObj } from '@/networks';
import { userAssetsStore } from '@/state/assets/userAssets';

const swapping = i18n.t(i18n.l.swap.actions.swapping);
Expand Down Expand Up @@ -157,21 +158,23 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {
};

const network = ethereumUtils.getNetworkFromChainId(parameters.chainId);
const provider = getCachedProviderForNetwork(network);
const provider =
parameters.flashbots && getNetworkObj(network).features.flashbots
? await getFlashbotsProvider()
: getCachedProviderForNetwork(network);
const providerUrl = provider?.connection?.url;
const connectedToHardhat = isHardHat(providerUrl);

const wallet = await loadWallet(parameters.quote.from, false, provider);
if (!wallet) {
const selectedGas = getSelectedGas(parameters.chainId);
if (!selectedGas) {
runOnUI(resetSwappingStatus)();
Alert.alert(i18n.t(i18n.l.swap.unable_to_load_wallet));
Alert.alert(i18n.t(i18n.l.gas.unable_to_determine_selected_gas));
return;
}

const selectedGas = getSelectedGas(parameters.chainId);
if (!selectedGas) {
const wallet = await loadWallet(parameters.quote.from, false, provider);
if (!wallet) {
runOnUI(resetSwappingStatus)();
// TODO: Show alert or something but this should never happen technically
Alert.alert(i18n.t(i18n.l.swap.unable_to_load_wallet));
return;
}
Expand Down Expand Up @@ -502,7 +505,6 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {
}
});

// TODO: i18n these
const confirmButtonLabel = useDerivedValue(() => {
if (isSwapping.value) {
return swapping;
Expand Down
1 change: 1 addition & 0 deletions src/languages/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,7 @@
"urgent": "Urgent",
"custom": "Custom"
},
"unable_to_determine_selected_gas": "Unable to determine selected gas",
"network_fee": "Est. network fee",
"current_base_fee": "Current base fee",
"max_base_fee": "Max base fee",
Expand Down

0 comments on commit c9a2e63

Please sign in to comment.