Skip to content

Commit

Permalink
Merge pull request #84 from subquery/feat/show-public-sale
Browse files Browse the repository at this point in the history
feat: show public sale result
  • Loading branch information
HuberTRoy authored Feb 5, 2024
2 parents ce63ece + 0cb76df commit b592413
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/components/Airdrop/Airdrop.module.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.container {
background: var(--dark-mode-card);
padding: 24px;
min-width: 661px;

}

.button {
Expand Down
44 changes: 37 additions & 7 deletions src/components/Airdrop/Airdrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { formatEther } from '@ethersproject/units';
import { openNotification, Spinner, Tag, Typography } from '@subql/components';
import { renderAsyncArray } from '@subql/react-hooks';
import { mergeAsync } from '@subql/react-hooks/dist/utils';
import { useMount } from 'ahooks';
import { useMount, useRequest } from 'ahooks';
import { Button, Table, TableProps } from 'antd';
import { BigNumber } from 'ethers';
import i18next from 'i18next';
Expand Down Expand Up @@ -164,6 +164,7 @@ export const Airdrop: FC = () => {
const [nftSerices, setNftSerices] = useState<NftIpfs>({});
const [redeemLoading, setRedeemLoading] = useState<boolean>(false);
const [redeemable, setRedeemable] = useState<boolean>(false);
const [currentUserPublicSaleResult, setCurrentUserPublicSaleResult] = useState<number>(0);

const accountUnclaimGifts = useQuery<IUnclaimedGifts>(
gql`
Expand Down Expand Up @@ -265,6 +266,20 @@ export const Airdrop: FC = () => {
}
);

const getPublicSaleResult = async () => {
if (!account) return;

try {
const res = await fetch(`https://sq-airdrop-backend.subquery.network/public-sale/token-claim/${account}`);

const text = await res.text();

setCurrentUserPublicSaleResult(+text);
} catch (e) {
// don't care about this
}
};

const getRedeemable = async () => {
try {
const fetchedRedeemable = await contracts?.sqtRedeem.redeemable();
Expand Down Expand Up @@ -430,6 +445,10 @@ export const Airdrop: FC = () => {
}
}, [redeemable]);

useEffect(() => {
getPublicSaleResult();
}, [account]);

useMount(() => {
getRedeemable();
});
Expand Down Expand Up @@ -461,11 +480,22 @@ export const Airdrop: FC = () => {
const [unClaimGifts, userNfts, redeemedNfts] = data;
const redeemNftsTokenIds = redeemedNfts?.userRedeemedNfts.nodes.map((i) => i.tokenId) || [];

const renderTable = sortGifts(
unClaimGifts || { userUnclaimedNfts: { nodes: [] } },
userNfts || { userNfts: { nodes: [], groupedAggregates: [] } },
redeemedNfts || { userRedeemedNfts: { nodes: [], groupedAggregates: [] } }
);
const renderTable = [
...sortGifts(
unClaimGifts || { userUnclaimedNfts: { nodes: [] } },
userNfts || { userNfts: { nodes: [], groupedAggregates: [] } },
redeemedNfts || { userRedeemedNfts: { nodes: [], groupedAggregates: [] } }
),
currentUserPublicSaleResult > 0
? {
id: <Typography>Public Sale Token Claim</Typography>,
sortedStatus: AirdropRoundStatus.LOCKED,
sortedNextMilestone: 'Unlock date: (Feb 22)',
amountString: `${currentUserPublicSaleResult} SQT`,
key: 'publicSale'
}
: null
].filter((i) => i);

const unlockSeriesIds = unClaimGifts?.userUnclaimedNfts.nodes.map((i) => i.seriesId) || [];
const canRedeemNfts = userNfts?.userNfts.nodes.filter((i) => !redeemNftsTokenIds.includes(i.id)) || [];
Expand All @@ -487,7 +517,7 @@ export const Airdrop: FC = () => {
<Table
className={styles.darkTable}
columns={getColumns(t)}
dataSource={[...renderTable]}
dataSource={renderTable}
pagination={{ hideOnSinglePage: true }}
rowKey="key"
/>
Expand Down

0 comments on commit b592413

Please sign in to comment.