From 4b2e47f300eb161e1da95ac73be2e669fae0f213 Mon Sep 17 00:00:00 2001 From: 0xMasayoshi <0xMasayoshi@protonmail.com> Date: Mon, 11 Nov 2024 03:18:29 +0700 Subject: [PATCH] feat: ZapInfoCard --- .../(evm)/[chainId]/pool/v2/add/page.tsx | 6 + .../src/ui/pool/SmartPoolLiquidityWidget.tsx | 2 +- .../Add/SteerPositionZap.tsx | 13 +- .../SteerStrategies/SteerBaseStrategy.tsx | 2 +- apps/web/src/ui/pool/ZapInfoCard.tsx | 85 ++++++++ apps/web/src/ui/pool/ZapRouteDialog.tsx | 184 ++++++++++++++++++ apps/web/src/ui/pool/ZapSectionLegacy.tsx | 80 ++++---- 7 files changed, 334 insertions(+), 38 deletions(-) create mode 100644 apps/web/src/ui/pool/ZapInfoCard.tsx create mode 100644 apps/web/src/ui/pool/ZapRouteDialog.tsx diff --git a/apps/web/src/app/(networks)/(evm)/[chainId]/pool/v2/add/page.tsx b/apps/web/src/app/(networks)/(evm)/[chainId]/pool/v2/add/page.tsx index c4d729383c..79fa60f9ed 100644 --- a/apps/web/src/app/(networks)/(evm)/[chainId]/pool/v2/add/page.tsx +++ b/apps/web/src/app/(networks)/(evm)/[chainId]/pool/v2/add/page.tsx @@ -32,6 +32,7 @@ import { AddSectionReviewModalLegacy } from 'src/ui/pool/AddSectionReviewModalLe import { SelectNetworkWidget } from 'src/ui/pool/SelectNetworkWidget' import { SelectTokensWidget } from 'src/ui/pool/SelectTokensWidget' import { ToggleZapCard } from 'src/ui/pool/ToggleZapCard' +import { ZapInfoCard } from 'src/ui/pool/ZapInfoCard' import { ChainId, ChainKey, TESTNET_CHAIN_IDS } from 'sushi/chain' import { SUSHISWAP_V2_ROUTER_ADDRESS, @@ -317,6 +318,11 @@ const ZapWidget: FC = ({ chainId, pool, poolState, title }) => { + ) } diff --git a/apps/web/src/ui/pool/SmartPoolLiquidityWidget.tsx b/apps/web/src/ui/pool/SmartPoolLiquidityWidget.tsx index a3dc5e9af0..e31dead651 100644 --- a/apps/web/src/ui/pool/SmartPoolLiquidityWidget.tsx +++ b/apps/web/src/ui/pool/SmartPoolLiquidityWidget.tsx @@ -60,7 +60,7 @@ export const SmartPoolLiquidityWidget: FC = ({ ) : null} {useZap ? ( - + ) : ( diff --git a/apps/web/src/ui/pool/Steer/SteerLiquidityManagement/Add/SteerPositionZap.tsx b/apps/web/src/ui/pool/Steer/SteerLiquidityManagement/Add/SteerPositionZap.tsx index 22fe43f028..cc67a1632b 100644 --- a/apps/web/src/ui/pool/Steer/SteerLiquidityManagement/Add/SteerPositionZap.tsx +++ b/apps/web/src/ui/pool/Steer/SteerLiquidityManagement/Add/SteerPositionZap.tsx @@ -8,15 +8,20 @@ import { useZap } from 'src/lib/hooks' import { Web3Input } from 'src/lib/wagmi/components/web3-input' import { Checker } from 'src/lib/wagmi/systems/Checker' import { CheckerProvider } from 'src/lib/wagmi/systems/Checker/Provider' +import { ZapInfoCard } from 'src/ui/pool/ZapInfoCard' import { defaultCurrency, isWNativeSupported } from 'sushi/config' import { Amount, Type, tryParseAmount } from 'sushi/currency' import { useAccount, useEstimateGas, useSendTransaction } from 'wagmi' interface SteerPositionAddProps { vault: VaultV1 + tokenRatios?: { token0: number; token1: number } } -export const SteerPositionZap: FC = ({ vault }) => { +export const SteerPositionZap: FC = ({ + vault, + tokenRatios, +}) => { const { address } = useAccount() const [inputAmount, setInputAmount] = useState('') @@ -117,6 +122,12 @@ export const SteerPositionZap: FC = ({ vault }) => { + ) } diff --git a/apps/web/src/ui/pool/Steer/SteerStrategies/SteerBaseStrategy.tsx b/apps/web/src/ui/pool/Steer/SteerStrategies/SteerBaseStrategy.tsx index 45b52f3ee9..5ae3845ac5 100644 --- a/apps/web/src/ui/pool/Steer/SteerStrategies/SteerBaseStrategy.tsx +++ b/apps/web/src/ui/pool/Steer/SteerStrategies/SteerBaseStrategy.tsx @@ -95,7 +95,7 @@ export const SteerBaseStrategy: SteerStrategyComponent = ({ ) : null} {useZap ? ( - + ) : ( diff --git a/apps/web/src/ui/pool/ZapInfoCard.tsx b/apps/web/src/ui/pool/ZapInfoCard.tsx new file mode 100644 index 0000000000..d3999aec89 --- /dev/null +++ b/apps/web/src/ui/pool/ZapInfoCard.tsx @@ -0,0 +1,85 @@ +import { SteerVault } from '@sushiswap/steer-sdk' +import { + Card, + CardContent, + Collapsible, + SkeletonBox, + SkeletonText, + classNames, +} from '@sushiswap/ui' +import { FC, useMemo } from 'react' +import { ZapResponse } from 'src/lib/hooks' +import { + warningSeverity, + warningSeverityClassName, +} from 'src/lib/swap/warningSeverity' +import { Type } from 'sushi/currency' +import { Percent, ZERO } from 'sushi/math' +import { SushiSwapV2Pool } from 'sushi/pool' +import { ZapRouteDialog } from './ZapRouteDialog' + +interface ZapInfoCardProps { + zapResponse?: ZapResponse + inputCurrency: Type + pool: SushiSwapV2Pool | SteerVault | null + tokenRatios?: { token0: number; token1: number } +} + +export const ZapInfoCard: FC = ({ + zapResponse, + inputCurrency, + pool, + tokenRatios, +}) => { + const priceImpact = useMemo( + () => + typeof zapResponse?.priceImpact === 'number' + ? new Percent(zapResponse.priceImpact, 10_000) + : undefined, + [zapResponse], + ) + + return ( + + + +
+ Price impact + + {!priceImpact ? ( + + ) : priceImpact ? ( + `${ + priceImpact?.lessThan(ZERO) + ? '+' + : priceImpact?.greaterThan(ZERO) + ? '-' + : '' + }${Math.abs(Number(priceImpact?.toFixed(2)))}%` + ) : null} + +
+
+ Route + {pool ? ( + + View Route + + ) : ( + + )} +
+
+
+
+ ) +} diff --git a/apps/web/src/ui/pool/ZapRouteDialog.tsx b/apps/web/src/ui/pool/ZapRouteDialog.tsx new file mode 100644 index 0000000000..b2841ee43e --- /dev/null +++ b/apps/web/src/ui/pool/ZapRouteDialog.tsx @@ -0,0 +1,184 @@ +import { SteerVault } from '@sushiswap/steer-sdk' +import { + Currency, + Dialog, + DialogContent, + DialogHeader, + DialogTitle, + DialogTrigger, +} from '@sushiswap/ui' +import { FC, ReactNode, useMemo } from 'react' +import { Token, Type } from 'sushi/currency' +import { formatPercent } from 'sushi/format' +import { SushiSwapV2Pool } from 'sushi/pool' + +interface ZapRouteDialogProps { + children: ReactNode + inputCurrency: Type + pool: SushiSwapV2Pool | SteerVault + tokenRatios?: { token0: number; token1: number } +} + +export const ZapRouteDialog: FC = ({ + children, + inputCurrency, + pool, + tokenRatios, +}) => { + const [token0, token1] = useMemo( + () => [ + pool.token0 instanceof Token ? pool.token0 : new Token(pool.token0), + pool.token1 instanceof Token ? pool.token1 : new Token(pool.token1), + ], + [pool], + ) + + return ( + + {children} + + + Route + + +
+ Split & Swap +
+
+
+ + + {inputCurrency.symbol} + +
+
+
+ {pool instanceof SushiSwapV2Pool + ? '50%' + : tokenRatios + ? `${formatPercent(tokenRatios.token0)}` + : '-%'} +
+ + SushiSwap + +
+
+ + + {token0.symbol} + +
+
+
+
+ + + {inputCurrency.symbol} + +
+
+
+ {pool instanceof SushiSwapV2Pool + ? '50%' + : tokenRatios + ? `${formatPercent(tokenRatios.token1)}` + : '-%'} +
+ + SushiSwap + +
+
+ + + {token1.symbol} + +
+
+
+
+ +
+ Add Liquidity +
+
+
+
+ + + {token0.symbol} + +
+
+ + + {token1.symbol} + +
+
+
+
100%
+ + Deposit to{' '} + {pool instanceof SushiSwapV2Pool ? 'SushiSwap V2' : 'Steer'} + +
+
+ + +
+ +
+
+ + {pool instanceof SushiSwapV2Pool ? 'SLP' : 'Steer LP'} + +
+
+
+
+
+
+ ) +} diff --git a/apps/web/src/ui/pool/ZapSectionLegacy.tsx b/apps/web/src/ui/pool/ZapSectionLegacy.tsx index ed1da0733e..79a1749ffa 100644 --- a/apps/web/src/ui/pool/ZapSectionLegacy.tsx +++ b/apps/web/src/ui/pool/ZapSectionLegacy.tsx @@ -31,6 +31,7 @@ import { SushiSwapV2Pool } from 'sushi/pool' import { useAccount, useEstimateGas, useSendTransaction } from 'wagmi' import { useZap } from '../../lib/hooks' import { ToggleZapCard } from './ToggleZapCard' +import { ZapInfoCard } from './ZapInfoCard' interface ZapSectionLegacyProps { chainId: SushiSwapV2ChainId @@ -134,44 +135,53 @@ export const ZapSectionLegacy: FC = ({ allowNative={isWNativeSupported(chainId)} /> - - - - - + + + + - - - - - - - - + + + + + + + + + + + )