aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-09-25 14:49:47 -0300
committerSebastian <sebasjm@gmail.com>2023-09-25 14:50:46 -0300
commitea0738ccd585445d7e2080d9009025dde9cf22c5 (patch)
tree1e89ceadefb2b66d8c762358c794f070c2f10dcd
parent820f953b96b2b2852c32dc16a2fa920c6c717788 (diff)
better /config error
-rw-r--r--packages/demobank-ui/src/components/ErrorLoading.tsx3
-rw-r--r--packages/demobank-ui/src/components/Transactions/state.ts2
-rw-r--r--packages/demobank-ui/src/components/app.tsx18
-rw-r--r--packages/demobank-ui/src/declaration.d.ts3
-rw-r--r--packages/demobank-ui/src/hooks/config.ts40
-rw-r--r--packages/demobank-ui/src/pages/AccountPage/state.ts4
-rw-r--r--packages/demobank-ui/src/pages/BankFrame.tsx14
-rw-r--r--packages/demobank-ui/src/pages/WithdrawalQRCode.tsx1
-rw-r--r--packages/web-util/src/hooks/index.ts1
-rw-r--r--packages/web-util/src/hooks/useNotifications.ts11
10 files changed, 60 insertions, 37 deletions
diff --git a/packages/demobank-ui/src/components/ErrorLoading.tsx b/packages/demobank-ui/src/components/ErrorLoading.tsx
index a4faa4d5d..f83b61234 100644
--- a/packages/demobank-ui/src/components/ErrorLoading.tsx
+++ b/packages/demobank-ui/src/components/ErrorLoading.tsx
@@ -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>
);
diff --git a/packages/demobank-ui/src/components/Transactions/state.ts b/packages/demobank-ui/src/components/Transactions/state.ts
index 30c48aa45..4b62b005e 100644
--- a/packages/demobank-ui/src/components/Transactions/state.ts
+++ b/packages/demobank-ui/src/components/Transactions/state.ts
@@ -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 {
diff --git a/packages/demobank-ui/src/components/app.tsx b/packages/demobank-ui/src/components/app.tsx
index ebda31035..a587c6f1e 100644
--- a/packages/demobank-ui/src/components/app.tsx
+++ b/packages/demobank-ui/src/components/app.tsx
@@ -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>
}
- return <Fragment>{children}</Fragment>
+ if (checked === true) {
+ return <Fragment>{children}</Fragment>
+ }
+
+ return <BankFrame>
+ <ErrorLoading error={checked}/>
+ </BankFrame>
}
function localStorageProvider(): Map<unknown, unknown> {
diff --git a/packages/demobank-ui/src/declaration.d.ts b/packages/demobank-ui/src/declaration.d.ts
index 8d729c1f7..d3d9e02ef 100644
--- a/packages/demobank-ui/src/declaration.d.ts
+++ b/packages/demobank-ui/src/declaration.d.ts
@@ -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 {
diff --git a/packages/demobank-ui/src/hooks/config.ts b/packages/demobank-ui/src/hooks/config.ts
index 4b22e8ad3..4cf677d35 100644
--- a/packages/demobank-ui/src/hooks/config.ts
+++ b/packages/demobank-ui/src/hooks/config.ts
@@ -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 {
- const url = getInitialBackendBaseURL();
- const result = await request<SandboxBackend.Config>(
- url,
- `config`,
- );
- return result.data;
- } catch (error) {
- return undefined;
- }
+): Promise<SandboxBackend.Config> {
+ const url = getInitialBackendBaseURL();
+ const result = await request<SandboxBackend.Config>(url, `config`);
+ return result.data;
}
-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;
}
diff --git a/packages/demobank-ui/src/pages/AccountPage/state.ts b/packages/demobank-ui/src/pages/AccountPage/state.ts
index c212e7484..ca7e1d447 100644
--- a/packages/demobank-ui/src/pages/AccountPage/state.ts
+++ b/packages/demobank-ui/src/pages/AccountPage/state.ts
@@ -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;
diff --git a/packages/demobank-ui/src/pages/BankFrame.tsx b/packages/demobank-ui/src/pages/BankFrame.tsx
index c4f872679..5c43d2c3e 100644
--- a/packages/demobank-ui/src/pages/BankFrame.tsx
+++ b/packages/demobank-ui/src/pages/BankFrame.tsx
@@ -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">
diff --git a/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx b/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx
index 25c571e28..8f4e175f6 100644
--- a/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx
+++ b/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx
@@ -45,7 +45,6 @@ export function WithdrawalQRCode({
withdrawUri,
onClose,
}: Props): VNode {
- const [settings, updateSettings] = useSettings();
const { i18n } = useTranslationContext();
const result = useWithdrawalDetails(withdrawUri.withdrawalOperationId);
diff --git a/packages/web-util/src/hooks/index.ts b/packages/web-util/src/hooks/index.ts
index c29de9023..cc3267dbd 100644
--- a/packages/web-util/src/hooks/index.ts
+++ b/packages/web-util/src/hooks/index.ts
@@ -4,6 +4,7 @@ export { useMemoryStorage } from "./useMemoryStorage.js";
export {
useNotifications,
notifyError,
+ notifyException,
notifyInfo,
notify,
ErrorNotification,
diff --git a/packages/web-util/src/hooks/useNotifications.ts b/packages/web-util/src/hooks/useNotifications.ts
index 2f9df24f9..792095b06 100644
--- a/packages/web-util/src/hooks/useNotifications.ts
+++ b/packages/web-util/src/hooks/useNotifications.ts
@@ -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,