diff options
author | Sebastian <sebasjm@gmail.com> | 2023-10-19 15:10:18 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-10-19 15:10:18 -0300 |
commit | 7582855e2723e11de25f10b6d5ba8a0757616765 (patch) | |
tree | 320f30c7202c88ba63542b93de1cbda533a73356 /packages/demobank-ui/src/pages/ShowAccountDetails.tsx | |
parent | 9e925a2f56677600973c4659f82776a6a56339bb (diff) | |
download | wallet-core-7582855e2723e11de25f10b6d5ba8a0757616765.tar.xz |
some ui fixes
Diffstat (limited to 'packages/demobank-ui/src/pages/ShowAccountDetails.tsx')
-rw-r--r-- | packages/demobank-ui/src/pages/ShowAccountDetails.tsx | 77 |
1 files changed, 34 insertions, 43 deletions
diff --git a/packages/demobank-ui/src/pages/ShowAccountDetails.tsx b/packages/demobank-ui/src/pages/ShowAccountDetails.tsx index 3534f9733..c65b90503 100644 --- a/packages/demobank-ui/src/pages/ShowAccountDetails.tsx +++ b/packages/demobank-ui/src/pages/ShowAccountDetails.tsx @@ -7,7 +7,7 @@ import { Loading } from "../components/Loading.js"; import { useBankCoreApiContext } from "../context/config.js"; import { useAccountDetails } from "../hooks/access.js"; import { useBackendState } from "../hooks/backend.js"; -import { buildRequestErrorMessage, undefinedIfEmpty } from "../utils.js"; +import { buildRequestErrorMessage, undefinedIfEmpty, withRuntimeErrorHandling } from "../utils.js"; import { assertUnreachable } from "./HomePage.js"; import { LoginForm } from "./LoginForm.js"; import { AccountForm } from "./admin/AccountForm.js"; @@ -49,50 +49,41 @@ export function ShowAccountDetails({ async function doUpdate() { if (!update) { setUpdate(true); - } else { - if (!submitAccount || !creds) return; - try { - const resp = await api.updateAccount(creds, { - cashout_address: submitAccount.cashout_payto_uri, - challenge_contact_data: undefinedIfEmpty({ - email: submitAccount.contact_data?.email, - phone: submitAccount.contact_data?.phone, - }), - is_exchange: false, - name: submitAccount.name, - }); - if (resp.type === "ok") { - onUpdateSuccess(); - } else { - switch (resp.case) { - case "unauthorized": return notify({ - type: "error", - title: i18n.str`The rights to change the account are not sufficient`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - }) - case "not-found": return notify({ - type: "error", - title: i18n.str`The username was not found`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - }) - default: assertUnreachable(resp) - } - } - } catch (error) { - if (error instanceof TalerError) { - notify(buildRequestErrorMessage(i18n, error)) - } else { - notifyError( - i18n.str`Operation failed, please report`, - (error instanceof Error - ? error.message - : JSON.stringify(error)) as TranslatedString - ) + return; + } + if (!submitAccount || !creds) return; + await withRuntimeErrorHandling(i18n, async () => { + const resp = await api.updateAccount(creds, { + cashout_address: submitAccount.cashout_payto_uri, + challenge_contact_data: undefinedIfEmpty({ + email: submitAccount.contact_data?.email, + phone: submitAccount.contact_data?.phone, + }), + is_exchange: false, + name: submitAccount.name, + }); + + if (resp.type === "ok") { + onUpdateSuccess(); + } else { + switch (resp.case) { + case "unauthorized": return notify({ + type: "error", + title: i18n.str`The rights to change the account are not sufficient`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + case "not-found": return notify({ + type: "error", + title: i18n.str`The username was not found`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + default: assertUnreachable(resp) } } - } + }) + } return ( |