Publish: name resolution bugfixes

This commit is contained in:
Alex Liebowitz 2017-04-11 00:12:34 -04:00
parent f64ad6e169
commit c49d229eef

View file

@ -171,44 +171,50 @@ var PublishPage = React.createClass({
}); });
const name = rawName.toLowerCase(); const name = rawName.toLowerCase();
lbry.resolve({uri: name}).then((info) => { lbry.getMyClaim(name, (myClaimInfo) => {
if (name != this.refs.name.getValue().toLowerCase()) { if (name != this.refs.name.getValue().toLowerCase()) {
// A new name has been typed already, so bail // A new name has been typed already, so bail
return; return;
} }
lbry.getMyClaim(name, (myClaimInfo) => { lbry.resolve({uri: name}).then((claimInfo) => {
lbry.getClaimInfo(name, (claimInfo) => { if (name != this.refs.name.getValue()) {
if (name != this.refs.name.getValue()) { return;
return; }
}
const topClaimIsMine = (myClaimInfo && myClaimInfo.amount >= claimInfo.amount); if (!claimInfo) {
this.setState({
name: name,
nameResolved: false,
myClaimExists: false,
});
} else {
const topClaimIsMine = (myClaimInfo && myClaimInfo.claim.amount >= claimInfo.claim.amount);
const newState = { const newState = {
name: name, name: name,
nameResolved: true, nameResolved: true,
topClaimValue: parseFloat(claimInfo.amount), topClaimValue: parseFloat(claimInfo.claim.amount),
myClaimExists: !!myClaimInfo, myClaimExists: !!myClaimInfo,
myClaimValue: myClaimInfo ? parseFloat(myClaimInfo.amount) : null, myClaimValue: myClaimInfo ? parseFloat(myClaimInfo.claim.amount) : null,
myClaimMetadata: myClaimInfo ? myClaimInfo.value : null, myClaimMetadata: myClaimInfo ? myClaimInfo.value : null,
topClaimIsMine: topClaimIsMine, topClaimIsMine: topClaimIsMine,
}; };
if (topClaimIsMine) { if (topClaimIsMine) {
newState.bid = myClaimInfo.amount; newState.bid = myClaimInfo.claim.amount;
} else if (this.state.myClaimMetadata) { } else if (this.state.myClaimMetadata) {
// Just changed away from a name we have a claim on, so clear pre-fill // Just changed away from a name we have a claim on, so clear pre-fill
newState.bid = ''; newState.bid = '';
} }
this.setState(newState); this.setState(newState);
}
}, () => { // Assume an error means the name is available
this.setState({
name: name,
nameResolved: false,
myClaimExists: false,
}); });
}); });
}, () => { // Assume an error means the name is available
this.setState({
name: name,
nameResolved: false,
myClaimExists: false,
});
}); });
}, },
handleBidChange: function(event) { handleBidChange: function(event) {