Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/fast-drinks-stop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@venusprotocol/evm": patch
---

feat: remove raw translate key on vai
19 changes: 1 addition & 18 deletions apps/evm/src/pages/Vai/Borrow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
AcknowledgementToggle,
Delimiter,
LabeledInlineContent,
NoticeError,
NoticeWarning,
Spinner,
} from 'components';
Expand Down Expand Up @@ -45,7 +44,7 @@ import { useSimulateBalanceMutations } from 'hooks/useSimulateBalanceMutations';
import type { BalanceMutation } from 'types';
import TEST_IDS from './testIds';
import type { FormValues } from './types';
import { ErrorCode, useForm } from './useForm';
import { useForm } from './useForm';

export const Borrow: React.FC = () => {
const { t, Trans } = useTranslation();
Expand Down Expand Up @@ -180,20 +179,6 @@ export const Borrow: React.FC = () => {
token: vai,
});

const errorMessage = useMemo(() => {
const errorCode = formState.errors.amountTokens?.message;

if (errorCode === ErrorCode.HIGHER_THAN_LIQUIDITY) {
return t('vai.borrow.notice.amountHigherThanLiquidity');
}

if (errorCode === ErrorCode.HIGHER_THAN_MINTABLE_AMOUNT) {
return t('vai.borrow.notice.amountHigherThanAccountMintableAmount');
}

return undefined;
}, [t, formState.errors.amountTokens]);

const isRiskyOperation =
simulatedPool?.userHealthFactor !== undefined &&
simulatedPool.userHealthFactor < HEALTH_FACTOR_MODERATE_THRESHOLD &&
Expand Down Expand Up @@ -277,8 +262,6 @@ export const Borrow: React.FC = () => {
}),
}}
/>

{errorMessage && <NoticeError description={errorMessage} />}
</div>

<div className="space-y-3">
Expand Down
9 changes: 5 additions & 4 deletions apps/evm/src/pages/Vai/Borrow/useForm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import { useForm as useRhfForm } from 'react-hook-form';
import { z } from 'zod';

import { useGetToken } from 'libs/tokens';
import { useTranslation } from 'libs/translations';
import { calculateHealthFactor, convertMantissaToTokens } from 'utilities';

import { HEALTH_FACTOR_MODERATE_THRESHOLD } from 'constants/healthFactor';
import type { FormValues } from '../types';

export enum ErrorCode {
HIGHER_THAN_LIQUIDITY = 'HIGHER_THAN_LIQUIDITY',
HIGHER_THAN_MINTABLE_AMOUNT = 'HIGHER_THAN_MINTABLE_AMOUNT',
REQUIRES_RISK_ACKNOWLEDGEMENT = 'REQUIRES_RISK_ACKNOWLEDGEMENT',
}

Expand All @@ -31,6 +30,7 @@ export const useForm = ({
userLiquidationThresholdCents,
vaiPriceCents,
}: UseFormProps) => {
const { t } = useTranslation();
const vai = useGetToken({
symbol: 'VAI',
})!;
Expand Down Expand Up @@ -61,15 +61,15 @@ export const useForm = ({
!vaiLiquidityTokens ||
new BigNumber(vaiLiquidityTokens).isGreaterThanOrEqualTo(value),
{
message: ErrorCode.HIGHER_THAN_LIQUIDITY,
message: t('vai.borrow.notice.amountHigherThanLiquidity'),
},
)
.refine(
value =>
!accountMintableVaiTokens ||
new BigNumber(accountMintableVaiTokens).isGreaterThanOrEqualTo(value),
{
message: ErrorCode.HIGHER_THAN_MINTABLE_AMOUNT,
message: t('vai.borrow.notice.amountHigherThanAccountMintableAmount'),
},
),
acknowledgeRisk: z.boolean(),
Expand Down Expand Up @@ -109,6 +109,7 @@ export const useForm = ({
userBorrowBalanceCents,
userLiquidationThresholdCents,
vaiPriceCents,
t,
],
);

Expand Down
35 changes: 3 additions & 32 deletions apps/evm/src/pages/Vai/Repay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ import { useCallback, useEffect, useMemo } from 'react';
import type { SubmitHandler } from 'react-hook-form';

import { useGetBalanceOf, useGetPool, useRepayVai } from 'clients/api';
import {
Delimiter,
LabeledInlineContent,
NoticeError,
NoticeWarning,
SpendingLimit,
Spinner,
} from 'components';
import { Delimiter, LabeledInlineContent, NoticeWarning, SpendingLimit, Spinner } from 'components';
import { NULL_ADDRESS } from 'constants/address';
import MAX_UINT256 from 'constants/maxUint256';
import { AccountData } from 'containers/AccountData';
Expand All @@ -32,7 +25,7 @@ import formatPercentageToReadableValue from 'utilities/formatPercentageToReadabl
import { generatePseudoRandomRefetchInterval } from 'utilities/generatePseudoRandomRefetchInterval';
import TEST_IDS from './testIds';
import type { FormValues } from './types';
import { ErrorCode, useForm } from './useForm';
import { useForm } from './useForm';

const userVaiBalanceRefetchInterval = generatePseudoRandomRefetchInterval();

Expand Down Expand Up @@ -127,26 +120,6 @@ export const Repay: React.FC = () => {

const isRepayingFullLoan = !!userVaiBorrowBalanceTokens?.isEqualTo(debouncedInputAmountTokens);

const errorMessage = useMemo(() => {
const errorCode = formState.errors.amountTokens?.message;

if (errorCode === ErrorCode.HIGHER_THAN_WALLET_BALANCE) {
return t('vai.repay.notice.amountHigherThanWalletBalance', {
tokenSymbol: vai.symbol,
});
}

if (errorCode === ErrorCode.HIGHER_THAN_WALLET_SPENDING_LIMIT) {
return t('vai.repay.notice.amountHigherThanWalletSpendingLimit');
}

if (errorCode === ErrorCode.HIGHER_THAN_BORROW_BALANCE) {
return t('vai.repay.notice.amountHigherThanBorrowBalance');
}

return undefined;
}, [t, formState.errors.amountTokens, vai]);

// Reset form when user disconnects their wallet
useEffect(() => {
if (!accountAddress) {
Expand Down Expand Up @@ -213,9 +186,7 @@ export const Repay: React.FC = () => {
}
/>

{errorMessage && <NoticeError description={errorMessage} />}

{!errorMessage && isRepayingFullLoan && (
{!formState.errors.amountTokens && isRepayingFullLoan && (
<NoticeWarning description={t('vai.repay.notice.fullRepaymentWarning')} />
)}
</div>
Expand Down
18 changes: 8 additions & 10 deletions apps/evm/src/pages/Vai/Repay/useForm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ import { useForm as useRhfForm } from 'react-hook-form';
import { z } from 'zod';

import { useGetToken } from 'libs/tokens';
import { useTranslation } from 'libs/translations';
import { convertMantissaToTokens } from 'utilities';
import type { FormValues } from '../types';

export enum ErrorCode {
HIGHER_THAN_WALLET_BALANCE = 'HIGHER_THAN_WALLET_BALANCE',
HIGHER_THAN_BORROW_BALANCE = 'HIGHER_THAN_BORROW_BALANCE',
HIGHER_THAN_WALLET_SPENDING_LIMIT = 'HIGHER_THAN_WALLET_SPENDING_LIMIT',
}

export interface UseFormProps {
userVaiWalletBalanceMantissa?: BigNumber;
userVaiBorrowBalanceTokens?: BigNumber;
Expand All @@ -25,6 +20,7 @@ export const useForm = ({
userVaiBorrowBalanceTokens,
userWalletSpendingLimitTokens,
}: UseFormProps) => {
const { t } = useTranslation();
const vai = useGetToken({
symbol: 'VAI',
})!;
Expand Down Expand Up @@ -65,15 +61,17 @@ export const useForm = ({
!userVaiWalletBalanceTokens ||
new BigNumber(userVaiWalletBalanceTokens).isGreaterThanOrEqualTo(value),
{
message: ErrorCode.HIGHER_THAN_WALLET_BALANCE,
message: t('vai.repay.notice.amountHigherThanWalletBalance', {
tokenSymbol: vai.symbol,
}),
},
)
.refine(
value =>
!userVaiBorrowBalanceTokens ||
new BigNumber(userVaiBorrowBalanceTokens).isGreaterThanOrEqualTo(value),
{
message: ErrorCode.HIGHER_THAN_BORROW_BALANCE,
message: t('vai.repay.notice.amountHigherThanBorrowBalance'),
},
)
.refine(
Expand All @@ -82,11 +80,11 @@ export const useForm = ({
userWalletSpendingLimitTokens.isEqualTo(0) ||
new BigNumber(userWalletSpendingLimitTokens).isGreaterThanOrEqualTo(value),
{
message: ErrorCode.HIGHER_THAN_WALLET_SPENDING_LIMIT,
message: t('vai.repay.notice.amountHigherThanWalletSpendingLimit'),
},
),
}) satisfies z.ZodType<FormValues>,
[userVaiWalletBalanceTokens, userVaiBorrowBalanceTokens, userWalletSpendingLimitTokens],
[userVaiWalletBalanceTokens, userVaiBorrowBalanceTokens, userWalletSpendingLimitTokens, t, vai],
);

const form = useRhfForm({
Expand Down
Loading