generated from proofoftom/buidler-waffle-typechain-quasar
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
try to get tally data statically from exported round data first, use …
…IPFS gateway if not available statically
- Loading branch information
Showing
2 changed files
with
28 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
import { Contract } from 'ethers' | ||
|
||
import { FundingRound } from './abi' | ||
import { provider, ipfsGatewayUrl } from './core' | ||
import { provider, chain } from './core' | ||
|
||
// https://github.com/webpack/webpack/issues/7378#issuecomment-683891615 | ||
import type { Tally } from '@clrfund/common' | ||
import { getIpfsUrl } from '@/utils/url' | ||
import { getLeaderboardRoundInfo } from './round' | ||
|
||
export { Tally } | ||
|
||
export async function getTally(fundingRoundAddress: string): Promise<Tally> { | ||
const fundingRound = new Contract(fundingRoundAddress, FundingRound, provider) | ||
const tallyHash = await fundingRound.tallyHash() | ||
const response = await fetch(`${ipfsGatewayUrl}/ipfs/${tallyHash}`) | ||
return await response.json() | ||
|
||
try { | ||
// try to get the tally file statically first, if not found, try the IPFS gateway | ||
const round = await getLeaderboardRoundInfo(fundingRoundAddress, chain.name) | ||
if (round?.tally) { | ||
return round.tally | ||
} else { | ||
throw new Error('No tally data, get from IPFS gateway') | ||
} | ||
} catch { | ||
const response = await fetch(getIpfsUrl(tallyHash) || '') | ||
return await response.json() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters