Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Pools): remove ratio customization #1541

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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