gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant-backoffice] branch master updated: extracting currency f


From: gnunet
Subject: [taler-merchant-backoffice] branch master updated: extracting currency from balance
Date: Thu, 10 Feb 2022 17:28:43 +0100

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository merchant-backoffice.

The following commit(s) were added to refs/heads/master by this push:
     new 77c3574  extracting currency from balance
77c3574 is described below

commit 77c3574fe5037c42c2351cedd4206f1b7be21cf7
Author: ms <ms@taler.net>
AuthorDate: Thu Feb 10 17:28:40 2022 +0100

    extracting currency from balance
---
 packages/bank/src/pages/home/index.tsx | 44 ++++++++++++++++++++++++++++------
 1 file changed, 37 insertions(+), 7 deletions(-)

diff --git a/packages/bank/src/pages/home/index.tsx 
b/packages/bank/src/pages/home/index.tsx
index 75620c5..f72cd63 100644
--- a/packages/bank/src/pages/home/index.tsx
+++ b/packages/bank/src/pages/home/index.tsx
@@ -1,6 +1,6 @@
 import useSWR, { SWRConfig, useSWRConfig } from "swr";
-import { h, Fragment, ComponentChildren, VNode } from "preact";
-import { useState, useEffect, StateUpdater } from "preact/hooks";
+import { h, Fragment, ComponentChildren, VNode, createContext } from "preact";
+import { useState, useEffect, StateUpdater, useContext } from "preact/hooks";
 import { Buffer } from "buffer";
 import { useTranslator, Translate } from "../../i18n";
 import { QR } from "../../components/QR";
@@ -24,6 +24,11 @@ import "../../scss/main.scss";
  * - Many strings need to be i18n-wrapped.
  */
 
+/************
+ * Contexts *
+ ***********/
+var CurrencyContext = createContext(null);
+
 /**********************************************
  * Type definitions for states and API calls. *
  *********************************************/
@@ -53,6 +58,11 @@ interface CredentialsRequestType {
   password: string;
 }
 
+interface Amount {
+  value: string;
+  currency: string;
+}
+
 /**
  * Track page state.
  */
@@ -81,10 +91,27 @@ interface AccountStateType {
   /* FIXME: Need history here.  */
 }
 
+/************
+ * Contexts *
+ ***********/
+const currencyContext = createContext<string>()
+
+
 /************
  * Helpers. *
  ***********/
 
+/**
+ * Parse amount.
+ */
+function parseAmount(val: string): Amount {
+  const format = /^[A-Z]+:[0-9]+(\.[0-9]+)?$/;
+  if (!format.test(val))
+    throw Error("Backend gave invalid amount", val)
+  const amountSplit = val.split(":");
+  return {value: amountSplit[1], currency: amountSplit[0]}
+}
+
 /**
  * Get username from the backend state, and throw
  * exception if not found.
@@ -624,6 +651,7 @@ async function registrationCall(
  */
 function TalerWithdrawal(Props: any): VNode {
   const {backendState, pageStateSetter} = Props;
+  const currency = useContext(CurrencyContext);
   const i18n = useTranslator();
   const amountRegex = "^[0-9]+(\.[0-9]+)?$";
   var submitAmount = ""; // without currency.
@@ -638,13 +666,14 @@ function TalerWithdrawal(Props: any): VNode {
       }
       console.log("Valid amount", submitAmount);
       createWithdrawalCall(
-        `EUR:${submitAmount}`, // FIXME: take currency from the balance.
+        `${currency}:${submitAmount}`,
         backendState,
         pageStateSetter
       )}}>{i18n`Charge Taler wallet`}
     </button>;
 
   return <Fragment>
+    <label>{currency}</label> 
     <input
       type="text"
       placeholder="amount"
@@ -653,7 +682,6 @@ function TalerWithdrawal(Props: any): VNode {
       onInput={(e): void => {
         submitAmount = e.currentTarget.value
       }} />
-    <label>FIXME: currency here!</label> 
       { submitButton }
   </Fragment>
 }
@@ -858,14 +886,16 @@ function Account(Props: any): VNode {
       {Props.children}
     </Fragment>);
   }
-
+  const balance = parseAmount(data.balance.amount)
   return (<Fragment>
-    <p>Your balance is {data.balance.amount}.</p>
+    <p>Your balance is {`${balance.value} ${balance.currency}`}.</p>
     <div>
       <span>{i18n`Last transactions:`}</span> { txsPages }
       <button onClick={() => setTxPageNumber(txPageNumber + 1)}>{i18n`Load 
more transactions`}</button>
     </div>
-    {Props.children}
+    <CurrencyContext.Provider value={balance.currency}>
+      {Props.children}
+    </CurrencyContext.Provider>
   </Fragment>);
 }
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]