fix: better loading page while waiting for server response

This commit is contained in:
Sebastian 2022-12-07 09:57:54 -03:00
parent 7061127c07
commit 2c04459a58
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
4 changed files with 46 additions and 47 deletions

View File

@ -23,7 +23,6 @@ declare module "jed" {
* Type definitions for states and API calls. * * Type definitions for states and API calls. *
*********************************************/ *********************************************/
/** /**
* Request body of POST /transactions. * Request body of POST /transactions.
* *

View File

@ -1,7 +1,6 @@
import { hooks } from "@gnu-taler/web-util/lib/index.browser"; import { hooks } from "@gnu-taler/web-util/lib/index.browser";
import { StateUpdater } from "preact/hooks"; import { StateUpdater } from "preact/hooks";
/** /**
* Has the information to reach and * Has the information to reach and
* authenticate at the bank's backend. * authenticate at the bank's backend.

View File

@ -890,7 +890,14 @@ function ShowInputErrorLabel({
return <Fragment />; 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 { pageState, pageStateSetter } = usePageContext(); // NOTE: used for go-back button?
const [submitData, submitDataSetter] = useWireTransferRequestType(); const [submitData, submitDataSetter] = useWireTransferRequestType();
@ -899,7 +906,6 @@ function PaytoWireTransfer(Props: any): VNode {
undefined, undefined,
); );
const { i18n } = useTranslationContext(); const { i18n } = useTranslationContext();
const { focus, backendState, currency } = Props;
const ibanRegex = "^[A-Z][A-Z][0-9]+$"; const ibanRegex = "^[A-Z][A-Z][0-9]+$";
let transactionData: TransactionRequestType; let transactionData: TransactionRequestType;
const ref = useRef<HTMLInputElement>(null); const ref = useRef<HTMLInputElement>(null);
@ -907,13 +913,6 @@ function PaytoWireTransfer(Props: any): VNode {
if (focus) ref.current?.focus(); if (focus) ref.current?.focus();
}, [focus, pageState.isRawPayto]); }, [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; let parsedAmount = undefined;
const errorsWire = { const errorsWire = {
@ -986,8 +985,8 @@ function PaytoWireTransfer(Props: any): VNode {
type="text" type="text"
readonly readonly
class="currency-indicator" class="currency-indicator"
size={currency.length} size={currency?.length}
maxLength={currency.length} maxLength={currency?.length}
tabIndex={-1} tabIndex={-1}
value={currency} value={currency}
/> />
@ -1367,8 +1366,15 @@ function TalerWithdrawalQRCode(Props: any): VNode {
return <TalerWithdrawalConfirmationQuestion backendState={backendState} />; return <TalerWithdrawalConfirmationQuestion backendState={backendState} />;
} }
function WalletWithdraw(Props: any): VNode { function WalletWithdraw({
const { backendState, pageStateSetter, focus, currency } = Props; focus,
currency,
}: {
currency?: string;
focus?: boolean;
}): VNode {
const [backendState, backendStateSetter] = useBackendState();
const { pageState, pageStateSetter } = usePageContext();
const { i18n } = useTranslationContext(); const { i18n } = useTranslationContext();
let submitAmount = "5.00"; let submitAmount = "5.00";
@ -1385,8 +1391,8 @@ function WalletWithdraw(Props: any): VNode {
type="text" type="text"
readonly readonly
class="currency-indicator" class="currency-indicator"
size={currency.length} size={currency?.length ?? 5}
maxLength={currency.length} maxLength={currency?.length}
tabIndex={-1} tabIndex={-1}
value={currency} value={currency}
/> />
@ -1419,7 +1425,7 @@ function WalletWithdraw(Props: any): VNode {
* on the console, and the browser colourizes the amount input * on the console, and the browser colourizes the amount input
* box to indicate a error. * box to indicate a error.
*/ */
if (!submitAmount) return; if (!submitAmount && currency) return;
createWithdrawalCall( createWithdrawalCall(
`${currency}:${submitAmount}`, `${currency}:${submitAmount}`,
backendState, backendState,
@ -1437,8 +1443,7 @@ function WalletWithdraw(Props: any): VNode {
* Let the user choose a payment option, * Let the user choose a payment option,
* then specify the details trigger the action. * then specify the details trigger the action.
*/ */
function PaymentOptions(Props: any): VNode { function PaymentOptions({ currency }: { currency?: string }): VNode {
const { backendState, pageStateSetter, currency } = Props;
const { i18n } = useTranslationContext(); const { i18n } = useTranslationContext();
const [tab, setTab] = useState<"charge-wallet" | "wire-transfer">( const [tab, setTab] = useState<"charge-wallet" | "wire-transfer">(
@ -1469,23 +1474,13 @@ function PaymentOptions(Props: any): VNode {
{tab === "charge-wallet" && ( {tab === "charge-wallet" && (
<div id="charge-wallet" class="tabcontent active"> <div id="charge-wallet" class="tabcontent active">
<h3>{i18n.str`Obtain digital cash`}</h3> <h3>{i18n.str`Obtain digital cash`}</h3>
<WalletWithdraw <WalletWithdraw focus currency={currency} />
backendState={backendState}
focus
currency={currency}
pageStateSetter={pageStateSetter}
/>
</div> </div>
)} )}
{tab === "wire-transfer" && ( {tab === "wire-transfer" && (
<div id="wire-transfer" class="tabcontent active"> <div id="wire-transfer" class="tabcontent active">
<h3>{i18n.str`Transfer to bank account`}</h3> <h3>{i18n.str`Transfer to bank account`}</h3>
<PaytoWireTransfer <PaytoWireTransfer focus currency={currency} />
backendState={backendState}
focus
currency={currency}
pageStateSetter={pageStateSetter}
/>
</div> </div>
)} )}
</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. * This block shows the withdrawal QR code.
@ -1970,36 +1967,41 @@ function Account(Props: any): VNode {
</BankFrame> </BankFrame>
); );
} }
const balance = Amounts.parseOrThrow(data.balance.amount); const balanceValue = !balance ? undefined : Amounts.stringifyValue(balance);
const balanceValue = Amounts.stringifyValue(balance);
return ( return (
<BankFrame> <BankFrame>
<div> <div>
<h1 class="nav welcome-text"> <h1 class="nav welcome-text">
<i18n.Translate> <i18n.Translate>
Welcome, {accountLabel} ({getIbanFromPayto(data.paytoUri)})! Welcome,
{accountNumber
? `${accountLabel} (${accountNumber})`
: accountLabel}
!
</i18n.Translate> </i18n.Translate>
</h1> </h1>
</div> </div>
<section id="assets"> <section id="assets">
<div class="asset-summary"> <div class="asset-summary">
<h2>{i18n.str`Bank account balance`}</h2> <h2>{i18n.str`Bank account balance`}</h2>
<div class="large-amount amount"> {!balance ? (
{data.balance.credit_debit_indicator == "debit" ? <b>-</b> : null} <div class="large-amount" style={{ color: "gray" }}>
<span class="value">{`${balanceValue}`}</span>&nbsp; Waiting server response...
<span class="currency">{`${balance.currency}`}</span> </div>
</div> ) : (
<div class="large-amount amount">
{balanceIsDebit ? <b>-</b> : null}
<span class="value">{`${balanceValue}`}</span>&nbsp;
<span class="currency">{`${balance.currency}`}</span>
</div>
)}
</div> </div>
</section> </section>
<section id="payments"> <section id="payments">
<div class="payments"> <div class="payments">
<h2>{i18n.str`Payments`}</h2> <h2>{i18n.str`Payments`}</h2>
<PaymentOptions <PaymentOptions currency={balance?.currency} />
currency={balance.currency}
backendState={backendState}
pageStateSetter={setPageState}
/>
</div> </div>
</section> </section>
<section id="main"> <section id="main">

View File

@ -1,4 +1,3 @@
/** /**
* Validate (the number part of) an amount. If needed, * Validate (the number part of) an amount. If needed,
* replace comma with a dot. Returns 'false' whenever * replace comma with a dot. Returns 'false' whenever