chore: testing ledger entry query
This commit is contained in:
parent
96d331e714
commit
0e87ee18b6
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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<Entry[]>(() => {
|
||||
if (!data?.ledgerEntries.edges.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return compact(data.ledgerEntries.edges).map((e, i) => ({
|
||||
id: i,
|
||||
...e.node,
|
||||
}));
|
||||
}, [data]);
|
||||
|
||||
return (
|
||||
<AsyncRenderer data={data} loading={loading} error={error}>
|
||||
<Table data={data} />
|
||||
<AsyncRenderer data={entries} loading={loading} error={error}>
|
||||
<Table data={entries} />
|
||||
</AsyncRenderer>
|
||||
);
|
||||
};
|
||||
|
||||
const Table = ({ data }: any) => {
|
||||
return <pre>{JSON.stringify(data, null, 2)}</pre>;
|
||||
const Table = ({ data }: { data: Entry[] }) => {
|
||||
return (
|
||||
<AgGrid
|
||||
style={{ width: '100%', height: '100%' }}
|
||||
rowData={data}
|
||||
getRowId={({ data }) => data.id}
|
||||
defaultColDef={{
|
||||
flex: 1,
|
||||
resizable: true,
|
||||
}}
|
||||
>
|
||||
<AgGridColumn field="accountType" />
|
||||
<AgGridColumn field="transferType" />
|
||||
<AgGridColumn field="quantity" />
|
||||
<AgGridColumn field="assetId" />
|
||||
<AgGridColumn field="marketId" />
|
||||
<AgGridColumn
|
||||
field="vegaTime"
|
||||
valueFormatter={({ value }: any) => {
|
||||
return getDateTimeFormat().format(fromNanoSeconds(value));
|
||||
}}
|
||||
/>
|
||||
</AgGrid>
|
||||
);
|
||||
};
|
||||
|
@ -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 (
|
||||
<AsyncRenderer data={data} loading={loading} error={error}>
|
||||
<Table />
|
||||
<Table data={data} />
|
||||
</AsyncRenderer>
|
||||
);
|
||||
};
|
||||
|
||||
const Table = () => {
|
||||
return <div>Foo</div>;
|
||||
const Table = ({ data }: { data: any }) => {
|
||||
return <pre>{JSON.stringify(data, null, 2)}</pre>;
|
||||
};
|
||||
|
@ -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)
|
||||
|
@ -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));
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user