CW-148 cake pay partial redemptions (#490)

* Ionia custom redemption screen

* update ionia gift card remaining amount with custom value

* [NO-TASK] Fix issues with custom redeem

* replace redeem

* update remaining amount

* fixed from code review

* Add localization
This commit is contained in:
Godwin Asuquo
2022-09-02 14:47:45 +01:00
committed by GitHub
parent 0aee6e1b8d
commit bd25d047b2
26 changed files with 446 additions and 32 deletions
@@ -0,0 +1,27 @@
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
import 'package:mobx/mobx.dart';
part 'ionia_custom_redeem_view_model.g.dart';
class IoniaCustomRedeemViewModel = IoniaCustomRedeemViewModelBase with _$IoniaCustomRedeemViewModel;
abstract class IoniaCustomRedeemViewModelBase with Store {
IoniaCustomRedeemViewModelBase(this.giftCard){
amount = 0;
}
final IoniaGiftCard giftCard;
@observable
double amount;
@computed
double get remaining => amount <= giftCard.remainingAmount ? giftCard.remainingAmount - amount : 0;
@computed
bool get disableRedeem => amount > giftCard.remainingAmount;
@action
void updateAmount(String text){
amount = text.isEmpty ? 0 : (double.parse(text.replaceAll(',', '.')) ?? 0);
}
}
@@ -12,6 +12,7 @@ abstract class IoniaGiftCardDetailsViewModelBase with Store {
IoniaGiftCardDetailsViewModelBase({this.ioniaService, this.giftCard}) {
redeemState = InitialExecutionState();
remainingAmount = giftCard.remainingAmount;
}
final IoniaService ioniaService;
@@ -20,11 +21,15 @@ abstract class IoniaGiftCardDetailsViewModelBase with Store {
@observable
IoniaGiftCard giftCard;
@observable
double remainingAmount;
@observable
ExecutionState redeemState;
@action
Future<void> redeem() async {
giftCard.remainingAmount = remainingAmount;
try {
redeemState = IsExecutingState();
await ioniaService.redeem(giftCard);
@@ -35,6 +40,11 @@ abstract class IoniaGiftCardDetailsViewModelBase with Store {
}
}
@action
void updateRemaining(double amount){
remainingAmount = amount;
}
void increaseBrightness() async {
brightness = await DeviceDisplayBrightness.getBrightness();
await DeviceDisplayBrightness.setBrightness(1.0);