// Copyright 2017-2020 @polkadot/app-accounts 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 { SubmittableExtrinsic } from '@polkadot/api/promise/types'; import BN from 'bn.js'; import React, { useEffect, useState } from 'react'; import styled from 'styled-components'; import { useApi } from '@polkadot/react-hooks'; import { Available } from '@polkadot/react-query'; import InputAddress from './InputAddress'; import InputBalance from './InputBalance'; import Modal from './Modal'; import TxButton from './TxButton'; import { useTranslation } from './translate'; interface Props { className?: string; onClose: () => void; recipientId?: string; senderId?: string; } const ZERO = new BN(0); function Transfer ({ className, onClose, recipientId: propRecipientId, senderId: propSenderId }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const [amount, setAmount] = useState(new BN(0)); const [extrinsic, setExtrinsic] = useState(null); const [hasAvailable] = useState(true); const [maxBalance] = useState(new BN(0)); const [recipientId, setRecipientId] = useState(propRecipientId || null); const [senderId, setSenderId] = useState(propSenderId || null); useEffect((): void => { senderId && recipientId && setExtrinsic( () => api.tx.balances.transfer(recipientId, amount || ZERO) ); }, [api, amount, recipientId, senderId]); const transferrable = {t('transferrable')}; return (
} onChange={setSenderId} type='account' /> } onChange={setRecipientId} type='allPlus' />
); } export default React.memo(styled(Transfer)` article.padded { box-shadow: none; margin-left: 2rem; } .balance { margin-bottom: 0.5rem; text-align: right; padding-right: 1rem; .label { opacity: 0.7; } } label.with-help { flex-basis: 10rem; } `);