import { ObservableChainQuery , ObservableChainQueryMap , } from "../../chain-query" ; import { ProposalVoter , ProposalVoterStargate } from "./types" ; import { KVStore } from "@keplr-wallet/common" ; import { ChainGetter } from "../../../common" ; export class ObservableQueryProposalVoteInner extends ObservableChainQuery < ProposalVoter | ProposalVoterStargate > { protected proposalId : string ; protected bech32Address : string ; constructor ( kvStore , chainId , chainGetter , proposalsId , bech32Address ) { super ( kvStore , chainId , chainGetter , `/gov/proposals/${ proposalsId }/votes/${ bech32Address }` ) ; this . proposalId = proposalsId ; this . bech32Address = bech32Address ; } get vote ( ) : "Yes" | "Abstain" | "No" | "NoWithVeto" | "Unspecified" { if ( ! this . response ) { return "Unspecified" ; } if ( typeof this . response . data . result . option === "string" ) { return this . response . data . result . option ; } return ( ( ) => { switch ( this . response . data . result . option ) { case 1 : return "Yes" ; case 2 : return "Abstain" ; case 3 : return "No" ; case 4 : return "NoWithVeto" ; default : return "Unspecified" ; } } ) ( ) ; } protected canFetch ( ) { return this . bech32Address . length > 0 ; } } export class ObservableQueryProposalVote extends ObservableChainQueryMap < ProposalVoter | ProposalVoterStargate > { constructor ( protected readonly kvStore , protected readonly chainId , protected readonly chainGetter ) { super ( kvStore , chainId , chainGetter , ( param ) => { const { proposalId , voter } = JSON . parse ( param ) ; return new ObservableQueryProposalVoteInner ( this . kvStore , this . chainId , this . chainGetter , proposalId , voter ) ; } ) ; } getVote ( proposalId , voter ) { const param = JSON . stringify ( { proposalId , voter , } ) ; return this . get ( param ) as ObservableQueryProposalVoteInner ; } }