2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
2022-11-09 18:20:10 +01:00
|
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
2022-09-14 16:55:31 +02:00
|
|
|
import { NETWORK_TYPES } from '../../../../shared/constants/network';
|
2023-01-27 19:28:03 +01:00
|
|
|
import { GasRecommendations } from '../../../../shared/constants/gas';
|
2021-03-16 22:00:08 +01:00
|
|
|
import ViewQuotePriceDifference from './view-quote-price-difference';
|
2020-12-02 22:27:45 +01:00
|
|
|
|
2021-04-09 19:20:32 +02:00
|
|
|
describe('View Price Quote Difference', () => {
|
2022-11-09 18:20:10 +01:00
|
|
|
const mockState = {
|
2020-12-02 22:27:45 +01:00
|
|
|
metamask: {
|
|
|
|
tokens: [],
|
2022-09-14 16:55:31 +02:00
|
|
|
provider: { type: NETWORK_TYPES.RPC, nickname: '', rpcUrl: '' },
|
2020-12-02 22:27:45 +01:00
|
|
|
preferences: { showFiatInTestnets: true },
|
|
|
|
currentCurrency: 'usd',
|
|
|
|
conversionRate: 600.0,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-12-02 22:27:45 +01:00
|
|
|
|
2022-11-09 18:20:10 +01:00
|
|
|
const mockStore = configureMockStore()(mockState);
|
2020-12-02 22:27:45 +01:00
|
|
|
|
|
|
|
// Sample transaction is 1 $ETH to ~42.880915 $LINK
|
|
|
|
const DEFAULT_PROPS = {
|
|
|
|
usedQuote: {
|
|
|
|
trade: {
|
2022-07-31 20:26:40 +02:00
|
|
|
data: '0x5f575529000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000007756e69737761700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000000000000000000000000000000dc1a09f859b20000000000000000000000000000000000000000000000000024855454cb32d335f0000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000005fc7b7100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001f161421c8e0000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca',
|
2020-12-02 22:27:45 +01:00
|
|
|
from: '0xd7440fdcb70a9fba55dfe06942ddbc17679c90ac',
|
|
|
|
value: '0xde0b6b3a7640000',
|
|
|
|
gas: '0xbbfd0',
|
|
|
|
to: '0x881D40237659C251811CEC9c364ef91dC08D300C',
|
|
|
|
},
|
|
|
|
sourceAmount: '1000000000000000000',
|
|
|
|
destinationAmount: '42947749216634160067',
|
|
|
|
error: null,
|
|
|
|
sourceToken: '0x0000000000000000000000000000000000000000',
|
|
|
|
destinationToken: '0x514910771af9ca656af840dff83e8264ecf986ca',
|
|
|
|
approvalNeeded: null,
|
|
|
|
maxGas: 770000,
|
|
|
|
averageGas: 210546,
|
|
|
|
estimatedRefund: 80000,
|
|
|
|
fetchTime: 647,
|
|
|
|
aggregator: 'uniswap',
|
|
|
|
aggType: 'DEX',
|
|
|
|
fee: 0.875,
|
|
|
|
gasMultiplier: 1.5,
|
|
|
|
priceSlippage: {
|
|
|
|
ratio: 1.007876641534847,
|
|
|
|
calculationError: '',
|
2023-01-27 19:28:03 +01:00
|
|
|
bucket: GasRecommendations.low,
|
2020-12-02 22:27:45 +01:00
|
|
|
sourceAmountInETH: 1,
|
2021-02-23 17:52:04 +01:00
|
|
|
destinationAmountInETH: 0.9921849150875727,
|
2020-12-02 22:27:45 +01:00
|
|
|
},
|
|
|
|
slippage: 2,
|
|
|
|
sourceTokenInfo: {
|
|
|
|
symbol: 'ETH',
|
|
|
|
name: 'Ether',
|
|
|
|
address: '0x0000000000000000000000000000000000000000',
|
|
|
|
decimals: 18,
|
|
|
|
iconUrl: 'images/black-eth-logo.svg',
|
|
|
|
},
|
|
|
|
destinationTokenInfo: {
|
|
|
|
address: '0x514910771af9ca656af840dff83e8264ecf986ca',
|
|
|
|
symbol: 'LINK',
|
|
|
|
decimals: 18,
|
|
|
|
occurances: 12,
|
|
|
|
iconUrl:
|
|
|
|
'https://cloudflare-ipfs.com/ipfs/QmQhZAdcZvW9T2tPm516yHqbGkfhyZwTZmLixW9MXJudTA',
|
|
|
|
},
|
|
|
|
ethFee: '0.011791',
|
|
|
|
ethValueOfTokens: '0.99220724791716534441',
|
|
|
|
overallValueOfQuote: '0.98041624791716534441',
|
|
|
|
metaMaskFeeInEth: '0.00875844985551091729',
|
|
|
|
isBestQuote: true,
|
|
|
|
savings: {
|
|
|
|
performance: '0.00207907025112527799',
|
|
|
|
fee: '0.005581',
|
|
|
|
metaMaskFee: '0.00875844985551091729',
|
|
|
|
total: '-0.0010983796043856393',
|
|
|
|
medianMetaMaskFee: '0.00874009740688812165',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
sourceTokenValue: '1',
|
|
|
|
destinationTokenValue: '42.947749',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-12-02 22:27:45 +01:00
|
|
|
|
2022-11-09 18:20:10 +01:00
|
|
|
it('should match snapshot', () => {
|
|
|
|
const { container } = renderWithProvider(
|
|
|
|
<ViewQuotePriceDifference {...DEFAULT_PROPS} />,
|
|
|
|
mockStore,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-12-02 22:27:45 +01:00
|
|
|
|
2022-11-09 18:20:10 +01:00
|
|
|
expect(container).toMatchSnapshot();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-12-02 22:27:45 +01:00
|
|
|
|
2021-04-09 19:20:32 +02:00
|
|
|
it('displays an error when in medium bucket', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const props = { ...DEFAULT_PROPS };
|
2023-01-27 19:28:03 +01:00
|
|
|
props.usedQuote.priceSlippage.bucket = GasRecommendations.medium;
|
2020-12-02 22:27:45 +01:00
|
|
|
|
2022-11-09 18:20:10 +01:00
|
|
|
const { container } = renderWithProvider(
|
|
|
|
<ViewQuotePriceDifference {...props} />,
|
|
|
|
mockStore,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-12-02 22:27:45 +01:00
|
|
|
|
2021-04-09 19:20:32 +02:00
|
|
|
it('displays an error when in high bucket', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const props = { ...DEFAULT_PROPS };
|
2023-01-27 19:28:03 +01:00
|
|
|
props.usedQuote.priceSlippage.bucket = GasRecommendations.high;
|
2020-12-02 22:27:45 +01:00
|
|
|
|
2022-11-09 18:20:10 +01:00
|
|
|
const { container } = renderWithProvider(
|
|
|
|
<ViewQuotePriceDifference {...props} />,
|
|
|
|
mockStore,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-12-02 22:27:45 +01:00
|
|
|
|
2021-04-09 19:20:32 +02:00
|
|
|
it('displays a fiat error when calculationError is present', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const props = { ...DEFAULT_PROPS, priceSlippageUnknownFiatValue: true };
|
2020-12-02 22:27:45 +01:00
|
|
|
props.usedQuote.priceSlippage.calculationError =
|
2021-02-04 19:15:23 +01:00
|
|
|
'Could not determine price.';
|
2020-12-02 22:27:45 +01:00
|
|
|
|
2022-11-09 18:20:10 +01:00
|
|
|
const { container } = renderWithProvider(
|
|
|
|
<ViewQuotePriceDifference {...props} />,
|
|
|
|
mockStore,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|