-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
38 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
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
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
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
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,32 +1,54 @@ | ||
import { Client } from 'viem'; | ||
|
||
import { appConfig } from '../../configs/appConfig'; | ||
import { cachingLayer } from './cachingLayer'; | ||
import { getPayloadsDataRPC } from './getPayloadsDataRPC'; | ||
|
||
export type GetPayloadsData = { | ||
chainId: number; | ||
payloadsIds: number[]; | ||
clients?: Record<number, Client>; | ||
}; | ||
|
||
export async function getPayloadsData({ | ||
chainId, | ||
payloadsIds, | ||
clients, | ||
}: GetPayloadsData) { | ||
const payloadsConfig = appConfig.payloadsControllerConfig[chainId]; | ||
return await Promise.all( | ||
payloadsIds.map(async (id) => { | ||
const data = await cachingLayer.getPayload({ | ||
chainId, | ||
payloadsController: payloadsConfig.contractAddresses[0], | ||
payloadId: id, | ||
}); | ||
return { | ||
id: BigInt(id), | ||
chain: BigInt(chainId), | ||
payloadsController: payloadsConfig.contractAddresses[0], | ||
data: { | ||
...data.payload, | ||
}, | ||
logs: data.logs, | ||
}; | ||
}), | ||
); | ||
// TODO: turn on for mainnets | ||
// try { | ||
// return await Promise.all( | ||
// payloadsIds.map(async (id) => { | ||
// const data = await cachingLayer.getPayload({ | ||
// chainId, | ||
// payloadsController: payloadsConfig.contractAddresses[0], | ||
// payloadId: id, | ||
// }); | ||
// return { | ||
// id: BigInt(id), | ||
// chain: BigInt(chainId), | ||
// payloadsController: payloadsConfig.contractAddresses[0], | ||
// data: { | ||
// ...data.payload, | ||
// }, | ||
// logs: data.logs, | ||
// }; | ||
// }), | ||
// ); | ||
// } catch (e) { | ||
// console.error( | ||
// 'Error getting payload data for list with cache, using RPC fallback', | ||
// e, | ||
// ); | ||
if (clients) { | ||
return await getPayloadsDataRPC({ | ||
chainId, | ||
payloadsIds, | ||
clients, | ||
}); | ||
} else { | ||
throw new Error('Clients not passed. Try to pass clients and try again'); | ||
} | ||
// } | ||
} |
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,32 +1,70 @@ | ||
import { Client } from 'viem'; | ||
|
||
import { appConfig } from '../../configs/appConfig'; | ||
import { cachingLayer } from './cachingLayer'; | ||
import { getProposalMetadata } from './getProposalMetadata'; | ||
import { getProposalsDataRPC } from './getProposalsDataRPC'; | ||
|
||
export type GetProposalsData = { | ||
proposalsCount?: number; | ||
proposalsIds?: number[]; | ||
clients?: Record<number, Client>; | ||
}; | ||
|
||
export async function getProposalsData({ | ||
proposalsCount, | ||
proposalsIds, | ||
clients, | ||
}: GetProposalsData) { | ||
const ids = proposalsCount | ||
? [...Array(Number(proposalsCount)).keys()] | ||
: (proposalsIds ?? []); | ||
return await Promise.all( | ||
ids.map(async (id) => { | ||
const data = await cachingLayer.getProposal({ | ||
chainId: appConfig.govCoreChainId, | ||
governance: appConfig.govCoreConfig.contractAddress, | ||
proposalId: BigInt(id), | ||
}); | ||
return { | ||
...data, | ||
proposal: { | ||
...data.proposal, | ||
id, | ||
}, | ||
}; | ||
}), | ||
); | ||
// TODO: turn on for mainnets | ||
// try { | ||
// return await Promise.all( | ||
// ids.map(async (id) => { | ||
// const data = await cachingLayer.getProposal({ | ||
// chainId: appConfig.govCoreChainId, | ||
// governance: appConfig.govCoreConfig.contractAddress, | ||
// proposalId: BigInt(id), | ||
// }); | ||
// return { | ||
// ...data, | ||
// proposal: { | ||
// ...data.proposal, | ||
// id, | ||
// }, | ||
// }; | ||
// }), | ||
// ); | ||
// } catch (e) { | ||
// console.error( | ||
// 'Error getting proposal data for list with cache, using RPC fallback', | ||
// e, | ||
// ); | ||
if (clients) { | ||
const proposalsData = await getProposalsDataRPC({ | ||
proposalsCount, | ||
proposalsIds, | ||
clients, | ||
}); | ||
return await Promise.all( | ||
proposalsData.map(async (proposal) => { | ||
return { | ||
proposal, | ||
// TODO: turn on | ||
// ipfs: { | ||
// title: (await getProposalMetadata({ hash: proposal.ipfsHash })) | ||
// .title, | ||
// }, | ||
ipfs: { | ||
title: `Proposal ${proposal.id}`, | ||
}, | ||
}; | ||
}), | ||
); | ||
} else { | ||
throw new Error('Clients not passed. Try to pass clients and try again'); | ||
} | ||
// } | ||
} |
788bda9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit was deployed on ipfs