merchant-backoffice

ZZZ: Inactive/Deprecated
Log | Files | Refs | Submodules | README

commit c6e9fdb7dac4f173271b831bd72c7a15301ff78c
parent d972287890401efa538cd0bb1b8e27505782d7d5
Author: ms <ms@taler.net>
Date:   Sat,  9 Apr 2022 08:16:07 +0200

move logic from children to component definition

Diffstat:
Mpackages/bank/src/pages/home/index.tsx | 73++++++++++++++++++++-----------------------------------------------------
1 file changed, 20 insertions(+), 53 deletions(-)

diff --git a/packages/bank/src/pages/home/index.tsx b/packages/bank/src/pages/home/index.tsx @@ -833,7 +833,7 @@ function PaytoWireTransfer(Props: any): VNode { size={90} required placeholder={i18n`payto address`} - pattern="payto://x-taler-bank/[a-z\.]+(:[0-9]+)?/[0-9a-zA-Z]+\?message=[a-zA-Z0-9 ]+&amount={currency}:[0-9]+(\.[0-9]+)?" + pattern={`payto://iban/[A-Z][A-Z][0-9]+\?message=[a-zA-Z0-9 ]+&amount=${currency}:[0-9]+(\.[0-9]+)?`} onInput={(e): void => { transactionData = { ...transactionData, @@ -1206,6 +1206,9 @@ function Transactions(Props: any): VNode { function Account(Props: any): VNode { const { cache } = useSWRConfig(); const { accountLabel, backendState } = Props; + // Getting the bank account balance: + const endpoint = `access-api/accounts/${accountLabel}`; + const { data, error } = useSWR(endpoint, {refreshIfStale: true}); const [pageState, pageStateSetter] = useContext(PageContext); const { withdrawalInProgress, @@ -1246,11 +1249,6 @@ function Account(Props: any): VNode { for (let i = 0; i <= txPageNumber; i++) { txsPages.push(<Transactions accountLabel={accountLabel} pageNumber={i} />) } - /** - * Getting the bank account balance. - */ - const endpoint = `access-api/accounts/${accountLabel}`; - const { data, error, mutate } = useSWR(endpoint); if (typeof error !== "undefined") { console.log("account error", error); /** @@ -1310,7 +1308,12 @@ function Account(Props: any): VNode { if (transferOutcome) { return <BankFrame> <p>{transferOutcome}</p> - {Props.children} + <button onClick={() => { + pageStateSetter((prevState) => { + const { transferOutcome, ...rest } = prevState; + return {...rest};})}}> + {i18n`Close wire transfer`} + </button> </BankFrame> } @@ -1320,7 +1323,15 @@ function Account(Props: any): VNode { if (withdrawalOutcome) { return <BankFrame> <p>{withdrawalOutcome}</p> - {Props.children} + <button onClick={() => { + pageStateSetter((prevState) => { + const { withdrawalOutcome, withdrawalId, ...rest } = prevState; + return { + ...rest, + withdrawalInProgress: false + };})}}> + {i18n`Close Taler withdrawal`} + </button> </BankFrame> } @@ -1562,51 +1573,7 @@ export function BankHome(): VNode { password={backendState.password} backendUrl={backendState.url}> <PageContext.Provider value={[pageState, pageStateSetter]}> - <Account accountLabel={backendState.username} backendState={backendState}> - { /** - * Wire transfer reached a persisten state: offer to - * return back to the pristine profile page. FIXME: - * move this into the Account component. - */ - pageState.transferOutcome && <button onClick={() => { - pageStateSetter((prevState) => { - const { transferOutcome, ...rest } = prevState; - return {...rest};})}}>{i18n`Close wire transfer`}</button> - } - - { /** - * Withdrawal reached a persisten state: offer to - * return back to the pristine profile page. FIXME: - * move this into the Account component. - */ - pageState.withdrawalOutcome && <button onClick={() => { - pageStateSetter((prevState) => { - const { withdrawalOutcome, withdrawalId, ...rest } = prevState; - return { - ...rest, - withdrawalInProgress: false - };} - )}}>{i18n`Close Taler withdrawal`}</button> - } - - { /** - * The withdrawal QR code is rendered: offer to confirm - * or abort the operation. FIXME: move this into the Account - * component. - */ - pageState.talerWithdrawUri && <div><button onClick={() => { - confirmWithdrawalCall( - backendState, - pageState.withdrawalId, - pageStateSetter);}}>{i18n`Confirm withdrawal`}</button> - <button onClick={() => { - abortWithdrawalCall( - backendState, - pageState.withdrawalId, - pageStateSetter);}}>{i18n`Abort withdrawal`}</button> - </div> - } - </Account> + <Account accountLabel={backendState.username} backendState={backendState} /> </PageContext.Provider> </SWRWithCredentials> );