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: use fixed ratio #652

Merged
merged 1 commit into from
Feb 7, 2024
Merged
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
37 changes: 35 additions & 2 deletions src/pages/swapksqt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import { useSQToken } from '@containers';
import { useSortedIndexer } from '@hooks';
import { useDelegating } from '@hooks/useDelegating';
import { FormatCardLine, reduceTotal } from '@pages/account';
import { openNotification, Typography } from '@subql/components';
import { openNotification, Spinner, Typography } from '@subql/components';
import { WithdrawalStatus } from '@subql/network-query';
import {
formatEther,
mergeAsync,
renderAsync,
truncFormatEtherStr,
useAsyncMemo,
useGetRewardsQuery,
useGetWithdrawlsQuery,
} from '@subql/react-hooks';
Expand Down Expand Up @@ -97,6 +98,21 @@ const SwapKsqtInner: FC = () => {
}
};

const tradeRadio = useAsyncMemo(async () => {
const orderId = await contracts?.tokenExchange.nextOrderId();
const res = await contracts?.tokenExchange.orders(orderId?.sub(1).toNumber() || 0);

if (res) {
const [_, __, amountGive, amountGet] = res;

const ratio = BigNumber(amountGet.toString()).div(amountGive.toString());

return ratio.toFixed();
}

return 1;
}, []);

const disableSwap = useMemo(() => {
if (!balance.data) return true;
const zeroBalance = balance.data.toString() === '0';
Expand All @@ -113,6 +129,23 @@ const SwapKsqtInner: FC = () => {
}
}, [balance, totalLocked]);

if (isRPCError(tradeRadio.error) || isRPCError(balance.error)) {
return (
<div
style={{
width: '100%',
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
padding: 40,
}}
>
<RpcError></RpcError>
</div>
);
}

return (
<div className={styles.swapksqt}>
<Typography variant="h4">Swap</Typography>
Expand All @@ -122,7 +155,7 @@ const SwapKsqtInner: FC = () => {
variant="medium"
>
SubQuery mainnet has launched, you can now swap your kSQT for real SQT so you can continue on the SubQuery
Network. The swap is at a fixed rate of 1:1
Network. The swap is at a fixed rate of 1:{tradeRadio.loading ? <Spinner size={10}></Spinner> : tradeRadio.data}
</Typography>

<Typography variant="medium" type="secondary">
Expand Down
Loading