From c7b3d5dbeaeb7bdb51ab7c3254b2147128c85772 Mon Sep 17 00:00:00 2001 From: Sam Holmes Date: Fri, 16 Aug 2024 13:12:09 -0700 Subject: [PATCH] Add handling for exceeds_quota Bity errors --- CHANGELOG.md | 3 ++- src/locales/en_US.ts | 1 + src/locales/strings/enUS.json | 1 + src/plugins/gui/providers/bityProvider.ts | 21 ++++++++++++++++++--- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 163dde58f01..2aa9d4f9f82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,9 @@ ## 4.11.0 -- added: Kado buy via wire transfer - added: Allow for Maestro specific iOS and Android builds +- added: Handle KYC error responses from Bity +- added: Kado buy via wire transfer - changed: Use partners API to determine US state support for Mooopay, Simplex, and Banxa - changed: Conditionalize use of Paybis promoCodes for new users <$1k purchases - changed: Cache exchange rates for five minutes to account for server or connection instability diff --git a/src/locales/en_US.ts b/src/locales/en_US.ts index b36dd1796dd..fd974a7ad46 100644 --- a/src/locales/en_US.ts +++ b/src/locales/en_US.ts @@ -1131,6 +1131,7 @@ const strings = { error_boundary_message2: "If the problem persists, tap below to contact us, and we'll do our best to fix the problem.", error_boundary_help_button: 'Help Closing App', error_unexpected_title: 'Unexpected Error', + error_kyc_required_s: 'KYC required: %s', export_transaction_date_range: 'Date Range', export_transaction_export_type: 'Export Type', diff --git a/src/locales/strings/enUS.json b/src/locales/strings/enUS.json index 63458ef9f29..398e0c8f5af 100644 --- a/src/locales/strings/enUS.json +++ b/src/locales/strings/enUS.json @@ -1008,6 +1008,7 @@ "error_boundary_message2": "If the problem persists, tap below to contact us, and we'll do our best to fix the problem.", "error_boundary_help_button": "Help Closing App", "error_unexpected_title": "Unexpected Error", + "error_kyc_required_s": "KYC required: %s", "export_transaction_date_range": "Date Range", "export_transaction_export_type": "Export Type", "export_transaction_this_month": "This Month", diff --git a/src/plugins/gui/providers/bityProvider.ts b/src/plugins/gui/providers/bityProvider.ts index 67051a608dc..b0e7ee01424 100644 --- a/src/plugins/gui/providers/bityProvider.ts +++ b/src/plugins/gui/providers/bityProvider.ts @@ -85,7 +85,8 @@ const asBityCurrency = asObject({ }) const asBityCurrencyResponse = asObject({ currencies: asArray(asBityCurrency) }) -const asBityErrorResponse = asObject({ errors: asArray(asObject({ code: asString, message: asString })) }) +const asBityError = asObject({ code: asString, message: asString }) +const asBityErrorResponse = asObject({ errors: asArray(asBityError) }) // const asCurrencyAmount = asObject({ // amount: asString, @@ -220,6 +221,14 @@ const asBityApproveQuoteResponse = asEither(asBityBuyApproveQuoteResponse, asBit type BityApproveQuoteResponse = ReturnType +class BityError extends Error { + code: string + constructor(message: string, code: string) { + super(message) + this.code = code + } +} + const fetchBityQuote = async (bodyData: BityQuoteRequest) => { const request = { method: 'POST', @@ -243,7 +252,7 @@ const fetchBityQuote = async (bodyData: BityQuoteRequest) => { // is a required FiatProviderQuoteError param. throw new Error('Bity: Unable to fetch quote: ' + (await result.text())) } - if (bityErrorRes.errors.some((bityError: { code: string; message: string }) => bityError.code === 'amount_too_large')) { + if (bityErrorRes.errors.some(bityError => bityError.code === 'amount_too_large')) { throw new FiatProviderError({ providerId, errorType: 'overLimit' }) } } @@ -272,7 +281,7 @@ const approveBityQuote = async ( if (orderRes.status !== 201) { const errorData = await orderRes.json() - throw new Error(errorData.errors[0].code + ' ' + errorData.errors[0].message) + throw new BityError(errorData.errors[0].message, errorData.errors[0].code) } // "location": "https://...bity.com/v2/orders/[orderid]" const locationHeader = orderRes.headers.get('Location') @@ -560,6 +569,12 @@ export const bityProvider: FiatProviderFactory = { // their personal info depending on what was wrong with the // order, i.e. invalid bank or address info. console.error('Bity order error: ', e) + + const bityError = asMaybe(asBityError)(e) + if (bityError?.code === 'exceeds_quota') { + await showUi.showError(sprintf(lstrings.error_kyc_required_s, bityError.message)) + return + } await showUi.showError(lstrings.error_unexpected_title) }