mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-29 11:44:01 +01:00
CW-1409-Update-Cakepay-cards-to-use-all-variants (#3112)
* add prepaid range support for CakePay cards * use selected denomination for order creation * fix Flexible widget issue * forces to use prod api * auto-reformat * fix the input string format [skip ci] Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * fix the value string format [skip ci] Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * fix the nextamount string format Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> --------- Co-authored-by: Robert Malikowski <malikowskirobert@gmail.com> Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
co-authored by
Omar Hatem
Robert Malikowski
parent
b1922fc663
commit
6fc27dd3a0
@@ -33,8 +33,12 @@ abstract class CakePayBuyCardViewModelBase with Store {
|
||||
: 0,
|
||||
quantity = 1,
|
||||
card = vendor.card!,
|
||||
min = _toDouble(vendor.card!.minValue) ?? 0,
|
||||
max = _toDouble(vendor.card!.maxValue) ?? 0 {
|
||||
min = vendor.card!.prepaidRange.isNotEmpty
|
||||
? vendor.card!.prepaidRange.first.minValue
|
||||
: _toDouble(vendor.card!.minValue) ?? 0,
|
||||
max = vendor.card!.prepaidRange.isNotEmpty
|
||||
? vendor.card!.prepaidRange.first.maxValue
|
||||
: _toDouble(vendor.card!.maxValue) ?? 0 {
|
||||
selectedPaymentMethod = availableMethods.isNotEmpty ? availableMethods.first : null;
|
||||
}
|
||||
|
||||
@@ -46,8 +50,6 @@ abstract class CakePayBuyCardViewModelBase with Store {
|
||||
final CakePayVendor vendor;
|
||||
final SendViewModel sendViewModel;
|
||||
final CakePayService _cakePayService;
|
||||
final double max;
|
||||
final double min;
|
||||
final CakePayCard card;
|
||||
final WalletType walletType;
|
||||
final Box<Order> orders;
|
||||
@@ -59,6 +61,8 @@ abstract class CakePayBuyCardViewModelBase with Store {
|
||||
bool confirmsNoVpn = false;
|
||||
bool confirmsVoidedRefund = false;
|
||||
bool confirmsTermsAgreed = false;
|
||||
double max;
|
||||
double min;
|
||||
(String, int?) selectedDenomination = ('', null);
|
||||
|
||||
String simulatedResponse = '';
|
||||
@@ -136,10 +140,24 @@ abstract class CakePayBuyCardViewModelBase with Store {
|
||||
@action
|
||||
void onQuantityChanged(int? input) => quantity = input ?? 1;
|
||||
|
||||
void onPrepaidRangeChanged(PrepaidRange range) {
|
||||
min = range.minValue;
|
||||
max = range.maxValue;
|
||||
selectedDenomination = (range.minValue.toString(), int.tryParse(range.rangeId));
|
||||
|
||||
if (amount < min || amount > max) {
|
||||
amount = min;
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
void onAmountChanged(String input) {
|
||||
if (input.isEmpty) return;
|
||||
amount = double.parse(input.replaceAll(',', '.'));
|
||||
|
||||
if (card.prepaidRange.isNotEmpty) {
|
||||
selectedDenomination = (input.replaceAll(',', '.'), selectedDenomination.$2);
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -153,10 +171,25 @@ abstract class CakePayBuyCardViewModelBase with Store {
|
||||
sendViewModel.state =
|
||||
FailureState('Unsupported wallet type, please use Bitcoin, Monero, Litecoin or Zcash.');
|
||||
}
|
||||
|
||||
final isPrepaidRangeSelected = card.prepaidRange.isNotEmpty;
|
||||
|
||||
int selectedCardId = card.id;
|
||||
String selectedPrice = amount.toString();
|
||||
|
||||
if (isPrepaidRangeSelected) {
|
||||
selectedCardId = selectedDenomination.$2 ?? card.id;
|
||||
selectedPrice =
|
||||
selectedDenomination.$1.isNotEmpty ? selectedDenomination.$1 : amount.toString();
|
||||
} else if (isDenominationSelected) {
|
||||
selectedCardId = selectedDenomination.$2 ?? card.id;
|
||||
selectedPrice = selectedDenomination.$1;
|
||||
}
|
||||
|
||||
try {
|
||||
order = await _cakePayService.createOrder(
|
||||
cardId: isDenominationSelected ? selectedDenomination.$2 ?? card.id : card.id,
|
||||
price: isDenominationSelected ? selectedDenomination.$1 : amount.toString(),
|
||||
cardId: selectedCardId,
|
||||
price: selectedPrice,
|
||||
quantity: quantity,
|
||||
confirmsNoVpn: confirmsNoVpn,
|
||||
confirmsVoidedRefund: confirmsVoidedRefund,
|
||||
|
||||
Reference in New Issue
Block a user