chore: testing ledger entry query
This commit is contained in:
parent
96d331e714
commit
0e87ee18b6
@ -1,5 +1,4 @@
|
|||||||
fragment LedgerEntry on AggregatedLedgerEntries {
|
fragment LedgerEntry on AggregatedLedgerEntries {
|
||||||
id
|
|
||||||
vegaTime
|
vegaTime
|
||||||
quantity
|
quantity
|
||||||
partyId
|
partyId
|
||||||
@ -11,10 +10,12 @@ fragment LedgerEntry on AggregatedLedgerEntries {
|
|||||||
|
|
||||||
query LedgerEntries($partyId: ID!) {
|
query LedgerEntries($partyId: ID!) {
|
||||||
ledgerEntries(
|
ledgerEntries(
|
||||||
filter: {
|
filter: { AccountFromFilter: { partyIds: [$partyId] } }
|
||||||
AccountFromFilters: [{ partyIds: [$partyId] }]
|
groupOptions: {
|
||||||
AccountToFilters: [{ partyIds: [$partyId] }]
|
ByAccountField: [PartyId, AccountType, AssetId, MarketId]
|
||||||
|
ByLedgerEntryField: [TransferType]
|
||||||
}
|
}
|
||||||
|
pagination: { first: 500 }
|
||||||
) {
|
) {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
|
@ -3,18 +3,17 @@ import { Schema as Types } from '@vegaprotocol/types';
|
|||||||
import { gql } from '@apollo/client';
|
import { gql } from '@apollo/client';
|
||||||
import * as Apollo from '@apollo/client';
|
import * as Apollo from '@apollo/client';
|
||||||
const defaultOptions = {} as const;
|
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<{
|
export type LedgerEntriesQueryVariables = Types.Exact<{
|
||||||
partyId: Types.Scalars['ID'];
|
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`
|
export const LedgerEntryFragmentDoc = gql`
|
||||||
fragment LedgerEntry on AggregatedLedgerEntries {
|
fragment LedgerEntry on AggregatedLedgerEntries {
|
||||||
id
|
|
||||||
vegaTime
|
vegaTime
|
||||||
quantity
|
quantity
|
||||||
partyId
|
partyId
|
||||||
@ -27,7 +26,9 @@ export const LedgerEntryFragmentDoc = gql`
|
|||||||
export const LedgerEntriesDocument = gql`
|
export const LedgerEntriesDocument = gql`
|
||||||
query LedgerEntries($partyId: ID!) {
|
query LedgerEntries($partyId: ID!) {
|
||||||
ledgerEntries(
|
ledgerEntries(
|
||||||
filter: {AccountFromFilters: [{partyIds: [$partyId]}], AccountToFilters: [{partyIds: [$partyId]}]}
|
filter: {AccountFromFilter: {partyIds: [$partyId]}}
|
||||||
|
groupOptions: {ByAccountField: [PartyId, AccountType, AssetId, MarketId], ByLedgerEntryField: [TransferType]}
|
||||||
|
pagination: {first: 500}
|
||||||
) {
|
) {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
|
@ -1,6 +1,20 @@
|
|||||||
|
import compact from 'lodash/compact';
|
||||||
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
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 { 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 = () => {
|
export const LedgerEntries = () => {
|
||||||
const { pubKey } = useVegaWallet();
|
const { pubKey } = useVegaWallet();
|
||||||
@ -9,13 +23,46 @@ export const LedgerEntries = () => {
|
|||||||
skip: !pubKey,
|
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 (
|
return (
|
||||||
<AsyncRenderer data={data} loading={loading} error={error}>
|
<AsyncRenderer data={entries} loading={loading} error={error}>
|
||||||
<Table data={data} />
|
<Table data={entries} />
|
||||||
</AsyncRenderer>
|
</AsyncRenderer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Table = ({ data }: any) => {
|
const Table = ({ data }: { data: Entry[] }) => {
|
||||||
return <pre>{JSON.stringify(data, null, 2)}</pre>;
|
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 = () => {
|
export const Transfers = () => {
|
||||||
const { pubKey } = useVegaWallet();
|
const { pubKey } = useVegaWallet();
|
||||||
const { data, loading, error } = useTransfersQuery({
|
const { data, loading, error } = useTransfersQuery({
|
||||||
variables: { partyId: pubKey },
|
variables: { partyId: pubKey || '' },
|
||||||
|
skip: !pubKey,
|
||||||
});
|
});
|
||||||
console.log(data);
|
console.log(data);
|
||||||
return (
|
return (
|
||||||
<AsyncRenderer data={data} loading={loading} error={error}>
|
<AsyncRenderer data={data} loading={loading} error={error}>
|
||||||
<Table />
|
<Table data={data} />
|
||||||
</AsyncRenderer>
|
</AsyncRenderer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Table = () => {
|
const Table = ({ data }: { data: any }) => {
|
||||||
return <div>Foo</div>;
|
return <pre>{JSON.stringify(data, null, 2)}</pre>;
|
||||||
};
|
};
|
||||||
|
@ -130,7 +130,6 @@ const getAssetAccountAggregation = (
|
|||||||
accountList: Account[],
|
accountList: Account[],
|
||||||
assetId: string
|
assetId: string
|
||||||
): AccountFields => {
|
): AccountFields => {
|
||||||
console.log(accountList);
|
|
||||||
const accounts = accountList.filter((a) => a.asset.id === assetId);
|
const accounts = accountList.filter((a) => a.asset.id === assetId);
|
||||||
const available = getTotalBalance(
|
const available = getTotalBalance(
|
||||||
accounts.filter((a) => a.type === AccountType.ACCOUNT_TYPE_GENERAL)
|
accounts.filter((a) => a.type === AccountType.ACCOUNT_TYPE_GENERAL)
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
export const toNanoSeconds = (date: Date | string) => {
|
export const toNanoSeconds = (date: Date | string) => {
|
||||||
return new Date(date).getTime().toString() + '000000';
|
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