Skip to content

Commit

Permalink
Add handling for exceeds_quota Bity errors
Browse files Browse the repository at this point in the history
  • Loading branch information
samholmes committed Aug 19, 2024
1 parent e60f6d6 commit c7b3d5d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/locales/strings/enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 18 additions & 3 deletions src/plugins/gui/providers/bityProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -220,6 +221,14 @@ const asBityApproveQuoteResponse = asEither(asBityBuyApproveQuoteResponse, asBit

type BityApproveQuoteResponse = ReturnType<typeof asBityApproveQuoteResponse>

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',
Expand All @@ -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' })
}
}
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit c7b3d5d

Please sign in to comment.