2019-06-28 09:27:55 +02:00
|
|
|
// @flow
|
2019-10-03 23:40:54 +02:00
|
|
|
import { CHANNEL_NEW, CHANNEL_ANONYMOUS, MINIMUM_PUBLISH_BID, INVALID_NAME_ERROR } from 'constants/claim';
|
2019-06-28 09:27:55 +02:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import { isNameValid } from 'lbry-redux';
|
|
|
|
import { FormField } from 'component/common/form';
|
|
|
|
import NameHelpText from './name-help-text';
|
|
|
|
import BidHelpText from './bid-help-text';
|
2019-09-27 20:56:15 +02:00
|
|
|
import Card from 'component/common/card';
|
2019-06-28 09:27:55 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
name: string,
|
|
|
|
channel: string,
|
|
|
|
uri: string,
|
2019-06-27 22:27:38 +02:00
|
|
|
bid: number,
|
2019-06-28 09:27:55 +02:00
|
|
|
balance: number,
|
|
|
|
isStillEditing: boolean,
|
|
|
|
myClaimForUri: ?StreamClaim,
|
|
|
|
isResolvingUri: boolean,
|
|
|
|
amountNeededForTakeover: number,
|
|
|
|
prepareEdit: ({}, string) => void,
|
|
|
|
updatePublishForm: ({}) => void,
|
|
|
|
};
|
|
|
|
|
2019-07-02 06:49:21 +02:00
|
|
|
function PublishName(props: Props) {
|
2019-06-28 09:27:55 +02:00
|
|
|
const {
|
|
|
|
name,
|
|
|
|
channel,
|
|
|
|
uri,
|
|
|
|
isStillEditing,
|
|
|
|
myClaimForUri,
|
2019-06-27 22:27:38 +02:00
|
|
|
bid,
|
2019-06-28 09:27:55 +02:00
|
|
|
isResolvingUri,
|
|
|
|
amountNeededForTakeover,
|
|
|
|
prepareEdit,
|
|
|
|
updatePublishForm,
|
|
|
|
balance,
|
|
|
|
} = props;
|
|
|
|
const [nameError, setNameError] = useState(undefined);
|
|
|
|
const [bidError, setBidError] = useState(undefined);
|
|
|
|
const previousBidAmount = myClaimForUri && Number(myClaimForUri.amount);
|
|
|
|
|
|
|
|
function editExistingClaim() {
|
|
|
|
if (myClaimForUri) {
|
|
|
|
prepareEdit(myClaimForUri, uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
let nameError;
|
|
|
|
if (!name) {
|
|
|
|
nameError = __('A name is required');
|
|
|
|
} else if (!isNameValid(name, false)) {
|
2019-10-03 23:40:54 +02:00
|
|
|
nameError = INVALID_NAME_ERROR;
|
2019-06-28 09:27:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setNameError(nameError);
|
|
|
|
}, [name]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
2019-11-22 01:24:43 +01:00
|
|
|
const totalAvailableBidAmount = previousBidAmount ? previousBidAmount + balance : balance;
|
2019-06-28 09:27:55 +02:00
|
|
|
|
|
|
|
let bidError;
|
|
|
|
if (bid === 0) {
|
|
|
|
bidError = __('Deposit cannot be 0');
|
2019-11-13 19:11:51 +01:00
|
|
|
} else if (bid < MINIMUM_PUBLISH_BID) {
|
2019-06-28 09:27:55 +02:00
|
|
|
bidError = __('Your deposit must be higher');
|
2020-03-02 18:11:14 +01:00
|
|
|
} else if (totalAvailableBidAmount < bid) {
|
|
|
|
bidError = __('Deposit cannot be higher than your balance');
|
|
|
|
} else if (totalAvailableBidAmount <= bid + 0.05) {
|
|
|
|
bidError = __('Please decrease your deposit to account for transaction fees or acquire more LBC.');
|
2019-06-28 09:27:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setBidError(bidError);
|
2020-03-02 18:11:14 +01:00
|
|
|
updatePublishForm({ bidError: bidError });
|
2019-06-28 09:27:55 +02:00
|
|
|
}, [bid, previousBidAmount, balance]);
|
|
|
|
|
|
|
|
return (
|
2019-09-27 20:56:15 +02:00
|
|
|
<Card
|
|
|
|
actions={
|
|
|
|
<React.Fragment>
|
|
|
|
<fieldset-group class="fieldset-group--smushed fieldset-group--disabled-prefix">
|
|
|
|
<fieldset-section>
|
|
|
|
<label>{__('Name')}</label>
|
|
|
|
<div className="form-field__prefix">{`lbry://${
|
|
|
|
!channel || channel === CHANNEL_ANONYMOUS || channel === CHANNEL_NEW ? '' : `${channel}/`
|
|
|
|
}`}</div>
|
|
|
|
</fieldset-section>
|
|
|
|
<FormField
|
|
|
|
type="text"
|
|
|
|
name="content_name"
|
|
|
|
value={name}
|
|
|
|
error={nameError}
|
|
|
|
onChange={event => updatePublishForm({ name: event.target.value })}
|
|
|
|
/>
|
|
|
|
</fieldset-group>
|
|
|
|
<div className="form-field__help">
|
|
|
|
<NameHelpText
|
|
|
|
uri={uri}
|
|
|
|
isStillEditing={isStillEditing}
|
|
|
|
myClaimForUri={myClaimForUri}
|
|
|
|
onEditMyClaim={editExistingClaim}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<FormField
|
|
|
|
type="number"
|
|
|
|
name="content_bid"
|
|
|
|
min="0"
|
|
|
|
step="any"
|
|
|
|
placeholder="0.123"
|
|
|
|
className="form-field--price-amount"
|
|
|
|
label={__('Deposit (LBC)')}
|
|
|
|
postfix="LBC"
|
|
|
|
value={bid}
|
|
|
|
error={bidError}
|
|
|
|
disabled={!name}
|
|
|
|
onChange={event => updatePublishForm({ bid: parseFloat(event.target.value) })}
|
2020-01-28 03:47:48 +01:00
|
|
|
onWheel={e => e.stopPropagation()}
|
2019-09-27 20:56:15 +02:00
|
|
|
helper={
|
|
|
|
<BidHelpText
|
2019-11-13 19:11:51 +01:00
|
|
|
uri={'lbry://' + name}
|
2019-09-27 20:56:15 +02:00
|
|
|
amountNeededForTakeover={amountNeededForTakeover}
|
|
|
|
isResolvingUri={isResolvingUri}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</React.Fragment>
|
|
|
|
}
|
|
|
|
/>
|
2019-06-28 09:27:55 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-07-02 06:49:21 +02:00
|
|
|
export default PublishName;
|