From 968506a8ddbd2b8310e7e3e13a4765e1b4c392a6 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Thu, 1 Sep 2016 03:28:07 -0400 Subject: [PATCH 1/2] Add lbry.formatName() --- js/lbry.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/js/lbry.js b/js/lbry.js index 00cbbe626..381dde98f 100644 --- a/js/lbry.js +++ b/js/lbry.js @@ -258,6 +258,11 @@ lbry.formatCredits = function(amount, precision) return amount.toFixed(precision || 1).replace(/\.?0+$/, ''); } +lbry.formatName = function(name) { + // Converts LBRY name to standard format (all lower case, no special characters) + return name.toLowerCase().replace(/[^a-z0-9\-]/, ''); +} + lbry.loadJs = function(src, type, onload) { var lbryScriptTag = document.getElementById('lbry'), From e453679729c146564dd1ff7d2ba756c4fed53c7c Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Thu, 1 Sep 2016 03:30:12 -0400 Subject: [PATCH 2/2] Lowercase and remove special chars from names on Publish page Also edited the text that appears next to the "name" box so the user always gets to sees the actual name that will be claimed. --- js/page/publish.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/js/page/publish.js b/js/page/publish.js index a47925da2..857fc1bb9 100644 --- a/js/page/publish.js +++ b/js/page/publish.js @@ -141,9 +141,9 @@ var PublishPage = React.createClass({ error.message); }, handleNameChange: function(event) { - var name = event.target.value; + var rawName = event.target.value; - if (!name) { + if (!rawName) { this.setState({ name: '', nameResolved: false, @@ -152,8 +152,11 @@ var PublishPage = React.createClass({ return; } + var name = lbry.formatName(rawName); + lbry.resolveName(name, (info) => { - if (name != this.refs.name.getValue()) { + if (name != lbry.formatName(this.refs.name.getValue())) { + // A new name has been typed already, so bail return; } @@ -285,9 +288,9 @@ var PublishPage = React.createClass({ lbry:// { (!this.state.name ? '' : - (! this.state.nameResolved ? This name is available: {this.state.name} - : (this.state.nameIsMine ? You already control this name. You can use this page to update your claim. - : This name is currently claimed for {lbry.formatCredits(this.state.claimValue)} credits.))) + (! 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.))) }
What LBRY name would you like to claim for this file?