diff --git a/ui/js/component/common.js b/ui/js/component/common.js index c4e1324f1..78bb6522e 100644 --- a/ui/js/component/common.js +++ b/ui/js/component/common.js @@ -121,7 +121,7 @@ export let FilePrice = React.createClass({ render: function() { if (this.state.cost === null && this.props.metadata) { if (!this.props.metadata.fee) { - return free; + return free*; } else { if (this.props.metadata.fee.currency === "LBC") { return diff --git a/ui/js/lbry.js b/ui/js/lbry.js index e7ca23c23..2b6330656 100644 --- a/ui/js/lbry.js +++ b/ui/js/lbry.js @@ -208,35 +208,48 @@ lbry.getPeersForBlobHash = function(blobHash, callback) { * - includes_data: Boolean; indicates whether or not the data fee info * from Lighthouse is included. */ +lbry.costPromiseCache = {} lbry.getCostInfo = function(lbryUri) { - return new Promise((resolve, reject) => { + if (lbry.costPromiseCache[lbryUri] === undefined) { + const COST_INFO_CACHE_KEY = 'cost_info_cache'; + lbry.costPromiseCache[lbryUri] = new Promise((resolve, reject) => { + let costInfoCache = getSession(COST_INFO_CACHE_KEY, {}) - if (!lbryUri) { - reject(new Error(`URI required.`)); - } - - function getCost(lbryUri, size) { - lbry.stream_cost_estimate({uri: lbryUri, ... size !== null ? {size} : {}}).then((cost) => { - resolve({ - cost: cost, - includesData: size !== null, - }); - }, reject); - } - - const uriObj = uri.parseLbryUri(lbryUri); - const name = uriObj.path || uriObj.name; - - lighthouse.get_size_for_name(name).then((size) => { - if (size) { - getCost(name, size); - } else { - getCost(name, null); + if (!lbryUri) { + reject(new Error(`URI required.`)); } - }, () => { - getCost(name, null); + + if (costInfoCache[lbryUri] && costInfoCache[lbryUri].cost) { + return resolve(costInfoCache[lbryUri]) + } + + function getCost(lbryUri, size) { + lbry.stream_cost_estimate({uri: lbryUri, ... size !== null ? {size} : {}}).then((cost) => { + costInfoCache[lbryUri] = { + cost: cost, + includesData: size !== null, + }; + setSession(COST_INFO_CACHE_KEY, costInfoCache); + resolve(costInfoCache[lbryUri]); + }, reject); + } + + const uriObj = uri.parseLbryUri(lbryUri); + const name = uriObj.path || uriObj.name; + + lighthouse.get_size_for_name(name).then((size) => { + if (size) { + getCost(name, size); + } + else { + getCost(name, null); + } + }, () => { + getCost(name, null); + }); }); - }) + } + return lbry.costPromiseCache[lbryUri]; } lbry.getMyClaims = function(callback) { diff --git a/ui/js/lighthouse.js b/ui/js/lighthouse.js index 41d2d996c..faa5b5b67 100644 --- a/ui/js/lighthouse.js +++ b/ui/js/lighthouse.js @@ -1,8 +1,8 @@ import lbry from './lbry.js'; import jsonrpc from './jsonrpc.js'; -const queryTimeout = 5000; -const maxQueryTries = 5; +const queryTimeout = 3000; +const maxQueryTries = 2; const defaultServers = [ 'http://lighthouse4.lbry.io:50005', 'http://lighthouse5.lbry.io:50005', @@ -20,8 +20,9 @@ function getServers() { } function call(method, params, callback, errorCallback) { - if (connectTryNum > maxQueryTries) { + if (connectTryNum >= maxQueryTries) { errorCallback(new Error(`Could not connect to Lighthouse server. Last server attempted: ${server}`)); + return; } /** diff --git a/ui/js/page/file-list.js b/ui/js/page/file-list.js index 4a3f56f50..fdb6c7649 100644 --- a/ui/js/page/file-list.js +++ b/ui/js/page/file-list.js @@ -162,12 +162,12 @@ export let FileList = React.createClass({ const fileInfosSorted = this._sortFunctions[this.state.sortBy](this.props.fileInfos); for (let {outpoint, name, channel_name, metadata: {stream: {metadata}}, mime_type, claim_id, has_signature, signature_is_valid} of fileInfosSorted) { - if (!metadata || seenUris[name] || channel_name === null) { + if (!metadata || seenUris[name]) { continue; } let fileUri; - if (channel_name === undefined) { + if (!channel_name) { fileUri = uri.buildLbryUri({name}); } else { fileUri = uri.buildLbryUri({name: channel_name, path: name}); diff --git a/ui/js/page/show.js b/ui/js/page/show.js index eb9f02e46..f3b361976 100644 --- a/ui/js/page/show.js +++ b/ui/js/page/show.js @@ -91,6 +91,7 @@ let ShowPage = React.createClass({ metadata = this.state.uriLookupComplete ? this.state.metadata : null, title = this.state.uriLookupComplete ? metadata.title : this._uri; + console.log(metadata); return ( @@ -101,7 +102,7 @@ let ShowPage = React.createClass({ - + {title} { this.state.uriLookupComplete ? @@ -109,7 +110,7 @@ let ShowPage = React.createClass({ - + : '' }