Skip to content

Commit

Permalink
fix testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
haunv3 committed Sep 11, 2024
1 parent d649a7f commit cad28b6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 94 deletions.
33 changes: 2 additions & 31 deletions src/pages/UniversalSwap/Swap/hooks/useHandleEffectTokenChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@ import { tokenMap } from 'config/bridgeTokens';
import { getAddressTransfer, networks } from 'helper';
import useConfigReducer from 'hooks/useConfigReducer';
import useWalletReducer from 'hooks/useWalletReducer';
import { genCurrentChain, generateNewSymbolV2, getFromToToken } from 'pages/UniversalSwap/helpers';
import { getFromToToken } from 'pages/UniversalSwap/helpers';
import { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
selectCurrentToChain,
selectCurrentToken,
setCurrentFromToken,
setCurrentToChain,
setCurrentToken,
setCurrentToToken
} from 'reducer/tradingSlice';
import { selectCurrentToChain, selectCurrentToken } from 'reducer/tradingSlice';
import useFilteredTokens from './useFilteredTokens';

const useHandleEffectTokenChange = ({ fromTokenDenomSwap, toTokenDenomSwap }) => {
Expand Down Expand Up @@ -90,28 +83,6 @@ const useHandleEffectTokenChange = ({ fromTokenDenomSwap, toTokenDenomSwap }) =>
window?.tronWebDapp
]);

useEffect(() => {
const newTVPair = generateNewSymbolV2(fromToken, toToken, currentPair);

if (newTVPair) dispatch(setCurrentToken(newTVPair));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fromToken, toToken]);

useEffect(() => {
const newCurrentToChain = genCurrentChain({ toToken: originalToToken, currentToChain });

if (toToken && originalToToken) {
dispatch(setCurrentToChain(newCurrentToChain));
dispatch(setCurrentToToken(originalToToken));
}
}, [originalToToken, toToken]);

useEffect(() => {
if (fromToken && originalFromToken) {
dispatch(setCurrentFromToken(originalFromToken));
}
}, [originalFromToken, fromToken]);

const isConnectedWallet =
walletByNetworks.cosmos || walletByNetworks.bitcoin || walletByNetworks.evm || walletByNetworks.tron;

Expand Down
62 changes: 1 addition & 61 deletions src/tests/helper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CoinGeckoPrices } from 'hooks/useCoingecko';
import { formateNumberDecimalsAuto, timeSince, toSumDisplay } from 'libs/utils';
import { getTotalUsd, reduceString } from './../libs/utils';
import { PairToken } from 'reducer/type';
import { calculateFinalPriceChange, generateNewSymbol } from 'pages/UniversalSwap/helpers';
import { calculateFinalPriceChange } from 'pages/UniversalSwap/helpers';
import {
MILKYBSC_ORAICHAIN_DENOM,
USDT_CONTRACT,
Expand Down Expand Up @@ -67,66 +67,6 @@ describe('should utils functions in libs/utils run exactly', () => {
});
});

it.each<[string, string, string, PairToken, PairToken | null]>([
[
'from-&-to-are-NOT-pair-in-pool',
'OSMO',
'AIRI',
{
symbol: 'OSMO/AIRI',
info: ''
},
{
symbol: 'ORAI/OSMO',
info: `orai-${OSMOSIS_ORAICHAIN_DENOM}`
}
],
[
'from-&-to-are-NOT-pair-in-pool',
'AIRI',
'OSMO',
{
symbol: 'AIRI/OSMO',
info: ''
},
{
symbol: 'AIRI/ORAI',
info: `${AIRI_CONTRACT}-orai`
}
],
[
'from-&-to-are-pair-in-pool-and-are-NOT-reversed',
'ORAI',
'USDT',
{
symbol: 'FOO/BAR',
info: 'foo-bar'
},
{
symbol: 'ORAI/USDT',
info: `orai-${USDT_CONTRACT}`
}
],
[
'from-&-to-are-pair-in-pool-and-are-reversed',
'USDT',
'ORAI',
{
symbol: 'ORAI/USDT',
info: `orai-${USDT_CONTRACT}`
},
null
]
])(
'test-generateNewSymbol-with-%s-should-return-correctly-new-pair',
(_caseName, from, to, currentPair, expectedResult) => {
const fromToken = oraichainTokens.find((t) => t.name === from);
const toToken = oraichainTokens.find((t) => t.name === to);
const result = generateNewSymbol(fromToken, toToken, currentPair);
expect(result).toEqual(expectedResult);
}
);

describe('timeSince', () => {
it.each<[number, string]>([
[Date.now() - 366 * 24 * 60 * 60 * 1000, '1 years'],
Expand Down
3 changes: 1 addition & 2 deletions src/tests/universal-swap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
NetworkChainId,
flattenTokens
} from '@oraichain/oraidex-common';
import { calcMaxAmount } from 'helper/helpers';
import {
SwapDirection,
SwapType,
calcMaxAmount,
checkEvmAddress,
filterNonPoolEvmTokens,
getSwapType
Expand Down Expand Up @@ -111,7 +111,6 @@ describe('universal-swap', () => {
coeff,
gas: gasEstimate
});
console.log({ result });

expect(result).toEqual(expectedResult);
});
Expand Down

0 comments on commit cad28b6

Please sign in to comment.