Skip to content

Commit

Permalink
Update webapp crowdloan logic
Browse files Browse the repository at this point in the history
  • Loading branch information
saltict committed Oct 19, 2023
1 parent 50e940b commit 850de9b
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions packages/extension-base/src/koni/api/dotsama/crowdloan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ const STATUS_MAP: Record<_FundStatus, CrowdloanParaState> = {
[_FundStatus.WON]: CrowdloanParaState.COMPLETED
};

export type CrowdloanFundInfo = _CrowdloanFund & {
chain: string;
}

const getOnlineFundList = (async () => {
const request = await axios.get<_CrowdloanFund[]>('https://static-data.subwallet.app/crowdloan-funds/list.json');
const request = await axios.get<CrowdloanFundInfo[]>('https://static-data.subwallet.app/crowdloan-funds/list.json');

return request.data;
})();
Expand Down Expand Up @@ -73,14 +77,13 @@ export const subscribeAcalaContributeInterval = (polkadotAddresses: string[], fu
let contribute = new BN(0);

resList.forEach((res) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
contribute = contribute.add(new BN(res.data.data?.acala?.[0]?.totalDOTLocked || '0'));
});

const rs: CrowdloanItem = {
state: APIItemState.READY,
paraState,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
contribute: contribute.toString(),
fundId,
paraId,
Expand Down Expand Up @@ -130,7 +133,16 @@ export const subscribeAcalaContributeInterval = (polkadotAddresses: string[], fu
// Get All crowdloan
export async function subscribeCrowdloan (addresses: string[], substrateApiMap: Record<string, _SubstrateApi>, callback: (networkKey: string, rs: CrowdloanItem) => void, chainInfoMap: Record<string, _ChainInfo>) {
const unsubMap: Record<string, any> = {};
const fundList = await getOnlineFundList;
const latestMap: Record<string, CrowdloanFundInfo> = {};
const rawFundList = await getOnlineFundList;

rawFundList.forEach((fundInfo) => {
const chainSlug = fundInfo.chain;

if (!latestMap[chainSlug] || fundInfo.auctionIndex > latestMap[chainSlug].auctionIndex) {
latestMap[chainSlug] = fundInfo;
}
});

if (Object.keys(substrateApiMap).includes(COMMON_CHAIN_SLUGS.KUSAMA) && Object.keys(substrateApiMap).includes(COMMON_CHAIN_SLUGS.POLKADOT)) {
const now = Date.now();
Expand All @@ -145,10 +157,8 @@ export async function subscribeCrowdloan (addresses: string[], substrateApiMap:
return;
}

fundList.forEach((fundInfo) => {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const chainSlug = fundInfo.chain as string;
Object.values(latestMap).forEach((fundInfo) => {
const chainSlug = fundInfo.chain;
const endTime = new Date(fundInfo.endTime).getTime();
const parentChain = fundInfo.relayChain;

Expand Down

0 comments on commit 850de9b

Please sign in to comment.