render both string and JSON amounts correctly to HTML
This commit is contained in:
parent
774a79d9de
commit
65228afb87
@ -48,12 +48,21 @@ import * as React from "react";
|
|||||||
* Render amount as HTML, which non-breaking space between
|
* Render amount as HTML, which non-breaking space between
|
||||||
* decimal value and currency.
|
* decimal value and currency.
|
||||||
*/
|
*/
|
||||||
export function renderAmount(amount: AmountJson) {
|
export function renderAmount(amount: AmountJson | string) {
|
||||||
const x = amount.value + amount.fraction / Amounts.fractionalBase;
|
let a;
|
||||||
return <span>{x} {amount.currency}</span>;
|
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} {a.currency}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AmountDisplay = ({amount}: {amount: AmountJson}) => renderAmount(amount);
|
export const AmountDisplay = ({amount}: {amount: AmountJson | string}) => renderAmount(amount);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user