From c67a0f2346a16e1c45da0889e9dec1069f70cedb Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Thu, 31 Jul 2025 20:39:26 +0300 Subject: [PATCH] minor fix [skip ci] --- lib/buy/buy_quote.dart | 34 +++++++++++++++---------- lib/entities/calculate_fiat_amount.dart | 6 ++--- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/lib/buy/buy_quote.dart b/lib/buy/buy_quote.dart index 42616659a..1e154de6b 100644 --- a/lib/buy/buy_quote.dart +++ b/lib/buy/buy_quote.dart @@ -75,10 +75,12 @@ class Quote extends SelectableOption { late FiatCurrency _fiatCurrency; late CryptoCurrency _cryptoCurrency; - bool get isSelected => _isSelected; + bool get isBestRate => _isBestRate; + FiatCurrency get fiatCurrency => _fiatCurrency; + CryptoCurrency get cryptoCurrency => _cryptoCurrency; @override @@ -96,15 +98,16 @@ class Quote extends SelectableOption { List get badges => recommendations.map((e) => e.title).toList(); @override - String get topLeftSubTitle => - this.rate > 0 ? '1 ${cryptoCurrency.toString()} = ${formatWithCommas(rate.toStringAsFixed(2))} ${fiatCurrency.toString()}' : ''; + String get topLeftSubTitle => this.rate > 0 + ? '1 ${cryptoCurrency.toString()} = ${formatWithCommas(rate.toStringAsFixed(2))} ${fiatCurrency.toString()}' + : ''; @override String get bottomLeftSubTitle { if (limits != null) { final min = limits!.min; final max = limits!.max; - return 'min: ${min} ${fiatCurrency.toString()} | max: ${max == double.infinity ? '' : '${max} ${fiatCurrency.toString()}'}'; + return 'min: ${formatWithCommas(min?.toString())} ${fiatCurrency.toString()} | max: ${max == double.infinity ? '' : '${formatWithCommas(max?.toString())} ${fiatCurrency.toString()}'}'; } return ''; } @@ -123,9 +126,13 @@ class Quote extends SelectableOption { String get formatedFee => '$feeAmount ${isBuyAction ? fiatCurrency : cryptoCurrency}'; set setIsSelected(bool isSelected) => _isSelected = isSelected; + set setIsBestRate(bool isBestRate) => _isBestRate = isBestRate; + set setFiatCurrency(FiatCurrency fiatCurrency) => _fiatCurrency = fiatCurrency; + set setCryptoCurrency(CryptoCurrency cryptoCurrency) => _cryptoCurrency = cryptoCurrency; + set setLimits(Limits limits) => this.limits = limits; factory Quote.fromOnramperJson(Map json, bool isBuyAction, @@ -185,7 +192,7 @@ class Quote extends SelectableOption { customPaymentMethodType: customPaymentMethodType, quoteId: json['quoteId'] as String? ?? '', recommendations: enumRecommendations, - provider: ProvidersHelper.getProviderByType(ProviderType.onramper)!, + provider: ProvidersHelper.getProviderByType(ProviderType.onramper), isBuyAction: isBuyAction, limits: Limits(min: minLimit, max: maxLimit), ); @@ -220,7 +227,7 @@ class Quote extends SelectableOption { paymentType: paymentType, recommendations: [], quoteId: json['signature'] as String? ?? '', - provider: ProvidersHelper.getProviderByType(ProviderType.moonpay)!, + provider: ProvidersHelper.getProviderByType(ProviderType.moonpay), isBuyAction: isBuyAction, limits: Limits(min: minLimit, max: maxLimit), ); @@ -245,7 +252,7 @@ class Quote extends SelectableOption { payout: _toDouble(json['payout']) ?? 0.0, paymentType: paymentType, recommendations: [ProviderRecommendation.lowKyc], - provider: ProvidersHelper.getProviderByType(ProviderType.dfx)!, + provider: ProvidersHelper.getProviderByType(ProviderType.dfx), isBuyAction: isBuyAction, limits: Limits(min: minVolume, max: maxVolume), ); @@ -267,7 +274,7 @@ class Quote extends SelectableOption { payout: _toDouble(json['cryptoAmount']) ?? 0.0, paymentType: paymentType, recommendations: [], - provider: ProvidersHelper.getProviderByType(ProviderType.robinhood)!, + provider: ProvidersHelper.getProviderByType(ProviderType.robinhood), isBuyAction: isBuyAction, limits: Limits(min: 0.0, max: double.infinity), ); @@ -283,7 +290,7 @@ class Quote extends SelectableOption { payout: quotes['payout'] as double? ?? 0.0, paymentType: paymentType, recommendations: [], - provider: ProvidersHelper.getProviderByType(ProviderType.meld)!, + provider: ProvidersHelper.getProviderByType(ProviderType.meld), isBuyAction: isBuyAction, limits: Limits(min: 0.0, max: double.infinity), ); @@ -292,7 +299,7 @@ class Quote extends SelectableOption { factory Quote.fromKryptonimJson( Map json, bool isBuyAction, PaymentType paymentType) { final fees = json['fees'] as Map; - final rate = _toDouble(json['rate']) ?? 0.0; + // final rate = _toDouble(json['rate']) ?? 0.0; final limits = json['limits'] as Map; final minLimit = _toDouble(limits['min_amount']) ?? 0.0; final maxLimit = _toDouble(limits['max_amount']) ?? double.infinity; @@ -300,14 +307,14 @@ class Quote extends SelectableOption { final amount = _toDouble(json['amount']) ?? 0.0; final calculatedRate = amount / convertedAmount; return Quote( - rate: calculatedRate, + rate: calculatedRate, feeAmount: _toDouble(fees['totalFee']) ?? 0.0, networkFee: _toDouble(fees['network_fee']) ?? 0.0, transactionFee: _toDouble(fees['operation_fee']) ?? 0.0, payout: _toDouble(json['amount']) ?? 0.0, paymentType: paymentType, recommendations: [], - provider: ProvidersHelper.getProviderByType(ProviderType.kriptonim)!, + provider: ProvidersHelper.getProviderByType(ProviderType.kriptonim), isBuyAction: isBuyAction, limits: Limits(min: minLimit, max: maxLimit)); } @@ -324,5 +331,6 @@ class Quote extends SelectableOption { } @override - String toString() => 'Quote: rate: $rate, feeAmount: $feeAmount, networkFee: $networkFee, transactionFee: $transactionFee, payout: $payout, paymentType: $paymentType, provider: $provider, quoteId: $quoteId, recommendations: $recommendations, isBuyAction: $isBuyAction, rampId: $rampId, rampName: $rampName, rampIconPath: $rampIconPath, [limits: min: ${limits?.min}, max: ${limits?.max}]'; + String toString() => + 'Quote: rate: $rate, feeAmount: $feeAmount, networkFee: $networkFee, transactionFee: $transactionFee, payout: $payout, paymentType: $paymentType, provider: $provider, quoteId: $quoteId, recommendations: $recommendations, isBuyAction: $isBuyAction, rampId: $rampId, rampName: $rampName, rampIconPath: $rampIconPath, [limits: min: ${limits?.min}, max: ${limits?.max}]'; } diff --git a/lib/entities/calculate_fiat_amount.dart b/lib/entities/calculate_fiat_amount.dart index 26750c00d..236d548cd 100644 --- a/lib/entities/calculate_fiat_amount.dart +++ b/lib/entities/calculate_fiat_amount.dart @@ -29,10 +29,10 @@ String calculateFiatAmount({double? price, String? cryptoAmount}) { return result > 0.01 ? formatted : '< 0.01'; } -String formatWithCommas(String number) { - if (number.isEmpty) return number; +String formatWithCommas(String? number) { + if (number?.isEmpty ?? true) return ''; - final parts = number.split('.'); + final parts = number!.split('.'); final integerPart = parts[0]; final decimalPart = parts.length > 1 ? parts[1] : '';