diff --git a/vue-app/src/api/tally.ts b/vue-app/src/api/tally.ts index 1280796d..fa1c3b15 100644 --- a/vue-app/src/api/tally.ts +++ b/vue-app/src/api/tally.ts @@ -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 { 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() + } } diff --git a/vue-app/src/utils/chains.ts b/vue-app/src/utils/chains.ts index acab4ecf..94e752f8 100644 --- a/vue-app/src/utils/chains.ts +++ b/vue-app/src/utils/chains.ts @@ -15,6 +15,7 @@ export enum ChainId { export type ChainInfo = { [chainId in ChainId]: { label: string + name: string currency: string logo: string isLayer2: boolean @@ -29,6 +30,7 @@ export type ChainInfo = { export const CHAIN_INFO: ChainInfo = { [ChainId.MAINNET]: { label: 'Mainnet', + name: 'mainnet', currency: 'ETH', logo: 'eth.svg', isLayer2: false, @@ -38,6 +40,7 @@ export const CHAIN_INFO: ChainInfo = { }, [ChainId.SEPOLIA]: { label: 'Sepolia', + name: 'sepolia', currency: 'ETH', logo: 'eth.svg', isLayer2: false, @@ -47,6 +50,7 @@ export const CHAIN_INFO: ChainInfo = { }, [ChainId.HARDHAT]: { label: 'Arbitrum Hardhat', + name: 'hardhat', currency: 'AETH', logo: 'arbitrum.svg', isLayer2: true, @@ -58,6 +62,7 @@ export const CHAIN_INFO: ChainInfo = { }, [ChainId.ARBITRUM_ONE]: { label: 'Arbitrum', + name: 'arbitrum', currency: 'AETH', logo: 'arbitrum.svg', isLayer2: true, @@ -69,6 +74,7 @@ export const CHAIN_INFO: ChainInfo = { }, [ChainId.ARBITRUM_RINKEBY]: { label: 'Arbitrum Rinkeby', + name: 'arbitrum-rinkeby', currency: 'AETH', logo: 'arbitrum.svg', isLayer2: true, @@ -80,6 +86,7 @@ export const CHAIN_INFO: ChainInfo = { }, [ChainId.ARBITRUM_GOERLI]: { label: 'Arbitrum Goerli', + name: 'arbitrum-goerli', currency: 'AETH', logo: 'arbitrum.svg', isLayer2: true, @@ -91,6 +98,7 @@ export const CHAIN_INFO: ChainInfo = { }, [ChainId.ARBITRUM_SEPOLIA]: { label: 'Arbitrum Sepolia', + name: 'arbitrum-sepolia', currency: 'AETH', logo: 'arbitrum.svg', isLayer2: true, @@ -102,6 +110,7 @@ export const CHAIN_INFO: ChainInfo = { }, [ChainId.OPTIMISM]: { label: 'Optimism', + name: 'optimism', currency: 'OETH', logo: 'optimism.svg', isLayer2: true, @@ -113,6 +122,7 @@ export const CHAIN_INFO: ChainInfo = { }, [ChainId.OPTIMISM_SEPOLIA]: { label: 'Optimism Sepolia', + name: 'optimism-sepolia', currency: 'OETH', logo: 'optimism.svg', isLayer2: true, @@ -124,6 +134,7 @@ export const CHAIN_INFO: ChainInfo = { }, [ChainId.XDAI]: { label: 'xDai', + name: 'xdai', currency: 'xDai', logo: 'xdai.svg', isLayer2: false, @@ -135,6 +146,7 @@ export const CHAIN_INFO: ChainInfo = { }, [ChainId.POLYGON]: { label: 'Polygon', + name: 'polygon', currency: 'MATIC', logo: 'polygon.svg', isLayer2: false,