some fixes
after update pageState reset info and error message input values should not be undefined, otherwise it gets uncontrolled (not controlled by preact) autofocus on captcha create a dependency from transactionList to balance, so tx list will be queried again if balance is updated update balance on any pageChange
This commit is contained in:
parent
d2e2c0198f
commit
1bfaf997c3
@ -112,8 +112,6 @@ export function useLocalStorage(
|
|||||||
value?: string | ((val?: string) => string | undefined),
|
value?: string | ((val?: string) => string | undefined),
|
||||||
) => {
|
) => {
|
||||||
setStoredValue((p) => {
|
setStoredValue((p) => {
|
||||||
console.log("calling setStoredValue");
|
|
||||||
console.log(window);
|
|
||||||
const toStore = value instanceof Function ? value(p) : value;
|
const toStore = value instanceof Function ? value(p) : value;
|
||||||
if (typeof window !== "undefined")
|
if (typeof window !== "undefined")
|
||||||
if (!toStore) window.localStorage.removeItem(key);
|
if (!toStore) window.localStorage.removeItem(key);
|
||||||
|
@ -176,6 +176,7 @@ interface PageStateType {
|
|||||||
* be moved in a future "withdrawal state" object.
|
* be moved in a future "withdrawal state" object.
|
||||||
*/
|
*/
|
||||||
withdrawalId?: string;
|
withdrawalId?: string;
|
||||||
|
timestamp?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -497,7 +498,24 @@ function usePageState(
|
|||||||
|
|
||||||
ret[1](newVal);
|
ret[1](newVal);
|
||||||
};
|
};
|
||||||
return [retObj, retSetter];
|
|
||||||
|
//when moving from one page to another
|
||||||
|
//clean up the info and error bar
|
||||||
|
function removeLatestInfo(val: any): ReturnType<typeof retSetter> {
|
||||||
|
const updater = typeof val === 'function' ? val : (c:any) => val
|
||||||
|
return retSetter((current:any) => {
|
||||||
|
const cleanedCurrent: PageStateType = {...current,
|
||||||
|
hasInfo: false,
|
||||||
|
info: undefined,
|
||||||
|
hasError: false,
|
||||||
|
errors: undefined,
|
||||||
|
timestamp: new Date().getTime()
|
||||||
|
}
|
||||||
|
return updater(cleanedCurrent)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return [retObj, removeLatestInfo];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -997,9 +1015,7 @@ function StatusBanner(Props: any): VNode | null {
|
|||||||
const i18n = useTranslator();
|
const i18n = useTranslator();
|
||||||
if (!pageState.hasInfo) return null;
|
if (!pageState.hasInfo) return null;
|
||||||
|
|
||||||
const rval = <p class="informational">{pageState.error}</p>;
|
const rval = <p class="informational informational-ok">{pageState.info}</p>;
|
||||||
delete pageState.info_msg;
|
|
||||||
pageState.hasInfo = false;
|
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1176,7 +1192,7 @@ function PaytoWireTransfer(Props: any): VNode {
|
|||||||
type="text"
|
type="text"
|
||||||
id="iban"
|
id="iban"
|
||||||
name="iban"
|
name="iban"
|
||||||
value={submitData?.iban}
|
value={submitData?.iban ?? ""}
|
||||||
placeholder="CC0123456789"
|
placeholder="CC0123456789"
|
||||||
required
|
required
|
||||||
pattern={ibanRegex}
|
pattern={ibanRegex}
|
||||||
@ -1199,7 +1215,7 @@ function PaytoWireTransfer(Props: any): VNode {
|
|||||||
name="subject"
|
name="subject"
|
||||||
id="subject"
|
id="subject"
|
||||||
placeholder="subject"
|
placeholder="subject"
|
||||||
value={submitData?.subject}
|
value={submitData?.subject ?? ""}
|
||||||
required
|
required
|
||||||
onInput={(e): void => {
|
onInput={(e): void => {
|
||||||
submitDataSetter((submitData: any) => ({
|
submitDataSetter((submitData: any) => ({
|
||||||
@ -1221,7 +1237,7 @@ function PaytoWireTransfer(Props: any): VNode {
|
|||||||
id="amount"
|
id="amount"
|
||||||
placeholder="amount"
|
placeholder="amount"
|
||||||
required
|
required
|
||||||
value={submitData?.amount}
|
value={submitData?.amount ?? ""}
|
||||||
pattern={amountRegex}
|
pattern={amountRegex}
|
||||||
onInput={(e): void => {
|
onInput={(e): void => {
|
||||||
submitDataSetter((submitData: any) => ({
|
submitDataSetter((submitData: any) => ({
|
||||||
@ -1282,7 +1298,11 @@ function PaytoWireTransfer(Props: any): VNode {
|
|||||||
transactionData,
|
transactionData,
|
||||||
backendState,
|
backendState,
|
||||||
pageStateSetter,
|
pageStateSetter,
|
||||||
() => submitDataSetter((p) => ({})),
|
() => submitDataSetter((p) => ({
|
||||||
|
amount: undefined,
|
||||||
|
iban: undefined,
|
||||||
|
subject: undefined,
|
||||||
|
})),
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@ -1291,7 +1311,11 @@ function PaytoWireTransfer(Props: any): VNode {
|
|||||||
class="pure-button"
|
class="pure-button"
|
||||||
value="Clear"
|
value="Clear"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
submitDataSetter((p) => ({}));
|
submitDataSetter((p) => ({
|
||||||
|
amount: undefined,
|
||||||
|
iban: undefined,
|
||||||
|
subject: undefined,
|
||||||
|
}));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</p>
|
</p>
|
||||||
@ -1436,6 +1460,7 @@ function TalerWithdrawalConfirmationQuestion(Props: any): VNode {
|
|||||||
name="answer"
|
name="answer"
|
||||||
id="answer"
|
id="answer"
|
||||||
type="text"
|
type="text"
|
||||||
|
autoFocus
|
||||||
required
|
required
|
||||||
onInput={(e): void => {
|
onInput={(e): void => {
|
||||||
captchaAnswer = e.currentTarget.value;
|
captchaAnswer = e.currentTarget.value;
|
||||||
@ -1472,8 +1497,8 @@ function TalerWithdrawalConfirmationQuestion(Props: any): VNode {
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
class="pure-button pure-button-secondary btn-cancel"
|
class="pure-button pure-button-secondary btn-cancel"
|
||||||
onClick={() =>
|
onClick={async () =>
|
||||||
abortWithdrawalCall(
|
await abortWithdrawalCall(
|
||||||
backendState,
|
backendState,
|
||||||
pageState.withdrawalId,
|
pageState.withdrawalId,
|
||||||
pageStateSetter,
|
pageStateSetter,
|
||||||
@ -1791,11 +1816,11 @@ function LoginForm(Props: any): VNode {
|
|||||||
ref.current?.focus();
|
ref.current?.focus();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const errors = undefinedIfEmpty({
|
const errors = !submitData ? undefined : undefinedIfEmpty({
|
||||||
username: !(submitData && submitData.username)
|
username: !submitData.username
|
||||||
? i18n`Missing username`
|
? i18n`Missing username`
|
||||||
: undefined,
|
: undefined,
|
||||||
password: !(submitData && submitData.password)
|
password: !submitData.password
|
||||||
? i18n`Missing password`
|
? i18n`Missing password`
|
||||||
: undefined,
|
: undefined,
|
||||||
});
|
});
|
||||||
@ -1865,7 +1890,11 @@ function LoginForm(Props: any): VNode {
|
|||||||
backendStateSetter,
|
backendStateSetter,
|
||||||
pageStateSetter,
|
pageStateSetter,
|
||||||
);
|
);
|
||||||
submitDataSetter({});
|
submitDataSetter({
|
||||||
|
password: "",
|
||||||
|
repeatPassword: "",
|
||||||
|
username:"",
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{i18n`Login`}
|
{i18n`Login`}
|
||||||
@ -2034,11 +2063,14 @@ function RegistrationForm(Props: any): VNode {
|
|||||||
* Show one page of transactions.
|
* Show one page of transactions.
|
||||||
*/
|
*/
|
||||||
function Transactions(Props: any): VNode {
|
function Transactions(Props: any): VNode {
|
||||||
const { pageNumber, accountLabel } = Props;
|
const { pageNumber, accountLabel, balanceValue } = Props;
|
||||||
const i18n = useTranslator();
|
const i18n = useTranslator();
|
||||||
const { data, error } = useSWR(
|
const { data, error, mutate } = useSWR(
|
||||||
`access-api/accounts/${accountLabel}/transactions?page=${pageNumber}`,
|
`access-api/accounts/${accountLabel}/transactions?page=${pageNumber}`,
|
||||||
);
|
);
|
||||||
|
useEffect(() => {
|
||||||
|
mutate()
|
||||||
|
}, [balanceValue])
|
||||||
if (typeof error !== "undefined") {
|
if (typeof error !== "undefined") {
|
||||||
console.log("transactions not found error", error);
|
console.log("transactions not found error", error);
|
||||||
switch (error.status) {
|
switch (error.status) {
|
||||||
@ -2120,12 +2152,12 @@ function Account(Props: any): VNode {
|
|||||||
// revalidateOnReconnect: false,
|
// revalidateOnReconnect: false,
|
||||||
});
|
});
|
||||||
const [pageState, setPageState] = useContext(PageContext);
|
const [pageState, setPageState] = useContext(PageContext);
|
||||||
const { withdrawalInProgress, withdrawalId, isLoggedIn, talerWithdrawUri } =
|
const { withdrawalInProgress, withdrawalId, isLoggedIn, talerWithdrawUri, timestamp } =
|
||||||
pageState;
|
pageState;
|
||||||
const i18n = useTranslator();
|
const i18n = useTranslator();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
mutate()
|
mutate()
|
||||||
}, [talerWithdrawUri])
|
}, [timestamp])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This part shows a list of transactions: with 5 elements by
|
* This part shows a list of transactions: with 5 elements by
|
||||||
@ -2262,7 +2294,7 @@ function Account(Props: any): VNode {
|
|||||||
<section id="main">
|
<section id="main">
|
||||||
<article>
|
<article>
|
||||||
<h2>{i18n`Latest transactions:`}</h2>
|
<h2>{i18n`Latest transactions:`}</h2>
|
||||||
<Transactions pageNumber="0" accountLabel={accountLabel} />
|
<Transactions balanceValue={balanceValue} pageNumber="0" accountLabel={accountLabel} />
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
</BankFrame>
|
</BankFrame>
|
||||||
|
Loading…
Reference in New Issue
Block a user