-
Notifications
You must be signed in to change notification settings - Fork 0
/
group-proposals.js
69 lines (60 loc) · 2.75 KB
/
group-proposals.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import {
AddressExplorerByChainID,
bitcoinChainID,
esploraAPIURL,
evmURL,
nodeURL,
groupAdminAddresses,
RPCByChainID,
externalChainIDs,
makeTableElement2, makeTableElement, renderHeader
} from './common.js';
import './web3.min.js';
import {convertbits, decode, encode} from "./bech32.js";
await renderHeader();
async function fetchProposalsByGroupAdminAddresses() {
const allProposals = [];
for (const [adminName, groupPolicyAddress] of Object.entries(groupAdminAddresses)) {
try {
const response = await fetch(`${nodeURL}/cosmos/group/v1/proposals_by_group_policy/${groupPolicyAddress}`);
const data = await response.json();
console.log(`Proposals for ${adminName}:`, data.proposals);
// Attach group name and address to each proposal
for (const proposal of data.proposals) {
proposal.groupName = adminName;
proposal.groupAddress = groupPolicyAddress;
// Fetch proposal details
const detailsResponse = await fetch(`${nodeURL}/cosmos/group/v1/proposal/${proposal.id}`);
const detailsData = await detailsResponse.json();
proposal.details = detailsData.proposal;
}
allProposals.push(...data.proposals);
} catch (error) {
console.error(`Error fetching proposals for ${adminName}:`, error);
}
}
displayProposals(allProposals);
}
function displayProposals(proposals) {
const proposalsList = document.getElementById('proposals-list');
if (proposals.length === 0) {
proposalsList.innerText = 'No open proposals found.';
return;
}
proposals.forEach(proposal => {
const proposalItem = document.createElement('div');
proposalItem.innerHTML = `
<strong>Group Name:</strong> ${proposal.groupName} <br />
<strong>Group Address:</strong> ${proposal.groupAddress} <br />
<strong>Proposal ID:</strong> ${proposal.id} <br />
<strong>Status:</strong> ${proposal.status} <br />
<strong>Title:</strong> ${proposal.details.title} <br />
<strong>Summary:</strong> ${proposal.details.summary} <br />
<strong>Final Tally Result:</strong> Yes: ${proposal.details.final_tally_result.yes_count}, No: ${proposal.details.final_tally_result.no_count}, Abstain: ${proposal.details.final_tally_result.abstain_count}, No with Veto: ${proposal.details.final_tally_result.no_with_veto_count} <br />
<strong>Messages:</strong> ${proposal.details.messages.map(msg => JSON.stringify(msg)).join(', ')}
<br /> <br />
`;
proposalsList.appendChild(proposalItem);
});
}
fetchProposalsByGroupAdminAddresses();