Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit ac9b9ab

Browse files
authored
Handle additional swapper errors in errorInfoAction (#1634)
* Handle additional swapper errors in errorInfoAction Extended errorInfoAction to handle InputAmountError by applying the minimum amount to the input model. Added applyMinAmount helper to update the input field based on the error context. * Add 'Use Minimum Amount' button for swap errors Introduces a localized 'Use Minimum Amount' button to the swap error section when the input amount is below the minimum. Updates SwapScene and SwapSceneViewModel to support the new action and adds translations for the button in all supported languages.
1 parent 28c46f7 commit ac9b9ab

34 files changed

Lines changed: 106 additions & 36 deletions

Features/Swap/Sources/Scenes/SwapScene.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,17 @@ public struct SwapScene: View {
2626
}
2727

2828
if let error = model.swapState.error {
29-
ListItemErrorView(errorTitle: model.errorTitle, error: error.asAnyError(asset: model.fromAsset?.asset), infoAction: model.errorInfoAction)
29+
Section {
30+
ListItemErrorView(
31+
errorTitle: model.errorTitle,
32+
error: error.asAnyError(asset: model.fromAsset?.asset),
33+
infoAction: model.errorInfoAction
34+
)
35+
if let title = model.errorInfoActionButtonTitle, let action = model.errorInfoAction {
36+
Button(title, action: action)
37+
.foregroundStyle(Colors.blue)
38+
}
39+
}
3040
}
3141
}
3242
.listSectionSpacing(.compact)

Features/Swap/Sources/ViewModels/SwapSceneViewModel.swift

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,34 @@ public final class SwapSceneViewModel {
125125
}
126126

127127
var errorInfoAction: VoidAction {
128-
guard case .error(let error) = swapState.quotes, error.swapperError == .NoQuoteAvailable else {
128+
guard case .error(let error) = swapState.quotes, let swapperError = error.swapperError else {
129129
return nil
130130
}
131-
132-
return VoidAction { [weak self] in
133-
self?.isPresentingInfoSheet = .info(.noQuote)
131+
132+
switch swapperError {
133+
case .NoQuoteAvailable:
134+
return VoidAction { [weak self] in
135+
self?.isPresentingInfoSheet = .info(.noQuote)
136+
}
137+
case .InputAmountError(let minAmount):
138+
guard let minAmount, let fromAsset else { return nil }
139+
return VoidAction { [weak self] in
140+
self?.applyMinAmount(minAmount, asset: fromAsset.asset)
141+
}
142+
default:
143+
return nil
144+
}
145+
}
146+
147+
var errorInfoActionButtonTitle: String? {
148+
guard case .error(let error) = swapState.quotes else {
149+
return nil
150+
}
151+
switch error.swapperError {
152+
case .InputAmountError:
153+
return Localized.Swap.useMinimumAmount
154+
default:
155+
return nil
134156
}
135157
}
136158

@@ -304,6 +326,11 @@ extension SwapSceneViewModel {
304326
)
305327
}
306328

329+
private func applyMinAmount(_ minAmount: String, asset: Asset) {
330+
guard let value = BigInt(minAmount) else { return }
331+
amountInputModel.text = formatter.format(value: value, decimals: asset.decimals.asInt)
332+
}
333+
307334
private func swap() {
308335
guard let fromAsset = fromAsset, let toAsset = toAsset, let quote = selectedSwapQuote else {
309336
return

Packages/Localization/Sources/Localized.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,8 @@ public enum Localized {
13821382
}
13831383
/// Slippage
13841384
public static let slippage = Localized.tr("Localizable", "swap.slippage", fallback: "Slippage")
1385+
/// Use Minimum Amount
1386+
public static let useMinimumAmount = Localized.tr("Localizable", "swap.use_minimum_amount", fallback: "Use Minimum Amount")
13851387
/// You Pay
13861388
public static let youPay = Localized.tr("Localizable", "swap.you_pay", fallback: "You Pay")
13871389
/// You Receive

Packages/Localization/Sources/Resources/ar.lproj/Localizable.strings

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,5 @@
580580
"perpetual.account_leverage" = "الاستفادة من الحساب";
581581
"asset.all_time_high" = "أعلى مستوى على الإطلاق";
582582
"asset.all_time_low" = "أدنى مستوى على الإطلاق";
583-
"errors.swap.minimum_amount" = "الحد الأدنى لمبلغ التداول هو %@يرجى إدخال مبلغ أعلى.";
583+
"errors.swap.minimum_amount" = "الحد الأدنى لمبلغ التداول هو %@يرجى إدخال مبلغ أعلى.";
584+
"swap.use_minimum_amount" = "استخدم الحد الأدنى من الكمية";

Packages/Localization/Sources/Resources/bn.lproj/Localizable.strings

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,5 @@
580580
"perpetual.account_leverage" = "অ্যাকাউন্ট লিভারেজ";
581581
"asset.all_time_high" = "সর্বকালের সর্বোচ্চ";
582582
"asset.all_time_low" = "সর্বকালের সর্বনিম্ন";
583-
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
583+
"errors.swap.minimum_amount" = "সর্বনিম্ন ট্রেডের পরিমাণ হল %@. অনুগ্রহ করে আরও বেশি পরিমাণ লিখুন।";
584+
"swap.use_minimum_amount" = "সর্বনিম্ন পরিমাণ ব্যবহার করুন";

Packages/Localization/Sources/Resources/cs.lproj/Localizable.strings

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,5 @@
580580
"perpetual.account_leverage" = "Pákový efekt účtu";
581581
"asset.all_time_high" = "Historické maximum";
582582
"asset.all_time_low" = "Historické minimum";
583-
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
583+
"errors.swap.minimum_amount" = "Minimální částka obchodu je %@Zadejte prosím vyšší částku.";
584+
"swap.use_minimum_amount" = "Použijte minimální množství";

Packages/Localization/Sources/Resources/da.lproj/Localizable.strings

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,5 @@
580580
"perpetual.account_leverage" = "Kontogearing";
581581
"asset.all_time_high" = "Alle tiders højder";
582582
"asset.all_time_low" = "Laveste niveau nogensinde";
583-
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
583+
"errors.swap.minimum_amount" = "Minimumsbeløbet for handel er %@Indtast venligst et højere beløb.";
584+
"swap.use_minimum_amount" = "Brug minimumsbeløb";

Packages/Localization/Sources/Resources/de.lproj/Localizable.strings

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,5 @@
580580
"perpetual.account_leverage" = "Kontohebel";
581581
"asset.all_time_high" = "Allzeithoch";
582582
"asset.all_time_low" = "Allzeittief";
583-
"errors.swap.minimum_amount" = "Der Mindesthandelsbetrag beträgt %@Bitte geben Sie einen höheren Betrag ein.";
583+
"errors.swap.minimum_amount" = "Der Mindesthandelsbetrag beträgt %@Bitte geben Sie einen höheren Betrag ein.";
584+
"swap.use_minimum_amount" = "Mindestmenge verwenden";

Packages/Localization/Sources/Resources/en.lproj/Localizable.strings

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,5 @@
580580
"perpetual.account_leverage" = "Account Leverage";
581581
"asset.all_time_high" = "All Time High";
582582
"asset.all_time_low" = "All Time Low";
583-
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
583+
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
584+
"swap.use_minimum_amount" = "Use Minimum Amount";

Packages/Localization/Sources/Resources/es.lproj/Localizable.strings

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,5 @@
580580
"perpetual.account_leverage" = "Apalancamiento de la cuenta";
581581
"asset.all_time_high" = "Máximo histórico";
582582
"asset.all_time_low" = "Mínimo histórico";
583-
"errors.swap.minimum_amount" = "La cantidad mínima de operación es %@. Introduce una cantidad mayor.";
583+
"errors.swap.minimum_amount" = "La cantidad mínima de operación es %@. Introduce una cantidad mayor.";
584+
"swap.use_minimum_amount" = "Utilice la cantidad mínima";

0 commit comments

Comments
 (0)