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

Degen mode #5933

Merged
merged 3 commits into from
Jul 24, 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
43 changes: 43 additions & 0 deletions src/__swaps__/screens/Swap/components/ReviewPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ function FlashbotsToggle() {
);
}

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

return (
<AnimatedSwitch
onToggle={SwapSettings.onToggleDegenMode}
value={SwapSettings.degenMode}
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 @@ -352,6 +365,36 @@ export function ReviewPanel() {
</Inline>
</Animated.View>

{/* <Animated.View style={[{ height: REVIEW_SHEET_ROW_HEIGHT, justifyContent: 'center' }]}>
<Inline wrap={false} horizontalSpace="10px" alignVertical="center" alignHorizontal="justify">
<Inline wrap={false} horizontalSpace="12px">
<TextIcon color="labelTertiary" height={9} size="icon 13px" weight="bold" width={16}>
🐵
</TextIcon>
<Inline wrap={false} horizontalSpace="4px">
<Text color="labelTertiary" weight="semibold" size="15pt">
DEGEN MODE
</Text>
<Bleed space="12px">
<ButtonPressAnimation onPress={openFlashbotsExplainer} scaleTo={0.8}>
<Text
align="center"
color={{ custom: opacity(labelTertiary, 0.24) }}
size="icon 13px"
style={{ padding: 12, top: 0.5 }}
weight="semibold"
>
􀅴
</Text>
</ButtonPressAnimation>
</Bleed>
</Inline>
</Inline>

<DegenModeToggle />
</Inline>
</Animated.View> */}

Comment on lines +368 to +397
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to change the explainer on this once we enable it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes waiting for designs

<Box height={{ custom: REVIEW_SHEET_ROW_HEIGHT }} justifyContent="center">
<Inline wrap={false} horizontalSpace="10px" alignVertical="center" alignHorizontal="justify">
<Inline wrap={false} alignHorizontal="left" horizontalSpace="12px" alignVertical="center">
Expand Down
21 changes: 12 additions & 9 deletions src/__swaps__/screens/Swap/hooks/useSwapNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function useSwapNavigation({
quoteFetchingInterval,
selectedInputAsset,
selectedOutputAsset,
isDegenMode,
}: {
executeSwap: () => void;
inputProgress: SharedValue<number>;
Expand All @@ -27,6 +28,7 @@ export function useSwapNavigation({
quoteFetchingInterval: ReturnType<typeof useAnimatedInterval>;
selectedInputAsset: SharedValue<ExtendedAnimatedAssetWithColors | null>;
selectedOutputAsset: SharedValue<ExtendedAnimatedAssetWithColors | null>;
isDegenMode: SharedValue<boolean>;
}) {
const navigateBackToReview = useSharedValue(false);

Expand Down Expand Up @@ -167,17 +169,18 @@ export function useSwapNavigation({
if (configProgress.value === NavigationSteps.SHOW_GAS) {
if (navigateBackToReview.value) {
navigateBackToReview.value = false;
handleShowReview();
} else {
handleDismissGas();
return handleShowReview();
}
} else if (configProgress.value === NavigationSteps.SHOW_REVIEW) {
// TODO: Handle long press
executeSwap();
} else {
handleShowReview();

return handleDismissGas();
}
}, [configProgress, executeSwap, handleDismissGas, handleShowReview, navigateBackToReview]);

if (isDegenMode.value || configProgress.value === NavigationSteps.SHOW_REVIEW) {
return executeSwap();
}

return handleShowReview();
}, [configProgress.value, executeSwap, handleDismissGas, handleShowReview, isDegenMode.value, navigateBackToReview]);

return {
navigateBackToReview,
Expand Down
12 changes: 12 additions & 0 deletions src/__swaps__/screens/Swap/hooks/useSwapSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import { SharedValue, runOnJS, useSharedValue } from 'react-native-reanimated';

export const useSwapSettings = ({ inputAsset }: { inputAsset: SharedValue<ExtendedAnimatedAssetWithColors | null> }) => {
const flashbots = useSharedValue(swapsStore.getState().flashbots);
const degenMode = useSharedValue(swapsStore.getState().degenMode);
const slippage = useSharedValue(getDefaultSlippageWorklet(inputAsset.value?.chainId || ChainId.mainnet, getRemoteConfig()));

const setSlippage = swapsStore(state => state.setSlippage);
const setFlashbots = swapsStore(state => state.setFlashbots);
const setDegenMode = swapsStore(state => state.setFlashbots);

const onToggleFlashbots = () => {
'worklet';
Expand All @@ -37,11 +39,21 @@ export const useSwapSettings = ({ inputAsset }: { inputAsset: SharedValue<Extend
runOnJS(setSlippage)(slippage.value);
};

const onToggleDegenMode = () => {
'worklet';

const current = degenMode.value;
degenMode.value = !current;
runOnJS(setDegenMode)(!current);
};

return {
flashbots,
slippage,
degenMode,

onToggleFlashbots,
onUpdateSlippage,
onToggleDegenMode,
};
};
3 changes: 2 additions & 1 deletion src/__swaps__/screens/Swap/providers/swap-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ import { swapsStore } from '@/state/swaps/swapsStore';
import { ethereumUtils, haptics } from '@/utils';
import { CrosschainQuote, Quote, QuoteError } from '@rainbow-me/swaps';

import { IS_IOS } from '@/env';
import { Address } from 'viem';
import { clearCustomGasSettings } from '../hooks/useCustomGas';
import { getGasSettingsBySpeed, getSelectedGas, getSelectedGasSpeed } from '../hooks/useSelectedGas';
import { useSwapOutputQuotesDisabled } from '../hooks/useSwapOutputQuotesDisabled';
import { SyncGasStateToSharedValues, SyncQuoteSharedValuesToState } from './SyncSwapStateAndSharedValues';
import { IS_IOS } from '@/env';

const swapping = i18n.t(i18n.l.swap.actions.swapping);
const tapToSwap = i18n.t(i18n.l.swap.actions.tap_to_swap);
Expand Down Expand Up @@ -390,6 +390,7 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {
quoteFetchingInterval: SwapInputController.quoteFetchingInterval,
selectedInputAsset: internalSelectedInputAsset,
selectedOutputAsset: internalSelectedOutputAsset,
isDegenMode: SwapSettings.degenMode,
});

const SwapWarning = useSwapWarning({
Expand Down
5 changes: 5 additions & 0 deletions src/state/swaps/swapsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface SwapsState {
setSlippage: (slippage: string) => void;
source: Source | 'auto';
setSource: (source: Source | 'auto') => void;
degenMode: boolean;
setDegenMode: (degenMode: boolean) => void;
}

const updateCustomGasSettingsForFlashbots = (flashbots: boolean, chainId: ChainId) => {
Expand Down Expand Up @@ -75,6 +77,9 @@ export const swapsStore = createRainbowStore<SwapsState>(
setSlippage: (slippage: string) => set({ slippage }),
source: 'auto',
setSource: (source: Source | 'auto') => set({ source }),

degenMode: false,
setDegenMode: (degenMode: boolean) => set({ degenMode }),
}),
{
storageKey: 'swapsStore',
Expand Down
Loading