lbry-desktop/ui/modal/modalConfirmTransaction/view.jsx

93 lines
3.3 KiB
React
Raw Permalink Normal View History

// @flow
import React from 'react';
2019-07-18 00:22:47 +02:00
import Button from 'component/button';
import { Form } from 'component/common/form';
import { Modal } from 'modal/modal';
2020-05-01 19:55:42 +02:00
import Card from 'component/common/card';
2020-09-02 22:08:37 +02:00
import LbcSymbol from 'component/common/lbc-symbol';
import ClaimPreview from 'component/claimPreview';
type TipParams = { amount: number, claim_id: string, channel_id?: string };
type Props = {
destination: string,
amount: number,
closeModal: () => void,
sendToAddress: (string, number) => void,
sendTip: (TipParams, boolean) => void,
isAddress: boolean,
claim: StreamClaim,
activeChannelClaim: ?ChannelClaim,
incognito: boolean,
setConfirmed: (boolean) => void,
};
class ModalConfirmTransaction extends React.PureComponent<Props> {
onConfirmed() {
const { closeModal, sendToAddress, sendTip, amount, destination, isAddress, claim, setConfirmed } = this.props;
if (!isAddress) {
const claimId = claim && claim.claim_id;
const tipParams: TipParams = { amount: amount, claim_id: claimId };
sendTip(tipParams, false);
} else {
sendToAddress(destination, amount);
}
setConfirmed(true);
closeModal();
}
render() {
const { amount, destination, closeModal, isAddress, incognito, activeChannelClaim } = this.props;
const activeChannelUrl = activeChannelClaim && activeChannelClaim.canonical_url;
2020-05-01 19:55:42 +02:00
const title = __('Confirm Transaction');
return (
2020-05-01 19:55:42 +02:00
<Modal isOpen contentLabel={title} type="card" onAborted={closeModal}>
2019-07-21 23:31:22 +02:00
<Form onSubmit={() => this.onConfirmed()}>
2020-05-01 19:55:42 +02:00
<Card
title={title}
body={
2020-09-02 22:08:37 +02:00
<div className="section section--padded card--inline confirm__wrapper">
2020-05-01 19:55:42 +02:00
<div className="section">
2020-09-02 22:08:37 +02:00
<div className="confirm__label">{__('Sending')}</div>
2020-09-10 17:54:41 +02:00
<div className="confirm__value">{<LbcSymbol postfix={amount} size={22} />}</div>
{!isAddress && <div className="confirm__label">{__('From')}</div>}
{!isAddress && (
<div className="confirm__value">
{incognito ? (
'Anonymous'
) : (
<ClaimPreview key={activeChannelUrl} uri={activeChannelUrl} actions={''} type={'small'} hideMenu hideRepostLabel />
)}
</div>
)}
2020-09-02 22:08:37 +02:00
<div className="confirm__label">{__('To')}</div>
<div className="confirm__value">
{!isAddress ? (
<ClaimPreview key={destination} uri={destination} actions={''} type={'small'} hideMenu hideRepostLabel />
) : (
destination
)}
</div>
2020-05-01 19:55:42 +02:00
</div>
2020-09-02 22:08:37 +02:00
</div>
2020-05-01 19:55:42 +02:00
}
actions={
<>
<div className="section__actions">
<Button autoFocus button="primary" label={__('Send')} onClick={() => this.onConfirmed()} />
<Button button="link" label={__('Cancel')} onClick={closeModal} />
</div>
<p className="help">{__('Once the transaction is sent, it cannot be reversed.')}</p>
</>
}
/>
2019-07-18 00:22:47 +02:00
</Form>
</Modal>
);
}
}
export default ModalConfirmTransaction;