diff --git a/apps/token/src/components/vega-wallet/Delegations.graphql b/apps/token/src/components/vega-wallet/Delegations.graphql index 851c321e5..877350da8 100644 --- a/apps/token/src/components/vega-wallet/Delegations.graphql +++ b/apps/token/src/components/vega-wallet/Delegations.graphql @@ -24,21 +24,25 @@ query Delegations($partyId: ID!) { stakingSummary { currentStakeAvailable } - accounts { - asset { - name - id - decimals - symbol - source { - __typename - ... on ERC20 { - contractAddress + accountsConnection { + edges { + node { + asset { + name + id + decimals + symbol + source { + __typename + ... on ERC20 { + contractAddress + } + } } + type + balance } } - type - balance } } } diff --git a/apps/token/src/components/vega-wallet/__generated__/Delegations.ts b/apps/token/src/components/vega-wallet/__generated__/Delegations.ts deleted file mode 100644 index 6cddf9ec8..000000000 --- a/apps/token/src/components/vega-wallet/__generated__/Delegations.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -// @generated -// This file was automatically generated and should not be edited. - -import { AccountType } from "@vegaprotocol/types"; - -// ==================================================== -// GraphQL query operation: Delegations -// ==================================================== - -export interface Delegations_epoch { - __typename: "Epoch"; - /** - * Numeric sequence number used to identify the epoch - */ - id: string; -} - -export interface Delegations_party_delegationsConnection_edges_node_node { - __typename: "Node"; - /** - * The node URL eg n01.vega.xyz - */ - id: string; - name: string; -} - -export interface Delegations_party_delegationsConnection_edges_node { - __typename: "Delegation"; - /** - * The amount field formatted by the client - */ - amountFormatted: string; - /** - * Amount delegated - */ - amount: string; - /** - * URL of node you are delegating to - */ - node: Delegations_party_delegationsConnection_edges_node_node; - /** - * Epoch of delegation - */ - epoch: number; -} - -export interface Delegations_party_delegationsConnection_edges { - __typename: "DelegationEdge"; - /** - * The delegation information - */ - node: Delegations_party_delegationsConnection_edges_node; -} - -export interface Delegations_party_delegationsConnection { - __typename: "DelegationsConnection"; - /** - * The delegation information available on this connection - */ - edges: (Delegations_party_delegationsConnection_edges | null)[] | null; -} - -export interface Delegations_party_stakingSummary { - __typename: "StakingSummary"; - /** - * The stake currently available for the party - */ - currentStakeAvailable: string; -} - -export interface Delegations_party_accounts_asset_source_BuiltinAsset { - __typename: "BuiltinAsset"; -} - -export interface Delegations_party_accounts_asset_source_ERC20 { - __typename: "ERC20"; - /** - * The address of the ERC20 contract - */ - contractAddress: string; -} - -export type Delegations_party_accounts_asset_source = Delegations_party_accounts_asset_source_BuiltinAsset | Delegations_party_accounts_asset_source_ERC20; - -export interface Delegations_party_accounts_asset { - __typename: "Asset"; - /** - * The full name of the asset (e.g: Great British Pound) - */ - name: string; - /** - * The ID of the asset - */ - id: string; - /** - * The precision of the asset. Should match the decimal precision of the asset on its native chain, e.g: for ERC20 assets, it is often 18 - */ - decimals: number; - /** - * The symbol of the asset (e.g: GBP) - */ - symbol: string; - /** - * The origin source of the asset (e.g: an ERC20 asset) - */ - source: Delegations_party_accounts_asset_source; -} - -export interface Delegations_party_accounts { - __typename: "AccountBalance"; - /** - * Asset, the 'currency' - */ - asset: Delegations_party_accounts_asset; - /** - * Account type (General, Margin, etc) - */ - type: AccountType; - /** - * Balance as string - current account balance (approx. as balances can be updated several times per second) - */ - balance: string; -} - -export interface Delegations_party { - __typename: "Party"; - /** - * Party identifier - */ - id: string; - delegationsConnection: Delegations_party_delegationsConnection | null; - /** - * The staking information for this Party - */ - stakingSummary: Delegations_party_stakingSummary; - /** - * Collateral accounts relating to a party - */ - accounts: Delegations_party_accounts[] | null; -} - -export interface Delegations { - /** - * Get data for a specific epoch, if ID omitted it gets the current epoch. If the string is 'next', fetch the next epoch - */ - epoch: Delegations_epoch; - /** - * An entity that is trading on the Vega network - */ - party: Delegations_party | null; -} - -export interface DelegationsVariables { - partyId: string; -} diff --git a/apps/token/src/components/vega-wallet/__generated___/Delegations.ts b/apps/token/src/components/vega-wallet/__generated___/Delegations.ts index a5b8bbacc..1193de991 100644 --- a/apps/token/src/components/vega-wallet/__generated___/Delegations.ts +++ b/apps/token/src/components/vega-wallet/__generated___/Delegations.ts @@ -10,7 +10,7 @@ export type DelegationsQueryVariables = Types.Exact<{ }>; -export type DelegationsQuery = { __typename?: 'Query', epoch: { __typename?: 'Epoch', id: string }, party?: { __typename?: 'Party', id: string, delegationsConnection?: { __typename?: 'DelegationsConnection', edges?: Array<{ __typename?: 'DelegationEdge', node: { __typename?: 'Delegation', amountFormatted: string, amount: string, epoch: number, node: { __typename?: 'Node', id: string, name: string } } } | null> | null } | null, stakingSummary: { __typename?: 'StakingSummary', currentStakeAvailable: string }, accounts?: Array<{ __typename?: 'AccountBalance', type: Types.AccountType, balance: string, asset: { __typename?: 'Asset', name: string, id: string, decimals: number, symbol: string, source: { __typename: 'BuiltinAsset' } | { __typename: 'ERC20', contractAddress: string } } }> | null } | null }; +export type DelegationsQuery = { __typename?: 'Query', epoch: { __typename?: 'Epoch', id: string }, party?: { __typename?: 'Party', id: string, delegationsConnection?: { __typename?: 'DelegationsConnection', edges?: Array<{ __typename?: 'DelegationEdge', node: { __typename?: 'Delegation', amountFormatted: string, amount: string, epoch: number, node: { __typename?: 'Node', id: string, name: string } } } | null> | null } | null, stakingSummary: { __typename?: 'StakingSummary', currentStakeAvailable: string }, accountsConnection?: { __typename?: 'AccountsConnection', edges?: Array<{ __typename?: 'AccountEdge', node: { __typename?: 'AccountBalance', type: Types.AccountType, balance: string, asset: { __typename?: 'Asset', name: string, id: string, decimals: number, symbol: string, source: { __typename: 'BuiltinAsset' } | { __typename: 'ERC20', contractAddress: string } } } } | null> | null } | null } | null }; export const WalletDelegationFieldsFragmentDoc = gql` fragment WalletDelegationFields on Delegation { @@ -40,21 +40,25 @@ export const DelegationsDocument = gql` stakingSummary { currentStakeAvailable } - accounts { - asset { - name - id - decimals - symbol - source { - __typename - ... on ERC20 { - contractAddress + accountsConnection { + edges { + node { + asset { + name + id + decimals + symbol + source { + __typename + ... on ERC20 { + contractAddress + } + } } + type + balance } } - type - balance } } } diff --git a/apps/token/src/components/vega-wallet/hooks.ts b/apps/token/src/components/vega-wallet/hooks.ts index 79ad79b87..5a4371234 100644 --- a/apps/token/src/components/vega-wallet/hooks.ts +++ b/apps/token/src/components/vega-wallet/hooks.ts @@ -1,4 +1,4 @@ -import { gql, useApolloClient } from '@apollo/client'; +import { useApolloClient } from '@apollo/client'; import * as Sentry from '@sentry/react'; import keyBy from 'lodash/keyBy'; import uniq from 'lodash/uniq'; @@ -10,11 +10,6 @@ import noIcon from '../../images/token-no-icon.png'; import vegaBlack from '../../images/vega_black.png'; import { BigNumber } from '../../lib/bignumber'; import type { WalletCardAssetProps } from '../wallet-card'; -import type { - Delegations, - Delegations_party_delegationsConnection_edges_node, - DelegationsVariables, -} from './__generated__/Delegations'; import { useVegaWallet } from '@vegaprotocol/wallet'; import { useContracts } from '../../contexts/contracts/contracts-context'; import type { ERC20Asset } from '@vegaprotocol/assets'; @@ -23,49 +18,12 @@ import { AccountType } from '@vegaprotocol/types'; import { toBigNum } from '@vegaprotocol/react-helpers'; import { useAppState } from '../../contexts/app-state/app-state-context'; import { addDecimal } from '@vegaprotocol/react-helpers'; - -const DELEGATIONS_QUERY = gql` - query Delegations($partyId: ID!) { - epoch { - id - } - party(id: $partyId) { - id - delegationsConnection { - edges { - node { - amountFormatted @client - amount - node { - id - name - } - epoch - } - } - } - stakingSummary { - currentStakeAvailable - } - accounts { - asset { - name - id - decimals - symbol - source { - __typename - ... on ERC20 { - contractAddress - } - } - } - type - balance - } - } - } -`; +import type { + DelegationsQuery, + DelegationsQueryVariables, + WalletDelegationFieldsFragment, +} from './__generated___/Delegations'; +import { DelegationsDocument } from './__generated___/Delegations'; export const usePollForDelegations = () => { const { token: vegaToken } = useContracts(); @@ -77,7 +35,7 @@ export const usePollForDelegations = () => { const { pubKey } = useVegaWallet(); const client = useApolloClient(); const [delegations, setDelegations] = React.useState< - Delegations_party_delegationsConnection_edges_node[] + WalletDelegationFieldsFragment[] >([]); const [delegatedNodes, setDelegatedNodes] = React.useState< { @@ -101,8 +59,8 @@ export const usePollForDelegations = () => { // start polling for delegation interval = setInterval(() => { client - .query({ - query: DELEGATIONS_QUERY, + .query({ + query: DelegationsDocument, variables: { partyId: pubKey }, fetchPolicy: 'network-only', }) @@ -127,7 +85,9 @@ export const usePollForDelegations = () => { decimals ) ); - const accounts = res.data.party?.accounts || []; + const accounts = compact( + res.data.party?.accountsConnection?.edges + ).map((e) => e.node); setAccounts( accounts .filter((a) => a.type === AccountType.ACCOUNT_TYPE_GENERAL) diff --git a/apps/token/src/routes/governance/Proposal.graphql b/apps/token/src/routes/governance/Proposal.graphql deleted file mode 100644 index 205d83a5e..000000000 --- a/apps/token/src/routes/governance/Proposal.graphql +++ /dev/null @@ -1,107 +0,0 @@ -fragment ProposalFields on Proposal { - id - reference - state - datetime - rejectionReason - errorDetails - party { - id - } - terms { - closingDatetime - enactmentDatetime - change { - ... on NewMarket { - decimalPlaces - metadata - instrument { - name - code - futureProduct { - settlementAsset { - symbol - } - } - } - } - ... on UpdateMarket { - marketId - } - ... on NewAsset { - __typename - name - symbol - source { - ... on BuiltinAsset { - __typename - maxFaucetAmountMint - } - ... on ERC20 { - __typename - contractAddress - } - } - } - ... on UpdateNetworkParameter { - networkParameter { - key - value - } - } - ... on UpdateAsset { - quantum - source { - ... on UpdateERC20 { - lifetimeLimit - withdrawThreshold - } - } - } - } - } - votes { - yes { - totalTokens - totalNumber - totalEquityLikeShareWeight - votes { - value - party { - id - stakingSummary { - currentStakeAvailable - } - } - datetime - } - } - no { - totalTokens - totalNumber - totalEquityLikeShareWeight - votes { - value - party { - id - stakingSummary { - currentStakeAvailable - } - } - datetime - } - } - } -} - -query Proposal($proposalId: ID!) { - proposal(id: $proposalId) { - ...ProposalFields - } -} - -query Proposals { - proposals { - ...ProposalFields - } -} diff --git a/apps/token/src/routes/governance/__generated___/Proposal.ts b/apps/token/src/routes/governance/__generated___/Proposal.ts deleted file mode 100644 index 6d5b43009..000000000 --- a/apps/token/src/routes/governance/__generated___/Proposal.ts +++ /dev/null @@ -1,185 +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 ProposalFieldsFragment = { __typename?: 'Proposal', id?: string | null, reference: string, state: Types.ProposalState, datetime: string, rejectionReason?: Types.ProposalRejectionReason | null, errorDetails?: string | null, party: { __typename?: 'Party', id: string }, terms: { __typename?: 'ProposalTerms', closingDatetime: string, enactmentDatetime?: string | null, change: { __typename: 'NewAsset', name: string, symbol: string, source: { __typename: 'BuiltinAsset', maxFaucetAmountMint: string } | { __typename: 'ERC20', contractAddress: string } } | { __typename?: 'NewFreeform' } | { __typename?: 'NewMarket', decimalPlaces: number, metadata?: Array | null, instrument: { __typename?: 'InstrumentConfiguration', name: string, code: string, futureProduct?: { __typename?: 'FutureProduct', settlementAsset: { __typename?: 'Asset', symbol: string } } | null } } | { __typename?: 'UpdateAsset', quantum: string, source: { __typename?: 'UpdateERC20', lifetimeLimit: string, withdrawThreshold: string } } | { __typename?: 'UpdateMarket', marketId: string } | { __typename?: 'UpdateNetworkParameter', networkParameter: { __typename?: 'NetworkParameter', key: string, value: string } } }, votes: { __typename?: 'ProposalVotes', yes: { __typename?: 'ProposalVoteSide', totalTokens: string, totalNumber: string, totalEquityLikeShareWeight: string, votes?: Array<{ __typename?: 'Vote', value: Types.VoteValue, datetime: string, party: { __typename?: 'Party', id: string, stakingSummary: { __typename?: 'StakingSummary', currentStakeAvailable: string } } }> | null }, no: { __typename?: 'ProposalVoteSide', totalTokens: string, totalNumber: string, totalEquityLikeShareWeight: string, votes?: Array<{ __typename?: 'Vote', value: Types.VoteValue, datetime: string, party: { __typename?: 'Party', id: string, stakingSummary: { __typename?: 'StakingSummary', currentStakeAvailable: string } } }> | null } } }; - -export type ProposalQueryVariables = Types.Exact<{ - proposalId: Types.Scalars['ID']; -}>; - - -export type ProposalQuery = { __typename?: 'Query', proposal?: { __typename?: 'Proposal', id?: string | null, reference: string, state: Types.ProposalState, datetime: string, rejectionReason?: Types.ProposalRejectionReason | null, errorDetails?: string | null, party: { __typename?: 'Party', id: string }, terms: { __typename?: 'ProposalTerms', closingDatetime: string, enactmentDatetime?: string | null, change: { __typename: 'NewAsset', name: string, symbol: string, source: { __typename: 'BuiltinAsset', maxFaucetAmountMint: string } | { __typename: 'ERC20', contractAddress: string } } | { __typename?: 'NewFreeform' } | { __typename?: 'NewMarket', decimalPlaces: number, metadata?: Array | null, instrument: { __typename?: 'InstrumentConfiguration', name: string, code: string, futureProduct?: { __typename?: 'FutureProduct', settlementAsset: { __typename?: 'Asset', symbol: string } } | null } } | { __typename?: 'UpdateAsset', quantum: string, source: { __typename?: 'UpdateERC20', lifetimeLimit: string, withdrawThreshold: string } } | { __typename?: 'UpdateMarket', marketId: string } | { __typename?: 'UpdateNetworkParameter', networkParameter: { __typename?: 'NetworkParameter', key: string, value: string } } }, votes: { __typename?: 'ProposalVotes', yes: { __typename?: 'ProposalVoteSide', totalTokens: string, totalNumber: string, totalEquityLikeShareWeight: string, votes?: Array<{ __typename?: 'Vote', value: Types.VoteValue, datetime: string, party: { __typename?: 'Party', id: string, stakingSummary: { __typename?: 'StakingSummary', currentStakeAvailable: string } } }> | null }, no: { __typename?: 'ProposalVoteSide', totalTokens: string, totalNumber: string, totalEquityLikeShareWeight: string, votes?: Array<{ __typename?: 'Vote', value: Types.VoteValue, datetime: string, party: { __typename?: 'Party', id: string, stakingSummary: { __typename?: 'StakingSummary', currentStakeAvailable: string } } }> | null } } } | null }; - -export type ProposalsQueryVariables = Types.Exact<{ [key: string]: never; }>; - - -export type ProposalsQuery = { __typename?: 'Query', proposals?: Array<{ __typename?: 'Proposal', id?: string | null, reference: string, state: Types.ProposalState, datetime: string, rejectionReason?: Types.ProposalRejectionReason | null, errorDetails?: string | null, party: { __typename?: 'Party', id: string }, terms: { __typename?: 'ProposalTerms', closingDatetime: string, enactmentDatetime?: string | null, change: { __typename: 'NewAsset', name: string, symbol: string, source: { __typename: 'BuiltinAsset', maxFaucetAmountMint: string } | { __typename: 'ERC20', contractAddress: string } } | { __typename?: 'NewFreeform' } | { __typename?: 'NewMarket', decimalPlaces: number, metadata?: Array | null, instrument: { __typename?: 'InstrumentConfiguration', name: string, code: string, futureProduct?: { __typename?: 'FutureProduct', settlementAsset: { __typename?: 'Asset', symbol: string } } | null } } | { __typename?: 'UpdateAsset', quantum: string, source: { __typename?: 'UpdateERC20', lifetimeLimit: string, withdrawThreshold: string } } | { __typename?: 'UpdateMarket', marketId: string } | { __typename?: 'UpdateNetworkParameter', networkParameter: { __typename?: 'NetworkParameter', key: string, value: string } } }, votes: { __typename?: 'ProposalVotes', yes: { __typename?: 'ProposalVoteSide', totalTokens: string, totalNumber: string, totalEquityLikeShareWeight: string, votes?: Array<{ __typename?: 'Vote', value: Types.VoteValue, datetime: string, party: { __typename?: 'Party', id: string, stakingSummary: { __typename?: 'StakingSummary', currentStakeAvailable: string } } }> | null }, no: { __typename?: 'ProposalVoteSide', totalTokens: string, totalNumber: string, totalEquityLikeShareWeight: string, votes?: Array<{ __typename?: 'Vote', value: Types.VoteValue, datetime: string, party: { __typename?: 'Party', id: string, stakingSummary: { __typename?: 'StakingSummary', currentStakeAvailable: string } } }> | null } } }> | null }; - -export const ProposalFieldsFragmentDoc = gql` - fragment ProposalFields on Proposal { - id - reference - state - datetime - rejectionReason - errorDetails - party { - id - } - terms { - closingDatetime - enactmentDatetime - change { - ... on NewMarket { - decimalPlaces - metadata - instrument { - name - code - futureProduct { - settlementAsset { - symbol - } - } - } - } - ... on UpdateMarket { - marketId - } - ... on NewAsset { - __typename - name - symbol - source { - ... on BuiltinAsset { - __typename - maxFaucetAmountMint - } - ... on ERC20 { - __typename - contractAddress - } - } - } - ... on UpdateNetworkParameter { - networkParameter { - key - value - } - } - ... on UpdateAsset { - quantum - source { - ... on UpdateERC20 { - lifetimeLimit - withdrawThreshold - } - } - } - } - } - votes { - yes { - totalTokens - totalNumber - totalEquityLikeShareWeight - votes { - value - party { - id - stakingSummary { - currentStakeAvailable - } - } - datetime - } - } - no { - totalTokens - totalNumber - totalEquityLikeShareWeight - votes { - value - party { - id - stakingSummary { - currentStakeAvailable - } - } - datetime - } - } - } -} - `; -export const ProposalDocument = gql` - query Proposal($proposalId: ID!) { - proposal(id: $proposalId) { - ...ProposalFields - } -} - ${ProposalFieldsFragmentDoc}`; - -/** - * __useProposalQuery__ - * - * To run a query within a React component, call `useProposalQuery` and pass it any options that fit your needs. - * When your component renders, `useProposalQuery` 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 } = useProposalQuery({ - * variables: { - * proposalId: // value for 'proposalId' - * }, - * }); - */ -export function useProposalQuery(baseOptions: Apollo.QueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useQuery(ProposalDocument, options); - } -export function useProposalLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useLazyQuery(ProposalDocument, options); - } -export type ProposalQueryHookResult = ReturnType; -export type ProposalLazyQueryHookResult = ReturnType; -export type ProposalQueryResult = Apollo.QueryResult; -export const ProposalsDocument = gql` - query Proposals { - proposals { - ...ProposalFields - } -} - ${ProposalFieldsFragmentDoc}`; - -/** - * __useProposalsQuery__ - * - * To run a query within a React component, call `useProposalsQuery` and pass it any options that fit your needs. - * When your component renders, `useProposalsQuery` 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 } = useProposalsQuery({ - * variables: { - * }, - * }); - */ -export function useProposalsQuery(baseOptions?: Apollo.QueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useQuery(ProposalsDocument, options); - } -export function useProposalsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useLazyQuery(ProposalsDocument, options); - } -export type ProposalsQueryHookResult = ReturnType; -export type ProposalsLazyQueryHookResult = ReturnType; -export type ProposalsQueryResult = Apollo.QueryResult; \ No newline at end of file