diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-24 16:45:57 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-24 16:45:57 +0200 |
commit | 8f35362dad9914cac16f421745a27a1cdd0f02bc (patch) | |
tree | b91b4be2c96d7cc9e141a7cd6af70f93ab617b70 /src/renderHtml.tsx | |
parent | 39cca9f8f6050d6e35c88f8cd3c6e825eae9cb9f (diff) |
style, deduplication and doc comments
Diffstat (limited to 'src/renderHtml.tsx')
-rw-r--r-- | src/renderHtml.tsx | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/renderHtml.tsx b/src/renderHtml.tsx index 1e6c5a8e1..9d14d6cb7 100644 --- a/src/renderHtml.tsx +++ b/src/renderHtml.tsx @@ -21,14 +21,18 @@ */ -import {AmountJson, Contract, Amounts} from "./types"; +/** + * Imports. + */ +import { + AmountJson, + Amounts, + Contract, +} from "./types"; import * as i18n from "./i18n"; +import { amountToPretty } from "./helpers"; import * as React from "react"; -export function prettyAmount(amount: AmountJson) { - let v = amount.value + amount.fraction / Amounts.fractionalBase; - return `${v} ${amount.currency}`; -} export function renderContract(contract: Contract): JSX.Element { let merchantName; @@ -37,7 +41,7 @@ export function renderContract(contract: Contract): JSX.Element { } else { merchantName = <strong>(pub: {contract.merchant_pub})</strong>; } - let amount = <strong>{prettyAmount(contract.amount)}</strong>; + let amount = <strong>{amountToPretty(contract.amount)}</strong>; return ( <div> @@ -49,7 +53,7 @@ export function renderContract(contract: Contract): JSX.Element { <p>{i18n.str`You are about to purchase:`}</p> <ul> {contract.products.map( - (p: any, i: number) => (<li key={i}>{`${p.description}: ${prettyAmount(p.price)}`}</li>)) + (p: any, i: number) => (<li key={i}>{`${p.description}: ${amountToPretty(p.price)}`}</li>)) } </ul> </div> @@ -57,6 +61,10 @@ export function renderContract(contract: Contract): JSX.Element { } +/** + * Abbreviate a string to a given length, and show the full + * string on hover as a tooltip. + */ export function abbrev(s: string, n: number = 5) { let sAbbrev = s; if (s.length > n) { |