Skip to content

Commit

Permalink
fixing the math for isApproved proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
Viterbo committed Apr 4, 2024
1 parent 61c485c commit f88529d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
14 changes: 12 additions & 2 deletions src/config/ConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
}
29 changes: 19 additions & 10 deletions src/pages/ProposalItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export default defineComponent({
const multsigTransactionData = ref<Action[]>([]);
const requestedApprovalsRows = ref<RequestedApprovals[]>([]);
const activeProducers = ref<RequestedApprovals[]>([]);
const activeProducersApproved = ref<RequestedApprovals[]>([]);
const requestedApprovalsColumns = [
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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(
Expand Down

0 comments on commit f88529d

Please sign in to comment.