From f88529ddd6db1076cbe709bb874e8256bbc42440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viterbo=20Rodr=C3=ADguez?= Date: Thu, 4 Apr 2024 18:39:04 -0300 Subject: [PATCH] fixing the math for isApproved proposal --- src/config/ConfigManager.ts | 14 ++++++++++++-- src/pages/ProposalItem.vue | 29 +++++++++++++++++++---------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/config/ConfigManager.ts b/src/config/ConfigManager.ts index 4bfb994a..1a0645bc 100644 --- a/src/config/ConfigManager.ts +++ b/src/config/ConfigManager.ts @@ -96,13 +96,23 @@ export default class ConfigManager { } private findChain(chainName: string) { - const fromMainnet = this.mainnets.find( + let fromMainnet = this.mainnets.find( c => c.getName() === chainName, ); if (fromMainnet) { return fromMainnet; + } else { + fromMainnet = this.testnets.find(c => c.getName() === chainName); } - return this.testnets.find(c => c.getName() === chainName); + if (fromMainnet) { + return fromMainnet; + } else { + if (typeof chainName === 'string') { + throw new Error(`Chain '${chainName}' not found`); + } else { + throw new Error('CHAIN_NAME env variable not found'); + } + } } } diff --git a/src/pages/ProposalItem.vue b/src/pages/ProposalItem.vue index 4f1b3257..52013c3d 100644 --- a/src/pages/ProposalItem.vue +++ b/src/pages/ProposalItem.vue @@ -40,6 +40,8 @@ export default defineComponent({ const multsigTransactionData = ref([]); const requestedApprovalsRows = ref([]); + const activeProducers = ref([]); + const activeProducersApproved = ref([]); const requestedApprovalsColumns = [ { @@ -99,15 +101,7 @@ export default defineComponent({ !isCanceled.value )); - const producersApprovalStatus = computed(() => { - const allProducers = requestedApprovalsRows.value.filter( - item => item.isBp, - ); - const producersHaveAlreadyApproved = allProducers.filter( - item => item.status, - ); - return `${producersHaveAlreadyApproved.length}/${allProducers.length}`; - }); + const producersApprovalStatus = computed(() => `${activeProducersApproved.value.length}/${activeProducers.value.length}`); function handleError(e: unknown, defaultMessage: string) { const error = JSON.parse(JSON.stringify(e)) as Error; @@ -282,7 +276,6 @@ export default defineComponent({ proposer.value = proposal.proposer; const totalRequestedApprovals = proposal.provided_approvals.length + proposal.requested_approvals.length; - isApproved.value = proposal.provided_approvals.length === totalRequestedApprovals; approvalStatus.value = `${proposal.provided_approvals.length}/${totalRequestedApprovals}`; isExecuted.value = proposal.executed; @@ -302,6 +295,22 @@ export default defineComponent({ requestedApprovalsRows.value = requestedApprovalsRowsValue; multsigTransactionData.value = multsigTransactionDataValue; + activeProducers.value = requestedApprovalsRows.value.filter( + item => item.isBp, + ); + activeProducersApproved.value = activeProducers.value.filter( + item => item.status, + ); + + if (activeProducers.value.length === 0) { + // No BPs are involved in the proposal, so we need to 100% of the requested approvals + isApproved.value = proposal.provided_approvals.length === totalRequestedApprovals; + } else { + // If BPs are involved, we need 2/3 (+1) of the BPs to approve the proposal + const approval = (activeProducers.value.length * 2 / 3) + 1; + isApproved.value = activeProducersApproved.value.length >= Math.floor(approval); + } + const transactions = await handleTransactionHistory(proposal.block_num); isCanceled.value = transactions.some(