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>
|
||||
</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>
|
||||
);
|
||||
|
@ -44,7 +44,7 @@ export function useComponentState({ account }: Props): State {
|
||||
cp.targetType === "bitcoin" ? `${cp.targetPath.substring(0, 6)}...` : undefined) ??
|
||||
"unkown";
|
||||
|
||||
const when = AbsoluteTime.fromMilliseconds(tx.date / 1000);
|
||||
const when = AbsoluteTime.fromProtocolTimestamp(tx.date);
|
||||
const amount = Amounts.parse(tx.amount);
|
||||
const subject = tx.subject;
|
||||
return {
|
||||
|
@ -29,6 +29,8 @@ import { useEffect, useState } from "preact/hooks";
|
||||
import { Loading } from "./Loading.js";
|
||||
import { getInitialBackendBaseURL } from "../hooks/backend.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;
|
||||
|
||||
/**
|
||||
@ -76,12 +78,18 @@ function VersionCheck({ children }: { children: ComponentChildren }): VNode {
|
||||
if (checked === undefined) {
|
||||
return <Loading />
|
||||
}
|
||||
if (checked === false) {
|
||||
return <div>
|
||||
the bank backend is not supported. supported version "{BANK_INTEGRATION_PROTOCOL_VERSION}"
|
||||
</div>
|
||||
if (typeof checked === "string") {
|
||||
return <BankFrame>
|
||||
the bank backend is not supported. supported version "{BANK_INTEGRATION_PROTOCOL_VERSION}", server version "{checked}"
|
||||
</BankFrame>
|
||||
}
|
||||
if (checked === true) {
|
||||
return <Fragment>{children}</Fragment>
|
||||
}
|
||||
|
||||
return <BankFrame>
|
||||
<ErrorLoading error={checked}/>
|
||||
</BankFrame>
|
||||
}
|
||||
|
||||
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_id from the URI.
|
||||
row_id: number;
|
||||
date: number;
|
||||
// date: Timestamp;
|
||||
date: Timestamp;
|
||||
}
|
||||
|
||||
interface CreateBankAccountTransactionCreate {
|
||||
|
@ -1,5 +1,5 @@
|
||||
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 { getInitialBackendBaseURL } from "./backend.js";
|
||||
|
||||
@ -12,38 +12,32 @@ export const BANK_INTEGRATION_PROTOCOL_VERSION = "0:0:0";
|
||||
|
||||
async function getConfigState(
|
||||
request: ReturnType<typeof useApiContext>["request"],
|
||||
): Promise<SandboxBackend.Config | undefined> {
|
||||
try {
|
||||
): Promise<SandboxBackend.Config> {
|
||||
const url = getInitialBackendBaseURL();
|
||||
const result = await request<SandboxBackend.Config>(
|
||||
url,
|
||||
`config`,
|
||||
);
|
||||
const result = await request<SandboxBackend.Config>(url, `config`);
|
||||
return result.data;
|
||||
} catch (error) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function useConfigState(): boolean | undefined {
|
||||
const [checked, setChecked] = useState<boolean>()
|
||||
export function useConfigState(): undefined | true | string | HttpError<SandboxBackend.SandboxError> {
|
||||
const [checked, setChecked] = useState<true | string | HttpError<SandboxBackend.SandboxError>>()
|
||||
const { request } = useApiContext();
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
getConfigState(request)
|
||||
.then((result) => {
|
||||
if (!result) {
|
||||
setChecked(false)
|
||||
.then((s) => {
|
||||
const r = LibtoolVersion.compare(BANK_INTEGRATION_PROTOCOL_VERSION, s.version)
|
||||
if (r?.compatible) {
|
||||
setChecked(true);
|
||||
} else {
|
||||
const r = LibtoolVersion.compare(BANK_INTEGRATION_PROTOCOL_VERSION, result.version)
|
||||
setChecked(r?.compatible);
|
||||
setChecked(s.version)
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
setChecked(false);
|
||||
});
|
||||
.catch((error: unknown) => {
|
||||
if (error instanceof RequestError) {
|
||||
setChecked(error.cause);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
||||
return checked;
|
||||
}
|
||||
|
@ -75,9 +75,7 @@ export function useComponentState({ account, goToBusinessAccount, goToConfirmOpe
|
||||
};
|
||||
}
|
||||
|
||||
// FIXME: balance
|
||||
const balanceIsDebit = true;
|
||||
// data.balance.credit_debit_indicator == "debit";
|
||||
const balanceIsDebit = data.balance.credit_debit_indicator == "debit";
|
||||
const limit = balanceIsDebit
|
||||
? Amounts.sub(debitThreshold, balance).amount
|
||||
: Amounts.add(balance, debitThreshold).amount;
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
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 { StateUpdater, useEffect, useErrorBoundary, useState } from "preact/hooks";
|
||||
import { LangSelectorLikePy as LangSelector } from "../components/LangSelector.js";
|
||||
@ -54,7 +54,12 @@ export function BankFrame({
|
||||
|
||||
useEffect(() => {
|
||||
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()
|
||||
}
|
||||
}, [error])
|
||||
@ -386,6 +391,11 @@ function StatusBanner(): VNode {
|
||||
{n.message.description}
|
||||
</div>
|
||||
}
|
||||
{n.message.debug &&
|
||||
<div class="mt-2 text-sm text-red-700 font-mono break-all">
|
||||
{n.message.debug}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
case "info":
|
||||
return <div class="rounded-md bg-green-50 border-4 border-green-600 p-6">
|
||||
|
@ -45,7 +45,6 @@ export function WithdrawalQRCode({
|
||||
withdrawUri,
|
||||
onClose,
|
||||
}: Props): VNode {
|
||||
const [settings, updateSettings] = useSettings();
|
||||
const { i18n } = useTranslationContext();
|
||||
const result = useWithdrawalDetails(withdrawUri.withdrawalOperationId);
|
||||
|
||||
|
@ -4,6 +4,7 @@ export { useMemoryStorage } from "./useMemoryStorage.js";
|
||||
export {
|
||||
useNotifications,
|
||||
notifyError,
|
||||
notifyException,
|
||||
notifyInfo,
|
||||
notify,
|
||||
ErrorNotification,
|
||||
|
@ -36,6 +36,17 @@ export function notifyError(
|
||||
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) {
|
||||
notify({
|
||||
type: "info" as const,
|
||||
|
Loading…
Reference in New Issue
Block a user