Fix for #461
show full price on confirmation don't format full price smart format for full price
This commit is contained in:
parent
a31e064c3e
commit
c03c0de0a2
6 changed files with 47 additions and 12 deletions
|
@ -340,7 +340,7 @@ export function doPurchaseUri(uri, purchaseModalName) {
|
||||||
const { cost } = costInfo;
|
const { cost } = costInfo;
|
||||||
|
|
||||||
// the file is free or we have partially downloaded it
|
// 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));
|
dispatch(doLoadVideo(uri));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { formatCredits } from "utils";
|
import { formatCredits, formatFullPrice } from "utils";
|
||||||
import lbry from "../lbry.js";
|
import lbry from "../lbry.js";
|
||||||
|
|
||||||
//component/icon.js
|
//component/icon.js
|
||||||
|
@ -68,23 +68,32 @@ export class CreditAmount extends React.PureComponent {
|
||||||
isEstimate: React.PropTypes.bool,
|
isEstimate: React.PropTypes.bool,
|
||||||
label: React.PropTypes.bool,
|
label: React.PropTypes.bool,
|
||||||
showFree: React.PropTypes.bool,
|
showFree: React.PropTypes.bool,
|
||||||
|
showFullPrice: React.PropTypes.bool,
|
||||||
look: React.PropTypes.oneOf(["indicator", "plain"]),
|
look: React.PropTypes.oneOf(["indicator", "plain"]),
|
||||||
};
|
};
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
precision: 2,
|
precision: 2,
|
||||||
label: true,
|
label: true,
|
||||||
showFree: false,
|
|
||||||
look: "indicator",
|
look: "indicator",
|
||||||
|
showFree: false,
|
||||||
|
showFullPrice: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const minimumRenderableAmount = Math.pow(10, -1 * this.props.precision);
|
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
|
let formattedAmount;
|
||||||
|
let fullPrice = formatFullPrice(amount, 2);
|
||||||
|
|
||||||
|
if (showFullPrice) {
|
||||||
|
formattedAmount = fullPrice;
|
||||||
|
} else {
|
||||||
|
formattedAmount = amount > 0 && amount < minimumRenderableAmount
|
||||||
? "<" + minimumRenderableAmount
|
? "<" + minimumRenderableAmount
|
||||||
: formatCredits(amount, precision);
|
: formatCredits(amount, precision);
|
||||||
|
}
|
||||||
|
|
||||||
let amountText;
|
let amountText;
|
||||||
if (this.props.showFree && parseFloat(this.props.amount) === 0) {
|
if (this.props.showFree && parseFloat(this.props.amount) === 0) {
|
||||||
|
@ -99,7 +108,10 @@ export class CreditAmount extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={`credit-amount credit-amount--${this.props.look}`}>
|
<span
|
||||||
|
className={`credit-amount credit-amount--${this.props.look}`}
|
||||||
|
title={fullPrice}
|
||||||
|
>
|
||||||
<span>
|
<span>
|
||||||
{amountText}
|
{amountText}
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -189,7 +189,7 @@ class FileActions extends React.PureComponent {
|
||||||
>
|
>
|
||||||
{__("This will purchase")} <strong>{title}</strong> {__("for")}{" "}
|
{__("This will purchase")} <strong>{title}</strong> {__("for")}{" "}
|
||||||
<strong>
|
<strong>
|
||||||
<FilePrice uri={uri} look="plain" />
|
<FilePrice uri={uri} showFullPrice={true} look="plain" />
|
||||||
</strong>{" "}
|
</strong>{" "}
|
||||||
{__("credits")}.
|
{__("credits")}.
|
||||||
</Modal>
|
</Modal>
|
||||||
|
@ -198,7 +198,8 @@ class FileActions extends React.PureComponent {
|
||||||
contentLabel={__("Download failed")}
|
contentLabel={__("Download failed")}
|
||||||
onConfirmed={closeModal}
|
onConfirmed={closeModal}
|
||||||
>
|
>
|
||||||
{__("LBRY was unable to download the stream")} <strong>{uri}</strong>.
|
{__("LBRY was unable to download the stream")}{" "}{" "}
|
||||||
|
<strong>{title}</strong>.
|
||||||
</Modal>
|
</Modal>
|
||||||
{modal == modals.CONFIRM_FILE_REMOVE &&
|
{modal == modals.CONFIRM_FILE_REMOVE &&
|
||||||
<ModalRemoveFile
|
<ModalRemoveFile
|
||||||
|
|
|
@ -19,7 +19,7 @@ class FilePrice extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { costInfo, look = "indicator" } = this.props;
|
const { costInfo, look = "indicator", showFullPrice = false } = this.props;
|
||||||
|
|
||||||
const isEstimate = costInfo ? !costInfo.includesData : null;
|
const isEstimate = costInfo ? !costInfo.includesData : null;
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ class FilePrice extends React.PureComponent {
|
||||||
amount={costInfo.cost}
|
amount={costInfo.cost}
|
||||||
isEstimate={isEstimate}
|
isEstimate={isEstimate}
|
||||||
showFree={true}
|
showFree={true}
|
||||||
|
showFullPrice={showFullPrice}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ class VideoPlayButton extends React.PureComponent {
|
||||||
>
|
>
|
||||||
{__("This will purchase")} <strong>{title}</strong> {__("for")}{" "}
|
{__("This will purchase")} <strong>{title}</strong> {__("for")}{" "}
|
||||||
<strong>
|
<strong>
|
||||||
<FilePrice uri={uri} look="plain" />
|
<FilePrice uri={uri} showFullPrice={true} look="plain" />
|
||||||
</strong>{" "}
|
</strong>{" "}
|
||||||
{__("credits")}.
|
{__("credits")}.
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
|
@ -33,3 +33,24 @@ export function setSession(key, value) {
|
||||||
export function formatCredits(amount, precision) {
|
export function formatCredits(amount, precision) {
|
||||||
return amount.toFixed(precision || 1).replace(/\.?0+$/, "");
|
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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue