Skip to content

Commit

Permalink
Disable flashbots toggle on appropriate chains (#5812)
Browse files Browse the repository at this point in the history
* disable flashbots on all chains other than mainnet

* .

* add networkobj check

* whoops

* fix lint
  • Loading branch information
walmat authored Jun 6, 2024
1 parent b6d2935 commit 984fabe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/__swaps__/screens/Swap/components/AnimatedSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ type AnimatedSwitchProps = {
value: SharedValue<boolean>;
activeLabel?: string;
inactiveLabel?: string;
disabled?: boolean;
} & Omit<GestureHandlerButtonProps, 'children'>;

export function AnimatedSwitch({ value, onToggle, activeLabel, inactiveLabel, ...props }: AnimatedSwitchProps) {
export function AnimatedSwitch({ value, onToggle, activeLabel, inactiveLabel, disabled = false, ...props }: AnimatedSwitchProps) {
const { isDarkMode } = useColorMode();

const inactiveBg = useForegroundColor('fillSecondary');
Expand All @@ -27,6 +28,7 @@ export function AnimatedSwitch({ value, onToggle, activeLabel, inactiveLabel, ..
? withTiming(opacityWorklet(inactiveBg, 0.12), TIMING_CONFIGS.fadeConfig)
: withTiming(opacityWorklet(activeBg, 0.64), TIMING_CONFIGS.fadeConfig),
borderColor: opacityWorklet(border, 0.06),
opacity: disabled ? 0.4 : 1,
};
});

Expand All @@ -41,6 +43,8 @@ export function AnimatedSwitch({ value, onToggle, activeLabel, inactiveLabel, ..
});

const labelItem = useDerivedValue(() => {
if (disabled) return;

if (!activeLabel && !inactiveLabel) {
return;
}
Expand Down
26 changes: 20 additions & 6 deletions src/__swaps__/screens/Swap/components/ReviewPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { useNavigation } from '@/navigation';
import Routes from '@/navigation/routesNames';
import { ethereumUtils } from '@/utils';
import { getNativeAssetForNetwork } from '@/utils/ethereumUtils';
import { getNetworkObj } from '@/networks';
import { chainNameFromChainId } from '@/__swaps__/utils/chains';

const UNKNOWN_LABEL = i18n.t(i18n.l.swap.unknown);
Expand Down Expand Up @@ -119,6 +120,24 @@ function EstimatedArrivalTime() {
);
}

function FlashbotsToggle() {
const { SwapSettings } = useSwapContext();

const inputAssetChainId = swapsStore(state => state.inputAsset?.chainId) ?? ChainId.mainnet;
const isFlashbotsEnabledForNetwork = getNetworkObj(ethereumUtils.getNetworkFromChainId(inputAssetChainId)).features.flashbots;
const flashbotsToggleValue = useDerivedValue(() => isFlashbotsEnabledForNetwork && SwapSettings.flashbots.value);

return (
<AnimatedSwitch
onToggle={SwapSettings.onToggleFlashbots}
disabled={!isFlashbotsEnabledForNetwork}
value={flashbotsToggleValue}
activeLabel={i18n.t(i18n.l.expanded_state.swap.on)}
inactiveLabel={i18n.t(i18n.l.expanded_state.swap.off)}
/>
);
}

export function ReviewPanel() {
const { navigate } = useNavigation();
const { isDarkMode } = useColorMode();
Expand Down Expand Up @@ -266,12 +285,7 @@ export function ReviewPanel() {
</ButtonPressAnimation>
</Inline>

<AnimatedSwitch
onToggle={SwapSettings.onToggleFlashbots}
value={SwapSettings.flashbots}
activeLabel={i18n.t(i18n.l.expanded_state.swap.on)}
inactiveLabel={i18n.t(i18n.l.expanded_state.swap.off)}
/>
<FlashbotsToggle />
</Inline>

<Inline wrap={false} horizontalSpace="10px" alignVertical="center" alignHorizontal="justify">
Expand Down

0 comments on commit 984fabe

Please sign in to comment.