Fix correct adjusted amount for custom redeem

This commit is contained in:
Godwin Asuquo 2022-11-30 10:00:05 +02:00
parent 2eb9db4ca6
commit 8511805ee3
7 changed files with 29 additions and 25 deletions

View file

@ -37,7 +37,7 @@ class IoniaGiftCard {
purchaseAmount: element['PurchaseAmount'] as double, purchaseAmount: element['PurchaseAmount'] as double,
actualAmount: element['ActualAmount'] as double, actualAmount: element['ActualAmount'] as double,
totalTransactionAmount: element['TotalTransactionAmount'] as double, totalTransactionAmount: element['TotalTransactionAmount'] as double,
totalDashTransactionAmount: element['TotalDashTransactionAmount'] as double, totalDashTransactionAmount: element['TotalDashTransactionAmount'] != null ? element['TotalDashTransactionAmount'] as double : 0.0,
remainingAmount: element['RemainingAmount'] as double, remainingAmount: element['RemainingAmount'] as double,
isActive: element['IsActive'] as bool, isActive: element['IsActive'] as bool,
isEmpty: element['IsEmpty'] as bool, isEmpty: element['IsEmpty'] as bool,

View file

@ -148,8 +148,8 @@ class IoniaService {
// Redeem // Redeem
Future<void> redeem(IoniaGiftCard giftCard) async { Future<void> redeem({required int giftCardId, required double amount}) async {
await chargeGiftCard(giftCardId: giftCard.id, amount: giftCard.remainingAmount); await chargeGiftCard(giftCardId: giftCardId, amount: amount);
} }
// Get Gift Card // Get Gift Card

View file

@ -149,7 +149,7 @@ class IoniaCustomRedeemPage extends BasePage {
padding: EdgeInsets.only(bottom: 12), padding: EdgeInsets.only(bottom: 12),
child: PrimaryButton( child: PrimaryButton(
onPressed: () { onPressed: () {
Navigator.of(context).pop(ioniaCustomRedeemViewModel.remaining.toString()); Navigator.of(context).pop([ioniaCustomRedeemViewModel.remaining.toString(), ioniaCustomRedeemViewModel.amount.toString()]);
}, },
isDisabled: ioniaCustomRedeemViewModel.disableRedeem, isDisabled: ioniaCustomRedeemViewModel.disableRedeem,
text: S.of(context).add_custom_redemption, text: S.of(context).add_custom_redemption,

View file

@ -130,19 +130,19 @@ class IoniaGiftCardDetailPage extends BasePage {
if (!viewModel.giftCard.isEmpty) { if (!viewModel.giftCard.isEmpty) {
return Column( return Column(
children: [ children: [
//PrimaryButton( PrimaryButton(
// onPressed: () async { onPressed: () async {
// final amount = await Navigator.of(context) final amount = await Navigator.of(context)
// .pushNamed(Routes.ioniaMoreOptionsPage, arguments: [viewModel.giftCard]) as String; .pushNamed(Routes.ioniaMoreOptionsPage, arguments: [viewModel.giftCard]) as List<String>?;
// if (amount != null) { if (amount != null) {
// viewModel.updateRemaining(double.parse(amount)); viewModel.updateRemaining( balance: double.parse(amount.first), customAmount: double.parse(amount.last));
// } }
// }, },
// text: S.of(context).more_options, text: S.of(context).more_options,
// color: Theme.of(context).accentTextTheme!.caption!.color!, color: Theme.of(context).accentTextTheme.caption!.color!,
// textColor: Theme.of(context).primaryTextTheme!.headline6!.color!, textColor: Theme.of(context).primaryTextTheme.headline6!.color!,
//), ),
//SizedBox(height: 12), SizedBox(height: 12),
LoadingPrimaryButton( LoadingPrimaryButton(
isLoading: viewModel.redeemState is IsExecutingState, isLoading: viewModel.redeemState is IsExecutingState,
onPressed: () => viewModel.redeem().then( onPressed: () => viewModel.redeem().then(
@ -152,7 +152,7 @@ class IoniaGiftCardDetailPage extends BasePage {
}, },
), ),
text: S.of(context).mark_as_redeemed, text: S.of(context).mark_as_redeemed,
color: Theme.of(context).accentTextTheme!.bodyText1!.color!, color: Theme.of(context).accentTextTheme.bodyText1!.color!,
textColor: Colors.white, textColor: Colors.white,
), ),
], ],

View file

@ -35,9 +35,9 @@ class IoniaMoreOptionsPage extends BasePage {
SizedBox(height: 40,), SizedBox(height: 40,),
InkWell( InkWell(
onTap: () async { onTap: () async {
final amount = await Navigator.of(context).pushNamed(Routes.ioniaCustomRedeemPage, arguments: [giftCard]) as String; final amounts = await Navigator.of(context).pushNamed(Routes.ioniaCustomRedeemPage, arguments: [giftCard]) as List<String>;
if(amount.isNotEmpty){ if(amounts.first.isNotEmpty){
Navigator.pop(context, amount); Navigator.pop(context, amounts);
} }
}, },
child: _GradiantContainer( child: _GradiantContainer(

View file

@ -53,7 +53,7 @@ class IoniaFilterModal extends StatelessWidget {
prefixIcon: searchIcon, prefixIcon: searchIcon,
hintText: S.of(context).search_category, hintText: S.of(context).search_category,
contentPadding: EdgeInsets.only(bottom: 5), contentPadding: EdgeInsets.only(bottom: 5),
fillColor: Theme.of(context).textTheme!.subtitle1!.backgroundColor!, fillColor: Theme.of(context).textTheme.subtitle1?.backgroundColor,
border: OutlineInputBorder( border: OutlineInputBorder(
borderSide: BorderSide.none, borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),

View file

@ -15,6 +15,7 @@ abstract class IoniaGiftCardDetailsViewModelBase with Store {
required this.giftCard}) required this.giftCard})
: redeemState = InitialExecutionState(), : redeemState = InitialExecutionState(),
remainingAmount = giftCard.remainingAmount, remainingAmount = giftCard.remainingAmount,
adjustedAmount = 0,
brightness = 0; brightness = 0;
final IoniaService ioniaService; final IoniaService ioniaService;
@ -27,6 +28,8 @@ abstract class IoniaGiftCardDetailsViewModelBase with Store {
@observable @observable
double remainingAmount; double remainingAmount;
double adjustedAmount;
@observable @observable
ExecutionState redeemState; ExecutionState redeemState;
@ -35,7 +38,7 @@ abstract class IoniaGiftCardDetailsViewModelBase with Store {
giftCard.remainingAmount = remainingAmount; giftCard.remainingAmount = remainingAmount;
try { try {
redeemState = IsExecutingState(); redeemState = IsExecutingState();
await ioniaService.redeem(giftCard); await ioniaService.redeem(giftCardId: giftCard.id, amount : adjustedAmount > 0 ? adjustedAmount : giftCard.remainingAmount);
giftCard = await ioniaService.getGiftCard(id: giftCard.id); giftCard = await ioniaService.getGiftCard(id: giftCard.id);
redeemState = ExecutedSuccessfullyState(); redeemState = ExecutedSuccessfullyState();
} catch(e) { } catch(e) {
@ -44,8 +47,9 @@ abstract class IoniaGiftCardDetailsViewModelBase with Store {
} }
@action @action
void updateRemaining(double amount){ void updateRemaining({required double balance, required double customAmount}) {
remainingAmount = amount; remainingAmount = balance;
adjustedAmount = customAmount;
} }
void increaseBrightness() async { void increaseBrightness() async {