aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/pages/OperationState/state.ts
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/OperationState/state.ts
parent9e925a2f56677600973c4659f82776a6a56339bb (diff)
downloadwallet-core-7582855e2723e11de25f10b6d5ba8a0757616765.tar.xz
some ui fixes
Diffstat (limited to 'packages/demobank-ui/src/pages/OperationState/state.ts')
-rw-r--r--packages/demobank-ui/src/pages/OperationState/state.ts58
1 files changed, 12 insertions, 46 deletions
diff --git a/packages/demobank-ui/src/pages/OperationState/state.ts b/packages/demobank-ui/src/pages/OperationState/state.ts
index 148571ec9..c9c1fa238 100644
--- a/packages/demobank-ui/src/pages/OperationState/state.ts
+++ b/packages/demobank-ui/src/pages/OperationState/state.ts
@@ -21,7 +21,7 @@ import { useBankCoreApiContext } from "../../context/config.js";
import { useWithdrawalDetails } from "../../hooks/access.js";
import { useBackendState } from "../../hooks/backend.js";
import { useSettings } from "../../hooks/settings.js";
-import { buildRequestErrorMessage } from "../../utils.js";
+import { buildRequestErrorMessage, withRuntimeErrorHandling } from "../../utils.js";
import { Props, State } from "./index.js";
import { assertUnreachable } from "../HomePage.js";
import { mutate } from "swr";
@@ -41,9 +41,8 @@ export function useComponentState({ currency, onClose }: Props): utils.Recursive
async function doSilentStart() {
//FIXME: if amount is not enough use balance
const parsedAmount = Amounts.parseOrThrow(`${currency}:${amount}`)
-
- try {
- if (!creds) return;
+ if (!creds) return;
+ await withRuntimeErrorHandling(i18n, async () => {
const resp = await api.createWithdrawal(creds, {
amount: Amounts.stringify(parsedAmount),
});
@@ -67,18 +66,7 @@ export function useComponentState({ currency, onClose }: Props): utils.Recursive
} else {
updateSettings("currentWithdrawalOperationId", uri.withdrawalOperationId)
}
- } 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
- )
- }
- }
+ })
}
const withdrawalOperationId = settings.currentWithdrawalOperationId
@@ -98,10 +86,9 @@ export function useComponentState({ currency, onClose }: Props): utils.Recursive
const wid = withdrawalOperationId
async function doAbort() {
- try {
- setBusy({})
+ setBusy({})
+ await withRuntimeErrorHandling(i18n, async () => {
const resp = await api.abortWithdrawalById(wid);
- setBusy(undefined)
if (resp.type === "ok") {
onClose();
} else {
@@ -115,30 +102,19 @@ export function useComponentState({ currency, onClose }: Props): utils.Recursive
default: assertUnreachable(resp.case)
}
}
- } 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
- )
- }
- }
+ })
+ setBusy(undefined)
}
async function doConfirm() {
- try {
- setBusy({})
+ setBusy({})
+ await withRuntimeErrorHandling(i18n, async () => {
const resp = await api.confirmWithdrawalById(wid);
if (resp.type === "ok") {
mutate(() => true)//clean withdrawal state
if (!settings.showWithdrawalSuccess) {
notifyInfo(i18n.str`Wire transfer completed!`)
}
- setBusy(undefined)
} else {
switch (resp.case) {
case "previously-aborted": return notify({
@@ -156,18 +132,8 @@ export function useComponentState({ currency, onClose }: Props): utils.Recursive
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
- )
- }
- }
+ })
+ setBusy(undefined)
}
const uri = stringifyWithdrawUri({