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

add execute swap #5754

Merged
merged 13 commits into from
May 29, 2024
11 changes: 4 additions & 7 deletions src/__swaps__/screens/Swap/components/SwapActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import React from 'react';
import { StyleProp, StyleSheet, TextStyle, ViewStyle } from 'react-native';
import Animated, { DerivedValue, useAnimatedStyle, useDerivedValue } from 'react-native-reanimated';

import { ButtonPressAnimation } from '@/components/animations';
import { AnimatedText, Box, Column, Columns, globalColors, useColorMode, useForegroundColor } from '@/design-system';
import { ExtendedAnimatedAssetWithColors } from '@/__swaps__/types/assets';
import { getColorValueForThemeWorklet } from '@/__swaps__/utils/swaps';
import { GestureHandlerV1Button } from './GestureHandlerV1Button';

export const SwapActionButton = ({
asset,
Expand All @@ -16,7 +16,6 @@ export const SwapActionButton = ({
icon,
iconStyle,
label,
onLongPress,
onPress,
outline,
rightIcon,
Expand All @@ -31,7 +30,6 @@ export const SwapActionButton = ({
icon?: string | DerivedValue<string | undefined>;
iconStyle?: StyleProp<TextStyle>;
label: string | DerivedValue<string | undefined>;
onLongPress?: () => void;
onPress?: () => void;
outline?: boolean;
rightIcon?: string;
Expand Down Expand Up @@ -98,9 +96,8 @@ export const SwapActionButton = ({
});

return (
<ButtonPressAnimation
onLongPress={onLongPress}
onPress={onPress}
<GestureHandlerV1Button
onPressWorklet={onPress}
scaleTo={scaleTo || (hugContent ? undefined : 0.925)}
style={{
...(hugContent && feedActionButtonStyles.buttonWrapper),
Expand Down Expand Up @@ -145,7 +142,7 @@ export const SwapActionButton = ({
)}
</Columns>
</Box>
</ButtonPressAnimation>
</GestureHandlerV1Button>
);
};

Expand Down
4 changes: 2 additions & 2 deletions src/__swaps__/screens/Swap/components/SwapBottomPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import Animated, { runOnUI, useAnimatedStyle, withSpring } from 'react-native-reanimated';
import Animated, { useAnimatedStyle, withSpring } from 'react-native-reanimated';
import { StyleSheet } from 'react-native';
import { getSoftMenuBarHeight } from 'react-native-extra-dimensions-android';
import { PanGestureHandler } from 'react-native-gesture-handler';
Expand Down Expand Up @@ -74,7 +74,7 @@ export function SwapBottomPanel() {
</Box>
</Column>
<SwapActionButton
onPress={() => runOnUI(SwapNavigation.handleSwapAction)()}
onPress={SwapNavigation.handleSwapAction}
asset={internalSelectedOutputAsset}
icon={confirmButtonIcon}
iconStyle={confirmButtonIconStyle}
Expand Down
2 changes: 1 addition & 1 deletion src/__swaps__/screens/Swap/components/SwapInputAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function SwapInputActionButton() {
disableShadow={isDarkMode}
hugContent
label={label}
onPress={runOnUI(SwapNavigation.handleInputPress)}
onPress={SwapNavigation.handleInputPress}
rightIcon={'􀆏'}
small
/>
Expand Down
2 changes: 1 addition & 1 deletion src/__swaps__/screens/Swap/components/SwapOutputAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function SwapOutputActionButton() {
disableShadow={isDarkMode}
hugContent
label={label}
onPress={runOnUI(SwapNavigation.handleOutputPress)}
onPress={SwapNavigation.handleOutputPress}
rightIcon={'􀆏'}
small
/>
Expand Down
8 changes: 8 additions & 0 deletions src/__swaps__/screens/Swap/hooks/useSelectedGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ export function useSelectedGas(chainId: ChainId) {
return useGasSettings(chainId, selectedGasSpeed);
}

export function getGasSettingsBySpeed(chainId: ChainId) {
const suggestions = getCachedGasSuggestions(chainId);
return {
...suggestions,
custom: getCustomGasSettings(chainId),
};
}

export function getGasSettings(speed: GasSpeed, chainId: ChainId) {
if (speed === 'custom') return getCustomGasSettings(chainId);
return getCachedGasSuggestions(chainId)?.[speed];
Expand Down
8 changes: 5 additions & 3 deletions src/__swaps__/screens/Swap/hooks/useSwapNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export function useSwapNavigation({
inputProgress,
outputProgress,
configProgress,
executeSwap,
}: {
SwapInputController: ReturnType<typeof useSwapInputsController>;
inputProgress: SharedValue<number>;
outputProgress: SharedValue<number>;
configProgress: SharedValue<number>;
executeSwap: () => void;
}) {
const navigateBackToReview = useSharedValue(false);

Expand Down Expand Up @@ -147,12 +149,12 @@ export function useSwapNavigation({
handleDismissGas();
}
} else if (configProgress.value === NavigationSteps.SHOW_REVIEW) {
// TODO: Handle executing swap
handleDismissReview();
// TODO: Handle long press
executeSwap();
} else {
handleShowReview();
}
}, [configProgress, handleDismissGas, handleDismissReview, handleShowReview, navigateBackToReview]);
}, [configProgress.value, executeSwap, handleDismissGas, handleShowReview, navigateBackToReview]);

return {
navigateBackToReview,
Expand Down
Loading
Loading