Skip to content

Commit 8876423

Browse files
committed
refactor: update top up, tx modals amount calculation, ValidatorsStatistic usd value
1 parent a51070c commit 8876423

8 files changed

Lines changed: 47 additions & 11 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { NotInPdg } from './not-in-pdg';
22
export { DepositPaused } from './diposit-paused';
3+
export { LowBalance } from './low-balance';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { LowBalance } from './low-balance';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { FC } from 'react';
2+
3+
import { vaultTexts } from 'modules/vaults';
4+
import { WEI_PER_ETHER } from 'consts/tx';
5+
6+
import { WarningInfo } from 'features/validators/shared';
7+
8+
type LowBalanceProps = {
9+
availableBalance: bigint;
10+
};
11+
12+
const { availableBalanceLow } = vaultTexts.actions.validators.modals.topUp;
13+
14+
export const LowBalance: FC<LowBalanceProps> = ({ availableBalance }) => {
15+
if (availableBalance >= WEI_PER_ETHER) {
16+
return null;
17+
}
18+
19+
return <WarningInfo>{availableBalanceLow(availableBalance)}</WarningInfo>;
20+
};

features/validators/modals/topup-modal/content/form/form.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import {
1111
import { useDappStatus } from 'modules/web3';
1212
import { useVault, vaultTexts } from 'modules/vaults';
1313
import { ConnectWalletButton } from 'shared/wallet';
14+
import { WEI_PER_ETHER } from 'consts/tx';
1415

1516
import { useValidators } from 'features/validators/contexts';
1617
import { ModalFormButton } from 'features/validators/shared';
1718

1819
import { useSubmitTopup } from '../../hooks';
1920
import { topUpFormResolver } from '../../validation';
20-
import { DepositPaused, NotInPdg } from '../../components';
21+
import { DepositPaused, NotInPdg, LowBalance } from '../../components';
2122
import type {
2223
TopUpFormFieldValues,
2324
TopUpFormValidationContext,
@@ -68,6 +69,7 @@ export const TopupModalForm: FC<FormProps> = ({ pubkey }) => {
6869
disabled ||
6970
!hasDepositorPermission ||
7071
!isValidatorInPDG ||
72+
availableBalance < WEI_PER_ETHER ||
7173
beaconChainDepositsPaused,
7274
resolver: topUpFormResolver,
7375
context: { availableBalance },
@@ -105,6 +107,7 @@ export const TopupModalForm: FC<FormProps> = ({ pubkey }) => {
105107
/>
106108
<NotInPdg isValidatorInPDG={isValidatorInPDG} />
107109
<DepositPaused beaconChainDepositsPaused={beaconChainDepositsPaused} />
110+
<LowBalance availableBalance={availableBalance} />
108111
<ConnectWalletButton>
109112
<ModalFormButton
110113
type="submit"

features/validators/modals/topup-modal/hooks/use-submit-topup.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from 'modules/web3';
1515
import { useDisableForm } from 'shared/hook-form';
1616
import { TopUpFormValidatedValues } from '../types';
17+
import { WEI_PER_GWEI } from '../../../../../consts/tx';
1718

1819
const { loadingText, mainCompleteText } =
1920
vaultTexts.actions.validators.modals.topUp.txModal;
@@ -33,15 +34,19 @@ export const useSubmitTopup = () => {
3334
'[useSubmitTopup] form has been disabled for any transactions',
3435
);
3536

36-
const mainActionLoadingText = loadingText(index, amount);
37-
const mainActionCompleteText = mainCompleteText(index, amount);
37+
// @notice min amount === 1 ETH
38+
// amount is result of rounds eth down using gwei
39+
const amountInGwei = (amount / WEI_PER_GWEI) * WEI_PER_GWEI;
40+
41+
const mainActionLoadingText = loadingText(index, amountInGwei);
42+
const mainActionCompleteText = mainCompleteText(index, amountInGwei);
3843

3944
const prepareTransactions = async () => {
4045
const calls: TransactionEntry[] = [...prepareReportCalls()];
4146

4247
calls.push({
4348
...activeVault.predepositGuarantee.encode.topUpExistingValidators([
44-
[{ pubkey, amount }],
49+
[{ pubkey, amount: amountInGwei }],
4550
]),
4651
loadingActionText: mainActionLoadingText,
4752
});

features/validators/shared/components/validators-statistic/validators-statistic.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ export const ValidatorsStatistic: FC<ValidatorsStatisticProps> = ({
3939
/>
4040
</Text>
4141
</InlineLoader>
42-
<InlineLoader isLoading={isLoading || !usdAmount} height={20} width={80}>
42+
<InlineLoader isLoading={isLoading} height={20} width={80}>
4343
<Text size="xxs" strong style={{ textTransform: 'uppercase' }}>
44-
<FormatPrice amount={usdAmount as number} />
44+
<FormatPrice amount={usdAmount} />
4545
</Text>
4646
</InlineLoader>
4747
</StatisticContainer>

modules/vaults/consts/texts.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,12 @@ export const vaultTexts = {
352352
partialWarning:
353353
"Withdrawals are subject for the withdrawal queue, which is not yet supported by this UI. So you'll see the result of your request only when it's done.",
354354
fullWarning: (amount: bigint) =>
355-
`You are about to force-exit this validator. The entire validator's actual balance (currently ${formatBalance(amount).trimmed} ETH) will be withdrawn.`,
355+
`You are about to force-exit this validator. The entire validator's actual balance (currently ${formatBalance(amount, { adaptiveDecimals: true }).trimmed} ETH) will be withdrawn.`,
356356
txModal: {
357357
loadingText: (index: number, amount: bigint) =>
358-
`You are withdrawing ${formatBalance(amount).trimmed} ETH from the validator #${index}`,
358+
`You are withdrawing ${formatBalance(amount, { adaptiveDecimals: true }).trimmed} ETH from the validator #${index}`,
359359
mainCompleteText: (index: number, amount: bigint) =>
360-
`${formatBalance(amount).trimmed} ETH has been withdrawn from the validator #${index}`,
360+
`${formatBalance(amount, { adaptiveDecimals: true }).trimmed} ETH has been withdrawn from the validator #${index}`,
361361
},
362362
},
363363
topUp: {
@@ -370,11 +370,13 @@ export const vaultTexts = {
370370
actionDisabled: 'Top up unavailable',
371371
validatorWithoutPDG: `Top-ups are unavailable for this validator because it has not been proven for Predeposit Guarantee. To enable top-ups in this interface, please prove the validator.`,
372372
depositPaused: `Top-ups are unavailable due to temporary restrictions on deposits from the stVault Balance to validators.`,
373+
availableBalanceLow: (amount: bigint) =>
374+
`Top-ups are unavailable due to low available balance ${formatBalance(amount, { adaptiveDecimals: true }).trimmed} ETH`,
373375
txModal: {
374376
loadingText: (index: number, amount: bigint) =>
375-
`You are topping up the validator #${index} with ${formatBalance(amount).trimmed} ETH`,
377+
`You are topping up the validator #${index} with ${formatBalance(amount, { adaptiveDecimals: true }).trimmed} ETH`,
376378
mainCompleteText: (index: number, amount: bigint) =>
377-
`The validator #${index} has been topped up with ${formatBalance(amount).trimmed} ETH`,
379+
`The validator #${index} has been topped up with ${formatBalance(amount, { adaptiveDecimals: true }).trimmed} ETH`,
378380
},
379381
},
380382
},

shared/components/value-with-loader/value-with-loader.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type InlineLoaderProps = {
88
height?: number;
99
placeholder?: ReactNode;
1010
loader?: ReactNode;
11+
showBy?: boolean;
1112
};
1213

1314
export const InlineLoader: FC<PropsWithChildren<InlineLoaderProps>> = ({
@@ -17,13 +18,16 @@ export const InlineLoader: FC<PropsWithChildren<InlineLoaderProps>> = ({
1718
loader,
1819
width,
1920
height,
21+
showBy,
2022
}) => {
2123
if (isLoading)
2224
return loader ? (
2325
loader
2426
) : (
2527
<InlineLoaderStyled width={width} height={height} />
2628
);
29+
30+
if (showBy === false) return placeholder ?? null;
2731
if (children === undefined) return placeholder || null;
2832

2933
return children;

0 commit comments

Comments
 (0)