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

feat(staking): use tolgee keys #976

Merged
5 changes: 4 additions & 1 deletion apps/shell/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
},
"governance": {},
"main": {},
"stacking": {},
"stacking": {
"attention-withdrawal-warning": "Attention! If in the future you want to withdraw the staked funds, it will take {{count}} day{count, plural, one {} other {s}}",
"funds-undelegated-in-days": "The funds will be undelegated within {count, plural, one {# day} other {# days}}"
},
"uc-dao": {},
"utils": {
"invalid-address": "Please enter a valid address",
Expand Down
2 changes: 2 additions & 0 deletions apps/shell/src/tolgee/shared.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FormatIcu } from '@tolgee/format-icu';
import { DevTools, Tolgee, FormatSimple, TolgeeStaticData } from '@tolgee/web';

export type Locale = 'en' | 'ar' | 'id' | 'tr';
Expand Down Expand Up @@ -53,6 +54,7 @@ export function TolgeeBase() {
Tolgee()
.use(FormatSimple())
.use(DevTools())
.use(FormatIcu())
// Preset shared settings
.updateDefaults({
apiKey,
Expand Down
11 changes: 9 additions & 2 deletions libs/staking/src/lib/components/delegate-modal-hooked.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';
import { useCallback, useEffect, useRef, useState } from 'react';
import { useTranslate } from '@tolgee/react';
import Link from 'next/link';
import { usePostHog } from 'posthog-js/react';
import { useDebounceValue } from 'usehooks-ts';
Expand Down Expand Up @@ -45,6 +46,7 @@ export function DelegateModalHooked({
unboundingTime,
validatorCommission,
}: DelegateModalProps) {
const { t } = useTranslate('staking');
const { delegate, getDelegateEstimatedFee } = useStakingActions();
const [delegateAmount, setDelegateAmount] = useState<number | undefined>(
undefined,
Expand Down Expand Up @@ -96,7 +98,11 @@ export function DelegateModalHooked({
await toast.promise(
delegationPromise,
{
loading: <ToastLoading>Delegation in progress</ToastLoading>,
loading: (
<ToastLoading>
{t('delegation-progress', 'Delegation in progress')}
</ToastLoading>
),
success: (tx) => {
console.log('Delegation successful', { tx });
const txHash = tx?.txhash;
Expand All @@ -115,7 +121,7 @@ export function DelegateModalHooked({
return (
<ToastSuccess>
<div className="flex flex-col items-center gap-[8px] text-[20px] leading-[26px]">
<div>Delegation successful</div>
<div>{t('delegation-success', 'Delegation successful')}</div>
<div>
<Link
href={`${explorerLink}/tx/${txHash}`}
Expand Down Expand Up @@ -174,6 +180,7 @@ export function DelegateModalHooked({
memo,
fee,
toast,
t,
onClose,
explorerLink,
invalidateQueries,
Expand Down
40 changes: 28 additions & 12 deletions libs/staking/src/lib/components/delegate-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ReactNode, useCallback, useMemo, useState } from 'react';
import { useTranslate } from '@tolgee/react';
import clsx from 'clsx';
import {
Modal,
Expand Down Expand Up @@ -134,6 +135,7 @@ export function DelegateModal({
onSubmit,
onMemoChange,
}: DelegateModalProps) {
const { t } = useTranslate('stacking');
const [isMemoVisible, setMemoVisible] = useState(false);

const handleMaxButtonClick = useCallback(() => {
Expand Down Expand Up @@ -163,13 +165,21 @@ export function DelegateModal({

const amountHint = useMemo(() => {
if (amountError === 'min') {
return <span className="text-haqq-danger">Bellow minimal value</span>;
return (
<span className="text-haqq-danger">
{t('amount-error-min', 'Bellow minimal value')}
</span>
);
} else if (amountError === 'max') {
return <span className="text-haqq-danger">More than you have</span>;
return (
<span className="text-haqq-danger">
{t('amount-error-more-than-have', 'More than you have')}
</span>
);
}

return undefined;
}, [amountError]);
}, [amountError, t]);

return (
<Modal isOpen={isOpen} onClose={onClose}>
Expand All @@ -183,25 +193,31 @@ export function DelegateModal({
<div className="divide-haqq-modal-border divide-y divide-dashed">
<div className="pb-[24px]">
<ModalHeading className="mt-[24px] sm:mt-[4px]">
Delegate
{t('delegate', 'Delegate')}
</ModalHeading>
<WarningMessage light wrapperClassName="mt-[24px]">
{`Attention! If in the future you want to withdraw the staked funds, it will take ${unboundingTime} ${unboundingTime === 1 ? 'day' : 'days'}`}
{t(
'attention-withdrawal-warning',
'Attention! If in the future you want to withdraw the staked funds, it will take {count} day{count, plural, one {} other {s}}',
{
count: unboundingTime,
},
)}
</WarningMessage>
</div>

<div className="py-[24px]">
<div className="flex flex-col gap-[8px]">
<DelegateModalDetails
title="My balance"
title={t('my-balance', 'My balance')}
value={`${formatNumber(balance)} ${symbol.toUpperCase()}`}
/>
<DelegateModalDetails
title="My delegation"
title={t('my-delegation', 'My delegation')}
value={`${formatNumber(delegation)} ${symbol.toUpperCase()}`}
/>
<DelegateModalDetails
title="Commission"
title={t('commission', 'Commission')}
value={`${formatNumber(validatorCommission)}%`}
/>
</div>
Expand All @@ -227,7 +243,7 @@ export function DelegateModal({
setMemoVisible(true);
}}
>
Add memo
{t('add-memo', 'Add memo')}
</OrangeLink>
</div>
) : (
Expand All @@ -245,14 +261,14 @@ export function DelegateModal({
'px-[16px] py-[12px] text-[14px] font-[500] leading-[22px]',
'bg-[#E7E7E7]',
)}
placeholder="Add your memo"
placeholder={t('memo-placeholder', 'Add your memo')}
/>
</div>
)}

<div>
<DelegateModalDetails
title="Estimated fee"
title={t('estimated-fee', 'Estimated fee')}
value={`${fee ? formatNumber(fee, 0, 7) : '---'} ${symbol.toUpperCase()}`}
isValuePending={isFeePending}
/>
Expand All @@ -265,7 +281,7 @@ export function DelegateModal({
className="w-full"
disabled={isDisabled}
>
Confirm delegation
{t('confirm-delegation', 'Confirm delegation')}
</Button>
</div>
</div>
Expand Down
13 changes: 11 additions & 2 deletions libs/staking/src/lib/components/redelegate-modal-hooked.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { Validator } from '@evmos/provider';
import { useTranslate } from '@tolgee/react';
import Link from 'next/link';
import { usePostHog } from 'posthog-js/react';
import { useDebounceValue } from 'usehooks-ts';
Expand Down Expand Up @@ -48,6 +49,7 @@ export function RedelegateModalHooked({
validatorsList,
balance,
}: RedelegateModalProps) {
const { t } = useTranslate('stacking');
const { haqqAddress, ethAddress } = useAddress();

const { data: redelegationValidatorAmount } = useRedelegationValidatorAmount(
Expand Down Expand Up @@ -107,7 +109,11 @@ export function RedelegateModalHooked({
await toast.promise(
redelegationPromise,
{
loading: <ToastLoading>Redelegate in progress</ToastLoading>,
loading: (
<ToastLoading>
{t('redelegate-progress', 'Redelegate in progress')}
</ToastLoading>
),
success: (tx) => {
console.log('Redelegation successful', { tx });
const txHash = tx?.txhash;
Expand All @@ -126,7 +132,9 @@ export function RedelegateModalHooked({
return (
<ToastSuccess>
<div className="flex flex-col items-center gap-[8px] text-[20px] leading-[26px]">
<div>Redelegation successful</div>
<div>
{t('redelegate-success', 'Redelegation successful')}
</div>
<div>
<Link
href={`${explorerLink}/tx/${txHash}`}
Expand Down Expand Up @@ -181,6 +189,7 @@ export function RedelegateModalHooked({
memo,
fee,
toast,
t,
onClose,
explorerLink,
invalidateQueries,
Expand Down
16 changes: 9 additions & 7 deletions libs/staking/src/lib/components/redelegate-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ReactNode, useCallback, useMemo, useState } from 'react';
import { useTranslate } from '@tolgee/react';
import clsx from 'clsx';
import { formatUnits } from 'viem';
import {
Expand Down Expand Up @@ -84,6 +85,7 @@ export function RedelegateModal({
onMemoChange,
redelegationValidatorAmount,
}: RedelegateModalProps) {
const { t } = useTranslate('stacking');
const [isMemoVisible, setMemoVisible] = useState(false);

const delegationNumber = useMemo(() => {
Expand Down Expand Up @@ -133,14 +135,14 @@ export function RedelegateModal({
<div className="divide-haqq-modal-border divide-y divide-dashed">
<div className="pb-[24px]">
<ModalHeading className="mt-[24px] sm:mt-[4px]">
Redelegate
{t('redelegate', 'Redelegate')}
</ModalHeading>
</div>

<div className="py-[24px]">
<div className="flex flex-col gap-[8px]">
<DelegateModalDetails
title="My delegation"
title={t('my-delegation', 'My delegation')}
value={`${formatNumber(delegationNumber)} ${symbol.toUpperCase()}`}
/>
</div>
Expand All @@ -150,7 +152,7 @@ export function RedelegateModal({
<div className="py-[24px]">
<div className="flex flex-col gap-[8px]">
<DelegateModalDetails
title="Redelegation amount"
title={t('redelegate-amount', 'Redelegation amount')}
value={`${formatNumber(redelegationValidatorAmountNumber)} ${symbol.toUpperCase()}`}
/>
</div>
Expand Down Expand Up @@ -183,7 +185,7 @@ export function RedelegateModal({
setMemoVisible(true);
}}
>
Add memo
{t('add-memo', 'Add memo')}
</OrangeLink>
</div>
) : (
Expand All @@ -201,14 +203,14 @@ export function RedelegateModal({
'px-[16px] py-[12px] text-[14px] font-[500] leading-[22px]',
'bg-[#E7E7E7]',
)}
placeholder="Add your memo"
placeholder={t('memo-placeholder', 'Add your memo')}
/>
</div>
)}

<div>
<DelegateModalDetails
title="Estimated fee"
title={t('estimated-fee', 'Estimated fee')}
value={`${fee ? formatNumber(fee, 0, 7) : '---'} ${symbol.toUpperCase()}`}
isValuePending={isFeePending}
/>
Expand All @@ -221,7 +223,7 @@ export function RedelegateModal({
className="w-full"
disabled={isDisabled}
>
Confirm redelegation
{t('confirm-redelegation', 'Confirm redelegation')}
</Button>
</div>
</div>
Expand Down
15 changes: 11 additions & 4 deletions libs/staking/src/lib/components/staking-info.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useTranslate } from '@tolgee/react';
import clsx from 'clsx';
import Link from 'next/link';
import { usePostHog } from 'posthog-js/react';
Expand Down Expand Up @@ -37,6 +38,7 @@ import { StakingStatsDesktop, StakingStatsMobile } from './staking-stats';
import { shouldUsePrecompile } from '../constants';

function useStakingStats() {
const { t } = useTranslate('staking');
const [delegatedValsAddrs, setDelegatedValsAddrs] = useState<Array<string>>(
[],
);
Expand Down Expand Up @@ -95,15 +97,19 @@ function useStakingStats() {
});

await toast.promise(claimAllRewardPromise, {
loading: <ToastLoading>Rewards claim in progress</ToastLoading>,
loading: (
<ToastLoading>
{t('rewards-progress', 'Rewards claim in progress')}
</ToastLoading>
),
success: (tx) => {
console.log('Rewards claimed', { tx });
const txHash = tx?.txhash;

return (
<ToastSuccess>
<div className="flex flex-col items-center gap-[8px] text-[20px] leading-[26px]">
<div>Rewards claimed</div>
<div>{t('rewards-claimed', 'Rewards claimed')}</div>
<div>
<Link
href={`${explorerLink}/tx/${txHash}`}
Expand Down Expand Up @@ -212,6 +218,7 @@ function useStakingStats() {
}

export function StakingInfo() {
const { t } = useTranslate('common');
const { ethAddress, haqqAddress } = useAddress();
const { openSelectWallet, isHaqqWallet } = useWallet();
const isWalletConnected = Boolean(ethAddress && haqqAddress);
Expand Down Expand Up @@ -243,15 +250,15 @@ export function StakingInfo() {
>
<Container className="flex min-h-[100px] flex-col items-center justify-center gap-[12px]">
<div className="font-guise text-[14px] leading-[22px] md:text-[18px] md:leading-[28px]">
You should connect wallet first
{t('connect-wallet-message', 'You should connect wallet first')}
</div>
<div>
<Button
onClick={openSelectWallet}
variant={2}
className="text-black hover:bg-transparent hover:text-white"
>
Connect wallet
{t('connect-wallet-btn', 'Connect wallet')}
</Button>
</div>
</Container>
Expand Down
Loading