) => {
- event.preventDefault();
- const { value, name } = event.target;
- // FIXME this is a hack
- if (name === 'amount') {
- setWithdrawObject((prevState) => ({
- ...prevState,
- [name]: parseInt(value),
- }));
- } else {
- setWithdrawObject((prevState) => ({ ...prevState, [name]: value }));
- }
- },
- []
- );
-
- const createWithdrawal = () => {
- if (!amount && amount === 0 && typeof amount === 'number') {
- setError(`${t('withdraw-tab.error-amount')}`);
- return;
- }
- if (!address) {
- setError(`${t('withdraw-tab.error-address')}`);
- return;
- }
- // TODO: address validation
- setError('');
- setModalState(true);
- };
-
- const startWithdrawal = () => {
- gateway
- .requestWithdrawal(federationId, amount, address)
- .then((txId) => {
- // FIXME: show this in a better way
- alert(`${t('withdraw-tab.your-transaction')} ${txId}`);
- setWithdrawObject({ ...withdrawObject, amount: 0, address: '' });
- setModalState(false);
- })
- .catch(({ error }) => {
- console.error(error);
- setError(`${t('withdraw-tab.error-request')}`);
- });
- };
-
- return (
-
-
-
-
- {t('withdraw-tab.tab-header')}
-
-
- {t('withdraw-tab.total_bitcoin')} {withdrawObject.amount / 100000}{' '}
- {t('common.btc')}
-
-
- {t('withdraw-tab.withdraw_all')}
-
-
-
-
-
- {t('common.amount')}
-
- handleInputChange(e)}
- name='amount'
- />
-
-
-
- {t('common.address')}
-
- handleInputChange(e)}
- name='address'
- />
-
-
- {error && (
-
-
- {t('withdraw-tab.error')}: {error}
-
-
- )}
-
-
-
-
-
- {modalState && (
- {
- setModalState(false);
- }}
- onCloseClickCallback={() => {
- setModalState(false);
- }}
- startWithdrawalCallback={startWithdrawal}
- />
- )}
-
- );
-});
-
-export interface ConfirmWithdrawModalProps {
- open: boolean;
- txRequest: {
- amount: number;
- address: string;
- };
- onModalClickCallback: () => void;
- onCloseClickCallback: () => void;
- startWithdrawalCallback: () => void;
-}
-
-const ConfirmWithdrawModal = (
- props: ConfirmWithdrawModalProps
-): JSX.Element => {
- const { t } = useTranslation();
- const { open, txRequest, onModalClickCallback, startWithdrawalCallback } =
- props;
-
- return (
-
- <>
-
-
-
- {t('withdraw-tab.confirm-withdraw')}
-
-
-
-
- {t('common.amount')}:
-
- {txRequest.amount} {t('common.sats')}
-
-
- {t('withdraw-tab.to')}
-
- {t('common.address')}:
- {truncateStringFormat(txRequest.address)}
-
-
-
-
-
-
-
-
- >
-
- );
-};
-
-export interface TransactionViewProps {
- amount: number;
- address: string;
- txId: string;
- confirmationsRequired: number;
- federationId?: string;
-}
-
-export interface TransactionInfoProps {
- title: string;
- detail?: string | number;
- children?: React.ReactNode;
- onClick?: () => void;
- color?: string;
-}