using loadingerror
This commit is contained in:
parent
e263907017
commit
e38be8d8ec
@ -30,28 +30,29 @@ import { PopupNavigation } from "./components/styled";
|
|||||||
|
|
||||||
export enum Pages {
|
export enum Pages {
|
||||||
welcome = "/welcome",
|
welcome = "/welcome",
|
||||||
|
|
||||||
balance = "/balance",
|
balance = "/balance",
|
||||||
balance_history = "/balance/history/:currency",
|
balance_history = "/balance/history/:currency",
|
||||||
manual_withdraw = "/balance/manual-withdraw/:currency?",
|
balance_manual_withdraw = "/balance/manual-withdraw/:currency?",
|
||||||
deposit = "/balance/deposit/:currency",
|
balance_deposit = "/balance/deposit/:currency",
|
||||||
transaction = "/balance/transaction/:tid",
|
balance_transaction = "/balance/transaction/:tid",
|
||||||
settings = "/settings",
|
|
||||||
dev = "/dev",
|
dev = "/dev",
|
||||||
cta = "/cta/:action",
|
|
||||||
backup = "/backup",
|
backup = "/backup",
|
||||||
|
backup_provider_detail = "/backup/provider/:pid",
|
||||||
|
backup_provider_add = "/backup/provider/add",
|
||||||
|
|
||||||
last_activity = "/last-activity",
|
last_activity = "/last-activity",
|
||||||
provider_detail = "/provider/:pid",
|
|
||||||
provider_add = "/provider/add",
|
|
||||||
exchange_add = "/exchange/add",
|
|
||||||
|
|
||||||
reset_required = "/reset-required",
|
settings = "/settings",
|
||||||
payback = "/payback",
|
settings_exchange_add = "/settings/exchange/add",
|
||||||
return_coins = "/return-coins",
|
|
||||||
|
|
||||||
pay = "/pay",
|
cta = "/cta/:action",
|
||||||
refund = "/refund",
|
cta_pay = "/cta/pay",
|
||||||
tips = "/tip",
|
cta_refund = "/cta/refund",
|
||||||
withdraw = "/withdraw",
|
cta_tips = "/cta/tip",
|
||||||
|
cta_withdraw = "/cta/withdraw",
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TabProps {
|
interface TabProps {
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
You should have received a copy of the GNU General Public License along with
|
You should have received a copy of the GNU General Public License along with
|
||||||
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
import { TalerErrorCode, TalerErrorDetails } from "@gnu-taler/taler-util";
|
import { TalerErrorDetails } from "@gnu-taler/taler-util";
|
||||||
import { VNode, h, Fragment } from "preact";
|
import { Fragment, h, VNode } from "preact";
|
||||||
import { useState } from "preact/hooks";
|
import { useState } from "preact/hooks";
|
||||||
import arrowDown from "../../static/img/chevron-down.svg";
|
import arrowDown from "../../static/img/chevron-down.svg";
|
||||||
import { useDevContext } from "../context/devContext";
|
import { useDevContext } from "../context/devContext";
|
||||||
@ -45,20 +45,23 @@ export function ErrorTalerOperation({
|
|||||||
setShowErrorDetail((v) => !v);
|
setShowErrorDetail((v) => !v);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<img style={{ height: "1.5em" }} src={arrowDown} />
|
<img
|
||||||
|
style={{
|
||||||
|
transform: !showErrorDetail ? undefined : "scaleY(-1)",
|
||||||
|
height: "1.5em",
|
||||||
|
}}
|
||||||
|
src={arrowDown}
|
||||||
|
/>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{showErrorDetail && (
|
{showErrorDetail && (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<div style={{ padding: 5, textAlign: "left" }}>
|
<div style={{ padding: 5, textAlign: "left" }}>
|
||||||
<div>{error.message}</div>
|
<div>
|
||||||
|
<b>{error.message}</b> {!errorHint ? "" : `: ${errorHint}`}{" "}
|
||||||
</div>
|
</div>
|
||||||
{errorHint && (
|
|
||||||
<div style={{ padding: 5, textAlign: "left" }}>
|
|
||||||
<div>{errorHint}</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
{devMode && (
|
{devMode && (
|
||||||
<div style={{ textAlign: "left", overflowX: "auto" }}>
|
<div style={{ textAlign: "left", overflowX: "auto" }}>
|
||||||
<pre>{JSON.stringify(error, undefined, 2)}</pre>
|
<pre>{JSON.stringify(error, undefined, 2)}</pre>
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
This file is part of TALER
|
||||||
|
(C) 2016 GNUnet e.V.
|
||||||
|
|
||||||
|
TALER is free software; you can redistribute it and/or modify it under the
|
||||||
|
terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 3, or (at your option) any later version.
|
||||||
|
|
||||||
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
import { h, VNode } from "preact";
|
||||||
|
import { HookError } from "../hooks/useAsyncAsHook";
|
||||||
|
import { ErrorMessage } from "./ErrorMessage";
|
||||||
|
import { ErrorTalerOperation } from "./ErrorTalerOperation";
|
||||||
|
|
||||||
|
export interface Props {
|
||||||
|
title: string;
|
||||||
|
error: HookError;
|
||||||
|
}
|
||||||
|
export function LoadingError({ title, error }: Props): VNode {
|
||||||
|
if (error.operational) {
|
||||||
|
return <ErrorTalerOperation title={title} error={error.details} />;
|
||||||
|
}
|
||||||
|
return <ErrorMessage title={title} description={error.message} />;
|
||||||
|
}
|
@ -127,7 +127,7 @@ export function TransactionItem(props: {
|
|||||||
|
|
||||||
function TransactionLayout(props: TransactionLayoutProps): VNode {
|
function TransactionLayout(props: TransactionLayoutProps): VNode {
|
||||||
return (
|
return (
|
||||||
<HistoryRow href={Pages.transaction.replace(":tid", props.id)}>
|
<HistoryRow href={Pages.balance_transaction.replace(":tid", props.id)}>
|
||||||
<img src={props.iconPath} />
|
<img src={props.iconPath} />
|
||||||
<Column>
|
<Column>
|
||||||
<LargeText>
|
<LargeText>
|
||||||
|
@ -29,7 +29,6 @@ import {
|
|||||||
Amounts,
|
Amounts,
|
||||||
amountToPretty,
|
amountToPretty,
|
||||||
ConfirmPayResult,
|
ConfirmPayResult,
|
||||||
ConfirmPayResultDone,
|
|
||||||
ConfirmPayResultType,
|
ConfirmPayResultType,
|
||||||
ContractTerms,
|
ContractTerms,
|
||||||
i18n,
|
i18n,
|
||||||
@ -174,11 +173,8 @@ export interface PaymentRequestViewProps {
|
|||||||
balance: AmountJson | undefined;
|
balance: AmountJson | undefined;
|
||||||
}
|
}
|
||||||
export function PaymentRequestView({
|
export function PaymentRequestView({
|
||||||
uri,
|
|
||||||
payStatus,
|
payStatus,
|
||||||
payResult,
|
payResult,
|
||||||
onClick,
|
|
||||||
balance,
|
|
||||||
}: PaymentRequestViewProps): VNode {
|
}: PaymentRequestViewProps): VNode {
|
||||||
let totalFees: AmountJson = Amounts.getZero(payStatus.amountRaw);
|
let totalFees: AmountJson = Amounts.getZero(payStatus.amountRaw);
|
||||||
const contractTerms: ContractTerms = payStatus.contractTerms;
|
const contractTerms: ContractTerms = payStatus.contractTerms;
|
||||||
|
@ -40,14 +40,14 @@ import {
|
|||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import { OperationFailedError } from "@gnu-taler/taler-wallet-core";
|
import { OperationFailedError } from "@gnu-taler/taler-wallet-core";
|
||||||
import { Fragment, h, VNode } from "preact";
|
import { Fragment, h, VNode } from "preact";
|
||||||
import { useEffect, useState } from "preact/hooks";
|
import { useState } from "preact/hooks";
|
||||||
import { ErrorTalerOperation } from "../components/ErrorTalerOperation";
|
import { Loading } from "../components/Loading";
|
||||||
|
import { LoadingError } from "../components/LoadingError";
|
||||||
import { LogoHeader } from "../components/LogoHeader";
|
import { LogoHeader } from "../components/LogoHeader";
|
||||||
import { Part } from "../components/Part";
|
import { Part } from "../components/Part";
|
||||||
import { QR } from "../components/QR";
|
import { QR } from "../components/QR";
|
||||||
import {
|
import {
|
||||||
ButtonSuccess,
|
ButtonSuccess,
|
||||||
ErrorBox,
|
|
||||||
LinkSuccess,
|
LinkSuccess,
|
||||||
SmallLightText,
|
SmallLightText,
|
||||||
SuccessBox,
|
SuccessBox,
|
||||||
@ -84,10 +84,8 @@ const doPayment = async (
|
|||||||
export function PayPage({
|
export function PayPage({
|
||||||
talerPayUri,
|
talerPayUri,
|
||||||
goToWalletManualWithdraw,
|
goToWalletManualWithdraw,
|
||||||
|
goBack,
|
||||||
}: Props): VNode {
|
}: Props): VNode {
|
||||||
const [payStatus, setPayStatus] = useState<PreparePayResult | undefined>(
|
|
||||||
undefined,
|
|
||||||
);
|
|
||||||
const [payResult, setPayResult] = useState<ConfirmPayResult | undefined>(
|
const [payResult, setPayResult] = useState<ConfirmPayResult | undefined>(
|
||||||
undefined,
|
undefined,
|
||||||
);
|
);
|
||||||
@ -95,83 +93,33 @@ export function PayPage({
|
|||||||
OperationFailedError | string | undefined
|
OperationFailedError | string | undefined
|
||||||
>(undefined);
|
>(undefined);
|
||||||
|
|
||||||
const balance = useAsyncAsHook(wxApi.getBalance, [
|
const hook = useAsyncAsHook(async () => {
|
||||||
NotificationType.CoinWithdrawn,
|
if (!talerPayUri) throw Error("Missing pay uri");
|
||||||
]);
|
const payStatus = await wxApi.preparePay(talerPayUri);
|
||||||
const balanceWithoutError = balance?.hasError
|
const balance = await wxApi.getBalance();
|
||||||
? []
|
return { payStatus, balance };
|
||||||
: balance?.response.balances || [];
|
}, [NotificationType.CoinWithdrawn]);
|
||||||
|
|
||||||
const foundBalance = balanceWithoutError.find(
|
if (!hook) {
|
||||||
|
return <Loading />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hook.hasError) {
|
||||||
|
return <LoadingError title="Could not load pay status" error={hook} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const foundBalance = hook.response.balance.balances.find(
|
||||||
(b) =>
|
(b) =>
|
||||||
payStatus &&
|
|
||||||
Amounts.parseOrThrow(b.available).currency ===
|
Amounts.parseOrThrow(b.available).currency ===
|
||||||
Amounts.parseOrThrow(payStatus?.amountRaw).currency,
|
Amounts.parseOrThrow(hook.response.payStatus.amountRaw).currency,
|
||||||
);
|
);
|
||||||
const foundAmount = foundBalance
|
const foundAmount = foundBalance
|
||||||
? Amounts.parseOrThrow(foundBalance.available)
|
? Amounts.parseOrThrow(foundBalance.available)
|
||||||
: undefined;
|
: undefined;
|
||||||
// We use a string here so that dependency tracking for useEffect works properly
|
|
||||||
const foundAmountStr = foundAmount
|
|
||||||
? Amounts.stringify(foundAmount)
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!talerPayUri) return;
|
|
||||||
const doFetch = async (): Promise<void> => {
|
|
||||||
try {
|
|
||||||
const p = await wxApi.preparePay(talerPayUri);
|
|
||||||
setPayStatus(p);
|
|
||||||
} catch (e) {
|
|
||||||
console.log("Got error while trying to pay", e);
|
|
||||||
if (e instanceof OperationFailedError) {
|
|
||||||
setPayErrMsg(e);
|
|
||||||
}
|
|
||||||
if (e instanceof Error) {
|
|
||||||
setPayErrMsg(e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
doFetch();
|
|
||||||
}, [talerPayUri, foundAmountStr]);
|
|
||||||
|
|
||||||
if (!talerPayUri) {
|
|
||||||
return <span>missing pay uri</span>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!payStatus) {
|
|
||||||
if (payErrMsg instanceof OperationFailedError) {
|
|
||||||
return (
|
|
||||||
<WalletAction>
|
|
||||||
<LogoHeader />
|
|
||||||
<h2>{i18n.str`Digital cash payment`}</h2>
|
|
||||||
<section>
|
|
||||||
<ErrorTalerOperation
|
|
||||||
title="Could not get the payment information for this order"
|
|
||||||
error={payErrMsg?.operationError}
|
|
||||||
/>
|
|
||||||
</section>
|
|
||||||
</WalletAction>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (payErrMsg) {
|
|
||||||
return (
|
|
||||||
<WalletAction>
|
|
||||||
<LogoHeader />
|
|
||||||
<h2>{i18n.str`Digital cash payment`}</h2>
|
|
||||||
<section>
|
|
||||||
<p>Could not get the payment information for this order</p>
|
|
||||||
<ErrorBox>{payErrMsg}</ErrorBox>
|
|
||||||
</section>
|
|
||||||
</WalletAction>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return <span>Loading payment information ...</span>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const onClick = async (): Promise<void> => {
|
const onClick = async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const res = await doPayment(payStatus);
|
const res = await doPayment(hook.response.payStatus);
|
||||||
setPayResult(res);
|
setPayResult(res);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@ -183,8 +131,8 @@ export function PayPage({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<PaymentRequestView
|
<PaymentRequestView
|
||||||
uri={talerPayUri}
|
uri={talerPayUri!}
|
||||||
payStatus={payStatus}
|
payStatus={hook.response.payStatus}
|
||||||
payResult={payResult}
|
payResult={payResult}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
goToWalletManualWithdraw={goToWalletManualWithdraw}
|
goToWalletManualWithdraw={goToWalletManualWithdraw}
|
||||||
|
@ -30,6 +30,8 @@ import {
|
|||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import { Fragment, h, VNode } from "preact";
|
import { Fragment, h, VNode } from "preact";
|
||||||
import { useState } from "preact/hooks";
|
import { useState } from "preact/hooks";
|
||||||
|
import { Loading } from "../components/Loading";
|
||||||
|
import { LoadingError } from "../components/LoadingError";
|
||||||
import { LogoHeader } from "../components/LogoHeader";
|
import { LogoHeader } from "../components/LogoHeader";
|
||||||
import { Part } from "../components/Part";
|
import { Part } from "../components/Part";
|
||||||
import { SelectList } from "../components/SelectList";
|
import { SelectList } from "../components/SelectList";
|
||||||
@ -237,19 +239,14 @@ export function WithdrawPageWithParsedURI({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!detailsHook) {
|
if (!detailsHook) {
|
||||||
return (
|
return <Loading />;
|
||||||
<span>
|
|
||||||
<i18n.Translate>Getting withdrawal details.</i18n.Translate>
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (detailsHook.hasError) {
|
if (detailsHook.hasError) {
|
||||||
return (
|
return (
|
||||||
<span>
|
<LoadingError
|
||||||
<i18n.Translate>
|
title="Could not load the withdrawal details"
|
||||||
Problems getting details: {detailsHook.message}
|
error={detailsHook}
|
||||||
</i18n.Translate>
|
/>
|
||||||
</span>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,21 +312,17 @@ export function WithdrawPage({ talerWithdrawUri }: Props): VNode {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!uriInfoHook) {
|
if (!uriInfoHook) {
|
||||||
return (
|
return <Loading />;
|
||||||
<span>
|
|
||||||
<i18n.Translate>Loading...</i18n.Translate>
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (uriInfoHook.hasError) {
|
if (uriInfoHook.hasError) {
|
||||||
return (
|
return (
|
||||||
<span>
|
<LoadingError
|
||||||
<i18n.Translate>
|
title="Could not get the info from the URI"
|
||||||
This URI is not valid anymore: {uriInfoHook.message}
|
error={uriInfoHook}
|
||||||
</i18n.Translate>
|
/>
|
||||||
</span>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WithdrawPageWithParsedURI
|
<WithdrawPageWithParsedURI
|
||||||
uri={talerWithdrawUri}
|
uri={talerWithdrawUri}
|
||||||
|
Loading…
Reference in New Issue
Block a user