From cae6c87937a6b7160a7fb82f1c3cbad0846f99f5 Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Tue, 4 Jun 2024 12:15:32 -0400 Subject: [PATCH 1/5] disable flashbots on all chains other than mainnet --- .../Swap/components/AnimatedSwitch.tsx | 3 +++ .../screens/Swap/components/ReviewPanel.tsx | 23 ++++++++++++++----- .../screens/Swap/hooks/useSwapSettings.ts | 11 +++++++++ .../screens/Swap/providers/swap-provider.tsx | 4 +++- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/__swaps__/screens/Swap/components/AnimatedSwitch.tsx b/src/__swaps__/screens/Swap/components/AnimatedSwitch.tsx index 7a344be6a26..0ca0387f042 100644 --- a/src/__swaps__/screens/Swap/components/AnimatedSwitch.tsx +++ b/src/__swaps__/screens/Swap/components/AnimatedSwitch.tsx @@ -27,6 +27,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: props.disabled ? 0.4 : 1, }; }); @@ -41,6 +42,8 @@ export function AnimatedSwitch({ value, onToggle, activeLabel, inactiveLabel, .. }); const labelItem = useDerivedValue(() => { + if (props.disabled) return; + if (!activeLabel && !inactiveLabel) { return; } diff --git a/src/__swaps__/screens/Swap/components/ReviewPanel.tsx b/src/__swaps__/screens/Swap/components/ReviewPanel.tsx index 6cd64347ab8..7304be04222 100644 --- a/src/__swaps__/screens/Swap/components/ReviewPanel.tsx +++ b/src/__swaps__/screens/Swap/components/ReviewPanel.tsx @@ -118,6 +118,22 @@ function EstimatedArrivalTime() { ); } +function FlashbotsToggle() { + const { SwapSettings } = useSwapContext(); + + const inputAssetChainId = swapsStore(state => state.inputAsset?.chainId) ?? ChainId.mainnet; + + return ( + + ); +} + export function ReviewPanel() { const { navigate } = useNavigation(); const { isDarkMode } = useColorMode(); @@ -263,12 +279,7 @@ export function ReviewPanel() { - + diff --git a/src/__swaps__/screens/Swap/hooks/useSwapSettings.ts b/src/__swaps__/screens/Swap/hooks/useSwapSettings.ts index de8ea866af8..e9e8ae02bba 100644 --- a/src/__swaps__/screens/Swap/hooks/useSwapSettings.ts +++ b/src/__swaps__/screens/Swap/hooks/useSwapSettings.ts @@ -14,6 +14,16 @@ export const useSwapSettings = ({ inputAsset }: { inputAsset: SharedValue state.setSlippage); const setFlashbots = swapsStore(state => state.setFlashbots); + const checkIfFlashbotsIsEnabledOnSelectedInputAssetChain = (asset: ExtendedAnimatedAssetWithColors | null) => { + 'worklet'; + + if (asset?.chainId === ChainId.mainnet) { + flashbots.value = true; + } else { + flashbots.value = false; + } + }; + const onToggleFlashbots = () => { 'worklet'; @@ -41,6 +51,7 @@ export const useSwapSettings = ({ inputAsset }: { inputAsset: SharedValue { switch (type) { case SwapAssetType.inputAsset: internalSelectedInputAsset.value = asset; + + SwapSettings.checkIfFlashbotsIsEnabledOnSelectedInputAssetChain(asset); break; case SwapAssetType.outputAsset: internalSelectedOutputAsset.value = asset; break; } }, - [internalSelectedInputAsset, internalSelectedOutputAsset] + [SwapSettings, internalSelectedInputAsset, internalSelectedOutputAsset] ); const chainSetTimeoutId = useRef(null); From 08fd2f7f738f27d12f8c9a546f73c2c709ead2b4 Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Wed, 5 Jun 2024 16:48:46 -0400 Subject: [PATCH 2/5] . --- .../screens/Swap/components/AnimatedSwitch.tsx | 5 +++-- src/__swaps__/screens/Swap/components/ReviewPanel.tsx | 5 ++++- src/__swaps__/screens/Swap/hooks/useSwapSettings.ts | 11 ----------- .../screens/Swap/providers/swap-provider.tsx | 4 +--- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/__swaps__/screens/Swap/components/AnimatedSwitch.tsx b/src/__swaps__/screens/Swap/components/AnimatedSwitch.tsx index 0ca0387f042..46c5be57db4 100644 --- a/src/__swaps__/screens/Swap/components/AnimatedSwitch.tsx +++ b/src/__swaps__/screens/Swap/components/AnimatedSwitch.tsx @@ -12,9 +12,10 @@ type AnimatedSwitchProps = { value: SharedValue; activeLabel?: string; inactiveLabel?: string; + disabled?: boolean; } & Omit; -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'); @@ -27,7 +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: props.disabled ? 0.4 : 1, + opacity: disabled ? 0.4 : 1, }; }); diff --git a/src/__swaps__/screens/Swap/components/ReviewPanel.tsx b/src/__swaps__/screens/Swap/components/ReviewPanel.tsx index 7304be04222..87da94315c4 100644 --- a/src/__swaps__/screens/Swap/components/ReviewPanel.tsx +++ b/src/__swaps__/screens/Swap/components/ReviewPanel.tsx @@ -123,11 +123,14 @@ function FlashbotsToggle() { const inputAssetChainId = swapsStore(state => state.inputAsset?.chainId) ?? ChainId.mainnet; + // TODO: Add getNetworkObj().features.flashbots check here... + const flashbotsToggleValue = useDerivedValue(() => SwapSettings.flashbots.value); + return ( diff --git a/src/__swaps__/screens/Swap/hooks/useSwapSettings.ts b/src/__swaps__/screens/Swap/hooks/useSwapSettings.ts index e9e8ae02bba..de8ea866af8 100644 --- a/src/__swaps__/screens/Swap/hooks/useSwapSettings.ts +++ b/src/__swaps__/screens/Swap/hooks/useSwapSettings.ts @@ -14,16 +14,6 @@ export const useSwapSettings = ({ inputAsset }: { inputAsset: SharedValue state.setSlippage); const setFlashbots = swapsStore(state => state.setFlashbots); - const checkIfFlashbotsIsEnabledOnSelectedInputAssetChain = (asset: ExtendedAnimatedAssetWithColors | null) => { - 'worklet'; - - if (asset?.chainId === ChainId.mainnet) { - flashbots.value = true; - } else { - flashbots.value = false; - } - }; - const onToggleFlashbots = () => { 'worklet'; @@ -51,7 +41,6 @@ export const useSwapSettings = ({ inputAsset }: { inputAsset: SharedValue { switch (type) { case SwapAssetType.inputAsset: internalSelectedInputAsset.value = asset; - - SwapSettings.checkIfFlashbotsIsEnabledOnSelectedInputAssetChain(asset); break; case SwapAssetType.outputAsset: internalSelectedOutputAsset.value = asset; break; } }, - [SwapSettings, internalSelectedInputAsset, internalSelectedOutputAsset] + [internalSelectedInputAsset, internalSelectedOutputAsset] ); const chainSetTimeoutId = useRef(null); From 50e82383f8ed78dc930874d741479aa697d4880a Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Wed, 5 Jun 2024 17:06:41 -0400 Subject: [PATCH 3/5] add networkobj check --- src/__swaps__/screens/Swap/components/ReviewPanel.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/__swaps__/screens/Swap/components/ReviewPanel.tsx b/src/__swaps__/screens/Swap/components/ReviewPanel.tsx index 87da94315c4..5f9b1f0cac6 100644 --- a/src/__swaps__/screens/Swap/components/ReviewPanel.tsx +++ b/src/__swaps__/screens/Swap/components/ReviewPanel.tsx @@ -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'; const UNKNOWN_LABEL = i18n.t(i18n.l.swap.unknown); const REVIEW_LABEL = i18n.t(i18n.l.expanded_state.swap_details.review); @@ -122,14 +123,13 @@ function FlashbotsToggle() { const { SwapSettings } = useSwapContext(); const inputAssetChainId = swapsStore(state => state.inputAsset?.chainId) ?? ChainId.mainnet; - - // TODO: Add getNetworkObj().features.flashbots check here... - const flashbotsToggleValue = useDerivedValue(() => SwapSettings.flashbots.value); + const isFlashbotsEnabledForNetwork = getNetworkObj(ethereumUtils.getNetworkFromChainId(inputAssetChainId)); + const flashbotsToggleValue = useDerivedValue(() => isFlashbotsEnabledForNetwork && SwapSettings.flashbots.value); return ( Date: Wed, 5 Jun 2024 17:07:32 -0400 Subject: [PATCH 4/5] whoops --- src/__swaps__/screens/Swap/components/ReviewPanel.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__swaps__/screens/Swap/components/ReviewPanel.tsx b/src/__swaps__/screens/Swap/components/ReviewPanel.tsx index 5f9b1f0cac6..3d7c8407d48 100644 --- a/src/__swaps__/screens/Swap/components/ReviewPanel.tsx +++ b/src/__swaps__/screens/Swap/components/ReviewPanel.tsx @@ -123,7 +123,7 @@ function FlashbotsToggle() { const { SwapSettings } = useSwapContext(); const inputAssetChainId = swapsStore(state => state.inputAsset?.chainId) ?? ChainId.mainnet; - const isFlashbotsEnabledForNetwork = getNetworkObj(ethereumUtils.getNetworkFromChainId(inputAssetChainId)); + const isFlashbotsEnabledForNetwork = getNetworkObj(ethereumUtils.getNetworkFromChainId(inputAssetChainId)).features.flashbots; const flashbotsToggleValue = useDerivedValue(() => isFlashbotsEnabledForNetwork && SwapSettings.flashbots.value); return ( From dc19b7724aab3b88708b8117ba9e1f69d1c67438 Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Thu, 6 Jun 2024 10:06:17 -0400 Subject: [PATCH 5/5] fix lint --- src/__swaps__/screens/Swap/components/AnimatedSwitch.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__swaps__/screens/Swap/components/AnimatedSwitch.tsx b/src/__swaps__/screens/Swap/components/AnimatedSwitch.tsx index 46c5be57db4..9f2032ca3a6 100644 --- a/src/__swaps__/screens/Swap/components/AnimatedSwitch.tsx +++ b/src/__swaps__/screens/Swap/components/AnimatedSwitch.tsx @@ -43,7 +43,7 @@ export function AnimatedSwitch({ value, onToggle, activeLabel, inactiveLabel, di }); const labelItem = useDerivedValue(() => { - if (props.disabled) return; + if (disabled) return; if (!activeLabel && !inactiveLabel) { return;