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

feat: slippage tune #2745

Merged
merged 1 commit into from
Jan 22, 2025
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
12 changes: 11 additions & 1 deletion src/ui/views/Bridge/Component/BridgeSlippage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const SlippageItem = styled.div`

const BRIDGE_SLIPPAGE = ['0.5', '1'];

const SWAP_SLIPPAGE = ['0.1', '0.5'];
export const SWAP_SLIPPAGE = ['0.5', '3'];

const BRIDGE_MAX_SLIPPAGE = 10;

Expand Down Expand Up @@ -215,6 +215,16 @@ export const BridgeSlippage = memo((props: BridgeSlippageProps) => {
[onChange, setAutoSlippage, setIsCustomSlippage]
);

useEffect(() => {
if (
!autoSlippage &&
!isCustomSlippage &&
SLIPPAGE.findIndex((item) => item === value) === -1
) {
setIsCustomSlippage(true);
}
}, [SLIPPAGE, autoSlippage, isCustomSlippage, setIsCustomSlippage, value]);

useEffect(() => {
if (tips) {
setSlippageOpen(true);
Expand Down
3 changes: 2 additions & 1 deletion src/ui/views/Swap/Component/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { BridgeSwitchBtn } from '../../Bridge/Component/BridgeSwitchButton';
import { BridgeShowMore } from '../../Bridge/Component/BridgeShowMore';
import { ReactComponent as RcIconWarningCC } from '@/ui/assets/warning-cc.svg';
import useDebounceValue from '@/ui/hooks/useDebounceValue';
import { SWAP_SLIPPAGE } from '../../Bridge/Component/BridgeSlippage';

const getDisabledTips: SelectChainItemProps['disabledTips'] = (ctx) => {
const chainItem = findChainByServerID(ctx.chain.serverId);
Expand Down Expand Up @@ -416,7 +417,7 @@ export const Main = () => {
!!payToken &&
!!receiveToken &&
activeProvider &&
Number(slippage) > 1
Number(slippage) >= Number(SWAP_SLIPPAGE[1])
) {
setShowMoreOpen(true);
}
Expand Down
4 changes: 4 additions & 0 deletions src/ui/views/Swap/hooks/slippage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ export const useSwapSlippage = () => {
...slippageStore,
};
};

export const getSwapAutoSlippageValue = (isStableCoin: boolean) => {
return isStableCoin ? '0.1' : '1';
};
4 changes: 2 additions & 2 deletions src/ui/views/Swap/hooks/token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { useAsyncInitializeChainList } from '@/ui/hooks/useChain';
import { SWAP_SUPPORT_CHAINS } from '@/constant';
import { findChain, findChainByEnum } from '@/utils/chain';
import { GasLevelType } from '../Component/ReserveGasPopup';
import { useSwapSlippage } from './slippage';
import { getSwapAutoSlippageValue, useSwapSlippage } from './slippage';
import { useLowCreditState } from '../Component/LowCreditModal';

const useTokenInfo = ({
Expand Down Expand Up @@ -399,7 +399,7 @@ export const useTokenPair = (userAddress: string) => {
setFeeRate('0');
}
if (slippageObj.autoSlippage) {
slippageObj.setSlippage(isStableCoin ? '0.1' : '0.5');
slippageObj.setSlippage(getSwapAutoSlippageValue(isStableCoin));
}
}, [slippageObj.autoSlippage, isWrapToken, isStableCoin]);

Expand Down
Loading