diff --git a/apps/trading-e2e/src/integration/trading-accounts.cy.ts b/apps/trading-e2e/src/integration/trading-accounts.cy.ts index c0e142b2d..e2f9a1dea 100644 --- a/apps/trading-e2e/src/integration/trading-accounts.cy.ts +++ b/apps/trading-e2e/src/integration/trading-accounts.cy.ts @@ -41,6 +41,12 @@ describe('accounts', { tags: '@smoke' }, () => { .should('have.text', '100,001.01'); }); + it('asset detail should be properly rendered', () => { + cy.getByTestId('Collateral').click(); + cy.getByTestId('asset').contains('tEURO').click(); + cy.get('[data-testid$="_label"]').should('have.length', 16); + }); + describe('sorting by ag-grid columns should work well', () => { it('sorting by asset', () => { cy.getByTestId('Collateral').click(); diff --git a/libs/assets/src/lib/Assets.graphql b/libs/assets/src/lib/Assets.graphql index 8a4dbc957..fc221c373 100644 --- a/libs/assets/src/lib/Assets.graphql +++ b/libs/assets/src/lib/Assets.graphql @@ -1,8 +1,25 @@ +fragment AssetListFields on Asset { + id + name + symbol + decimals + quantum + source { + __typename + ... on ERC20 { + contractAddress + lifetimeLimit + withdrawThreshold + } + } + status +} + query Assets { assetsConnection { edges { node { - ...AssetFields + ...AssetListFields } } } diff --git a/libs/assets/src/lib/__generated__/Assets.ts b/libs/assets/src/lib/__generated__/Assets.ts index 8d6d977b0..b9c72a4c0 100644 --- a/libs/assets/src/lib/__generated__/Assets.ts +++ b/libs/assets/src/lib/__generated__/Assets.ts @@ -1,26 +1,44 @@ import * as Types from '@vegaprotocol/types'; import { gql } from '@apollo/client'; -import { AssetFieldsFragmentDoc } from './Asset'; import * as Apollo from '@apollo/client'; const defaultOptions = {} as const; +export type AssetListFieldsFragment = { __typename?: 'Asset', id: string, name: string, symbol: string, decimals: number, quantum: string, status: Types.AssetStatus, source: { __typename: 'BuiltinAsset' } | { __typename: 'ERC20', contractAddress: string, lifetimeLimit: string, withdrawThreshold: string } }; + export type AssetsQueryVariables = Types.Exact<{ [key: string]: never; }>; -export type AssetsQuery = { __typename?: 'Query', assetsConnection?: { __typename?: 'AssetsConnection', edges?: Array<{ __typename?: 'AssetEdge', node: { __typename?: 'Asset', id: string, name: string, symbol: string, decimals: number, quantum: string, status: Types.AssetStatus, source: { __typename: 'BuiltinAsset', maxFaucetAmountMint: string } | { __typename: 'ERC20', contractAddress: string, lifetimeLimit: string, withdrawThreshold: string }, infrastructureFeeAccount?: { __typename?: 'AccountBalance', balance: string } | null, globalRewardPoolAccount?: { __typename?: 'AccountBalance', balance: string } | null, takerFeeRewardAccount?: { __typename?: 'AccountBalance', balance: string } | null, makerFeeRewardAccount?: { __typename?: 'AccountBalance', balance: string } | null, lpFeeRewardAccount?: { __typename?: 'AccountBalance', balance: string } | null, marketProposerRewardAccount?: { __typename?: 'AccountBalance', balance: string } | null } } | null> | null } | null }; - +export type AssetsQuery = { __typename?: 'Query', assetsConnection?: { __typename?: 'AssetsConnection', edges?: Array<{ __typename?: 'AssetEdge', node: { __typename?: 'Asset', id: string, name: string, symbol: string, decimals: number, quantum: string, status: Types.AssetStatus, source: { __typename: 'BuiltinAsset' } | { __typename: 'ERC20', contractAddress: string, lifetimeLimit: string, withdrawThreshold: string } } } | null> | null } | null }; +export const AssetListFieldsFragmentDoc = gql` + fragment AssetListFields on Asset { + id + name + symbol + decimals + quantum + source { + __typename + ... on ERC20 { + contractAddress + lifetimeLimit + withdrawThreshold + } + } + status +} + `; export const AssetsDocument = gql` query Assets { assetsConnection { edges { node { - ...AssetFields + ...AssetListFields } } } } - ${AssetFieldsFragmentDoc}`; + ${AssetListFieldsFragmentDoc}`; /** * __useAssetsQuery__ diff --git a/libs/assets/src/lib/asset-details-dialog.spec.tsx b/libs/assets/src/lib/asset-details-dialog.spec.tsx index 69cb9d24f..3d080abf2 100644 --- a/libs/assets/src/lib/asset-details-dialog.spec.tsx +++ b/libs/assets/src/lib/asset-details-dialog.spec.tsx @@ -3,7 +3,7 @@ import { render, screen } from '@testing-library/react'; import * as Schema from '@vegaprotocol/types'; import { AssetDetailsDialog } from './asset-details-dialog'; import { AssetDetail, testId } from './asset-details-table'; -import { AssetsDocument } from './__generated__/Assets'; +import { AssetDocument } from './__generated__/Asset'; import { generateBuiltinAsset, generateERC20Asset } from './test-helpers'; const mockedData = { @@ -39,15 +39,17 @@ const mockedData = { }, }; -const mocks = [ - { - request: { - query: AssetsDocument, - variables: {}, - }, - result: mockedData, +const mocks = mockedData.data.assetsConnection.edges.map((mock) => ({ + request: { + query: AssetDocument, + variables: { assetId: mock.node.id }, }, -]; + result: { + data: { + assetsConnection: { edges: [mock] }, + }, + }, +})); const WrappedAssetDetailsDialog = ({ assetId }: { assetId: string }) => ( diff --git a/libs/assets/src/lib/asset-details-dialog.tsx b/libs/assets/src/lib/asset-details-dialog.tsx index 168fc3399..f1bf66e39 100644 --- a/libs/assets/src/lib/asset-details-dialog.tsx +++ b/libs/assets/src/lib/asset-details-dialog.tsx @@ -1,5 +1,4 @@ import { t } from '@vegaprotocol/i18n'; -import { useAssetsDataProvider } from './assets-data-provider'; import { Button, Dialog, @@ -10,6 +9,7 @@ import { import { create } from 'zustand'; import { AssetDetailsTable } from './asset-details-table'; import { AssetProposalNotification } from '@vegaprotocol/proposals'; +import { useAssetDataProvider } from './asset-data-provider'; export type AssetDetailsDialogStore = { isOpen: boolean; @@ -55,9 +55,8 @@ export const AssetDetailsDialog = ({ onChange, asJson = false, }: AssetDetailsDialogProps) => { - const { data } = useAssetsDataProvider(); + const { data: asset } = useAssetDataProvider(assetId); - const asset = data?.find((a) => a.id === assetId); const assetSymbol = asset?.symbol || ''; const content = asset ? ( diff --git a/libs/assets/src/lib/assets.mock.ts b/libs/assets/src/lib/assets.mock.ts index e4ed73dc2..727103391 100644 --- a/libs/assets/src/lib/assets.mock.ts +++ b/libs/assets/src/lib/assets.mock.ts @@ -1,8 +1,10 @@ import merge from 'lodash/merge'; -import type { AssetsQuery } from './__generated__/Assets'; +import type { + AssetsQuery, + AssetListFieldsFragment, +} from './__generated__/Assets'; import * as Types from '@vegaprotocol/types'; import type { PartialDeep } from 'type-fest'; -import type { AssetFieldsFragment } from './__generated__/Asset'; export const assetsQuery = ( override?: PartialDeep @@ -18,7 +20,7 @@ export const assetsQuery = ( return merge(defaultAssets, override); }; -const assetFields: AssetFieldsFragment[] = [ +const assetFields: AssetListFieldsFragment[] = [ { __typename: 'Asset', id: 'asset-id', @@ -33,30 +35,6 @@ const assetFields: AssetFieldsFragment[] = [ }, quantum: '1', status: Types.AssetStatus.STATUS_ENABLED, - infrastructureFeeAccount: { - balance: '1', - __typename: 'AccountBalance', - }, - globalRewardPoolAccount: { - balance: '2', - __typename: 'AccountBalance', - }, - takerFeeRewardAccount: { - balance: '3', - __typename: 'AccountBalance', - }, - makerFeeRewardAccount: { - balance: '4', - __typename: 'AccountBalance', - }, - lpFeeRewardAccount: { - balance: '5', - __typename: 'AccountBalance', - }, - marketProposerRewardAccount: { - balance: '6', - __typename: 'AccountBalance', - }, }, { __typename: 'Asset', @@ -72,30 +50,6 @@ const assetFields: AssetFieldsFragment[] = [ }, quantum: '1', status: Types.AssetStatus.STATUS_ENABLED, - infrastructureFeeAccount: { - balance: '1', - __typename: 'AccountBalance', - }, - globalRewardPoolAccount: { - balance: '2', - __typename: 'AccountBalance', - }, - takerFeeRewardAccount: { - balance: '3', - __typename: 'AccountBalance', - }, - makerFeeRewardAccount: { - balance: '4', - __typename: 'AccountBalance', - }, - lpFeeRewardAccount: { - balance: '5', - __typename: 'AccountBalance', - }, - marketProposerRewardAccount: { - balance: '6', - __typename: 'AccountBalance', - }, }, { __typename: 'Asset', @@ -104,20 +58,10 @@ const assetFields: AssetFieldsFragment[] = [ decimals: 5, name: 'Asto', source: { - maxFaucetAmountMint: '5000000000', __typename: 'BuiltinAsset', }, quantum: '1', status: Types.AssetStatus.STATUS_ENABLED, - infrastructureFeeAccount: { - balance: '0', - __typename: 'AccountBalance', - }, - globalRewardPoolAccount: null, - takerFeeRewardAccount: null, - makerFeeRewardAccount: null, - lpFeeRewardAccount: null, - marketProposerRewardAccount: null, }, { __typename: 'Asset', @@ -126,20 +70,10 @@ const assetFields: AssetFieldsFragment[] = [ decimals: 5, name: 'tBTC TEST', source: { - maxFaucetAmountMint: '5000000000', __typename: 'BuiltinAsset', }, quantum: '1', status: Types.AssetStatus.STATUS_ENABLED, - infrastructureFeeAccount: { - balance: '0', - __typename: 'AccountBalance', - }, - globalRewardPoolAccount: null, - takerFeeRewardAccount: null, - makerFeeRewardAccount: null, - lpFeeRewardAccount: null, - marketProposerRewardAccount: null, }, // NOTE: These assets ids and contract addresses are real assets on Sepolia, this is needed // because we don't currently mock our seplia infura provider. If we change network these will @@ -158,30 +92,6 @@ const assetFields: AssetFieldsFragment[] = [ __typename: 'ERC20', }, quantum: '1', - infrastructureFeeAccount: { - balance: '1', - __typename: 'AccountBalance', - }, - globalRewardPoolAccount: { - balance: '2', - __typename: 'AccountBalance', - }, - takerFeeRewardAccount: { - balance: '3', - __typename: 'AccountBalance', - }, - makerFeeRewardAccount: { - balance: '4', - __typename: 'AccountBalance', - }, - lpFeeRewardAccount: { - balance: '5', - __typename: 'AccountBalance', - }, - marketProposerRewardAccount: { - balance: '6', - __typename: 'AccountBalance', - }, }, { __typename: 'Asset', @@ -197,29 +107,5 @@ const assetFields: AssetFieldsFragment[] = [ __typename: 'ERC20', }, quantum: '1', - infrastructureFeeAccount: { - balance: '1', - __typename: 'AccountBalance', - }, - globalRewardPoolAccount: { - balance: '2', - __typename: 'AccountBalance', - }, - takerFeeRewardAccount: { - balance: '3', - __typename: 'AccountBalance', - }, - makerFeeRewardAccount: { - balance: '4', - __typename: 'AccountBalance', - }, - lpFeeRewardAccount: { - balance: '5', - __typename: 'AccountBalance', - }, - marketProposerRewardAccount: { - balance: '6', - __typename: 'AccountBalance', - }, }, ];