From 304bd033845593b639c48563b870b903f716551f Mon Sep 17 00:00:00 2001 From: "Alex M. - Clockwork" Date: Fri, 15 Mar 2024 14:27:11 +0200 Subject: [PATCH 1/4] feat: Add params query --- src/composables/queries.ts | 7 +++++++ src/composables/useChainData.ts | 7 ++++++- src/gql/gql.ts | 5 +++++ src/gql/graphql.ts | 6 ++++++ src/graphql/params.graphql | 7 +++++++ 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/graphql/params.graphql diff --git a/src/composables/queries.ts b/src/composables/queries.ts index 2f67bf1..7278dd0 100644 --- a/src/composables/queries.ts +++ b/src/composables/queries.ts @@ -2,6 +2,9 @@ import { BalanceDocument, BalanceQuery, BalanceQueryVariables, + ParamsDocument, + ParamsQuery, + ParamsQueryVariables, ProposalDocument, ProposalQuery, ProposalQueryVariables, @@ -36,6 +39,10 @@ export const useProposalsQuery = (options?: UseQueryOptions(ProposalsDocument, {}, options ?? {}); }; +export const useParamsQuery = (options?: UseQueryOptions) => { + return useQuery(ParamsDocument, {}, options ?? {}); +}; + export const useVoteHistoryQuery = ( variables: VoteHistoryQueryVariables, options?: UseQueryOptions, diff --git a/src/composables/useChainData.ts b/src/composables/useChainData.ts index 51eb317..c6cbe98 100644 --- a/src/composables/useChainData.ts +++ b/src/composables/useChainData.ts @@ -1,5 +1,6 @@ import { useBalanceQuery, + useParamsQuery, useProposalQuery, useProposalTalliesQuery, useProposalsQuery, @@ -19,6 +20,10 @@ export const useChainData = () => { const { result } = useProposalQuery({ id: proposal_id }, { pollInterval: 5000 }); return result; }; + const getParams = () => { + const { result } = useParamsQuery(); + return result; + }; const getVoteHistory = (address: string) => { const { result } = useVoteHistoryQuery({ address }); return result; @@ -27,5 +32,5 @@ export const useChainData = () => { const { result } = useProposalTalliesQuery({ id: proposal_id }, { pollInterval: 5000 }); return result; }; - return { getBalance, getProposals, getProposal, getVoteHistory, getProposalTallies }; + return { getBalance, getProposals, getProposal, getParams, getVoteHistory, getProposalTallies }; }; diff --git a/src/gql/gql.ts b/src/gql/gql.ts index 7f88f1d..12b57de 100644 --- a/src/gql/gql.ts +++ b/src/gql/gql.ts @@ -14,6 +14,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/ */ const documents = { "query Balance($address: String!) {\n action_account_balance(address: $address) {\n coins\n }\n}": types.BalanceDocument, + "query Params {\n gov_params {\n tally_params\n deposit_params\n voting_params\n }\n}": types.ParamsDocument, "query Proposal($id: Int!) {\n proposal(where: {id: {_eq: $id}}) {\n content\n deposit_end_time\n description\n proposal_route\n proposal_type\n proposal_votes {\n voter_address\n option\n }\n id\n proposer_address\n status\n submit_time\n title\n voting_end_time\n voting_start_time\n proposal_tally_results {\n yes\n no_with_veto\n no\n abstain\n }\n }\n}": types.ProposalDocument, "query ProposalTallies($id: Int!) {\n proposal_tally_result(where: {proposal_id: {_eq: $id}}) {\n height\n no\n no_with_veto\n abstain\n yes\n proposal_id\n }\n}": types.ProposalTalliesDocument, "query Proposals {\n deposit_proposals: proposal(\n where: {status: {_eq: \"PROPOSAL_STATUS_DEPOSIT_PERIOD\"}, proposal_deposits: {}}\n ) {\n content\n deposit_end_time\n description\n id\n proposal_type\n proposal_deposits {\n amount\n depositor_address\n }\n proposal_votes_aggregate(distinct_on: voter_address) {\n aggregate {\n count\n }\n }\n proposer_address\n status\n submit_time\n title\n voting_end_time\n voting_start_time\n }\n voting_proposals: proposal(\n where: {status: {_eq: \"PROPOSAL_STATUS_VOTING_PERIOD\"}}\n ) {\n content\n deposit_end_time\n description\n id\n proposal_type\n proposal_deposits {\n amount\n depositor_address\n }\n proposal_votes_aggregate(distinct_on: voter_address) {\n aggregate {\n count\n }\n }\n proposer_address\n status\n submit_time\n title\n voting_end_time\n voting_start_time\n }\n all_proposals: proposal {\n content\n deposit_end_time\n description\n id\n proposal_type\n proposal_deposits {\n amount\n depositor_address\n }\n proposal_votes_aggregate(distinct_on: voter_address) {\n aggregate {\n count\n }\n }\n proposer_address\n status\n submit_time\n title\n voting_end_time\n voting_start_time\n }\n}": types.ProposalsDocument, @@ -38,6 +39,10 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql(source: "query Balance($address: String!) {\n action_account_balance(address: $address) {\n coins\n }\n}"): (typeof documents)["query Balance($address: String!) {\n action_account_balance(address: $address) {\n coins\n }\n}"]; +/** + * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. + */ +export function graphql(source: "query Params {\n gov_params {\n tally_params\n deposit_params\n voting_params\n }\n}"): (typeof documents)["query Params {\n gov_params {\n tally_params\n deposit_params\n voting_params\n }\n}"]; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ diff --git a/src/gql/graphql.ts b/src/gql/graphql.ts index fcfaa68..05a2d57 100644 --- a/src/gql/graphql.ts +++ b/src/gql/graphql.ts @@ -8790,6 +8790,11 @@ export type BalanceQueryVariables = Exact<{ export type BalanceQuery = { __typename?: 'query_root', action_account_balance?: { __typename?: 'ActionBalance', coins?: Array | null } | null }; +export type ParamsQueryVariables = Exact<{ [key: string]: never; }>; + + +export type ParamsQuery = { __typename?: 'query_root', gov_params: Array<{ __typename?: 'gov_params', tally_params: any, deposit_params: any, voting_params: any }> }; + export type ProposalQueryVariables = Exact<{ id: Scalars['Int']['input']; }>; @@ -8818,6 +8823,7 @@ export type VoteHistoryQuery = { __typename?: 'query_root', proposal_vote: Array export const BalanceDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Balance"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"address"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"action_account_balance"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"address"},"value":{"kind":"Variable","name":{"kind":"Name","value":"address"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"coins"}}]}}]}}]} as unknown as DocumentNode; +export const ParamsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Params"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"gov_params"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"tally_params"}},{"kind":"Field","name":{"kind":"Name","value":"deposit_params"}},{"kind":"Field","name":{"kind":"Name","value":"voting_params"}}]}}]}}]} as unknown as DocumentNode; export const ProposalDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Proposal"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"proposal"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"id"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"_eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"content"}},{"kind":"Field","name":{"kind":"Name","value":"deposit_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_route"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_type"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_votes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"voter_address"}},{"kind":"Field","name":{"kind":"Name","value":"option"}}]}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"proposer_address"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"submit_time"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"voting_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"voting_start_time"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_tally_results"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"yes"}},{"kind":"Field","name":{"kind":"Name","value":"no_with_veto"}},{"kind":"Field","name":{"kind":"Name","value":"no"}},{"kind":"Field","name":{"kind":"Name","value":"abstain"}}]}}]}}]}}]} as unknown as DocumentNode; export const ProposalTalliesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"ProposalTallies"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"proposal_tally_result"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"proposal_id"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"_eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"height"}},{"kind":"Field","name":{"kind":"Name","value":"no"}},{"kind":"Field","name":{"kind":"Name","value":"no_with_veto"}},{"kind":"Field","name":{"kind":"Name","value":"abstain"}},{"kind":"Field","name":{"kind":"Name","value":"yes"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_id"}}]}}]}}]} as unknown as DocumentNode; export const ProposalsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Proposals"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"deposit_proposals"},"name":{"kind":"Name","value":"proposal"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"status"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"_eq"},"value":{"kind":"StringValue","value":"PROPOSAL_STATUS_DEPOSIT_PERIOD","block":false}}]}},{"kind":"ObjectField","name":{"kind":"Name","value":"proposal_deposits"},"value":{"kind":"ObjectValue","fields":[]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"content"}},{"kind":"Field","name":{"kind":"Name","value":"deposit_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_type"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_deposits"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"amount"}},{"kind":"Field","name":{"kind":"Name","value":"depositor_address"}}]}},{"kind":"Field","name":{"kind":"Name","value":"proposal_votes_aggregate"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"distinct_on"},"value":{"kind":"EnumValue","value":"voter_address"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"aggregate"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"count"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"proposer_address"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"submit_time"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"voting_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"voting_start_time"}}]}},{"kind":"Field","alias":{"kind":"Name","value":"voting_proposals"},"name":{"kind":"Name","value":"proposal"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"status"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"_eq"},"value":{"kind":"StringValue","value":"PROPOSAL_STATUS_VOTING_PERIOD","block":false}}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"content"}},{"kind":"Field","name":{"kind":"Name","value":"deposit_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_type"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_deposits"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"amount"}},{"kind":"Field","name":{"kind":"Name","value":"depositor_address"}}]}},{"kind":"Field","name":{"kind":"Name","value":"proposal_votes_aggregate"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"distinct_on"},"value":{"kind":"EnumValue","value":"voter_address"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"aggregate"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"count"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"proposer_address"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"submit_time"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"voting_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"voting_start_time"}}]}},{"kind":"Field","alias":{"kind":"Name","value":"all_proposals"},"name":{"kind":"Name","value":"proposal"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"content"}},{"kind":"Field","name":{"kind":"Name","value":"deposit_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_type"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_deposits"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"amount"}},{"kind":"Field","name":{"kind":"Name","value":"depositor_address"}}]}},{"kind":"Field","name":{"kind":"Name","value":"proposal_votes_aggregate"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"distinct_on"},"value":{"kind":"EnumValue","value":"voter_address"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"aggregate"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"count"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"proposer_address"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"submit_time"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"voting_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"voting_start_time"}}]}}]}}]} as unknown as DocumentNode; diff --git a/src/graphql/params.graphql b/src/graphql/params.graphql new file mode 100644 index 0000000..8f7efc3 --- /dev/null +++ b/src/graphql/params.graphql @@ -0,0 +1,7 @@ +query Params { + gov_params { + tally_params + deposit_params + voting_params + } +} From f9bfe9e7c798af3c99f0f4cabb6b85ccab0e882f Mon Sep 17 00:00:00 2001 From: "Alex M. - Clockwork" Date: Fri, 15 Mar 2024 18:07:47 +0200 Subject: [PATCH 2/4] wip: Wiring data to proposal page --- src/components/ui/SimpleBadge.vue | 2 +- src/composables/queries.ts | 7 +++ src/composables/useChainData.ts | 7 ++- src/gql/gql.ts | 5 ++ src/gql/graphql.ts | 6 +++ src/graphql/staking.graphql | 9 ++++ src/utility/text.ts | 3 ++ src/views/ProposalView.vue | 81 +++++++++++++++++++++++++++++-- tailwind.config.ts | 1 + 9 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 src/graphql/staking.graphql diff --git a/src/components/ui/SimpleBadge.vue b/src/components/ui/SimpleBadge.vue index 15942a9..9ccbf18 100644 --- a/src/components/ui/SimpleBadge.vue +++ b/src/components/ui/SimpleBadge.vue @@ -12,7 +12,7 @@ const colorClasses = computed(() => { case ContextTypes.SUCCESS: return ""; case ContextTypes.FAIL: - return ""; + return "bg-badge-fail text-neg-200"; case ContextTypes.PLAIN: default: return "bg-badge-plain text-light"; diff --git a/src/composables/queries.ts b/src/composables/queries.ts index 7278dd0..184c890 100644 --- a/src/composables/queries.ts +++ b/src/composables/queries.ts @@ -14,6 +14,9 @@ import { ProposalsDocument, ProposalsQuery, ProposalsQueryVariables, + StakingDocument, + StakingQuery, + StakingQueryVariables, VoteHistoryDocument, VoteHistoryQuery, VoteHistoryQueryVariables, @@ -43,6 +46,10 @@ export const useParamsQuery = (options?: UseQueryOptions(ParamsDocument, {}, options ?? {}); }; +export const useStakingQuery = (options?: UseQueryOptions) => { + return useQuery(StakingDocument, {}, options ?? {}); +}; + export const useVoteHistoryQuery = ( variables: VoteHistoryQueryVariables, options?: UseQueryOptions, diff --git a/src/composables/useChainData.ts b/src/composables/useChainData.ts index c6cbe98..81b2f92 100644 --- a/src/composables/useChainData.ts +++ b/src/composables/useChainData.ts @@ -4,6 +4,7 @@ import { useProposalQuery, useProposalTalliesQuery, useProposalsQuery, + useStakingQuery, useVoteHistoryQuery, } from "./queries"; @@ -24,6 +25,10 @@ export const useChainData = () => { const { result } = useParamsQuery(); return result; }; + const getStakingStatus = () => { + const { result } = useStakingQuery(); + return result; + }; const getVoteHistory = (address: string) => { const { result } = useVoteHistoryQuery({ address }); return result; @@ -32,5 +37,5 @@ export const useChainData = () => { const { result } = useProposalTalliesQuery({ id: proposal_id }, { pollInterval: 5000 }); return result; }; - return { getBalance, getProposals, getProposal, getParams, getVoteHistory, getProposalTallies }; + return { getBalance, getProposals, getProposal, getParams, getVoteHistory, getProposalTallies, getStakingStatus }; }; diff --git a/src/gql/gql.ts b/src/gql/gql.ts index 12b57de..05b4051 100644 --- a/src/gql/gql.ts +++ b/src/gql/gql.ts @@ -18,6 +18,7 @@ const documents = { "query Proposal($id: Int!) {\n proposal(where: {id: {_eq: $id}}) {\n content\n deposit_end_time\n description\n proposal_route\n proposal_type\n proposal_votes {\n voter_address\n option\n }\n id\n proposer_address\n status\n submit_time\n title\n voting_end_time\n voting_start_time\n proposal_tally_results {\n yes\n no_with_veto\n no\n abstain\n }\n }\n}": types.ProposalDocument, "query ProposalTallies($id: Int!) {\n proposal_tally_result(where: {proposal_id: {_eq: $id}}) {\n height\n no\n no_with_veto\n abstain\n yes\n proposal_id\n }\n}": types.ProposalTalliesDocument, "query Proposals {\n deposit_proposals: proposal(\n where: {status: {_eq: \"PROPOSAL_STATUS_DEPOSIT_PERIOD\"}, proposal_deposits: {}}\n ) {\n content\n deposit_end_time\n description\n id\n proposal_type\n proposal_deposits {\n amount\n depositor_address\n }\n proposal_votes_aggregate(distinct_on: voter_address) {\n aggregate {\n count\n }\n }\n proposer_address\n status\n submit_time\n title\n voting_end_time\n voting_start_time\n }\n voting_proposals: proposal(\n where: {status: {_eq: \"PROPOSAL_STATUS_VOTING_PERIOD\"}}\n ) {\n content\n deposit_end_time\n description\n id\n proposal_type\n proposal_deposits {\n amount\n depositor_address\n }\n proposal_votes_aggregate(distinct_on: voter_address) {\n aggregate {\n count\n }\n }\n proposer_address\n status\n submit_time\n title\n voting_end_time\n voting_start_time\n }\n all_proposals: proposal {\n content\n deposit_end_time\n description\n id\n proposal_type\n proposal_deposits {\n amount\n depositor_address\n }\n proposal_votes_aggregate(distinct_on: voter_address) {\n aggregate {\n count\n }\n }\n proposer_address\n status\n submit_time\n title\n voting_end_time\n voting_start_time\n }\n}": types.ProposalsDocument, + "query Staking {\n staking_pool {\n bonded_tokens\n height\n not_bonded_tokens\n staked_not_bonded_tokens\n unbonding_tokens\n }\n}": types.StakingDocument, "query VoteHistory($address: String!) {\n proposal_vote(where: {voter_address: {_eq: $address}}) {\n option\n voter_address\n proposal_id\n }\n}": types.VoteHistoryDocument, }; @@ -55,6 +56,10 @@ export function graphql(source: "query ProposalTallies($id: Int!) {\n proposal_ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql(source: "query Proposals {\n deposit_proposals: proposal(\n where: {status: {_eq: \"PROPOSAL_STATUS_DEPOSIT_PERIOD\"}, proposal_deposits: {}}\n ) {\n content\n deposit_end_time\n description\n id\n proposal_type\n proposal_deposits {\n amount\n depositor_address\n }\n proposal_votes_aggregate(distinct_on: voter_address) {\n aggregate {\n count\n }\n }\n proposer_address\n status\n submit_time\n title\n voting_end_time\n voting_start_time\n }\n voting_proposals: proposal(\n where: {status: {_eq: \"PROPOSAL_STATUS_VOTING_PERIOD\"}}\n ) {\n content\n deposit_end_time\n description\n id\n proposal_type\n proposal_deposits {\n amount\n depositor_address\n }\n proposal_votes_aggregate(distinct_on: voter_address) {\n aggregate {\n count\n }\n }\n proposer_address\n status\n submit_time\n title\n voting_end_time\n voting_start_time\n }\n all_proposals: proposal {\n content\n deposit_end_time\n description\n id\n proposal_type\n proposal_deposits {\n amount\n depositor_address\n }\n proposal_votes_aggregate(distinct_on: voter_address) {\n aggregate {\n count\n }\n }\n proposer_address\n status\n submit_time\n title\n voting_end_time\n voting_start_time\n }\n}"): (typeof documents)["query Proposals {\n deposit_proposals: proposal(\n where: {status: {_eq: \"PROPOSAL_STATUS_DEPOSIT_PERIOD\"}, proposal_deposits: {}}\n ) {\n content\n deposit_end_time\n description\n id\n proposal_type\n proposal_deposits {\n amount\n depositor_address\n }\n proposal_votes_aggregate(distinct_on: voter_address) {\n aggregate {\n count\n }\n }\n proposer_address\n status\n submit_time\n title\n voting_end_time\n voting_start_time\n }\n voting_proposals: proposal(\n where: {status: {_eq: \"PROPOSAL_STATUS_VOTING_PERIOD\"}}\n ) {\n content\n deposit_end_time\n description\n id\n proposal_type\n proposal_deposits {\n amount\n depositor_address\n }\n proposal_votes_aggregate(distinct_on: voter_address) {\n aggregate {\n count\n }\n }\n proposer_address\n status\n submit_time\n title\n voting_end_time\n voting_start_time\n }\n all_proposals: proposal {\n content\n deposit_end_time\n description\n id\n proposal_type\n proposal_deposits {\n amount\n depositor_address\n }\n proposal_votes_aggregate(distinct_on: voter_address) {\n aggregate {\n count\n }\n }\n proposer_address\n status\n submit_time\n title\n voting_end_time\n voting_start_time\n }\n}"]; +/** + * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. + */ +export function graphql(source: "query Staking {\n staking_pool {\n bonded_tokens\n height\n not_bonded_tokens\n staked_not_bonded_tokens\n unbonding_tokens\n }\n}"): (typeof documents)["query Staking {\n staking_pool {\n bonded_tokens\n height\n not_bonded_tokens\n staked_not_bonded_tokens\n unbonding_tokens\n }\n}"]; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ diff --git a/src/gql/graphql.ts b/src/gql/graphql.ts index 05a2d57..099afde 100644 --- a/src/gql/graphql.ts +++ b/src/gql/graphql.ts @@ -8814,6 +8814,11 @@ export type ProposalsQueryVariables = Exact<{ [key: string]: never; }>; export type ProposalsQuery = { __typename?: 'query_root', deposit_proposals: Array<{ __typename?: 'proposal', content: any, deposit_end_time?: any | null, description: string, id: number, proposal_type: string, proposer_address: string, status?: string | null, submit_time: any, title: string, voting_end_time?: any | null, voting_start_time?: any | null, proposal_deposits: Array<{ __typename?: 'proposal_deposit', amount?: Array | null, depositor_address?: string | null }>, proposal_votes_aggregate: { __typename?: 'proposal_vote_aggregate', aggregate?: { __typename?: 'proposal_vote_aggregate_fields', count: number } | null } }>, voting_proposals: Array<{ __typename?: 'proposal', content: any, deposit_end_time?: any | null, description: string, id: number, proposal_type: string, proposer_address: string, status?: string | null, submit_time: any, title: string, voting_end_time?: any | null, voting_start_time?: any | null, proposal_deposits: Array<{ __typename?: 'proposal_deposit', amount?: Array | null, depositor_address?: string | null }>, proposal_votes_aggregate: { __typename?: 'proposal_vote_aggregate', aggregate?: { __typename?: 'proposal_vote_aggregate_fields', count: number } | null } }>, all_proposals: Array<{ __typename?: 'proposal', content: any, deposit_end_time?: any | null, description: string, id: number, proposal_type: string, proposer_address: string, status?: string | null, submit_time: any, title: string, voting_end_time?: any | null, voting_start_time?: any | null, proposal_deposits: Array<{ __typename?: 'proposal_deposit', amount?: Array | null, depositor_address?: string | null }>, proposal_votes_aggregate: { __typename?: 'proposal_vote_aggregate', aggregate?: { __typename?: 'proposal_vote_aggregate_fields', count: number } | null } }> }; +export type StakingQueryVariables = Exact<{ [key: string]: never; }>; + + +export type StakingQuery = { __typename?: 'query_root', staking_pool: Array<{ __typename?: 'staking_pool', bonded_tokens: string, height: any, not_bonded_tokens: string, staked_not_bonded_tokens: string, unbonding_tokens: string }> }; + export type VoteHistoryQueryVariables = Exact<{ address: Scalars['String']['input']; }>; @@ -8827,4 +8832,5 @@ export const ParamsDocument = {"kind":"Document","definitions":[{"kind":"Operati export const ProposalDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Proposal"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"proposal"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"id"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"_eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"content"}},{"kind":"Field","name":{"kind":"Name","value":"deposit_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_route"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_type"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_votes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"voter_address"}},{"kind":"Field","name":{"kind":"Name","value":"option"}}]}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"proposer_address"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"submit_time"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"voting_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"voting_start_time"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_tally_results"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"yes"}},{"kind":"Field","name":{"kind":"Name","value":"no_with_veto"}},{"kind":"Field","name":{"kind":"Name","value":"no"}},{"kind":"Field","name":{"kind":"Name","value":"abstain"}}]}}]}}]}}]} as unknown as DocumentNode; export const ProposalTalliesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"ProposalTallies"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"proposal_tally_result"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"proposal_id"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"_eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"height"}},{"kind":"Field","name":{"kind":"Name","value":"no"}},{"kind":"Field","name":{"kind":"Name","value":"no_with_veto"}},{"kind":"Field","name":{"kind":"Name","value":"abstain"}},{"kind":"Field","name":{"kind":"Name","value":"yes"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_id"}}]}}]}}]} as unknown as DocumentNode; export const ProposalsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Proposals"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"deposit_proposals"},"name":{"kind":"Name","value":"proposal"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"status"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"_eq"},"value":{"kind":"StringValue","value":"PROPOSAL_STATUS_DEPOSIT_PERIOD","block":false}}]}},{"kind":"ObjectField","name":{"kind":"Name","value":"proposal_deposits"},"value":{"kind":"ObjectValue","fields":[]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"content"}},{"kind":"Field","name":{"kind":"Name","value":"deposit_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_type"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_deposits"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"amount"}},{"kind":"Field","name":{"kind":"Name","value":"depositor_address"}}]}},{"kind":"Field","name":{"kind":"Name","value":"proposal_votes_aggregate"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"distinct_on"},"value":{"kind":"EnumValue","value":"voter_address"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"aggregate"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"count"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"proposer_address"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"submit_time"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"voting_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"voting_start_time"}}]}},{"kind":"Field","alias":{"kind":"Name","value":"voting_proposals"},"name":{"kind":"Name","value":"proposal"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"status"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"_eq"},"value":{"kind":"StringValue","value":"PROPOSAL_STATUS_VOTING_PERIOD","block":false}}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"content"}},{"kind":"Field","name":{"kind":"Name","value":"deposit_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_type"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_deposits"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"amount"}},{"kind":"Field","name":{"kind":"Name","value":"depositor_address"}}]}},{"kind":"Field","name":{"kind":"Name","value":"proposal_votes_aggregate"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"distinct_on"},"value":{"kind":"EnumValue","value":"voter_address"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"aggregate"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"count"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"proposer_address"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"submit_time"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"voting_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"voting_start_time"}}]}},{"kind":"Field","alias":{"kind":"Name","value":"all_proposals"},"name":{"kind":"Name","value":"proposal"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"content"}},{"kind":"Field","name":{"kind":"Name","value":"deposit_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_type"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_deposits"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"amount"}},{"kind":"Field","name":{"kind":"Name","value":"depositor_address"}}]}},{"kind":"Field","name":{"kind":"Name","value":"proposal_votes_aggregate"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"distinct_on"},"value":{"kind":"EnumValue","value":"voter_address"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"aggregate"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"count"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"proposer_address"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"submit_time"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"voting_end_time"}},{"kind":"Field","name":{"kind":"Name","value":"voting_start_time"}}]}}]}}]} as unknown as DocumentNode; +export const StakingDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Staking"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"staking_pool"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"bonded_tokens"}},{"kind":"Field","name":{"kind":"Name","value":"height"}},{"kind":"Field","name":{"kind":"Name","value":"not_bonded_tokens"}},{"kind":"Field","name":{"kind":"Name","value":"staked_not_bonded_tokens"}},{"kind":"Field","name":{"kind":"Name","value":"unbonding_tokens"}}]}}]}}]} as unknown as DocumentNode; export const VoteHistoryDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"VoteHistory"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"address"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"proposal_vote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"voter_address"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"_eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"address"}}}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"option"}},{"kind":"Field","name":{"kind":"Name","value":"voter_address"}},{"kind":"Field","name":{"kind":"Name","value":"proposal_id"}}]}}]}}]} as unknown as DocumentNode; \ No newline at end of file diff --git a/src/graphql/staking.graphql b/src/graphql/staking.graphql new file mode 100644 index 0000000..974897a --- /dev/null +++ b/src/graphql/staking.graphql @@ -0,0 +1,9 @@ +query Staking { + staking_pool { + bonded_tokens + height + not_bonded_tokens + staked_not_bonded_tokens + unbonding_tokens + } +} \ No newline at end of file diff --git a/src/utility/text.ts b/src/utility/text.ts index 78232f0..5eb046c 100644 --- a/src/utility/text.ts +++ b/src/utility/text.ts @@ -15,6 +15,9 @@ export function formatAmount(amount: string, precision: number) { return n.toLocaleString(undefined, { maximumFractionDigits: 6 }); } +export function decToPerc(dec: string, prec: number) { + return (parseFloat(dec) * 100).toFixed(prec); +} /** * Verify input is a link * diff --git a/src/views/ProposalView.vue b/src/views/ProposalView.vue index b5bfd91..0139f2c 100644 --- a/src/views/ProposalView.vue +++ b/src/views/ProposalView.vue @@ -8,15 +8,58 @@ import SimpleCard from "@/components/ui/SimpleCard.vue"; import { ContextTypes } from "@/types/ui"; import * as dayjs from "dayjs"; import duration from "dayjs/plugin/duration"; +import { computed } from "vue"; +import { decToPerc } from "@/utility"; dayjs.extend(duration); -const { getProposal } = useChainData(); +const { getProposal, getParams, getProposalTallies, getStakingStatus } = useChainData(); const route = useRoute(); const proposalTerm = `Proposal #${route.params.id}`; const linksTerm = `Links #${route.params.id}`; const proposal = getProposal(parseInt(route.params.id as string)); +const proposalTallies = getProposalTallies(parseInt(route.params.id as string)); +const params = getParams(); +const voted = computed(() => { + return proposalTallies.value?.proposal_tally_result[0]. +}) +const tally_params = computed(() => { + try { + return params.value?.gov_params[0].tally_params; + } catch (e) { + return {}; + } +}); + +const quorum = computed(() => { + return decToPerc(tally_params.value?.quorum ?? "0", 1); +}); + +const threshold = computed(() => { + return decToPerc(tally_params.value?.threshold ?? "0", 1); +}); + +const veto_threshold = computed(() => { + return decToPerc(tally_params.value?.veto_threshold ?? "0", 1); +}); + +/* +const voting_params = computed(() => { + try { + return JSON.parse(params.value?.gov_params[0].voting_params); + } catch (e) { + return {}; + } +}); +const deposit_params = computed(() => { + try { + return JSON.parse(params.value?.gov_params[0].deposit_params); + } catch (e) { + return {}; + } +}); +*/ const timeTo = (dateString: string) => { const now = dayjs(); const to = dayjs(dateString); @@ -28,7 +71,39 @@ const timeTo = (dateString: string) => {