summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/cta
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-03-23 10:50:12 -0300
committerSebastian <sebasjm@gmail.com>2022-03-23 10:58:57 -0300
commit32f6409ac312f31821f791c3a376168289f0e4f4 (patch)
treec77c660bb85cf359faf74b5cddbe95eb0a915c5e /packages/taler-wallet-webextension/src/cta
parentc539d1803c1376cba0831be64866b6d2c1652403 (diff)
downloadwallet-core-32f6409ac312f31821f791c3a376168289f0e4f4.tar.gz
wallet-core-32f6409ac312f31821f791c3a376168289f0e4f4.tar.bz2
wallet-core-32f6409ac312f31821f791c3a376168289f0e4f4.zip
all the browser related code move into one place, making it easy for specific platform code or mocking for testing
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta')
-rw-r--r--packages/taler-wallet-webextension/src/cta/Refund.tsx32
-rw-r--r--packages/taler-wallet-webextension/src/cta/Tip.tsx31
2 files changed, 58 insertions, 5 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Refund.tsx b/packages/taler-wallet-webextension/src/cta/Refund.tsx
index efc436bc8..790e8d9fa 100644
--- a/packages/taler-wallet-webextension/src/cta/Refund.tsx
+++ b/packages/taler-wallet-webextension/src/cta/Refund.tsx
@@ -20,11 +20,15 @@
* @author sebasjm
*/
-import { Amounts, ApplyRefundResponse } from "@gnu-taler/taler-util";
+import {
+ amountFractionalBase,
+ AmountJson,
+ Amounts,
+ ApplyRefundResponse,
+} from "@gnu-taler/taler-util";
import { h, VNode } from "preact";
import { useEffect, useState } from "preact/hooks";
import { useTranslationContext } from "../context/translation";
-import { AmountView } from "../renderHtml";
import * as wxApi from "../wxApi";
interface Props {
@@ -120,3 +124,27 @@ export function RefundPage({ talerRefundUri }: Props): VNode {
return <View applyResult={applyResult} />;
}
+
+export function renderAmount(amount: AmountJson | string): VNode {
+ 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 / amountFractionalBase;
+ return (
+ <span>
+ {x}&nbsp;{a.currency}
+ </span>
+ );
+}
+
+export const AmountView = ({
+ amount,
+}: {
+ amount: AmountJson | string;
+}): VNode => renderAmount(amount);
diff --git a/packages/taler-wallet-webextension/src/cta/Tip.tsx b/packages/taler-wallet-webextension/src/cta/Tip.tsx
index 71aa04a2b..5767b5008 100644
--- a/packages/taler-wallet-webextension/src/cta/Tip.tsx
+++ b/packages/taler-wallet-webextension/src/cta/Tip.tsx
@@ -17,15 +17,19 @@
/**
* Page shown to the user to accept or ignore a tip from a merchant.
*
- * @author sebasjm <dold@taler.net>
+ * @author sebasjm
*/
-import { PrepareTipResult } from "@gnu-taler/taler-util";
+import {
+ amountFractionalBase,
+ AmountJson,
+ Amounts,
+ PrepareTipResult,
+} from "@gnu-taler/taler-util";
import { h, VNode } from "preact";
import { useEffect, useState } from "preact/hooks";
import { Loading } from "../components/Loading";
import { useTranslationContext } from "../context/translation";
-import { AmountView } from "../renderHtml";
import * as wxApi from "../wxApi";
interface Props {
@@ -136,3 +140,24 @@ export function TipPage({ talerTipUri }: Props): VNode {
/>
);
}
+
+function renderAmount(amount: AmountJson | string): VNode {
+ 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 / amountFractionalBase;
+ return (
+ <span>
+ {x}&nbsp;{a.currency}
+ </span>
+ );
+}
+
+const AmountView = ({ amount }: { amount: AmountJson | string }): VNode =>
+ renderAmount(amount);