From 97496c33da3a58c743b9fd21ceca39c9debe9920 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 9 Dec 2016 04:27:31 -0500 Subject: [PATCH 1/9] Make cost prop optional in --- js/page/discover.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/js/page/discover.js b/js/page/discover.js index f533a3afb..70bbd2e49 100644 --- a/js/page/discover.js +++ b/js/page/discover.js @@ -122,9 +122,11 @@ var SearchResultRow = React.createClass({
- - - + {'cost' in this.props + ? + + + : null}
lbry://{this.props.name}

@@ -173,7 +175,7 @@ var FeaturedContentItem = React.createClass({ return { metadata: null, title: null, - amount: 0.0, + cost: null, overlayShowing: false, }; }, @@ -206,10 +208,11 @@ var FeaturedContentItem = React.createClass({ return null; } + const costProp = this.state.cost === null ? {} : {cost: this.state.cost} return (
+ nsfw={this.state.metadata.nsfw} compact {... costProp} />
); } }); From 6963d877df655c614ab2436703745556fd0ec80e Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Tue, 6 Dec 2016 13:46:02 -0500 Subject: [PATCH 2/9] Break lbry.getCostEstimate() into 2 separate functions lbrynet now supports getting the total cost if you provide the "size" param, so we break this into two functions: lbry.getKeyFee() and lbry.getTotalCost() --- js/lbry.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/js/lbry.js b/js/lbry.js index 4be044fb0..76bd21a81 100644 --- a/js/lbry.js +++ b/js/lbry.js @@ -179,10 +179,17 @@ lbry.getMyClaim = function(name, callback) { lbry.call('get_my_claim', { name: name }, callback); } -lbry.getCostEstimate = function(name, callback) { +lbry.getKeyFee = function(name, callback) { lbry.call('get_est_cost', { name: name }, callback); } +lbry.getTotalCost = function(name, size, callback) { + lbry.call('get_est_cost', { + name: name, + size: size, + }, callback); +} + lbry.getPeersForBlobHash = function(blobHash, callback) { lbry.call('get_peers_for_hash', { blob_hash: blobHash }, callback) } From 0b58ae6e6e10adb920949e98c409fa67195e7fb6 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Wed, 7 Dec 2016 18:00:31 -0500 Subject: [PATCH 3/9] Add error and connection failure callbacks to Lighthouse methods --- js/lighthouse.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/js/lighthouse.js b/js/lighthouse.js index 73315cabb..588b924c8 100644 --- a/js/lighthouse.js +++ b/js/lighthouse.js @@ -15,23 +15,27 @@ var lighthouse = { lbry.jsonrpc_call(this.server + this.path, method, params, callback, errorCallback, connectFailedCallback, timeout); }, - search: function(query, callback) { + search: function(query, callback, errorCallback, connectFailedCallback, timeout) { let handleSearchFailed = function(tryNum=0) { if (tryNum > lighthouse._max_search_tries) { - throw new Error(`Could not connect to Lighthouse server. Last server attempted: ${lighthouse.server}`); + if (connectFailedCallback) { + connectFailedCallback(); + } else { + throw new Error(`Could not connect to Lighthouse server. Last server attempted: ${lighthouse.server}`); + } } else { // Randomly choose one of the other search servers to switch to let otherServers = lighthouse.servers.slice(); otherServers.splice(otherServers.indexOf(lighthouse.server), 1); lighthouse.server = otherServers[Math.round(Math.random() * (otherServers.length - 1))]; - lighthouse.call('search', [query], callback, undefined, function() { + lighthouse.call('search', [query], callback, errorCallback, function() { handleSearchFailed(tryNum + 1); }, lighthouse._search_timeout); } } - lighthouse.call('search', [query], callback, undefined, function() { handleSearchFailed() }, lighthouse._search_timeout); + lighthouse.call('search', [query], callback, errorCallback, function() { handleSearchFailed() }, lighthouse._search_timeout); } }; From d59c5c2a1cbf6ddd56abd9af40570c6e8332fe8b Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 9 Dec 2016 04:57:13 -0500 Subject: [PATCH 4/9] Add lbry.getSizeForName() --- js/lighthouse.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/js/lighthouse.js b/js/lighthouse.js index 588b924c8..0c5d6934a 100644 --- a/js/lighthouse.js +++ b/js/lighthouse.js @@ -36,6 +36,10 @@ var lighthouse = { } lighthouse.call('search', [query], callback, errorCallback, function() { handleSearchFailed() }, lighthouse._search_timeout); + }, + + getSizeForName: function(name, callback, errorCallback, connectFailedCallback, timeout) { + return lighthouse.call('get_size_for_name', [name], callback, errorCallback, connectFailedCallback, timeout); } }; From d9a4442cc360f4590a032d75fd76866e6c1cbcef Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 9 Dec 2016 01:54:18 -0500 Subject: [PATCH 5/9] Add lbry.getCostInfoForName() --- js/lbry.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/js/lbry.js b/js/lbry.js index 76bd21a81..9c013c0fa 100644 --- a/js/lbry.js +++ b/js/lbry.js @@ -1,3 +1,5 @@ +import lighthouse from './lighthouse.js'; + var lbry = { isConnected: false, rootPath: '.', @@ -194,6 +196,44 @@ lbry.getPeersForBlobHash = function(blobHash, callback) { lbry.call('get_peers_for_hash', { blob_hash: blobHash }, callback) } +lbry.getCostInfoForName = function(name, callback) { + /** + * Takes a LBRY name; will first try and calculate a total cost using + * Lighthouse. If Lighthouse can't be reached, it just retrives the + * key fee. + * + * Returns an object with members: + * - cost: Number; the calculated cost of the name + * - includes_data: Boolean; indicates whether or not the data fee info + * from Lighthouse is included. + */ + function getCostWithData(size, callback) { + lbry.getTotalCost(name, size, (cost) => { + callback({ + cost: cost, + includesData: true, + }); + }); + } + + function getCostNoData(name, callback) { + lbry.getKeyFee(name, (cost) => { + callback({ + cost: cost, + includesData: false, + }); + }); + } + + lighthouse.getSizeForName(name, (size) => { + getCostWithData(name, size, callback); + }, () => { + getCostNoData(name, callback); + }, () => { + getCostNoData(name, callback); + }); +} + lbry.getFileStatus = function(name, callback) { lbry.call('get_lbry_file', { 'name': name }, callback); } From 34a7d41dc77223b4ab71ac80f2ff3bebaba386ef Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Wed, 7 Dec 2016 18:03:16 -0500 Subject: [PATCH 6/9] Make search result tiles use new Lighthouse cost reporting Featured/Community Content and regular search results now calculate cost the same way, so instead of calculating the cost in the outer component we now do it inside itself. --- js/page/discover.js | 50 ++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/js/page/discover.js b/js/page/discover.js index 70bbd2e49..77633ca84 100644 --- a/js/page/discover.js +++ b/js/page/discover.js @@ -46,8 +46,7 @@ var SearchResults = React.createClass({ var mediaType = lbry.getMediaType(result.value.content_type); rows.push( + description={result.value.description} nsfw={result.value.nsfw} mediaType={mediaType} /> ); }); return ( @@ -93,6 +92,8 @@ var SearchResultRow = React.createClass({ return { downloading: false, isHovered: false, + cost: null, + costIncludesData: null, } }, handleMouseOver: function() { @@ -105,6 +106,21 @@ var SearchResultRow = React.createClass({ isHovered: false, }); }, + componentWillMount: function() { + if ('cost' in this.props) { + this.setState({ + cost: this.props.cost, + costIncludesData: this.props.costIncludesData, + }); + } else { + lbry.getCostInfoForName(this.props.name, ({cost, includesData}) => { + this.setState({ + cost: cost, + costIncludesData: includesData, + }); + }); + } + }, render: function() { var obscureNsfw = !lbry.getClientSetting('showNsfw') && this.props.nsfw; if (!this.props.compact) { @@ -122,9 +138,9 @@ var SearchResultRow = React.createClass({

- {'cost' in this.props + {this.state.cost !== null ? - + : null}
lbry://{this.props.name}
@@ -185,21 +201,18 @@ var FeaturedContentItem = React.createClass({ }, componentDidMount: function() { - this.resolveSearch = true; + this._isMounted = true; - lighthouse.search(this.props.name, function(results) { - var result = results[0]; - var metadata = result.value; - if (this.resolveSearch) - { - this.setState({ - metadata: metadata, - amount: result.cost, - available: result.available, - title: metadata && metadata.title ? metadata.title : ('lbry://' + this.props.name), - }); + lbry.resolveName(this.props.name, (metadata) => { + if (!this._isMounted) { + return; } - }.bind(this)); + + this.setState({ + metadata: metadata, + title: metadata && metadata.title ? metadata.title : ('lbry://' + this.props.name), + }); + }); }, render: function() { @@ -208,11 +221,10 @@ var FeaturedContentItem = React.createClass({ return null; } - const costProp = this.state.cost === null ? {} : {cost: this.state.cost} return (
+ nsfw={this.state.metadata.nsfw} compact />
); } }); From 06de4534cd2dda7bf46bcbf57a43f0954622e441 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Wed, 7 Dec 2016 18:45:18 -0500 Subject: [PATCH 7/9] Show: rename some variables and props for clarity - cost -> amount - available -> costIncludesData - claimInfo -> metadata (only in DetailPage for now) --- js/page/show.js | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/js/page/show.js b/js/page/show.js index c7458a792..0f45a278e 100644 --- a/js/page/show.js +++ b/js/page/show.js @@ -16,9 +16,9 @@ var formatItemImgStyle = { var FormatItem = React.createClass({ propTypes: { claimInfo: React.PropTypes.object, - amount: React.PropTypes.number, + cost: React.PropTypes.number, name: React.PropTypes.string, - available: React.PropTypes.bool, + costIncludesData: React.PropTypes.bool, }, render: function() { @@ -31,8 +31,8 @@ var FormatItem = React.createClass({ var license = claimInfo.license; var fileContentType = (claimInfo.content_type || claimInfo['content-type']); var mediaType = lbry.getMediaType(fileContentType); - var available = this.props.available; - var amount = this.props.amount || 0.0; + var costIncludesData = this.props.costIncludesData; + var cost = this.props.cost || 0.0; return (
@@ -48,7 +48,7 @@ var FormatItem = React.createClass({ Content-Type{fileContentType} - Cost + Cost Author{author} @@ -78,9 +78,9 @@ var FormatItem = React.createClass({ var FormatsSection = React.createClass({ propTypes: { claimInfo: React.PropTypes.object, - amount: React.PropTypes.number, + cost: React.PropTypes.number, name: React.PropTypes.string, - available: React.PropTypes.bool, + costIncludesData: React.PropTypes.bool, }, render: function() { var name = this.props.name; @@ -102,7 +102,7 @@ var FormatsSection = React.createClass({ {/* In future, anticipate multiple formats, just a guess at what it could look like // var formats = this.props.claimInfo.formats // return ({formats.map(function(format,i){ */} - + {/* })}); */}
); } @@ -114,8 +114,8 @@ var DetailPage = React.createClass({ }, getInitialState: function() { return { - claimInfo: null, - amount: null, + metadata: null, + cost: null, searching: true, matchFound: null, }; @@ -133,9 +133,9 @@ var DetailPage = React.createClass({ }); } else { this.setState({ - amount: result.cost, - available: result.available, - claimInfo: result.value, + cost: result.cost, + costIncludesData: result.costIncludesData, + metadata: result.value, searching: false, matchFound: true, }); @@ -143,21 +143,20 @@ var DetailPage = React.createClass({ }); }, render: function() { - if (this.state.claimInfo == null && this.state.searching) { - // Still waiting for metadata + if (this.state.metadata == null) { return null; } var name = this.props.name; - var available = this.state.available; - var claimInfo = this.state.claimInfo; - var amount = this.state.amount; + var costIncludesData = this.state.costIncludesData; + var metadata = this.state.metadata; + var cost = this.state.cost; return (
{this.state.matchFound ? ( - + ) : (

No content

From 8b781694f26b2b340f5b286791fbb88c93a7941b Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Wed, 7 Dec 2016 19:38:52 -0500 Subject: [PATCH 8/9] Show: use new Lighthouse cost reporting --- js/page/show.js | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/js/page/show.js b/js/page/show.js index 0f45a278e..339a827f1 100644 --- a/js/page/show.js +++ b/js/page/show.js @@ -116,30 +116,25 @@ var DetailPage = React.createClass({ return { metadata: null, cost: null, - searching: true, - matchFound: null, + costIncludesData: null, + nameLookupComplete: null, }; }, componentWillMount: function() { document.title = 'lbry://' + this.props.name; - lighthouse.search(this.props.name, (results) => { - var result = results[0]; + lbry.resolveName(this.props.name, (metadata) => { + this.setState({ + metadata: metadata, + nameLookupComplete: true, + }); + }); - if (result.name != this.props.name) { - this.setState({ - searching: false, - matchFound: false, - }); - } else { - this.setState({ - cost: result.cost, - costIncludesData: result.costIncludesData, - metadata: result.value, - searching: false, - matchFound: true, - }); - } + lbry.getCostInfoForName(this.props.name, ({cost, includesData}) => { + this.setState({ + cost: cost, + costIncludesData: includesData, + }); }); }, render: function() { @@ -155,7 +150,7 @@ var DetailPage = React.createClass({ return (
- {this.state.matchFound ? ( + {this.state.nameLookupComplete ? ( ) : (
From 1cad30d1886c14f4770634f70ff7268be9842bbc Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Wed, 14 Dec 2016 13:27:04 -0500 Subject: [PATCH 9/9] Show: var -> const in DetailPage.render() --- js/page/show.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/page/show.js b/js/page/show.js index 339a827f1..7486b0c93 100644 --- a/js/page/show.js +++ b/js/page/show.js @@ -142,10 +142,10 @@ var DetailPage = React.createClass({ return null; } - var name = this.props.name; - var costIncludesData = this.state.costIncludesData; - var metadata = this.state.metadata; - var cost = this.state.cost; + const name = this.props.name; + const costIncludesData = this.state.costIncludesData; + const metadata = this.state.metadata; + const cost = this.state.cost; return (