/** * 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 { FC } from 'react'; import { Modal } from '../../ui/modal/modal'; import { Button } from '../../ui/button'; import { useI18n } from '../../../features/settings/hooks/use-i18n'; import styles from './low-balance-modal.module.css'; export type LowBalanceMode = 'reduce' | 'topup' | 'gasless'; const MESSAGE_KEY_BY_MODE: Record = { reduce: 'lowBalance.messageReduce', topup: 'lowBalance.messageTopup', gasless: 'lowBalance.messageGasless', }; export interface LowBalanceModalProps { open: boolean; /** * `reduce` — user can fix it by reducing the amount (shows Change/Cancel). Requires `onChange`. * `topup` — reducing doesn't help, user must top up TON (shows Close only). * `gasless` — alternative path via gasless flow (shows Switch/Cancel). Requires `onSwitchToGasless`. */ mode: LowBalanceMode; /** Required amount in TON, formatted as a decimal string (e.g. "0.423"). */ requiredTon: string; onCancel: () => void; /** Primary action for `reduce` mode. */ onChange?: () => void; /** Primary action for `gasless` mode. */ onSwitchToGasless?: () => void; } export const LowBalanceModal: FC = ({ open, mode, requiredTon, onCancel, onChange, onSwitchToGasless, }) => { const { t } = useI18n(); const messageKey = MESSAGE_KEY_BY_MODE[mode]; return ( !isOpen && onCancel()} title={t('lowBalance.title')}>

{t(messageKey, { amount: requiredTon })}

{mode === 'reduce' && ( <> )} {mode === 'gasless' && ( <> )} {mode === 'topup' && ( )}
); };