aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-12-07 09:57:54 -0300
committerSebastian <sebasjm@gmail.com>2022-12-07 16:08:15 -0300
commit2c04459a58c04fe7a6c6dc657c1d3fb58132a933 (patch)
tree6e7ac4f8e116b621c8ad359a170e57ced5294a5b
parent7061127c073ba3710c55d13294a75f8bc9b91229 (diff)
fix: better loading page while waiting for server response
-rw-r--r--packages/demobank-ui/src/declaration.d.ts1
-rw-r--r--packages/demobank-ui/src/hooks/backend.ts1
-rw-r--r--packages/demobank-ui/src/pages/home/index.tsx90
-rw-r--r--packages/demobank-ui/src/utils.ts1
4 files changed, 46 insertions, 47 deletions
diff --git a/packages/demobank-ui/src/declaration.d.ts b/packages/demobank-ui/src/declaration.d.ts
index 70272cc54..1b56f1358 100644
--- a/packages/demobank-ui/src/declaration.d.ts
+++ b/packages/demobank-ui/src/declaration.d.ts
@@ -23,7 +23,6 @@ declare module "jed" {
* Type definitions for states and API calls. *
*********************************************/
-
/**
* Request body of POST /transactions.
*
diff --git a/packages/demobank-ui/src/hooks/backend.ts b/packages/demobank-ui/src/hooks/backend.ts
index fa4211f13..3b00edee3 100644
--- a/packages/demobank-ui/src/hooks/backend.ts
+++ b/packages/demobank-ui/src/hooks/backend.ts
@@ -1,7 +1,6 @@
import { hooks } from "@gnu-taler/web-util/lib/index.browser";
import { StateUpdater } from "preact/hooks";
-
/**
* Has the information to reach and
* authenticate at the bank's backend.
diff --git a/packages/demobank-ui/src/pages/home/index.tsx b/packages/demobank-ui/src/pages/home/index.tsx
index 7631ebf46..884113e85 100644
--- a/packages/demobank-ui/src/pages/home/index.tsx
+++ b/packages/demobank-ui/src/pages/home/index.tsx
@@ -890,7 +890,14 @@ function ShowInputErrorLabel({
return <Fragment />;
}
-function PaytoWireTransfer(Props: any): VNode {
+function PaytoWireTransfer({
+ focus,
+ currency,
+}: {
+ focus?: boolean;
+ currency?: string;
+}): VNode {
+ const [backendState, backendStateSetter] = useBackendState();
const { pageState, pageStateSetter } = usePageContext(); // NOTE: used for go-back button?
const [submitData, submitDataSetter] = useWireTransferRequestType();
@@ -899,7 +906,6 @@ function PaytoWireTransfer(Props: any): VNode {
undefined,
);
const { i18n } = useTranslationContext();
- const { focus, backendState, currency } = Props;
const ibanRegex = "^[A-Z][A-Z][0-9]+$";
let transactionData: TransactionRequestType;
const ref = useRef<HTMLInputElement>(null);
@@ -907,13 +913,6 @@ function PaytoWireTransfer(Props: any): VNode {
if (focus) ref.current?.focus();
}, [focus, pageState.isRawPayto]);
- // typeof submitData === "undefined" ||
- // typeof submitData.iban === "undefined" ||
- // submitData.iban === "" ||
- // typeof submitData.subject === "undefined" ||
- // submitData.subject === "" ||
- // typeof submitData.amount === "undefined" ||
- // submitData.amount === ""
let parsedAmount = undefined;
const errorsWire = {
@@ -986,8 +985,8 @@ function PaytoWireTransfer(Props: any): VNode {
type="text"
readonly
class="currency-indicator"
- size={currency.length}
- maxLength={currency.length}
+ size={currency?.length}
+ maxLength={currency?.length}
tabIndex={-1}
value={currency}
/>
@@ -1367,8 +1366,15 @@ function TalerWithdrawalQRCode(Props: any): VNode {
return <TalerWithdrawalConfirmationQuestion backendState={backendState} />;
}
-function WalletWithdraw(Props: any): VNode {
- const { backendState, pageStateSetter, focus, currency } = Props;
+function WalletWithdraw({
+ focus,
+ currency,
+}: {
+ currency?: string;
+ focus?: boolean;
+}): VNode {
+ const [backendState, backendStateSetter] = useBackendState();
+ const { pageState, pageStateSetter } = usePageContext();
const { i18n } = useTranslationContext();
let submitAmount = "5.00";
@@ -1385,8 +1391,8 @@ function WalletWithdraw(Props: any): VNode {
type="text"
readonly
class="currency-indicator"
- size={currency.length}
- maxLength={currency.length}
+ size={currency?.length ?? 5}
+ maxLength={currency?.length}
tabIndex={-1}
value={currency}
/>
@@ -1419,7 +1425,7 @@ function WalletWithdraw(Props: any): VNode {
* on the console, and the browser colourizes the amount input
* box to indicate a error.
*/
- if (!submitAmount) return;
+ if (!submitAmount && currency) return;
createWithdrawalCall(
`${currency}:${submitAmount}`,
backendState,
@@ -1437,8 +1443,7 @@ function WalletWithdraw(Props: any): VNode {
* Let the user choose a payment option,
* then specify the details trigger the action.
*/
-function PaymentOptions(Props: any): VNode {
- const { backendState, pageStateSetter, currency } = Props;
+function PaymentOptions({ currency }: { currency?: string }): VNode {
const { i18n } = useTranslationContext();
const [tab, setTab] = useState<"charge-wallet" | "wire-transfer">(
@@ -1469,23 +1474,13 @@ function PaymentOptions(Props: any): VNode {
{tab === "charge-wallet" && (
<div id="charge-wallet" class="tabcontent active">
<h3>{i18n.str`Obtain digital cash`}</h3>
- <WalletWithdraw
- backendState={backendState}
- focus
- currency={currency}
- pageStateSetter={pageStateSetter}
- />
+ <WalletWithdraw focus currency={currency} />
</div>
)}
{tab === "wire-transfer" && (
<div id="wire-transfer" class="tabcontent active">
<h3>{i18n.str`Transfer to bank account`}</h3>
- <PaytoWireTransfer
- backendState={backendState}
- focus
- currency={currency}
- pageStateSetter={pageStateSetter}
- />
+ <PaytoWireTransfer focus currency={currency} />
</div>
)}
</div>
@@ -1942,7 +1937,9 @@ function Account(Props: any): VNode {
}
}
}
- if (!data) return <p>Retrieving the profile page...</p>;
+ const balance = !data ? undefined : Amounts.parseOrThrow(data.balance.amount);
+ const accountNumber = !data ? undefined : getIbanFromPayto(data.paytoUri);
+ const balanceIsDebit = data && data.balance.credit_debit_indicator == "debit";
/**
* This block shows the withdrawal QR code.
@@ -1970,36 +1967,41 @@ function Account(Props: any): VNode {
</BankFrame>
);
}
- const balance = Amounts.parseOrThrow(data.balance.amount);
- const balanceValue = Amounts.stringifyValue(balance);
+ const balanceValue = !balance ? undefined : Amounts.stringifyValue(balance);
return (
<BankFrame>
<div>
<h1 class="nav welcome-text">
<i18n.Translate>
- Welcome, {accountLabel} ({getIbanFromPayto(data.paytoUri)})!
+ Welcome,
+ {accountNumber
+ ? `${accountLabel} (${accountNumber})`
+ : accountLabel}
+ !
</i18n.Translate>
</h1>
</div>
<section id="assets">
<div class="asset-summary">
<h2>{i18n.str`Bank account balance`}</h2>
- <div class="large-amount amount">
- {data.balance.credit_debit_indicator == "debit" ? <b>-</b> : null}
- <span class="value">{`${balanceValue}`}</span>&nbsp;
- <span class="currency">{`${balance.currency}`}</span>
- </div>
+ {!balance ? (
+ <div class="large-amount" style={{ color: "gray" }}>
+ Waiting server response...
+ </div>
+ ) : (
+ <div class="large-amount amount">
+ {balanceIsDebit ? <b>-</b> : null}
+ <span class="value">{`${balanceValue}`}</span>&nbsp;
+ <span class="currency">{`${balance.currency}`}</span>
+ </div>
+ )}
</div>
</section>
<section id="payments">
<div class="payments">
<h2>{i18n.str`Payments`}</h2>
- <PaymentOptions
- currency={balance.currency}
- backendState={backendState}
- pageStateSetter={setPageState}
- />
+ <PaymentOptions currency={balance?.currency} />
</div>
</section>
<section id="main">
diff --git a/packages/demobank-ui/src/utils.ts b/packages/demobank-ui/src/utils.ts
index d812f2ec9..8b9e9a89c 100644
--- a/packages/demobank-ui/src/utils.ts
+++ b/packages/demobank-ui/src/utils.ts
@@ -1,4 +1,3 @@
-
/**
* Validate (the number part of) an amount. If needed,
* replace comma with a dot. Returns 'false' whenever