Skip to content

Commit fb6aca7

Browse files
author
Jon Tzeng
committed
Fix/extend minimum errors
- Show the selected crypto in the error - Add generic vendor error handling when no minimums are given
1 parent bff9da8 commit fb6aca7

3 files changed

Lines changed: 36 additions & 26 deletions

File tree

src/components/scenes/GiftCardPurchaseScene.tsx

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -366,22 +366,23 @@ export const GiftCardPurchaseScene: React.FC<Props> = props => {
366366

367367
const caip19 = tokenInfo.caip19
368368

369+
// Get currency code for display (used in warnings, success, and error messages)
370+
const currencyCode =
371+
tokenId != null
372+
? account.currencyConfig[wallet.currencyInfo.pluginId]?.allTokens[
373+
tokenId
374+
]?.currencyCode ?? wallet.currencyInfo.currencyCode
375+
: wallet.currencyInfo.currencyCode
376+
369377
// Check minimum amount for selected token
370378
if (selectedAmount < tokenInfo.minimumAmountInUSD) {
371-
const currencyCode =
372-
tokenId != null
373-
? account.currencyConfig[wallet.currencyInfo.pluginId]?.allTokens[
374-
tokenId
375-
]?.currencyCode ?? wallet.currencyInfo.currencyCode
376-
: wallet.currencyInfo.currencyCode
377-
378379
setMinimumWarning({
379380
header: sprintf(
380-
lstrings.gift_card_minimum_warning_header,
381+
lstrings.gift_card_minimum_warning_header_1s,
381382
currencyCode
382383
),
383384
footer: sprintf(
384-
lstrings.gift_card_minimum_warning_footer,
385+
lstrings.gift_card_minimum_warning_footer_1s,
385386
formatMinimumInBrandCurrency(tokenInfo.minimumAmountInUSD)
386387
)
387388
})
@@ -424,13 +425,6 @@ export const GiftCardPurchaseScene: React.FC<Props> = props => {
424425

425426
// Convert quantity to native amount (crypto amount to pay)
426427
// The quantity is in the token's standard units (e.g., BTC, ETH)
427-
const currencyCode =
428-
tokenId != null
429-
? account.currencyConfig[wallet.currencyInfo.pluginId]?.allTokens[
430-
tokenId
431-
]?.currencyCode ?? wallet.currencyInfo.currencyCode
432-
: wallet.currencyInfo.currencyCode
433-
434428
const multiplier =
435429
tokenId != null
436430
? account.currencyConfig[wallet.currencyInfo.pluginId]?.allTokens[
@@ -568,23 +562,36 @@ export const GiftCardPurchaseScene: React.FC<Props> = props => {
568562
return
569563
}
570564

571-
// Check for minimum amount error from API
565+
// Check for minimum amount error from API (with specific minimum)
572566
const minimumMatch = /Minimum cart cost should be above: ([\d.]+)/.exec(
573567
errorMessage
574568
)
575569

570+
// Check for generic "order too small" error (no specific minimum)
571+
const isGenericMinimumError = errorMessage.includes(
572+
'Order amount is too small'
573+
)
574+
576575
if (minimumMatch != null) {
577576
const minimumUSD = parseFloat(minimumMatch[1])
578577
setMinimumWarning({
579578
header: sprintf(
580-
lstrings.gift_card_minimum_warning_header,
581-
'this cryptocurrency'
579+
lstrings.gift_card_minimum_warning_header_1s,
580+
currencyCode
582581
),
583582
footer: sprintf(
584-
lstrings.gift_card_minimum_warning_footer,
583+
lstrings.gift_card_minimum_warning_footer_1s,
585584
formatMinimumInBrandCurrency(minimumUSD)
586585
)
587586
})
587+
} else if (isGenericMinimumError) {
588+
setMinimumWarning({
589+
header: sprintf(
590+
lstrings.gift_card_minimum_warning_header_1s,
591+
currencyCode
592+
),
593+
footer: lstrings.gift_card_minimum_warning_generic
594+
})
588595
} else {
589596
// Show ErrorCard for other errors
590597
setError(err)

src/locales/en_US.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,10 +1918,12 @@ const strings = {
19181918
gift_card_network_error:
19191919
'Unable to load gift cards. Please check your network connection.',
19201920
gift_card_minimum_warning_title: 'Below Minimum',
1921-
gift_card_minimum_warning_header:
1922-
'The selected amount is below the minimum for %s.',
1923-
gift_card_minimum_warning_footer:
1924-
'Please select a different payment method or increase your purchase amount to at least %s.',
1921+
gift_card_minimum_warning_header_1s:
1922+
'The selected amount is below the minimum for %1$s.',
1923+
gift_card_minimum_warning_footer_1s:
1924+
'Please select a different payment method or increase your purchase amount to at least %1$s.',
1925+
gift_card_minimum_warning_generic:
1926+
'The selected amount is too small for this cryptocurrency. Please select a different payment method or increase your purchase amount.',
19251927
gift_card_redeemed_cards: 'Redeemed Cards',
19261928
gift_card_unmark_as_redeemed: 'Unmark as Redeemed',
19271929
gift_card_active_cards: 'Active Cards',

src/locales/strings/enUS.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,8 +1491,9 @@
14911491
"gift_card_more_options": "Browse more gift cards",
14921492
"gift_card_network_error": "Unable to load gift cards. Please check your network connection.",
14931493
"gift_card_minimum_warning_title": "Below Minimum",
1494-
"gift_card_minimum_warning_header": "The selected amount is below the minimum for %s.",
1495-
"gift_card_minimum_warning_footer": "Please select a different payment method or increase your purchase amount to at least %s.",
1494+
"gift_card_minimum_warning_header_1s": "The selected amount is below the minimum for %1$s.",
1495+
"gift_card_minimum_warning_footer_1s": "Please select a different payment method or increase your purchase amount to at least %1$s.",
1496+
"gift_card_minimum_warning_generic": "The selected amount is too small for this cryptocurrency. Please select a different payment method or increase your purchase amount.",
14961497
"gift_card_redeemed_cards": "Redeemed Cards",
14971498
"gift_card_unmark_as_redeemed": "Unmark as Redeemed",
14981499
"gift_card_active_cards": "Active Cards",

0 commit comments

Comments
 (0)