feat: process item

This commit is contained in:
Alisa | Side.one 2023-05-28 02:38:29 +08:00
parent ee75361cef
commit 455be157d3
2 changed files with 25 additions and 22 deletions

View File

@ -9,7 +9,7 @@ import {
useTxDialog, useTxDialog,
} from '@/stores'; } from '@/stores';
import { import {
PageRequest, PageRequest,
type GovProposal, type GovProposal,
type GovVote, type GovVote,
type PaginatedProposalDeposit, type PaginatedProposalDeposit,
@ -17,7 +17,7 @@ PageRequest,
} from '@/types'; } from '@/types';
import { ref, reactive } from 'vue'; import { ref, reactive } from 'vue';
import Countdown from '@/components/Countdown.vue'; import Countdown from '@/components/Countdown.vue';
import PaginationBar from '@/components/PaginationBar.vue' import PaginationBar from '@/components/PaginationBar.vue';
import { fromBech32, toHex } from '@cosmjs/encoding'; import { fromBech32, toHex } from '@cosmjs/encoding';
const props = defineProps(['proposal_id', 'chain']); const props = defineProps(['proposal_id', 'chain']);
@ -57,8 +57,8 @@ const deposit = ref({} as PaginatedProposalDeposit);
store.fetchProposalDeposits(props.proposal_id).then((x) => (deposit.value = x)); store.fetchProposalDeposits(props.proposal_id).then((x) => (deposit.value = x));
const votes = ref({} as GovVote[]); const votes = ref({} as GovVote[]);
const pageRequest = ref(new PageRequest()) const pageRequest = ref(new PageRequest());
const pageResponse = ref({} as Pagination) const pageResponse = ref({} as Pagination);
store.fetchProposalVotes(props.proposal_id).then((x) => { store.fetchProposalVotes(props.proposal_id).then((x) => {
votes.value = x.votes; votes.value = x.votes;
@ -152,17 +152,17 @@ const processList = computed(() => {
}); });
function showValidatorName(voter: string) { function showValidatorName(voter: string) {
const {data} = fromBech32(voter) const { data } = fromBech32(voter);
const hex = toHex(data) const hex = toHex(data);
const v = stakingStore.validators.find( x => toHex(fromBech32(x.operator_address).data) === hex) const v = stakingStore.validators.find(
return v? v.description.moniker : voter (x) => toHex(fromBech32(x.operator_address).data) === hex
);
return v ? v.description.moniker : voter;
} }
function pageload(p: number) { function pageload(p: number) {
pageRequest.value.setPage(p) pageRequest.value.setPage(p);
store store.fetchProposalVotes(props.proposal_id, pageRequest.value).then((x) => {
.fetchProposalVotes(props.proposal_id, pageRequest.value)
.then((x) => {
votes.value = x.votes; votes.value = x.votes;
pageResponse.value = x.pagination; pageResponse.value = x.pagination;
}); });
@ -209,7 +209,9 @@ function pageload(p: number) {
<div <div
class="absolute inset-x-0 inset-y-0 rounded-sm" class="absolute inset-x-0 inset-y-0 rounded-sm"
:class="`${item.class}`" :class="`${item.class}`"
:style="`width: ${item.value}`" :style="`width: ${
item.value === '-' || item.value === 'NaN%' ? '0%' : item.value
}`"
></div> ></div>
<p <p
class="absolute inset-x-0 inset-y-0 text-center text-sm text-[#666] dark:text-[#eee] flex items-center justify-center" class="absolute inset-x-0 inset-y-0 text-center text-sm text-[#666] dark:text-[#eee] flex items-center justify-center"
@ -234,9 +236,7 @@ function pageload(p: number) {
</div> </div>
</div> </div>
<div <div class="bg-base-100 px-4 pt-3 pb-5 rounded shadow lg:!!col-span-2">
class="bg-base-100 px-4 pt-3 pb-5 rounded shadow lg:!!col-span-2"
>
<h2 class="card-title">Timeline</h2> <h2 class="card-title">Timeline</h2>
<div class="px-1"> <div class="px-1">
@ -341,12 +341,16 @@ function pageload(p: number) {
'text-gray-400': item.option === 'VOTE_OPTION_ABSTAIN', 'text-gray-400': item.option === 'VOTE_OPTION_ABSTAIN',
}" }"
> >
{{ String(item.option).replace("VOTE_OPTION_", "") }} {{ String(item.option).replace('VOTE_OPTION_', '') }}
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<PaginationBar :limit="pageRequest.limit" :total="pageResponse.total" :callback="pageload"/> <PaginationBar
:limit="pageRequest.limit"
:total="pageResponse.total"
:callback="pageload"
/>
</div> </div>
</div> </div>
</div> </div>

View File

@ -57,7 +57,6 @@ export const useStakingStore = defineStore('stakingStore', {
async fetchPool() { async fetchPool() {
const response = await this.blockchain.rpc?.getStakingPool(); const response = await this.blockchain.rpc?.getStakingPool();
if (response) { if (response) {
response.pool.bonded_tokens;
this.pool = response.pool; this.pool = response.pool;
} }
}, },