diff options
author | Sebastian <sebasjm@gmail.com> | 2024-01-10 14:25:39 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-01-10 14:25:39 -0300 |
commit | 2c7db170a45fcb82deae3892d610b6b2805ee46c (patch) | |
tree | 09a4218a05e18784e3dfb2dfe211836185769924 /packages/demobank-ui | |
parent | b609f48ae664618b6f4e75e42221f1240c8f61f0 (diff) | |
download | wallet-core-2c7db170a45fcb82deae3892d610b6b2805ee46c.tar.xz |
bank: handles 2fa response
Diffstat (limited to 'packages/demobank-ui')
9 files changed, 197 insertions, 98 deletions
diff --git a/packages/demobank-ui/src/pages/OperationState/views.tsx b/packages/demobank-ui/src/pages/OperationState/views.tsx index a02bb3bbd..98eb7169f 100644 --- a/packages/demobank-ui/src/pages/OperationState/views.tsx +++ b/packages/demobank-ui/src/pages/OperationState/views.tsx @@ -96,45 +96,52 @@ export function NeedConfirmationView({ error, onAbort: doAbort, onConfirm: doCon async function onConfirm() { errorHandler(async () => { if (!doConfirm) return; - const hasError = await doConfirm() - if (!hasError) { + const resp = await doConfirm() + if (!resp) { if (!settings.showWithdrawalSuccess) { notifyInfo(i18n.str`Wire transfer completed!`) } return } - switch (hasError.case) { + switch (resp.case) { case TalerErrorCode.BANK_CONFIRM_ABORT_CONFLICT: return notify({ type: "error", title: i18n.str`The withdrawal has been aborted previously and can't be confirmed`, - description: hasError.detail.hint as TranslatedString, - debug: hasError.detail, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, }) case TalerErrorCode.BANK_CONFIRM_INCOMPLETE: return notify({ type: "error", title: i18n.str`The withdraw operation cannot be confirmed because no exchange and reserve public key selection happened before`, - description: hasError.detail.hint as TranslatedString, - debug: hasError.detail, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, }) case HttpStatusCode.BadRequest: return notify({ type: "error", title: i18n.str`The operation id is invalid.`, - description: hasError.detail.hint as TranslatedString, - debug: hasError.detail, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, }); case HttpStatusCode.NotFound: return notify({ type: "error", title: i18n.str`The operation was not found.`, - description: hasError.detail.hint as TranslatedString, - debug: hasError.detail, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, }); case TalerErrorCode.BANK_UNALLOWED_DEBIT: return notify({ type: "error", title: i18n.str`Your balance is not enough.`, - description: hasError.detail.hint as TranslatedString, - debug: hasError.detail, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, }); - default: assertUnreachable(hasError) + case HttpStatusCode.Accepted: { + resp.body.challenge_id; + return notify({ + type: "info", + title: i18n.str`The operation needs a confirmation to complete.`, + }); + } + default: assertUnreachable(resp) } }) } diff --git a/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx b/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx index 7a94f5486..2ef93d35c 100644 --- a/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx +++ b/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx @@ -146,50 +146,57 @@ export function PaytoWireTransferForm({ const puri = payto_uri; await handleError(async () => { - const res = await api.createTransaction(credentials, { + const resp = await api.createTransaction(credentials, { payto_uri: puri, amount: sendingAmount, }); mutate(() => true) - if (res.type === "fail") { - switch (res.case) { + if (resp.type === "fail") { + switch (resp.case) { case HttpStatusCode.BadRequest: return notify({ type: "error", title: i18n.str`The request was invalid or the payto://-URI used unacceptable features.`, - description: res.detail.hint as TranslatedString, - debug: res.detail, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, }) case HttpStatusCode.Unauthorized: return notify({ type: "error", title: i18n.str`Not enough permission to complete the operation.`, - description: res.detail.hint as TranslatedString, - debug: res.detail, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, }) case TalerErrorCode.BANK_UNKNOWN_CREDITOR: return notify({ type: "error", title: i18n.str`The destination account "${puri}" was not found.`, - description: res.detail.hint as TranslatedString, - debug: res.detail, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, }) case TalerErrorCode.BANK_SAME_ACCOUNT: return notify({ type: "error", title: i18n.str`The origin and the destination of the transfer can't be the same.`, - description: res.detail.hint as TranslatedString, - debug: res.detail, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, }) case TalerErrorCode.BANK_UNALLOWED_DEBIT: return notify({ type: "error", title: i18n.str`Your balance is not enough.`, - description: res.detail.hint as TranslatedString, - debug: res.detail, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, }) case HttpStatusCode.NotFound: return notify({ type: "error", title: i18n.str`The origin account "${puri}" was not found.`, - description: res.detail.hint as TranslatedString, - debug: res.detail, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, }) - default: assertUnreachable(res) + case HttpStatusCode.Accepted: { + resp.body.challenge_id; + return notify({ + type: "info", + title: i18n.str`The operation needs a confirmation to complete.`, + }); + } + default: assertUnreachable(resp) } } onSuccess(); diff --git a/packages/demobank-ui/src/pages/RegistrationPage.tsx b/packages/demobank-ui/src/pages/RegistrationPage.tsx index 89bfbcb35..e7ed8a2b8 100644 --- a/packages/demobank-ui/src/pages/RegistrationPage.tsx +++ b/packages/demobank-ui/src/pages/RegistrationPage.tsx @@ -98,78 +98,101 @@ function RegistrationForm({ onComplete, onCancel }: { onComplete: () => void, on async function doRegistrationAndLogin(name: string, username: string, password: string, onComplete: () => void) { await handleError(async () => { - const creationResponse = await api.createAccount("" as AccessToken, { name, username, password }); - if (creationResponse.type === "fail") { - switch (creationResponse.case) { - case HttpStatusCode.BadRequest: return notify({ - type: "error", - title: i18n.str`Server replied with invalid phone or email.`, - description: creationResponse.detail.hint as TranslatedString, - debug: creationResponse.detail, - }) - case TalerErrorCode.BANK_UNALLOWED_DEBIT: return notify({ - type: "error", - title: i18n.str`Registration is disabled because the bank ran out of bonus credit.`, - description: creationResponse.detail.hint as TranslatedString, - debug: creationResponse.detail, - }) - case HttpStatusCode.Unauthorized: return notify({ - type: "error", - title: i18n.str`No enough permission to create that account.`, - description: creationResponse.detail.hint as TranslatedString, - debug: creationResponse.detail, - }) - case TalerErrorCode.BANK_REGISTER_PAYTO_URI_REUSE: return notify({ - type: "error", - title: i18n.str`That account id is already taken.`, - description: creationResponse.detail.hint as TranslatedString, - debug: creationResponse.detail, - }) - case TalerErrorCode.BANK_REGISTER_USERNAME_REUSE: return notify({ - type: "error", - title: i18n.str`That username is already taken.`, - description: creationResponse.detail.hint as TranslatedString, - debug: creationResponse.detail, - }) - case TalerErrorCode.BANK_RESERVED_USERNAME_CONFLICT: return notify({ - type: "error", - title: i18n.str`That username can't be used because is reserved.`, - description: creationResponse.detail.hint as TranslatedString, - debug: creationResponse.detail, - }) - case TalerErrorCode.BANK_NON_ADMIN_PATCH_DEBT_LIMIT: return notify({ - type: "error", - title: i18n.str`Only admin is allow to set debt limit.`, - description: creationResponse.detail.hint as TranslatedString, - debug: creationResponse.detail, - }) - default: assertUnreachable(creationResponse) + createAccount: { + const resp = await api.createAccount("" as AccessToken, { name, username, password }); + if (resp.type === "fail") { + switch (resp.case) { + case HttpStatusCode.BadRequest: return notify({ + type: "error", + title: i18n.str`Server replied with invalid phone or email.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + case TalerErrorCode.BANK_UNALLOWED_DEBIT: return notify({ + type: "error", + title: i18n.str`Registration is disabled because the bank ran out of bonus credit.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + case HttpStatusCode.Unauthorized: return notify({ + type: "error", + title: i18n.str`No enough permission to create that account.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + case TalerErrorCode.BANK_REGISTER_PAYTO_URI_REUSE: return notify({ + type: "error", + title: i18n.str`That account id is already taken.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + case TalerErrorCode.BANK_REGISTER_USERNAME_REUSE: return notify({ + type: "error", + title: i18n.str`That username is already taken.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + case TalerErrorCode.BANK_RESERVED_USERNAME_CONFLICT: return notify({ + type: "error", + title: i18n.str`That username can't be used because is reserved.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + case TalerErrorCode.BANK_NON_ADMIN_PATCH_DEBT_LIMIT: return notify({ + type: "error", + title: i18n.str`Only admin is allow to set debt limit.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + case TalerErrorCode.BANK_MISSING_TAN_INFO: return notify({ + type: "error", + title: i18n.str`No information for the selected authentication channel.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + case TalerErrorCode.BANK_TAN_CHANNEL_NOT_SUPPORTED: return notify({ + type: "error", + title: i18n.str`Authentication channel is not supported.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + case TalerErrorCode.BANK_NON_ADMIN_SET_TAN_CHANNEL: return notify({ + type: "error", + title: i18n.str`Only admin can create accounts with second factor authentication.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + default: assertUnreachable(resp) + } } } - const resp = await api.getAuthenticationAPI(username).createAccessToken(password, { - scope: "readwrite", - duration: { d_us: "forever" }, - refreshable: true, - }) + login: { + const resp = await api.getAuthenticationAPI(username).createAccessToken(password, { + scope: "readwrite", + duration: { d_us: "forever" }, + 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) + 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) + } } + } onComplete() }) diff --git a/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx b/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx index ed1db854a..6f18e1283 100644 --- a/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx +++ b/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx @@ -153,6 +153,13 @@ export function WithdrawalConfirmationQuestion({ description: resp.detail.hint as TranslatedString, debug: resp.detail, }) + case HttpStatusCode.Accepted: { + resp.body.challenge_id; + return notify({ + type: "info", + title: i18n.str`The operation needs a confirmation to complete.`, + }); + } default: assertUnreachable(resp) } } diff --git a/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx b/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx index 98fb72283..1bf21f62e 100644 --- a/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx +++ b/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx @@ -96,6 +96,21 @@ export function ShowAccountDetails({ description: resp.detail.hint as TranslatedString, debug: resp.detail, }) + case HttpStatusCode.Accepted: { + resp.body.challenge_id; + return notify({ + type: "info", + title: i18n.str`Cashout created but confirmation is required.`, + }); + } + case TalerErrorCode.BANK_TAN_CHANNEL_NOT_SUPPORTED: { + return notify({ + type: "error", + title: i18n.str`Authentication channel is not supported.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }); + } default: assertUnreachable(resp) } } diff --git a/packages/demobank-ui/src/pages/account/UpdateAccountPassword.tsx b/packages/demobank-ui/src/pages/account/UpdateAccountPassword.tsx index 95c425dc7..ed074b9c4 100644 --- a/packages/demobank-ui/src/pages/account/UpdateAccountPassword.tsx +++ b/packages/demobank-ui/src/pages/account/UpdateAccountPassword.tsx @@ -74,6 +74,13 @@ export function UpdateAccountPassword({ type: "error", title: i18n.str`Your current password doesn't match, can't change to a new password.` }) + case HttpStatusCode.Accepted: { + resp.body.challenge_id; + return notify({ + type: "info", + title: i18n.str`Cashout created but confirmation is required.`, + }); + } default: assertUnreachable(resp) } } diff --git a/packages/demobank-ui/src/pages/admin/CreateNewAccount.tsx b/packages/demobank-ui/src/pages/admin/CreateNewAccount.tsx index d6b7d5b1e..1cfbd8234 100644 --- a/packages/demobank-ui/src/pages/admin/CreateNewAccount.tsx +++ b/packages/demobank-ui/src/pages/admin/CreateNewAccount.tsx @@ -90,6 +90,24 @@ export function CreateNewAccount({ description: resp.detail.hint as TranslatedString, debug: resp.detail, }) + case TalerErrorCode.BANK_MISSING_TAN_INFO: return notify({ + type: "error", + title: i18n.str`No information for the selected authentication channel.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + case TalerErrorCode.BANK_TAN_CHANNEL_NOT_SUPPORTED: return notify({ + type: "error", + title: i18n.str`Authentication channel is not supported.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + case TalerErrorCode.BANK_NON_ADMIN_SET_TAN_CHANNEL: return notify({ + type: "error", + title: i18n.str`Only admin can create accounts with second factor authentication.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) default: assertUnreachable(resp) } } diff --git a/packages/demobank-ui/src/pages/admin/RemoveAccount.tsx b/packages/demobank-ui/src/pages/admin/RemoveAccount.tsx index d47f48dd9..330ebf3a9 100644 --- a/packages/demobank-ui/src/pages/admin/RemoveAccount.tsx +++ b/packages/demobank-ui/src/pages/admin/RemoveAccount.tsx @@ -89,6 +89,13 @@ export function RemoveAccount({ description: resp.detail.hint as TranslatedString, debug: resp.detail, }) + case HttpStatusCode.Accepted: { + resp.body.challenge_id; + return notify({ + type: "info", + title: i18n.str`The operation needs a confirmation to complete.`, + }); + } default: { assertUnreachable(resp) } diff --git a/packages/demobank-ui/src/pages/business/CreateCashout.tsx b/packages/demobank-ui/src/pages/business/CreateCashout.tsx index c3921cbd0..9ee5cbeaf 100644 --- a/packages/demobank-ui/src/pages/business/CreateCashout.tsx +++ b/packages/demobank-ui/src/pages/business/CreateCashout.tsx @@ -16,6 +16,7 @@ import { Amounts, HttpStatusCode, + TalerCorebankApi, TalerError, TalerErrorCode, TranslatedString, @@ -197,6 +198,13 @@ export function CreateCashout({ notifyInfo(i18n.str`Cashout created`) } else { switch (resp.case) { + case HttpStatusCode.Accepted: { + resp.body.challenge_id; + return notify({ + type: "info", + title: i18n.str`Cashout created but confirmation is required.`, + }); + } case HttpStatusCode.NotFound: return notify({ type: "error", title: i18n.str`Account not found`, |