better /config error

This commit is contained in:
Sebastian 2023-09-25 14:49:47 -03:00
parent 820f953b96
commit ea0738ccd5
No known key found for this signature in database
GPG Key ID: 173909D1A5F66069
10 changed files with 60 additions and 37 deletions

View File

@ -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>
);

View File

@ -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 {

View File

@ -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> {

View File

@ -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 {

View File

@ -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;
}

View File

@ -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;

View File

@ -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">

View File

@ -45,7 +45,6 @@ export function WithdrawalQRCode({
withdrawUri,
onClose,
}: Props): VNode {
const [settings, updateSettings] = useSettings();
const { i18n } = useTranslationContext();
const result = useWithdrawalDetails(withdrawUri.withdrawalOperationId);

View File

@ -4,6 +4,7 @@ export { useMemoryStorage } from "./useMemoryStorage.js";
export {
useNotifications,
notifyError,
notifyException,
notifyInfo,
notify,
ErrorNotification,

View File

@ -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,