From c6ec239b634bca5789e4ae7dc7c43b91b424b85a Mon Sep 17 00:00:00 2001 From: Magic Cat <37407870+MonikaCat@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:17:24 +0700 Subject: [PATCH] fix: token and params display [web-nym] (#1312) ## Description Closes: #XXXX --- ### Author Checklist _All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues._ I have... - [x] ran linting via `yarn lint` - [ ] wrote tests where necessary - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] targeted the correct branch - [x] provided a link to the relevant issue or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed - [x] added a changeset via [`yarn && yarn changeset`](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md) --- .changeset/empty-months-sniff.md | 6 + apps/web-nym/src/chain.json | 8 +- apps/web-nym/src/chainConfig/types.ts | 149 ++++++++ .../src/graphql/general/params.graphql | 6 +- .../graphql/general/proposal_details.graphql | 3 +- .../src/graphql/types/general_types.ts | 359 ++++++++++++++---- apps/web-nym/src/models/gov_params/index.ts | 65 ++++ .../home/components/data_blocks/hooks.ts | 107 ++++++ .../src/screens/home/components/hero/hooks.ts | 53 +++ apps/web-nym/src/screens/params/hooks.ts | 169 +++++++++ apps/web-nym/src/screens/params/index.tsx | 79 ++++ apps/web-nym/src/screens/params/types.ts | 53 +++ apps/web-nym/src/screens/params/utils.tsx | 179 +++++++++ .../src/screens/proposal_details/hooks.ts | 95 +++++ .../src/screens/proposal_details/types.ts | 24 ++ packages/ui/public/locales/en/web_nym.json | 5 + packages/ui/public/locales/it/web_nym.json | 5 + packages/ui/public/locales/pl/web_nym.json | 5 + packages/ui/public/locales/zhs/web_nym.json | 5 + packages/ui/public/locales/zht/web_nym.json | 5 + 20 files changed, 1305 insertions(+), 75 deletions(-) create mode 100644 .changeset/empty-months-sniff.md create mode 100644 apps/web-nym/src/chainConfig/types.ts create mode 100644 apps/web-nym/src/models/gov_params/index.ts create mode 100644 apps/web-nym/src/screens/home/components/data_blocks/hooks.ts create mode 100644 apps/web-nym/src/screens/home/components/hero/hooks.ts create mode 100644 apps/web-nym/src/screens/params/hooks.ts create mode 100644 apps/web-nym/src/screens/params/index.tsx create mode 100644 apps/web-nym/src/screens/params/types.ts create mode 100644 apps/web-nym/src/screens/params/utils.tsx create mode 100644 apps/web-nym/src/screens/proposal_details/hooks.ts create mode 100644 apps/web-nym/src/screens/proposal_details/types.ts create mode 100644 packages/ui/public/locales/en/web_nym.json create mode 100644 packages/ui/public/locales/it/web_nym.json create mode 100644 packages/ui/public/locales/pl/web_nym.json create mode 100644 packages/ui/public/locales/zhs/web_nym.json create mode 100644 packages/ui/public/locales/zht/web_nym.json diff --git a/.changeset/empty-months-sniff.md b/.changeset/empty-months-sniff.md new file mode 100644 index 0000000000..6a4a331c48 --- /dev/null +++ b/.changeset/empty-months-sniff.md @@ -0,0 +1,6 @@ +--- +'web-nym': patch +'ui': patch +--- + +fix: token and params display diff --git a/apps/web-nym/src/chain.json b/apps/web-nym/src/chain.json index 78dd598cfc..e321bafa7a 100644 --- a/apps/web-nym/src/chain.json +++ b/apps/web-nym/src/chain.json @@ -2,6 +2,7 @@ "chainName": "nym", "title": "NYM Block Explorer", "extra": { + "votingPowerExponent": 6, "profile": true, "graphqlWs": false }, @@ -205,7 +206,7 @@ } } }, - "keplr": "{\"chainId\":\"nyx\",\"chainName\":\"Nyx\",\"chainSymbolImageUrl\":\"https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/nyx/chain.png\",\"rpc\":\"https://rpc.nyx.nodes.guru\",\"rest\":\"https://api.nyx.nodes.guru/\",\"nodeProvider\":{\"name\":\"NodesGuru\",\"email\":\"andreym@nodes.guru\",\"website\":\"https://nodes.guru/\"},\"bip44\":{\"coinType\":118},\"bech32Config\":{\"bech32PrefixAccAddr\":\"n\",\"bech32PrefixAccPub\":\"npub\",\"bech32PrefixValAddr\":\"nvaloper\",\"bech32PrefixValPub\":\"nvaloperpub\",\"bech32PrefixConsAddr\":\"nvalcons\",\"bech32PrefixConsPub\":\"nvalconspub\"},\"stakeCurrency\":{\"coinDenom\":\"nyx\",\"coinMinimalDenom\":\"unyx\",\"coinDecimals\":6},\"currencies\":[{\"coinDenom\":\"NYM\",\"coinMinimalDenom\":\"unym\",\"coinDecimals\":6,\"coinGeckoId\":\"nym\"},{\"coinDenom\":\"NYX\",\"coinMinimalDenom\":\"unyx\",\"coinDecimals\":6,\"coinGeckoId\":\"nyx\"}],\"feeCurrencies\":[{\"coinDenom\":\"nym\",\"coinMinimalDenom\":\"unym\",\"coinDecimals\":6,\"coinGeckoId\":\"nym\"},{\"coinDenom\":\"nyx\",\"coinMinimalDenom\":\"unyx\",\"coinDecimals\":6,\"coinGeckoId\":\"nyx\"}],\"features\":[\"cosmwasm\"]}", + "keplr": "{\"chainId\":\"nyx\",\"chainName\":\"Nyx\",\"chainSymbolImageUrl\":\"https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/nyx/chain.png\",\"rpc\":\"https://rpc.nyx.nodes.guru\",\"rest\":\"https://api.nyx.nodes.guru/\",\"nodeProvider\":{\"name\":\"NodesGuru\",\"email\":\"andreym@nodes.guru\",\"website\":\"https://nodes.guru/\"},\"bip44\":{\"coinType\":118},\"bech32Config\":{\"bech32PrefixAccAddr\":\"n\",\"bech32PrefixAccPub\":\"npub\",\"bech32PrefixValAddr\":\"nvaloper\",\"bech32PrefixValPub\":\"nvaloperpub\",\"bech32PrefixConsAddr\":\"nvalcons\",\"bech32PrefixConsPub\":\"nvalconspub\"},\"stakeCurrency\":{\"coinDenom\":\"nyx\",\"coinMinimalDenom\":\"unyx\",\"coinDecimals\":6},\"currencies\":[{\"coinDenom\":\"NYX\",\"coinMinimalDenom\":\"unyx\",\"coinDecimals\":6,\"coinGeckoId\":\"nym\"},{\"coinDenom\":\"NYX\",\"coinMinimalDenom\":\"unyx\",\"coinDecimals\":6,\"coinGeckoId\":\"nyx\"}],\"feeCurrencies\":[{\"coinDenom\":\"nyx\",\"coinMinimalDenom\":\"unyx\",\"coinDecimals\":6,\"coinGeckoId\":\"nym\"},{\"coinDenom\":\"nyx\",\"coinMinimalDenom\":\"unyx\",\"coinDecimals\":6,\"coinGeckoId\":\"nyx\"}],\"features\":[\"cosmwasm\"]}", "chains": [ { "network": "nyx", @@ -221,8 +222,13 @@ }, "primaryTokenUnit": "unyx", "votingPowerTokenUnit": "unyx", + "priceTokenUnit": "unym", "tokenUnits": { "unyx": { + "display": "nyx", + "exponent": 6 + }, + "unym": { "display": "nym", "exponent": 6 } diff --git a/apps/web-nym/src/chainConfig/types.ts b/apps/web-nym/src/chainConfig/types.ts new file mode 100644 index 0000000000..1aa953fcaa --- /dev/null +++ b/apps/web-nym/src/chainConfig/types.ts @@ -0,0 +1,149 @@ +export interface ChainSettings { + network: string; + chainType: string; + genesis: { + time: string; + height: number; + }; + prefix: { + consensus: string; + validator: string; + account: string; + }; + primaryTokenUnit: string; + priceTokenUnit: string; + votingPowerTokenUnit: string; + tokenUnits: { + [token: string]: { + display: string; + exponent: number; + }; + }; + endpoints: { + graphql?: string; + graphqlWebsocket?: string; + publicRpcWebsocket?: string; + }; + marketing: { + matomoURL?: string; + matomoSiteID?: string; + }; +} + +export interface PaletteSettings { + primary: { + main?: string; + contractText?: string; + }; + background: { + default?: string; + paper?: string; + }; + divider?: string; + text: { + primary?: string; + secondary?: string; + }; + custom: { + general: { + background?: string; + surfaceOne?: string; + surfaceTwo?: string; + surfaceThree?: string; + icon?: string; + }; + fonts: { + fontOne?: string; + fontTwo?: string; + fontThree?: string; + fontFour?: string; + fontFive?: string; + highlight?: string; + }; + primaryData: { + one?: string; + two?: string; + three?: string; + four?: string; + }; + results: { + pass?: string; + fail?: string; + }; + tokenomics: { + one?: string; + two?: string; + three?: string; + }; + conditions: { + zero?: string; + one?: string; + two?: string; + three?: string; + }; + charts: { + zero?: string; + one?: string; + two?: string; + three?: string; + four?: string; + five?: string; + }; + tags: { + zero?: string; + one?: string; + two?: string; + three?: string; + four?: string; + five?: string; + six?: string; + seven?: string; + eight?: string; + nine?: string; + ten?: string; + eleven?: string; + twelve?: string; + thirteen?: string; + fourteen?: string; + fifteen?: string; + sixteen?: string; + seventeen?: string; + eighteen?: string; + nineteen?: string; + twenty?: string; + }; + wallet: { + background?: string; + backgroundTwo?: string; + surfaceOne: string; + surfaceTwo: string; + surfaceThree: string; + surfaceFour: string; + surfaceFive: string; + divider?: string; + textPrimary?: string; + textSecondary?: string; + active?: string; + inactive?: string; + }; + }; +} + +export interface ChainConfig extends ChainSettings { + chainName: string; + title: string; + extra: { + profile: boolean; + graphqlWs: boolean; + votingPowerExponent?: number; + }; + basePath: string; + previewImage?: string; + themes: { + default: string; + themeList: Array<'dark' | 'light' | 'deuteranopia' | 'tritanopia'>; + dark: PaletteSettings; + light: PaletteSettings; + }; + keplr: string | undefined; +} diff --git a/apps/web-nym/src/graphql/general/params.graphql b/apps/web-nym/src/graphql/general/params.graphql index b5415d40e3..6c98662632 100644 --- a/apps/web-nym/src/graphql/general/params.graphql +++ b/apps/web-nym/src/graphql/general/params.graphql @@ -11,9 +11,7 @@ query Params { distributionParams: distribution_params(limit: 1, order_by: {height: desc}) { params } - govParams: gov_params (limit: 1, order_by: {height: desc}) { - depositParams: deposit_params - tallyParams: tally_params - votingParams: voting_params + govParams: gov_params(limit: 1, order_by: {height: desc}) { + params } } diff --git a/apps/web-nym/src/graphql/general/proposal_details.graphql b/apps/web-nym/src/graphql/general/proposal_details.graphql index 82ddef911b..2f810101ee 100644 --- a/apps/web-nym/src/graphql/general/proposal_details.graphql +++ b/apps/web-nym/src/graphql/general/proposal_details.graphql @@ -7,7 +7,6 @@ query ProposalDetails($proposalId: Int) { content proposalId: id submitTime: submit_time - proposalType: proposal_type depositEndTime: deposit_end_time votingStartTime: voting_start_time votingEndTime: voting_end_time @@ -25,7 +24,7 @@ query ProposalDetailsTally($proposalId: Int) { bondedTokens: bonded_tokens } quorum: gov_params (limit: 1, order_by: {height: desc}) { - tallyParams: tally_params + tallyParams: params } } diff --git a/apps/web-nym/src/graphql/types/general_types.ts b/apps/web-nym/src/graphql/types/general_types.ts index 074e39f6ad..c98df8c3c9 100644 --- a/apps/web-nym/src/graphql/types/general_types.ts +++ b/apps/web-nym/src/graphql/types/general_types.ts @@ -185,6 +185,14 @@ export type Account = { __typename?: 'account'; address: Scalars['String']; /** An array relationship */ + feeGrantAllowancesByGranterAddress: Array; + /** An aggregate relationship */ + feeGrantAllowancesByGranterAddress_aggregate: Fee_Grant_Allowance_Aggregate; + /** An array relationship */ + fee_grant_allowances: Array; + /** An aggregate relationship */ + fee_grant_allowances_aggregate: Fee_Grant_Allowance_Aggregate; + /** An array relationship */ proposal_deposits: Array; /** An aggregate relationship */ proposal_deposits_aggregate: Proposal_Deposit_Aggregate; @@ -209,6 +217,46 @@ export type Account = { }; +/** columns and relationships of "account" */ +export type AccountFeeGrantAllowancesByGranterAddressArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + +/** columns and relationships of "account" */ +export type AccountFeeGrantAllowancesByGranterAddress_AggregateArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + +/** columns and relationships of "account" */ +export type AccountFee_Grant_AllowancesArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + +/** columns and relationships of "account" */ +export type AccountFee_Grant_Allowances_AggregateArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + /** columns and relationships of "account" */ export type AccountProposal_DepositsArgs = { distinct_on?: InputMaybe>; @@ -336,6 +384,8 @@ export type Account_Bool_Exp = { _not?: InputMaybe; _or?: InputMaybe>; address?: InputMaybe; + feeGrantAllowancesByGranterAddress?: InputMaybe; + fee_grant_allowances?: InputMaybe; proposal_deposits?: InputMaybe; proposal_votes?: InputMaybe; proposals?: InputMaybe; @@ -359,6 +409,8 @@ export type Account_Min_Fields = { /** Ordering options when selecting data from "account". */ export type Account_Order_By = { address?: InputMaybe; + feeGrantAllowancesByGranterAddress_aggregate?: InputMaybe; + fee_grant_allowances_aggregate?: InputMaybe; proposal_deposits_aggregate?: InputMaybe; proposal_votes_aggregate?: InputMaybe; proposals_aggregate?: InputMaybe; @@ -2199,6 +2251,21 @@ export type Fee_Grant_Allowance_Aggregate_FieldsCountArgs = { distinct?: InputMaybe; }; +/** order by aggregate values of table "fee_grant_allowance" */ +export type Fee_Grant_Allowance_Aggregate_Order_By = { + avg?: InputMaybe; + count?: InputMaybe; + max?: InputMaybe; + min?: InputMaybe; + stddev?: InputMaybe; + stddev_pop?: InputMaybe; + stddev_samp?: InputMaybe; + sum?: InputMaybe; + var_pop?: InputMaybe; + var_samp?: InputMaybe; + variance?: InputMaybe; +}; + /** aggregate avg on columns */ export type Fee_Grant_Allowance_Avg_Fields = { __typename?: 'fee_grant_allowance_avg_fields'; @@ -2206,6 +2273,12 @@ export type Fee_Grant_Allowance_Avg_Fields = { id?: Maybe; }; +/** order by avg() on columns of table "fee_grant_allowance" */ +export type Fee_Grant_Allowance_Avg_Order_By = { + height?: InputMaybe; + id?: InputMaybe; +}; + /** Boolean expression to filter rows from the table "fee_grant_allowance". All fields are combined with a logical 'AND'. */ export type Fee_Grant_Allowance_Bool_Exp = { _and?: InputMaybe>; @@ -2229,6 +2302,14 @@ export type Fee_Grant_Allowance_Max_Fields = { id?: Maybe; }; +/** order by max() on columns of table "fee_grant_allowance" */ +export type Fee_Grant_Allowance_Max_Order_By = { + grantee_address?: InputMaybe; + granter_address?: InputMaybe; + height?: InputMaybe; + id?: InputMaybe; +}; + /** aggregate min on columns */ export type Fee_Grant_Allowance_Min_Fields = { __typename?: 'fee_grant_allowance_min_fields'; @@ -2238,6 +2319,14 @@ export type Fee_Grant_Allowance_Min_Fields = { id?: Maybe; }; +/** order by min() on columns of table "fee_grant_allowance" */ +export type Fee_Grant_Allowance_Min_Order_By = { + grantee_address?: InputMaybe; + granter_address?: InputMaybe; + height?: InputMaybe; + id?: InputMaybe; +}; + /** Ordering options when selecting data from "fee_grant_allowance". */ export type Fee_Grant_Allowance_Order_By = { allowance?: InputMaybe; @@ -2270,6 +2359,12 @@ export type Fee_Grant_Allowance_Stddev_Fields = { id?: Maybe; }; +/** order by stddev() on columns of table "fee_grant_allowance" */ +export type Fee_Grant_Allowance_Stddev_Order_By = { + height?: InputMaybe; + id?: InputMaybe; +}; + /** aggregate stddev_pop on columns */ export type Fee_Grant_Allowance_Stddev_Pop_Fields = { __typename?: 'fee_grant_allowance_stddev_pop_fields'; @@ -2277,6 +2372,12 @@ export type Fee_Grant_Allowance_Stddev_Pop_Fields = { id?: Maybe; }; +/** order by stddev_pop() on columns of table "fee_grant_allowance" */ +export type Fee_Grant_Allowance_Stddev_Pop_Order_By = { + height?: InputMaybe; + id?: InputMaybe; +}; + /** aggregate stddev_samp on columns */ export type Fee_Grant_Allowance_Stddev_Samp_Fields = { __typename?: 'fee_grant_allowance_stddev_samp_fields'; @@ -2284,6 +2385,12 @@ export type Fee_Grant_Allowance_Stddev_Samp_Fields = { id?: Maybe; }; +/** order by stddev_samp() on columns of table "fee_grant_allowance" */ +export type Fee_Grant_Allowance_Stddev_Samp_Order_By = { + height?: InputMaybe; + id?: InputMaybe; +}; + /** aggregate sum on columns */ export type Fee_Grant_Allowance_Sum_Fields = { __typename?: 'fee_grant_allowance_sum_fields'; @@ -2291,6 +2398,12 @@ export type Fee_Grant_Allowance_Sum_Fields = { id?: Maybe; }; +/** order by sum() on columns of table "fee_grant_allowance" */ +export type Fee_Grant_Allowance_Sum_Order_By = { + height?: InputMaybe; + id?: InputMaybe; +}; + /** aggregate var_pop on columns */ export type Fee_Grant_Allowance_Var_Pop_Fields = { __typename?: 'fee_grant_allowance_var_pop_fields'; @@ -2298,6 +2411,12 @@ export type Fee_Grant_Allowance_Var_Pop_Fields = { id?: Maybe; }; +/** order by var_pop() on columns of table "fee_grant_allowance" */ +export type Fee_Grant_Allowance_Var_Pop_Order_By = { + height?: InputMaybe; + id?: InputMaybe; +}; + /** aggregate var_samp on columns */ export type Fee_Grant_Allowance_Var_Samp_Fields = { __typename?: 'fee_grant_allowance_var_samp_fields'; @@ -2305,6 +2424,12 @@ export type Fee_Grant_Allowance_Var_Samp_Fields = { id?: Maybe; }; +/** order by var_samp() on columns of table "fee_grant_allowance" */ +export type Fee_Grant_Allowance_Var_Samp_Order_By = { + height?: InputMaybe; + id?: InputMaybe; +}; + /** aggregate variance on columns */ export type Fee_Grant_Allowance_Variance_Fields = { __typename?: 'fee_grant_allowance_variance_fields'; @@ -2312,6 +2437,12 @@ export type Fee_Grant_Allowance_Variance_Fields = { id?: Maybe; }; +/** order by variance() on columns of table "fee_grant_allowance" */ +export type Fee_Grant_Allowance_Variance_Order_By = { + height?: InputMaybe; + id?: InputMaybe; +}; + /** columns and relationships of "genesis" */ export type Genesis = { __typename?: 'genesis'; @@ -2444,28 +2575,14 @@ export type Genesis_Variance_Fields = { /** columns and relationships of "gov_params" */ export type Gov_Params = { __typename?: 'gov_params'; - deposit_params: Scalars['jsonb']; height: Scalars['bigint']; one_row_id: Scalars['Boolean']; - tally_params: Scalars['jsonb']; - voting_params: Scalars['jsonb']; -}; - - -/** columns and relationships of "gov_params" */ -export type Gov_ParamsDeposit_ParamsArgs = { - path?: InputMaybe; -}; - - -/** columns and relationships of "gov_params" */ -export type Gov_ParamsTally_ParamsArgs = { - path?: InputMaybe; + params: Scalars['jsonb']; }; /** columns and relationships of "gov_params" */ -export type Gov_ParamsVoting_ParamsArgs = { +export type Gov_ParamsParamsArgs = { path?: InputMaybe; }; @@ -2510,11 +2627,9 @@ export type Gov_Params_Bool_Exp = { _and?: InputMaybe>; _not?: InputMaybe; _or?: InputMaybe>; - deposit_params?: InputMaybe; height?: InputMaybe; one_row_id?: InputMaybe; - tally_params?: InputMaybe; - voting_params?: InputMaybe; + params?: InputMaybe; }; /** aggregate max on columns */ @@ -2531,25 +2646,19 @@ export type Gov_Params_Min_Fields = { /** Ordering options when selecting data from "gov_params". */ export type Gov_Params_Order_By = { - deposit_params?: InputMaybe; height?: InputMaybe; one_row_id?: InputMaybe; - tally_params?: InputMaybe; - voting_params?: InputMaybe; + params?: InputMaybe; }; /** select columns of table "gov_params" */ export enum Gov_Params_Select_Column { - /** column name */ - DepositParams = 'deposit_params', /** column name */ Height = 'height', /** column name */ OneRowId = 'one_row_id', /** column name */ - TallyParams = 'tally_params', - /** column name */ - VotingParams = 'voting_params' + Params = 'params' } /** aggregate stddev on columns */ @@ -2756,6 +2865,8 @@ export type Message = { partition_id: Scalars['bigint']; /** An object relationship */ transaction?: Maybe; + /** An object relationship */ + transactionByPartitionIdTransactionHash?: Maybe; transaction_hash: Scalars['String']; type: Scalars['String']; value: Scalars['jsonb']; @@ -2797,6 +2908,21 @@ export type Message_Aggregate_FieldsCountArgs = { distinct?: InputMaybe; }; +/** order by aggregate values of table "message" */ +export type Message_Aggregate_Order_By = { + avg?: InputMaybe; + count?: InputMaybe; + max?: InputMaybe; + min?: InputMaybe; + stddev?: InputMaybe; + stddev_pop?: InputMaybe; + stddev_samp?: InputMaybe; + sum?: InputMaybe; + var_pop?: InputMaybe; + var_samp?: InputMaybe; + variance?: InputMaybe; +}; + /** aggregate avg on columns */ export type Message_Avg_Fields = { __typename?: 'message_avg_fields'; @@ -2805,6 +2931,13 @@ export type Message_Avg_Fields = { partition_id?: Maybe; }; +/** order by avg() on columns of table "message" */ +export type Message_Avg_Order_By = { + height?: InputMaybe; + index?: InputMaybe; + partition_id?: InputMaybe; +}; + /** Boolean expression to filter rows from the table "message". All fields are combined with a logical 'AND'. */ export type Message_Bool_Exp = { _and?: InputMaybe>; @@ -2815,6 +2948,7 @@ export type Message_Bool_Exp = { involved_accounts_addresses?: InputMaybe<_Text_Comparison_Exp>; partition_id?: InputMaybe; transaction?: InputMaybe; + transactionByPartitionIdTransactionHash?: InputMaybe; transaction_hash?: InputMaybe; type?: InputMaybe; value?: InputMaybe; @@ -2830,6 +2964,15 @@ export type Message_Max_Fields = { type?: Maybe; }; +/** order by max() on columns of table "message" */ +export type Message_Max_Order_By = { + height?: InputMaybe; + index?: InputMaybe; + partition_id?: InputMaybe; + transaction_hash?: InputMaybe; + type?: InputMaybe; +}; + /** aggregate min on columns */ export type Message_Min_Fields = { __typename?: 'message_min_fields'; @@ -2840,6 +2983,15 @@ export type Message_Min_Fields = { type?: Maybe; }; +/** order by min() on columns of table "message" */ +export type Message_Min_Order_By = { + height?: InputMaybe; + index?: InputMaybe; + partition_id?: InputMaybe; + transaction_hash?: InputMaybe; + type?: InputMaybe; +}; + /** Ordering options when selecting data from "message". */ export type Message_Order_By = { height?: InputMaybe; @@ -2847,6 +2999,7 @@ export type Message_Order_By = { involved_accounts_addresses?: InputMaybe; partition_id?: InputMaybe; transaction?: InputMaybe; + transactionByPartitionIdTransactionHash?: InputMaybe; transaction_hash?: InputMaybe; type?: InputMaybe; value?: InputMaybe; @@ -2878,6 +3031,13 @@ export type Message_Stddev_Fields = { partition_id?: Maybe; }; +/** order by stddev() on columns of table "message" */ +export type Message_Stddev_Order_By = { + height?: InputMaybe; + index?: InputMaybe; + partition_id?: InputMaybe; +}; + /** aggregate stddev_pop on columns */ export type Message_Stddev_Pop_Fields = { __typename?: 'message_stddev_pop_fields'; @@ -2886,6 +3046,13 @@ export type Message_Stddev_Pop_Fields = { partition_id?: Maybe; }; +/** order by stddev_pop() on columns of table "message" */ +export type Message_Stddev_Pop_Order_By = { + height?: InputMaybe; + index?: InputMaybe; + partition_id?: InputMaybe; +}; + /** aggregate stddev_samp on columns */ export type Message_Stddev_Samp_Fields = { __typename?: 'message_stddev_samp_fields'; @@ -2894,6 +3061,13 @@ export type Message_Stddev_Samp_Fields = { partition_id?: Maybe; }; +/** order by stddev_samp() on columns of table "message" */ +export type Message_Stddev_Samp_Order_By = { + height?: InputMaybe; + index?: InputMaybe; + partition_id?: InputMaybe; +}; + /** aggregate sum on columns */ export type Message_Sum_Fields = { __typename?: 'message_sum_fields'; @@ -2902,6 +3076,13 @@ export type Message_Sum_Fields = { partition_id?: Maybe; }; +/** order by sum() on columns of table "message" */ +export type Message_Sum_Order_By = { + height?: InputMaybe; + index?: InputMaybe; + partition_id?: InputMaybe; +}; + /** aggregate var_pop on columns */ export type Message_Var_Pop_Fields = { __typename?: 'message_var_pop_fields'; @@ -2910,6 +3091,13 @@ export type Message_Var_Pop_Fields = { partition_id?: Maybe; }; +/** order by var_pop() on columns of table "message" */ +export type Message_Var_Pop_Order_By = { + height?: InputMaybe; + index?: InputMaybe; + partition_id?: InputMaybe; +}; + /** aggregate var_samp on columns */ export type Message_Var_Samp_Fields = { __typename?: 'message_var_samp_fields'; @@ -2918,6 +3106,13 @@ export type Message_Var_Samp_Fields = { partition_id?: Maybe; }; +/** order by var_samp() on columns of table "message" */ +export type Message_Var_Samp_Order_By = { + height?: InputMaybe; + index?: InputMaybe; + partition_id?: InputMaybe; +}; + /** aggregate variance on columns */ export type Message_Variance_Fields = { __typename?: 'message_variance_fields'; @@ -2926,6 +3121,13 @@ export type Message_Variance_Fields = { partition_id?: Maybe; }; +/** order by variance() on columns of table "message" */ +export type Message_Variance_Order_By = { + height?: InputMaybe; + index?: InputMaybe; + partition_id?: InputMaybe; +}; + export type Messages_By_Address_Args = { addresses?: InputMaybe; limit?: InputMaybe; @@ -3411,18 +3613,17 @@ export type Proposal = { deposit_end_time?: Maybe; description: Scalars['String']; id: Scalars['Int']; + metadata: Scalars['String']; /** An array relationship */ proposal_deposits: Array; /** An aggregate relationship */ proposal_deposits_aggregate: Proposal_Deposit_Aggregate; - proposal_route: Scalars['String']; /** An object relationship */ proposal_tally_result?: Maybe; /** An array relationship */ proposal_tally_results: Array; /** An aggregate relationship */ proposal_tally_results_aggregate: Proposal_Tally_Result_Aggregate; - proposal_type: Scalars['String']; /** An array relationship */ proposal_votes: Array; /** An aggregate relationship */ @@ -3594,11 +3795,10 @@ export type Proposal_Bool_Exp = { deposit_end_time?: InputMaybe; description?: InputMaybe; id?: InputMaybe; + metadata?: InputMaybe; proposal_deposits?: InputMaybe; - proposal_route?: InputMaybe; proposal_tally_result?: InputMaybe; proposal_tally_results?: InputMaybe; - proposal_type?: InputMaybe; proposal_votes?: InputMaybe; proposer?: InputMaybe; proposer_address?: InputMaybe; @@ -3625,6 +3825,7 @@ export type Proposal_Deposit = { proposal: Proposal; proposal_id: Scalars['Int']; timestamp?: Maybe; + transaction_hash: Scalars['String']; }; /** aggregated selection of "proposal_deposit" */ @@ -3698,6 +3899,7 @@ export type Proposal_Deposit_Bool_Exp = { proposal?: InputMaybe; proposal_id?: InputMaybe; timestamp?: InputMaybe; + transaction_hash?: InputMaybe; }; /** aggregate max on columns */ @@ -3707,6 +3909,7 @@ export type Proposal_Deposit_Max_Fields = { height?: Maybe; proposal_id?: Maybe; timestamp?: Maybe; + transaction_hash?: Maybe; }; /** order by max() on columns of table "proposal_deposit" */ @@ -3715,6 +3918,7 @@ export type Proposal_Deposit_Max_Order_By = { height?: InputMaybe; proposal_id?: InputMaybe; timestamp?: InputMaybe; + transaction_hash?: InputMaybe; }; /** aggregate min on columns */ @@ -3724,6 +3928,7 @@ export type Proposal_Deposit_Min_Fields = { height?: Maybe; proposal_id?: Maybe; timestamp?: Maybe; + transaction_hash?: Maybe; }; /** order by min() on columns of table "proposal_deposit" */ @@ -3732,6 +3937,7 @@ export type Proposal_Deposit_Min_Order_By = { height?: InputMaybe; proposal_id?: InputMaybe; timestamp?: InputMaybe; + transaction_hash?: InputMaybe; }; /** Ordering options when selecting data from "proposal_deposit". */ @@ -3744,6 +3950,7 @@ export type Proposal_Deposit_Order_By = { proposal?: InputMaybe; proposal_id?: InputMaybe; timestamp?: InputMaybe; + transaction_hash?: InputMaybe; }; /** select columns of table "proposal_deposit" */ @@ -3757,7 +3964,9 @@ export enum Proposal_Deposit_Select_Column { /** column name */ ProposalId = 'proposal_id', /** column name */ - Timestamp = 'timestamp' + Timestamp = 'timestamp', + /** column name */ + TransactionHash = 'transaction_hash' } /** aggregate stddev on columns */ @@ -3857,8 +4066,7 @@ export type Proposal_Max_Fields = { deposit_end_time?: Maybe; description?: Maybe; id?: Maybe; - proposal_route?: Maybe; - proposal_type?: Maybe; + metadata?: Maybe; proposer_address?: Maybe; status?: Maybe; submit_time?: Maybe; @@ -3872,8 +4080,7 @@ export type Proposal_Max_Order_By = { deposit_end_time?: InputMaybe; description?: InputMaybe; id?: InputMaybe; - proposal_route?: InputMaybe; - proposal_type?: InputMaybe; + metadata?: InputMaybe; proposer_address?: InputMaybe; status?: InputMaybe; submit_time?: InputMaybe; @@ -3888,8 +4095,7 @@ export type Proposal_Min_Fields = { deposit_end_time?: Maybe; description?: Maybe; id?: Maybe; - proposal_route?: Maybe; - proposal_type?: Maybe; + metadata?: Maybe; proposer_address?: Maybe; status?: Maybe; submit_time?: Maybe; @@ -3903,8 +4109,7 @@ export type Proposal_Min_Order_By = { deposit_end_time?: InputMaybe; description?: InputMaybe; id?: InputMaybe; - proposal_route?: InputMaybe; - proposal_type?: InputMaybe; + metadata?: InputMaybe; proposer_address?: InputMaybe; status?: InputMaybe; submit_time?: InputMaybe; @@ -3919,11 +4124,10 @@ export type Proposal_Order_By = { deposit_end_time?: InputMaybe; description?: InputMaybe; id?: InputMaybe; + metadata?: InputMaybe; proposal_deposits_aggregate?: InputMaybe; - proposal_route?: InputMaybe; proposal_tally_result?: InputMaybe; proposal_tally_results_aggregate?: InputMaybe; - proposal_type?: InputMaybe; proposal_votes_aggregate?: InputMaybe; proposer?: InputMaybe; proposer_address?: InputMaybe; @@ -3947,9 +4151,7 @@ export enum Proposal_Select_Column { /** column name */ Id = 'id', /** column name */ - ProposalRoute = 'proposal_route', - /** column name */ - ProposalType = 'proposal_type', + Metadata = 'metadata', /** column name */ ProposerAddress = 'proposer_address', /** column name */ @@ -4750,6 +4952,7 @@ export type Proposal_Vote = { proposal_id: Scalars['Int']; timestamp?: Maybe; voter_address: Scalars['String']; + weight?: Maybe; }; /** aggregated selection of "proposal_vote" */ @@ -4823,6 +5026,7 @@ export type Proposal_Vote_Bool_Exp = { proposal_id?: InputMaybe; timestamp?: InputMaybe; voter_address?: InputMaybe; + weight?: InputMaybe; }; /** aggregate max on columns */ @@ -4833,6 +5037,7 @@ export type Proposal_Vote_Max_Fields = { proposal_id?: Maybe; timestamp?: Maybe; voter_address?: Maybe; + weight?: Maybe; }; /** order by max() on columns of table "proposal_vote" */ @@ -4842,6 +5047,7 @@ export type Proposal_Vote_Max_Order_By = { proposal_id?: InputMaybe; timestamp?: InputMaybe; voter_address?: InputMaybe; + weight?: InputMaybe; }; /** aggregate min on columns */ @@ -4852,6 +5058,7 @@ export type Proposal_Vote_Min_Fields = { proposal_id?: Maybe; timestamp?: Maybe; voter_address?: Maybe; + weight?: Maybe; }; /** order by min() on columns of table "proposal_vote" */ @@ -4861,6 +5068,7 @@ export type Proposal_Vote_Min_Order_By = { proposal_id?: InputMaybe; timestamp?: InputMaybe; voter_address?: InputMaybe; + weight?: InputMaybe; }; /** Ordering options when selecting data from "proposal_vote". */ @@ -4873,6 +5081,7 @@ export type Proposal_Vote_Order_By = { proposal_id?: InputMaybe; timestamp?: InputMaybe; voter_address?: InputMaybe; + weight?: InputMaybe; }; /** select columns of table "proposal_vote" */ @@ -4886,7 +5095,9 @@ export enum Proposal_Vote_Select_Column { /** column name */ Timestamp = 'timestamp', /** column name */ - VoterAddress = 'voter_address' + VoterAddress = 'voter_address', + /** column name */ + Weight = 'weight' } /** aggregate stddev on columns */ @@ -6392,6 +6603,8 @@ export type Software_Upgrade_Plan = { height: Scalars['bigint']; info: Scalars['String']; plan_name: Scalars['String']; + /** An object relationship */ + proposal?: Maybe; proposal_id?: Maybe; upgrade_height: Scalars['bigint']; }; @@ -6442,6 +6655,7 @@ export type Software_Upgrade_Plan_Bool_Exp = { height?: InputMaybe; info?: InputMaybe; plan_name?: InputMaybe; + proposal?: InputMaybe; proposal_id?: InputMaybe; upgrade_height?: InputMaybe; }; @@ -6471,6 +6685,7 @@ export type Software_Upgrade_Plan_Order_By = { height?: InputMaybe; info?: InputMaybe; plan_name?: InputMaybe; + proposal?: InputMaybe; proposal_id?: InputMaybe; upgrade_height?: InputMaybe; }; @@ -8978,6 +9193,10 @@ export type Transaction = { logs?: Maybe; memo?: Maybe; messages: Scalars['jsonb']; + /** An array relationship */ + messagesByPartitionIdTransactionHash: Array; + /** An aggregate relationship */ + messagesByPartitionIdTransactionHash_aggregate: Message_Aggregate; partition_id: Scalars['bigint']; raw_log?: Maybe; signatures: Scalars['_text']; @@ -9004,6 +9223,26 @@ export type TransactionMessagesArgs = { }; +/** columns and relationships of "transaction" */ +export type TransactionMessagesByPartitionIdTransactionHashArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + +/** columns and relationships of "transaction" */ +export type TransactionMessagesByPartitionIdTransactionHash_AggregateArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + /** columns and relationships of "transaction" */ export type TransactionSigner_InfosArgs = { path?: InputMaybe; @@ -9085,6 +9324,7 @@ export type Transaction_Bool_Exp = { logs?: InputMaybe; memo?: InputMaybe; messages?: InputMaybe; + messagesByPartitionIdTransactionHash?: InputMaybe; partition_id?: InputMaybe; raw_log?: InputMaybe; signatures?: InputMaybe<_Text_Comparison_Exp>; @@ -9149,6 +9389,7 @@ export type Transaction_Order_By = { logs?: InputMaybe; memo?: InputMaybe; messages?: InputMaybe; + messagesByPartitionIdTransactionHash_aggregate?: InputMaybe; partition_id?: InputMaybe; raw_log?: InputMaybe; signatures?: InputMaybe; @@ -11468,7 +11709,6 @@ export type Wasm_Params = { code_upload_access: Scalars['access_config']; height: Scalars['bigint']; instantiate_default_permission: Scalars['Int']; - max_wasm_code_size: Scalars['Int']; one_row_id: Scalars['Boolean']; }; @@ -11507,7 +11747,6 @@ export type Wasm_Params_Avg_Fields = { __typename?: 'wasm_params_avg_fields'; height?: Maybe; instantiate_default_permission?: Maybe; - max_wasm_code_size?: Maybe; }; /** Boolean expression to filter rows from the table "wasm_params". All fields are combined with a logical 'AND'. */ @@ -11518,7 +11757,6 @@ export type Wasm_Params_Bool_Exp = { code_upload_access?: InputMaybe; height?: InputMaybe; instantiate_default_permission?: InputMaybe; - max_wasm_code_size?: InputMaybe; one_row_id?: InputMaybe; }; @@ -11527,7 +11765,6 @@ export type Wasm_Params_Max_Fields = { __typename?: 'wasm_params_max_fields'; height?: Maybe; instantiate_default_permission?: Maybe; - max_wasm_code_size?: Maybe; }; /** aggregate min on columns */ @@ -11535,7 +11772,6 @@ export type Wasm_Params_Min_Fields = { __typename?: 'wasm_params_min_fields'; height?: Maybe; instantiate_default_permission?: Maybe; - max_wasm_code_size?: Maybe; }; /** Ordering options when selecting data from "wasm_params". */ @@ -11543,7 +11779,6 @@ export type Wasm_Params_Order_By = { code_upload_access?: InputMaybe; height?: InputMaybe; instantiate_default_permission?: InputMaybe; - max_wasm_code_size?: InputMaybe; one_row_id?: InputMaybe; }; @@ -11556,8 +11791,6 @@ export enum Wasm_Params_Select_Column { /** column name */ InstantiateDefaultPermission = 'instantiate_default_permission', /** column name */ - MaxWasmCodeSize = 'max_wasm_code_size', - /** column name */ OneRowId = 'one_row_id' } @@ -11566,7 +11799,6 @@ export type Wasm_Params_Stddev_Fields = { __typename?: 'wasm_params_stddev_fields'; height?: Maybe; instantiate_default_permission?: Maybe; - max_wasm_code_size?: Maybe; }; /** aggregate stddev_pop on columns */ @@ -11574,7 +11806,6 @@ export type Wasm_Params_Stddev_Pop_Fields = { __typename?: 'wasm_params_stddev_pop_fields'; height?: Maybe; instantiate_default_permission?: Maybe; - max_wasm_code_size?: Maybe; }; /** aggregate stddev_samp on columns */ @@ -11582,7 +11813,6 @@ export type Wasm_Params_Stddev_Samp_Fields = { __typename?: 'wasm_params_stddev_samp_fields'; height?: Maybe; instantiate_default_permission?: Maybe; - max_wasm_code_size?: Maybe; }; /** aggregate sum on columns */ @@ -11590,7 +11820,6 @@ export type Wasm_Params_Sum_Fields = { __typename?: 'wasm_params_sum_fields'; height?: Maybe; instantiate_default_permission?: Maybe; - max_wasm_code_size?: Maybe; }; /** aggregate var_pop on columns */ @@ -11598,7 +11827,6 @@ export type Wasm_Params_Var_Pop_Fields = { __typename?: 'wasm_params_var_pop_fields'; height?: Maybe; instantiate_default_permission?: Maybe; - max_wasm_code_size?: Maybe; }; /** aggregate var_samp on columns */ @@ -11606,7 +11834,6 @@ export type Wasm_Params_Var_Samp_Fields = { __typename?: 'wasm_params_var_samp_fields'; height?: Maybe; instantiate_default_permission?: Maybe; - max_wasm_code_size?: Maybe; }; /** aggregate variance on columns */ @@ -11614,7 +11841,6 @@ export type Wasm_Params_Variance_Fields = { __typename?: 'wasm_params_variance_fields'; height?: Maybe; instantiate_default_permission?: Maybe; - max_wasm_code_size?: Maybe; }; export type AccountCommissionQueryVariables = Exact<{ @@ -11767,14 +11993,14 @@ export type OnlineVotingPowerQuery = { activeTotal: { __typename?: 'validator_st export type ParamsQueryVariables = Exact<{ [key: string]: never; }>; -export type ParamsQuery = { stakingParams: Array<{ __typename?: 'staking_params', params: any }>, slashingParams: Array<{ __typename?: 'slashing_params', params: any }>, mintParams: Array<{ __typename?: 'mint_params', params: any }>, distributionParams: Array<{ __typename?: 'distribution_params', params: any }>, govParams: Array<{ __typename?: 'gov_params', depositParams: any, tallyParams: any, votingParams: any }> }; +export type ParamsQuery = { stakingParams: Array<{ __typename?: 'staking_params', params: any }>, slashingParams: Array<{ __typename?: 'slashing_params', params: any }>, mintParams: Array<{ __typename?: 'mint_params', params: any }>, distributionParams: Array<{ __typename?: 'distribution_params', params: any }>, govParams: Array<{ __typename?: 'gov_params', params: any }> }; export type ProposalDetailsQueryVariables = Exact<{ proposalId?: InputMaybe; }>; -export type ProposalDetailsQuery = { proposal: Array<{ __typename?: 'proposal', title: string, description: string, status?: string | null, content: any, proposer: string, proposalId: number, submitTime: any, proposalType: string, depositEndTime?: any | null, votingStartTime?: any | null, votingEndTime?: any | null }> }; +export type ProposalDetailsQuery = { proposal: Array<{ __typename?: 'proposal', title: string, description: string, status?: string | null, content: any, proposer: string, proposalId: number, submitTime: any, depositEndTime?: any | null, votingStartTime?: any | null, votingEndTime?: any | null }> }; export type ProposalDetailsTallyQueryVariables = Exact<{ proposalId?: InputMaybe; @@ -12766,9 +12992,7 @@ export const ParamsDocument = gql` params } govParams: gov_params(limit: 1, order_by: {height: desc}) { - depositParams: deposit_params - tallyParams: tally_params - votingParams: voting_params + params } } `; @@ -12809,7 +13033,6 @@ export const ProposalDetailsDocument = gql` content proposalId: id submitTime: submit_time - proposalType: proposal_type depositEndTime: deposit_end_time votingStartTime: voting_start_time votingEndTime: voting_end_time @@ -12860,7 +13083,7 @@ export const ProposalDetailsTallyDocument = gql` bondedTokens: bonded_tokens } quorum: gov_params(limit: 1, order_by: {height: desc}) { - tallyParams: tally_params + tallyParams: params } } `; diff --git a/apps/web-nym/src/models/gov_params/index.ts b/apps/web-nym/src/models/gov_params/index.ts new file mode 100644 index 0000000000..2a13f6536c --- /dev/null +++ b/apps/web-nym/src/models/gov_params/index.ts @@ -0,0 +1,65 @@ +import * as R from 'ramda'; + +class GovParams { + public params: { + quorum: string; + threshold: string; + minDeposit: Array<{ + denom: string; + amount: string; + }>; + votingPeriod: number; + burnVoteVeto: boolean; + vetoThreshold: string; + maxDepositPeriod: number; + minInitialDepositRatio: string; + burnProposalDepositPrevote: boolean; + }; + + constructor(payload: object) { + this.params = R.pathOr( + { + quorum: '', + threshold: '', + minDeposit: [], + votingPeriod: 0, + burnVoteVeto: false, + vetoThreshold: '', + maxDepositPeriod: 0, + minInitialDepositRatio: '', + burnProposalDepositPrevote: false, + }, + ['params'], + payload + ); + } + + static fromJson(data: object): GovParams { + return { + params: { + quorum: R.pathOr('0', ['params', 'quorum'], data), + threshold: R.pathOr('0', ['params', 'threshold'], data), + minDeposit: R.pathOr( + [], + ['params', 'min_deposit'], + data + ).map((x) => ({ + denom: x.denom, + amount: String(x.amount), + })), + votingPeriod: R.pathOr(0, ['params', 'voting_period'], data), + burnVoteVeto: R.pathOr(false, ['params', 'burn_veto_vote'], data), + vetoThreshold: R.pathOr('0', ['params', 'veto_threshold'], data), + maxDepositPeriod: R.pathOr(0, ['params', 'max_deposit_period'], data), + minInitialDepositRatio: R.pathOr('0', ['params', 'min_initial_deposit_ratio'], data), + burnProposalDepositPrevote: R.pathOr( + false, + ['params', 'burn_proposal_deposit_prevote'], + data + ), + }, + }; + } +} + +export default GovParams; diff --git a/apps/web-nym/src/screens/home/components/data_blocks/hooks.ts b/apps/web-nym/src/screens/home/components/data_blocks/hooks.ts new file mode 100644 index 0000000000..a2697fc0a2 --- /dev/null +++ b/apps/web-nym/src/screens/home/components/data_blocks/hooks.ts @@ -0,0 +1,107 @@ +import numeral from 'numeral'; +import { useState } from 'react'; +import chainConfig from '@/chainConfig'; +import { + ActiveValidatorCountQuery, + AverageBlockTimeQuery, + TokenPriceListenerSubscription, + useActiveValidatorCountQuery, + useAverageBlockTimeQuery, + useLatestBlockHeightListenerSubscription, + useTokenPriceListenerSubscription, +} from '@/graphql/types/general_types'; + +const { priceTokenUnit, tokenUnits } = chainConfig(); + +type DataBlocksState = { + blockHeight: number; + blockTime: number; + price: number | null; + validators: { + active: number; + total: number; + }; +}; + +const formatAverageBlockTime = (data: AverageBlockTimeQuery, state: DataBlocksState) => + data.averageBlockTime[0]?.averageTime ?? state.blockTime; + +const formatTokenPrice = (data: TokenPriceListenerSubscription, state: DataBlocksState) => { + if (data?.tokenPrice[0]?.price) { + return numeral(numeral(data?.tokenPrice[0]?.price).format('0.0000', Math.floor)).value(); + } + return state.price; +}; + +const formatActiveValidatorsCount = (data: ActiveValidatorCountQuery) => ({ + active: data.activeTotal.aggregate?.count ?? 0, + total: data.total?.aggregate?.count ?? 0, +}); + +export const useDataBlocks = () => { + const [state, setState] = useState({ + blockHeight: 0, + blockTime: 0, + price: null, + validators: { + active: 0, + total: 0, + }, + }); + + // ==================================== + // block height + // ==================================== + + useLatestBlockHeightListenerSubscription({ + onData: (data) => { + setState((prevState) => ({ + ...prevState, + blockHeight: data.data.data?.height?.[0]?.height ?? 0, + })); + }, + }); + + // ==================================== + // block time + // ==================================== + useAverageBlockTimeQuery({ + onCompleted: (data) => { + setState((prevState) => ({ + ...prevState, + blockTime: formatAverageBlockTime(data, state), + })); + }, + }); + + // ==================================== + // token price + // ==================================== + useTokenPriceListenerSubscription({ + variables: { + denom: tokenUnits?.[priceTokenUnit]?.display, + }, + onData: (data) => { + setState((prevState) => ({ + ...prevState, + price: data.data.data ? formatTokenPrice(data.data.data, state) : 0, + })); + }, + }); + + // ==================================== + // validators + // ==================================== + useActiveValidatorCountQuery({ + onCompleted: (data) => { + setState((prevState) => ({ + ...prevState, + validators: formatActiveValidatorsCount(data), + })); + }, + }); + + return { + state, + }; +}; diff --git a/apps/web-nym/src/screens/home/components/hero/hooks.ts b/apps/web-nym/src/screens/home/components/hero/hooks.ts new file mode 100644 index 0000000000..fa397753f4 --- /dev/null +++ b/apps/web-nym/src/screens/home/components/hero/hooks.ts @@ -0,0 +1,53 @@ +import * as R from 'ramda'; +import { useCallback, useState } from 'react'; +import chainConfig from '@/chainConfig'; +import { useTokenPriceHistoryQuery } from '@/graphql/types/general_types'; +import type { HeroState } from '@/screens/home/components/hero/types'; + +const { priceTokenUnit, tokenUnits } = chainConfig(); +const limit = 48; + +export const useHero = () => { + const [state, setState] = useState({ + loading: true, + exists: true, + tokenPriceHistory: [], + }); + + const handleSetState = useCallback((stateChange: (prevState: HeroState) => HeroState) => { + setState((prevState) => { + const newState = stateChange(prevState); + return R.equals(prevState, newState) ? prevState : newState; + }); + }, []); + + useTokenPriceHistoryQuery({ + variables: { + limit, + denom: tokenUnits?.[priceTokenUnit]?.display, + }, + onCompleted: (data) => { + handleSetState((prevState) => { + const newState = { + ...prevState, + loading: false, + tokenPriceHistory: + data.tokenPrice.length === limit + ? [...data.tokenPrice].reverse().map((x) => ({ + time: x.timestamp, + value: x.price, + })) + : prevState.tokenPriceHistory, + }; + return R.equals(prevState, newState) ? prevState : newState; + }); + }, + onError: () => { + handleSetState((prevState) => ({ ...prevState, loading: false })); + }, + }); + + return { + state, + }; +}; diff --git a/apps/web-nym/src/screens/params/hooks.ts b/apps/web-nym/src/screens/params/hooks.ts new file mode 100644 index 0000000000..f7ccabc92b --- /dev/null +++ b/apps/web-nym/src/screens/params/hooks.ts @@ -0,0 +1,169 @@ +import * as R from 'ramda'; +import { useCallback, useState } from 'react'; +import chainConfig from '@/chainConfig'; +import { ParamsQuery, useParamsQuery } from '@/graphql/types/general_types'; +import { DistributionParams, MintParams, SlashingParams, StakingParams } from '@/models'; +import numeral from 'numeral'; + +import { formatToken } from '@/utils/format_token'; +import type { ParamsState } from './types'; +import GovParams from '../../models/gov_params'; + +const { primaryTokenUnit } = chainConfig(); + +const initialState: ParamsState = { + loading: true, + exists: true, + staking: null, + slashing: null, + minting: null, + distribution: null, + gov: null, +}; + +// ================================ +// staking +// ================================ +const formatStaking = (data: ParamsQuery) => { + if (data.stakingParams.length) { + const stakingParamsRaw = StakingParams.fromJson(data?.stakingParams?.[0]?.params ?? {}); + return { + bondDenom: stakingParamsRaw.bondDenom, + unbondingTime: stakingParamsRaw.unbondingTime, + maxEntries: stakingParamsRaw.maxEntries, + historicalEntries: stakingParamsRaw.historicalEntries, + maxValidators: stakingParamsRaw.maxValidators, + }; + } + + return null; +}; + +// ================================ +// slashing +// ================================ +const formatSlashing = (data: ParamsQuery) => { + if (data.slashingParams.length) { + const slashingParamsRaw = SlashingParams.fromJson(data?.slashingParams?.[0]?.params ?? {}); + return { + downtimeJailDuration: slashingParamsRaw.downtimeJailDuration, + minSignedPerWindow: slashingParamsRaw.minSignedPerWindow, + signedBlockWindow: slashingParamsRaw.signedBlockWindow, + slashFractionDoubleSign: slashingParamsRaw.slashFractionDoubleSign, + slashFractionDowntime: slashingParamsRaw.slashFractionDowntime, + }; + } + return null; +}; + +// ================================ +// minting +// ================================ +const formatMint = (data: ParamsQuery) => { + if (data.mintParams.length) { + const mintParamsRaw = MintParams.fromJson(data?.mintParams?.[0]?.params ?? {}); + + return { + blocksPerYear: mintParamsRaw.blocksPerYear, + goalBonded: mintParamsRaw.goalBonded, + inflationMax: mintParamsRaw.inflationMax, + inflationMin: mintParamsRaw.inflationMin, + inflationRateChange: mintParamsRaw.inflationRateChange, + mintDenom: mintParamsRaw.mintDenom, + }; + } + + return null; +}; + +// ================================ +// distribution +// ================================ +const formatDistribution = (data: ParamsQuery) => { + if (data.distributionParams.length) { + const distributionParamsRaw = DistributionParams.fromJson( + data?.distributionParams?.[0]?.params ?? {} + ); + return { + baseProposerReward: distributionParamsRaw.baseProposerReward, + bonusProposerReward: distributionParamsRaw.bonusProposerReward, + communityTax: distributionParamsRaw.communityTax, + withdrawAddressEnabled: distributionParamsRaw.withdrawAddressEnabled, + }; + } + + return null; +}; + +// ================================ +// gov +// ================================ +const formatGov = (data: ParamsQuery) => { + if (data.govParams.length) { + const govParamsRaw = GovParams.fromJson(data?.govParams?.[0] ?? {}); + return { + quorum: numeral(numeral(govParamsRaw?.params?.quorum).format('0.[00]')).value() ?? 0, + threshold: numeral(numeral(govParamsRaw?.params?.threshold).format('0.[00]')).value() ?? 0, + minDeposit: + formatToken( + govParamsRaw?.params?.minDeposit?.[0]?.amount ?? 0, + govParamsRaw?.params?.minDeposit?.[0]?.denom ?? primaryTokenUnit + ) ?? 0, + votingPeriod: govParamsRaw?.params?.votingPeriod ?? 0, + burnVoteVeto: govParamsRaw?.params?.burnVoteVeto ?? false, + vetoThreshold: + numeral(numeral(govParamsRaw?.params?.vetoThreshold).format('0.[00]')).value() ?? 0, + maxDepositPeriod: govParamsRaw?.params?.maxDepositPeriod ?? 0, + minInitialDepositRatio: govParamsRaw?.params?.minInitialDepositRatio ?? '', + burnProposalDepositPrevote: govParamsRaw?.params?.burnProposalDepositPrevote ?? false, + }; + } + return null; +}; + +const formatParam = (data: ParamsQuery) => { + const results: Partial = {}; + + results.staking = formatStaking(data); + + results.slashing = formatSlashing(data); + + results.minting = formatMint(data); + + results.distribution = formatDistribution(data); + + results.gov = formatGov(data); + + return results; +}; + +export const useParams = () => { + const [state, setState] = useState(initialState); + + const handleSetState = useCallback((stateChange: (prevState: ParamsState) => ParamsState) => { + setState((prevState) => { + const newState = stateChange(prevState); + return R.equals(prevState, newState) ? prevState : newState; + }); + }, []); + + // ================================ + // param query + // ================================ + useParamsQuery({ + onCompleted: (data) => { + handleSetState((prevState) => ({ + ...prevState, + loading: false, + ...formatParam(data), + })); + }, + onError: () => { + handleSetState((prevState) => ({ ...prevState, loading: false })); + }, + }); + + return { + state, + }; +}; diff --git a/apps/web-nym/src/screens/params/index.tsx b/apps/web-nym/src/screens/params/index.tsx new file mode 100644 index 0000000000..e7087ba347 --- /dev/null +++ b/apps/web-nym/src/screens/params/index.tsx @@ -0,0 +1,79 @@ +import BoxDetails from '@/components/box_details'; +import Layout from '@/components/layout'; +import LoadAndExist from '@/components/load_and_exist'; +import useAppTranslation from '@/hooks/useAppTranslation'; +import { useParams } from '@/screens/params/hooks'; +import useStyles from '@/screens/params/styles'; +import { + formatDistribution, + formatGov, + formatMinting, + formatSlashing, + formatStaking, +} from '@/screens/params/utils'; +import { NextSeo } from 'next-seo'; + +const Params = () => { + const { t } = useAppTranslation('params'); + const { classes } = useStyles(); + const { state } = useParams(); + + const staking = state.staking + ? { + title: t('staking') ?? undefined, + details: formatStaking(state.staking, t), + } + : null; + + const slashing = state.slashing + ? { + title: t('slashing') ?? undefined, + details: formatSlashing(state.slashing, t), + } + : null; + + const minting = state.minting + ? { + title: t('minting') ?? undefined, + details: formatMinting(state.minting, t), + } + : null; + + const distribution = state.distribution + ? { + title: t('distribution') ?? undefined, + details: formatDistribution(state.distribution, t), + } + : null; + + const gov = state.gov + ? { + title: t('gov') ?? undefined, + details: formatGov(state.gov, t), + } + : null; + + return ( + <> + + + + + {staking && } + {slashing && } + {minting && } + {distribution && } + {gov && } + + + + + ); +}; + +export default Params; diff --git a/apps/web-nym/src/screens/params/types.ts b/apps/web-nym/src/screens/params/types.ts new file mode 100644 index 0000000000..db0e0da854 --- /dev/null +++ b/apps/web-nym/src/screens/params/types.ts @@ -0,0 +1,53 @@ +export interface Staking { + bondDenom: string; + unbondingTime: number; + maxEntries: number; + historicalEntries: number; + maxValidators: number; +} + +export interface Slashing { + downtimeJailDuration: number; + minSignedPerWindow: number; + signedBlockWindow: number; + slashFractionDoubleSign: number; + slashFractionDowntime: number; +} + +export interface Minting { + blocksPerYear: number; + goalBonded: number; + inflationMax: number; + inflationMin: number; + inflationRateChange: number; + mintDenom: string; +} + +export interface Distribution { + baseProposerReward: number; + bonusProposerReward: number; + communityTax: number; + withdrawAddressEnabled: boolean; +} + +export interface Gov { + quorum: number; + threshold: number; + minDeposit: TokenUnit; + votingPeriod: number; + burnVoteVeto: boolean; + vetoThreshold: number; + maxDepositPeriod: number; + minInitialDepositRatio: string; + burnProposalDepositPrevote: boolean; +} + +export interface ParamsState { + loading: boolean; + exists: boolean; + staking: Staking | null; + slashing: Slashing | null; + minting: Minting | null; + distribution: Distribution | null; + gov: Gov | null; +} diff --git a/apps/web-nym/src/screens/params/utils.tsx b/apps/web-nym/src/screens/params/utils.tsx new file mode 100644 index 0000000000..5506c8a9dd --- /dev/null +++ b/apps/web-nym/src/screens/params/utils.tsx @@ -0,0 +1,179 @@ +import { nanoToSeconds, secondsToDays } from '@/utils/time'; +import type { TFunction } from '@/hooks/useAppTranslation'; +import numeral from 'numeral'; +import type { Distribution, Minting, Slashing, Staking, Gov } from './types'; + +const convertBySeconds = (seconds: number, t: TFunction) => { + const SECONDS_IN_DAY = 86400; + return seconds >= SECONDS_IN_DAY + ? t('days', { + day: secondsToDays(seconds), + }) + : t('seconds', { + second: seconds, + }); +}; + +export const formatStaking = (data: Staking, t: TFunction) => [ + { + key: 'bondDenom', + label: t('bondDenom'), + detail: data.bondDenom, + }, + { + key: 'unbondingTime', + label: t('unbondingTime'), + detail: convertBySeconds(nanoToSeconds(data.unbondingTime), t), + }, + { + key: 'maxEntries', + label: t('maxEntries'), + detail: numeral(data.maxEntries).format('0,0'), + }, + { + key: 'historicalEntries', + label: t('historicalEntries'), + detail: numeral(data.historicalEntries).format('0,0'), + }, + { + key: 'maxValidators', + label: t('maxValidators'), + detail: numeral(data.maxValidators).format('0,0'), + }, +]; + +export const formatSlashing = (data: Slashing, t: TFunction) => [ + { + key: 'downtimeJailDuration', + label: t('downtimeJailDuration'), + detail: t('seconds', { + second: numeral(nanoToSeconds(data.downtimeJailDuration)).format('0,0'), + }), + }, + { + key: 'minSignedPerWindow', + label: t('minSignedPerWindow'), + detail: `${numeral(data.minSignedPerWindow * 100).format('0.[00]')}%`, + }, + { + key: 'signedBlockWindow', + label: t('signedBlockWindow'), + detail: numeral(data.signedBlockWindow).format('0,0'), + }, + { + key: 'slashFractionDoubleSign', + label: t('slashFractionDoubleSign'), + detail: `${data.slashFractionDoubleSign * 100} / 100`, + }, + { + key: 'slashFractionDowntime', + label: t('slashFractionDowntime'), + detail: `${data.slashFractionDowntime * 10000} / ${numeral(10000).format('0,0')}`, + }, +]; + +export const formatMinting = (data: Minting, t: TFunction) => [ + { + key: 'blocksPerYear', + label: t('blocksPerYear'), + detail: numeral(data.blocksPerYear).format('0,0'), + }, + { + key: 'goalBonded', + label: t('goalBonded'), + detail: `${numeral(data.goalBonded * 100).format('0.[00]')}%`, + }, + { + key: 'inflationMax', + label: t('inflationMax'), + detail: `${numeral(data.inflationMax * 100).format('0.[00]')}%`, + }, + { + key: 'inflationMin', + label: t('inflationMin'), + detail: `${numeral(data.inflationMin * 100).format('0.[00]')}%`, + }, + { + key: 'inflationRateChange', + label: t('inflationRateChange'), + detail: `${numeral(data.inflationRateChange * 100).format('0.[00]')}%`, + }, + { + key: 'mintDenom', + label: t('mintDenom'), + detail: data.mintDenom, + }, +]; + +export const formatDistribution = (data: Distribution, t: TFunction) => [ + { + key: 'baseProposerReward', + label: t('baseProposerReward'), + detail: `${numeral(data.baseProposerReward * 100).format('0.[00]')}%`, + }, + { + key: 'bonusProposerReward', + label: t('bonusProposerReward'), + detail: `${numeral(data.bonusProposerReward * 100).format('0.[00]')}%`, + }, + { + key: 'communityTax', + label: t('communityTax'), + detail: `${numeral(data.communityTax * 100).format('0.[00]')}%`, + }, + { + key: 'withdrawAddressEnabled', + label: t('withdrawAddressEnabled'), + detail: `${data.withdrawAddressEnabled}`.toUpperCase(), + }, +]; + +export const formatGov = (data: Gov, t: TFunction) => [ + { + key: 'burnVoteVeto', + label: t('burnVoteVeto'), + detail: `${data.burnVoteVeto}`.toUpperCase(), + }, + { + key: 'burnProposalDepositPrevote', + label: t('burnProposalDepositPrevote'), + detail: `${data.burnProposalDepositPrevote}`.toUpperCase(), + }, + { + key: 'minDeposit', + label: t('minDeposit'), + detail: `${numeral(data.minDeposit.value).format( + '0.[00]' + )} ${data.minDeposit.displayDenom.toUpperCase()}`, + }, + { + key: 'maxDepositPeriod', + label: t('maxDepositPeriod'), + detail: convertBySeconds(nanoToSeconds(data.maxDepositPeriod), t), + }, + { + key: 'minInitialDepositRatio', + label: t('minInitialDepositRatio'), + detail: `${numeral(data.minInitialDepositRatio).format('0.[00]')}`, + }, + { + key: 'quorum', + label: t('quorum'), + detail: `${numeral(data.quorum * 100).format('0.[00]')}%`, + }, + { + key: 'threshold', + label: t('threshold'), + detail: `${numeral(data.threshold * 100).format('0.[00]')}%`, + }, + { + key: 'vetoThreshold', + label: t('vetoThreshold'), + detail: `${numeral(data.vetoThreshold * 100).format('0.[00]')}%`, + }, + { + key: 'votingPeriod', + label: t('votingPeriod'), + detail: convertBySeconds(nanoToSeconds(data.votingPeriod), t), + }, +]; diff --git a/apps/web-nym/src/screens/proposal_details/hooks.ts b/apps/web-nym/src/screens/proposal_details/hooks.ts new file mode 100644 index 0000000000..df656789ab --- /dev/null +++ b/apps/web-nym/src/screens/proposal_details/hooks.ts @@ -0,0 +1,95 @@ +import { useRouter } from 'next/router'; +import * as R from 'ramda'; +import { useCallback, useState } from 'react'; +import { ProposalDetailsQuery, useProposalDetailsQuery } from '@/graphql/types/general_types'; +import type { ProposalState } from './types'; + +// ========================= +// overview +// ========================= +const formatOverview = (data: ProposalDetailsQuery) => { + const DEFAULT_TIME = '0001-01-01T00:00:00'; + let votingStartTime = data?.proposal?.[0]?.votingStartTime ?? DEFAULT_TIME; + votingStartTime = votingStartTime === DEFAULT_TIME ? '' : votingStartTime; + let votingEndTime = data?.proposal?.[0]?.votingEndTime ?? DEFAULT_TIME; + votingEndTime = votingEndTime === DEFAULT_TIME ? '' : votingEndTime; + + const overview = { + proposer: data?.proposal?.[0]?.proposer ?? '', + content: data?.proposal?.[0]?.content ?? '', + title: data?.proposal?.[0]?.title ?? '', + id: data?.proposal?.[0]?.proposalId ?? '', + description: data?.proposal?.[0]?.description ?? '', + status: data?.proposal?.[0]?.status ?? '', + submitTime: data?.proposal?.[0]?.submitTime ?? '', + depositEndTime: data?.proposal?.[0]?.depositEndTime ?? '', + votingStartTime, + votingEndTime, + }; + + return overview; +}; + +// ========================== +// parsers +// ========================== +const formatProposalQuery = (data: ProposalDetailsQuery) => { + const stateChange: Partial = { + loading: false, + }; + + if (!data.proposal.length) { + stateChange.exists = false; + return stateChange; + } + + stateChange.overview = formatOverview(data); + + return stateChange; +}; + +export const useProposalDetails = () => { + const router = useRouter(); + const [state, setState] = useState({ + loading: true, + exists: true, + overview: { + proposer: '', + content: { + recipient: '', + amount: [], + }, + title: '', + id: 0, + description: '', + status: '', + submitTime: '', + depositEndTime: '', + votingStartTime: '', + votingEndTime: '', + }, + }); + + const handleSetState = useCallback((stateChange: (prevState: ProposalState) => ProposalState) => { + setState((prevState) => { + const newState = stateChange(prevState); + return R.equals(prevState, newState) ? prevState : newState; + }); + }, []); + + // ========================== + // fetch data + // ========================== + useProposalDetailsQuery({ + variables: { + proposalId: parseFloat((router?.query?.id as string) ?? '0'), + }, + onCompleted: (data) => { + handleSetState((prevState) => ({ ...prevState, ...formatProposalQuery(data) })); + }, + }); + + return { + state, + }; +}; diff --git a/apps/web-nym/src/screens/proposal_details/types.ts b/apps/web-nym/src/screens/proposal_details/types.ts new file mode 100644 index 0000000000..2055522c4b --- /dev/null +++ b/apps/web-nym/src/screens/proposal_details/types.ts @@ -0,0 +1,24 @@ +export interface OverviewType { + title: string; + id: number; + proposer: string; + description: string; + status: string; + submitTime: string; + depositEndTime: string; + votingStartTime: string | null; + votingEndTime: string | null; + content: { + recipient: string; + amount: Array<{ + amount: string; + denom: string; + }>; + }; +} + +export interface ProposalState { + loading: boolean; + exists: boolean; + overview: OverviewType; +} diff --git a/packages/ui/public/locales/en/web_nym.json b/packages/ui/public/locales/en/web_nym.json new file mode 100644 index 0000000000..b9f11ce37f --- /dev/null +++ b/packages/ui/public/locales/en/web_nym.json @@ -0,0 +1,5 @@ +{ + "params.burnVoteVeto": "Burn Vote Veto", + "params.burnProposalDepositPrevote": "Burn Proposal Deposit Prevote", + "params.minInitialDepositRatio": "Min Initial Deposit Ratio" +} \ No newline at end of file diff --git a/packages/ui/public/locales/it/web_nym.json b/packages/ui/public/locales/it/web_nym.json new file mode 100644 index 0000000000..86425218fc --- /dev/null +++ b/packages/ui/public/locales/it/web_nym.json @@ -0,0 +1,5 @@ +{ + "params.burnVoteVeto": "Brucia il veto al voto", + "params.burnProposalDepositPrevote": "Brucia il deposito della proposta prima del voto", + "params.minInitialDepositRatio": "Rapporto minimo di deposito iniziale" +} \ No newline at end of file diff --git a/packages/ui/public/locales/pl/web_nym.json b/packages/ui/public/locales/pl/web_nym.json new file mode 100644 index 0000000000..7037528ae2 --- /dev/null +++ b/packages/ui/public/locales/pl/web_nym.json @@ -0,0 +1,5 @@ +{ + "params.burnVoteVeto": "Spal głos weto", + "params.burnProposalDepositPrevote": "Spal depozyt propozycji przed głosowaniem", + "params.minInitialDepositRatio": "Min początkowy stosunek depozytu" +} \ No newline at end of file diff --git a/packages/ui/public/locales/zhs/web_nym.json b/packages/ui/public/locales/zhs/web_nym.json new file mode 100644 index 0000000000..4feae16063 --- /dev/null +++ b/packages/ui/public/locales/zhs/web_nym.json @@ -0,0 +1,5 @@ +{ + "params.burnVoteVeto": "烧毁投票否决权", + "params.burnProposalDepositPrevote": "销毁提案 存款 预投票", + "params.minInitialDepositRatio": "最低初始存款比例" +} \ No newline at end of file diff --git a/packages/ui/public/locales/zht/web_nym.json b/packages/ui/public/locales/zht/web_nym.json new file mode 100644 index 0000000000..d460f439b1 --- /dev/null +++ b/packages/ui/public/locales/zht/web_nym.json @@ -0,0 +1,5 @@ +{ + "params.burnVoteVeto": "燒毀投票否決權", + "params.burnProposalDepositPrevote": "銷毀提案押金預投票", + "params.minInitialDepositRatio": "最低初始存款比例" +} \ No newline at end of file