/** * Copyright (c) TonTech. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import type { ComponentProps, FC } from 'react'; import type { StakingQuote, StakingProviderInfo, StakingQuoteDirection } from '@ton/appkit'; import type { StakingProviderMetadata } from '@ton/appkit'; import { InfoBlock } from '../../../../components/ui/info-block'; import { useI18n } from '../../../settings/hooks/use-i18n'; import { formatAmount } from './utils'; export interface StakingInfoProps extends ComponentProps { quote: StakingQuote | undefined; isQuoteLoading: boolean; providerInfo: StakingProviderInfo | undefined; providerMetadata: StakingProviderMetadata | undefined; isProviderInfoLoading: boolean; direction?: StakingQuoteDirection; } export const StakingInfo: FC = ({ quote, isQuoteLoading, providerInfo, providerMetadata, isProviderInfoLoading, direction = 'stake', ...props }) => { const { t } = useI18n(); const receiveToken = providerMetadata?.receiveToken; const stakeToken = providerMetadata?.stakeToken; const youGetDecimals = direction === 'stake' ? receiveToken?.decimals : stakeToken?.decimals; const youGetTicker = direction === 'stake' ? receiveToken?.ticker : stakeToken?.ticker; return ( {t('staking.youGet')} {isQuoteLoading || isProviderInfoLoading ? ( ) : ( {formatAmount(quote?.amountOut, youGetDecimals)} {youGetTicker} )} {t('staking.currentApy')} {isProviderInfoLoading ? ( ) : ( {providerInfo?.apy !== undefined ? `${formatAmount(providerInfo.apy.toString(), 2)}%` : '—'} )} {receiveToken && ( {t('staking.exchangeRate')} {isProviderInfoLoading ? ( ) : ( 1 {stakeToken?.ticker} = {formatAmount(providerInfo?.exchangeRate, receiveToken.decimals)}{' '} {receiveToken.ticker} )} )} {t('staking.provider')} {providerMetadata?.name ? ( {providerMetadata.name} ) : ( )} ); };