Skip to content

Commit 9e07574

Browse files
aidai524xieqian
andauthored
Hotfix swap estimate (#474)
* fix swap estimate issue * add log * fix swap issue * remove log * fix ui bugs * add link for Top Farm APY --------- Co-authored-by: xieqian <[email protected]>
1 parent 6d44c7a commit 9e07574

File tree

6 files changed

+81
-53
lines changed

6 files changed

+81
-53
lines changed

src/components/meme/Overview.tsx

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,24 @@ const Overview = () => {
4040
const list = Object.entries(lpSeeds);
4141
if (!list.length) return [];
4242
return list.reduce((acc, cur) => {
43-
const [, seed] = cur;
43+
const [seedId, seed] = cur;
4444
const apr = getSeedApr(seed);
45-
if (!acc[0]) return [seed, apr];
45+
if (!acc[0]) return [seed, apr, seedId];
4646
if (Big(acc[1]).gt(apr)) {
4747
return acc;
4848
} else {
49-
return [seed, apr];
49+
return [seed, apr, seedId];
5050
}
5151
}, []);
5252
}, [lpSeeds]);
53+
function goFarmDetail(seed_id: string) {
54+
const lpSeed = lpSeeds[seed_id];
55+
if (lpSeed.farmList[0].status == 'Ended') {
56+
window.open(`/v2farms/${lpSeed.pool.id}-e`);
57+
} else {
58+
window.open(`/v2farms/${lpSeed.pool.id}-r`);
59+
}
60+
}
5361
const is_mobile = isMobile();
5462
return (
5563
<>
@@ -81,7 +89,14 @@ const Overview = () => {
8189
<span className="text-xl gotham_bold text-white">-</span>
8290
)}
8391
</TemplateMobile>
84-
<TemplateMobile title="Top Farm APY">
92+
<TemplateMobile
93+
title="Top Farm APY"
94+
onClick={() => {
95+
if (topApyFarm[0]) {
96+
goFarmDetail(topApyFarm[2]);
97+
}
98+
}}
99+
>
85100
{topApyFarm[0] ? (
86101
<div className="flex items-center gap-2">
87102
<div className="flex items-center">
@@ -130,7 +145,15 @@ const Overview = () => {
130145
<span className="text-3xl gotham_bold text-white">-</span>
131146
)}
132147
</Template>
133-
<Template title="Top Farm APY">
148+
<Template
149+
title="Top Farm APY"
150+
className="cursor-pointer"
151+
onClick={() => {
152+
if (topApyFarm[0]) {
153+
goFarmDetail(topApyFarm[2]);
154+
}
155+
}}
156+
>
134157
{topApyFarm[0] ? (
135158
<div className="flex items-center gap-2">
136159
<div className="flex items-center">
@@ -166,20 +189,24 @@ const Overview = () => {
166189
);
167190
};
168191

169-
function Template({ title, children }: any) {
192+
function Template({ title, children, className, ...props }: any) {
170193
return (
171194
<div
172-
className="flex flex-grow flex-col items-center justify-center border border-memeBorderColor bg-swapCardGradient rounded-2xl"
195+
{...props}
196+
className={`flex flex-grow flex-col items-center justify-center border border-memeBorderColor bg-swapCardGradient rounded-2xl ${
197+
className ? className : ''
198+
}`}
173199
style={{ height: '110px' }}
174200
>
175201
<span className="text-base text-white">{title}</span>
176202
{children}
177203
</div>
178204
);
179205
}
180-
function TemplateMobile({ title, children }: any) {
206+
function TemplateMobile({ title, children, ...props }: any) {
181207
return (
182208
<div
209+
{...props}
183210
className="flex flex-grow flex-col justify-center w-full gap-1.5"
184211
style={{ height: '80px' }}
185212
>

src/components/meme/SeedsBox.tsx

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -237,45 +237,25 @@ const SeedsBox = () => {
237237
<span className="text-xl gotham_bold text-white">
238238
{seed.token_meta_data.symbol}
239239
</span>
240-
{/* {hasLpSeed ? (
241-
<div
242-
onClick={() => {
243-
goFarmDetail(seed_id);
244-
}}
245-
className="flex items-center border border-memePoolBoxBorderColor gap-2 rounded-lg h-8 px-2 cursor-pointer"
246-
>
247-
<span className="text-xs text-white">
248-
{seed.token_meta_data.symbol}/NEAR
249-
</span>
250-
<ArrowRightIcon />
251-
</div>
252-
) : (
253-
<div
254-
data-class="reactTip"
255-
data-tooltip-id={`lp_farm_${seed_id}`}
256-
data-place="top"
257-
data-tooltip-html={comeSoonTip()}
258-
>
259-
<div className="flex items-center border border-memePoolBoxBorderColor gap-2 rounded-lg h-8 px-2 opacity-30 cursor-not-allowed">
260-
<span className="text-xs text-white">
261-
{seed.token_meta_data.symbol}/NEAR
262-
</span>
263-
<ArrowRightIcon />
264-
</div>
265-
<CustomTooltip id={`lp_farm_${seed_id}`} />
266-
</div>
267-
)} */}
268240
<div
269241
data-class="reactTip"
270242
data-tooltip-id={`lp_farm_${seed_id}`}
271243
data-place="top"
272-
data-tooltip-html={getFarmAPYTip(seed_id)}
244+
data-tooltip-html={
245+
hasLpSeed ? getFarmAPYTip(seed_id) : comeSoonTip()
246+
}
273247
>
274248
<div
275249
onClick={() => {
276-
goFarmDetail(seed_id);
250+
if (hasLpSeed) {
251+
goFarmDetail(seed_id);
252+
}
277253
}}
278-
className="flex items-center border border-memePoolBoxBorderColor gap-2 rounded-lg h-8 px-2 cursor-pointer"
254+
className={`flex items-center border border-memePoolBoxBorderColor gap-2 rounded-lg h-8 px-2 ${
255+
hasLpSeed
256+
? 'cursor-pointer'
257+
: 'opacity-30 cursor-not-allowed'
258+
}`}
279259
>
280260
<span className="text-xs text-white">
281261
{seed.token_meta_data.symbol}/NEAR

src/pages/Orderly/components/AllOrders/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4389,6 +4389,7 @@ function HistoryOrders({
43894389
hasMore={hasMore}
43904390
dataLength={records}
43914391
loader={null}
4392+
style={{ overflow: 'static' }}
43924393
scrollableTarget={isMobile() ? null : 'all-orders-body-history'}
43934394
>
43944395
{data.slice(0, records)}

src/pages/Orderly/components/AssetModal/index.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { usePerpData } from '../UserBoardPerp/state';
5151
import { OrderAsset, useOrderAssets } from './state';
5252
const configV2 = getConfigV2();
5353
import CustomTooltip from 'src/components/customTooltip/customTooltip';
54+
import { index } from 'mathjs';
5455

5556
function getTipAsset() {
5657
const intl = useIntl();
@@ -756,9 +757,10 @@ export function AssetModal(props: Modal.Props & { curHoldingOut }) {
756757
maxHeight: '50vh',
757758
}}
758759
>
759-
{sortedBalances.map((b: OrderAsset) => {
760+
{sortedBalances.map((b: OrderAsset, index) => {
760761
return (
761762
<AssetLine
763+
key={index}
762764
tokenInfo={tokenInfo}
763765
{...b}
764766
freeCollateral={freeCollateral}
@@ -780,7 +782,13 @@ export function AssetModal(props: Modal.Props & { curHoldingOut }) {
780782
scrollableTarget="mobile-asset-body"
781783
>
782784
{records.map((r) => {
783-
return <RecordLine {...r} tokenInfo={tokenInfo} />;
785+
return (
786+
<RecordLine
787+
key={r.id + index}
788+
{...r}
789+
tokenInfo={tokenInfo}
790+
/>
791+
);
784792
})}
785793
</InfiniteScroll>
786794
</section>
@@ -794,7 +802,13 @@ export function AssetModal(props: Modal.Props & { curHoldingOut }) {
794802
curPage * DEFAULT_PAGE_SIZE
795803
)
796804
.map((r) => {
797-
return <RecordLine tokenInfo={tokenInfo} {...r} />;
805+
return (
806+
<RecordLine
807+
key={r.id + index + 1}
808+
tokenInfo={tokenInfo}
809+
{...r}
810+
/>
811+
);
798812
})
799813
))}
800814

src/pages/pools/DetailsPage.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ export function RecentTransactions({
14341434
}
14351435
}
14361436

1437-
const renderSwapTransactions = swapTransaction.map((tx) => {
1437+
const renderSwapTransactions = swapTransaction.map((tx, index) => {
14381438
const swapIn = tokens.find((t) => t.id === tx.token_in);
14391439

14401440
const swapOut = tokens.find((t) => t.id === tx.token_out);
@@ -1465,14 +1465,15 @@ export function RecentTransactions({
14651465
);
14661466
return (
14671467
<tr
1468+
key={tx.receipt_id + index}
14681469
className={`text-sm lg:grid lg:grid-cols-3 text-primaryText hover:text-white hover:bg-poolRecentHover`}
14691470
>
1470-
<td className="gap-1 p-4 lg:flex items-center">
1471-
<span className="col-span-1 text-white" title={swapInAmount}>
1471+
<td className="gap-1 p-4 lg:flex lg:flex-wrap items-center">
1472+
<span className="col-span-1 text-white mr-1" title={swapInAmount}>
14721473
{displayInAmount}
14731474
</span>
14741475

1475-
<span className="ml-1 text-primaryText">
1476+
<span className="text-primaryText">
14761477
{toRealSymbol(swapIn.symbol)}
14771478
</span>
14781479
</td>
@@ -1516,7 +1517,7 @@ export function RecentTransactions({
15161517
);
15171518
});
15181519

1519-
const renderLiquidityTransactions = liquidityTransactions.map((tx) => {
1520+
const renderLiquidityTransactions = liquidityTransactions.map((tx, index) => {
15201521
const { amounts } = tx;
15211522
const renderTokens: any[] = [];
15221523
const amountsObj: any[] = JSON.parse(amounts.replace(/\'/g, '"'));
@@ -1539,6 +1540,7 @@ export function RecentTransactions({
15391540

15401541
return (
15411542
<tr
1543+
key={tx.receipt_id + index}
15421544
className={`text-sm lg:grid overflow-hidden lg:grid-cols-${
15431545
tab == 'swap' ? 3 : 5
15441546
} text-primaryText hover:text-white hover:bg-poolRecentHover`}

src/state/swap.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ export const useSwap = ({
400400
}: SwapOptions) => {
401401
const [pool, setPool] = useState<Pool>();
402402
const [canSwap, setCanSwap] = useState<boolean>();
403-
403+
const [estimateInOut, setEstimateInOut] = useState<string[]>([]);
404404
const [tokenOutAmount, setTokenOutAmount] = useState<string>('');
405405
const [swapError, setSwapError] = useState<Error>();
406406
const [swapsToDo, setSwapsToDo] = useState<EstimateSwapView[]>();
@@ -504,7 +504,6 @@ export const useSwap = ({
504504
),
505505
new Big(0)
506506
);
507-
508507
const tokenPriceListForCal = !!tokenPriceList?.NEAR
509508
? tokenPriceList
510509
: (await getTokenPriceListFromCache()).reduce(
@@ -532,6 +531,7 @@ export const useSwap = ({
532531
scientificNotationToString(expectedOut.toString())
533532
);
534533
setSwapsToDo(estimates);
534+
setEstimateInOut([tokenInAmount, expectedOut.toString()]);
535535
setCanSwap(true);
536536
setQuoteDone(true);
537537
}
@@ -686,6 +686,7 @@ export const useSwap = ({
686686
priceImpactValue: scientificNotationToString(
687687
new Big(priceImpactValue).minus(new Big((avgFee || 0) / 100)).toString()
688688
),
689+
estimateInOut,
689690
};
690691
};
691692
export const useSwapV3 = ({
@@ -1499,7 +1500,7 @@ export const useRefSwap = ({
14991500
}: SwapOptions): ExchangeEstimate => {
15001501
const {
15011502
canSwap,
1502-
tokenOutAmount,
1503+
// tokenOutAmount,
15031504
minAmountOut,
15041505
swapError,
15051506
makeSwap: makeSwapV1,
@@ -1508,6 +1509,7 @@ export const useRefSwap = ({
15081509
quoteDone,
15091510
priceImpactValue,
15101511
tokenInAmount: tokenInAmountV1,
1512+
estimateInOut,
15111513
} = useSwap({
15121514
tokenIn,
15131515
tokenInAmount,
@@ -1523,6 +1525,7 @@ export const useRefSwap = ({
15231525
reEstimateTrigger,
15241526
supportLedger,
15251527
});
1528+
const [estimateInAmount, tokenOutAmount] = estimateInOut;
15261529

15271530
const {
15281531
makeSwap: makeSwapV2,
@@ -1548,8 +1551,10 @@ export const useRefSwap = ({
15481551
reEstimateTrigger,
15491552
});
15501553

1551-
const quoteDoneRef = quoteDoneV2 && quoteDone;
1552-
1554+
const quoteDoneRef =
1555+
quoteDoneV2 &&
1556+
quoteDone &&
1557+
Big(estimateInAmount || 0).eq(tokenInAmount || 0);
15531558
if (!quoteDoneRef)
15541559
return {
15551560
quoteDone: false,
@@ -1560,7 +1565,6 @@ export const useRefSwap = ({
15601565
market: 'ref',
15611566
tokenOutAmount: '0',
15621567
};
1563-
15641568
const bestSwap =
15651569
new Big(tokenOutAmountV2 || '0').gte(tokenOutAmount || '0') &&
15661570
canSwapV2 &&

0 commit comments

Comments
 (0)