fix: Governance Voting onmounted no data

This commit is contained in:
alisa 2023-04-25 13:01:04 +08:00
parent d50f8ded10
commit df5e8afb14
3 changed files with 15 additions and 15 deletions

View File

@ -1,10 +1,11 @@
<script lang="ts" setup>
import { useGovStore } from '@/stores';
import ProposalListItem from '@/components/ProposalListItem.vue';
import { ref } from 'vue'
const tab = ref("")
const store = useGovStore()
store.fetchProposals("2")
store.fetchProposals('2')
</script>
<template>
<div>

View File

@ -127,7 +127,6 @@ export const useFormatter = defineStore('formatter', {
calculatePercent(input?: string|number, total?: string|number ) {
if(!input || !total) return '0'
const percent = Number(input)/Number(total)
console.log(input, total, percent);
return numeral(percent>0.0001?percent: 0).format("0.[00]%")
},
formatDecimalToPercent(decimal: string) {

View File

@ -2,6 +2,7 @@ import { defineStore } from "pinia";
import { useBlockchain } from "./useBlockchain";
import type { PageRequest, PaginatedProposals } from "@/types";
import { LoadingStatus } from "./useDashboard";
import {reactive} from 'vue'
export const useGovStore = defineStore('govStore', {
state: () => {
@ -27,18 +28,16 @@ export const useGovStore = defineStore('govStore', {
async fetchProposals( status: string, pagination?: PageRequest ) {
if(!this.loading[status]) {
this.loading[status] = LoadingStatus.Loading
const proposals = await this.blockchain.rpc.getGovProposals(status)
this.loading[status] = LoadingStatus.Loaded
this.proposals[status] = proposals
const proposals = reactive(await this.blockchain.rpc.getGovProposals(status))
if(status === '2') {
proposals.proposals.forEach(x1 => {
this.fetchTally(x1.proposal_id).then(t => {
x1.final_tally_result = t.tally
this.proposals[status] = proposals
proposals.proposals.forEach(async(x1) => {
await this.fetchTally(x1.proposal_id).then(res => {
x1.final_tally_result = res?.tally
})
})
}
this.loading[status] = LoadingStatus.Loaded
this.proposals[status] = proposals
}
return this.proposals[status]
},
@ -48,7 +47,7 @@ export const useGovStore = defineStore('govStore', {
// })
},
async fetchTally(proposalId: string) {
return this.blockchain.rpc.getGovProposalTally(proposalId)
return await this.blockchain.rpc.getGovProposalTally(proposalId)
},
async fetchProposal(proposalId: string) {
return this.blockchain.rpc.getGovProposal(proposalId)
@ -59,5 +58,6 @@ export const useGovStore = defineStore('govStore', {
async fetchProposalVotes(proposalId: string, next_key?: string) {
return this.blockchain.rpc.getGovProposalVotes(proposalId, next_key)
}
}
},
})