Tell user to reduce 'Channel Description' when exceeded tx-limit.

## Issue
Second attempt at 5571: Limit description length on channel edit

## Changes
- Undo #5573: restore limit back to 5000.
- Translate the `bad-txns-claimscriptsize-toolarge (code 16)` error into `Transaction limit reached. Try reducing the Description length.`
This commit is contained in:
infinite-persistence 2021-02-25 09:53:56 +08:00 committed by Sean Yesmunt
parent df17504649
commit 277a1d5d1f
3 changed files with 36 additions and 30 deletions

View file

@ -1586,5 +1586,6 @@
"Creator tools": "Creator tools",
"Interacting as %channelName%": "Interacting as %channelName%",
"Page Not Found": "Page Not Found",
"Transaction limit reached. Try reducing the Description length.": "Transaction limit reached. Try reducing the Description length.",
"--end--": "--end--"
}

View file

@ -6,7 +6,7 @@ import classnames from 'classnames';
import { FormField } from 'component/common/form';
import Button from 'component/button';
import TagsSearch from 'component/tagsSearch';
import { FF_MAX_CHARS_IN_DESCRIPTION_CHANNEL } from 'constants/form-field';
import { FF_MAX_CHARS_IN_DESCRIPTION } from 'constants/form-field';
import ErrorText from 'component/common/error-text';
import ChannelThumbnail from 'component/channelThumbnail';
import { isNameValid, parseURI } from 'lbry-redux';
@ -39,17 +39,17 @@ type Props = {
tags: Array<string>,
locations: Array<string>,
languages: Array<string>,
updateChannel: any => Promise<any>,
updateChannel: (any) => Promise<any>,
updatingChannel: boolean,
updateError: string,
createChannel: any => Promise<any>,
createChannel: (any) => Promise<any>,
createError: string,
creatingChannel: boolean,
clearChannelErrors: () => void,
onDone: () => void,
openModal: (
id: string,
{ onUpdate: string => void, assetName: string, helpText: string, currentValue: string, title: string }
{ onUpdate: (string) => void, assetName: string, helpText: string, currentValue: string, title: string }
) => void,
uri: string,
disabled: boolean,
@ -118,7 +118,7 @@ function ChannelForm(props: Props) {
languages: languages || [],
locations: locations || [],
tags: tags
? tags.map(tag => {
? tags.map((tag) => {
return { name: tag };
})
: [],
@ -181,13 +181,13 @@ function ChannelForm(props: Props) {
function handleSubmit() {
if (uri) {
updateChannel(params).then(success => {
updateChannel(params).then((success) => {
if (success) {
onDone();
}
});
} else {
createChannel(params).then(success => {
createChannel(params).then((success) => {
if (success) {
analytics.apiLogPublish(success);
onDone();
@ -196,6 +196,12 @@ function ChannelForm(props: Props) {
}
}
const LIMIT_ERR_PARTIAL_MSG = 'bad-txns-claimscriptsize-toolarge (code 16)';
let errorMsg = updateError || createError;
if (errorMsg && errorMsg.includes(LIMIT_ERR_PARTIAL_MSG)) {
errorMsg = __('Transaction limit reached. Try reducing the Description length.');
}
React.useEffect(() => {
let nameError;
if (!name && name !== undefined) {
@ -222,7 +228,7 @@ function ChannelForm(props: Props) {
title={__('Cover')}
onClick={() =>
openModal(MODALS.IMAGE_UPLOAD, {
onUpdate: coverUrl => handleCoverChange(coverUrl),
onUpdate: (coverUrl) => handleCoverChange(coverUrl),
title: __('Edit Cover Image'),
helpText: __('(6.25:1)'),
assetName: __('Cover Image'),
@ -246,7 +252,7 @@ function ChannelForm(props: Props) {
title={__('Edit')}
onClick={() =>
openModal(MODALS.IMAGE_UPLOAD, {
onUpdate: v => handleThumbnailChange(v),
onUpdate: (v) => handleThumbnailChange(v),
title: __('Edit Thumbnail Image'),
helpText: __('(1:1)'),
assetName: __('Thumbnail'),
@ -297,7 +303,7 @@ function ChannelForm(props: Props) {
value={params.name || channelName}
error={nameError}
disabled={!isNewChannel}
onChange={e => setParams({ ...params, name: e.target.value })}
onChange={(e) => setParams({ ...params, name: e.target.value })}
/>
</fieldset-group>
{!isNewChannel && <span className="form-field__help">{__('This field cannot be changed.')}</span>}
@ -308,7 +314,7 @@ function ChannelForm(props: Props) {
label={__('Title')}
placeholder={__('My Awesome Channel')}
value={params.title}
onChange={e => setParams({ ...params, title: e.target.value })}
onChange={(e) => setParams({ ...params, title: e.target.value })}
/>
<FormField
type="markdown"
@ -316,8 +322,8 @@ function ChannelForm(props: Props) {
label={__('Description')}
placeholder={__('Description of your content')}
value={params.description}
onChange={text => setParams({ ...params, description: text })}
textAreaMaxLength={FF_MAX_CHARS_IN_DESCRIPTION_CHANNEL}
onChange={(text) => setParams({ ...params, description: text })}
textAreaMaxLength={FF_MAX_CHARS_IN_DESCRIPTION}
/>
</>
}
@ -336,7 +342,7 @@ function ChannelForm(props: Props) {
error={bidError}
min="0.0"
disabled={false}
onChange={event => handleBidChange(parseFloat(event.target.value))}
onChange={(event) => handleBidChange(parseFloat(event.target.value))}
placeholder={0.1}
helper={
<>
@ -357,17 +363,17 @@ function ChannelForm(props: Props) {
limitSelect={MAX_TAG_SELECT}
tagsPassedIn={params.tags || []}
label={__('Selected Tags')}
onRemove={clickedTag => {
const newTags = params.tags.slice().filter(tag => tag.name !== clickedTag.name);
onRemove={(clickedTag) => {
const newTags = params.tags.slice().filter((tag) => tag.name !== clickedTag.name);
setParams({ ...params, tags: newTags });
}}
onSelect={newTags => {
newTags.forEach(newTag => {
if (!params.tags.map(savedTag => savedTag.name).includes(newTag.name)) {
onSelect={(newTags) => {
newTags.forEach((newTag) => {
if (!params.tags.map((savedTag) => savedTag.name).includes(newTag.name)) {
setParams({ ...params, tags: [...params.tags, newTag] });
} else {
// If it already exists and the user types it in, remove it
setParams({ ...params, tags: params.tags.filter(tag => tag.name !== newTag.name) });
setParams({ ...params, tags: params.tags.filter((tag) => tag.name !== newTag.name) });
}
});
}}
@ -386,7 +392,7 @@ function ChannelForm(props: Props) {
placeholder={__('aprettygoodsite.com')}
disabled={false}
value={params.website}
onChange={e => setParams({ ...params, website: e.target.value })}
onChange={(e) => setParams({ ...params, website: e.target.value })}
/>
<FormField
type="text"
@ -395,20 +401,20 @@ function ChannelForm(props: Props) {
placeholder={__('yourstruly@example.com')}
disabled={false}
value={params.email}
onChange={e => setParams({ ...params, email: e.target.value })}
onChange={(e) => setParams({ ...params, email: e.target.value })}
/>
<FormField
name="language_select"
type="select"
label={__('Primary Language')}
onChange={event => handleLanguageChange(0, event.target.value)}
onChange={(event) => handleLanguageChange(0, event.target.value)}
value={primaryLanguage}
helper={__('Your main content language')}
>
<option key={'pri-langNone'} value={LANG_NONE}>
{__('None selected')}
</option>
{Object.keys(SUPPORTED_LANGUAGES).map(language => (
{Object.keys(SUPPORTED_LANGUAGES).map((language) => (
<option key={language} value={language}>
{SUPPORTED_LANGUAGES[language]}
</option>
@ -418,7 +424,7 @@ function ChannelForm(props: Props) {
name="language_select2"
type="select"
label={__('Secondary Language')}
onChange={event => handleLanguageChange(1, event.target.value)}
onChange={(event) => handleLanguageChange(1, event.target.value)}
value={secondaryLanguage}
disabled={!languageParam[0]}
helper={__('Your other content language')}
@ -427,8 +433,8 @@ function ChannelForm(props: Props) {
{__('None selected')}
</option>
{Object.keys(SUPPORTED_LANGUAGES)
.filter(lang => lang !== languageParam[0])
.map(language => (
.filter((lang) => lang !== languageParam[0])
.map((language) => (
<option key={language} value={language}>
{SUPPORTED_LANGUAGES[language]}
</option>
@ -456,8 +462,8 @@ function ChannelForm(props: Props) {
/>
<Button button="link" label={__('Cancel')} onClick={onDone} />
</div>
{updateError || createError ? (
<ErrorText>{updateError || createError}</ErrorText>
{errorMsg ? (
<ErrorText>{errorMsg}</ErrorText>
) : (
<p className="help">
{__('After submitting, it will take a few minutes for your changes to be live for everyone.')}

View file

@ -1,5 +1,4 @@
export const FF_MAX_CHARS_DEFAULT = 2000;
export const FF_MAX_CHARS_IN_COMMENT = 2000;
export const FF_MAX_CHARS_IN_DESCRIPTION = 5000;
export const FF_MAX_CHARS_IN_DESCRIPTION_CHANNEL = 3000;
export const FF_MAX_CHARS_IN_POST = 10000;