demobank-ui: fix error reporting

This commit is contained in:
Florian Dold 2022-10-31 16:06:22 +01:00
parent 6e7928062f
commit d3855a1861
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
3 changed files with 17 additions and 36 deletions

View File

@ -1,8 +1,5 @@
# This Makefile has been placed in the public domain. # This Makefile has been placed in the public domain.
src = src
poname = taler-wallet-webex
tsc = node_modules/typescript/bin/tsc tsc = node_modules/typescript/bin/tsc
pogen = node_modules/@gnu-taler/pogen/bin/pogen.js pogen = node_modules/@gnu-taler/pogen/bin/pogen.js
typedoc = node_modules/typedoc/bin/typedoc typedoc = node_modules/typedoc/bin/typedoc
@ -82,30 +79,10 @@ webextension-dev:
pnpm install --frozen-lockfile --filter @gnu-taler/taler-wallet-webextension... pnpm install --frozen-lockfile --filter @gnu-taler/taler-wallet-webextension...
pnpm run --filter @gnu-taler/taler-wallet-webextension... dev pnpm run --filter @gnu-taler/taler-wallet-webextension... dev
.PHONY: i18n
i18n: compile
# extract translatable strings
find $(src) \( -name '*.ts' -or -name '*.tsx' \) ! -name '*.d.ts' \
| xargs node $(pogen) \
| msguniq \
| msgmerge src/i18n/poheader - \
> src/i18n/$(poname).pot
# merge existing translations
@for pofile in src/i18n/*.po; do \
echo merging $$pofile; \
msgmerge -o $$pofile $$pofile src/i18n/$(poname).pot; \
done;
# generate .ts file containing all translations
cat src/i18n/strings-prelude > src/i18n/strings.ts
@for pofile in src/i18n/*.po; do \
echo appending $$pofile; \
./contrib/po2ts $$pofile >> src/i18n/strings.ts; \
done;
./node_modules/.bin/prettier --config .prettierrc --write src/i18n/strings.ts
# Some commands are only available when ./configure has been run
.PHONY: lint .PHONY: lint
lint: lint:
./node_modules/.bin/eslint --ext '.js,.ts,.tsx' 'src' ./node_modules/.bin/eslint --ext '.js,.ts,.tsx' 'src'
install:
@echo Please run \'make install\' from one of the directories in packages/\'

View File

@ -31,7 +31,7 @@ import { QR } from "../../components/QR.js";
import { useLocalStorage, useNotNullLocalStorage } from "../../hooks/index.js"; import { useLocalStorage, useNotNullLocalStorage } from "../../hooks/index.js";
import { Translate, useTranslator } from "../../i18n/index.js"; import { Translate, useTranslator } from "../../i18n/index.js";
import "../../scss/main.scss"; import "../../scss/main.scss";
import { Amounts, parsePaytoUri } from "@gnu-taler/taler-util"; import { Amounts, HttpStatusCode, parsePaytoUri } from "@gnu-taler/taler-util";
interface BankUiSettings { interface BankUiSettings {
allowRegistrations: boolean; allowRegistrations: boolean;
@ -2119,7 +2119,7 @@ function Account(Props: any): VNode {
// revalidateOnFocus: false, // revalidateOnFocus: false,
// revalidateOnReconnect: false, // revalidateOnReconnect: false,
}); });
const [pageState, pageStateSetter] = useContext(PageContext); const [pageState, setPageState] = useContext(PageContext);
const { withdrawalInProgress, withdrawalId, isLoggedIn, talerWithdrawUri } = const { withdrawalInProgress, withdrawalId, isLoggedIn, talerWithdrawUri } =
pageState; pageState;
const i18n = useTranslator(); const i18n = useTranslator();
@ -2141,7 +2141,7 @@ function Account(Props: any): VNode {
*/ */
switch (error.status) { switch (error.status) {
case 404: { case 404: {
pageStateSetter((prevState: PageStateType) => ({ setPageState((prevState: PageStateType) => ({
...prevState, ...prevState,
hasError: true, hasError: true,
isLoggedIn: false, isLoggedIn: false,
@ -2166,8 +2166,9 @@ function Account(Props: any): VNode {
(cache as any).clear(); (cache as any).clear();
return <p>Profile not found...</p>; return <p>Profile not found...</p>;
} }
case 401: { case HttpStatusCode.Unauthorized:
pageStateSetter((prevState: PageStateType) => ({ case HttpStatusCode.Forbidden: {
setPageState((prevState: PageStateType) => ({
...prevState, ...prevState,
hasError: true, hasError: true,
isLoggedIn: false, isLoggedIn: false,
@ -2178,10 +2179,10 @@ function Account(Props: any): VNode {
return <p>Wrong credentials...</p>; return <p>Wrong credentials...</p>;
} }
default: { default: {
pageStateSetter((prevState: PageStateType) => ({ setPageState((prevState: PageStateType) => ({
...prevState, ...prevState,
hasError: true, hasError: true,
// isLoggedIn: false, isLoggedIn: false,
error: { error: {
title: i18n`Account information could not be retrieved.`, title: i18n`Account information could not be retrieved.`,
debug: JSON.stringify(error), debug: JSON.stringify(error),
@ -2249,7 +2250,7 @@ function Account(Props: any): VNode {
{Props.children} {Props.children}
<PaymentOptions <PaymentOptions
backendState={backendState} backendState={backendState}
pageStateSetter={pageStateSetter} pageStateSetter={setPageState}
/> />
</CurrencyContext.Provider> </CurrencyContext.Provider>
</div> </div>

View File

@ -1,7 +1,10 @@
# This Makefile has been placed in the public domain. # This Makefile has been placed in the public domain.
-include ../../.config.mk
include .config.mk include .config.mk
$(info prefix is $(prefix))
all: all:
@echo use 'make install' to build and install taler-wallet-cli @echo use 'make install' to build and install taler-wallet-cli
@ -22,6 +25,6 @@ install:
install -d $(install_target)/node_modules/taler-wallet-cli/dist install -d $(install_target)/node_modules/taler-wallet-cli/dist
install ./dist/taler-wallet-cli.js $(install_target)/node_modules/taler-wallet-cli/dist/ install ./dist/taler-wallet-cli.js $(install_target)/node_modules/taler-wallet-cli/dist/
install ./dist/taler-wallet-cli.js.map $(install_target)/node_modules/taler-wallet-cli/dist/ install ./dist/taler-wallet-cli.js.map $(install_target)/node_modules/taler-wallet-cli/dist/
install ./bin/taler-wallet-cli $(install_target)/node_modules/taler-wallet-cli/bin/ install ./bin/taler-wallet-cli.js $(install_target)/node_modules/taler-wallet-cli/bin/
ln -sf $(install_target)/node_modules/taler-wallet-cli/bin/taler-wallet-cli $(prefix)/bin/taler-wallet-cli ln -sf $(install_target)/node_modules/taler-wallet-cli/bin/taler-wallet-cli $(prefix)/bin/taler-wallet-cli
endif endif