Skip to content

Commit

Permalink
fix(Pools): remove ratio customization (#1541)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsimao authored Aug 25, 2023
1 parent babdcb8 commit b8b99ae
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 60 deletions.
17 changes: 3 additions & 14 deletions src/pages/Pools/components/DepositForm/DepositForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ import { PoolName } from '../PoolName';
import { StyledPlusDivider, StyledTokenInput } from './DepositForm.styles';
import { DepositOutputAssets } from './DepositOutputAssets';

const isCustomAmountsMode = (form: ReturnType<typeof useForm>, pool: LiquidityPool) =>
// If pool has no liquidity, the assets ratio is set by the user,
// therefore the value inputted is directly used.
(form.dirty && Object.values(form.touched).filter(Boolean).length > 0) || pool.isEmpty;

type DepositFormProps = {
pool: LiquidityPool;
overlappingModalRef: RefObject<HTMLDivElement>;
Expand All @@ -45,8 +40,6 @@ const DepositForm = ({ pool, overlappingModalRef, onSuccess, onSigning }: Deposi

const [slippage, setSlippage] = useState(0.1);

const [isCustomMode, setCustomMode] = useState(false);

const accountId = useAccountId();
const { t } = useTranslation();
const { getAvailableBalance } = useGetBalances();
Expand All @@ -64,7 +57,7 @@ const DepositForm = ({ pool, overlappingModalRef, onSuccess, onSigning }: Deposi
if (feeCurrencyAmount && transaction.fee.data) {
const newFeeCurrencyAmount = transaction.calculateAmountWithFeeDeducted(feeCurrencyAmount);

if (isCustomMode) {
if (pool.isEmpty) {
return amounts.map((amount) =>
transaction.fee.isEqualFeeCurrency(amount.currency) ? newFeeCurrencyAmount : amount
);
Expand All @@ -75,7 +68,7 @@ const DepositForm = ({ pool, overlappingModalRef, onSuccess, onSigning }: Deposi

return amounts;
},
[isCustomMode, pool, transaction]
[pool, transaction]
);

const getTransactionArgs = useCallback(
Expand Down Expand Up @@ -148,11 +141,7 @@ const DepositForm = ({ pool, overlappingModalRef, onSuccess, onSigning }: Deposi
});

const handleChange: ChangeEventHandler<HTMLInputElement> = async (e) => {
const isCustom = isCustomAmountsMode(form, pool);

if (isCustom) {
return setCustomMode(true);
}
if (pool.isEmpty) return;

if (!e.target.value || isNaN(Number(e.target.value))) {
return form.setValues({ ...form.values, ...defaultValues });
Expand Down
46 changes: 0 additions & 46 deletions src/test/pages/Pools.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,52 +206,6 @@ describe('Pools Page', () => {
getClaimableFarmingRewards.mockReturnValue(CLAIMABLE_REWARDS);
});

it('should be able to enter customisable input amounts mode', async () => {
jest
.spyOn(LIQUIDITY_POOLS.ONE, 'getLiquidityDepositInputAmounts')
.mockReturnValue(LIQUIDITY_POOLS.ONE.pooledCurrencies);

const [DEFAULT_CURRENCY_1, DEFAULT_CURRENCY_2] = LIQUIDITY_POOLS.ONE.pooledCurrencies;

await render(<App />, { path });

const tabPanel = await withinModalTabPanel(TABLES.AVAILABLE_POOLS, LP_TOKEN_A.ticker, TABS.DEPOSIT);

await userEvent.type(
tabPanel.getByRole('textbox', {
name: new RegExp(`${DEFAULT_CURRENCY_1.currency.ticker} deposit amount`, 'i')
}),
DEFAULT_CURRENCY_1.toString(),
{ delay: 1 }
);

expect(LIQUIDITY_POOLS.ONE.getLiquidityDepositInputAmounts).toHaveBeenCalledWith(DEFAULT_CURRENCY_1);

await waitFor(() => {
expect(
tabPanel.getByRole('textbox', {
name: new RegExp(`${DEFAULT_CURRENCY_2.currency.ticker} deposit amount`, 'i')
})
).toHaveValue(DEFAULT_CURRENCY_2.toString());
});

await userEvent.type(
tabPanel.getByRole('textbox', {
name: new RegExp(`${DEFAULT_CURRENCY_2.currency.ticker} deposit amount`, 'i')
}),
'10',
{ delay: 1 }
);

await waitFor(() => {
expect(
tabPanel.getByRole('textbox', {
name: new RegExp(`${DEFAULT_CURRENCY_1.currency.ticker} deposit amount`, 'i')
})
).toHaveValue(DEFAULT_CURRENCY_1.toString());
});
});

it('should render illiquid pool and deposit with custom ratio', async () => {
jest
.spyOn(LIQUIDITY_POOLS.EMPTY, 'getLiquidityDepositInputAmounts')
Expand Down

2 comments on commit b8b99ae

@vercel
Copy link

@vercel vercel bot commented on b8b99ae Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on b8b99ae Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.