aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/pages/LoginForm.tsx
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-10-19 15:10:18 -0300
committerSebastian <sebasjm@gmail.com>2023-10-19 15:10:18 -0300
commit7582855e2723e11de25f10b6d5ba8a0757616765 (patch)
tree320f30c7202c88ba63542b93de1cbda533a73356 /packages/demobank-ui/src/pages/LoginForm.tsx
parent9e925a2f56677600973c4659f82776a6a56339bb (diff)
downloadwallet-core-7582855e2723e11de25f10b6d5ba8a0757616765.tar.xz
some ui fixes
Diffstat (limited to 'packages/demobank-ui/src/pages/LoginForm.tsx')
-rw-r--r--packages/demobank-ui/src/pages/LoginForm.tsx69
1 files changed, 31 insertions, 38 deletions
diff --git a/packages/demobank-ui/src/pages/LoginForm.tsx b/packages/demobank-ui/src/pages/LoginForm.tsx
index a8167cca5..981b0f880 100644
--- a/packages/demobank-ui/src/pages/LoginForm.tsx
+++ b/packages/demobank-ui/src/pages/LoginForm.tsx
@@ -21,7 +21,7 @@ import { useEffect, useRef, useState } from "preact/hooks";
import { ShowInputErrorLabel } from "../components/ShowInputErrorLabel.js";
import { useBackendContext } from "../context/backend.js";
import { bankUiSettings } from "../settings.js";
-import { undefinedIfEmpty } from "../utils.js";
+import { undefinedIfEmpty, withRuntimeErrorHandling } from "../utils.js";
import { doAutoFocus } from "./PaytoWireTransferForm.js";
import { useBankCoreApiContext } from "../context/config.js";
import { assertUnreachable } from "./HomePage.js";
@@ -78,43 +78,36 @@ export function LoginForm({ reason, onRegister }: { reason?: "not-found" | "forb
async function doLogin() {
if (!username || !password) return;
setBusy({})
- const data: TalerAuthentication.TokenRequest = {
- // scope: "readwrite" as "write", //FIX: different than merchant
- scope: "readwrite",
- duration: {
- d_us: "forever" //FIX: should return shortest
- // d_us: 60 * 60 * 24 * 7 * 1000 * 1000
- },
- refreshable: true,
- }
- const resp = await api.getAuthenticationAPI(username).createAccessToken(password, {
- // scope: "readwrite" as "write", //FIX: different than merchant
- scope: "readwrite",
- duration: {
- d_us: "forever" //FIX: should return shortest
- // d_us: 60 * 60 * 24 * 7 * 1000 * 1000
- },
- refreshable: true,
- })
- if (resp.type === "ok") {
- backend.logIn({ username, token: resp.body.access_token });
- } else {
- switch (resp.case) {
- case "wrong-credentials": return notify({
- type: "error",
- title: i18n.str`Wrong credentials for "${username}"`,
- description: resp.detail.hint as TranslatedString,
- debug: resp.detail,
- })
- case "not-found": return notify({
- type: "error",
- title: i18n.str`Account not found`,
- description: resp.detail.hint as TranslatedString,
- debug: resp.detail,
- })
- default: assertUnreachable(resp)
+ await withRuntimeErrorHandling(i18n, async () => {
+ const resp = await api.getAuthenticationAPI(username).createAccessToken(password, {
+ // scope: "readwrite" as "write", //FIX: different than merchant
+ scope: "readwrite",
+ duration: {
+ d_us: "forever" //FIX: should return shortest
+ // d_us: 60 * 60 * 24 * 7 * 1000 * 1000
+ },
+ refreshable: true,
+ })
+ if (resp.type === "ok") {
+ backend.logIn({ username, token: resp.body.access_token });
+ } else {
+ switch (resp.case) {
+ case "wrong-credentials": return notify({
+ type: "error",
+ title: i18n.str`Wrong credentials for "${username}"`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ case "not-found": return notify({
+ type: "error",
+ title: i18n.str`Account not found`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ default: assertUnreachable(resp)
+ }
}
- }
+ })
setPassword(undefined);
setBusy(undefined)
}
@@ -198,7 +191,7 @@ export function LoginForm({ reason, onRegister }: { reason?: "not-found" | "forb
<button type="submit"
class="rounded-md bg-indigo-600 disabled:bg-gray-300 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
disabled={!!errors}
- onClick={(e) => {
+ onClick={async (e) => {
e.preventDefault()
doLogin()
}}