Skip to content

Commit

Permalink
Add testing capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjurco committed Nov 27, 2024
1 parent 776a93b commit b580234
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 153 deletions.
41 changes: 39 additions & 2 deletions src/chain-data/context.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { createContext, useState, useMemo, useContext, ReactNode } from 'react';
import { initialSettableChainData, initialChainData, SettableChainData } from './state';
import { initialSettableChainData, initialChainData, SettableChainData, Proposal } from './state';
import { useAccount, useNetwork } from 'wagmi';
import { getDaoAddresses, updateNetworkName } from '../contracts';
import { useEthersProvider, useEthersSigner } from './adapters';
import { ethers } from 'ethers';
import { BigNumber, ethers } from 'ethers';
import testProposals from '../pages/proposals/test-proposals.json';

export const ChainDataContext = createContext(initialSettableChainData);

Expand Down Expand Up @@ -48,6 +49,41 @@ const ChainDataContextProvider = (props: { children: ReactNode }) => {

export default ChainDataContextProvider;

const convertBigNumbersAndDates = (obj: any): any => {
if (Array.isArray(obj)) {
return obj.map(convertBigNumbersAndDates);
} else if (obj && typeof obj === 'object') {
return Object.keys(obj).reduce((acc, key) => {
const value = obj[key];
if (value && value.type === 'BigNumber' && value.hex) {
acc[key] = BigNumber.from(value.hex);
} else if (key === 'deadline' || key === 'startDate') {
acc[key] = new Date(value);
} else {
acc[key] = convertBigNumbersAndDates(value);
}
return acc;
}, {} as any);
}
return obj;
};

const convertToProposals = (
data: any
): { primary: { [key: string]: Proposal }; secondary: { [key: string]: Proposal } } => {
const convertSection = (section: { [key: string]: any }) => {
return Object.keys(section).reduce((acc, key) => {
acc[key] = convertBigNumbersAndDates(section[key]);
return acc;
}, {} as { [key: string]: Proposal });
};

return {
primary: convertSection(data.primary),
secondary: convertSection(data.secondary),
};
};

export const useChainData = () => {
const data = useContext(ChainDataContext);
const { provider, signer } = useContext(ProviderSignerContext) || {};
Expand All @@ -59,6 +95,7 @@ export const useChainData = () => {
const networkName = updateNetworkName(chain?.network || '');
return {
...data,
// proposals: convertToProposals(testProposals),
isConnected: true,
provider,
signer,
Expand Down
306 changes: 155 additions & 151 deletions src/pages/proposals/test-proposals.json
Original file line number Diff line number Diff line change
@@ -1,164 +1,168 @@
[
{
"0": {
"type": "BigNumber",
"hex": "0x69"
},
"1": "0x1251c6528e8EE095Cdb7cb6284860F3290756cdE",
"2": "2\u001ftransfer(address,uint256)\u001fIndependent monitoring team #6 - Dec 1st, 2024 - Feb 28th, 2025\u001fThe team provides development of the Centurion ecosystem which monitors dAPIs on supported chains as well as technical support for the API3 documentation.\n\nhttps://magenta-written-lemming-206.mypinata.cloud/ipfs/Qmc4q7sYVExuLSLFQz9mHdpHegmibsN7giPRJXzA1CoZb5",
"type": "secondary",
"voteId": {
"type": "BigNumber",
"hex": "0x69"
},
"creator": "0x1251c6528e8EE095Cdb7cb6284860F3290756cdE",
"metadata": {
"version": "2",
"targetSignature": "transfer(address,uint256)",
"title": "Independent monitoring team #6 - Dec 1st, 2024 - Feb 28th, 2025",
"description": "The team provides development of the Centurion ecosystem which monitors dAPIs on supported chains as well as technical support for the API3 documentation.\n\nhttps://magenta-written-lemming-206.mypinata.cloud/ipfs/Qmc4q7sYVExuLSLFQz9mHdpHegmibsN7giPRJXzA1CoZb5"
},
"open": true,
"startDate": "2024-11-19T23:03:59.000Z",
"supportRequired": 50,
"minAcceptQuorum": 15,
"votingPower": {
"type": "BigNumber",
"hex": "0x1acb427cba1a0a34910e11"
},
"deadline": "2024-12-26T23:03:59.000Z",
"startDateRaw": {
"type": "BigNumber",
"hex": "0x673d195f"
},
"script": "0x00000001556ecbb0311d350491ba0ec7e019c354d7723ce0000000e4b61d27f6000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000bd94c3f81cc8d5a993908270103639c8a0e9f0aa000000000000000000000000000000000000000000000000000000052041800000000000000000000000000000000000000000000000000000000000",
"userVotingPowerAt": {
"type": "BigNumber",
"hex": "0x00"
},
"delegateAt": null,
"delegateState": 0,
"voterState": 0,
"executed": false,
"yea": {
"type": "BigNumber",
"hex": "0x06881c252ae98757f77052"
},
"nay": {
"type": "BigNumber",
"hex": "0x016ee5dfa160531f3957c7"
},
"decodedEvmScript": {
"targetAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"value": {
{
"secondary": {
"105": {
"0": {
"type": "BigNumber",
"hex": "0x69"
},
"1": "0x1251c6528e8EE095Cdb7cb6284860F3290756cdE",
"2": "2\u001ftransfer(address,uint256)\u001fIndependent monitoring team #6 - Dec 1st, 2024 - Feb 28th, 2025\u001fThe team provides development of the Centurion ecosystem which monitors dAPIs on supported chains as well as technical support for the API3 documentation.\n\nhttps://magenta-written-lemming-206.mypinata.cloud/ipfs/Qmc4q7sYVExuLSLFQz9mHdpHegmibsN7giPRJXzA1CoZb5",
"type": "secondary",
"voteId": {
"type": "BigNumber",
"hex": "0x69"
},
"creator": "0x1251c6528e8EE095Cdb7cb6284860F3290756cdE",
"metadata": {
"version": "2",
"targetSignature": "transfer(address,uint256)",
"title": "Independent monitoring team #6 - Dec 1st, 2024 - Feb 28th, 2025",
"description": "The team provides development of the Centurion ecosystem which monitors dAPIs on supported chains as well as technical support for the API3 documentation.\n\nhttps://magenta-written-lemming-206.mypinata.cloud/ipfs/Qmc4q7sYVExuLSLFQz9mHdpHegmibsN7giPRJXzA1CoZb5"
},
"open": true,
"startDate": "2024-11-19T23:03:59.000Z",
"supportRequired": 50,
"minAcceptQuorum": 15,
"votingPower": {
"type": "BigNumber",
"hex": "0x1acb427cba1a0a34910e11"
},
"deadline": "2024-12-26T23:03:59.000Z",
"startDateRaw": {
"type": "BigNumber",
"hex": "0x673d195f"
},
"script": "0x00000001556ecbb0311d350491ba0ec7e019c354d7723ce0000000e4b61d27f6000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000bd94c3f81cc8d5a993908270103639c8a0e9f0aa000000000000000000000000000000000000000000000000000000052041800000000000000000000000000000000000000000000000000000000000",
"userVotingPowerAt": {
"type": "BigNumber",
"hex": "0x00"
},
"parameters": ["0xBd94c3F81CC8d5a993908270103639C8a0E9F0aA", "22016000000"]
}
},
{
"type": "primary",
"voteId": {
"type": "BigNumber",
"hex": "0x0e"
},
"creator": "0x1cccb306a2BFADe9860A33689551B38cCC6eb66E",
"metadata": {
"version": "1",
"targetSignature": "transfer(address,uint256)",
"title": "DWF Labs Liquidity Enhancement Proposal",
"description": "https://gateway.pinata.cloud/ipfs/QmPEJ9GTp5xNSEn2kFsVMGFDD3wbhRZZnU22KUscEt32rx"
},
"open": true,
"startDate": "2024-11-11T15:39:35.000Z",
"supportRequired": 50,
"minAcceptQuorum": 50,
"votingPower": {
"type": "BigNumber",
"hex": "0x1be184a52dc19a43bbb18a"
},
"deadline": "2024-11-18T15:39:35.000Z",
"startDateRaw": {
"type": "BigNumber",
"hex": "0x66180437"
},
"script": "0x00000001d9f80bdb37e6bad114d747e60ce6d2aaf26704ae000000e4b61d27f60000000000000000000000000b38210ea11411557c13457d4da7dc6ea731b88a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000413f624710af8c637cd581311bd2b81cd7da5c3200000000000000000000000000000000000000000000d3c21bcecceda100000000000000000000000000000000000000000000000000000000000000",
"userVotingPowerAt": {
"type": "BigNumber",
"hex": "0x00"
},
"delegateAt": null,
"delegateState": 0,
"voterState": 1,
"executed": false,
"yea": {
"type": "BigNumber",
"hex": "0x0e2347359a77856c516a7c"
},
"nay": {
"type": "BigNumber",
"hex": "0x00"
},
"decodedEvmScript": {
"targetAddress": "0x0b38210ea11411557c13457D4dA7dC6ea731B88a",
"value": {
"delegateAt": null,
"delegateState": 0,
"voterState": 0,
"executed": false,
"yea": {
"type": "BigNumber",
"hex": "0x06881c252ae98757f77052"
},
"nay": {
"type": "BigNumber",
"hex": "0x016ee5dfa160531f3957c7"
},
"decodedEvmScript": {
"targetAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"value": {
"type": "BigNumber",
"hex": "0x00"
},
"parameters": ["0xBd94c3F81CC8d5a993908270103639C8a0E9F0aA", "22016000000"]
}
},
"16": {
"type": "secondary",
"voteId": {
"type": "BigNumber",
"hex": "0x10"
},
"creator": "0x01AD8A993cEa95C18447171a64D84d4eab275a98",
"metadata": {
"version": "1",
"targetSignature": "transfer(address,uint256)",
"title": "API3 API Integration Team Proposal",
"description": "Proposal Name x ipsum dolor sit amet. consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia. Link to discussion: http://link.here"
},
"open": true,
"startDate": "2021-11-26T14:37:37.000Z",
"supportRequired": 50,
"minAcceptQuorum": 15,
"votingPower": {
"type": "BigNumber",
"hex": "0x277ff928b8e6a7fe59d835"
},
"deadline": "2024-12-03T14:37:37.000Z",
"startDateRaw": {
"type": "BigNumber",
"hex": "0x61a0f131"
},
"script": "0x00000001556ecbb0311d350491ba0ec7e019c354d7723ce0000000e4b61d27f6000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000002be5bd7f529974e197cfe70f2361971f65c12042000000000000000000000000000000000000000000000000000000084129d94000000000000000000000000000000000000000000000000000000000",
"userVotingPowerAt": {
"type": "BigNumber",
"hex": "0x00"
},
"parameters": ["0x413f624710AF8C637Cd581311Bd2b81CD7da5C32", "1000000000000000000000000"]
"delegateAt": null,
"delegateState": 0,
"voterState": 0,
"executed": false,
"yea": {
"type": "BigNumber",
"hex": "0x016ee5dfa160531f3957c7"
},
"nay": {
"type": "BigNumber",
"hex": "0x046ee5dfa160531f3957c7"
},
"decodedEvmScript": {
"targetAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"value": {
"type": "BigNumber",
"hex": "0x00"
},
"parameters": ["0x2BE5bd7f529974E197cFe70f2361971f65c12042", "35453000000"]
}
}
},
{
"type": "secondary",
"voteId": {
"type": "BigNumber",
"hex": "0x10"
},
"creator": "0x01AD8A993cEa95C18447171a64D84d4eab275a98",
"metadata": {
"version": "1",
"targetSignature": "transfer(address,uint256)",
"title": "API3 API Integration Team Proposal",
"description": "https://ipfs.fleek.co/ipfs/bafybeicfx6fp6v75f3ukn5q64tm63eje22kw7xfhujsoqo2vr4plea3jpu\n\nhttps://forum.api3.org/t/secondary-proposal-12-api-integrations-team-november-2021-january-2022/780"
},
"open": true,
"startDate": "2021-11-26T14:37:37.000Z",
"supportRequired": 50,
"minAcceptQuorum": 15,
"votingPower": {
"type": "BigNumber",
"hex": "0x277ff928b8e6a7fe59d835"
},
"deadline": "2024-12-03T14:37:37.000Z",
"startDateRaw": {
"type": "BigNumber",
"hex": "0x61a0f131"
},
"script": "0x00000001556ecbb0311d350491ba0ec7e019c354d7723ce0000000e4b61d27f6000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000002be5bd7f529974e197cfe70f2361971f65c12042000000000000000000000000000000000000000000000000000000084129d94000000000000000000000000000000000000000000000000000000000",
"userVotingPowerAt": {
"type": "BigNumber",
"hex": "0x00"
},
"delegateAt": null,
"delegateState": 0,
"voterState": 2,
"executed": false,
"yea": {
"type": "BigNumber",
"hex": "0x016ee5dfa160531f3957c7"
},
"nay": {
"type": "BigNumber",
"hex": "0x046ee5dfa160531f3957c7"
},
"decodedEvmScript": {
"targetAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"value": {
"primary": {
"1": {
"type": "primary",
"voteId": {
"type": "BigNumber",
"hex": "0x01"
},
"creator": "0x1cccb306a2BFADe9860A33689551B38cCC6eb66E",
"metadata": {
"version": "1",
"targetSignature": "transfer(address,uint256)",
"title": "DWF Labs Liquidity Enhancement Proposal",
"description": "https://gateway.pinata.cloud/ipfs/QmPEJ9GTp5xNSEn2kFsVMGFDD3wbhRZZnU22KUscEt32rx"
},
"open": true,
"startDate": "2024-11-11T15:39:35.000Z",
"supportRequired": 50,
"minAcceptQuorum": 50,
"votingPower": {
"type": "BigNumber",
"hex": "0x1be184a52dc19a43bbb18a"
},
"deadline": "2024-11-18T15:39:35.000Z",
"startDateRaw": {
"type": "BigNumber",
"hex": "0x66180437"
},
"script": "0x00000001d9f80bdb37e6bad114d747e60ce6d2aaf26704ae000000e4b61d27f60000000000000000000000000b38210ea11411557c13457d4da7dc6ea731b88a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000413f624710af8c637cd581311bd2b81cd7da5c3200000000000000000000000000000000000000000000d3c21bcecceda100000000000000000000000000000000000000000000000000000000000000",
"userVotingPowerAt": {
"type": "BigNumber",
"hex": "0x00"
},
"delegateAt": "0x1cccb306a2BFADe9860A33689551B38cCC6eb66E",
"delegateState": 0,
"voterState": 1,
"executed": true,
"yea": {
"type": "BigNumber",
"hex": "0x0e2347359a77856c516a7c"
},
"nay": {
"type": "BigNumber",
"hex": "0x00"
},
"parameters": ["0x2BE5bd7f529974E197cFe70f2361971f65c12042", "35453000000"]
"decodedEvmScript": {
"targetAddress": "0x0b38210ea11411557c13457D4dA7dC6ea731B88a",
"value": {
"type": "BigNumber",
"hex": "0x00"
},
"parameters": ["0x413f624710AF8C637Cd581311Bd2b81CD7da5C32", "1000000000000000000000000"]
}
}
}
]
}

0 comments on commit b580234

Please sign in to comment.