Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Features/Swap/Sources/Scenes/SwapScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ public struct SwapScene: View {
}

if let error = model.swapState.error {
ListItemErrorView(errorTitle: model.errorTitle, error: error.asAnyError(asset: model.fromAsset?.asset), infoAction: model.errorInfoAction)
Section {
ListItemErrorView(
errorTitle: model.errorTitle,
error: error.asAnyError(asset: model.fromAsset?.asset),
infoAction: model.errorInfoAction
)
if let title = model.errorInfoActionButtonTitle, let action = model.errorInfoAction {
Button(title, action: action)
.foregroundStyle(Colors.blue)
}
}
}
}
.listSectionSpacing(.compact)
Expand Down
35 changes: 31 additions & 4 deletions Features/Swap/Sources/ViewModels/SwapSceneViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,34 @@ public final class SwapSceneViewModel {
}

var errorInfoAction: VoidAction {
guard case .error(let error) = swapState.quotes, error.swapperError == .NoQuoteAvailable else {
guard case .error(let error) = swapState.quotes, let swapperError = error.swapperError else {
return nil
}

return VoidAction { [weak self] in
self?.isPresentingInfoSheet = .info(.noQuote)

switch swapperError {
case .NoQuoteAvailable:
return VoidAction { [weak self] in
self?.isPresentingInfoSheet = .info(.noQuote)
}
case .InputAmountError(let minAmount):
guard let minAmount, let fromAsset else { return nil }
return VoidAction { [weak self] in
self?.applyMinAmount(minAmount, asset: fromAsset.asset)
}
Comment on lines +137 to +141
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve robustness and avoid creating a VoidAction that does nothing if minAmount is not a valid number, it's better to parse minAmount into a BigInt here. This ensures that the action is only available when it's guaranteed to work.

You can then pass the BigInt value directly to applyMinAmount, which simplifies that function as well. I'll leave a corresponding suggestion on applyMinAmount.

Suggested change
case .InputAmountError(let minAmount):
guard let minAmount, let fromAsset else { return nil }
return VoidAction { [weak self] in
self?.applyMinAmount(minAmount, asset: fromAsset.asset)
}
case .InputAmountError(let minAmount):
guard let minAmount, let value = BigInt(minAmount), let fromAsset else { return nil }
return VoidAction { [weak self] in
self?.applyMinAmount(value, asset: fromAsset.asset)
}

default:
return nil
}
}

var errorInfoActionButtonTitle: String? {
guard case .error(let error) = swapState.quotes else {
return nil
}
switch error.swapperError {
case .InputAmountError:
return Localized.Swap.useMinimumAmount
default:
return nil
}
}

Expand Down Expand Up @@ -304,6 +326,11 @@ extension SwapSceneViewModel {
)
}

private func applyMinAmount(_ minAmount: String, asset: Asset) {
guard let value = BigInt(minAmount) else { return }
amountInputModel.text = formatter.format(value: value, decimals: asset.decimals.asInt)
}
Comment on lines +329 to +332
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Following the suggestion to parse minAmount in errorInfoAction, this function can be simplified to accept a BigInt directly. This makes the function's responsibility clearer and removes the need for failable string parsing within it.

    private func applyMinAmount(_ value: BigInt, asset: Asset) {
        amountInputModel.text = formatter.format(value: value, decimals: asset.decimals.asInt)
    }


private func swap() {
guard let fromAsset = fromAsset, let toAsset = toAsset, let quote = selectedSwapQuote else {
return
Expand Down
2 changes: 2 additions & 0 deletions Packages/Localization/Sources/Localized.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,8 @@ public enum Localized {
}
/// Slippage
public static let slippage = Localized.tr("Localizable", "swap.slippage", fallback: "Slippage")
/// Use Minimum Amount
public static let useMinimumAmount = Localized.tr("Localizable", "swap.use_minimum_amount", fallback: "Use Minimum Amount")
/// You Pay
public static let youPay = Localized.tr("Localizable", "swap.you_pay", fallback: "You Pay")
/// You Receive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "الاستفادة من الحساب";
"asset.all_time_high" = "أعلى مستوى على الإطلاق";
"asset.all_time_low" = "أدنى مستوى على الإطلاق";
"errors.swap.minimum_amount" = "الحد الأدنى لمبلغ التداول هو %@يرجى إدخال مبلغ أعلى.";
"errors.swap.minimum_amount" = "الحد الأدنى لمبلغ التداول هو %@يرجى إدخال مبلغ أعلى.";
"swap.use_minimum_amount" = "استخدم الحد الأدنى من الكمية";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "অ্যাকাউন্ট লিভারেজ";
"asset.all_time_high" = "সর্বকালের সর্বোচ্চ";
"asset.all_time_low" = "সর্বকালের সর্বনিম্ন";
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
"errors.swap.minimum_amount" = "সর্বনিম্ন ট্রেডের পরিমাণ হল %@. অনুগ্রহ করে আরও বেশি পরিমাণ লিখুন।";
"swap.use_minimum_amount" = "সর্বনিম্ন পরিমাণ ব্যবহার করুন";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Pákový efekt účtu";
"asset.all_time_high" = "Historické maximum";
"asset.all_time_low" = "Historické minimum";
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
"errors.swap.minimum_amount" = "Minimální částka obchodu je %@Zadejte prosím vyšší částku.";
"swap.use_minimum_amount" = "Použijte minimální množství";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Kontogearing";
"asset.all_time_high" = "Alle tiders højder";
"asset.all_time_low" = "Laveste niveau nogensinde";
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
"errors.swap.minimum_amount" = "Minimumsbeløbet for handel er %@Indtast venligst et højere beløb.";
"swap.use_minimum_amount" = "Brug minimumsbeløb";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Kontohebel";
"asset.all_time_high" = "Allzeithoch";
"asset.all_time_low" = "Allzeittief";
"errors.swap.minimum_amount" = "Der Mindesthandelsbetrag beträgt %@Bitte geben Sie einen höheren Betrag ein.";
"errors.swap.minimum_amount" = "Der Mindesthandelsbetrag beträgt %@Bitte geben Sie einen höheren Betrag ein.";
"swap.use_minimum_amount" = "Mindestmenge verwenden";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Account Leverage";
"asset.all_time_high" = "All Time High";
"asset.all_time_low" = "All Time Low";
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
"swap.use_minimum_amount" = "Use Minimum Amount";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Apalancamiento de la cuenta";
"asset.all_time_high" = "Máximo histórico";
"asset.all_time_low" = "Mínimo histórico";
"errors.swap.minimum_amount" = "La cantidad mínima de operación es %@. Introduce una cantidad mayor.";
"errors.swap.minimum_amount" = "La cantidad mínima de operación es %@. Introduce una cantidad mayor.";
"swap.use_minimum_amount" = "Utilice la cantidad mínima";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "اهرم حساب";
"asset.all_time_high" = "بالاترین رکورد تمام دوران";
"asset.all_time_low" = "پایین‌ترین سطح تمام دوران";
"errors.swap.minimum_amount" = "حداقل مبلغ معامله %@لطفا مبلغ بیشتری وارد کنید.";
"errors.swap.minimum_amount" = "حداقل مبلغ معامله %@لطفا مبلغ بیشتری وارد کنید.";
"swap.use_minimum_amount" = "از حداقل مقدار استفاده کنید";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Leverage ng Account";
"asset.all_time_high" = "Mataas sa Lahat ng Panahon";
"asset.all_time_low" = "Mababa sa Lahat ng Panahon";
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
"errors.swap.minimum_amount" = "Ang minimum na halaga ng kalakalan ay %@Mangyaring maglagay ng mas mataas na halaga.";
"swap.use_minimum_amount" = "Gamitin ang Minimum na Halaga";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Effet de levier du compte";
"asset.all_time_high" = "Record absolu";
"asset.all_time_low" = "Plus bas historique";
"errors.swap.minimum_amount" = "Le montant minimum de transaction est %@Veuillez saisir un montant plus élevé.";
"errors.swap.minimum_amount" = "Le montant minimum de transaction est %@Veuillez saisir un montant plus élevé.";
"swap.use_minimum_amount" = "Utiliser le montant minimum";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Amfani da Asusu";
"asset.all_time_high" = "Babban Lokaci";
"asset.all_time_low" = "Ƙasa a Kowane Lokaci";
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
"errors.swap.minimum_amount" = "Mafi ƙarancin adadin ciniki shine %@. Da fatan a shigar da adadin da ya fi girma.";
"swap.use_minimum_amount" = "Yi amfani da Mafi ƙarancin Adadin";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "מינוף חשבון";
"asset.all_time_high" = "שיא כל הזמנים";
"asset.all_time_low" = "שפל של כל הזמנים";
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
"errors.swap.minimum_amount" = "סכום המסחר המינימלי הוא %@אנא הזן סכום גבוה יותר.";
"swap.use_minimum_amount" = "השתמש בסכום מינימלי";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "खाता उत्तोलन";
"asset.all_time_high" = "सर्वकालिक उच्च";
"asset.all_time_low" = "सबसे कम";
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
"errors.swap.minimum_amount" = "न्यूनतम व्यापार राशि है %@कृपया अधिक राशि दर्ज करें।";
"swap.use_minimum_amount" = "न्यूनतम राशि का प्रयोग करें";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Pemanfaatan Akun";
"asset.all_time_high" = "Tertinggi Sepanjang Masa";
"asset.all_time_low" = "Terendah Sepanjang Masa";
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
"errors.swap.minimum_amount" = "Jumlah transaksi minimum adalah %@Silakan masukkan jumlah yang lebih tinggi.";
"swap.use_minimum_amount" = "Gunakan Jumlah Minimum";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Leva finanziaria del conto";
"asset.all_time_high" = "Massimo storico";
"asset.all_time_low" = "Minimo storico";
"errors.swap.minimum_amount" = "L'importo minimo di scambio è %@Inserisci un importo maggiore.";
"errors.swap.minimum_amount" = "L'importo minimo di scambio è %@Inserisci un importo maggiore.";
"swap.use_minimum_amount" = "Utilizzare l'importo minimo";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "アカウントレバレッジ";
"asset.all_time_high" = "史上最高値";
"asset.all_time_low" = "オールタイムロー";
"errors.swap.minimum_amount" = "最低取引金額は %@より高い金額を入力してください。";
"errors.swap.minimum_amount" = "最低取引金額は %@より高い金額を入力してください。";
"swap.use_minimum_amount" = "最小量を使用する";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "계정 레버리지";
"asset.all_time_high" = "역대 최고";
"asset.all_time_low" = "역대 최저치";
"errors.swap.minimum_amount" = "최소 거래 금액은 %@더 높은 금액을 입력해 주세요.";
"errors.swap.minimum_amount" = "최소 거래 금액은 %@더 높은 금액을 입력해 주세요.";
"swap.use_minimum_amount" = "최소 금액을 사용하세요";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Leveraj Akaun";
"asset.all_time_high" = "Tertinggi Sepanjang Masa";
"asset.all_time_low" = "Rendah Sepanjang Masa";
"errors.swap.minimum_amount" = "Jumlah dagangan minimum ialah %@Sila masukkan jumlah yang lebih tinggi.";
"errors.swap.minimum_amount" = "Jumlah dagangan minimum ialah %@Sila masukkan jumlah yang lebih tinggi.";
"swap.use_minimum_amount" = "Gunakan Jumlah Minimum";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Accounthefboomwerking";
"asset.all_time_high" = "Hoogste ooit";
"asset.all_time_low" = "Laagste ooit";
"errors.swap.minimum_amount" = "Het minimale handelsbedrag is %@Voer een hoger bedrag in.";
"errors.swap.minimum_amount" = "Het minimale handelsbedrag is %@Voer een hoger bedrag in.";
"swap.use_minimum_amount" = "Gebruik de minimale hoeveelheid";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Dźwignia konta";
"asset.all_time_high" = "Najwyższy poziom wszech czasów";
"asset.all_time_low" = "Najniższy poziom wszech czasów";
"errors.swap.minimum_amount" = "Minimalna kwota transakcji wynosi %@. Proszę wprowadzić wyższą kwotę.";
"errors.swap.minimum_amount" = "Minimalna kwota transakcji wynosi %@. Proszę wprowadzić wyższą kwotę.";
"swap.use_minimum_amount" = "Użyj minimalnej kwoty";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Alavancagem da conta";
"asset.all_time_high" = "Maior de todos os tempos";
"asset.all_time_low" = "Mínima histórica";
"errors.swap.minimum_amount" = "O valor mínimo de transação é %@Por favor, insira um valor maior.";
"errors.swap.minimum_amount" = "O valor mínimo de transação é %@Por favor, insira um valor maior.";
"swap.use_minimum_amount" = "Use o valor mínimo";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Levierul contului";
"asset.all_time_high" = "Maxim istoric";
"asset.all_time_low" = "Minim istoric";
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
"errors.swap.minimum_amount" = "Suma minimă a tranzacției este %@Vă rugăm să introduceți o sumă mai mare.";
"swap.use_minimum_amount" = "Utilizați suma minimă";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Кредитное плечо счета";
"asset.all_time_high" = "Рекордный максимум за все время";
"asset.all_time_low" = "Рекордный минимум за все время";
"errors.swap.minimum_amount" = "Минимальная сумма сделки — %@. Введите, пожалуйста, сумму побольше.";
"errors.swap.minimum_amount" = "Минимальная сумма сделки — %@. Введите, пожалуйста, сумму побольше.";
"swap.use_minimum_amount" = "Использовать минимальное количество";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Ufaidi wa Akaunti";
"asset.all_time_high" = "Wakati Wote Juu";
"asset.all_time_low" = "Chini Wakati Wote";
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
"errors.swap.minimum_amount" = "Kiwango cha chini cha biashara ni %@Tafadhali weka kiasi cha juu zaidi.";
"swap.use_minimum_amount" = "Tumia Kiasi cha Chini Zaidi";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "การใช้ประโยชน์จากบัญชี";
"asset.all_time_high" = "สูงสุดตลอดกาล";
"asset.all_time_low" = "ออลไทม์โลว์";
"errors.swap.minimum_amount" = "จำนวนเงินขั้นต่ำในการซื้อขายคือ %@กรุณาป้อนจำนวนเงินที่สูงกว่านี้";
"errors.swap.minimum_amount" = "จำนวนเงินขั้นต่ำในการซื้อขายคือ %@กรุณาป้อนจำนวนเงินที่สูงกว่านี้";
"swap.use_minimum_amount" = "ใช้ในปริมาณน้อยที่สุด";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Hesap Kaldıraç";
"asset.all_time_high" = "Tüm Zamanların En Yüksek Seviyesi";
"asset.all_time_low" = "Tüm Zamanların En Düşük Seviyesi";
"errors.swap.minimum_amount" = "Minimum işlem tutarı %@. Lütfen daha yüksek bir tutar girin.";
"errors.swap.minimum_amount" = "Minimum işlem tutarı %@. Lütfen daha yüksek bir tutar girin.";
"swap.use_minimum_amount" = "Minimum Tutarı Kullanın";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Кредитне плече рахунку";
"asset.all_time_high" = "Рекордний максимум за весь час";
"asset.all_time_low" = "Найнижчий показник за весь час";
"errors.swap.minimum_amount" = "Мінімально дозволена сума угоди становить %@. Будь ласка, введіть більшу суму.";
"errors.swap.minimum_amount" = "Мінімально дозволена сума угоди становить %@. Будь ласка, введіть більшу суму.";
"swap.use_minimum_amount" = "Використовуйте мінімальну суму";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "اکاؤنٹ لیوریج";
"asset.all_time_high" = "آل ٹائم ہائی";
"asset.all_time_low" = "آل ٹائم لو";
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
"errors.swap.minimum_amount" = "کم از کم تجارتی رقم ہے۔ %@. براہ کرم زیادہ رقم درج کریں۔";
"swap.use_minimum_amount" = "کم سے کم رقم استعمال کریں۔";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "Tận dụng tài khoản";
"asset.all_time_high" = "Mức cao nhất mọi thời đại";
"asset.all_time_low" = "Mức thấp nhất mọi thời đại";
"errors.swap.minimum_amount" = "Minimum trade amount is %@. Please enter a higher amount.";
"errors.swap.minimum_amount" = "Số tiền giao dịch tối thiểu là %@Vui lòng nhập số tiền lớn hơn.";
"swap.use_minimum_amount" = "Sử dụng số lượng tối thiểu";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "账户杠杆";
"asset.all_time_high" = "历史最高点";
"asset.all_time_low" = "最低";
"errors.swap.minimum_amount" = "最低交易金额为 %@请输入更高的金额。";
"errors.swap.minimum_amount" = "最低交易金额为 %@请输入更高的金额。";
"swap.use_minimum_amount" = "使用最低金额";
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,5 @@
"perpetual.account_leverage" = "帳戶槓桿";
"asset.all_time_high" = "歷史最高點";
"asset.all_time_low" = "最低";
"errors.swap.minimum_amount" = "最低交易金額為 %@請輸入更高的金額。";
"errors.swap.minimum_amount" = "最低交易金額為 %@請輸入更高的金額。";
"swap.use_minimum_amount" = "使用最低金額";