diff --git a/apps/explorer/src/app/routes/network-parameters/NetworkParameters.graphql b/apps/explorer/src/app/routes/network-parameters/NetworkParameters.graphql deleted file mode 100644 index 7fbac2c00..000000000 --- a/apps/explorer/src/app/routes/network-parameters/NetworkParameters.graphql +++ /dev/null @@ -1,6 +0,0 @@ -query NetworkParametersQuery { - networkParameters { - key - value - } -} diff --git a/apps/explorer/src/app/routes/network-parameters/__generated__/NetworkParametersQuery.ts b/apps/explorer/src/app/routes/network-parameters/__generated__/NetworkParametersQuery.ts deleted file mode 100644 index 6d8fcc5f1..000000000 --- a/apps/explorer/src/app/routes/network-parameters/__generated__/NetworkParametersQuery.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -// @generated -// This file was automatically generated and should not be edited. - -// ==================================================== -// GraphQL query operation: NetworkParametersQuery -// ==================================================== - -export interface NetworkParametersQuery_networkParameters { - __typename: "NetworkParameter"; - /** - * The name of the network parameter - */ - key: string; - /** - * The value of the network parameter - */ - value: string; -} - -export interface NetworkParametersQuery { - /** - * Return the full list of network parameters - */ - networkParameters: NetworkParametersQuery_networkParameters[] | null; -} diff --git a/apps/explorer/src/app/routes/network-parameters/__generated___/NetworkParameters.ts b/apps/explorer/src/app/routes/network-parameters/__generated___/NetworkParameters.ts deleted file mode 100644 index dd1045c07..000000000 --- a/apps/explorer/src/app/routes/network-parameters/__generated___/NetworkParameters.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Schema as Types } from '@vegaprotocol/types'; - -import { gql } from '@apollo/client'; -import * as Apollo from '@apollo/client'; -const defaultOptions = {} as const; -export type NetworkParametersQueryQueryVariables = Types.Exact<{ [key: string]: never; }>; - - -export type NetworkParametersQueryQuery = { __typename?: 'Query', networkParameters?: Array<{ __typename?: 'NetworkParameter', key: string, value: string }> | null }; - - -export const NetworkParametersQueryDocument = gql` - query NetworkParametersQuery { - networkParameters { - key - value - } -} - `; - -/** - * __useNetworkParametersQueryQuery__ - * - * To run a query within a React component, call `useNetworkParametersQueryQuery` and pass it any options that fit your needs. - * When your component renders, `useNetworkParametersQueryQuery` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useNetworkParametersQueryQuery({ - * variables: { - * }, - * }); - */ -export function useNetworkParametersQueryQuery(baseOptions?: Apollo.QueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useQuery(NetworkParametersQueryDocument, options); - } -export function useNetworkParametersQueryLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useLazyQuery(NetworkParametersQueryDocument, options); - } -export type NetworkParametersQueryQueryHookResult = ReturnType; -export type NetworkParametersQueryLazyQueryHookResult = ReturnType; -export type NetworkParametersQueryQueryResult = Apollo.QueryResult; \ No newline at end of file diff --git a/apps/explorer/src/app/routes/network-parameters/network-parameters.spec.tsx b/apps/explorer/src/app/routes/network-parameters/network-parameters.spec.tsx index db966e9dc..67176d0a4 100644 --- a/apps/explorer/src/app/routes/network-parameters/network-parameters.spec.tsx +++ b/apps/explorer/src/app/routes/network-parameters/network-parameters.spec.tsx @@ -1,22 +1,28 @@ import { render, screen } from '@testing-library/react'; +import type { NetworkParamsQuery } from '@vegaprotocol/react-helpers'; import { NetworkParametersTable } from './network-parameters'; -import type { NetworkParametersQuery } from './__generated__/NetworkParametersQuery'; describe('NetworkParametersTable', () => { it('renders correctly when it has network params', () => { - const data: NetworkParametersQuery = { - networkParameters: [ - { - __typename: 'NetworkParameter', - key: 'market.liquidityProvision.minLpStakeQuantumMultiple', - value: '1', - }, - { - __typename: 'NetworkParameter', - key: 'market.fee.factors.infrastructureFee', - value: '0.0005', - }, - ], + const data: NetworkParamsQuery = { + networkParametersConnection: { + edges: [ + { + node: { + __typename: 'NetworkParameter', + key: 'market.liquidityProvision.minLpStakeQuantumMultiple', + value: '1', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'market.fee.factors.infrastructureFee', + value: '0.0005', + }, + }, + ], + }, }; render(); expect(screen.getByTestId('network-param-header')).toHaveTextContent( @@ -34,19 +40,25 @@ describe('NetworkParametersTable', () => { }); it('renders the rows in ascending order', () => { - const data: NetworkParametersQuery = { - networkParameters: [ - { - __typename: 'NetworkParameter', - key: 'market.fee.factors.infrastructureFee', - value: '0.0005', - }, - { - __typename: 'NetworkParameter', - key: 'market.liquidityProvision.minLpStakeQuantumMultiple', - value: '1', - }, - ], + const data: NetworkParamsQuery = { + networkParametersConnection: { + edges: [ + { + node: { + __typename: 'NetworkParameter', + key: 'market.fee.factors.infrastructureFee', + value: '0.0005', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'market.liquidityProvision.minLpStakeQuantumMultiple', + value: '1', + }, + }, + ], + }, }; render(); expect(screen.getByTestId('network-param-header')).toHaveTextContent( diff --git a/apps/explorer/src/app/routes/network-parameters/network-parameters.tsx b/apps/explorer/src/app/routes/network-parameters/network-parameters.tsx index 10240cfcd..d02931a3f 100644 --- a/apps/explorer/src/app/routes/network-parameters/network-parameters.tsx +++ b/apps/explorer/src/app/routes/network-parameters/network-parameters.tsx @@ -1,4 +1,3 @@ -import { gql, useQuery } from '@apollo/client'; import { AsyncRenderer, KeyValueTable, @@ -12,11 +11,10 @@ import { } from '@vegaprotocol/react-helpers'; import { suitableForSyntaxHighlighter } from '@vegaprotocol/react-helpers'; import { RouteTitle } from '../../components/route-title'; -import type { - NetworkParametersQuery, - NetworkParametersQuery_networkParameters, -} from './__generated__/NetworkParametersQuery'; import orderBy from 'lodash/orderBy'; +import type { NetworkParamsQuery } from '@vegaprotocol/react-helpers'; +import { useNetworkParamsQuery } from '@vegaprotocol/react-helpers'; +import compact from 'lodash/compact'; const PERCENTAGE_PARAMS = [ 'governance.proposal.asset.requiredMajority', @@ -57,7 +55,7 @@ const BIG_NUMBER_PARAMS = [ export const NetworkParameterRow = ({ row: { key, value }, }: { - row: NetworkParametersQuery_networkParameters; + row: { key: string; value: string }; }) => { const isSyntaxRow = suitableForSyntaxHighlighter(value); @@ -86,18 +84,9 @@ export const NetworkParameterRow = ({ ); }; -export const NETWORK_PARAMETERS_QUERY = gql` - query NetworkParametersQuery { - networkParameters { - key - value - } - } -`; - export interface NetworkParametersTableProps extends React.HTMLAttributes { - data?: NetworkParametersQuery; + data?: NetworkParamsQuery | undefined; error?: Error; loading: boolean; } @@ -118,7 +107,9 @@ export const NetworkParametersTable = ({ error={error} render={(data) => { const ascParams = orderBy( - data.networkParameters || [], + compact(data.networkParametersConnection.edges).map( + ({ node }) => node + ) || [], (param) => param.key, 'asc' ); @@ -135,8 +126,6 @@ export const NetworkParametersTable = ({ ); export const NetworkParameters = () => { - const { data, loading, error } = useQuery( - NETWORK_PARAMETERS_QUERY - ); + const { data, loading, error } = useNetworkParamsQuery(); return ; }; diff --git a/apps/token/src/hooks/NetworkParams.graphql b/apps/token/src/hooks/NetworkParams.graphql deleted file mode 100644 index fade0b2ce..000000000 --- a/apps/token/src/hooks/NetworkParams.graphql +++ /dev/null @@ -1,6 +0,0 @@ -query NetworkParams { - networkParameters { - key - value - } -} diff --git a/apps/token/src/hooks/__generated__/NetworkParams.ts b/apps/token/src/hooks/__generated__/NetworkParams.ts deleted file mode 100644 index 493e5eaf1..000000000 --- a/apps/token/src/hooks/__generated__/NetworkParams.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -// @generated -// This file was automatically generated and should not be edited. - -// ==================================================== -// GraphQL query operation: NetworkParams -// ==================================================== - -export interface NetworkParams_networkParameters { - __typename: "NetworkParameter"; - /** - * The name of the network parameter - */ - key: string; - /** - * The value of the network parameter - */ - value: string; -} - -export interface NetworkParams { - /** - * return the full list of network parameters - */ - networkParameters: NetworkParams_networkParameters[] | null; -} diff --git a/apps/token/src/hooks/__generated___/NetworkParams.ts b/apps/token/src/hooks/__generated___/NetworkParams.ts deleted file mode 100644 index d63723105..000000000 --- a/apps/token/src/hooks/__generated___/NetworkParams.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Schema as Types } from '@vegaprotocol/types'; - -import { gql } from '@apollo/client'; -import * as Apollo from '@apollo/client'; -const defaultOptions = {} as const; -export type NetworkParamsQueryVariables = Types.Exact<{ [key: string]: never; }>; - - -export type NetworkParamsQuery = { __typename?: 'Query', networkParameters?: Array<{ __typename?: 'NetworkParameter', key: string, value: string }> | null }; - - -export const NetworkParamsDocument = gql` - query NetworkParams { - networkParameters { - key - value - } -} - `; - -/** - * __useNetworkParamsQuery__ - * - * To run a query within a React component, call `useNetworkParamsQuery` and pass it any options that fit your needs. - * When your component renders, `useNetworkParamsQuery` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useNetworkParamsQuery({ - * variables: { - * }, - * }); - */ -export function useNetworkParamsQuery(baseOptions?: Apollo.QueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useQuery(NetworkParamsDocument, options); - } -export function useNetworkParamsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useLazyQuery(NetworkParamsDocument, options); - } -export type NetworkParamsQueryHookResult = ReturnType; -export type NetworkParamsLazyQueryHookResult = ReturnType; -export type NetworkParamsQueryResult = Apollo.QueryResult; \ No newline at end of file diff --git a/apps/token/src/routes/governance/components/current-proposal-status/current-proposal-status.spec.tsx b/apps/token/src/routes/governance/components/current-proposal-status/current-proposal-status.spec.tsx index e0a628173..e9f09e60a 100644 --- a/apps/token/src/routes/governance/components/current-proposal-status/current-proposal-status.spec.tsx +++ b/apps/token/src/routes/governance/components/current-proposal-status/current-proposal-status.spec.tsx @@ -1,9 +1,9 @@ import type { MockedResponse } from '@apollo/client/testing'; import { MockedProvider } from '@apollo/client/testing'; import { render, screen } from '@testing-library/react'; -import { NETWORK_PARAMETERS_QUERY } from '@vegaprotocol/react-helpers'; import { ProposalRejectionReason, ProposalState } from '@vegaprotocol/types'; -import type { NetworkParamsQuery } from '@vegaprotocol/web3'; +import type { NetworkParamsQuery } from '@vegaprotocol/react-helpers'; +import { NetworkParamsDocument } from '@vegaprotocol/react-helpers'; import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider'; import { generateProposal } from '../../test-helpers/generate-proposals'; import { CurrentProposalStatus } from './current-proposal-status'; @@ -11,22 +11,28 @@ import type { Proposal_proposal } from '../../proposal/__generated__/Proposal'; const networkParamsQueryMock: MockedResponse = { request: { - query: NETWORK_PARAMETERS_QUERY, + query: NetworkParamsDocument, }, result: { data: { - networkParameters: [ - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateNetParam.requiredMajority', - value: '0.00000001', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateNetParam.requiredParticipation', - value: '0.000000001', - }, - ], + networkParametersConnection: { + edges: [ + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateNetParam.requiredMajority', + value: '0.00000001', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateNetParam.requiredParticipation', + value: '0.000000001', + }, + }, + ], + }, }, }, }; diff --git a/apps/token/src/routes/governance/propose/freeform/propose-freeform.spec.tsx b/apps/token/src/routes/governance/propose/freeform/propose-freeform.spec.tsx index 4bf639d83..a8164e26d 100644 --- a/apps/token/src/routes/governance/propose/freeform/propose-freeform.spec.tsx +++ b/apps/token/src/routes/governance/propose/freeform/propose-freeform.spec.tsx @@ -5,9 +5,9 @@ import { mockWalletContext } from '../../test-helpers/mocks'; import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider'; import { VegaWalletContext } from '@vegaprotocol/wallet'; import { MemoryRouter as Router } from 'react-router-dom'; -import type { NetworkParamsQuery } from '@vegaprotocol/web3'; +import type { NetworkParamsQuery } from '@vegaprotocol/react-helpers'; import type { MockedResponse } from '@apollo/client/testing'; -import { NETWORK_PARAMETERS_QUERY } from '@vegaprotocol/react-helpers'; +import { NetworkParamsDocument } from '@vegaprotocol/react-helpers'; jest.mock('@vegaprotocol/environment', () => ({ useEnvironment: () => ({ @@ -17,42 +17,56 @@ jest.mock('@vegaprotocol/environment', () => ({ const updateMarketNetworkParamsQueryMock: MockedResponse = { request: { - query: NETWORK_PARAMETERS_QUERY, + query: NetworkParamsDocument, }, result: { data: { - networkParameters: [ - { - __typename: 'NetworkParameter', - key: 'governance.proposal.freeform.maxClose', - value: '8760h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.freeform.maxEnact', - value: '8760h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.freeform.minClose', - value: '1h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.freeform.minEnact', - value: '2h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.freeform.minProposerBalance', - value: '1', - }, - { - __typename: 'NetworkParameter', - key: 'spam.protection.proposal.min.tokens', - value: '1000000000000000000', - }, - ], + networkParametersConnection: { + edges: [ + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.freeform.maxClose', + value: '8760h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.freeform.maxEnact', + value: '8760h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.freeform.minClose', + value: '1h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.freeform.minEnact', + value: '2h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.freeform.minProposerBalance', + value: '1', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'spam.protection.proposal.min.tokens', + value: '1000000000000000000', + }, + }, + ], + }, }, }, }; diff --git a/apps/token/src/routes/governance/propose/network-parameter/propose-network-parameter.spec.tsx b/apps/token/src/routes/governance/propose/network-parameter/propose-network-parameter.spec.tsx index 146466482..59699b104 100644 --- a/apps/token/src/routes/governance/propose/network-parameter/propose-network-parameter.spec.tsx +++ b/apps/token/src/routes/governance/propose/network-parameter/propose-network-parameter.spec.tsx @@ -5,9 +5,9 @@ import { mockWalletContext } from '../../test-helpers/mocks'; import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider'; import { VegaWalletContext } from '@vegaprotocol/wallet'; import { MemoryRouter as Router } from 'react-router-dom'; -import type { NetworkParamsQuery } from '@vegaprotocol/web3'; +import type { NetworkParamsQuery } from '@vegaprotocol/react-helpers'; +import { NetworkParamsDocument } from '@vegaprotocol/react-helpers'; import type { MockedResponse } from '@apollo/client/testing'; -import { NETWORK_PARAMETERS_QUERY } from '@vegaprotocol/react-helpers'; jest.mock('@vegaprotocol/environment', () => ({ useEnvironment: () => ({ @@ -17,42 +17,56 @@ jest.mock('@vegaprotocol/environment', () => ({ const updateMarketNetworkParamsQueryMock: MockedResponse = { request: { - query: NETWORK_PARAMETERS_QUERY, + query: NetworkParamsDocument, }, result: { data: { - networkParameters: [ - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateNetParam.maxClose', - value: '8760h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateNetParam.maxEnact', - value: '8760h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateNetParam.minClose', - value: '1h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateNetParam.minEnact', - value: '2h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateNetParam.minProposerBalance', - value: '1', - }, - { - __typename: 'NetworkParameter', - key: 'spam.protection.proposal.min.tokens', - value: '1000000000000000000', - }, - ], + networkParametersConnection: { + edges: [ + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateNetParam.maxClose', + value: '8760h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateNetParam.maxEnact', + value: '8760h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateNetParam.minClose', + value: '1h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateNetParam.minEnact', + value: '2h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateNetParam.minProposerBalance', + value: '1', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'spam.protection.proposal.min.tokens', + value: '1000000000000000000', + }, + }, + ], + }, }, }, }; diff --git a/apps/token/src/routes/governance/propose/new-asset/propose-new-asset.spec.tsx b/apps/token/src/routes/governance/propose/new-asset/propose-new-asset.spec.tsx index cc72ab409..fa7ac1924 100644 --- a/apps/token/src/routes/governance/propose/new-asset/propose-new-asset.spec.tsx +++ b/apps/token/src/routes/governance/propose/new-asset/propose-new-asset.spec.tsx @@ -5,9 +5,9 @@ import { VegaWalletContext } from '@vegaprotocol/wallet'; import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider'; import { mockWalletContext } from '../../test-helpers/mocks'; import { ProposeNewAsset } from './propose-new-asset'; -import type { NetworkParamsQuery } from '@vegaprotocol/web3'; +import type { NetworkParamsQuery } from '@vegaprotocol/react-helpers'; import type { MockedResponse } from '@apollo/client/testing'; -import { NETWORK_PARAMETERS_QUERY } from '@vegaprotocol/react-helpers'; +import { NetworkParamsDocument } from '@vegaprotocol/react-helpers'; jest.mock('@vegaprotocol/environment', () => ({ useEnvironment: () => ({ @@ -17,42 +17,56 @@ jest.mock('@vegaprotocol/environment', () => ({ const newAssetNetworkParamsQueryMock: MockedResponse = { request: { - query: NETWORK_PARAMETERS_QUERY, + query: NetworkParamsDocument, }, result: { data: { - networkParameters: [ - { - __typename: 'NetworkParameter', - key: 'governance.proposal.asset.maxClose', - value: '8760h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.asset.maxEnact', - value: '8760h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.asset.minClose', - value: '1h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.asset.minEnact', - value: '2h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.asset.minProposerBalance', - value: '1', - }, - { - __typename: 'NetworkParameter', - key: 'spam.protection.proposal.min.tokens', - value: '1000000000000000000', - }, - ], + networkParametersConnection: { + edges: [ + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.asset.maxClose', + value: '8760h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.asset.maxEnact', + value: '8760h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.asset.minClose', + value: '1h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.asset.minEnact', + value: '2h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.asset.minProposerBalance', + value: '1', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'spam.protection.proposal.min.tokens', + value: '1000000000000000000', + }, + }, + ], + }, }, }, }; diff --git a/apps/token/src/routes/governance/propose/new-market/propose-new-market.spec.tsx b/apps/token/src/routes/governance/propose/new-market/propose-new-market.spec.tsx index 01a4681c5..3477a6baf 100644 --- a/apps/token/src/routes/governance/propose/new-market/propose-new-market.spec.tsx +++ b/apps/token/src/routes/governance/propose/new-market/propose-new-market.spec.tsx @@ -6,8 +6,8 @@ import { AppStateProvider } from '../../../../contexts/app-state/app-state-provi import { VegaWalletContext } from '@vegaprotocol/wallet'; import { BrowserRouter as Router } from 'react-router-dom'; import type { MockedResponse } from '@apollo/client/testing'; -import type { NetworkParamsQuery } from '@vegaprotocol/web3'; -import { NETWORK_PARAMETERS_QUERY } from '@vegaprotocol/react-helpers'; +import type { NetworkParamsQuery } from '@vegaprotocol/react-helpers'; +import { NetworkParamsDocument } from '@vegaprotocol/react-helpers'; jest.mock('@vegaprotocol/environment', () => ({ useEnvironment: () => ({ @@ -17,42 +17,56 @@ jest.mock('@vegaprotocol/environment', () => ({ const newMarketNetworkParamsQueryMock: MockedResponse = { request: { - query: NETWORK_PARAMETERS_QUERY, + query: NetworkParamsDocument, }, result: { data: { - networkParameters: [ - { - __typename: 'NetworkParameter', - key: 'governance.proposal.market.maxClose', - value: '8760h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.market.maxEnact', - value: '8760h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.market.minClose', - value: '1h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.market.minEnact', - value: '2h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.market.minProposerBalance', - value: '1', - }, - { - __typename: 'NetworkParameter', - key: 'spam.protection.proposal.min.tokens', - value: '1000000000000000000', - }, - ], + networkParametersConnection: { + edges: [ + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.market.maxClose', + value: '8760h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.market.maxEnact', + value: '8760h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.market.minClose', + value: '1h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.market.minEnact', + value: '2h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.market.minProposerBalance', + value: '1', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'spam.protection.proposal.min.tokens', + value: '1000000000000000000', + }, + }, + ], + }, }, }, }; diff --git a/apps/token/src/routes/governance/propose/raw/proposal-raw.spec.tsx b/apps/token/src/routes/governance/propose/raw/proposal-raw.spec.tsx index 68f028cb9..1d6d88202 100644 --- a/apps/token/src/routes/governance/propose/raw/proposal-raw.spec.tsx +++ b/apps/token/src/routes/governance/propose/raw/proposal-raw.spec.tsx @@ -13,54 +13,71 @@ import { import { ProposeRaw } from './propose-raw'; import { ProposalEventDocument } from '@vegaprotocol/governance'; import type { ProposalEventSubscription } from '@vegaprotocol/governance'; -import { NETWORK_PARAMETERS_QUERY } from '@vegaprotocol/react-helpers'; -import type { NetworkParamsQuery } from '@vegaprotocol/web3'; + +import type { NetworkParamsQuery } from '@vegaprotocol/react-helpers'; +import { NetworkParamsDocument } from '@vegaprotocol/react-helpers'; const paramsDelay = 20; const rawProposalNetworkParamsQueryMock: MockedResponse = { request: { - query: NETWORK_PARAMETERS_QUERY, + query: NetworkParamsDocument, }, result: { data: { - networkParameters: [ - { - __typename: 'NetworkParameter', - key: 'governance.proposal.asset.minProposerBalance', - value: '1', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateAsset.minProposerBalance', - value: '1', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.market.minProposerBalance', - value: '1', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateMarket.minProposerBalance', - value: '1', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateNetParam.minProposerBalance', - value: '1', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.freeform.minProposerBalance', - value: '1', - }, - { - __typename: 'NetworkParameter', - key: 'spam.protection.proposal.min.tokens', - value: '1000000000000000000', - }, - ], + networkParametersConnection: { + edges: [ + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.asset.minProposerBalance', + value: '1', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateAsset.minProposerBalance', + value: '1', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.market.minProposerBalance', + value: '1', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateMarket.minProposerBalance', + value: '1', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateNetParam.minProposerBalance', + value: '1', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.freeform.minProposerBalance', + value: '1', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'spam.protection.proposal.min.tokens', + value: '1000000000000000000', + }, + }, + ], + }, }, }, delay: paramsDelay, diff --git a/apps/token/src/routes/governance/propose/update-asset/propose-update-asset.spec.tsx b/apps/token/src/routes/governance/propose/update-asset/propose-update-asset.spec.tsx index fd5e453e0..02399dae1 100644 --- a/apps/token/src/routes/governance/propose/update-asset/propose-update-asset.spec.tsx +++ b/apps/token/src/routes/governance/propose/update-asset/propose-update-asset.spec.tsx @@ -5,9 +5,9 @@ import { VegaWalletContext } from '@vegaprotocol/wallet'; import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider'; import { mockWalletContext } from '../../test-helpers/mocks'; import { ProposeUpdateAsset } from './propose-update-asset'; -import type { NetworkParamsQuery } from '@vegaprotocol/web3'; +import type { NetworkParamsQuery } from '@vegaprotocol/react-helpers'; import type { MockedResponse } from '@apollo/client/testing'; -import { NETWORK_PARAMETERS_QUERY } from '@vegaprotocol/react-helpers'; +import { NetworkParamsDocument } from '@vegaprotocol/react-helpers'; jest.mock('@vegaprotocol/environment', () => ({ useEnvironment: () => ({ @@ -17,42 +17,56 @@ jest.mock('@vegaprotocol/environment', () => ({ const updateAssetNetworkParamsQueryMock: MockedResponse = { request: { - query: NETWORK_PARAMETERS_QUERY, + query: NetworkParamsDocument, }, result: { data: { - networkParameters: [ - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateAsset.maxClose', - value: '8760h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateAsset.maxEnact', - value: '8760h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateAsset.minClose', - value: '1h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateAsset.minEnact', - value: '2h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateAsset.minProposerBalance', - value: '1', - }, - { - __typename: 'NetworkParameter', - key: 'spam.protection.proposal.min.tokens', - value: '1000000000000000000', - }, - ], + networkParametersConnection: { + edges: [ + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateAsset.maxClose', + value: '8760h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateAsset.maxEnact', + value: '8760h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateAsset.minClose', + value: '1h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateAsset.minEnact', + value: '2h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateAsset.minProposerBalance', + value: '1', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'spam.protection.proposal.min.tokens', + value: '1000000000000000000', + }, + }, + ], + }, }, }, }; diff --git a/apps/token/src/routes/governance/propose/update-market/propose-update-market.spec.tsx b/apps/token/src/routes/governance/propose/update-market/propose-update-market.spec.tsx index ab88929a6..07089a635 100644 --- a/apps/token/src/routes/governance/propose/update-market/propose-update-market.spec.tsx +++ b/apps/token/src/routes/governance/propose/update-market/propose-update-market.spec.tsx @@ -6,49 +6,63 @@ import { VegaWalletContext } from '@vegaprotocol/wallet'; import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider'; import { mockWalletContext } from '../../test-helpers/mocks'; import { ProposeUpdateMarket } from './propose-update-market'; -import type { NetworkParamsQuery } from '@vegaprotocol/web3'; +import type { NetworkParamsQuery } from '@vegaprotocol/react-helpers'; import { MARKETS_QUERY } from './propose-update-market'; import type { ProposalMarketsQuery } from './__generated__/ProposalMarketsQuery'; -import { NETWORK_PARAMETERS_QUERY } from '@vegaprotocol/react-helpers'; +import { NetworkParamsDocument } from '@vegaprotocol/react-helpers'; const updateMarketNetworkParamsQueryMock: MockedResponse = { request: { - query: NETWORK_PARAMETERS_QUERY, + query: NetworkParamsDocument, }, result: { data: { - networkParameters: [ - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateMarket.maxClose', - value: '8760h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateMarket.maxEnact', - value: '8760h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateMarket.minClose', - value: '1h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateMarket.minEnact', - value: '2h0m0s', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateMarket.minProposerBalance', - value: '1', - }, - { - __typename: 'NetworkParameter', - key: 'spam.protection.proposal.min.tokens', - value: '1000000000000000000', - }, - ], + networkParametersConnection: { + edges: [ + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateMarket.maxClose', + value: '8760h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateMarket.maxEnact', + value: '8760h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateMarket.minClose', + value: '1h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateMarket.minEnact', + value: '2h0m0s', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateMarket.minProposerBalance', + value: '1', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'spam.protection.proposal.min.tokens', + value: '1000000000000000000', + }, + }, + ], + }, }, }, }; diff --git a/apps/token/src/routes/governance/test-helpers/mocks.ts b/apps/token/src/routes/governance/test-helpers/mocks.ts index c15c51e8c..0743799ea 100644 --- a/apps/token/src/routes/governance/test-helpers/mocks.ts +++ b/apps/token/src/routes/governance/test-helpers/mocks.ts @@ -1,6 +1,6 @@ -import { NETWORK_PARAMS_QUERY } from '@vegaprotocol/web3'; +import { NetworkParamsDocument } from '@vegaprotocol/react-helpers'; import type { MockedResponse } from '@apollo/client/testing'; -import type { NetworkParamsQuery } from '@vegaprotocol/web3'; +import type { NetworkParamsQuery } from '@vegaprotocol/react-helpers'; import type { PubKey } from '@vegaprotocol/wallet'; export const mockPubkey: PubKey = { @@ -29,17 +29,21 @@ const mockEthereumConfig = { export const networkParamsQueryMock: MockedResponse = { request: { - query: NETWORK_PARAMS_QUERY, + query: NetworkParamsDocument, }, result: { data: { - networkParameters: [ - { - __typename: 'NetworkParameter', - key: 'blockchains.ethereumConfig', - value: JSON.stringify(mockEthereumConfig), - }, - ], + networkParametersConnection: { + edges: [ + { + node: { + __typename: 'NetworkParameter', + key: 'blockchains.ethereumConfig', + value: JSON.stringify(mockEthereumConfig), + }, + }, + ], + }, }, }, }; diff --git a/apps/trading-e2e/src/integration/global.cy.ts b/apps/trading-e2e/src/integration/global.cy.ts index 74e72b251..896fd504f 100644 --- a/apps/trading-e2e/src/integration/global.cy.ts +++ b/apps/trading-e2e/src/integration/global.cy.ts @@ -81,7 +81,7 @@ describe('ethereum wallet', { tags: '@smoke' }, () => { // Using portfolio withdrawals tab is it requires Ethereum wallet connection cy.visit('/portfolio'); cy.mockGQL((req) => { - aliasQuery(req, 'NetworkParamsQuery', generateNetworkParameters()); + aliasQuery(req, 'NetworkParams', generateNetworkParameters()); }); cy.mockGQLSubscription(); cy.get('main[data-testid="portfolio"]').should('exist'); @@ -89,7 +89,7 @@ describe('ethereum wallet', { tags: '@smoke' }, () => { }); it('can connect', () => { - cy.wait('@NetworkParamsQuery'); + cy.wait('@NetworkParams'); cy.getByTestId('connect-eth-wallet-btn').click(); cy.getByTestId('web3-connector-list').should('exist'); cy.getByTestId('web3-connector-MetaMask').click(); diff --git a/apps/trading-e2e/src/support/mocks/generate-network-parameters.ts b/apps/trading-e2e/src/support/mocks/generate-network-parameters.ts index 4ca302030..e8eda477e 100644 --- a/apps/trading-e2e/src/support/mocks/generate-network-parameters.ts +++ b/apps/trading-e2e/src/support/mocks/generate-network-parameters.ts @@ -1,37 +1,41 @@ import merge from 'lodash/merge'; -import type { NetworkParamsQuery } from '@vegaprotocol/web3'; +import type { NetworkParamsQuery } from '@vegaprotocol/react-helpers'; import type { PartialDeep } from 'type-fest'; export const generateNetworkParameters = ( override?: PartialDeep ): NetworkParamsQuery => { const defaultResult: NetworkParamsQuery = { - networkParameters: [ - { - __typename: 'NetworkParameter', - key: 'blockchains.ethereumConfig', - value: JSON.stringify({ - network_id: '3', - chain_id: '3', - collateral_bridge_contract: { - address: '0x7fe27d970bc8Afc3B11Cc8d9737bfB66B1efd799', + networkParametersConnection: { + edges: [ + { + node: { + __typename: 'NetworkParameter', + key: 'blockchains.ethereumConfig', + value: JSON.stringify({ + network_id: '3', + chain_id: '3', + collateral_bridge_contract: { + address: '0x7fe27d970bc8Afc3B11Cc8d9737bfB66B1efd799', + }, + multisig_control_contract: { + address: '0x6eBc32d66277D94DB8FF2ccF86E36f37F29a52D3', + deployment_block_height: 12341882, + }, + staking_bridge_contract: { + address: '0xFFb0A0d4806502ceF491aF1141f66669A1Bd0D03', + deployment_block_height: 11177313, + }, + token_vesting_contract: { + address: '0x680fF88252FA7071CAce7398e77872d54D781d0B', + deployment_block_height: 11177353, + }, + confirmations: 3, + }), }, - multisig_control_contract: { - address: '0x6eBc32d66277D94DB8FF2ccF86E36f37F29a52D3', - deployment_block_height: 12341882, - }, - staking_bridge_contract: { - address: '0xFFb0A0d4806502ceF491aF1141f66669A1Bd0D03', - deployment_block_height: 11177313, - }, - token_vesting_contract: { - address: '0x680fF88252FA7071CAce7398e77872d54D781d0B', - deployment_block_height: 11177353, - }, - confirmations: 3, - }), - }, - ], + }, + ], + }, }; return merge(defaultResult, override); }; diff --git a/apps/trading-e2e/src/support/trading.ts b/apps/trading-e2e/src/support/trading.ts index cc69b1e42..1d8647ea5 100644 --- a/apps/trading-e2e/src/support/trading.ts +++ b/apps/trading-e2e/src/support/trading.ts @@ -101,7 +101,7 @@ const mockTradingPage = ( aliasQuery(req, 'Chart', generateChart()); aliasQuery(req, 'Candles', generateCandles()); aliasQuery(req, 'Withdrawals', generateWithdrawals()); - aliasQuery(req, 'NetworkParamsQuery', generateNetworkParameters()); + aliasQuery(req, 'NetworkParams', generateNetworkParameters()); aliasQuery(req, 'EstimateOrder', generateEstimateOrder()); aliasQuery(req, 'MarketMarkPrice', generateMarkPrice()); aliasQuery(req, 'PartyBalance', generatePartyBalance()); diff --git a/libs/cypress/src/lib/commands/get-network-parameters.ts b/libs/cypress/src/lib/commands/get-network-parameters.ts index 108bfaee0..3fd91f8da 100644 --- a/libs/cypress/src/lib/commands/get-network-parameters.ts +++ b/libs/cypress/src/lib/commands/get-network-parameters.ts @@ -11,7 +11,17 @@ declare global { export function addGetNetworkParameters() { // @ts-ignore - ignoring Cypress type error which gets resolved when Cypress uses the command Cypress.Commands.add('get_network_parameters', () => { - const mutation = '{networkParameters {key value}}'; + const mutation = ` + { + networkParametersConnection { + edges { + node { + key + value + } + } + } + }`; cy.request({ method: 'POST', url: `http://localhost:3028/query`, @@ -20,11 +30,12 @@ export function addGetNetworkParameters() { }, headers: { 'content-type': 'application/json' }, }) - .its('body.data.networkParameters') + .its('body.data.networkParametersConnection.edges') .then(function (response) { // @ts-ignore - ignoring Cypress type error which gets resolved when Cypress uses the command const object = response.reduce(function (r, e) { - r[e.key] = e.value; + const { value, key } = e.node; + r[key] = value; return r; }, {}); return object; diff --git a/libs/liquidity/src/lib/liquidity-table.tsx b/libs/liquidity/src/lib/liquidity-table.tsx index 21e2716a1..d30db5c1c 100644 --- a/libs/liquidity/src/lib/liquidity-table.tsx +++ b/libs/liquidity/src/lib/liquidity-table.tsx @@ -33,7 +33,7 @@ export interface LiquidityTableProps { data?: LiquidityProvisionData[]; symbol?: string; assetDecimalPlaces?: number; - stakeToCcySiskas: string; + stakeToCcySiskas: string | null; } export const LiquidityTable = forwardRef( diff --git a/libs/react-helpers/src/hooks/NetworkParams.graphql b/libs/react-helpers/src/hooks/NetworkParams.graphql new file mode 100644 index 000000000..b37016a0f --- /dev/null +++ b/libs/react-helpers/src/hooks/NetworkParams.graphql @@ -0,0 +1,17 @@ +query NetworkParams { + networkParametersConnection { + edges { + node { + key + value + } + } + } +} + +query NetworkParam($key: String!) { + networkParameter(key: $key) { + key + value + } +} diff --git a/libs/react-helpers/src/hooks/__generated__/NetworkParam.ts b/libs/react-helpers/src/hooks/__generated__/NetworkParam.ts deleted file mode 100644 index 1e4ef5b88..000000000 --- a/libs/react-helpers/src/hooks/__generated__/NetworkParam.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -// @generated -// This file was automatically generated and should not be edited. - -// ==================================================== -// GraphQL query operation: NetworkParam -// ==================================================== - -export interface NetworkParam_networkParameter { - __typename: "NetworkParameter"; - /** - * The name of the network parameter - */ - key: string; - /** - * The value of the network parameter - */ - value: string; -} - -export interface NetworkParam { - /** - * Return a single network parameter - */ - networkParameter: NetworkParam_networkParameter | null; -} - -export interface NetworkParamVariables { - key: string; -} diff --git a/libs/react-helpers/src/hooks/__generated__/NetworkParams.ts b/libs/react-helpers/src/hooks/__generated__/NetworkParams.ts deleted file mode 100644 index 2ba906c75..000000000 --- a/libs/react-helpers/src/hooks/__generated__/NetworkParams.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -// @generated -// This file was automatically generated and should not be edited. - -// ==================================================== -// GraphQL query operation: NetworkParams -// ==================================================== - -export interface NetworkParams_networkParameters { - __typename: "NetworkParameter"; - /** - * The name of the network parameter - */ - key: string; - /** - * The value of the network parameter - */ - value: string; -} - -export interface NetworkParams { - /** - * Return the full list of network parameters - */ - networkParameters: NetworkParams_networkParameters[] | null; -} diff --git a/libs/react-helpers/src/hooks/__generated___/NetworkParams.ts b/libs/react-helpers/src/hooks/__generated___/NetworkParams.ts new file mode 100644 index 000000000..30a15c3fa --- /dev/null +++ b/libs/react-helpers/src/hooks/__generated___/NetworkParams.ts @@ -0,0 +1,93 @@ +import { Schema as Types } from '@vegaprotocol/types'; + +import { gql } from '@apollo/client'; +import * as Apollo from '@apollo/client'; +const defaultOptions = {} as const; +export type NetworkParamsQueryVariables = Types.Exact<{ [key: string]: never; }>; + + +export type NetworkParamsQuery = { __typename?: 'Query', networkParametersConnection: { __typename?: 'NetworkParametersConnection', edges?: Array<{ __typename?: 'NetworkParameterEdge', node: { __typename?: 'NetworkParameter', key: string, value: string } } | null> | null } }; + +export type NetworkParamQueryVariables = Types.Exact<{ + key: Types.Scalars['String']; +}>; + + +export type NetworkParamQuery = { __typename?: 'Query', networkParameter?: { __typename?: 'NetworkParameter', key: string, value: string } | null }; + + +export const NetworkParamsDocument = gql` + query NetworkParams { + networkParametersConnection { + edges { + node { + key + value + } + } + } +} + `; + +/** + * __useNetworkParamsQuery__ + * + * To run a query within a React component, call `useNetworkParamsQuery` and pass it any options that fit your needs. + * When your component renders, `useNetworkParamsQuery` returns an object from Apollo Client that contains loading, error, and data properties + * you can use to render your UI. + * + * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; + * + * @example + * const { data, loading, error } = useNetworkParamsQuery({ + * variables: { + * }, + * }); + */ +export function useNetworkParamsQuery(baseOptions?: Apollo.QueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useQuery(NetworkParamsDocument, options); + } +export function useNetworkParamsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useLazyQuery(NetworkParamsDocument, options); + } +export type NetworkParamsQueryHookResult = ReturnType; +export type NetworkParamsLazyQueryHookResult = ReturnType; +export type NetworkParamsQueryResult = Apollo.QueryResult; +export const NetworkParamDocument = gql` + query NetworkParam($key: String!) { + networkParameter(key: $key) { + key + value + } +} + `; + +/** + * __useNetworkParamQuery__ + * + * To run a query within a React component, call `useNetworkParamQuery` and pass it any options that fit your needs. + * When your component renders, `useNetworkParamQuery` returns an object from Apollo Client that contains loading, error, and data properties + * you can use to render your UI. + * + * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; + * + * @example + * const { data, loading, error } = useNetworkParamQuery({ + * variables: { + * key: // value for 'key' + * }, + * }); + */ +export function useNetworkParamQuery(baseOptions: Apollo.QueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useQuery(NetworkParamDocument, options); + } +export function useNetworkParamLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useLazyQuery(NetworkParamDocument, options); + } +export type NetworkParamQueryHookResult = ReturnType; +export type NetworkParamLazyQueryHookResult = ReturnType; +export type NetworkParamQueryResult = Apollo.QueryResult; \ No newline at end of file diff --git a/libs/react-helpers/src/hooks/index.ts b/libs/react-helpers/src/hooks/index.ts index a18ccef85..8d9d134ce 100644 --- a/libs/react-helpers/src/hooks/index.ts +++ b/libs/react-helpers/src/hooks/index.ts @@ -1,4 +1,4 @@ -export * from './__generated__/NetworkParam'; +export * from './__generated___/NetworkParams'; export * from './use-apply-grid-transaction'; export * from './use-data-provider'; export * from './use-fetch'; diff --git a/libs/react-helpers/src/hooks/use-network-params.spec.tsx b/libs/react-helpers/src/hooks/use-network-params.spec.tsx index 8fce6ebd4..2ef22bd66 100644 --- a/libs/react-helpers/src/hooks/use-network-params.spec.tsx +++ b/libs/react-helpers/src/hooks/use-network-params.spec.tsx @@ -4,19 +4,19 @@ import { MockedProvider } from '@apollo/client/testing'; import type { NetworkParamsKey } from './use-network-params'; import { NetworkParams, - NETWORK_PARAMETERS_QUERY, - NETWORK_PARAMETER_QUERY, useNetworkParam, useNetworkParams, } from './use-network-params'; import type { ReactNode } from 'react'; -import type { NetworkParams as NetworkParamsResponse } from './__generated__/NetworkParams'; +import type { NetworkParamsQuery } from './__generated___/NetworkParams'; +import { NetworkParamDocument } from './__generated___/NetworkParams'; +import { NetworkParamsDocument } from './__generated___/NetworkParams'; describe('useNetworkParam', () => { const setup = (arg: NetworkParamsKey) => { const mock: MockedResponse = { request: { - query: NETWORK_PARAMETER_QUERY, + query: NetworkParamDocument, variables: { key: arg, }, @@ -51,29 +51,37 @@ describe('useNetworkParam', () => { describe('useNetworkParams', () => { const setup = (args?: NetworkParamsKey[]) => { - const mock: MockedResponse = { + const mock: MockedResponse = { request: { - query: NETWORK_PARAMETERS_QUERY, + query: NetworkParamsDocument, }, result: { data: { - networkParameters: [ - { - __typename: 'NetworkParameter', - key: 'spam.protection.proposal.min.tokens', - value: '1', - }, - { - __typename: 'NetworkParameter', - key: 'governance.proposal.updateMarket.minProposerBalance', - value: '2', - }, - { - __typename: 'NetworkParameter', - key: 'reward.staking.delegation.payoutDelay', - value: '200', - }, - ], + networkParametersConnection: { + edges: [ + { + node: { + __typename: 'NetworkParameter', + key: 'spam.protection.proposal.min.tokens', + value: '1', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'governance.proposal.updateMarket.minProposerBalance', + value: '2', + }, + }, + { + node: { + __typename: 'NetworkParameter', + key: 'reward.staking.delegation.payoutDelay', + value: '200', + }, + }, + ], + }, }, }, }; diff --git a/libs/react-helpers/src/hooks/use-network-params.ts b/libs/react-helpers/src/hooks/use-network-params.ts index ba74c14a1..731eba089 100644 --- a/libs/react-helpers/src/hooks/use-network-params.ts +++ b/libs/react-helpers/src/hooks/use-network-params.ts @@ -1,24 +1,9 @@ -import { gql, useQuery } from '@apollo/client'; +import compact from 'lodash/compact'; import { useMemo } from 'react'; -import type { NetworkParams as NetworkParamsResponse } from './__generated__/NetworkParams'; - -export const NETWORK_PARAMETERS_QUERY = gql` - query NetworkParams { - networkParameters { - key - value - } - } -`; - -export const NETWORK_PARAMETER_QUERY = gql` - query NetworkParam($key: String!) { - networkParameter(key: $key) { - key - value - } - } -`; +import { + useNetworkParamQuery, + useNetworkParamsQuery, +} from './__generated___/NetworkParams'; export const NetworkParams = { blockchains_ethereumConfig: 'blockchains_ethereumConfig', @@ -126,16 +111,14 @@ type Result = { }; export const useNetworkParams = (params?: T) => { - const { data, loading, error } = useQuery( - NETWORK_PARAMETERS_QUERY - ); + const { data, loading, error } = useNetworkParamsQuery(); const paramsObj = useMemo(() => { - if (!data?.networkParameters) return null; - return data.networkParameters + if (!data?.networkParametersConnection.edges) return null; + return compact(data.networkParametersConnection.edges) .map((p) => ({ - ...p, - key: p.key.split('.').join('_'), + ...p.node, + key: p.node.key.split('.').join('_'), })) .filter((p) => { if (params === undefined || params.length === 0) return true; @@ -156,11 +139,12 @@ export const useNetworkParams = (params?: T) => { }; export const useNetworkParam = (param: NetworkParamsKey) => { - const { data, loading, error } = useQuery(NETWORK_PARAMETER_QUERY, { + const { data, loading, error } = useNetworkParamQuery({ variables: { key: param, }, }); + return { param: data?.networkParameter ? data.networkParameter.value : null, loading, diff --git a/libs/web3/src/index.ts b/libs/web3/src/index.ts index 80b2c4c21..041bf094c 100644 --- a/libs/web3/src/index.ts +++ b/libs/web3/src/index.ts @@ -1,5 +1,4 @@ export * from './lib/ethereum-error'; -export * from './lib/__generated__/NetworkParamsQuery'; export * from './lib/use-bridge-contract'; export * from './lib/use-token-contract'; export * from './lib/use-token-decimals'; diff --git a/libs/web3/src/lib/NetworkParams.graphql b/libs/web3/src/lib/NetworkParams.graphql deleted file mode 100644 index f21986e42..000000000 --- a/libs/web3/src/lib/NetworkParams.graphql +++ /dev/null @@ -1,6 +0,0 @@ -query NetworkParamsQuery { - networkParameters { - key - value - } -} diff --git a/libs/web3/src/lib/__generated__/NetworkParamsQuery.ts b/libs/web3/src/lib/__generated__/NetworkParamsQuery.ts deleted file mode 100644 index 0f1a3effc..000000000 --- a/libs/web3/src/lib/__generated__/NetworkParamsQuery.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -// @generated -// This file was automatically generated and should not be edited. - -// ==================================================== -// GraphQL query operation: NetworkParamsQuery -// ==================================================== - -export interface NetworkParamsQuery_networkParameters { - __typename: "NetworkParameter"; - /** - * The name of the network parameter - */ - key: string; - /** - * The value of the network parameter - */ - value: string; -} - -export interface NetworkParamsQuery { - /** - * Return the full list of network parameters - */ - networkParameters: NetworkParamsQuery_networkParameters[] | null; -} diff --git a/libs/web3/src/lib/__generated___/NetworkParams.ts b/libs/web3/src/lib/__generated___/NetworkParams.ts deleted file mode 100644 index bf9bbd4dd..000000000 --- a/libs/web3/src/lib/__generated___/NetworkParams.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Schema as Types } from '@vegaprotocol/types'; - -import { gql } from '@apollo/client'; -import * as Apollo from '@apollo/client'; -const defaultOptions = {} as const; -export type NetworkParamsQueryQueryVariables = Types.Exact<{ [key: string]: never; }>; - - -export type NetworkParamsQueryQuery = { __typename?: 'Query', networkParameters?: Array<{ __typename?: 'NetworkParameter', key: string, value: string }> | null }; - - -export const NetworkParamsQueryDocument = gql` - query NetworkParamsQuery { - networkParameters { - key - value - } -} - `; - -/** - * __useNetworkParamsQueryQuery__ - * - * To run a query within a React component, call `useNetworkParamsQueryQuery` and pass it any options that fit your needs. - * When your component renders, `useNetworkParamsQueryQuery` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useNetworkParamsQueryQuery({ - * variables: { - * }, - * }); - */ -export function useNetworkParamsQueryQuery(baseOptions?: Apollo.QueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useQuery(NetworkParamsQueryDocument, options); - } -export function useNetworkParamsQueryLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useLazyQuery(NetworkParamsQueryDocument, options); - } -export type NetworkParamsQueryQueryHookResult = ReturnType; -export type NetworkParamsQueryLazyQueryHookResult = ReturnType; -export type NetworkParamsQueryQueryResult = Apollo.QueryResult; \ No newline at end of file diff --git a/libs/web3/src/lib/use-ethereum-config.ts b/libs/web3/src/lib/use-ethereum-config.ts index af3603d0d..4f8597d79 100644 --- a/libs/web3/src/lib/use-ethereum-config.ts +++ b/libs/web3/src/lib/use-ethereum-config.ts @@ -1,6 +1,6 @@ -import { gql, useQuery } from '@apollo/client'; +import { useNetworkParamsQuery } from '@vegaprotocol/react-helpers'; +import compact from 'lodash/compact'; import { useMemo } from 'react'; -import type { NetworkParamsQuery } from './__generated__/NetworkParamsQuery'; export interface EthereumConfig { network_id: string; @@ -23,27 +23,17 @@ export interface EthereumConfig { }; } -export const NETWORK_PARAMS_QUERY = gql` - query NetworkParamsQuery { - networkParameters { - key - value - } - } -`; - export const useEthereumConfig = () => { - const { data, loading, error } = - useQuery(NETWORK_PARAMS_QUERY); + const { data, loading, error } = useNetworkParamsQuery(); const config = useMemo(() => { if (!data) { return null; } - const param = data.networkParameters?.find( - (np) => np.key === 'blockchains.ethereumConfig' - ); + const param = compact(data.networkParametersConnection.edges) + .map(({ node }) => node) + ?.find((node) => node.key === 'blockchains.ethereumConfig'); if (!param) { return null; diff --git a/libs/web3/src/lib/web3-container.spec.tsx b/libs/web3/src/lib/web3-container.spec.tsx index abb789429..d456b8461 100644 --- a/libs/web3/src/lib/web3-container.spec.tsx +++ b/libs/web3/src/lib/web3-container.spec.tsx @@ -3,8 +3,8 @@ import type { MockedResponse } from '@apollo/client/testing'; import { MockedProvider } from '@apollo/client/testing'; import { Web3Container } from './web3-container'; import type { useWeb3React } from '@web3-react/core'; -import type { NetworkParamsQuery } from './__generated__/NetworkParamsQuery'; -import { NETWORK_PARAMS_QUERY } from './use-ethereum-config'; +import type { NetworkParamsQuery } from '@vegaprotocol/react-helpers'; +import { NetworkParamsDocument } from '@vegaprotocol/react-helpers'; import { EnvironmentProvider } from '@vegaprotocol/environment'; const defaultHookValue = { @@ -26,17 +26,21 @@ const mockEthereumConfig = { const networkParamsQueryMock: MockedResponse = { request: { - query: NETWORK_PARAMS_QUERY, + query: NetworkParamsDocument, }, result: { data: { - networkParameters: [ - { - __typename: 'NetworkParameter', - key: 'blockchains.ethereumConfig', - value: JSON.stringify(mockEthereumConfig), - }, - ], + networkParametersConnection: { + edges: [ + { + node: { + __typename: 'NetworkParameter', + key: 'blockchains.ethereumConfig', + value: JSON.stringify(mockEthereumConfig), + }, + }, + ], + }, }, }, }; @@ -135,17 +139,21 @@ it('Passes ethereum config to children', async () => { it('Shows no config found message if the network parameter doesnt exist', async () => { const mock: MockedResponse = { request: { - query: NETWORK_PARAMS_QUERY, + query: NetworkParamsDocument, }, result: { data: { - networkParameters: [ - { - __typename: 'NetworkParameter', - key: 'nope', - value: 'foo', - }, - ], + networkParametersConnection: { + edges: [ + { + node: { + __typename: 'NetworkParameter', + key: 'nope', + value: 'foo', + }, + }, + ], + }, }, }, };