feat: gov vote

This commit is contained in:
Alisa | Side.one 2023-06-05 11:19:52 +08:00
parent 57657fe627
commit a4b2fd2e23
3 changed files with 311 additions and 328 deletions

View File

@ -31,7 +31,7 @@ const statusMap: Record<string, string> = {
PROPOSAL_STATUS_REJECTED: 'REJECTED', PROPOSAL_STATUS_REJECTED: 'REJECTED',
}; };
const voterStatusMap: Record<string, string> = { const voterStatusMap: Record<string, string> = {
No_With_Veto: '', VOTE_OPTION_NO_WITH_VETO: '',
VOTE_OPTION_YES: 'success', VOTE_OPTION_YES: 'success',
VOTE_OPTION_NO: 'error', VOTE_OPTION_NO: 'error',
VOTE_OPTION_ABSTAIN: 'warning', VOTE_OPTION_ABSTAIN: 'warning',
@ -81,8 +81,7 @@ const proposalInfo = ref();
:class=" :class="
statusMap?.[item?.status] === 'PASSED' statusMap?.[item?.status] === 'PASSED'
? 'text-yes' ? 'text-yes'
: statusMap?.[item?.status] === : statusMap?.[item?.status] === 'REJECTED'
'REJECTED'
? 'text-no' ? 'text-no'
: 'text-info' : 'text-info'
" "
@ -92,17 +91,13 @@ const proposalInfo = ref();
:class=" :class="
statusMap?.[item?.status] === 'PASSED' statusMap?.[item?.status] === 'PASSED'
? 'bg-yes' ? 'bg-yes'
: statusMap?.[item?.status] === : statusMap?.[item?.status] === 'REJECTED'
'REJECTED'
? 'bg-no' ? 'bg-no'
: 'bg-info' : 'bg-info'
" "
></div> ></div>
<div class="text-xs"> <div class="text-xs">
{{ {{ statusMap?.[item?.status] || item?.status }}
statusMap?.[item?.status] ||
item?.status
}}
</div> </div>
</div> </div>
<div <div
@ -113,10 +108,7 @@ const proposalInfo = ref();
</div> </div>
</td> </td>
<td <td v-if="statusMap?.[item?.status] === 'VOTING'" class="w-40">
v-if="statusMap?.[item?.status] === 'VOTING'"
class="w-40"
>
<div class=""> <div class="">
<label <label
for="vote" for="vote"
@ -127,12 +119,10 @@ const proposalInfo = ref();
}) })
" "
> >
<span v-if="item?.voterStatus">{{ <span v-if="item?.voterStatus !== 'VOTE_OPTION_NO_WITH_VETO'">{{
item?.voterStatus.replace( item?.voterStatus?.replace('VOTE_OPTION_', '')
'VOTE_OPTION_',
''
)
}}</span> }}</span>
<span v-else>Vote</span> <span v-else>Vote</span>
</label> </label>
</div> </div>
@ -211,7 +201,7 @@ const proposalInfo = ref();
</div> </div>
<div class="mt-4" v-if="statusMap?.[item?.status] === 'VOTING'"> <div class="mt-4" v-if="statusMap?.[item?.status] === 'VOTING'">
<div class="" v-show="item?.voterStatus === 'No With Veto'"> <div class="">
<label <label
for="vote" for="vote"
class="btn btn-xs btn-primary rounded-sm" class="btn btn-xs btn-primary rounded-sm"
@ -220,33 +210,19 @@ const proposalInfo = ref();
proposal_id: item?.proposal_id, proposal_id: item?.proposal_id,
}) })
" "
>Vote</label
> >
<div <span v-if="item?.voterStatus !== 'VOTE_OPTION_NO_WITH_VETO'">{{
class="text-xs truncate relative py-1 px-3 rounded-full w-fit" item?.voterStatus?.replace('VOTE_OPTION_', '')
:class="`text-${ }}</span>
voterStatusMap?.[item?.voterStatus]
}`" <span v-else>Vote</span></label
v-show="item?.voterStatus !== 'No With Veto'"
> >
<span
class="inset-x-0 inset-y-0 opacity-10 absolute"
:class="`bg-${
voterStatusMap?.[item?.voterStatus]
}`"
></span>
{{ item?.voterStatus }}
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<input <input type="checkbox" id="proposal-detail-modal" class="modal-toggle" />
type="checkbox"
id="proposal-detail-modal"
class="modal-toggle"
/>
<label for="proposal-detail-modal" class="modal"> <label for="proposal-detail-modal" class="modal">
<label class="modal-box w-11/12 max-w-5xl" for=""> <label class="modal-box w-11/12 max-w-5xl" for="">
<label <label
@ -258,12 +234,7 @@ const proposalInfo = ref();
<p class="py-4"> <p class="py-4">
<Component <Component
v-if="proposalInfo?.content?.description" v-if="proposalInfo?.content?.description"
:is=" :is="select(proposalInfo?.content?.description, 'horizontal')"
select(
proposalInfo?.content?.description,
'horizontal'
)
"
:value="proposalInfo?.content?.description" :value="proposalInfo?.content?.description"
> >
</Component> </Component>

View File

@ -2,7 +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 { useWalletStore } from './useWalletStore' import { useWalletStore } from './useWalletStore';
import { reactive } from 'vue'; import { reactive } from 'vue';
export const useGovStore = defineStore('govStore', { export const useGovStore = defineStore('govStore', {
@ -23,13 +23,13 @@ export const useGovStore = defineStore('govStore', {
}, },
walletstore() { walletstore() {
return useWalletStore(); return useWalletStore();
} },
}, },
actions: { actions: {
initial() { initial() {
this.$reset() this.$reset();
this.fetchParams(); this.fetchParams();
this.fetchProposals("2"); this.fetchProposals('2');
}, },
async fetchProposals(status: string, pagination?: PageRequest) { async fetchProposals(status: string, pagination?: PageRequest) {
//if (!this.loading[status]) { //if (!this.loading[status]) {
@ -44,14 +44,22 @@ export const useGovStore = defineStore('govStore', {
}); });
if (this.walletstore.currentAddress) { if (this.walletstore.currentAddress) {
try { try {
this.fetchProposalVotesVoter(item.proposal_id, this.walletstore.currentAddress).then((res) => { this.fetchProposalVotesVoter(
item.voterStatus = res?.vote?.option || 'No With Veto' item.proposal_id,
this.walletstore.currentAddress
)
.then((res) => {
item.voterStatus = res?.vote?.option || 'VOTE_OPTION_NO_WITH_VETO'
// 'No With Veto';
})
.catch((reject) => {
item.voterStatus = 'VOTE_OPTION_NO_WITH_VETO'
}); });
} catch (error) { } catch (error) {
item.voterStatus = 'No With Veto' item.voterStatus = 'VOTE_OPTION_NO_WITH_VETO'
} }
} else { } else {
item.voterStatus = 'No With Veto' item.voterStatus = 'VOTE_OPTION_NO_WITH_VETO'
} }
}); });
} }

View File

@ -1,79 +1,83 @@
import type { Coin, PaginatedResponse } from './common';
import type { Coin, PaginatedResponse } from "./common"
export interface GovParams { export interface GovParams {
"voting_params": { voting_params: {
"voting_period": string, voting_period: string;
"proposal_voting_periods": any[], proposal_voting_periods: any[];
"expedited_voting_period": string expedited_voting_period: string;
}, };
"deposit_params": { deposit_params: {
"min_deposit": Coin[], min_deposit: Coin[];
"max_deposit_period": string, max_deposit_period: string;
"min_expedited_deposit": Coin[], min_expedited_deposit: Coin[];
"min_initial_deposit_ratio": string min_initial_deposit_ratio: string;
}, };
"tally_params": { tally_params: {
"quorum": string, quorum: string;
"threshold": string, threshold: string;
"veto_threshold": string, veto_threshold: string;
"expedited_threshold": string expedited_threshold: string;
} };
} }
export interface GovProposal { export interface GovProposal {
"proposal_id": string, proposal_id: string;
"content": { content: {
"@type": string, '@type': string;
"title": string, title: string;
"description": string, description: string;
"plan"?: { plan?: {
'height'?: string | number, height?: string | number;
'time'?: string | number, time?: string | number;
} };
}, };
"status": string, status: string;
"final_tally_result": { final_tally_result: {
"yes": string, yes: string;
"abstain": string, abstain: string;
"no": string, no: string;
"no_with_veto": string, no_with_veto: string;
}, };
"submit_time": string, submit_time: string;
"deposit_end_time": string, deposit_end_time: string;
"total_deposit": Coin[], total_deposit: Coin[];
"voting_start_time": string, voting_start_time: string;
"voting_end_time": string, voting_end_time: string;
"is_expedited": boolean, is_expedited: boolean;
"voterStatus"?: string, voterStatus?: string
// VoteOption[];
} }
export interface VoteOption {
option: string;
weight: string;
}
export interface Tally { export interface Tally {
yes: string, yes: string;
abstain: string, abstain: string;
no: string, no: string;
no_with_veto: string no_with_veto: string;
} }
export interface GovVote { export interface GovVote {
proposal_id: string, proposal_id: string;
voter: string, voter: string;
option: string, option: string;
options: { "option": string, "weight": string }[] options: { option: string; weight: string }[];
} }
export interface PaginatedProposals extends PaginatedResponse { export interface PaginatedProposals extends PaginatedResponse {
proposals: GovProposal[] proposals: GovProposal[];
} }
export interface PaginatedProposalDeposit extends PaginatedResponse { export interface PaginatedProposalDeposit extends PaginatedResponse {
deposits: { deposits: {
amount: Coin[], amount: Coin[];
proposal_id: string, proposal_id: string;
depositor: string depositor: string;
} };
} }
export interface PaginatedProposalVotes extends PaginatedResponse { export interface PaginatedProposalVotes extends PaginatedResponse {
votes: GovVote[] votes: GovVote[];
} }