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

[GSW-450] feat: Implement Swap Expected Result Details #235

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const SwapButtonTooltip: React.FC<WalletBalanceDetailInfoProps> = ({
</div>
<div className="tooltip-list">
<span>Gas Fee</span>
<span>{gasFeeStr} GNOT</span>
<span>{gasFeeStr}</span>
</div>
</SwapButtonTooltipWrap>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { ComponentStory, ComponentMeta } from "@storybook/react";
import SwapCardAutoRouter from "./SwapCardAutoRouter";
import { css } from "@emotion/react";
import { SwapRouteInfo } from "@models/swap/swap-route-info";
import PoolData from "@repositories/pool/mock/pools.json";

const pools = PoolData.pools;

const swapRouteInfos: SwapRouteInfo[] = [{
from: {
Expand Down Expand Up @@ -35,7 +32,7 @@ const swapRouteInfos: SwapRouteInfo[] = [{
currency: "GNOT"
},
gasFeeUSD: 0.1,
pools,
pools: [],
version: "V1",
weight: 100,
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AutoRouterWrapper, DotLine } from "./SwapCardAutoRouter.styles";
import { SwapRouteInfo } from "@models/swap/swap-route-info";
import DoubleLogo from "@components/common/double-logo/DoubleLogo";
import { SwapSummaryInfo } from "@models/swap/swap-summary-info";
import { useTokenImage } from "@hooks/token/use-token-image";

interface ContentProps {
swapRouteInfos: SwapRouteInfo[];
Expand All @@ -13,6 +14,7 @@ const SwapCardAutoRouter: React.FC<ContentProps> = ({
swapRouteInfos,
swapSummaryInfo,
}) => {

const bestGasFee = useMemo(() => {
const totalGasFee = swapRouteInfos.reduce((prev, current) => prev + current.gasFeeUSD, 0);
return `$${totalGasFee}`;
Expand All @@ -39,10 +41,27 @@ const SwapCardAutoRouterItem: React.FC<SwapCardAutoRouterItemProps> = ({
swapRouteInfo,
swapSummaryInfo,
}) => {
const { getTokenImage } = useTokenImage();

const weightStr = useMemo(() => {
return `${swapRouteInfo.weight}%`;
}, [swapRouteInfo.weight]);

const routeInfos = useMemo(() => {
let currentFromToken = swapSummaryInfo.tokenA.path;
return swapRouteInfo.pools.map((pool) => {
const ordered = currentFromToken === pool.tokenAPath;
const fromToken = ordered ? pool.tokenAPath : pool.tokenBPath;
const toToken = ordered ? pool.tokenBPath : pool.tokenAPath;
currentFromToken = toToken;
return {
fee: `${(pool.fee / 10000).toFixed(2)}%`,
fromToken,
toToken
};
});
}, [swapRouteInfo.pools, swapSummaryInfo.tokenA.path]);

return (
<div className="row">
<img src={swapSummaryInfo.tokenA.logoURI} alt="token logo" className="token-logo" />
Expand All @@ -51,14 +70,14 @@ const SwapCardAutoRouterItem: React.FC<SwapCardAutoRouterItemProps> = ({
<span>{weightStr}</span>
</div>
<DotLine />
{swapRouteInfo.pools.map((pool, index) => (
<>
<div key={`pool-${index}`} className="pair-fee">
<DoubleLogo left={pool.tokenA.logoURI} right={pool.tokenB.logoURI} size={16} />
<h1>{pool.fee}</h1>
{routeInfos.map((routeInfo, index) => (
<React.Fragment key={`pool-${index}`}>
<div className="pair-fee">
<DoubleLogo left={getTokenImage(routeInfo.fromToken) || ""} right={getTokenImage(routeInfo.toToken) || ""} size={16} />
<h1>{routeInfo.fee}</h1>
</div>
<DotLine key={`line-${index}`} />
</>
<DotLine />
</React.Fragment>
))}
<img src={swapSummaryInfo.tokenB.logoURI} alt="token logo" className="token-logo" />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import { ComponentStory, ComponentMeta } from "@storybook/react";
import SwapCardContentDetail from "./SwapCardContentDetail";
import { css } from "@emotion/react";
import { SwapRouteInfo } from "@models/swap/swap-route-info";
import PoolData from "@repositories/pool/mock/pools.json";
import { SwapSummaryInfo } from "@models/swap/swap-summary-info";

const pools = PoolData.pools;

const swapSummaryInfo: SwapSummaryInfo = {
tokenA: {
chainId: "test3",
Expand Down Expand Up @@ -74,7 +71,7 @@ const swapRouteInfos: SwapRouteInfo[] = [{
currency: "GNOT"
},
gasFeeUSD: 0.1,
pools,
pools: [],
version: "V1",
weight: 100,
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const SwapCardFeeInfo: React.FC<ContentProps> = ({
<div className="gas-fee">
<span className="gray-text">Gas Fee</span>
<span className="white-text">
{gasFeeStr} GNOT
{gasFeeStr}
<span className="gray-text">{`(${gasFeeUSDStr})`}</span>
</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { ComponentStory, ComponentMeta } from "@storybook/react";
import SwapCard from "./SwapCard";
import { css } from "@emotion/react";
import { SwapSummaryInfo } from "@models/swap/swap-summary-info";
import PoolData from "@repositories/pool/mock/pools.json";
import { SwapRouteInfo } from "@models/swap/swap-route-info";

const pools = PoolData.pools;

const swapSummaryInfo: SwapSummaryInfo = {
tokenA: {
Expand Down Expand Up @@ -74,7 +72,7 @@ export const swapRouteInfos: SwapRouteInfo[] = [{
currency: "GNOT"
},
gasFeeUSD: 0.1,
pools,
pools: [],
version: "V1",
weight: 100,
}];
Expand Down
Loading