Skip to content
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

Disable flashbots toggle on appropriate chains #5812

Merged
merged 6 commits into from
Jun 6, 2024
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
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
Loading