vega-frontend-monorepo/libs/accounts/src/lib/accounts-data-provider.spec.ts

244 lines
6.2 KiB
TypeScript
Raw Normal View History

feat(#847): collateral table, add breakdown (#1442) * feat: #847 show progress bar, margin accounts, no used/deposited * feat: #847 add collateral tables * fix: #847 add deposit asset type and fix tests * feat: #847 show deposited value, avaliable and percentage used * fix: #847 add styling fixes * fix: #847 add deposit new asset button * fix: #847 remove disabledSelect to fix withdraw and deposit dialogs * fix: #847 remove global reward from incoming - needs to be party specific * fix: #847 integration tests * fix: #847 default select deposit & withdraw * fix: #847 default select deposit & withdraw * fix: #847 pass asset id as default value * fix: #847 use only bigint no bignumber, remove NaN check * fix: #847 update deposit-form.spec.tsx * fix: revert update on account fields * feat: add storybook set up * chore: ignore apollo errors - to be reverted after API will be fixed * fix: container moved, progress bar in helpers * fix: #847 UI tweaks around accounts container * feat: #847 added useDepositAsset and useWithdrawAsset * fix: #847 fix progress bar in accounts and positions * feat: #847 add storybook * fix: #847 added tooltip and updated filtering * chore: #847 add get account data test * fix: #847 fix lint and type in account story * fix: #847 update data provider * fix: #847 fix get account data dry & lp link * fix: #847 fix breakdown table test * fix: #847 account data provider test * fix: #847 remove deposit new asset button - subscription does not display a sset data * fix: #847 add defaultValue in select otherwise default is not set up * feat: #847 update data provider update method and tables * fix: #847 fix accounts tests * fix: #847 remove unused getRows * fix: add decimals * fix: #847 fix imports * fix: update ids * Update apps/trading/pages/liquidity/[marketId].page.tsx * fix: #847 accounts update method check delta * fix: #847 use vega value formatters and cell renderers * fix: #847 fix imports * fix: #847 handle new account else block comment * fix: accounts and breakdown tables * fix(#847): account data provider improvments * fix: #847 fix formatters null check and add param * fix: #847 fix withdraw test and mock the hook * fix: #847 fix console lite grid select market test * fix: console lite build * fix: revert withdraw limits * fix: remove redundant waitFor use vega cell renderer * fix: breakdown display only use accounts * fix: breakdown display only use accounts * fix: updated accounts table * fix: move update inside try useWithdrawAsset * fix: update trading-accounts test * fix: portfolio-page.test.ts Co-authored-by: Bartłomiej Głownia <bglownia@gmail.com>
2022-09-30 00:40:44 +00:00
import { AccountType } from '@vegaprotocol/types';
import type { AccountFields } from './accounts-data-provider';
import { getAccountData } from './accounts-data-provider';
import type { AccountFieldsFragment } from './__generated___/Accounts';
describe('getAccountData', () => {
it('should return the correct aggregated data', () => {
const data = getAccountData(accounts);
expect(data).toEqual(accountResult);
});
});
const accounts: AccountFieldsFragment[] = [
{
__typename: 'Account',
type: AccountType.ACCOUNT_TYPE_MARGIN,
balance: '2781397',
market: {
__typename: 'Market',
id: 'd90fd7c746286625504d7a3f5f420a280875acd3cd611676d9e70acc675f4540',
tradableInstrument: {
__typename: 'TradableInstrument',
instrument: {
__typename: 'Instrument',
name: 'Tesla Quarterly (30 Jun 2022)',
},
},
},
asset: {
__typename: 'Asset',
id: '8b52d4a3a4b0ffe733cddbc2b67be273816cfeb6ca4c8b339bac03ffba08e4e4',
symbol: 'tEURO',
decimals: 5,
},
},
{
__typename: 'Account',
type: AccountType.ACCOUNT_TYPE_MARGIN,
balance: '406922',
market: {
__typename: 'Market',
id: '9c1ee71959e566c484fcea796513137f8a02219cca2e973b7ae72dc29d099581',
tradableInstrument: {
__typename: 'TradableInstrument',
instrument: {
__typename: 'Instrument',
name: 'AAVEDAI Monthly (30 Jun 2022)',
},
},
},
asset: {
__typename: 'Asset',
id: '6d9d35f657589e40ddfb448b7ad4a7463b66efb307527fedd2aa7df1bbd5ea61',
symbol: 'tDAI',
decimals: 5,
},
},
{
__typename: 'Account',
type: AccountType.ACCOUNT_TYPE_GENERAL,
balance: '10001000000',
market: null,
asset: {
__typename: 'Asset',
id: 'XYZalpha',
symbol: 'XYZalpha',
decimals: 5,
},
},
{
__typename: 'Account',
type: AccountType.ACCOUNT_TYPE_GENERAL,
balance: '1990351587',
market: null,
asset: {
__typename: 'Asset',
id: '993ed98f4f770d91a796faab1738551193ba45c62341d20597df70fea6704ede',
symbol: 'tUSDC',
decimals: 5,
},
},
{
__typename: 'Account',
type: AccountType.ACCOUNT_TYPE_GENERAL,
balance: '2996218603',
market: null,
asset: {
__typename: 'Asset',
id: '8b52d4a3a4b0ffe733cddbc2b67be273816cfeb6ca4c8b339bac03ffba08e4e4',
symbol: 'tEURO',
decimals: 5,
},
},
{
__typename: 'Account',
type: AccountType.ACCOUNT_TYPE_GENERAL,
balance: '5000593078',
market: null,
asset: {
__typename: 'Asset',
id: '6d9d35f657589e40ddfb448b7ad4a7463b66efb307527fedd2aa7df1bbd5ea61',
symbol: 'tDAI',
decimals: 5,
},
},
{
__typename: 'Account',
type: AccountType.ACCOUNT_TYPE_GENERAL,
balance: '4000000000000001006031',
market: null,
asset: {
__typename: 'Asset',
id: '5cfa87844724df6069b94e4c8a6f03af21907d7bc251593d08e4251043ee9f7c',
symbol: 'tBTC',
decimals: 5,
},
},
];
const accountResult: AccountFields[] = [
{
asset: {
__typename: 'Asset',
decimals: 5,
id: '5cfa87844724df6069b94e4c8a6f03af21907d7bc251593d08e4251043ee9f7c',
symbol: 'tBTC',
},
available: '4000000000000001006031',
balance: '4000000000000001006031',
breakdown: [],
deposited: '4000000000000001006031',
type: AccountType.ACCOUNT_TYPE_GENERAL,
used: '0',
},
{
asset: {
__typename: 'Asset',
decimals: 5,
id: '6d9d35f657589e40ddfb448b7ad4a7463b66efb307527fedd2aa7df1bbd5ea61',
symbol: 'tDAI',
},
available: '5000593078',
balance: '5000593078',
breakdown: [
{
__typename: 'Account',
asset: {
__typename: 'Asset',
decimals: 5,
id: '6d9d35f657589e40ddfb448b7ad4a7463b66efb307527fedd2aa7df1bbd5ea61',
symbol: 'tDAI',
},
available: '5000593078',
balance: '406922',
deposited: '5001000000',
market: {
__typename: 'Market',
id: '9c1ee71959e566c484fcea796513137f8a02219cca2e973b7ae72dc29d099581',
tradableInstrument: {
__typename: 'TradableInstrument',
instrument: {
__typename: 'Instrument',
name: 'AAVEDAI Monthly (30 Jun 2022)',
},
},
},
type: AccountType.ACCOUNT_TYPE_MARGIN,
used: '406922',
},
],
deposited: '5001000000',
type: AccountType.ACCOUNT_TYPE_GENERAL,
used: '406922',
},
{
asset: {
__typename: 'Asset',
decimals: 5,
id: '8b52d4a3a4b0ffe733cddbc2b67be273816cfeb6ca4c8b339bac03ffba08e4e4',
symbol: 'tEURO',
},
available: '2996218603',
balance: '2996218603',
breakdown: [
{
__typename: 'Account',
asset: {
__typename: 'Asset',
decimals: 5,
id: '8b52d4a3a4b0ffe733cddbc2b67be273816cfeb6ca4c8b339bac03ffba08e4e4',
symbol: 'tEURO',
},
available: '2996218603',
balance: '2781397',
deposited: '2999000000',
market: {
__typename: 'Market',
id: 'd90fd7c746286625504d7a3f5f420a280875acd3cd611676d9e70acc675f4540',
tradableInstrument: {
__typename: 'TradableInstrument',
instrument: {
__typename: 'Instrument',
name: 'Tesla Quarterly (30 Jun 2022)',
},
},
},
type: AccountType.ACCOUNT_TYPE_MARGIN,
used: '2781397',
},
],
deposited: '2999000000',
type: AccountType.ACCOUNT_TYPE_GENERAL,
used: '2781397',
},
{
asset: {
__typename: 'Asset',
decimals: 5,
id: '993ed98f4f770d91a796faab1738551193ba45c62341d20597df70fea6704ede',
symbol: 'tUSDC',
},
available: '1990351587',
balance: '1990351587',
breakdown: [],
deposited: '1990351587',
type: AccountType.ACCOUNT_TYPE_GENERAL,
used: '0',
},
{
asset: {
__typename: 'Asset',
decimals: 5,
id: 'XYZalpha',
symbol: 'XYZalpha',
},
available: '10001000000',
balance: '10001000000',
breakdown: [],
deposited: '10001000000',
type: AccountType.ACCOUNT_TYPE_GENERAL,
used: '0',
},
];