lbry-desktop/src/renderer/component/walletSendTip/view.jsx

97 lines
2.4 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import React from 'react';
2018-03-26 23:32:43 +02:00
import Button from 'component/button';
import { FormField } from 'component/common/form';
import UriIndicator from 'component/uriIndicator';
import type { Claim } from 'types/claim';
2017-09-17 22:33:52 +02:00
2018-03-26 23:32:43 +02:00
type Props = {
uri: string,
title: string,
claim: Claim,
2018-03-26 23:32:43 +02:00
errorMessage: string,
isPending: boolean,
sendSupport: (number, string, string) => void,
onCancel: () => void,
sendTipCallback?: () => void,
};
type State = {
amount: number,
};
class WalletSendTip extends React.PureComponent<Props, State> {
constructor(props: Props) {
2017-09-17 22:33:52 +02:00
super(props);
this.state = {
2018-03-26 23:32:43 +02:00
amount: 0,
2017-09-17 22:33:52 +02:00
};
2018-03-26 23:32:43 +02:00
(this: any).handleSendButtonClicked = this.handleSendButtonClicked.bind(this);
2017-09-17 22:33:52 +02:00
}
handleSendButtonClicked() {
2018-04-04 01:58:58 +02:00
const { claim, uri, sendSupport, sendTipCallback } = this.props;
const { claim_id: claimId } = claim;
2018-03-26 23:32:43 +02:00
const { amount } = this.state;
sendSupport(amount, claimId, uri);
// ex: close modal
if (sendTipCallback) {
sendTipCallback();
}
2017-09-17 22:33:52 +02:00
}
2018-03-26 23:32:43 +02:00
handleSupportPriceChange(event: SyntheticInputEvent<*>) {
2017-09-17 22:33:52 +02:00
this.setState({
amount: Number(event.target.value),
});
}
render() {
2018-04-04 01:58:58 +02:00
const { title, errorMessage, isPending, uri, onCancel } = this.props;
2017-09-17 22:33:52 +02:00
return (
<div>
2018-03-26 23:32:43 +02:00
<div className="card__title">
2017-11-24 15:31:05 +01:00
<h1>
2018-03-26 23:32:43 +02:00
{__('Send a tip to')} <UriIndicator uri={uri} />
2017-11-24 15:31:05 +01:00
</h1>
2017-09-17 22:33:52 +02:00
</div>
<div className="card__content">
2018-03-26 23:32:43 +02:00
<FormField
label={__('Amount')}
postfix={__('LBC')}
2018-03-26 23:32:43 +02:00
className="input--price-amount"
error={errorMessage}
2017-09-17 22:33:52 +02:00
min="0"
step="any"
2017-09-17 22:33:52 +02:00
type="number"
2018-03-26 23:32:43 +02:00
placeholder="1.00"
onChange={event => this.handleSupportPriceChange(event)}
2017-09-17 22:33:52 +02:00
helper={
<span>
2018-03-26 23:32:43 +02:00
{__(`This will appear as a tip for ${title} located at ${uri}.`)}{' '}
<Button label={__('Learn more')} button="link" href="https://lbry.io/faq/tipping" />
2017-09-17 22:33:52 +02:00
</span>
}
/>
2018-03-26 23:32:43 +02:00
<div className="card__actions">
<Button
2017-09-17 22:33:52 +02:00
button="primary"
2018-03-26 23:32:43 +02:00
label={__('Send')}
2017-09-17 22:33:52 +02:00
disabled={isPending}
2018-03-26 23:32:43 +02:00
onClick={this.handleSendButtonClicked}
2017-09-17 22:33:52 +02:00
/>
2018-03-26 23:32:43 +02:00
<Button button="alt" label={__('Cancel')} onClick={onCancel} navigateParams={{ uri }} />
2017-09-17 22:33:52 +02:00
</div>
</div>
</div>
);
}
}
export default WalletSendTip;