fix loop rendering

This commit is contained in:
Sebastian 2022-03-30 14:22:42 -03:00
parent bbd6ccf1c7
commit 8642f8edcd
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
15 changed files with 73 additions and 41 deletions

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/*
This file is part of TALER
(C) 2015 GNUnet e.V.
@ -197,7 +198,7 @@ export function PaymentRequestView({
payStatus,
payResult,
}: PaymentRequestViewProps): VNode {
let totalFees: AmountJson = Amounts.getZero(payStatus.amountRaw);
const totalFees: AmountJson = Amounts.getZero(payStatus.amountRaw);
const contractTerms: ContractTerms = payStatus.contractTerms;
const { i18n } = useTranslationContext();

View File

@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/*
This file is part of TALER
(C) 2015 GNUnet e.V.

View File

@ -28,7 +28,7 @@ import {
WithdrawUriInfoResponse,
} from "@gnu-taler/taler-util";
import { Fragment, h, VNode } from "preact";
import { useState } from "preact/hooks";
import { useCallback, useMemo, useState } from "preact/hooks";
import { Loading } from "../components/Loading.js";
import { LoadingError } from "../components/LoadingError.js";
import { ErrorTalerOperation } from "../components/ErrorTalerOperation.js";
@ -247,37 +247,52 @@ export function WithdrawPageWithParsedURI({
const [reviewing, setReviewing] = useState<boolean>(false);
const [reviewed, setReviewed] = useState<boolean>(false);
const knownExchangesHook = useAsyncAsHook(() => wxApi.listExchanges());
const knownExchanges =
!knownExchangesHook || knownExchangesHook.hasError
? []
: knownExchangesHook.response.exchanges;
const withdrawAmount = Amounts.parseOrThrow(uriInfo.amount);
const thisCurrencyExchanges = knownExchanges.filter(
(ex) => ex.currency === withdrawAmount.currency,
const knownExchangesHook = useAsyncAsHook(
useCallback(() => wxApi.listExchanges(), []),
);
const exchange: string | undefined =
customExchange ??
uriInfo.defaultExchangeBaseUrl ??
(thisCurrencyExchanges[0]
? thisCurrencyExchanges[0].exchangeBaseUrl
: undefined);
const knownExchanges = useMemo(
() =>
!knownExchangesHook || knownExchangesHook.hasError
? []
: knownExchangesHook.response.exchanges,
[knownExchangesHook],
);
const withdrawAmount = useMemo(
() => Amounts.parseOrThrow(uriInfo.amount),
[uriInfo.amount],
);
const thisCurrencyExchanges = useMemo(
() =>
knownExchanges.filter((ex) => ex.currency === withdrawAmount.currency),
[knownExchanges, withdrawAmount.currency],
);
const detailsHook = useAsyncAsHook(async () => {
if (!exchange) throw Error("no default exchange");
const tos = await wxApi.getExchangeTos(exchange, ["text/xml"]);
const exchange: string | undefined = useMemo(
() =>
customExchange ??
uriInfo.defaultExchangeBaseUrl ??
(thisCurrencyExchanges[0]
? thisCurrencyExchanges[0].exchangeBaseUrl
: undefined),
[customExchange, thisCurrencyExchanges, uriInfo.defaultExchangeBaseUrl],
);
const tosState = buildTermsOfServiceState(tos);
const detailsHook = useAsyncAsHook(
useCallback(async () => {
if (!exchange) throw Error("no default exchange");
const tos = await wxApi.getExchangeTos(exchange, ["text/xml"]);
const info = await wxApi.getExchangeWithdrawalInfo({
exchangeBaseUrl: exchange,
amount: withdrawAmount,
tosAcceptedFormat: ["text/xml"],
});
return { tos: tosState, info };
});
const tosState = buildTermsOfServiceState(tos);
const info = await wxApi.getExchangeWithdrawalInfo({
exchangeBaseUrl: exchange,
amount: withdrawAmount,
tosAcceptedFormat: ["text/xml"],
});
return { tos: tosState, info };
}, [exchange, withdrawAmount]),
);
if (!detailsHook) {
return <Loading />;
@ -342,10 +357,14 @@ export function WithdrawPageWithParsedURI({
}
export function WithdrawPage({ talerWithdrawUri }: Props): VNode {
const { i18n } = useTranslationContext();
const uriInfoHook = useAsyncAsHook(() =>
!talerWithdrawUri
? Promise.reject(undefined)
: wxApi.getWithdrawalDetailsForUri({ talerWithdrawUri }),
const uriInfoHook = useAsyncAsHook(
useCallback(
() =>
!talerWithdrawUri
? Promise.reject(undefined)
: wxApi.getWithdrawalDetailsForUri({ talerWithdrawUri }),
[talerWithdrawUri],
),
);
if (!talerWithdrawUri) {

View File

@ -74,6 +74,6 @@ export function useAsyncAsHook<T>(
doAsync();
});
}
});
}, [fn, updateOnNotification]);
return result;
}

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/*
This file is part of GNU Taler
(C) 2021 Taler Systems S.A.

View File

@ -1,6 +1,6 @@
import { css } from "@linaria/core";
import { ComponentChildren, createContext, h, VNode } from "preact";
import { useContext, useState } from "preact/hooks";
import { useContext, useMemo, useState } from "preact/hooks";
// eslint-disable-next-line import/extensions
import { Colors } from "../style";
@ -152,6 +152,10 @@ function withoutUndefinedProperties(obj: any): any {
export function useFormControl(props: Partial<FCCProps> = {}): FCCProps {
const ctx = useContext(FormControlContext);
const cleanedProps = withoutUndefinedProperties(props);
if (!ctx) return { ...defaultContextValue, ...cleanedProps };
return { ...ctx, ...cleanedProps };
return useMemo(() => {
return !ctx
? { ...defaultContextValue, ...cleanedProps }
: { ...ctx, ...cleanedProps };
}, [cleanedProps, ctx]);
}

View File

@ -169,7 +169,7 @@ export function InputBase({
} else {
fcs.onEmpty();
}
}, [value]);
}, [value, fcs]);
const handleFocus = (event: JSX.TargetedFocusEvent<EventTarget>): void => {
// Fix a bug with IE11 where the focus/blur events are triggered

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/*
This file is part of TALER
(C) 2017 INRIA

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/*
This file is part of GNU Taler
(C) 2021 Taler Systems S.A.

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/*
This file is part of GNU Taler
(C) 2021 Taler Systems S.A.

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/*
This file is part of GNU Taler
(C) 2021 Taler Systems S.A.

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/*
This file is part of TALER
(C) 2016 GNUnet e.V.
@ -162,7 +163,7 @@ export function useComponentState(
onCalculateFee(selectedAccount, parsedAmount).then((result) => {
setFee(result);
});
}, [amount]);
}, [amount, selectedAccount, parsedAmount, onCalculateFee]);
const bs = balances.filter((b) => b.available.startsWith(currency));
const balance =

View File

@ -64,7 +64,7 @@ function useEndpointStatus<T>(
}
}, 500);
setHandler(h);
}, [value]);
}, [value, setHandler, handler, onVerify]);
return {
error: dirty ? error : undefined,

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/*
This file is part of GNU Taler
(C) 2021 Taler Systems S.A.
@ -112,7 +113,7 @@ export function SetUrlView({
setUrlError(true);
setName(undefined);
}
}, [value]);
}, [onVerify, value]);
return (
<Fragment>
<section>

View File

@ -40,7 +40,6 @@ import {
Wallet,
WalletStoresV1
} from "@gnu-taler/taler-wallet-core";
import { VNode } from "preact";
import { BrowserCryptoWorkerFactory } from "./browserCryptoWorkerFactory.js";
import { BrowserHttpLib } from "./browserHttpLib.js";
import { getReadRequestPermissions } from "./permissions.js";