diff --git a/js/lbry.js b/js/lbry.js index cf3e88770..d1216b6f1 100644 --- a/js/lbry.js +++ b/js/lbry.js @@ -296,7 +296,7 @@ lbry.formatCredits = function(amount, precision) lbry.formatName = function(name) { // Converts LBRY name to standard format (all lower case, no special characters) - return name.toLowerCase().replace(/[^a-z0-9\-]/, ''); + return name.toLowerCase().replace(/[^a-z0-9\-]/g, ''); } lbry.loadJs = function(src, type, onload) diff --git a/js/page/publish.js b/js/page/publish.js index 063e52efa..f5181c85f 100644 --- a/js/page/publish.js +++ b/js/page/publish.js @@ -18,7 +18,7 @@ var PublishPage = React.createClass({ }); var checkFields = this._requiredFields.slice(); - if (!this.state.nameIsMine) { + if (!this.state.myClaimExists) { checkFields.push('file'); } @@ -43,7 +43,7 @@ var PublishPage = React.createClass({ if (this.state.nameIsMine) { // Pre-populate with existing metadata - var metadata = Object.assign({}, this.state.claimMetadata); + var metadata = Object.assign({}, this.state.myClaimMetadata); if (this.refs.file.getValue() !== '') { delete metadata.sources; } @@ -111,9 +111,10 @@ var PublishPage = React.createClass({ feeAmount: '', feeCurrency: 'USD', nameResolved: false, - nameIsMine: false, - claimValue: 0.0, - claimMetadata: null, + topClaimValue: 0.0, + myClaimValue: 0.0, + myClaimMetadata: null, + myClaimExists: null, fileInfo: null, copyrightNotice: '', otherLicenseDescription: '', @@ -159,27 +160,33 @@ var PublishPage = React.createClass({ nameResolved: false, }); } else { - lbry.getClaimInfo(name, (claimInfo) => { - if (name != this.refs.name.getValue()) { - return; - } + lbry.getMyClaim(name, (myClaimInfo) => { + lbry.getClaimInfo(name, (claimInfo) => { + if (name != this.refs.name.getValue()) { + return; + } - var newState = { - name: name, - nameResolved: true, - nameIsMine: claimInfo.is_mine, - claimValue: parseFloat(claimInfo.amount), - claimMetadata: claimInfo.value, - }; + var topClaimIsMine = (myClaimInfo && myClaimInfo.amount >= claimInfo.amount); - if (claimInfo.is_mine) { - newState.bid = claimInfo.amount; - } else if (this.state.nameIsMine && !claimInfo.name_is_mine) { - // Just changed away from a name we control, so clear pre-fill - newState.bid = ''; - } + var newState = { + name: name, + nameResolved: true, + topClaimValue: parseFloat(claimInfo.amount), + myClaimExists: !!myClaimInfo, + myClaimValue: parseFloat(myClaimInfo.amount), + myClaimMetadata: myClaimInfo.value, + topClaimIsMine: topClaimIsMine, + }; - this.setState(newState); + if (topClaimIsMine) { + newState.bid = myClaimInfo.amount; + } else if (this.state.myClaimMetadata) { + // Just changed away from a name we have a claim on, so clear pre-fill + newState.bid = ''; + } + + this.setState(newState); + }); }); } }); @@ -320,8 +327,8 @@ var PublishPage = React.createClass({ { (!this.state.name ? '' : (! this.state.nameResolved ? The name {this.state.name} is available. - : (this.state.nameIsMine ? You already control the name {this.state.name}. You can use this page to update your claim. - : The name {this.state.name} is currently claimed for {lbry.formatCredits(this.state.claimValue)} credits.))) + : (this.state.myClaimExists ? You already have a claim on the name {this.state.name}. You can use this page to update your claim. + : The name {this.state.name} is currently claimed for {lbry.formatCredits(this.state.topClaimValue)} credits.))) }