better /config error
This commit is contained in:
parent
820f953b96
commit
ea0738ccd5
@ -32,6 +32,9 @@ export function ErrorLoading({ error }: { error: HttpError<SandboxBackend.Sandbo
|
|||||||
<p class="text-sm font-medium text-red-800">{error.message}</p>
|
<p class="text-sm font-medium text-red-800">{error.message}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="ml-3 flex-1 md:flex md:justify-between">
|
||||||
|
<p class="text-sm font-medium text-red-800">Got status "{error.info.status}" on {error.info.url}</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -44,7 +44,7 @@ export function useComponentState({ account }: Props): State {
|
|||||||
cp.targetType === "bitcoin" ? `${cp.targetPath.substring(0, 6)}...` : undefined) ??
|
cp.targetType === "bitcoin" ? `${cp.targetPath.substring(0, 6)}...` : undefined) ??
|
||||||
"unkown";
|
"unkown";
|
||||||
|
|
||||||
const when = AbsoluteTime.fromMilliseconds(tx.date / 1000);
|
const when = AbsoluteTime.fromProtocolTimestamp(tx.date);
|
||||||
const amount = Amounts.parse(tx.amount);
|
const amount = Amounts.parse(tx.amount);
|
||||||
const subject = tx.subject;
|
const subject = tx.subject;
|
||||||
return {
|
return {
|
||||||
|
@ -29,6 +29,8 @@ import { useEffect, useState } from "preact/hooks";
|
|||||||
import { Loading } from "./Loading.js";
|
import { Loading } from "./Loading.js";
|
||||||
import { getInitialBackendBaseURL } from "../hooks/backend.js";
|
import { getInitialBackendBaseURL } from "../hooks/backend.js";
|
||||||
import { BANK_INTEGRATION_PROTOCOL_VERSION, useConfigState } from "../hooks/config.js";
|
import { BANK_INTEGRATION_PROTOCOL_VERSION, useConfigState } from "../hooks/config.js";
|
||||||
|
import { ErrorLoading } from "./ErrorLoading.js";
|
||||||
|
import { BankFrame } from "../pages/BankFrame.js";
|
||||||
const WITH_LOCAL_STORAGE_CACHE = false;
|
const WITH_LOCAL_STORAGE_CACHE = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,12 +78,18 @@ function VersionCheck({ children }: { children: ComponentChildren }): VNode {
|
|||||||
if (checked === undefined) {
|
if (checked === undefined) {
|
||||||
return <Loading />
|
return <Loading />
|
||||||
}
|
}
|
||||||
if (checked === false) {
|
if (typeof checked === "string") {
|
||||||
return <div>
|
return <BankFrame>
|
||||||
the bank backend is not supported. supported version "{BANK_INTEGRATION_PROTOCOL_VERSION}"
|
the bank backend is not supported. supported version "{BANK_INTEGRATION_PROTOCOL_VERSION}", server version "{checked}"
|
||||||
</div>
|
</BankFrame>
|
||||||
}
|
}
|
||||||
return <Fragment>{children}</Fragment>
|
if (checked === true) {
|
||||||
|
return <Fragment>{children}</Fragment>
|
||||||
|
}
|
||||||
|
|
||||||
|
return <BankFrame>
|
||||||
|
<ErrorLoading error={checked}/>
|
||||||
|
</BankFrame>
|
||||||
}
|
}
|
||||||
|
|
||||||
function localStorageProvider(): Map<unknown, unknown> {
|
function localStorageProvider(): Map<unknown, unknown> {
|
||||||
|
3
packages/demobank-ui/src/declaration.d.ts
vendored
3
packages/demobank-ui/src/declaration.d.ts
vendored
@ -205,8 +205,7 @@ namespace SandboxBackend {
|
|||||||
// Transaction unique ID. Matches
|
// Transaction unique ID. Matches
|
||||||
// $transaction_id from the URI.
|
// $transaction_id from the URI.
|
||||||
row_id: number;
|
row_id: number;
|
||||||
date: number;
|
date: Timestamp;
|
||||||
// date: Timestamp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CreateBankAccountTransactionCreate {
|
interface CreateBankAccountTransactionCreate {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { LibtoolVersion } from "@gnu-taler/taler-util";
|
import { LibtoolVersion } from "@gnu-taler/taler-util";
|
||||||
import { useApiContext } from "@gnu-taler/web-util/browser";
|
import { ErrorType, HttpError, HttpResponseServerError, RequestError, useApiContext } from "@gnu-taler/web-util/browser";
|
||||||
import { useEffect, useState } from "preact/hooks";
|
import { useEffect, useState } from "preact/hooks";
|
||||||
import { getInitialBackendBaseURL } from "./backend.js";
|
import { getInitialBackendBaseURL } from "./backend.js";
|
||||||
|
|
||||||
@ -12,38 +12,32 @@ export const BANK_INTEGRATION_PROTOCOL_VERSION = "0:0:0";
|
|||||||
|
|
||||||
async function getConfigState(
|
async function getConfigState(
|
||||||
request: ReturnType<typeof useApiContext>["request"],
|
request: ReturnType<typeof useApiContext>["request"],
|
||||||
): Promise<SandboxBackend.Config | undefined> {
|
): Promise<SandboxBackend.Config> {
|
||||||
try {
|
const url = getInitialBackendBaseURL();
|
||||||
const url = getInitialBackendBaseURL();
|
const result = await request<SandboxBackend.Config>(url, `config`);
|
||||||
const result = await request<SandboxBackend.Config>(
|
return result.data;
|
||||||
url,
|
|
||||||
`config`,
|
|
||||||
);
|
|
||||||
return result.data;
|
|
||||||
} catch (error) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useConfigState(): boolean | undefined {
|
export function useConfigState(): undefined | true | string | HttpError<SandboxBackend.SandboxError> {
|
||||||
const [checked, setChecked] = useState<boolean>()
|
const [checked, setChecked] = useState<true | string | HttpError<SandboxBackend.SandboxError>>()
|
||||||
const { request } = useApiContext();
|
const { request } = useApiContext();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
getConfigState(request)
|
getConfigState(request)
|
||||||
.then((result) => {
|
.then((s) => {
|
||||||
if (!result) {
|
const r = LibtoolVersion.compare(BANK_INTEGRATION_PROTOCOL_VERSION, s.version)
|
||||||
setChecked(false)
|
if (r?.compatible) {
|
||||||
|
setChecked(true);
|
||||||
} else {
|
} else {
|
||||||
const r = LibtoolVersion.compare(BANK_INTEGRATION_PROTOCOL_VERSION, result.version)
|
setChecked(s.version)
|
||||||
setChecked(r?.compatible);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error: unknown) => {
|
||||||
setChecked(false);
|
if (error instanceof RequestError) {
|
||||||
|
setChecked(error.cause);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
}, []);
|
||||||
|
|
||||||
return checked;
|
return checked;
|
||||||
}
|
}
|
||||||
|
@ -75,9 +75,7 @@ export function useComponentState({ account, goToBusinessAccount, goToConfirmOpe
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: balance
|
const balanceIsDebit = data.balance.credit_debit_indicator == "debit";
|
||||||
const balanceIsDebit = true;
|
|
||||||
// data.balance.credit_debit_indicator == "debit";
|
|
||||||
const limit = balanceIsDebit
|
const limit = balanceIsDebit
|
||||||
? Amounts.sub(debitThreshold, balance).amount
|
? Amounts.sub(debitThreshold, balance).amount
|
||||||
: Amounts.add(balance, debitThreshold).amount;
|
: Amounts.add(balance, debitThreshold).amount;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Amounts, Logger, PaytoUriIBAN, TranslatedString, parsePaytoUri, stringifyPaytoUri } from "@gnu-taler/taler-util";
|
import { Amounts, Logger, PaytoUriIBAN, TranslatedString, parsePaytoUri, stringifyPaytoUri } from "@gnu-taler/taler-util";
|
||||||
import { notifyError, useNotifications, useTranslationContext } from "@gnu-taler/web-util/browser";
|
import { notifyError, notifyException, useNotifications, useTranslationContext } from "@gnu-taler/web-util/browser";
|
||||||
import { ComponentChildren, Fragment, h, VNode } from "preact";
|
import { ComponentChildren, Fragment, h, VNode } from "preact";
|
||||||
import { StateUpdater, useEffect, useErrorBoundary, useState } from "preact/hooks";
|
import { StateUpdater, useEffect, useErrorBoundary, useState } from "preact/hooks";
|
||||||
import { LangSelectorLikePy as LangSelector } from "../components/LangSelector.js";
|
import { LangSelectorLikePy as LangSelector } from "../components/LangSelector.js";
|
||||||
@ -54,7 +54,12 @@ export function BankFrame({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (error) {
|
if (error) {
|
||||||
notifyError(i18n.str`Internal error, please report.`, (error instanceof Error ? error.message : String(error)) as TranslatedString)
|
const desc = (error instanceof Error ? error.stack : String(error)) as TranslatedString
|
||||||
|
if (error instanceof Error) {
|
||||||
|
notifyException(i18n.str`Internal error, please report.`, error)
|
||||||
|
} else {
|
||||||
|
notifyError(i18n.str`Internal error, please report.`, String(error) as TranslatedString)
|
||||||
|
}
|
||||||
resetError()
|
resetError()
|
||||||
}
|
}
|
||||||
}, [error])
|
}, [error])
|
||||||
@ -386,6 +391,11 @@ function StatusBanner(): VNode {
|
|||||||
{n.message.description}
|
{n.message.description}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
{n.message.debug &&
|
||||||
|
<div class="mt-2 text-sm text-red-700 font-mono break-all">
|
||||||
|
{n.message.debug}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
case "info":
|
case "info":
|
||||||
return <div class="rounded-md bg-green-50 border-4 border-green-600 p-6">
|
return <div class="rounded-md bg-green-50 border-4 border-green-600 p-6">
|
||||||
|
@ -45,7 +45,6 @@ export function WithdrawalQRCode({
|
|||||||
withdrawUri,
|
withdrawUri,
|
||||||
onClose,
|
onClose,
|
||||||
}: Props): VNode {
|
}: Props): VNode {
|
||||||
const [settings, updateSettings] = useSettings();
|
|
||||||
const { i18n } = useTranslationContext();
|
const { i18n } = useTranslationContext();
|
||||||
const result = useWithdrawalDetails(withdrawUri.withdrawalOperationId);
|
const result = useWithdrawalDetails(withdrawUri.withdrawalOperationId);
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ export { useMemoryStorage } from "./useMemoryStorage.js";
|
|||||||
export {
|
export {
|
||||||
useNotifications,
|
useNotifications,
|
||||||
notifyError,
|
notifyError,
|
||||||
|
notifyException,
|
||||||
notifyInfo,
|
notifyInfo,
|
||||||
notify,
|
notify,
|
||||||
ErrorNotification,
|
ErrorNotification,
|
||||||
|
@ -36,6 +36,17 @@ export function notifyError(
|
|||||||
debug,
|
debug,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
export function notifyException(
|
||||||
|
title: TranslatedString,
|
||||||
|
ex: Error,
|
||||||
|
) {
|
||||||
|
notify({
|
||||||
|
type: "error" as const,
|
||||||
|
title,
|
||||||
|
description: ex.message as TranslatedString,
|
||||||
|
debug: ex.stack,
|
||||||
|
});
|
||||||
|
}
|
||||||
export function notifyInfo(title: TranslatedString) {
|
export function notifyInfo(title: TranslatedString) {
|
||||||
notify({
|
notify({
|
||||||
type: "info" as const,
|
type: "info" as const,
|
||||||
|
Loading…
Reference in New Issue
Block a user