Skip to content

Commit

Permalink
fix: swap quote length
Browse files Browse the repository at this point in the history
  • Loading branch information
dmy147 committed May 15, 2024
1 parent ace88fd commit e038928
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
10 changes: 9 additions & 1 deletion apps/mobile/src/screens/Swap/components/QuoteItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,20 @@ export const DexQuoteItem = (
.times(receiveToken.price)
.minus(sortIncludeGasFee ? bestQuoteGasUsd : 0);

const percent = receivedUsdBn
let percent = receivedUsdBn
.minus(bestQuoteUsdBn)
.div(bestQuoteUsdBn)
.abs()
.times(100);

if (!receiveToken.price) {
percent = receivedTokeAmountBn
.minus(bestQuoteAmountBn)
.div(bestQuoteAmountBn)
.abs()
.times(100);
}

receivedUsd = formatUsdValue(
receivedTokeAmountBn.times(receiveToken.price || 0).toString(10),
);
Expand Down
31 changes: 20 additions & 11 deletions apps/mobile/src/screens/Swap/components/Quotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,27 @@ export const Quotes = ({

const viewCount = useMemo(() => {
if (swapViewList) {
const DexList = Object.keys(DEX);
const CEXList = Object.keys(CEX);

const availableList = [...DexList, ...CEXList];

return (
exchangeCount -
Object.values(swapViewList).filter(e => e === false).length
Object.entries(swapViewList).filter(
([name, e]) => e === false && availableList.includes(name),
).length
);
}
return exchangeCount;
}, [swapViewList]);

const tradeCount = useMemo(() => {
if (swapTradeList) {
return Object.values(swapTradeList).filter(e => e === true).length;
const TradeDexList = Object.keys(DEX);
return Object.entries(swapTradeList).filter(
([name, enable]) => enable === true && TradeDexList.includes(name),
).length;
}
return 0;
}, [swapTradeList]);
Expand All @@ -83,6 +93,7 @@ export const Quotes = ({
() => [
...(list?.sort((a, b) => {
const getNumber = (quote: typeof a) => {
const price = other.receiveToken.price ? other.receiveToken.price : 1;
if (quote.isDex) {
if (inSufficient) {
return new BigNumber(quote.data?.toTokenAmount || 0)
Expand All @@ -91,32 +102,30 @@ export const Quotes = ({
(quote.data?.toTokenDecimals ||
other.receiveToken.decimals),
)
.times(other.receiveToken.price);
.times(price);
}
if (!quote.preExecResult) {
return new BigNumber(-Number.MAX_SAFE_INTEGER);
return new BigNumber(Number.MIN_SAFE_INTEGER);
}

if (sortIncludeGasFee) {
return new BigNumber(
quote?.preExecResult.swapPreExecTx.balance_change
.receive_token_list?.[0]?.amount || 0,
)
.times(other.receiveToken.price)
.times(price)
.minus(quote?.preExecResult?.gasUsdValue || 0);
}

return new BigNumber(
quote?.preExecResult.swapPreExecTx.balance_change
.receive_token_list?.[0]?.amount || 0,
).times(other.receiveToken.price);
).times(price);
}

return new BigNumber(
quote?.data?.receive_token
? quote?.data?.receive_token?.amount
: -Number.MAX_SAFE_INTEGER,
).times(other.receiveToken.price);
return quote?.data?.receive_token
? new BigNumber(quote?.data?.receive_token?.amount).times(price)
: new BigNumber(Number.MIN_SAFE_INTEGER);
};
return getNumber(b).minus(getNumber(a)).toNumber();
}) || []),
Expand Down

0 comments on commit e038928

Please sign in to comment.