mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-09 04:19:36 +00:00
Fixes for instructions. Remove diplay error on payment status screen.
This commit is contained in:
parent
232ed8936f
commit
1cfd1df45b
7 changed files with 188 additions and 176 deletions
|
@ -159,9 +159,14 @@ class IoniaApi {
|
|||
|
||||
final data = decodedBody['Data'] as List<dynamic>;
|
||||
return data.map((dynamic e) {
|
||||
try {
|
||||
final element = e as Map<String, dynamic>;
|
||||
return IoniaMerchant.fromJsonMap(element);
|
||||
}).toList();
|
||||
} catch(_) {
|
||||
return null;
|
||||
}
|
||||
}).where((e) => e != null)
|
||||
.toList();
|
||||
}
|
||||
|
||||
// Get Merchants By Filter
|
||||
|
@ -208,9 +213,14 @@ class IoniaApi {
|
|||
|
||||
final data = decodedBody['Data'] as List<dynamic>;
|
||||
return data.map((dynamic e) {
|
||||
try {
|
||||
final element = e['Merchant'] as Map<String, dynamic>;
|
||||
return IoniaMerchant.fromJsonMap(element);
|
||||
}).toList();
|
||||
} catch(_) {
|
||||
return null;
|
||||
}
|
||||
}).where((e) => e != null)
|
||||
.toList();
|
||||
}
|
||||
|
||||
// Purchase Gift Card
|
||||
|
@ -273,9 +283,14 @@ class IoniaApi {
|
|||
|
||||
final data = decodedBody['Data'] as List<dynamic>;
|
||||
return data.map((dynamic e) {
|
||||
try {
|
||||
final element = e as Map<String, dynamic>;
|
||||
return IoniaGiftCard.fromJsonMap(element);
|
||||
}).toList();
|
||||
} catch(e) {
|
||||
return null;
|
||||
}
|
||||
}).where((e) => e != null)
|
||||
.toList();
|
||||
}
|
||||
|
||||
// Charge Gift Card
|
||||
|
|
|
@ -1,20 +1,7 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:cake_wallet/ionia/ionia_gift_card_instruction.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class IoniaGiftCardInstruction {
|
||||
IoniaGiftCardInstruction(this.header, this.body);
|
||||
|
||||
factory IoniaGiftCardInstruction.fromJsonMap(Map<String, dynamic> element) {
|
||||
return IoniaGiftCardInstruction(
|
||||
element['header'] as String,
|
||||
element['body'] as String);
|
||||
}
|
||||
|
||||
final String header;
|
||||
final String body;
|
||||
}
|
||||
|
||||
class IoniaGiftCard {
|
||||
IoniaGiftCard({
|
||||
@required this.id,
|
||||
|
@ -24,10 +11,7 @@ class IoniaGiftCard {
|
|||
@required this.barcodeUrl,
|
||||
@required this.cardNumber,
|
||||
@required this.cardPin,
|
||||
@required this.usageInstructions,
|
||||
@required this.balanceInstructions,
|
||||
@required this.paymentInstructions,
|
||||
@required this.cardImageUrl,
|
||||
@required this.instructions,
|
||||
@required this.tip,
|
||||
@required this.purchaseAmount,
|
||||
@required this.actualAmount,
|
||||
|
@ -41,11 +25,6 @@ class IoniaGiftCard {
|
|||
@required this.logoUrl});
|
||||
|
||||
factory IoniaGiftCard.fromJsonMap(Map<String, dynamic> element) {
|
||||
final decodedInstructions = json.decode(element['UsageInstructions'] as String) as Map<String, dynamic>;
|
||||
final instruction = decodedInstructions['instruction'] as List<dynamic>;
|
||||
final instructions = instruction
|
||||
.map((dynamic e) =>IoniaGiftCardInstruction.fromJsonMap(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return IoniaGiftCard(
|
||||
id: element['Id'] as int,
|
||||
merchantId: element['MerchantId'] as int,
|
||||
|
@ -65,7 +44,7 @@ class IoniaGiftCard {
|
|||
logoUrl: element['LogoUrl'] as String,
|
||||
createdDateFormatted: element['CreatedDate'] as String,
|
||||
lastTransactionDateFormatted: element['LastTransactionDate'] as String,
|
||||
usageInstructions: instructions);
|
||||
instructions: IoniaGiftCardInstruction.parseListOfInstructions(element['PaymentInstructions'] as String));
|
||||
}
|
||||
|
||||
final int id;
|
||||
|
@ -75,10 +54,7 @@ class IoniaGiftCard {
|
|||
final String barcodeUrl;
|
||||
final String cardNumber;
|
||||
final String cardPin;
|
||||
final List<IoniaGiftCardInstruction> usageInstructions;
|
||||
final Map<String, dynamic> balanceInstructions;
|
||||
final Map<String, dynamic> paymentInstructions;
|
||||
final String cardImageUrl;
|
||||
final List<IoniaGiftCardInstruction> instructions;
|
||||
final double tip;
|
||||
final double purchaseAmount;
|
||||
final double actualAmount;
|
||||
|
|
28
lib/ionia/ionia_gift_card_instruction.dart
Normal file
28
lib/ionia/ionia_gift_card_instruction.dart
Normal file
|
@ -0,0 +1,28 @@
|
|||
import 'dart:convert';
|
||||
import 'package:intl/intl.dart' show toBeginningOfSentenceCase;
|
||||
|
||||
class IoniaGiftCardInstruction {
|
||||
IoniaGiftCardInstruction(this.header, this.body);
|
||||
|
||||
factory IoniaGiftCardInstruction.fromJsonMap(Map<String, dynamic> element) {
|
||||
return IoniaGiftCardInstruction(
|
||||
toBeginningOfSentenceCase(element['title'] as String ?? ''),
|
||||
element['description'] as String);
|
||||
}
|
||||
|
||||
static List<IoniaGiftCardInstruction> parseListOfInstructions(String instructionsJSON) {
|
||||
List<IoniaGiftCardInstruction> instructions = <IoniaGiftCardInstruction>[];
|
||||
|
||||
if (instructionsJSON.isNotEmpty) {
|
||||
final decodedInstructions = json.decode(instructionsJSON) as List<dynamic>;
|
||||
instructions = decodedInstructions
|
||||
.map((dynamic e) =>IoniaGiftCardInstruction.fromJsonMap(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
return instructions;
|
||||
}
|
||||
|
||||
final String header;
|
||||
final String body;
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_gift_card_instruction.dart';
|
||||
|
||||
class IoniaMerchant {
|
||||
IoniaMerchant({
|
||||
@required this.id,
|
||||
|
@ -48,7 +50,7 @@ class IoniaMerchant {
|
|||
@required this.isVoidable,
|
||||
@required this.receiptMessage,
|
||||
@required this.cssBorderCode,
|
||||
@required this.paymentInstructions,
|
||||
@required this.instructions,
|
||||
@required this.alderSku,
|
||||
@required this.ngcSku,
|
||||
@required this.acceptedCurrency,
|
||||
|
@ -105,7 +107,7 @@ class IoniaMerchant {
|
|||
isVoidable: element["IsVoidable"] as bool,
|
||||
receiptMessage: element["ReceiptMessage"] as String,
|
||||
cssBorderCode: element["CssBorderCode"] as String,
|
||||
paymentInstructions: element["PaymentInstructions"] as String,
|
||||
instructions: IoniaGiftCardInstruction.parseListOfInstructions(element['PaymentInstructions'] as String),
|
||||
alderSku: element["AlderSku"] as String,
|
||||
ngcSku: element["NgcSku"] as String,
|
||||
acceptedCurrency: element["AcceptedCurrency"] as String,
|
||||
|
@ -113,7 +115,16 @@ class IoniaMerchant {
|
|||
isPayLater: element["IsPayLater"] as bool);
|
||||
}
|
||||
|
||||
final int id; final String legalName; final String systemName; final String description; final String website; final String termsAndConditions; final String logoUrl; final String cardImageUrl; final String cardholderAgreement; final double purchaseFee;
|
||||
final int id;
|
||||
final String legalName;
|
||||
final String systemName;
|
||||
final String description;
|
||||
final String website;
|
||||
final String termsAndConditions;
|
||||
final String logoUrl;
|
||||
final String cardImageUrl;
|
||||
final String cardholderAgreement;
|
||||
final double purchaseFee;
|
||||
final double revenueShare;
|
||||
final double marketingFee;
|
||||
final double minimumDiscount;
|
||||
|
@ -151,7 +162,7 @@ class IoniaMerchant {
|
|||
final bool isVoidable;
|
||||
final String receiptMessage;
|
||||
final String cssBorderCode;
|
||||
final String paymentInstructions;
|
||||
final List<IoniaGiftCardInstruction> instructions;
|
||||
final String alderSku;
|
||||
final String ngcSku;
|
||||
final String acceptedCurrency;
|
||||
|
|
|
@ -258,15 +258,29 @@ class IoniaBuyGiftCardDetailPage extends BasePage {
|
|||
builder: (BuildContext context) {
|
||||
return IoniaAlertModal(
|
||||
title: S.of(context).how_to_use_card,
|
||||
content: Align(
|
||||
alignment: Alignment.bottomLeft,
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: merchant.instructions
|
||||
.map((instruction) {
|
||||
return [
|
||||
Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Text(
|
||||
merchant.usageInstructionsBak,
|
||||
instruction.header,
|
||||
style: textLargeSemiBold(
|
||||
color: Theme.of(context).textTheme.display2.color,
|
||||
),
|
||||
)),
|
||||
Text(
|
||||
instruction.body,
|
||||
style: textMedium(
|
||||
color: Theme.of(context).textTheme.display2.color,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
];
|
||||
})
|
||||
.expand((e) => e)
|
||||
.toList()),
|
||||
actionTitle: S.current.send_got_it,
|
||||
);
|
||||
});
|
||||
|
|
|
@ -159,7 +159,7 @@ class IoniaGiftCardDetailPage extends BasePage {
|
|||
title: S.of(context).how_to_use_card,
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: viewModel.giftCard.usageInstructions
|
||||
children: viewModel.giftCard.instructions
|
||||
.map((instruction) {
|
||||
return [
|
||||
Padding(
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
|
||||
import 'package:cake_wallet/routes.dart';
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
||||
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
|
||||
import 'package:cake_wallet/typography.dart';
|
||||
import 'package:cake_wallet/utils/show_bar.dart';
|
||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||
import 'package:cake_wallet/view_model/ionia/ionia_payment_status_view_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
|
@ -44,7 +42,6 @@ class _IoniaPaymentStatusPageBody extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _IoniaPaymentStatusPageBodyBodyState extends State<_IoniaPaymentStatusPageBody> {
|
||||
ReactionDisposer _onErrorReaction;
|
||||
ReactionDisposer _onGiftCardReaction;
|
||||
|
||||
@override
|
||||
|
@ -56,34 +53,6 @@ class _IoniaPaymentStatusPageBodyBodyState extends State<_IoniaPaymentStatusPage
|
|||
});
|
||||
}
|
||||
|
||||
if (widget.viewModel.error != null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithOneAction(
|
||||
alertTitle: S.of(context).error,
|
||||
alertContent: widget.viewModel.error,
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(context).pop());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_onErrorReaction = reaction((_) => widget.viewModel.error, (String error) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithOneAction(
|
||||
alertTitle: S.of(context).error,
|
||||
alertContent: error,
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(context).pop());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
_onGiftCardReaction = reaction((_) => widget.viewModel.giftCard, (IoniaGiftCard giftCard) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
Navigator.of(context)
|
||||
|
@ -96,7 +65,6 @@ class _IoniaPaymentStatusPageBodyBodyState extends State<_IoniaPaymentStatusPage
|
|||
|
||||
@override
|
||||
void dispose() {
|
||||
_onErrorReaction?.reaction?.dispose();
|
||||
_onGiftCardReaction?.reaction?.dispose();
|
||||
widget.viewModel.timer.cancel();
|
||||
super.dispose();
|
||||
|
|
Loading…
Reference in a new issue