diff --git a/apps/trading/pages/portfolio/LedgerEntries.graphql b/apps/trading/pages/portfolio/LedgerEntries.graphql index 6c4b62189..26fe4fdb4 100644 --- a/apps/trading/pages/portfolio/LedgerEntries.graphql +++ b/apps/trading/pages/portfolio/LedgerEntries.graphql @@ -1,5 +1,4 @@ fragment LedgerEntry on AggregatedLedgerEntries { - id vegaTime quantity partyId @@ -11,10 +10,12 @@ fragment LedgerEntry on AggregatedLedgerEntries { query LedgerEntries($partyId: ID!) { ledgerEntries( - filter: { - AccountFromFilters: [{ partyIds: [$partyId] }] - AccountToFilters: [{ partyIds: [$partyId] }] + filter: { AccountFromFilter: { partyIds: [$partyId] } } + groupOptions: { + ByAccountField: [PartyId, AccountType, AssetId, MarketId] + ByLedgerEntryField: [TransferType] } + pagination: { first: 500 } ) { edges { node { diff --git a/apps/trading/pages/portfolio/__generated___/LedgerEntries.ts b/apps/trading/pages/portfolio/__generated___/LedgerEntries.ts index 35c056a13..ad52d301c 100644 --- a/apps/trading/pages/portfolio/__generated___/LedgerEntries.ts +++ b/apps/trading/pages/portfolio/__generated___/LedgerEntries.ts @@ -3,18 +3,17 @@ import { Schema as Types } from '@vegaprotocol/types'; import { gql } from '@apollo/client'; import * as Apollo from '@apollo/client'; const defaultOptions = {} as const; -export type LedgerEntryFragment = { __typename?: 'AggregatedLedgerEntries', id?: string | null, vegaTime: string, quantity: string, partyId?: string | null, assetId?: string | null, marketId?: string | null, accountType?: Types.AccountType | null, transferType?: string | null }; +export type LedgerEntryFragment = { __typename?: 'AggregatedLedgerEntries', vegaTime: string, quantity: string, partyId?: string | null, assetId?: string | null, marketId?: string | null, accountType?: Types.AccountType | null, transferType?: string | null }; export type LedgerEntriesQueryVariables = Types.Exact<{ partyId: Types.Scalars['ID']; }>; -export type LedgerEntriesQuery = { __typename?: 'Query', ledgerEntries: { __typename?: 'AggregatedLedgerEntriesConnection', edges: Array<{ __typename?: 'AggregatedLedgerEntriesEdge', node: { __typename?: 'AggregatedLedgerEntries', id?: string | null, vegaTime: string, quantity: string, partyId?: string | null, assetId?: string | null, marketId?: string | null, accountType?: Types.AccountType | null, transferType?: string | null } } | null> } }; +export type LedgerEntriesQuery = { __typename?: 'Query', ledgerEntries: { __typename?: 'AggregatedLedgerEntriesConnection', edges: Array<{ __typename?: 'AggregatedLedgerEntriesEdge', node: { __typename?: 'AggregatedLedgerEntries', vegaTime: string, quantity: string, partyId?: string | null, assetId?: string | null, marketId?: string | null, accountType?: Types.AccountType | null, transferType?: string | null } } | null> } }; export const LedgerEntryFragmentDoc = gql` fragment LedgerEntry on AggregatedLedgerEntries { - id vegaTime quantity partyId @@ -27,7 +26,9 @@ export const LedgerEntryFragmentDoc = gql` export const LedgerEntriesDocument = gql` query LedgerEntries($partyId: ID!) { ledgerEntries( - filter: {AccountFromFilters: [{partyIds: [$partyId]}], AccountToFilters: [{partyIds: [$partyId]}]} + filter: {AccountFromFilter: {partyIds: [$partyId]}} + groupOptions: {ByAccountField: [PartyId, AccountType, AssetId, MarketId], ByLedgerEntryField: [TransferType]} + pagination: {first: 500} ) { edges { node { diff --git a/apps/trading/pages/portfolio/leger-entries.tsx b/apps/trading/pages/portfolio/leger-entries.tsx index 7d39d6f2f..aba526d83 100644 --- a/apps/trading/pages/portfolio/leger-entries.tsx +++ b/apps/trading/pages/portfolio/leger-entries.tsx @@ -1,6 +1,20 @@ +import compact from 'lodash/compact'; import { AsyncRenderer } from '@vegaprotocol/ui-toolkit'; import { useVegaWallet } from '@vegaprotocol/wallet'; +import { AgGridDynamic as AgGrid } from '@vegaprotocol/ui-toolkit'; +import type { LedgerEntryFragment } from './__generated___/LedgerEntries'; import { useLedgerEntriesQuery } from './__generated___/LedgerEntries'; +import { AgGridColumn } from 'ag-grid-react'; +import { useMemo } from 'react'; +import { + fromNanoSeconds, + getDateTimeFormat, + toNanoSeconds, +} from '@vegaprotocol/react-helpers'; + +type Entry = LedgerEntryFragment & { + id: number; +}; export const LedgerEntries = () => { const { pubKey } = useVegaWallet(); @@ -9,13 +23,46 @@ export const LedgerEntries = () => { skip: !pubKey, }); + const entries = useMemo(() => { + if (!data?.ledgerEntries.edges.length) { + return []; + } + + return compact(data.ledgerEntries.edges).map((e, i) => ({ + id: i, + ...e.node, + })); + }, [data]); + return ( - - + +
); }; -const Table = ({ data }: any) => { - return
{JSON.stringify(data, null, 2)}
; +const Table = ({ data }: { data: Entry[] }) => { + return ( + data.id} + defaultColDef={{ + flex: 1, + resizable: true, + }} + > + + + + + + { + return getDateTimeFormat().format(fromNanoSeconds(value)); + }} + /> + + ); }; diff --git a/apps/trading/pages/portfolio/transfers.tsx b/apps/trading/pages/portfolio/transfers.tsx index 9bf65a14d..654e76d67 100644 --- a/apps/trading/pages/portfolio/transfers.tsx +++ b/apps/trading/pages/portfolio/transfers.tsx @@ -5,16 +5,17 @@ import { useTransfersQuery } from './__generated___/Transfers'; export const Transfers = () => { const { pubKey } = useVegaWallet(); const { data, loading, error } = useTransfersQuery({ - variables: { partyId: pubKey }, + variables: { partyId: pubKey || '' }, + skip: !pubKey, }); console.log(data); return ( -
+
); }; -const Table = () => { - return
Foo
; +const Table = ({ data }: { data: any }) => { + return
{JSON.stringify(data, null, 2)}
; }; diff --git a/libs/accounts/src/lib/accounts-data-provider.ts b/libs/accounts/src/lib/accounts-data-provider.ts index ab3fbf7f9..792ef411c 100644 --- a/libs/accounts/src/lib/accounts-data-provider.ts +++ b/libs/accounts/src/lib/accounts-data-provider.ts @@ -130,7 +130,6 @@ const getAssetAccountAggregation = ( accountList: Account[], assetId: string ): AccountFields => { - console.log(accountList); const accounts = accountList.filter((a) => a.asset.id === assetId); const available = getTotalBalance( accounts.filter((a) => a.type === AccountType.ACCOUNT_TYPE_GENERAL) diff --git a/libs/react-helpers/src/lib/time.ts b/libs/react-helpers/src/lib/time.ts index 27485b259..af7d9b6a2 100644 --- a/libs/react-helpers/src/lib/time.ts +++ b/libs/react-helpers/src/lib/time.ts @@ -1,3 +1,8 @@ export const toNanoSeconds = (date: Date | string) => { return new Date(date).getTime().toString() + '000000'; }; + +export const fromNanoSeconds = (ts: string) => { + const validTs = ts.substring(0, ts.length - 6); + return new Date(Number(validTs)); +};