fix: Governance Voting onmounted no data
This commit is contained in:
parent
d50f8ded10
commit
df5e8afb14
@ -1,10 +1,11 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useGovStore } from '@/stores';
|
import { useGovStore } from '@/stores';
|
||||||
import ProposalListItem from '@/components/ProposalListItem.vue';
|
import ProposalListItem from '@/components/ProposalListItem.vue';
|
||||||
|
import { ref } from 'vue'
|
||||||
const tab = ref("")
|
const tab = ref("")
|
||||||
const store = useGovStore()
|
const store = useGovStore()
|
||||||
store.fetchProposals("2")
|
store.fetchProposals('2')
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
|
@ -127,7 +127,6 @@ export const useFormatter = defineStore('formatter', {
|
|||||||
calculatePercent(input?: string|number, total?: string|number ) {
|
calculatePercent(input?: string|number, total?: string|number ) {
|
||||||
if(!input || !total) return '0'
|
if(!input || !total) return '0'
|
||||||
const percent = Number(input)/Number(total)
|
const percent = Number(input)/Number(total)
|
||||||
console.log(input, total, percent);
|
|
||||||
return numeral(percent>0.0001?percent: 0).format("0.[00]%")
|
return numeral(percent>0.0001?percent: 0).format("0.[00]%")
|
||||||
},
|
},
|
||||||
formatDecimalToPercent(decimal: string) {
|
formatDecimalToPercent(decimal: string) {
|
||||||
|
@ -2,6 +2,7 @@ import { defineStore } from "pinia";
|
|||||||
import { useBlockchain } from "./useBlockchain";
|
import { useBlockchain } from "./useBlockchain";
|
||||||
import type { PageRequest, PaginatedProposals } from "@/types";
|
import type { PageRequest, PaginatedProposals } from "@/types";
|
||||||
import { LoadingStatus } from "./useDashboard";
|
import { LoadingStatus } from "./useDashboard";
|
||||||
|
import {reactive} from 'vue'
|
||||||
|
|
||||||
export const useGovStore = defineStore('govStore', {
|
export const useGovStore = defineStore('govStore', {
|
||||||
state: () => {
|
state: () => {
|
||||||
@ -27,18 +28,16 @@ export const useGovStore = defineStore('govStore', {
|
|||||||
async fetchProposals( status: string, pagination?: PageRequest ) {
|
async fetchProposals( status: string, pagination?: PageRequest ) {
|
||||||
if(!this.loading[status]) {
|
if(!this.loading[status]) {
|
||||||
this.loading[status] = LoadingStatus.Loading
|
this.loading[status] = LoadingStatus.Loading
|
||||||
const proposals = await this.blockchain.rpc.getGovProposals(status)
|
const proposals = reactive(await this.blockchain.rpc.getGovProposals(status))
|
||||||
|
if(status === '2') {
|
||||||
|
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.loading[status] = LoadingStatus.Loaded
|
||||||
this.proposals[status] = proposals
|
this.proposals[status] = proposals
|
||||||
|
|
||||||
if(status === '2') {
|
|
||||||
proposals.proposals.forEach(x1 => {
|
|
||||||
this.fetchTally(x1.proposal_id).then(t => {
|
|
||||||
x1.final_tally_result = t.tally
|
|
||||||
this.proposals[status] = proposals
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return this.proposals[status]
|
return this.proposals[status]
|
||||||
},
|
},
|
||||||
@ -48,7 +47,7 @@ export const useGovStore = defineStore('govStore', {
|
|||||||
// })
|
// })
|
||||||
},
|
},
|
||||||
async fetchTally(proposalId: string) {
|
async fetchTally(proposalId: string) {
|
||||||
return this.blockchain.rpc.getGovProposalTally(proposalId)
|
return await this.blockchain.rpc.getGovProposalTally(proposalId)
|
||||||
},
|
},
|
||||||
async fetchProposal(proposalId: string) {
|
async fetchProposal(proposalId: string) {
|
||||||
return this.blockchain.rpc.getGovProposal(proposalId)
|
return this.blockchain.rpc.getGovProposal(proposalId)
|
||||||
@ -59,5 +58,6 @@ export const useGovStore = defineStore('govStore', {
|
|||||||
async fetchProposalVotes(proposalId: string, next_key?: string) {
|
async fetchProposalVotes(proposalId: string, next_key?: string) {
|
||||||
return this.blockchain.rpc.getGovProposalVotes(proposalId, next_key)
|
return this.blockchain.rpc.getGovProposalVotes(proposalId, next_key)
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user