Compare commits

...

7 Commits

2 changed files with 45 additions and 2 deletions

View File

@ -1,6 +1,6 @@
import { MarketState, MarketTradingMode } from '@vegaprotocol/types'; import { MarketState, MarketTradingMode } from '@vegaprotocol/types';
import type { Market } from '../markets-provider'; import type { Market } from '../markets-provider';
import { mapDataToMarketList } from './market-utils'; import { mapDataToMarketList, totalFees } from './market-utils';
const MARKET_A: Partial<Market> = { const MARKET_A: Partial<Market> = {
id: '1', id: '1',
@ -11,6 +11,15 @@ const MARKET_A: Partial<Market> = {
}, },
state: MarketState.STATE_ACTIVE, state: MarketState.STATE_ACTIVE,
tradingMode: MarketTradingMode.TRADING_MODE_CONTINUOUS, tradingMode: MarketTradingMode.TRADING_MODE_CONTINUOUS,
fees: {
__typename: 'Fees',
factors: {
__typename: 'FeeFactors',
makerFee: '0.0001',
infrastructureFee: '0.0002',
liquidityFee: '0.0000',
}
},
}; };
const MARKET_B: Partial<Market> = { const MARKET_B: Partial<Market> = {
@ -22,6 +31,15 @@ const MARKET_B: Partial<Market> = {
}, },
state: MarketState.STATE_ACTIVE, state: MarketState.STATE_ACTIVE,
tradingMode: MarketTradingMode.TRADING_MODE_CONTINUOUS, tradingMode: MarketTradingMode.TRADING_MODE_CONTINUOUS,
fees: {
__typename: 'Fees',
factors: {
__typename: 'FeeFactors',
makerFee: '0.0000',
infrastructureFee: '0.0002',
liquidityFee: '0.002',
}
},
}; };
const MARKET_C: Partial<Market> = { const MARKET_C: Partial<Market> = {
@ -31,6 +49,15 @@ const MARKET_C: Partial<Market> = {
open: '2022-05-17T13:00:39.328347732Z', open: '2022-05-17T13:00:39.328347732Z',
close: null, close: null,
}, },
fees: {
__typename: 'Fees',
factors: {
__typename: 'FeeFactors',
makerFee: '0.0001',
infrastructureFee: '0.0002',
liquidityFee: '0.0003',
}
},
state: MarketState.STATE_REJECTED, state: MarketState.STATE_REJECTED,
tradingMode: MarketTradingMode.TRADING_MODE_CONTINUOUS, tradingMode: MarketTradingMode.TRADING_MODE_CONTINUOUS,
}; };
@ -43,6 +70,15 @@ const MARKET_D: Partial<Market> = {
close: null, close: null,
}, },
state: MarketState.STATE_ACTIVE, state: MarketState.STATE_ACTIVE,
fees: {
__typename: 'Fees',
factors: {
__typename: 'FeeFactors',
makerFee: '0.0001',
infrastructureFee: '0.0002',
liquidityFee: '0.00000056',
}
},
tradingMode: MarketTradingMode.TRADING_MODE_NO_TRADING, tradingMode: MarketTradingMode.TRADING_MODE_NO_TRADING,
}; };
@ -56,4 +92,11 @@ describe('mapDataToMarketList', () => {
] as unknown as Market[]); ] as unknown as Market[]);
expect(result).toEqual([MARKET_B, MARKET_A]); expect(result).toEqual([MARKET_B, MARKET_A]);
}); });
it('should format total fees', () => {
expect(MARKET_A.fees?.factors && totalFees(MARKET_A.fees?.factors)).toEqual('0.03%');
expect(MARKET_B.fees?.factors && totalFees(MARKET_B.fees?.factors)).toEqual('0.22%');
expect(MARKET_C.fees?.factors && totalFees(MARKET_C.fees?.factors)).toEqual('0.06%');
expect(MARKET_D.fees?.factors && totalFees(MARKET_D.fees?.factors)).toEqual('0.030056%');
});
}); });

View File

@ -11,7 +11,7 @@ export const totalFees = (fees: Market['fees']['factors']) => {
return formatNumberPercentage( return formatNumberPercentage(
new BigNumber(fees.makerFee) new BigNumber(fees.makerFee)
.plus(fees.liquidityFee) .plus(fees.liquidityFee)
.plus(fees.makerFee) .plus(fees.infrastructureFee)
.times(100) .times(100)
); );
}; };