// Copyright 2017-2020 @polkadot/app-contracts authors & contributors // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. import { TxModalProps as Props } from './types'; import React, { useState, useEffect } from 'react'; import { Button, InputAddress, Modal } from '@polkadot/react-components'; // import { useTx } from '@polkadot/react-hooks'; import { isUndefined } from '@polkadot/util'; import translate from './translate'; function TxModal
({
t,
accountId,
onChangeAccountId,
sendTx,
isSending,
trigger: Trigger,
header = t | null {
const isControlled = !isUndefined(props.isOpen);
const [isOpen, setIsOpen] = useState(isControlled ? props.isOpen : false);
const onOpen = (): void => {
!isControlled && setIsOpen(true);
props.onOpen && props.onOpen();
};
const onClose = (): void => {
!isControlled && setIsOpen(false);
props.onClose && props.onClose();
};
const onSend = (): void => {
sendTx();
onClose();
};
// const onStart = (): void => {
// props.onSubmit && props.onSubmit();
// };
// const onFailed = (): void => {
// props.onFailed && props.onFailed();
// };
// const onSuccess = (): void => {
// !isControlled && setIsOpen(false);
// props.onSuccess && props.onSuccess();
// };
// const txState = useTx(
// txSource,
// {
// ...(props.accountId ? { accountId: props.accountId } : {}),
// onChangeAccountId: props.onChangeAccountId,
// onStart,
// onFailed,
// onSuccess
// }
// );
// const { accountId, onChangeAccountId, isSending, sendTx } = th
useEffect((): void => {
!isUndefined(props.isOpen) && setIsOpen(props.isOpen);
}, [props.isOpen]);
const allModalProps = {
className: ['ui--Modal', modalProps.className || ''].join(' '),
dimmer: 'inverted',
header,
...modalProps,
onClose,
open: isOpen
};
return (
<>
{Trigger &&