Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e87ee18b6 | ||
|
|
96d331e714 |
+1
-1
@@ -6,5 +6,5 @@ NX_VEGA_ENV=TESTNET
|
||||
NX_VEGA_EXPLORER_URL=https://explorer.fairground.wtf
|
||||
NX_VEGA_NETWORKS={\"TESTNET\":\"https://console.fairground.wtf\",\"STAGNET1\":\"https://stagnet1.console.vega.xyz\",\"STAGNET3\":\"https://stagnet3.console.vega.xyz\"}
|
||||
NX_VEGA_TOKEN_URL=https://token.fairground.wtf
|
||||
NX_VEGA_URL=https://api.n06.testnet.vega.xyz/graphql
|
||||
NX_VEGA_URL=https://api.n08.testnet.vega.xyz/graphql
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
fragment LedgerEntry on AggregatedLedgerEntries {
|
||||
vegaTime
|
||||
quantity
|
||||
partyId
|
||||
assetId
|
||||
marketId
|
||||
accountType
|
||||
transferType
|
||||
}
|
||||
|
||||
query LedgerEntries($partyId: ID!) {
|
||||
ledgerEntries(
|
||||
filter: { AccountFromFilter: { partyIds: [$partyId] } }
|
||||
groupOptions: {
|
||||
ByAccountField: [PartyId, AccountType, AssetId, MarketId]
|
||||
ByLedgerEntryField: [TransferType]
|
||||
}
|
||||
pagination: { first: 500 }
|
||||
) {
|
||||
edges {
|
||||
node {
|
||||
...LedgerEntry
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
fragment TransferFields on Transfer {
|
||||
id
|
||||
from
|
||||
fromAccountType
|
||||
to
|
||||
toAccountType
|
||||
asset {
|
||||
id
|
||||
symbol
|
||||
decimals
|
||||
}
|
||||
amount
|
||||
reference
|
||||
status
|
||||
timestamp
|
||||
kind {
|
||||
... on OneOffTransfer {
|
||||
deliverOn
|
||||
}
|
||||
... on RecurringTransfer {
|
||||
startEpoch
|
||||
endEpoch
|
||||
factor
|
||||
dispatchStrategy {
|
||||
dispatchMetric
|
||||
dispatchMetricAssetId
|
||||
marketIdsInScope
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query Transfers($partyId: ID!) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
transfersConnection {
|
||||
edges {
|
||||
node {
|
||||
...TransferFields
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
// ====================================================
|
||||
// GraphQL fragment: AssetFields
|
||||
// ====================================================
|
||||
|
||||
export interface AssetFields_source_BuiltinAsset {
|
||||
__typename: "BuiltinAsset";
|
||||
}
|
||||
|
||||
export interface AssetFields_source_ERC20 {
|
||||
__typename: "ERC20";
|
||||
/**
|
||||
* The address of the ERC20 contract
|
||||
*/
|
||||
contractAddress: string;
|
||||
}
|
||||
|
||||
export type AssetFields_source = AssetFields_source_BuiltinAsset | AssetFields_source_ERC20;
|
||||
|
||||
export interface AssetFields {
|
||||
__typename: "Asset";
|
||||
/**
|
||||
* The ID of the asset
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* The symbol of the asset (e.g: GBP)
|
||||
*/
|
||||
symbol: string;
|
||||
/**
|
||||
* The full name of the asset (e.g: Great British Pound)
|
||||
*/
|
||||
name: 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 origin source of the asset (e.g: an ERC20 asset)
|
||||
*/
|
||||
source: AssetFields_source;
|
||||
}
|
||||
@@ -1,119 +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: WithdrawFormQuery
|
||||
// ====================================================
|
||||
|
||||
export interface WithdrawFormQuery_party_withdrawals {
|
||||
__typename: "Withdrawal";
|
||||
/**
|
||||
* The Vega internal ID of the withdrawal
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* Hash of the transaction on the foreign chain
|
||||
*/
|
||||
txHash: string | null;
|
||||
}
|
||||
|
||||
export interface WithdrawFormQuery_party_accounts_asset {
|
||||
__typename: "Asset";
|
||||
/**
|
||||
* The ID of the asset
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* The symbol of the asset (e.g: GBP)
|
||||
*/
|
||||
symbol: string;
|
||||
}
|
||||
|
||||
export interface WithdrawFormQuery_party_accounts {
|
||||
__typename: "Account";
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* Asset, the 'currency'
|
||||
*/
|
||||
asset: WithdrawFormQuery_party_accounts_asset;
|
||||
}
|
||||
|
||||
export interface WithdrawFormQuery_party {
|
||||
__typename: "Party";
|
||||
/**
|
||||
* Party identifier
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* The list of all withdrawals initiated by the party
|
||||
*/
|
||||
withdrawals: WithdrawFormQuery_party_withdrawals[] | null;
|
||||
/**
|
||||
* Collateral accounts relating to a party
|
||||
*/
|
||||
accounts: WithdrawFormQuery_party_accounts[] | null;
|
||||
}
|
||||
|
||||
export interface WithdrawFormQuery_assets_source_BuiltinAsset {
|
||||
__typename: "BuiltinAsset";
|
||||
}
|
||||
|
||||
export interface WithdrawFormQuery_assets_source_ERC20 {
|
||||
__typename: "ERC20";
|
||||
/**
|
||||
* The address of the ERC20 contract
|
||||
*/
|
||||
contractAddress: string;
|
||||
}
|
||||
|
||||
export type WithdrawFormQuery_assets_source = WithdrawFormQuery_assets_source_BuiltinAsset | WithdrawFormQuery_assets_source_ERC20;
|
||||
|
||||
export interface WithdrawFormQuery_assets {
|
||||
__typename: "Asset";
|
||||
/**
|
||||
* The ID of the asset
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* The symbol of the asset (e.g: GBP)
|
||||
*/
|
||||
symbol: string;
|
||||
/**
|
||||
* The full name of the asset (e.g: Great British Pound)
|
||||
*/
|
||||
name: 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 origin source of the asset (e.g: an ERC20 asset)
|
||||
*/
|
||||
source: WithdrawFormQuery_assets_source;
|
||||
}
|
||||
|
||||
export interface WithdrawFormQuery {
|
||||
/**
|
||||
* An entity that is trading on the Vega network
|
||||
*/
|
||||
party: WithdrawFormQuery_party | null;
|
||||
/**
|
||||
* The list of all assets in use in the Vega network
|
||||
*/
|
||||
assets: WithdrawFormQuery_assets[] | null;
|
||||
}
|
||||
|
||||
export interface WithdrawFormQueryVariables {
|
||||
partyId: string;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
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', 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', 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 {
|
||||
vegaTime
|
||||
quantity
|
||||
partyId
|
||||
assetId
|
||||
marketId
|
||||
accountType
|
||||
transferType
|
||||
}
|
||||
`;
|
||||
export const LedgerEntriesDocument = gql`
|
||||
query LedgerEntries($partyId: ID!) {
|
||||
ledgerEntries(
|
||||
filter: {AccountFromFilter: {partyIds: [$partyId]}}
|
||||
groupOptions: {ByAccountField: [PartyId, AccountType, AssetId, MarketId], ByLedgerEntryField: [TransferType]}
|
||||
pagination: {first: 500}
|
||||
) {
|
||||
edges {
|
||||
node {
|
||||
...LedgerEntry
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
${LedgerEntryFragmentDoc}`;
|
||||
|
||||
/**
|
||||
* __useLedgerEntriesQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useLedgerEntriesQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useLedgerEntriesQuery` 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 } = useLedgerEntriesQuery({
|
||||
* variables: {
|
||||
* partyId: // value for 'partyId'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useLedgerEntriesQuery(baseOptions: Apollo.QueryHookOptions<LedgerEntriesQuery, LedgerEntriesQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useQuery<LedgerEntriesQuery, LedgerEntriesQueryVariables>(LedgerEntriesDocument, options);
|
||||
}
|
||||
export function useLedgerEntriesLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<LedgerEntriesQuery, LedgerEntriesQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useLazyQuery<LedgerEntriesQuery, LedgerEntriesQueryVariables>(LedgerEntriesDocument, options);
|
||||
}
|
||||
export type LedgerEntriesQueryHookResult = ReturnType<typeof useLedgerEntriesQuery>;
|
||||
export type LedgerEntriesLazyQueryHookResult = ReturnType<typeof useLedgerEntriesLazyQuery>;
|
||||
export type LedgerEntriesQueryResult = Apollo.QueryResult<LedgerEntriesQuery, LedgerEntriesQueryVariables>;
|
||||
@@ -0,0 +1,89 @@
|
||||
import { Schema as Types } from '@vegaprotocol/types';
|
||||
|
||||
import { gql } from '@apollo/client';
|
||||
import * as Apollo from '@apollo/client';
|
||||
const defaultOptions = {} as const;
|
||||
export type TransferFieldsFragment = { __typename?: 'Transfer', id: string, from: string, fromAccountType: Types.AccountType, to: string, toAccountType: Types.AccountType, amount: string, reference?: string | null, status: Types.TransferStatus, timestamp: string, asset?: { __typename?: 'Asset', id: string, symbol: string, decimals: number } | null, kind: { __typename?: 'OneOffTransfer', deliverOn?: string | null } | { __typename?: 'RecurringTransfer', startEpoch: number, endEpoch?: number | null, factor: string, dispatchStrategy?: { __typename?: 'DispatchStrategy', dispatchMetric: Types.DispatchMetric, dispatchMetricAssetId: string, marketIdsInScope?: Array<string> | null } | null } };
|
||||
|
||||
export type TransfersQueryVariables = Types.Exact<{
|
||||
partyId: Types.Scalars['ID'];
|
||||
}>;
|
||||
|
||||
|
||||
export type TransfersQuery = { __typename?: 'Query', party?: { __typename?: 'Party', id: string, transfersConnection?: { __typename?: 'TransferConnection', edges?: Array<{ __typename?: 'TransferEdge', node: { __typename?: 'Transfer', id: string, from: string, fromAccountType: Types.AccountType, to: string, toAccountType: Types.AccountType, amount: string, reference?: string | null, status: Types.TransferStatus, timestamp: string, asset?: { __typename?: 'Asset', id: string, symbol: string, decimals: number } | null, kind: { __typename?: 'OneOffTransfer', deliverOn?: string | null } | { __typename?: 'RecurringTransfer', startEpoch: number, endEpoch?: number | null, factor: string, dispatchStrategy?: { __typename?: 'DispatchStrategy', dispatchMetric: Types.DispatchMetric, dispatchMetricAssetId: string, marketIdsInScope?: Array<string> | null } | null } } } | null> | null } | null } | null };
|
||||
|
||||
export const TransferFieldsFragmentDoc = gql`
|
||||
fragment TransferFields on Transfer {
|
||||
id
|
||||
from
|
||||
fromAccountType
|
||||
to
|
||||
toAccountType
|
||||
asset {
|
||||
id
|
||||
symbol
|
||||
decimals
|
||||
}
|
||||
amount
|
||||
reference
|
||||
status
|
||||
timestamp
|
||||
kind {
|
||||
... on OneOffTransfer {
|
||||
deliverOn
|
||||
}
|
||||
... on RecurringTransfer {
|
||||
startEpoch
|
||||
endEpoch
|
||||
factor
|
||||
dispatchStrategy {
|
||||
dispatchMetric
|
||||
dispatchMetricAssetId
|
||||
marketIdsInScope
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const TransfersDocument = gql`
|
||||
query Transfers($partyId: ID!) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
transfersConnection {
|
||||
edges {
|
||||
node {
|
||||
...TransferFields
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
${TransferFieldsFragmentDoc}`;
|
||||
|
||||
/**
|
||||
* __useTransfersQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useTransfersQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useTransfersQuery` 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 } = useTransfersQuery({
|
||||
* variables: {
|
||||
* partyId: // value for 'partyId'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useTransfersQuery(baseOptions: Apollo.QueryHookOptions<TransfersQuery, TransfersQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useQuery<TransfersQuery, TransfersQueryVariables>(TransfersDocument, options);
|
||||
}
|
||||
export function useTransfersLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<TransfersQuery, TransfersQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useLazyQuery<TransfersQuery, TransfersQueryVariables>(TransfersDocument, options);
|
||||
}
|
||||
export type TransfersQueryHookResult = ReturnType<typeof useTransfersQuery>;
|
||||
export type TransfersLazyQueryHookResult = ReturnType<typeof useTransfersLazyQuery>;
|
||||
export type TransfersQueryResult = Apollo.QueryResult<TransfersQuery, TransfersQueryVariables>;
|
||||
@@ -12,6 +12,8 @@ import { ResizableGrid } from '@vegaprotocol/ui-toolkit';
|
||||
import { LayoutPriority } from 'allotment';
|
||||
import { usePageTitleStore } from '../../stores';
|
||||
import { AccountsContainer } from './accounts-container';
|
||||
import { Transfers } from './transfers';
|
||||
import { LedgerEntries } from './leger-entries';
|
||||
|
||||
const Portfolio = () => {
|
||||
const { updateTitle } = usePageTitleStore((store) => ({
|
||||
@@ -28,6 +30,16 @@ const Portfolio = () => {
|
||||
<ResizableGridPanel minSize={75}>
|
||||
<PortfolioGridChild>
|
||||
<Tabs>
|
||||
<Tab id="ledger-entries" name={t('Ledger Entries')}>
|
||||
<VegaWalletContainer>
|
||||
<LedgerEntries />
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
<Tab id="transfers" name={t('Transfers')}>
|
||||
<VegaWalletContainer>
|
||||
<Transfers />
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
<Tab id="positions" name={t('Positions')}>
|
||||
<VegaWalletContainer>
|
||||
<PositionsContainer />
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
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();
|
||||
const { data, loading, error } = useLedgerEntriesQuery({
|
||||
variables: { partyId: 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 (
|
||||
<AsyncRenderer data={entries} loading={loading} error={error}>
|
||||
<Table data={entries} />
|
||||
</AsyncRenderer>
|
||||
);
|
||||
};
|
||||
|
||||
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>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { useTransfersQuery } from './__generated___/Transfers';
|
||||
|
||||
export const Transfers = () => {
|
||||
const { pubKey } = useVegaWallet();
|
||||
const { data, loading, error } = useTransfersQuery({
|
||||
variables: { partyId: pubKey || '' },
|
||||
skip: !pubKey,
|
||||
});
|
||||
console.log(data);
|
||||
return (
|
||||
<AsyncRenderer data={data} loading={loading} error={error}>
|
||||
<Table data={data} />
|
||||
</AsyncRenderer>
|
||||
);
|
||||
};
|
||||
|
||||
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));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user