aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-02-20 09:33:17 +0100
committerFlorian Dold <florian.dold@gmail.com>2018-02-20 09:33:17 +0100
commit65228afb876d4fcec36ceabd3e6bfc1ea6f15cee (patch)
tree9ac5de3018d42a791cf467db77f7325c8ba2d43e /src
parent774a79d9de7651b45d66e8667afe1493de7d678a (diff)
render both string and JSON amounts correctly to HTML
Diffstat (limited to 'src')
-rw-r--r--src/webex/renderHtml.tsx17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/webex/renderHtml.tsx b/src/webex/renderHtml.tsx
index 2e21932b0..e4686adee 100644
--- a/src/webex/renderHtml.tsx
+++ b/src/webex/renderHtml.tsx
@@ -48,12 +48,21 @@ import * as React from "react";
* Render amount as HTML, which non-breaking space between
* decimal value and currency.
*/
-export function renderAmount(amount: AmountJson) {
- const x = amount.value + amount.fraction / Amounts.fractionalBase;
- return <span>{x}&nbsp;{amount.currency}</span>;
+export function renderAmount(amount: AmountJson | string) {
+ let a;
+ if (typeof amount === "string") {
+ a = Amounts.parse(amount);
+ } else {
+ a = amount;
+ }
+ if (!a) {
+ return <span>(invalid amount)</span>;
+ }
+ const x = a.value + a.fraction / Amounts.fractionalBase;
+ return <span>{x}&nbsp;{a.currency}</span>;
}
-export const AmountDisplay = ({amount}: {amount: AmountJson}) => renderAmount(amount);
+export const AmountDisplay = ({amount}: {amount: AmountJson | string}) => renderAmount(amount);
/**