Fix correct adjusted amount for custom redeem
Godwin Asuquo committed
Nov 30, 2022 at 10:00 UTC
8511805ee35fca9ddbf5818fb50622dc305c180b
7 files changed
+29
-25
lib/ionia/ionia_gift_card.dart
+1
-1
@@ -37,7 +37,7 @@ class IoniaGiftCard {
37
purchaseAmount: element['PurchaseAmount'] as double,
38
actualAmount: element['ActualAmount'] as double,
39
totalTransactionAmount: element['TotalTransactionAmount'] as double,
40
- totalDashTransactionAmount: element['TotalDashTransactionAmount'] as double,
40
+ totalDashTransactionAmount: element['TotalDashTransactionAmount'] != null ? element['TotalDashTransactionAmount'] as double : 0.0,
41
remainingAmount: element['RemainingAmount'] as double,
42
isActive: element['IsActive'] as bool,
43
isEmpty: element['IsEmpty'] as bool,
lib/ionia/ionia_service.dart
+2
-2
@@ -148,8 +148,8 @@ class IoniaService {
148
149
// Redeem
150
151
- Future<void> redeem(IoniaGiftCard giftCard) async {
152
- await chargeGiftCard(giftCardId: giftCard.id, amount: giftCard.remainingAmount);
151
+ Future<void> redeem({required int giftCardId, required double amount}) async {
152
+ await chargeGiftCard(giftCardId: giftCardId, amount: amount);
153
}
154
155
// Get Gift Card
lib/src/screens/ionia/cards/ionia_custom_redeem_page.dart
+1
-1
@@ -149,7 +149,7 @@ class IoniaCustomRedeemPage extends BasePage {
149
padding: EdgeInsets.only(bottom: 12),
150
child: PrimaryButton(
151
onPressed: () {
152
- Navigator.of(context).pop(ioniaCustomRedeemViewModel.remaining.toString());
152
+ Navigator.of(context).pop([ioniaCustomRedeemViewModel.remaining.toString(), ioniaCustomRedeemViewModel.amount.toString()]);
153
},
154
isDisabled: ioniaCustomRedeemViewModel.disableRedeem,
155
text: S.of(context).add_custom_redemption,
lib/src/screens/ionia/cards/ionia_gift_card_detail_page.dart
+14
-14
@@ -130,19 +130,19 @@ class IoniaGiftCardDetailPage extends BasePage {
130
if (!viewModel.giftCard.isEmpty) {
131
return Column(
132
children: [
133
- //PrimaryButton(
134
- // onPressed: () async {
135
- // final amount = await Navigator.of(context)
136
- // .pushNamed(Routes.ioniaMoreOptionsPage, arguments: [viewModel.giftCard]) as String;
137
- // if (amount != null) {
138
- // viewModel.updateRemaining(double.parse(amount));
139
- // }
140
- // },
141
- // text: S.of(context).more_options,
142
- // color: Theme.of(context).accentTextTheme!.caption!.color!,
143
- // textColor: Theme.of(context).primaryTextTheme!.headline6!.color!,
144
- //),
145
- //SizedBox(height: 12),
133
+ PrimaryButton(
134
+ onPressed: () async {
135
+ final amount = await Navigator.of(context)
136
+ .pushNamed(Routes.ioniaMoreOptionsPage, arguments: [viewModel.giftCard]) as List<String>?;
137
+ if (amount != null) {
138
+ viewModel.updateRemaining( balance: double.parse(amount.first), customAmount: double.parse(amount.last));
139
+ }
140
+ },
141
+ text: S.of(context).more_options,
142
+ color: Theme.of(context).accentTextTheme.caption!.color!,
143
+ textColor: Theme.of(context).primaryTextTheme.headline6!.color!,
144
+ ),
145
+ SizedBox(height: 12),
146
LoadingPrimaryButton(
147
isLoading: viewModel.redeemState is IsExecutingState,
148
onPressed: () => viewModel.redeem().then(
@@ -152,7 +152,7 @@ class IoniaGiftCardDetailPage extends BasePage {
152
},
153
),
154
text: S.of(context).mark_as_redeemed,
155
- color: Theme.of(context).accentTextTheme!.bodyText1!.color!,
155
+ color: Theme.of(context).accentTextTheme.bodyText1!.color!,
156
textColor: Colors.white,
157
),
158
],
lib/src/screens/ionia/cards/ionia_more_options_page.dart
+3
-3
@@ -35,9 +35,9 @@ class IoniaMoreOptionsPage extends BasePage {
35
SizedBox(height: 40,),
36
InkWell(
37
onTap: () async {
38
- final amount = await Navigator.of(context).pushNamed(Routes.ioniaCustomRedeemPage, arguments: [giftCard]) as String;
39
- if(amount.isNotEmpty){
40
- Navigator.pop(context, amount);
38
+ final amounts = await Navigator.of(context).pushNamed(Routes.ioniaCustomRedeemPage, arguments: [giftCard]) as List<String>;
39
+ if(amounts.first.isNotEmpty){
40
+ Navigator.pop(context, amounts);
41
}
42
},
43
child: _GradiantContainer(
lib/src/screens/ionia/widgets/ionia_filter_modal.dart
+1
-1
@@ -53,7 +53,7 @@ class IoniaFilterModal extends StatelessWidget {
53
prefixIcon: searchIcon,
54
hintText: S.of(context).search_category,
55
contentPadding: EdgeInsets.only(bottom: 5),
56
- fillColor: Theme.of(context).textTheme!.subtitle1!.backgroundColor!,
56
+ fillColor: Theme.of(context).textTheme.subtitle1?.backgroundColor,
57
border: OutlineInputBorder(
58
borderSide: BorderSide.none,
59
borderRadius: BorderRadius.circular(8),
lib/view_model/ionia/ionia_gift_card_details_view_model.dart
+7
-3
@@ -15,6 +15,7 @@ abstract class IoniaGiftCardDetailsViewModelBase with Store {
15
required this.giftCard})
16
: redeemState = InitialExecutionState(),
17
remainingAmount = giftCard.remainingAmount,
18
+ adjustedAmount = 0,
19
brightness = 0;
20
21
final IoniaService ioniaService;
@@ -27,6 +28,8 @@ abstract class IoniaGiftCardDetailsViewModelBase with Store {
28
@observable
29
double remainingAmount;
30
31
+ double adjustedAmount;
32
+
33
@observable
34
ExecutionState redeemState;
35
@@ -35,7 +38,7 @@ abstract class IoniaGiftCardDetailsViewModelBase with Store {
38
giftCard.remainingAmount = remainingAmount;
39
try {
40
redeemState = IsExecutingState();
38
- await ioniaService.redeem(giftCard);
41
+ await ioniaService.redeem(giftCardId: giftCard.id, amount : adjustedAmount > 0 ? adjustedAmount : giftCard.remainingAmount);
42
giftCard = await ioniaService.getGiftCard(id: giftCard.id);
43
redeemState = ExecutedSuccessfullyState();
44
} catch(e) {
@@ -44,8 +47,9 @@ abstract class IoniaGiftCardDetailsViewModelBase with Store {
47
}
48
49
@action
47
- void updateRemaining(double amount){
48
- remainingAmount = amount;
50
+ void updateRemaining({required double balance, required double customAmount}) {
51
+ remainingAmount = balance;
52
+ adjustedAmount = customAmount;
53
}
54
55
void increaseBrightness() async {