lbry-desktop/src/ui/component/walletSendTip/view.jsx
Thomas Zarebczan a628776518 Few UX improvements
- add message about deleting/editing to comment create intro (feel free to remove, but I thought people would be wondering after they used em)
- add note on publish, link to faq
- better handling of own urls + takeovers
- Add manage email preferences to account page
- move recent believe send/receive (on the fence, but I think this is better)
- rewards messaging
- Add support button for own claims, fix up messaging around this
- Help page improvements
- Add privacy policy to settings/diagnostics option
- maybe a couple things I'm forgetting
2019-07-17 01:11:23 -04:00

120 lines
3.4 KiB
JavaScript

// @flow
import React from 'react';
import Button from 'component/button';
import { FormField, Form } from 'component/common/form';
type Props = {
uri: string,
claimIsMine: boolean,
title: string,
claim: StreamClaim,
isPending: boolean,
sendSupport: (number, string, string) => void,
onCancel: () => void,
sendTipCallback?: () => void,
balance: number,
};
type State = {
tipAmount: number,
tipError: string,
};
class WalletSendTip extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
tipAmount: 0,
tipError: '',
};
(this: any).handleSendButtonClicked = this.handleSendButtonClicked.bind(this);
}
handleSendButtonClicked() {
const { claim, uri, sendSupport, sendTipCallback } = this.props;
const { claim_id: claimId } = claim;
const { tipAmount } = this.state;
sendSupport(tipAmount, claimId, uri);
// ex: close modal
if (sendTipCallback) {
sendTipCallback();
}
}
handleSupportPriceChange(event: SyntheticInputEvent<*>) {
const { balance } = this.props;
const regexp = RegExp(/^(\d*([.]\d{0,8})?)$/);
const validTipInput = regexp.test(event.target.value);
const tipAmount = parseFloat(event.target.value);
let tipError;
if (!tipAmount) {
tipError = __('Tip must be a number');
} else if (tipAmount <= 0) {
tipError = __('Tip must be a positive number');
} else if (!validTipInput) {
tipError = __('Tip must have no more than 8 decimal places');
} else if (tipAmount === balance) {
tipError = __('Please decrease your tip to account for transaction fees');
} else if (tipAmount > balance) {
tipError = __('Not enough credits');
}
this.setState({
tipAmount,
tipError,
});
}
render() {
const { title, isPending, uri, onCancel, claimIsMine } = this.props;
const { tipAmount, tipError } = this.state;
return (
<React.Fragment>
<Form className="card__content">
<FormField
autoFocus
name="tip-input"
label={
(tipAmount && tipAmount !== 0 && `Tip ${tipAmount.toFixed(8).replace(/\.?0+$/, '')} LBC`) || __('Amount')
}
className="form-field--price-amount"
error={tipError}
min="0"
step="any"
type="number"
placeholder="1.23"
onChange={event => this.handleSupportPriceChange(event)}
inputButton={
<Button
button="primary"
label={__('Send')}
disabled={isPending || tipError || !tipAmount}
onClick={this.handleSendButtonClicked}
/>
}
helper={
<p>
{claimIsMine
? __('This will increase your overall bid amount for ')
: __('This will appear as a tip for ')}
{`"${title}" which will boost its ability to be discovered while active.`}{' '}
<Button label={__('Learn more')} button="link" href="https://lbry.com/faq/tipping" />
</p>
}
/>
</Form>
<div className="card__actions">
<Button button="link" label={__('Cancel')} onClick={onCancel} navigateParams={{ uri }} />
</div>
</React.Fragment>
);
}
}
export default WalletSendTip;