merchant-backoffice

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

commit 04623aa3b6ab7c86f06191c7a8754fd2e988f096
parent 54457bc6bdfe9ee61c3678012729f7199abf2a81
Author: ms <ms@taler.net>
Date:   Fri,  8 Apr 2022 13:17:32 +0200

Copying pybank's appearance.  WIP

Cache invalidation when login hits 404.

Diffstat:
Mpackages/bank/src/pages/home/index.tsx | 29+++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/packages/bank/src/pages/home/index.tsx b/packages/bank/src/pages/home/index.tsx @@ -648,7 +648,6 @@ async function registrationCall( error: errorRaw })); } else { - console.log("Credentials are valid"); pageStateSetter((prevState) => ({ ...prevState, isLoggedIn: true, @@ -859,7 +858,7 @@ function PaytoWireTransfer(Props: any): VNode { * Additional authentication required to complete the operation. * Not providing a back button, only abort. */ -function TalerWithdrawalConfirmationQuestion(Props): VNode { +function TalerWithdrawalConfirmationQuestion(Props: any): VNode { const [pageState, pageStateSetter] = useContext(PageContext); const { backendState } = Props; const i18n = useTranslator(); @@ -1060,6 +1059,7 @@ function LoginForm(Props: any): VNode { type="submit" class="pure-button pure-button-primary" onClick={() => { + if (typeof submitData === "undefined") return; if (submitData.password.length > 0 && submitData.username.length > 0) loginCall( submitData, @@ -1076,7 +1076,7 @@ function LoginForm(Props: any): VNode { */ function RegistrationForm(Props: any): VNode { const [pageState, pageStateSetter] = useContext(PageContext); - var submitData: CredentialsRequestType = {}; + var submitData: CredentialsRequestType; const i18n = useTranslator(); return ( @@ -1116,6 +1116,7 @@ function RegistrationForm(Props: any): VNode { class="pure-button pure-button-primary" onClick={() => { console.log("maybe submitting the registration.."); + if (typeof submitData === "undefined") return; if ((typeof submitData.password === "undefined") || (typeof submitData.username === "undefined")) return; if (submitData.password.length === 0 || @@ -1200,6 +1201,7 @@ function Transactions(Props: any): VNode { * to the bank. */ function Account(Props: any): VNode { + const { cache } = useSWRConfig(); const { accountLabel, backendState } = Props; const [pageState, pageStateSetter] = useContext(PageContext); const { @@ -1208,6 +1210,7 @@ function Account(Props: any): VNode { withdrawalOutcome, transferOutcome, withdrawalId, + isLoggedIn, talerWithdrawUri } = pageState; const i18n = useTranslator(); const logOut = ( @@ -1243,7 +1246,8 @@ function Account(Props: any): VNode { /** * Getting the bank account balance. */ - const { data, error } = useSWR(`access-api/accounts/${accountLabel}`); + const endpoint = `access-api/accounts/${accountLabel}`; + const { data, error, mutate } = useSWR(endpoint); if (typeof error !== "undefined") { console.log("account error", error); /** @@ -1256,8 +1260,21 @@ function Account(Props: any): VNode { ...prevState, hasError: true, isLoggedIn: false, - error: i18n`Username or account label '${accountLabel}' not found. Won't login.` + error: i18n`Username or account label '${accountLabel}' not found. Won't login.` })); + + /** + * 404 should never stick to the cache, because they + * taint successful registrations: + */ + console.log("Cache at Account:", cache); + for (const key of cache.keys()) { + console.log("processing key: " + key); + if (RegExp(`${endpoint}$`).test(key)) { + console.log("Deleting key: " + key); + cache.delete(key) + } + } return <p>Profile not found...</p>; } case 401: { @@ -1419,7 +1436,7 @@ function SWRWithoutCredentials(Props: any): VNode { */ function PublicHistories(Props: any): VNode { const [showAccount, setShowAccount] = useState<string | undefined>(); - const { data, error } = useSWR("access-api/public-accounts") + const { data, error } = useSWR("access-api/public-accounts"); const i18n = useTranslator(); if (typeof error !== "undefined") {