Compare commits

...
Author SHA1 Message Date
Madalina Raicu 3eb41aec13 fix(trading): update fills type 2023-03-06 15:50:34 +00:00
Madalina Raicu 78e33f08c4 fix(trading): remove trading mode column 2023-03-06 15:42:56 +00:00
Madalina Raicu c9304ce2b4 fix(trading): fix fills-table test 2023-03-06 15:25:20 +00:00
Madalina Raicu 062146920d fix(trading): add fills fee breakdown tests 2023-03-06 15:12:56 +00:00
Madalina Raicu 6a02792d8b fix(trading): fills table fees display 2023-03-02 21:31:39 +00:00
dexturr a8401d4c6f chore: update tranches
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-02 12:07:58 +00:00
Maciek c030264211 chore(react-helpers): improve error catching in useResizeObserver (#3058) 2023-03-02 10:32:42 +01:00
Maciek 068f7b3fc3 chore(trading): tweaking catching no market data error (#3044) 2023-03-02 08:25:57 +01:00
dexturr 4430f0c5f6 chore: update tranches
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-02 06:09:50 +00:00
dexturr 0a14000708 chore: update tranches
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-02 00:15:49 +00:00
Matthew Russell 9ca6fe3cbf fix(trading): env vars for validator testnet (#3061) 2023-03-01 10:08:45 -08:00
dexturr 4f96472375 chore: update tranches
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-01 18:07:09 +00:00
10 changed files with 341 additions and 130 deletions
+100 -34
View File
@@ -2761,7 +2761,7 @@
"tranche_end": "2023-12-05T00:00:00.000Z",
"total_added": "86666.297",
"total_removed": "0",
"locked_amount": "66126.2911732114998055325",
"locked_amount": "65888.8190337497085175298",
"deposits": [
{
"amount": "86666.297",
@@ -2827,7 +2827,7 @@
"tranche_end": "2023-06-01T00:00:00.000Z",
"total_added": "2500",
"total_removed": "0",
"locked_amount": "1256.794045075295",
"locked_amount": "1243.0560325091575",
"deposits": [
{
"amount": "2500",
@@ -2948,7 +2948,7 @@
"tranche_end": "2023-09-01T00:00:00.000Z",
"total_added": "17500",
"total_removed": "0",
"locked_amount": "17451.93268166264",
"locked_amount": "17356.8118772644925",
"deposits": [
{
"amount": "12500",
@@ -3215,7 +3215,7 @@
"tranche_end": "2023-08-01T00:00:00.000Z",
"total_added": "37500",
"total_removed": "3451.5629793",
"locked_amount": "31594.18642572130125",
"locked_amount": "31386.97772790055125",
"deposits": [
{
"amount": "7500",
@@ -3381,7 +3381,7 @@
"tranche_end": "2023-12-05T00:00:00.000Z",
"total_added": "129999.45",
"total_removed": "0",
"locked_amount": "66065.95925284494122844",
"locked_amount": "65828.703776830530732315",
"deposits": [
{
"amount": "129999.45",
@@ -3447,7 +3447,7 @@
"tranche_end": "2023-09-03T00:00:00.000Z",
"total_added": "62600",
"total_removed": "0",
"locked_amount": "31813.59552257737524",
"locked_amount": "31642.06683789954558",
"deposits": [
{
"amount": "10000",
@@ -3640,7 +3640,7 @@
"tranche_end": "2023-09-17T00:00:00.000Z",
"total_added": "5000",
"total_removed": "0",
"locked_amount": "2732.8028285134455",
"locked_amount": "2719.1024543378995",
"deposits": [
{
"amount": "5000",
@@ -3851,7 +3851,7 @@
"tranche_end": "2023-04-05T00:00:00.000Z",
"total_added": "97499.58",
"total_removed": "0",
"locked_amount": "8026.753327469502229788",
"locked_amount": "7794.0278068466617184238",
"deposits": [
{
"amount": "97499.58",
@@ -3884,7 +3884,7 @@
"tranche_end": "2023-04-05T00:00:00.000Z",
"total_added": "135173.4239508",
"total_removed": "98230.390980249184455396",
"locked_amount": "10971.186037499547718723312584",
"locked_amount": "10653.090429193107744542476008",
"deposits": [
{
"amount": "135173.4239508",
@@ -3930,7 +3930,7 @@
"tranche_end": "2023-04-05T00:00:00.000Z",
"total_added": "32499.86",
"total_removed": "0",
"locked_amount": "3376.7165102507267945488",
"locked_amount": "3278.8129026794692276046",
"deposits": [
{
"amount": "32499.86",
@@ -3963,7 +3963,7 @@
"tranche_end": "2023-04-05T00:00:00.000Z",
"total_added": "10833.29",
"total_removed": "0",
"locked_amount": "1099.0884572052014268704",
"locked_amount": "1067.221782974876983662",
"deposits": [
{
"amount": "10833.29",
@@ -3996,7 +3996,7 @@
"tranche_end": "2023-04-05T00:00:00.000Z",
"total_added": "22749.93",
"total_removed": "4720.860935375",
"locked_amount": "4108.63813000654408794",
"locked_amount": "3989.5133844404452945716",
"deposits": [
{
"amount": "6500",
@@ -4148,7 +4148,7 @@
"tranche_end": "2023-05-01T00:00:00.000Z",
"total_added": "22500",
"total_removed": "4988.60449275",
"locked_amount": "7520.047767034992",
"locked_amount": "7395.722548342542",
"deposits": [
{
"amount": "7500",
@@ -4434,7 +4434,7 @@
"tranche_end": "2023-06-02T00:00:00.000Z",
"total_added": "1939928.38",
"total_removed": "928642.9598472029154",
"locked_amount": "491597.019480432441937998",
"locked_amount": "486281.47054448047845174",
"deposits": [
{
"amount": "1852091.69",
@@ -36813,8 +36813,8 @@
"tranche_start": "2022-03-05T00:00:00.000Z",
"tranche_end": "2023-06-05T00:00:00.000Z",
"total_added": "3732368.4671",
"total_removed": "615950.831401702010493",
"locked_amount": "779914.787767187799364679587",
"total_removed": "618385.665327542135993",
"locked_amount": "771746.63973020695967996929",
"deposits": [
{
"amount": "1998.95815",
@@ -36983,6 +36983,11 @@
}
],
"withdrawals": [
{
"amount": "2434.8339258401255",
"user": "0xE6CacAE56Cca8dFdB7910b5A13578719D4E57DA0",
"tx": "0xcba878ae28c2c84219f8281dc2a57d0d9b6c99b7920900d5344c76aabe8f1e84"
},
{
"amount": "16659.576193025747093",
"user": "0xB523235B6c7C74DDB26b10E78bFb2d0Cb63Ae289",
@@ -37357,6 +37362,12 @@
}
],
"withdrawals": [
{
"amount": "2434.8339258401255",
"user": "0xE6CacAE56Cca8dFdB7910b5A13578719D4E57DA0",
"tranche_id": 1,
"tx": "0xcba878ae28c2c84219f8281dc2a57d0d9b6c99b7920900d5344c76aabe8f1e84"
},
{
"amount": "6293.20485405503",
"user": "0xE6CacAE56Cca8dFdB7910b5A13578719D4E57DA0",
@@ -37641,8 +37652,8 @@
}
],
"total_tokens": "187637.95",
"withdrawn_tokens": "146054.503703913043",
"remaining_tokens": "41583.446296086957"
"withdrawn_tokens": "148489.3376297531685",
"remaining_tokens": "39148.6123702468315"
},
{
"address": "0x1A71e3ED1996CAbB91bB043f880CE963D601707e",
@@ -38162,8 +38173,8 @@
"tranche_start": "2022-06-05T00:00:00.000Z",
"tranche_end": "2023-12-05T00:00:00.000Z",
"total_added": "15870102.715470999700000001",
"total_removed": "585442.32676055889219452",
"locked_amount": "8065215.3477477860118006909778900766450392",
"total_removed": "586757.93761874998960452",
"locked_amount": "8036251.6192538834556613842019307768004867",
"deposits": [
{
"amount": "16249.93",
@@ -38707,6 +38718,26 @@
"user": "0x20CD77B9FC2f1fEDfb6F184E25f7127BFE991C8b",
"tx": "0xb54d54fd5a6211e97495020ad17e9f045d032999ed94ea31994958304010aa85"
},
{
"amount": "133.7749515525265",
"user": "0xE6CacAE56Cca8dFdB7910b5A13578719D4E57DA0",
"tx": "0xed77ed534414a1949b1473707782223907e0ac001f899037ff822f10bd4a358a"
},
{
"amount": "261.60674662018875",
"user": "0x20CD77B9FC2f1fEDfb6F184E25f7127BFE991C8b",
"tx": "0xdbd9367c0d60c1bd9165752d8fab223aa43c7c2e85568a4e98e86ad0e0c97a01"
},
{
"amount": "394.58033601838216",
"user": "0xe3eB4CF43C072658401996b71D43eE26E573562D",
"tx": "0xe479984e1fc0f4a0040603b528c841013d6da2c890361ce5f4152256ea9dd009"
},
{
"amount": "525.648824",
"user": "0xF4c75FdbAe821C6B5DBB9f001bB23cBA58D1bA37",
"tx": "0x132a15c0b5f8c6016ac1a90437b9dca119ebc2479cde9c702327653fa3c11750"
},
{
"amount": "535.4042378778335",
"user": "0x20CD77B9FC2f1fEDfb6F184E25f7127BFE991C8b",
@@ -40500,6 +40531,12 @@
"tranche_id": 2,
"tx": "0xb54d54fd5a6211e97495020ad17e9f045d032999ed94ea31994958304010aa85"
},
{
"amount": "261.60674662018875",
"user": "0x20CD77B9FC2f1fEDfb6F184E25f7127BFE991C8b",
"tranche_id": 2,
"tx": "0xdbd9367c0d60c1bd9165752d8fab223aa43c7c2e85568a4e98e86ad0e0c97a01"
},
{
"amount": "535.4042378778335",
"user": "0x20CD77B9FC2f1fEDfb6F184E25f7127BFE991C8b",
@@ -41714,8 +41751,8 @@
}
],
"total_tokens": "259998.8875",
"withdrawn_tokens": "127812.81440269060675",
"remaining_tokens": "132186.07309730939325"
"withdrawn_tokens": "128074.4211493107955",
"remaining_tokens": "131924.4663506892045"
},
{
"address": "0x89051CAb67Bc7F8CC44F7e270c6EDaf1EC57676c",
@@ -41948,6 +41985,12 @@
"tranche_id": 2,
"tx": "0x3c76f03b71481a44c6ba2c7cea407f5f1bac60bcaa9242af18de287f94c8ed90"
},
{
"amount": "394.58033601838216",
"user": "0xe3eB4CF43C072658401996b71D43eE26E573562D",
"tranche_id": 2,
"tx": "0xe479984e1fc0f4a0040603b528c841013d6da2c890361ce5f4152256ea9dd009"
},
{
"amount": "1640.93679110232897",
"user": "0xe3eB4CF43C072658401996b71D43eE26E573562D",
@@ -42190,8 +42233,8 @@
}
],
"total_tokens": "150551.801",
"withdrawn_tokens": "73885.95651128121547",
"remaining_tokens": "76665.84448871878453"
"withdrawn_tokens": "74280.53684729959763",
"remaining_tokens": "76271.26415270040237"
},
{
"address": "0x4d982Ab0823fD2f48e934a7be2bb0a5374a26148",
@@ -42399,6 +42442,12 @@
"tranche_id": 2,
"tx": "0x1887d1fb77d9fa555dd5b55da307edc91e395f3a7e0ca5f874740f5a10077cdf"
},
{
"amount": "525.648824",
"user": "0xF4c75FdbAe821C6B5DBB9f001bB23cBA58D1bA37",
"tranche_id": 2,
"tx": "0x132a15c0b5f8c6016ac1a90437b9dca119ebc2479cde9c702327653fa3c11750"
},
{
"amount": "2820.55961",
"user": "0xF4c75FdbAe821C6B5DBB9f001bB23cBA58D1bA37",
@@ -42611,8 +42660,8 @@
}
],
"total_tokens": "200000",
"withdrawn_tokens": "98152.824242",
"remaining_tokens": "101847.175758"
"withdrawn_tokens": "98678.473066",
"remaining_tokens": "101321.526934"
},
{
"address": "0x1b956E6c00E238194B331eddEFF72Cb5f28A8d01",
@@ -43072,6 +43121,12 @@
}
],
"withdrawals": [
{
"amount": "133.7749515525265",
"user": "0xE6CacAE56Cca8dFdB7910b5A13578719D4E57DA0",
"tranche_id": 2,
"tx": "0xed77ed534414a1949b1473707782223907e0ac001f899037ff822f10bd4a358a"
},
{
"amount": "345.7620519411935",
"user": "0xE6CacAE56Cca8dFdB7910b5A13578719D4E57DA0",
@@ -43338,8 +43393,8 @@
}
],
"total_tokens": "12362.05",
"withdrawn_tokens": "5949.173638923777",
"remaining_tokens": "6412.876361076223"
"withdrawn_tokens": "6082.9485904763035",
"remaining_tokens": "6279.1014095236965"
},
{
"address": "0xb091D456d0dFCB94dcba6f355379056C5bb995fC",
@@ -43970,8 +44025,8 @@
"tranche_start": "2021-11-05T00:00:00.000Z",
"tranche_end": "2023-05-05T00:00:00.000Z",
"total_added": "14597706.0446472999",
"total_removed": "5577730.800522677126225156",
"locked_amount": "1724310.085864232345131785821604681",
"total_removed": "5578092.828988683569444906",
"locked_amount": "1697570.95665381351801300648336951",
"deposits": [
{
"amount": "129284.449",
@@ -44205,6 +44260,11 @@
"user": "0x4Aa3c35F6CC2d507E5C18205ee57099A4C80B19b",
"tx": "0xcc545119eac3fe838555697dae55ce68273cb4c5f414c8983bac9f7ef8338f2c"
},
{
"amount": "362.02846600644321975",
"user": "0x4Aa3c35F6CC2d507E5C18205ee57099A4C80B19b",
"tx": "0xbecb2d5ad72cdfe972b450c388f111d9262c39896c71acceecb5f672e50c3ce9"
},
{
"amount": "800.792718381487871",
"user": "0x4Aa3c35F6CC2d507E5C18205ee57099A4C80B19b",
@@ -47190,6 +47250,12 @@
"tranche_id": 3,
"tx": "0xcc545119eac3fe838555697dae55ce68273cb4c5f414c8983bac9f7ef8338f2c"
},
{
"amount": "362.02846600644321975",
"user": "0x4Aa3c35F6CC2d507E5C18205ee57099A4C80B19b",
"tranche_id": 3,
"tx": "0xbecb2d5ad72cdfe972b450c388f111d9262c39896c71acceecb5f672e50c3ce9"
},
{
"amount": "800.792718381487871",
"user": "0x4Aa3c35F6CC2d507E5C18205ee57099A4C80B19b",
@@ -49706,8 +49772,8 @@
}
],
"total_tokens": "359123.469575",
"withdrawn_tokens": "316627.82419217025121175",
"remaining_tokens": "42495.64538282974878825"
"withdrawn_tokens": "316989.8526581766944315",
"remaining_tokens": "42133.6169168233055685"
},
{
"address": "0xBdd412797c1B78535Afc5F71503b91fAbD0160fB",
@@ -51051,7 +51117,7 @@
"tranche_end": "2023-04-05T00:00:00.000Z",
"total_added": "5778205.3912159303",
"total_removed": "3077573.36197477479025324",
"locked_amount": "364381.939925353626624604984386745",
"locked_amount": "353817.1482574094718858681604364422",
"deposits": [
{
"amount": "552496.6455",
@@ -53123,7 +53189,7 @@
"tranche_end": "2023-06-05T00:00:00.000Z",
"total_added": "472355.6199999996",
"total_removed": "34992.4553336210685",
"locked_amount": "123581.941326403371637891942567224",
"locked_amount": "122287.66655711750460814439269404",
"deposits": [
{
"amount": "3000",
@@ -20,46 +20,78 @@ describe('positions', { tags: '@smoke' }, () => {
cy.getByTestId('Positions').click();
validatePositionsDisplayed();
});
it('renders position among some graphql errors', () => {
const errors = [
{
message: 'no market data for market: market-2',
path: ['market', 'data'],
extensions: {
code: 13,
type: 'Internal',
describe('renders position among some graphql errors', () => {
it('rows should be displayed despite errors', () => {
const errors = [
{
message:
'no market data for market: 9c55fb644c6f7de5422d40d691a62bffd5898384c70135bab29ba1e3e2e5280a',
path: ['marketsConnection', 'edges'],
extensions: {
code: 13,
type: 'Internal',
},
},
},
];
const marketData = marketsDataQuery();
const edges = marketData.marketsConnection?.edges.map((market) => {
const replace =
market.node.data?.market.id === 'market-2' ? null : market.node.data;
return { ...market, node: { ...market.node, data: replace } };
});
const overrides = {
...marketData,
marketsConnection: { ...marketData.marketsConnection, edges },
};
cy.mockGQL((req) => {
aliasGQLQuery(req, 'MarketsData', overrides, errors);
});
cy.visit('/#/markets/market-0');
const emptyCells = [
'notional',
'markPrice',
'liquidationPrice',
'currentLeverage',
'averageEntryPrice',
];
cy.getByTestId('tab-positions').within(() => {
cy.get('[row-id="market-2"]').within(() => {
emptyCells.forEach((cell) => {
cy.get(`[col-id="${cell}"]`).should('contain.text', '-');
];
const marketData = marketsDataQuery();
const edges = marketData.marketsConnection?.edges.map((market) => {
const replace =
market.node.data?.market.id === 'market-2' ? null : market.node.data;
return { ...market, node: { ...market.node, data: replace } };
});
const overrides = {
...marketData,
marketsConnection: { ...marketData.marketsConnection, edges },
};
cy.mockGQL((req) => {
aliasGQLQuery(req, 'MarketsData', overrides, errors);
});
cy.visit('/#/markets/market-0');
const emptyCells = [
'notional',
'markPrice',
'liquidationPrice',
'currentLeverage',
'averageEntryPrice',
];
cy.getByTestId('tab-positions').within(() => {
cy.get('[row-id="market-2"]').within(() => {
emptyCells.forEach((cell) => {
cy.get(`[col-id="${cell}"]`).should('contain.text', '-');
});
});
});
});
it('error message should be displayed', () => {
const errors = [
{
message:
'no market data for asset: 9c55fb644c6f7de5422d40d691a62bffd5898384c70135bab29ba1e3e2e5280a',
path: ['assets', 'edges'],
extensions: {
code: 13,
type: 'Internal',
},
},
];
const marketData = marketsDataQuery();
const edges = marketData.marketsConnection?.edges.map((market) => {
const replace =
market.node.data?.market.id === 'market-2' ? null : market.node.data;
return { ...market, node: { ...market.node, data: replace } };
});
const overrides = {
...marketData,
marketsConnection: { ...marketData.marketsConnection, edges },
};
cy.mockGQL((req) => {
aliasGQLQuery(req, 'MarketsData', overrides, errors);
});
cy.visit('/#/markets/market-0');
cy.get('.pointer-events-none.absolute.inset-0').contains(
'Something went wrong:'
);
});
});
describe('sorting by ag-grid columns should work well', () => {
+3 -4
View File
@@ -1,12 +1,11 @@
NX_ETHEREUM_PROVIDER_URL=https://sepolia.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL=https://sepolia.etherscan.io
NX_HOSTED_WALLET_URL=https://wallet.testnet.vega.xyz
NX_VEGA_CONFIG_URL=https://static.vega.xyz/assets/validator-testnet-network.json
NX_VEGA_ENV=VALIDATOR_TESTNET
NX_VEGA_EXPLORER_URL=https://dev.explorer.vega.xyz
NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET3":"https://stagnet3.token.vega.xyz","TESTNET":"https://token.fairground.wtf","MAINNET":"https://token.vega.xyz"}'
NX_VEGA_TOKEN_URL=https://token.fairground.wtf
NX_VEGA_EXPLORER_URL=https://validator-testnet.explorer.vega.xyz
NX_VEGA_NETWORKS={\"STAGNET3\":\"https://stagnet3.console.vega.xyz\",\"STAGNET1\":\"https://stagnet1.console.vega.xyz\",\"TESTNET\":\"https://console.fairground.wtf\"}
NX_VEGA_TOKEN_URL=https://validator-testnet.governance.fairground.wtf
NX_VEGA_WALLET_URL=http://localhost:1789
NX_VEGA_DOCS_URL=https://docs.vega.xyz/testnet
NX_VEGA_REPO_URL=https://github.com/vegaprotocol/vega/releases
@@ -24,6 +24,7 @@ export const Banner = () => {
<AnnouncementBanner>
<div className="grid grid-cols-[auto_1fr] gap-4 font-alpha calt uppercase text-center text-lg text-white">
<button
className="flex items-center"
onClick={() => update({ shouldDisplayAnnouncementBanner: false })}
>
<Icon name="cross" className="w-6 h-6" ariaLabel="dismiss" />
+3
View File
@@ -104,6 +104,7 @@ export const AccountTable = forwardRef<AgGridReact, AccountTableProps>(
/>
<AgGridColumn
headerName={t('Total')}
type="rightAligned"
field="deposited"
headerTooltip={t(
'This is the total amount of collateral used plus the amount available in your general account.'
@@ -121,6 +122,7 @@ export const AccountTable = forwardRef<AgGridReact, AccountTableProps>(
/>
<AgGridColumn
headerName={t('Used')}
type="rightAligned"
field="used"
headerTooltip={t(
'This is the amount of collateral used from your general account.'
@@ -139,6 +141,7 @@ export const AccountTable = forwardRef<AgGridReact, AccountTableProps>(
<AgGridColumn
headerName={t('Available')}
field="available"
type="rightAligned"
headerTooltip={t(
'This is the amount of collateral available in your general account.'
)}
+34 -2
View File
@@ -5,7 +5,7 @@ import * as Schema from '@vegaprotocol/types';
import type { PartialDeep } from 'type-fest';
import type { Trade } from './fills-data-provider';
import { FillsTable } from './fills-table';
import { FillsTable, getFeesBreakdown } from './fills-table';
import { generateFill } from './test-helpers';
describe('FillsTable', () => {
@@ -75,7 +75,7 @@ describe('FillsTable', () => {
'1.00 BTC',
'3.00 BTC',
'Maker',
'0.06 BTC',
'2.00 BTC',
getDateTimeFormat().format(new Date(buyerFill.createdAt)),
];
cells.forEach((cell, i) => {
@@ -176,4 +176,36 @@ describe('FillsTable', () => {
await screen.findByTestId('fee-breakdown-tooltip')
).toBeInTheDocument();
});
describe('getFeesBreakdown', () => {
it('should return correct fees breakdown for a taker', () => {
const fees = {
makerFee: '1000',
infrastructureFee: '2000',
liquidityFee: '3000',
};
const expectedBreakdown = {
infrastructureFee: '2000',
liquidityFee: '3000',
makerFee: '1000',
totalFee: '6000',
};
expect(getFeesBreakdown('TAKER', fees)).toEqual(expectedBreakdown);
});
it('should return correct fees breakdown for a maker', () => {
const fees = {
makerFee: '1000',
infrastructureFee: '2000',
liquidityFee: '3000',
};
const expectedBreakdown = {
infrastructureFee: '2000',
liquidityFee: '3000',
makerFee: '-1000',
totalFee: '4000',
};
expect(getFeesBreakdown('MAKER', fees)).toEqual(expectedBreakdown);
});
});
});
+101 -31
View File
@@ -27,6 +27,10 @@ import type {
import { forwardRef } from 'react';
import BigNumber from 'bignumber.js';
import type { Trade } from './fills-data-provider';
import type { FillFieldsFragment } from './__generated__/Fills';
const TAKER = 'TAKER';
const MAKER = 'MAKER';
export type Props = (AgGridReactProps | AgReactUiProps) & {
partyId: string;
@@ -228,66 +232,132 @@ const formatFee = (partyId: string) => {
return '-';
}
const asset = value.settlementAsset;
let feesObj;
if (data?.buyer.id === partyId) {
feesObj = data?.buyerFee;
} else if (data?.seller.id === partyId) {
feesObj = data?.sellerFee;
} else {
return '-';
}
const { fees: feesObj, role } = getRoleAndFees({ data, partyId });
if (!feesObj) return '-';
const fee = new BigNumber(feesObj.makerFee)
.plus(feesObj.infrastructureFee)
.plus(feesObj.liquidityFee);
const totalFees = addDecimalsFormatNumber(fee.toString(), asset.decimals);
const { totalFee } = getFeesBreakdown(role, feesObj);
const totalFees = addDecimalsFormatNumber(totalFee, asset.decimals);
return `${totalFees} ${asset.symbol}`;
};
};
export const getRoleAndFees = ({
data,
partyId,
}: {
data: Pick<
FillFieldsFragment,
'buyerFee' | 'sellerFee' | 'buyer' | 'seller' | 'aggressor'
>;
partyId?: string;
}) => {
let role;
let feesObj;
if (data?.buyer.id === partyId) {
role = data.aggressor === Schema.Side.SIDE_BUY ? TAKER : MAKER;
feesObj = role === TAKER ? data?.buyerFee : data.sellerFee;
} else if (data?.seller.id === partyId) {
role = data.aggressor === Schema.Side.SIDE_SELL ? TAKER : MAKER;
feesObj = role === TAKER ? data?.sellerFee : data.buyerFee;
} else {
return { role: '-', feesObj: '-' };
}
return { role, fees: feesObj };
};
const FeesBreakdownTooltip = ({
data,
value,
valueFormatted,
partyId,
}: ITooltipParams & { partyId?: string }) => {
if (!value?.settlementAsset || !data) {
return null;
}
const asset = value.settlementAsset;
let feesObj;
if (data?.buyer.id === partyId) {
feesObj = data?.buyerFee;
} else if (data?.seller.id === partyId) {
feesObj = data?.sellerFee;
} else {
return null;
}
const { role, fees: feesObj } = getRoleAndFees({ data, partyId }) ?? {};
if (!feesObj) return null;
const { infrastructureFee, liquidityFee, makerFee, totalFee } =
getFeesBreakdown(role, feesObj);
return (
<div
data-testid="fee-breakdown-tooltip"
className="max-w-sm border border-neutral-600 bg-neutral-100 dark:bg-neutral-800 px-4 py-2 z-20 rounded text-sm break-word text-black dark:text-white"
>
<dl className="grid grid-cols-3 gap-x-1">
{role === MAKER && (
<>
<p className="mb-1">{t('The maker will receive the maker fee.')}</p>
<p className="mb-1">
{t(
'If the market is in monitoring auction the maker will pay half of the infrastructure and liquidity fees.'
)}
</p>
<p className="mb-1">
{t(
'If the market is active the maker will pay zero infrastructure and liquidity fees.'
)}
</p>
</>
)}
{role === TAKER && (
<>
<p className="mb-1">{t('Fees to be paid by the taker.')}</p>
<p className="mb-1">
{t(
'If the market is in monitoring auction the taker will pay half of the infrastructure and liquidity fees.'
)}
</p>
</>
)}
<dl className="grid grid-cols-2 gap-x-1">
<dt className="col-span-1">{t('Infrastructure fee')}</dt>
<dd className="text-right col-span-2">
{addDecimalsFormatNumber(feesObj.infrastructureFee, asset.decimals)}{' '}
<dd className="text-right col-span-1">
{addDecimalsFormatNumber(infrastructureFee, asset.decimals)}{' '}
{asset.symbol}
</dd>
<dt className="col-span-1">{t('Liquidity fee')}</dt>
<dd className="text-right col-span-2">
{addDecimalsFormatNumber(feesObj.liquidityFee, asset.decimals)}{' '}
{asset.symbol}
<dd className="text-right col-span-1">
{addDecimalsFormatNumber(liquidityFee, asset.decimals)} {asset.symbol}
</dd>
<dt className="col-span-1">{t('Maker fee')}</dt>
<dd className="text-right col-span-2">
{addDecimalsFormatNumber(feesObj.makerFee, asset.decimals)}{' '}
{asset.symbol}
<dd className="text-right col-span-1">
{addDecimalsFormatNumber(makerFee, asset.decimals)} {asset.symbol}
</dd>
<dt className="col-span-1">{t('Total fees')}</dt>
<dd className="text-right col-span-2">{valueFormatted}</dd>
<dd className="text-right col-span-1">
{addDecimalsFormatNumber(totalFee, asset.decimals)} {asset.symbol}
</dd>
</dl>
</div>
);
};
export const getFeesBreakdown = (
role: string,
feesObj: {
__typename?: 'TradeFee' | undefined;
makerFee: string;
infrastructureFee: string;
liquidityFee: string;
}
) => {
const makerFee =
role === MAKER
? new BigNumber(feesObj.makerFee).times(-1).toString()
: feesObj.makerFee;
const infrastructureFee = feesObj.infrastructureFee;
const liquidityFee = feesObj.liquidityFee;
const totalFee = new BigNumber(infrastructureFee)
.plus(makerFee)
.plus(liquidityFee)
.toString();
return {
infrastructureFee,
liquidityFee,
makerFee,
totalFee,
};
};
@@ -1,6 +1,6 @@
import { captureException } from '@sentry/react';
import debounce from 'lodash/debounce';
import { useEffect, useMemo } from 'react';
import { useCallback, useEffect, useMemo } from 'react';
import { localLoggerFactory } from '@vegaprotocol/utils';
type ResizeObserverConfiguration = {
debounceTime: number;
@@ -19,20 +19,26 @@ export function useResizeObserver(
callback: ResizeObserverCallback,
options: ResizeObserverConfiguration = DEFAULT_OPTIONS
) {
const wrappedCb = useCallback(
(entries: ResizeObserverEntry[], observer: ResizeObserver) =>
window.requestAnimationFrame(() => {
options.debounceTime > 0
? debounce(callback, options.debounceTime)(entries, observer)
: callback(entries, observer);
}),
[callback, options.debounceTime]
);
const observer = useMemo(() => {
return new ResizeObserver(
options.debounceTime > 0
? debounce(callback, options.debounceTime)
: callback
);
}, [callback, options.debounceTime]);
return new ResizeObserver(wrappedCb);
}, [wrappedCb]);
useEffect(() => {
if (!observer || !target) return;
try {
observer.observe(target, options.config);
} catch (err) {
captureException(err);
localLoggerFactory({ application: 'react-helpers' }).debug(err as Error);
}
return () => observer?.disconnect();
}, [observer, options.config, target]);
+2 -10
View File
@@ -2,7 +2,6 @@ import type { ApolloError } from '@apollo/client';
import type { GraphQLErrors } from '@apollo/client/errors';
const NOT_FOUND = 'NotFound';
const INTERNAL = 'Internal';
const isApolloGraphQLError = (
error: ApolloError | Error | undefined
@@ -29,12 +28,5 @@ export const isNotFoundGraphQLError = (
);
};
export const marketDataErrorPolicyGuard = (errors: GraphQLErrors) => {
const path = ['market', 'data'];
return errors.every(
(e) =>
e.extensions &&
e.extensions['type'] === INTERNAL &&
(!path || path.every((item, i) => item === e?.path?.[i]))
);
};
export const marketDataErrorPolicyGuard = (errors: GraphQLErrors) =>
errors.every((e) => e.message.match(/no market data for market:/i));
+14 -4
View File
@@ -49,10 +49,10 @@ export class LocalLogger {
return LocalLogger.levelLogMap[this._logLevel];
}
private tags: string[] = [];
private application = 'trading';
private _application = 'trading';
constructor(conf: LoggerConf) {
if (conf.application) {
this.application = conf.application;
this._application = conf.application;
}
this.tags = [...(conf.tags || [])];
this._logLevel = conf.logLevel || this._logLevel;
@@ -85,7 +85,7 @@ export class LocalLogger {
) {
if (this.numberLogLevel <= LocalLogger.levelLogMap[level]) {
console[logMethod].apply(console, [
`${this.application}:${level}: `,
`${this._application}:${level}: `,
...args,
]);
}
@@ -148,13 +148,23 @@ export class LocalLogger {
public get logLevel() {
return this._logLevel;
}
public get application() {
return this._application;
}
}
let singleLoggerInstance: LocalLogger;
let singleLoggerInstances: LocalLogger[];
export const localLoggerFactory = (conf: LoggerConf) => {
if (!singleLoggerInstances) {
singleLoggerInstances = [];
}
let singleLoggerInstance = singleLoggerInstances.find(
(instance) => instance.application === conf.application
);
if (!singleLoggerInstance) {
singleLoggerInstance = new LocalLogger(conf);
singleLoggerInstances.push(singleLoggerInstance);
}
if (conf.logLevel && singleLoggerInstance.logLevel !== conf.logLevel) {
singleLoggerInstance.setLogLevel(conf.logLevel);