Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8173d79b3f | ||
|
|
9d410099fa | ||
|
|
6e07aabca2 | ||
|
|
739b701905 | ||
|
|
a7a2abb1c0 | ||
|
|
4f8e8c1f7a | ||
|
|
30487791da | ||
|
|
106b040977 | ||
|
|
bf84b04a30 | ||
|
|
9f442698a4 |
No files matched your search
@@ -10,6 +10,8 @@
|
||||
"governance.proposal.updateMarket.minVoterBalance",
|
||||
"governance.proposal.updateNetParam.minProposerBalance",
|
||||
"governance.proposal.updateNetParam.minVoterBalance",
|
||||
"governance.proposal.updateAsset.minProposerBalance",
|
||||
"governance.proposal.updateAsset.minVoterBalance",
|
||||
"reward.staking.delegation.maxPayoutPerEpoch",
|
||||
"reward.staking.delegation.maxPayoutPerParticipant",
|
||||
"reward.staking.delegation.minimumValidatorStake",
|
||||
@@ -19,9 +21,6 @@
|
||||
"validators.delegation.minAmount"
|
||||
],
|
||||
"fiveDecimal": [
|
||||
"governance.proposal.updateAsset.minProposerBalance",
|
||||
"governance.proposal.updateAsset.minVoterBalance",
|
||||
"governance.proposal.updateAsset.requiredParticipation",
|
||||
"market.fee.factors.infrastructureFee",
|
||||
"market.fee.factors.makerFee",
|
||||
"market.liquidity.bondPenaltyParameter",
|
||||
@@ -77,6 +76,7 @@
|
||||
"governance.proposal.updateNetParam.requiredMajority",
|
||||
"governance.proposal.updateNetParam.requiredParticipation",
|
||||
"governance.proposal.updateMarket.minProposerEquityLikeShare",
|
||||
"governance.proposal.updateAsset.requiredParticipation",
|
||||
"validators.vote.required"
|
||||
],
|
||||
"duration": [
|
||||
|
||||
@@ -21,6 +21,7 @@ import { useDocumentTitle } from '../../hooks/use-document-title';
|
||||
const PERCENTAGE_PARAMS = [
|
||||
'governance.proposal.asset.requiredMajority',
|
||||
'governance.proposal.asset.requiredParticipation',
|
||||
'governance.proposal.updateAsset.requiredParticipation',
|
||||
'governance.proposal.freeform.requiredMajority',
|
||||
'governance.proposal.freeform.requiredParticipation',
|
||||
'governance.proposal.market.requiredMajority',
|
||||
|
||||
@@ -21,10 +21,10 @@ export const useGetUserBalances = (account: string | undefined) => {
|
||||
token.allowance(account, config.staking_bridge_contract.address),
|
||||
]);
|
||||
|
||||
const balance = toBigNum(b, decimals);
|
||||
const walletBalance = toBigNum(w, decimals);
|
||||
const lien = toBigNum(stats.lien, decimals);
|
||||
const allowance = toBigNum(a, decimals);
|
||||
const balance = toBigNum(b.toString(), decimals);
|
||||
const walletBalance = toBigNum(w.toString(), decimals);
|
||||
const lien = toBigNum(stats.lien.toString(), decimals);
|
||||
const allowance = toBigNum(a.toString(), decimals);
|
||||
|
||||
return {
|
||||
balanceFormatted: balance,
|
||||
|
||||
@@ -21,8 +21,14 @@ export function useRefreshAssociatedBalances() {
|
||||
]);
|
||||
|
||||
updateBalances({
|
||||
walletAssociatedBalance: toBigNum(walletAssociatedBalance, decimals),
|
||||
vestingAssociatedBalance: toBigNum(vestingAssociatedBalance, decimals),
|
||||
walletAssociatedBalance: toBigNum(
|
||||
walletAssociatedBalance.toString(),
|
||||
decimals
|
||||
),
|
||||
vestingAssociatedBalance: toBigNum(
|
||||
vestingAssociatedBalance.toString(),
|
||||
decimals
|
||||
),
|
||||
});
|
||||
},
|
||||
[staking, vesting, updateBalances, decimals]
|
||||
|
||||
@@ -31,12 +31,18 @@ export const useRefreshBalances = (address: string) => {
|
||||
pubKey ? vesting.stake_balance(address, pubKey) : null,
|
||||
]);
|
||||
|
||||
const balance = toBigNum(b, decimals);
|
||||
const walletBalance = toBigNum(w, decimals);
|
||||
const lien = toBigNum(stats.lien, decimals);
|
||||
const allowance = toBigNum(a, decimals);
|
||||
const walletAssociatedBalance = toBigNum(walletStakeBalance, decimals);
|
||||
const vestingAssociatedBalance = toBigNum(vestingStakeBalance, decimals);
|
||||
const balance = toBigNum(b.toString(), decimals);
|
||||
const walletBalance = toBigNum(w.toString(), decimals);
|
||||
const lien = toBigNum(stats.lien.toString(), decimals);
|
||||
const allowance = toBigNum(a.toString(), decimals);
|
||||
const walletAssociatedBalance = toBigNum(
|
||||
walletStakeBalance ? walletStakeBalance.toString() : 0,
|
||||
decimals
|
||||
);
|
||||
const vestingAssociatedBalance = toBigNum(
|
||||
vestingStakeBalance ? vestingStakeBalance.toString() : 0,
|
||||
decimals
|
||||
);
|
||||
|
||||
updateBalances({
|
||||
balanceFormatted: balance,
|
||||
|
||||
@@ -34,8 +34,9 @@ export const useUserTrancheBalances = (address: string | undefined) => {
|
||||
vesting.get_vested_for_tranche(address, tId),
|
||||
]);
|
||||
|
||||
const total = toBigNum(t, decimals);
|
||||
const vested = toBigNum(v, decimals);
|
||||
// Convert t and v EthersBigNumbers to regular BigNumbers
|
||||
const total = toBigNum(t.toString(), decimals);
|
||||
const vested = toBigNum(v.toString(), decimals);
|
||||
|
||||
return {
|
||||
id: tId,
|
||||
|
||||
@@ -54,7 +54,7 @@ export const WalletAssociate = ({
|
||||
address,
|
||||
ethereumConfig.staking_bridge_contract.address
|
||||
);
|
||||
const allowance = toBigNum(a, decimals);
|
||||
const allowance = toBigNum(a.toString(), decimals);
|
||||
setAllowance(allowance);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
"tranche_end": "2023-05-20T00:00:00.000Z",
|
||||
"total_added": "19242.125",
|
||||
"total_removed": "1523.8177488329475",
|
||||
"locked_amount": "7371.31511443865825548625",
|
||||
"locked_amount": "7212.6566671006941451225",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "188",
|
||||
@@ -4861,7 +4861,7 @@
|
||||
"tranche_end": "2023-12-05T00:00:00.000Z",
|
||||
"total_added": "86666.297",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "49979.7329096604869903443",
|
||||
"locked_amount": "49920.9990150801905814456",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "86666.297",
|
||||
@@ -4927,7 +4927,7 @@
|
||||
"tranche_end": "2023-06-01T00:00:00.000Z",
|
||||
"total_added": "2500",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "322.698698870573775",
|
||||
"locked_amount": "319.3008814102563",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "2500",
|
||||
@@ -4960,7 +4960,7 @@
|
||||
"tranche_end": "2023-11-01T00:00:00.000Z",
|
||||
"total_added": "15000.000000000000015",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "14387.9727128623185143879727128623185",
|
||||
"locked_amount": "14367.8074048913055143678074048913055",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "1.5e-14",
|
||||
@@ -5048,7 +5048,7 @@
|
||||
"tranche_end": "2023-09-01T00:00:00.000Z",
|
||||
"total_added": "17500",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "10984.33773022342925",
|
||||
"locked_amount": "10960.81153759058075",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "12500",
|
||||
@@ -5315,7 +5315,7 @@
|
||||
"tranche_end": "2023-08-01T00:00:00.000Z",
|
||||
"total_added": "37500",
|
||||
"total_removed": "18077.0118744",
|
||||
"locked_amount": "17505.34501611418125",
|
||||
"locked_amount": "17454.09616712707275",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "7500",
|
||||
@@ -5734,7 +5734,7 @@
|
||||
"tranche_end": "2023-12-05T00:00:00.000Z",
|
||||
"total_added": "129999.45",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "49934.132692071551825937",
|
||||
"locked_amount": "49875.452384779875914865",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "129999.45",
|
||||
@@ -5767,7 +5767,7 @@
|
||||
"tranche_end": "2024-04-01T00:00:00.000Z",
|
||||
"total_added": "54144.7663",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "48596.0321414648663214997",
|
||||
"locked_amount": "48559.43839951727367721104",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "54144.7663",
|
||||
@@ -5800,7 +5800,7 @@
|
||||
"tranche_end": "2023-09-03T00:00:00.000Z",
|
||||
"total_added": "62600",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "20150.76253805175029",
|
||||
"locked_amount": "20108.33841324200696",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "10000",
|
||||
@@ -5993,7 +5993,7 @@
|
||||
"tranche_end": "2023-09-17T00:00:00.000Z",
|
||||
"total_added": "5000",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "1801.26664764079125",
|
||||
"locked_amount": "1797.8781392694065",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "5000",
|
||||
@@ -7062,7 +7062,7 @@
|
||||
"tranche_end": "2023-06-02T00:00:00.000Z",
|
||||
"total_added": "1939928.38",
|
||||
"total_removed": "1709370.7872515768348",
|
||||
"locked_amount": "130174.32462609789781957",
|
||||
"locked_amount": "128859.6319149943131426072",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "1852091.69",
|
||||
@@ -40934,7 +40934,7 @@
|
||||
"tranche_end": "2023-06-05T00:00:00.000Z",
|
||||
"total_added": "3732368.4671",
|
||||
"total_removed": "715655.108029600523393",
|
||||
"locked_amount": "224533.9397934779571663606186",
|
||||
"locked_amount": "222513.620297182261029038238",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "1998.95815",
|
||||
@@ -42327,7 +42327,7 @@
|
||||
"tranche_end": "2023-12-05T00:00:00.000Z",
|
||||
"total_added": "15870102.715470999700000001",
|
||||
"total_removed": "871680.07831804700259352",
|
||||
"locked_amount": "6095870.51969169065811272227952994009813466",
|
||||
"locked_amount": "6088706.59647473650614127721578713908867263",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "16249.93",
|
||||
@@ -59070,7 +59070,7 @@
|
||||
"tranche_end": "2023-06-05T00:00:00.000Z",
|
||||
"total_added": "472355.6199999996",
|
||||
"total_removed": "44479.0535455583416",
|
||||
"locked_amount": "35578.671272696564429696212379508",
|
||||
"locked_amount": "35258.555078168385972699682090332",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "3000",
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
formatNumberPercentage,
|
||||
} from '@vegaprotocol/utils';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { updateGridData } from '@vegaprotocol/react-helpers';
|
||||
import { updateGridData } from '@vegaprotocol/datagrid';
|
||||
import {
|
||||
NetworkParams,
|
||||
useNetworkParams,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { AsyncRenderer, Button } from '@vegaprotocol/ui-toolkit';
|
||||
import { useDepositDialog, DepositsTable } from '@vegaprotocol/deposits';
|
||||
import { depositsProvider } from '@vegaprotocol/deposits';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { useBottomPlaceholder } from '@vegaprotocol/react-helpers';
|
||||
import { useBottomPlaceholder } from '@vegaprotocol/datagrid';
|
||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { useRef } from 'react';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useRef, useMemo, memo, useCallback } from 'react';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { useBottomPlaceholder } from '@vegaprotocol/react-helpers';
|
||||
import { useBottomPlaceholder } from '@vegaprotocol/datagrid';
|
||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
||||
import type { AgGridReact } from 'ag-grid-react';
|
||||
|
||||
@@ -9,9 +9,8 @@ declare global {
|
||||
}
|
||||
|
||||
export function addGetNetworkParameters() {
|
||||
// @ts-ignore - ignoring Cypress type error which gets resolved when Cypress uses the command
|
||||
Cypress.Commands.add('get_network_parameters', () => {
|
||||
const mutation = `
|
||||
const query = `
|
||||
{
|
||||
networkParametersConnection {
|
||||
edges {
|
||||
@@ -26,17 +25,17 @@ export function addGetNetworkParameters() {
|
||||
method: 'POST',
|
||||
url: `http://localhost:3008/graphql`,
|
||||
body: {
|
||||
query: mutation,
|
||||
query,
|
||||
},
|
||||
headers: { 'content-type': 'application/json' },
|
||||
})
|
||||
.its('body.data.networkParametersConnection.edges')
|
||||
.then(function (response) {
|
||||
// @ts-ignore - ignoring Cypress type error which gets resolved when Cypress uses the command
|
||||
const object = response.reduce(function (r, e) {
|
||||
const { value, key } = e.node;
|
||||
r[key] = value;
|
||||
return r;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const object = response.reduce(function (obj: any, edge: any) {
|
||||
const { value, key } = edge.node;
|
||||
obj[key] = value;
|
||||
return obj;
|
||||
}, {});
|
||||
return cy.wrap(object);
|
||||
});
|
||||
|
||||
@@ -10,6 +10,7 @@ export * from './lib/cells/vol-cell';
|
||||
export * from './lib/cells/centered-grid-cell';
|
||||
export * from './lib/cells/market-name-cell';
|
||||
export * from './lib/cells/order-type-cell';
|
||||
export * from './lib/cells/size';
|
||||
|
||||
export * from './lib/filters/date-range-filter';
|
||||
export * from './lib/filters/set-filter';
|
||||
@@ -18,3 +19,6 @@ export * from './lib/cell-class-rules';
|
||||
export * from './lib/type-helpers';
|
||||
|
||||
export * from './lib/cells/grid-progress-bar';
|
||||
|
||||
export * from './lib/ag-grid-update';
|
||||
export * from './lib/use-bottom-placeholder';
|
||||
+2
-12
@@ -1,7 +1,8 @@
|
||||
import type { MutableRefObject, RefObject } from 'react';
|
||||
import type { AgGridReact } from 'ag-grid-react';
|
||||
import type { IGetRowsParams } from 'ag-grid-community';
|
||||
|
||||
type AnyArray = Array<any> | null; // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
|
||||
export const isXOrWasEmpty = (prev?: AnyArray, curr?: AnyArray) =>
|
||||
Boolean(Number(!!prev?.length) ^ Number(!!curr?.length));
|
||||
|
||||
@@ -17,14 +18,3 @@ export const updateGridData = (
|
||||
}
|
||||
return !rerender;
|
||||
};
|
||||
|
||||
export const makeGetRows =
|
||||
(dataRef: MutableRefObject<AnyArray>) =>
|
||||
() =>
|
||||
async ({ successCallback, startRow, endRow }: IGetRowsParams) => {
|
||||
const rowsThisBlock = dataRef.current
|
||||
? dataRef.current.slice(startRow, endRow)
|
||||
: [];
|
||||
const lastRow = dataRef.current ? dataRef.current.length : 0;
|
||||
successCallback(rowsThisBlock, lastRow);
|
||||
};
|
||||
File renamed without changes.
File renamed without changes.
@@ -6,7 +6,7 @@ import { FillsTable } from './fills-table';
|
||||
import type { BodyScrollEvent, BodyScrollEndEvent } from 'ag-grid-community';
|
||||
import { useFillsList } from './use-fills-list';
|
||||
import type { Trade } from './fills-data-provider';
|
||||
import { useBottomPlaceholder } from '@vegaprotocol/react-helpers';
|
||||
import { useBottomPlaceholder } from '@vegaprotocol/datagrid';
|
||||
|
||||
interface FillsManagerProps {
|
||||
partyId: string;
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { RefObject } from 'react';
|
||||
import type { AgGridReact } from 'ag-grid-react';
|
||||
import { useCallback, useRef } from 'react';
|
||||
import { makeInfiniteScrollGetRows } from '@vegaprotocol/data-provider';
|
||||
import { updateGridData } from '@vegaprotocol/react-helpers';
|
||||
import { updateGridData } from '@vegaprotocol/datagrid';
|
||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||
import type { Trade, TradeEdge } from './fills-data-provider';
|
||||
import { fillsWithMarketProvider } from './fills-data-provider';
|
||||
|
||||
@@ -3,7 +3,7 @@ import { assetsProvider } from '@vegaprotocol/assets';
|
||||
import type { Market } from '@vegaprotocol/market-list';
|
||||
import { marketsProvider } from '@vegaprotocol/market-list';
|
||||
import { makeInfiniteScrollGetRows } from '@vegaprotocol/data-provider';
|
||||
import { updateGridData } from '@vegaprotocol/react-helpers';
|
||||
import { updateGridData } from '@vegaprotocol/datagrid';
|
||||
import {
|
||||
makeDataProvider,
|
||||
makeDerivedDataProvider,
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { GridReadyEvent, FilterChangedEvent } from 'ag-grid-community';
|
||||
|
||||
import { OrderListTable } from '../order-list/order-list';
|
||||
import { useHasAmendableOrder } from '../../order-hooks/use-has-amendable-order';
|
||||
import { useBottomPlaceholder } from '@vegaprotocol/react-helpers';
|
||||
import { useBottomPlaceholder } from '@vegaprotocol/datagrid';
|
||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||
import { ordersWithMarketProvider } from '../order-data-provider/order-data-provider';
|
||||
import {
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
validateAmount,
|
||||
} from '@vegaprotocol/utils';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { Size } from '@vegaprotocol/react-helpers';
|
||||
import { Size } from '@vegaprotocol/datagrid';
|
||||
import * as Schema from '@vegaprotocol/types';
|
||||
import {
|
||||
FormGroup,
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { AgGridReact } from 'ag-grid-react';
|
||||
import * as Schema from '@vegaprotocol/types';
|
||||
import { useVegaTransactionStore } from '@vegaprotocol/wallet';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { useBottomPlaceholder } from '@vegaprotocol/react-helpers';
|
||||
import { useBottomPlaceholder } from '@vegaprotocol/datagrid';
|
||||
|
||||
interface PositionsManagerProps {
|
||||
partyId: string;
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { AgGridReact } from 'ag-grid-react';
|
||||
import type { Position } from './positions-data-providers';
|
||||
import { positionsMetricsProvider } from './positions-data-providers';
|
||||
import type { PositionsQueryVariables } from './__generated__/Positions';
|
||||
import { updateGridData } from '@vegaprotocol/react-helpers';
|
||||
import { updateGridData } from '@vegaprotocol/datagrid';
|
||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||
import type { GetRowsParams } from '@vegaprotocol/datagrid';
|
||||
import isEqual from 'lodash/isEqual';
|
||||
|
||||
@@ -9,9 +9,13 @@
|
||||
"error",
|
||||
"@apollo/client",
|
||||
"@vegaprotocol/data-provider",
|
||||
"ag-grid-react",
|
||||
"ag-grid-community",
|
||||
"graphql",
|
||||
"graphql-tag",
|
||||
"graphql-ws"
|
||||
"graphql-ws",
|
||||
"ethers",
|
||||
"@ethersproject"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export * from './use-apply-grid-transaction';
|
||||
export * from './use-fetch';
|
||||
export * from './use-local-storage';
|
||||
export * from './use-mutation-observer';
|
||||
@@ -13,5 +12,4 @@ export * from './use-storybook-theme-observer';
|
||||
export * from './use-yesterday';
|
||||
export * from './use-previous';
|
||||
export * from './use-logger';
|
||||
export * from './use-bottom-placeholder';
|
||||
export * from './use-pane-layout';
|
||||
@@ -1,74 +0,0 @@
|
||||
import { useApplyGridTransaction } from './use-apply-grid-transaction';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
|
||||
type Items = Array<{ id: string; value: number }>;
|
||||
|
||||
const item = {
|
||||
id: '1',
|
||||
value: 1,
|
||||
};
|
||||
const item2 = {
|
||||
id: '2',
|
||||
value: 2,
|
||||
};
|
||||
const items = [item, item2];
|
||||
|
||||
function setup(items: Items, rowNodes: Items) {
|
||||
const gridApiMock = {
|
||||
applyTransaction: jest.fn(),
|
||||
getRowNode: (id: string) => {
|
||||
const node = rowNodes.find((i) => i.id === id);
|
||||
if (node) {
|
||||
return { data: node };
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
renderHook(() => useApplyGridTransaction(items, gridApiMock as any));
|
||||
return gridApiMock;
|
||||
}
|
||||
|
||||
it('Adds items', () => {
|
||||
const gridApiMock = setup(items, []);
|
||||
expect(gridApiMock.applyTransaction).toHaveBeenCalledWith({
|
||||
update: [],
|
||||
add: items,
|
||||
addIndex: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('Doesnt update rows without changes', () => {
|
||||
const rowNodes: Array<{ id: string; value: number }> = [...items];
|
||||
const gridApiMock = setup(items, rowNodes);
|
||||
expect(gridApiMock.applyTransaction).toHaveBeenCalledWith({
|
||||
update: [],
|
||||
add: [],
|
||||
addIndex: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('Update rows with changes', () => {
|
||||
const rowNodes = [...items];
|
||||
const updatedItems = [
|
||||
{ id: '1', value: 10 },
|
||||
{ id: '2', value: 20 },
|
||||
];
|
||||
const gridApiMock = setup(updatedItems, rowNodes);
|
||||
expect(gridApiMock.applyTransaction).toHaveBeenCalledWith({
|
||||
update: updatedItems,
|
||||
add: [],
|
||||
addIndex: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('Updates and adds at the same time', () => {
|
||||
const newItem = { id: '3', value: 3 };
|
||||
const updatedItem = { id: '2', value: 20 };
|
||||
const gridApiMock = setup([newItem, updatedItem], [...items]);
|
||||
expect(gridApiMock.applyTransaction).toHaveBeenCalledWith({
|
||||
update: [updatedItem],
|
||||
add: [newItem],
|
||||
addIndex: 0,
|
||||
});
|
||||
});
|
||||
@@ -1,36 +0,0 @@
|
||||
import type { GridApi } from 'ag-grid-community';
|
||||
import { useEffect } from 'react';
|
||||
import isEqual from 'lodash/isEqual';
|
||||
|
||||
export const useApplyGridTransaction = <T extends { id: string }>(
|
||||
data: T[],
|
||||
gridApi: GridApi | null
|
||||
) => {
|
||||
useEffect(() => {
|
||||
if (!gridApi) return;
|
||||
|
||||
const update: T[] = [];
|
||||
const add: T[] = [];
|
||||
|
||||
// split into updates and adds
|
||||
data.forEach((d) => {
|
||||
if (!gridApi) return;
|
||||
|
||||
const rowNode = gridApi.getRowNode(d.id);
|
||||
|
||||
if (rowNode) {
|
||||
if (!isEqual(rowNode.data, d)) {
|
||||
update.push(d);
|
||||
}
|
||||
} else {
|
||||
add.push(d);
|
||||
}
|
||||
});
|
||||
|
||||
gridApi.applyTransaction({
|
||||
update,
|
||||
add,
|
||||
addIndex: 0,
|
||||
});
|
||||
}, [data, gridApi]);
|
||||
};
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './size';
|
||||
export * from './summary-rows';
|
||||
@@ -1,75 +0,0 @@
|
||||
import type { GridApi, ColumnApi } from 'ag-grid-community';
|
||||
import { addSummaryRows } from './summary-rows';
|
||||
|
||||
type RowMock = { group: string; count: string };
|
||||
|
||||
const getGroupId = jest.fn();
|
||||
getGroupId.mockImplementation(
|
||||
(data: { group: string; __summaryRow: boolean }) =>
|
||||
data.__summaryRow ? null : data.group
|
||||
);
|
||||
const getGroupSummaryRow = jest.fn();
|
||||
getGroupSummaryRow.mockImplementation(
|
||||
(data: RowMock[]): Partial<RowMock> | null => {
|
||||
if (!data.length) {
|
||||
return null;
|
||||
}
|
||||
const row: Partial<RowMock> = {
|
||||
count: data.reduce((a, c) => a + parseFloat(c.count), 0).toString(),
|
||||
};
|
||||
return row;
|
||||
}
|
||||
);
|
||||
|
||||
const api = {
|
||||
forEachNodeAfterFilterAndSort: jest.fn(),
|
||||
applyTransactionAsync: jest.fn(),
|
||||
};
|
||||
|
||||
const columnsApi = {};
|
||||
|
||||
describe('addSummaryRows', () => {
|
||||
it('should render search input and button', () => {
|
||||
const nodes = [
|
||||
{ data: { group: 'a', count: 10 } },
|
||||
{ data: { group: 'a', count: 10, __summaryRow: true } },
|
||||
{ data: { group: 'a', count: 20 } },
|
||||
{ data: { group: 'b', count: 30 } },
|
||||
{ data: { group: 'c', count: 40 } },
|
||||
{ data: { group: 'c', count: 50 } },
|
||||
{ data: { group: 'c', count: 60 } },
|
||||
{ data: { group: 'd', count: 10, __summaryRow: true } },
|
||||
{ data: { group: 'd', count: 70 } },
|
||||
{ data: { group: 'd', count: 80 } },
|
||||
];
|
||||
api.forEachNodeAfterFilterAndSort.mockImplementationOnce(
|
||||
nodes.forEach.bind(nodes)
|
||||
);
|
||||
addSummaryRows(
|
||||
api as unknown as GridApi,
|
||||
columnsApi as unknown as ColumnApi,
|
||||
getGroupId,
|
||||
getGroupSummaryRow
|
||||
);
|
||||
expect(api.forEachNodeAfterFilterAndSort).toBeCalledTimes(1);
|
||||
expect(api.applyTransactionAsync).toBeCalledTimes(5);
|
||||
expect(api.applyTransactionAsync).toHaveBeenNthCalledWith(1, {
|
||||
remove: [nodes[1].data],
|
||||
});
|
||||
expect(api.applyTransactionAsync).toHaveBeenNthCalledWith(2, {
|
||||
add: [{ count: '30' }],
|
||||
addIndex: 2,
|
||||
});
|
||||
expect(api.applyTransactionAsync).toHaveBeenNthCalledWith(3, {
|
||||
remove: [nodes[7].data],
|
||||
});
|
||||
expect(api.applyTransactionAsync).toHaveBeenNthCalledWith(4, {
|
||||
add: [{ count: '150' }],
|
||||
addIndex: 7,
|
||||
});
|
||||
expect(api.applyTransactionAsync).toHaveBeenNthCalledWith(5, {
|
||||
add: [{ count: '150' }],
|
||||
addIndex: 10,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,47 +0,0 @@
|
||||
import type { ColumnApi, GridApi } from 'ag-grid-community';
|
||||
|
||||
export interface SummaryRow {
|
||||
__summaryRow?: boolean;
|
||||
}
|
||||
|
||||
export function addSummaryRows<T extends SummaryRow>(
|
||||
api: GridApi,
|
||||
columnApi: ColumnApi,
|
||||
getGroupId: (data: T, columnApi: ColumnApi) => string | null | undefined,
|
||||
getGroupSummaryRow: (data: T[], columnApi: ColumnApi) => Partial<T> | null
|
||||
) {
|
||||
let currentGroupId: string | null | undefined = undefined;
|
||||
let group: T[] = [];
|
||||
let addIndex = 0;
|
||||
api.forEachNodeAfterFilterAndSort((node) => {
|
||||
const nodeGroupId = getGroupId(node.data, columnApi);
|
||||
if (currentGroupId === undefined) {
|
||||
currentGroupId = nodeGroupId;
|
||||
}
|
||||
if (node.data.__summaryRow) {
|
||||
api.applyTransactionAsync({
|
||||
remove: [node.data],
|
||||
});
|
||||
addIndex -= 1;
|
||||
} else if (currentGroupId !== undefined && currentGroupId !== nodeGroupId) {
|
||||
if (group.length > 1) {
|
||||
api.applyTransactionAsync({
|
||||
add: [getGroupSummaryRow(group, columnApi)],
|
||||
addIndex,
|
||||
});
|
||||
addIndex += 1;
|
||||
}
|
||||
group = [node.data];
|
||||
currentGroupId = nodeGroupId;
|
||||
} else if (currentGroupId) {
|
||||
group.push(node.data);
|
||||
}
|
||||
addIndex += 1;
|
||||
});
|
||||
if (group.length > 1) {
|
||||
api.applyTransactionAsync({
|
||||
add: [getGroupSummaryRow(group, columnApi)],
|
||||
addIndex,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,2 @@
|
||||
export * from './ag-grid-update';
|
||||
export * from './format';
|
||||
export * from './grid';
|
||||
export * from './validation';
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ethers } from 'ethers';
|
||||
import abi from '../abis/staking_abi.json';
|
||||
import { calcGasBuffer, prepend0x } from '../utils';
|
||||
import type { BigNumber as EthersBigNum } from 'ethers';
|
||||
|
||||
export class StakingBridge {
|
||||
public contract: ethers.Contract;
|
||||
@@ -51,7 +52,7 @@ export class StakingBridge {
|
||||
staking_token() {
|
||||
return this.contract.staking_token();
|
||||
}
|
||||
stake_balance(target: string, vegaPublicKey: string) {
|
||||
stake_balance(target: string, vegaPublicKey: string): Promise<EthersBigNum> {
|
||||
return this.contract.stake_balance(target, prepend0x(vegaPublicKey));
|
||||
}
|
||||
total_staked() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ethers } from 'ethers';
|
||||
import abi from '../abis/vesting_abi.json';
|
||||
import { calcGasBuffer, prepend0x } from '../utils';
|
||||
import type { BigNumber as EthersBigNum } from 'ethers';
|
||||
|
||||
export class TokenVesting {
|
||||
public contract: ethers.Contract;
|
||||
@@ -29,13 +30,15 @@ export class TokenVesting {
|
||||
gasLimit,
|
||||
});
|
||||
}
|
||||
stake_balance(address: string, vegaPublicKey: string) {
|
||||
stake_balance(address: string, vegaPublicKey: string): Promise<EthersBigNum> {
|
||||
return this.contract.stake_balance(address, prepend0x(vegaPublicKey));
|
||||
}
|
||||
total_staked() {
|
||||
return this.contract.total_staked();
|
||||
}
|
||||
user_stats(address: string) {
|
||||
user_stats(
|
||||
address: string
|
||||
): Promise<{ lien: EthersBigNum; total_in_all_tranches: EthersBigNum }> {
|
||||
return this.contract.user_stats(address);
|
||||
}
|
||||
get_tranche_balance(address: string, trancheId: number) {
|
||||
@@ -44,7 +47,7 @@ export class TokenVesting {
|
||||
get_vested_for_tranche(address: string, trancheId: number) {
|
||||
return this.contract.get_vested_for_tranche(address, trancheId);
|
||||
}
|
||||
user_total_all_tranches(address: string) {
|
||||
user_total_all_tranches(address: string): Promise<EthersBigNum> {
|
||||
return this.contract.user_total_all_tranches(address);
|
||||
}
|
||||
async withdraw_from_tranche(trancheId: number) {
|
||||
|
||||
@@ -9,9 +9,13 @@
|
||||
"error",
|
||||
"@apollo/client",
|
||||
"@vegaprotocol/data-provider",
|
||||
"ag-grid-react",
|
||||
"ag-grid-community",
|
||||
"graphql",
|
||||
"graphql-tag",
|
||||
"graphql-ws"
|
||||
"graphql-ws",
|
||||
"ethers",
|
||||
"@ethersproject"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import { BigNumber as EthersBigNumber } from 'ethers';
|
||||
import isNil from 'lodash/isNil';
|
||||
import memoize from 'lodash/memoize';
|
||||
|
||||
@@ -15,16 +14,14 @@ export function toDecimal(numberOfDecimals: number) {
|
||||
}
|
||||
|
||||
export function toBigNum(
|
||||
rawValue: string | number | EthersBigNumber,
|
||||
rawValue: string | number,
|
||||
decimals: number
|
||||
): BigNumber {
|
||||
return new BigNumber(
|
||||
rawValue instanceof EthersBigNumber ? rawValue.toString() : rawValue || 0
|
||||
).dividedBy(Math.pow(10, decimals));
|
||||
return new BigNumber(rawValue || 0).dividedBy(Math.pow(10, decimals));
|
||||
}
|
||||
|
||||
export function addDecimal(
|
||||
value: string | number | EthersBigNumber,
|
||||
value: string | number,
|
||||
decimals: number,
|
||||
decimalPrecision = decimals
|
||||
): string {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { ethereumAddress, vegaPublicKey } from './common';
|
||||
|
||||
it('ethereumAddress', () => {
|
||||
const errorMessage = 'Invalid Ethereum address';
|
||||
|
||||
const validAddress = '0x72c22822A19D20DE7e426fB84aa047399Ddd8853';
|
||||
expect(ethereumAddress(validAddress)).toEqual(true);
|
||||
|
||||
const invalidChars = '0xzzc22822A19D20DE7e426fB84aa047399Ddd8853';
|
||||
expect(ethereumAddress(invalidChars)).toEqual(errorMessage);
|
||||
|
||||
const tooManyChars = '0x72c22822A19D20DE7e426fB84aa047399Ddd88531111111';
|
||||
expect(ethereumAddress(tooManyChars)).toEqual(errorMessage);
|
||||
|
||||
const no0x = '1x72c22822A19D20DE7e426fB84aa047399Ddd8853';
|
||||
expect(ethereumAddress(no0x)).toEqual(errorMessage);
|
||||
});
|
||||
|
||||
it('vegaPublicKey', () => {
|
||||
const errorMessage = 'Invalid Vega key';
|
||||
|
||||
const validKey =
|
||||
'70d14a321e02e71992fd115563df765000ccc4775cbe71a0e2f9ff5a3b9dc680';
|
||||
expect(vegaPublicKey(validKey)).toEqual(true);
|
||||
|
||||
const invalidChars =
|
||||
'zzz14a321e02e71992fd115563df765000ccc4775cbe71a0e2f9ff5a3b9dc680';
|
||||
expect(vegaPublicKey(invalidChars)).toEqual(errorMessage);
|
||||
|
||||
const tooManyChars =
|
||||
'70d14a321e02e71992fd115563df765000ccc4775cbe71a0e2f9ff5a3b9dc680111111';
|
||||
expect(vegaPublicKey(tooManyChars)).toEqual(errorMessage);
|
||||
});
|
||||
@@ -1,5 +1,4 @@
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { ethers } from 'ethers';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
|
||||
export const required = (value: string) => {
|
||||
@@ -10,14 +9,14 @@ export const required = (value: string) => {
|
||||
};
|
||||
|
||||
export const ethereumAddress = (value: string) => {
|
||||
if (!ethers.utils.isAddress(value)) {
|
||||
if (!/^0x[0-9a-fA-F]{40}$/i.test(value)) {
|
||||
return t('Invalid Ethereum address');
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
export const vegaPublicKey = (value: string) => {
|
||||
if (value.length !== 64 || !/^[A-Fa-f0-9]*$/i.test(value)) {
|
||||
if (!/^[A-Fa-f0-9]{64}$/i.test(value)) {
|
||||
return t('Invalid Vega key');
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -48,7 +48,7 @@ import {
|
||||
import { useMarketList } from '@vegaprotocol/market-list';
|
||||
import type { Side } from '@vegaprotocol/types';
|
||||
import { OrderStatusMapping } from '@vegaprotocol/types';
|
||||
import { Size } from '@vegaprotocol/react-helpers';
|
||||
import { Size } from '@vegaprotocol/datagrid';
|
||||
|
||||
const intentMap: { [s in VegaTxStatus]: Intent } = {
|
||||
Default: Intent.Primary,
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
isNumeric,
|
||||
truncateByChars,
|
||||
} from '@vegaprotocol/utils';
|
||||
import { useBottomPlaceholder } from '@vegaprotocol/react-helpers';
|
||||
import { useBottomPlaceholder } from '@vegaprotocol/datagrid';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { ButtonLink } from '@vegaprotocol/ui-toolkit';
|
||||
import type {
|
||||
|
||||
Reference in new issue
Block a user