From c03c0de0a2b7c3b12b6041f7a851997f0e4229c2 Mon Sep 17 00:00:00 2001 From: Baltazar Gomez Date: Tue, 22 Aug 2017 18:59:36 -0600 Subject: [PATCH] Fix for #461 show full price on confirmation don't format full price smart format for full price --- ui/js/actions/content.js | 2 +- ui/js/component/common.js | 26 ++++++++++++++----- ui/js/component/fileActions/view.jsx | 5 ++-- ui/js/component/filePrice/view.jsx | 3 ++- .../component/video/internal/play-button.jsx | 2 +- ui/js/utils.js | 21 +++++++++++++++ 6 files changed, 47 insertions(+), 12 deletions(-) diff --git a/ui/js/actions/content.js b/ui/js/actions/content.js index 919eccac5..95ebf28f1 100644 --- a/ui/js/actions/content.js +++ b/ui/js/actions/content.js @@ -340,7 +340,7 @@ export function doPurchaseUri(uri, purchaseModalName) { const { cost } = costInfo; // the file is free or we have partially downloaded it - if (cost <= 0.01 || (fileInfo && fileInfo.download_directory)) { + if (cost === 0 || (fileInfo && fileInfo.download_directory)) { dispatch(doLoadVideo(uri)); return Promise.resolve(); } diff --git a/ui/js/component/common.js b/ui/js/component/common.js index 91919b32f..a39abc802 100644 --- a/ui/js/component/common.js +++ b/ui/js/component/common.js @@ -1,5 +1,5 @@ import React from "react"; -import { formatCredits } from "utils"; +import { formatCredits, formatFullPrice } from "utils"; import lbry from "../lbry.js"; //component/icon.js @@ -68,23 +68,32 @@ export class CreditAmount extends React.PureComponent { isEstimate: React.PropTypes.bool, label: React.PropTypes.bool, showFree: React.PropTypes.bool, + showFullPrice: React.PropTypes.bool, look: React.PropTypes.oneOf(["indicator", "plain"]), }; static defaultProps = { precision: 2, label: true, - showFree: false, look: "indicator", + showFree: false, + showFullPrice: false, }; render() { const minimumRenderableAmount = Math.pow(10, -1 * this.props.precision); - const { amount, precision } = this.props; + const { amount, precision, showFullPrice } = this.props; - let formattedAmount = amount > 0 && amount < minimumRenderableAmount - ? "<" + minimumRenderableAmount - : formatCredits(amount, precision); + let formattedAmount; + let fullPrice = formatFullPrice(amount, 2); + + if (showFullPrice) { + formattedAmount = fullPrice; + } else { + formattedAmount = amount > 0 && amount < minimumRenderableAmount + ? "<" + minimumRenderableAmount + : formatCredits(amount, precision); + } let amountText; if (this.props.showFree && parseFloat(this.props.amount) === 0) { @@ -99,7 +108,10 @@ export class CreditAmount extends React.PureComponent { } return ( - + {amountText} diff --git a/ui/js/component/fileActions/view.jsx b/ui/js/component/fileActions/view.jsx index 7b3463d3d..1a2ed7931 100644 --- a/ui/js/component/fileActions/view.jsx +++ b/ui/js/component/fileActions/view.jsx @@ -189,7 +189,7 @@ class FileActions extends React.PureComponent { > {__("This will purchase")} {title} {__("for")}{" "} - + {" "} {__("credits")}. @@ -198,7 +198,8 @@ class FileActions extends React.PureComponent { contentLabel={__("Download failed")} onConfirmed={closeModal} > - {__("LBRY was unable to download the stream")} {uri}. + {__("LBRY was unable to download the stream")}{" "}{" "} + {title}. {modal == modals.CONFIRM_FILE_REMOVE && ); } diff --git a/ui/js/component/video/internal/play-button.jsx b/ui/js/component/video/internal/play-button.jsx index bb49d05b4..2ae39fe7c 100644 --- a/ui/js/component/video/internal/play-button.jsx +++ b/ui/js/component/video/internal/play-button.jsx @@ -83,7 +83,7 @@ class VideoPlayButton extends React.PureComponent { > {__("This will purchase")} {title} {__("for")}{" "} - + {" "} {__("credits")}. diff --git a/ui/js/utils.js b/ui/js/utils.js index b41a2e0d4..67d3ed804 100644 --- a/ui/js/utils.js +++ b/ui/js/utils.js @@ -33,3 +33,24 @@ export function setSession(key, value) { export function formatCredits(amount, precision) { return amount.toFixed(precision || 1).replace(/\.?0+$/, ""); } + +export function formatFullPrice(amount, precision) { + let formated = ""; + + const quantity = amount.toString().split("."); + const fraction = quantity[1]; + + if (fraction) { + // Set precision + precision = precision || 1; + + const decimals = fraction.split(""); + const first = decimals.filter(number => number != "0")[0]; + const index = decimals.indexOf(first); + + // Set format fraction + formated = "." + fraction.substring(0, index + precision); + } + + return parseFloat(quantity[0] + formated); +}