fix #7469: also remove hasInfo hasError and use the present of value instead
This commit is contained in:
parent
2146aac17d
commit
1c4b3b4488
@ -91,8 +91,6 @@ const CurrencyContext = createContext<any>(null);
|
|||||||
type PageContextType = [PageStateType, StateUpdater<PageStateType>];
|
type PageContextType = [PageStateType, StateUpdater<PageStateType>];
|
||||||
const PageContextDefault: PageContextType = [
|
const PageContextDefault: PageContextType = [
|
||||||
{
|
{
|
||||||
hasError: false,
|
|
||||||
hasInfo: false,
|
|
||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
isRawPayto: false,
|
isRawPayto: false,
|
||||||
showPublicHistories: false,
|
showPublicHistories: false,
|
||||||
@ -161,8 +159,6 @@ interface PageStateType {
|
|||||||
isLoggedIn: boolean;
|
isLoggedIn: boolean;
|
||||||
isRawPayto: boolean;
|
isRawPayto: boolean;
|
||||||
showPublicHistories: boolean;
|
showPublicHistories: boolean;
|
||||||
hasError: boolean;
|
|
||||||
hasInfo: boolean;
|
|
||||||
withdrawalInProgress: boolean;
|
withdrawalInProgress: boolean;
|
||||||
error?: {
|
error?: {
|
||||||
description?: string;
|
description?: string;
|
||||||
@ -480,8 +476,6 @@ function usePageState(
|
|||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
isRawPayto: false,
|
isRawPayto: false,
|
||||||
showPublicHistories: false,
|
showPublicHistories: false,
|
||||||
hasError: false,
|
|
||||||
hasInfo: false,
|
|
||||||
withdrawalInProgress: false,
|
withdrawalInProgress: false,
|
||||||
},
|
},
|
||||||
): [PageStateType, StateUpdater<PageStateType>] {
|
): [PageStateType, StateUpdater<PageStateType>] {
|
||||||
@ -504,9 +498,7 @@ function usePageState(
|
|||||||
return retSetter((current: any) => {
|
return retSetter((current: any) => {
|
||||||
const cleanedCurrent: PageStateType = {
|
const cleanedCurrent: PageStateType = {
|
||||||
...current,
|
...current,
|
||||||
hasInfo: false,
|
|
||||||
info: undefined,
|
info: undefined,
|
||||||
hasError: false,
|
|
||||||
errors: undefined,
|
errors: undefined,
|
||||||
timestamp: new Date().getTime(),
|
timestamp: new Date().getTime(),
|
||||||
};
|
};
|
||||||
@ -545,7 +537,7 @@ async function abortWithdrawalCall(
|
|||||||
console.log("No credentials found.");
|
console.log("No credentials found.");
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: `No credentials found.`,
|
title: `No credentials found.`,
|
||||||
},
|
},
|
||||||
@ -556,7 +548,7 @@ async function abortWithdrawalCall(
|
|||||||
console.log("No withdrawal ID found.");
|
console.log("No withdrawal ID found.");
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: `No withdrawal ID found.`,
|
title: `No withdrawal ID found.`,
|
||||||
},
|
},
|
||||||
@ -588,7 +580,7 @@ async function abortWithdrawalCall(
|
|||||||
console.log("Could not abort the withdrawal", error);
|
console.log("Could not abort the withdrawal", error);
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: `Could not abort the withdrawal.`,
|
title: `Could not abort the withdrawal.`,
|
||||||
description: (error as any).error.description,
|
description: (error as any).error.description,
|
||||||
@ -605,7 +597,7 @@ async function abortWithdrawalCall(
|
|||||||
);
|
);
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: `Withdrawal abortion failed.`,
|
title: `Withdrawal abortion failed.`,
|
||||||
description: response.error.description,
|
description: response.error.description,
|
||||||
@ -619,6 +611,7 @@ async function abortWithdrawalCall(
|
|||||||
const { ...rest } = prevState;
|
const { ...rest } = prevState;
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
|
|
||||||
info: "Withdrawal aborted!",
|
info: "Withdrawal aborted!",
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -643,7 +636,7 @@ async function confirmWithdrawalCall(
|
|||||||
console.log("No credentials found.");
|
console.log("No credentials found.");
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: "No credentials found.",
|
title: "No credentials found.",
|
||||||
},
|
},
|
||||||
@ -654,7 +647,7 @@ async function confirmWithdrawalCall(
|
|||||||
console.log("No withdrawal ID found.");
|
console.log("No withdrawal ID found.");
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: "No withdrawal ID found.",
|
title: "No withdrawal ID found.",
|
||||||
},
|
},
|
||||||
@ -689,7 +682,7 @@ async function confirmWithdrawalCall(
|
|||||||
console.log("Could not POST withdrawal confirmation to the bank", error);
|
console.log("Could not POST withdrawal confirmation to the bank", error);
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: `Could not confirm the withdrawal`,
|
title: `Could not confirm the withdrawal`,
|
||||||
description: (error as any).error.description,
|
description: (error as any).error.description,
|
||||||
@ -707,7 +700,7 @@ async function confirmWithdrawalCall(
|
|||||||
);
|
);
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: `Withdrawal confirmation gave response error`,
|
title: `Withdrawal confirmation gave response error`,
|
||||||
debug: JSON.stringify(response),
|
debug: JSON.stringify(response),
|
||||||
@ -720,6 +713,7 @@ async function confirmWithdrawalCall(
|
|||||||
const { talerWithdrawUri, ...rest } = prevState;
|
const { talerWithdrawUri, ...rest } = prevState;
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
|
|
||||||
info: "Withdrawal confirmed!",
|
info: "Withdrawal confirmed!",
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -752,7 +746,7 @@ async function createTransactionCall(
|
|||||||
console.log("Could not POST transaction request to the bank", error);
|
console.log("Could not POST transaction request to the bank", error);
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: `Could not create the wire transfer`,
|
title: `Could not create the wire transfer`,
|
||||||
description: (error as any).error.description,
|
description: (error as any).error.description,
|
||||||
@ -769,7 +763,7 @@ async function createTransactionCall(
|
|||||||
);
|
);
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: `Transfer creation gave response error`,
|
title: `Transfer creation gave response error`,
|
||||||
description: response.error.description,
|
description: response.error.description,
|
||||||
@ -782,7 +776,7 @@ async function createTransactionCall(
|
|||||||
console.log("Wire transfer created!");
|
console.log("Wire transfer created!");
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasInfo: true,
|
|
||||||
info: "Wire transfer created!",
|
info: "Wire transfer created!",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -809,7 +803,7 @@ async function createWithdrawalCall(
|
|||||||
console.log("Page has a problem: no credentials found in the state.");
|
console.log("Page has a problem: no credentials found in the state.");
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: "No credentials given.",
|
title: "No credentials given.",
|
||||||
},
|
},
|
||||||
@ -836,7 +830,7 @@ async function createWithdrawalCall(
|
|||||||
console.log("Could not POST withdrawal request to the bank", error);
|
console.log("Could not POST withdrawal request to the bank", error);
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: `Could not create withdrawal operation`,
|
title: `Could not create withdrawal operation`,
|
||||||
description: (error as any).error.description,
|
description: (error as any).error.description,
|
||||||
@ -852,7 +846,7 @@ async function createWithdrawalCall(
|
|||||||
);
|
);
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: `Withdrawal creation gave response error`,
|
title: `Withdrawal creation gave response error`,
|
||||||
description: response.error.description,
|
description: response.error.description,
|
||||||
@ -942,7 +936,7 @@ async function registrationCall(
|
|||||||
);
|
);
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: `Registration failed, please report`,
|
title: `Registration failed, please report`,
|
||||||
debug: JSON.stringify(error),
|
debug: JSON.stringify(error),
|
||||||
@ -955,7 +949,7 @@ async function registrationCall(
|
|||||||
if (res.status === 409) {
|
if (res.status === 409) {
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: `That username is already taken`,
|
title: `That username is already taken`,
|
||||||
debug: JSON.stringify(response),
|
debug: JSON.stringify(response),
|
||||||
@ -964,7 +958,7 @@ async function registrationCall(
|
|||||||
} else {
|
} else {
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: `New registration gave response error`,
|
title: `New registration gave response error`,
|
||||||
debug: JSON.stringify(response),
|
debug: JSON.stringify(response),
|
||||||
@ -994,7 +988,7 @@ async function registrationCall(
|
|||||||
function ErrorBanner(Props: any): VNode | null {
|
function ErrorBanner(Props: any): VNode | null {
|
||||||
const [pageState, pageStateSetter] = Props.pageState;
|
const [pageState, pageStateSetter] = Props.pageState;
|
||||||
// const i18n = useTranslator();
|
// const i18n = useTranslator();
|
||||||
if (!pageState.hasError) return null;
|
if (!pageState.error) return null;
|
||||||
|
|
||||||
const rval = (
|
const rval = (
|
||||||
<div class="informational informational-fail" style={{ marginTop: 8 }}>
|
<div class="informational informational-fail" style={{ marginTop: 8 }}>
|
||||||
@ -1017,16 +1011,32 @@ function ErrorBanner(Props: any): VNode | null {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
delete pageState.error;
|
delete pageState.error;
|
||||||
pageState.hasError = false;
|
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
function StatusBanner(Props: any): VNode | null {
|
function StatusBanner(Props: any): VNode | null {
|
||||||
const [pageState, pageStateSetter] = Props.pageState;
|
const [pageState, pageStateSetter] = Props.pageState;
|
||||||
const i18n = useTranslator();
|
if (!pageState.info) return null;
|
||||||
if (!pageState.hasInfo) return null;
|
|
||||||
|
|
||||||
const rval = <p class="informational informational-ok">{pageState.info}</p>;
|
const rval = (
|
||||||
|
<div class="informational informational-ok" style={{ marginTop: 8 }}>
|
||||||
|
<div style={{ display: "flex", justifyContent: "space-between" }}>
|
||||||
|
<p>
|
||||||
|
<b>{pageState.info}</b>
|
||||||
|
</p>
|
||||||
|
<div>
|
||||||
|
<input
|
||||||
|
type="button"
|
||||||
|
class="pure-button"
|
||||||
|
value="Clear"
|
||||||
|
onClick={async () => {
|
||||||
|
pageStateSetter((prev: any) => ({ ...prev, info: undefined }));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1046,8 +1056,8 @@ function BankFrame(Props: any): VNode {
|
|||||||
...rest,
|
...rest,
|
||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
withdrawalInProgress: false,
|
withdrawalInProgress: false,
|
||||||
hasInfo: false,
|
error: undefined,
|
||||||
hasError: false,
|
info: undefined,
|
||||||
isRawPayto: false,
|
isRawPayto: false,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -1297,7 +1307,7 @@ function PaytoWireTransfer(Props: any): VNode {
|
|||||||
console.log("Not all the fields were given.");
|
console.log("Not all the fields were given.");
|
||||||
pageStateSetter((prevState: PageStateType) => ({
|
pageStateSetter((prevState: PageStateType) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: i18n`Field(s) missing.`,
|
title: i18n`Field(s) missing.`,
|
||||||
},
|
},
|
||||||
@ -1502,7 +1512,7 @@ function TalerWithdrawalConfirmationQuestion(Props: any): VNode {
|
|||||||
}
|
}
|
||||||
pageStateSetter((prevState: PageStateType) => ({
|
pageStateSetter((prevState: PageStateType) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: i18n`Answer is wrong.`,
|
title: i18n`Answer is wrong.`,
|
||||||
},
|
},
|
||||||
@ -1617,7 +1627,7 @@ function TalerWithdrawalQRCode(Props: any): VNode {
|
|||||||
);
|
);
|
||||||
pageStateSetter((prevState: PageStateType) => ({
|
pageStateSetter((prevState: PageStateType) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: i18n`withdrawal (${withdrawalId}) was never (correctly) created at the bank...`,
|
title: i18n`withdrawal (${withdrawalId}) was never (correctly) created at the bank...`,
|
||||||
},
|
},
|
||||||
@ -1645,7 +1655,7 @@ function TalerWithdrawalQRCode(Props: any): VNode {
|
|||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
withdrawalInProgress: false,
|
withdrawalInProgress: false,
|
||||||
hasError: true,
|
|
||||||
error: {
|
error: {
|
||||||
title: i18n`This withdrawal was aborted!`,
|
title: i18n`This withdrawal was aborted!`,
|
||||||
},
|
},
|
||||||
@ -2193,7 +2203,7 @@ function Account(Props: any): VNode {
|
|||||||
case 404: {
|
case 404: {
|
||||||
setPageState((prevState: PageStateType) => ({
|
setPageState((prevState: PageStateType) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
error: {
|
error: {
|
||||||
title: i18n`Username or account label '${accountLabel}' not found. Won't login.`,
|
title: i18n`Username or account label '${accountLabel}' not found. Won't login.`,
|
||||||
@ -2220,7 +2230,7 @@ function Account(Props: any): VNode {
|
|||||||
case HttpStatusCode.Forbidden: {
|
case HttpStatusCode.Forbidden: {
|
||||||
setPageState((prevState: PageStateType) => ({
|
setPageState((prevState: PageStateType) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
error: {
|
error: {
|
||||||
title: i18n`Wrong credentials given.`,
|
title: i18n`Wrong credentials given.`,
|
||||||
@ -2231,7 +2241,7 @@ function Account(Props: any): VNode {
|
|||||||
default: {
|
default: {
|
||||||
setPageState((prevState: PageStateType) => ({
|
setPageState((prevState: PageStateType) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
error: {
|
error: {
|
||||||
title: i18n`Account information could not be retrieved.`,
|
title: i18n`Account information could not be retrieved.`,
|
||||||
@ -2378,7 +2388,7 @@ function PublicHistories(Props: any): VNode {
|
|||||||
console.log("public accounts: 404", error);
|
console.log("public accounts: 404", error);
|
||||||
Props.pageStateSetter((prevState: PageStateType) => ({
|
Props.pageStateSetter((prevState: PageStateType) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
showPublicHistories: false,
|
showPublicHistories: false,
|
||||||
error: {
|
error: {
|
||||||
title: i18n`List of public accounts was not found.`,
|
title: i18n`List of public accounts was not found.`,
|
||||||
@ -2390,7 +2400,7 @@ function PublicHistories(Props: any): VNode {
|
|||||||
console.log("public accounts: non-404 error", error);
|
console.log("public accounts: non-404 error", error);
|
||||||
Props.pageStateSetter((prevState: PageStateType) => ({
|
Props.pageStateSetter((prevState: PageStateType) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
showPublicHistories: false,
|
showPublicHistories: false,
|
||||||
error: {
|
error: {
|
||||||
title: i18n`List of public accounts could not be retrieved.`,
|
title: i18n`List of public accounts could not be retrieved.`,
|
||||||
@ -2530,7 +2540,7 @@ function AccountPage(): VNode {
|
|||||||
if (typeof backendState === "undefined") {
|
if (typeof backendState === "undefined") {
|
||||||
pageStateSetter((prevState) => ({
|
pageStateSetter((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
hasError: true,
|
|
||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
error: {
|
error: {
|
||||||
title: i18n`Page has a problem: logged in but backend state is lost.`,
|
title: i18n`Page has a problem: logged in but backend state is lost.`,
|
||||||
|
Loading…
Reference in New Issue
Block a user