mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-01 12:04:21 +01:00
Ionia (#437)
* Initial ionia service * Ionia manage card UI (#374) * design ui for cakepay * Add manage cards page ui * create auth ui for ionia * add authentication logic * implement user create card * Add ionia merchant sevic * Add anypay. Add purschase gift card. * display virtual card (#385) * display virtual card * fix formatting * Remove IoniaMerchantService from IoniaViewModel * Add hex and txKey for monero pending transaction. * Changed monero version and monero repo to cake tech. * Add anypay payment. Add filter by search for ionia, add get purchased items for ionia. * Fix for get transactions for hidden addresses for electrum wallet * Add ionia categories. * Add anypay commited info for payments. * Update UI with new fixes (#400) * Change ionia base url. Add exception throwing for error messaging for some of ionia calls. * CW-102 fix logic for ionia issues (#403) * refactor tips (#406) * refactor tips * refactor ionia tips implementation * Cw 115 implement gift cards list for ionia (#405) * Implement show purchased cards * fix padding * Fixes for getting of purchased gift cards. * Implement gift card details screen (#408) * Implement gift card details screen * Add redeem for ionia gift cards * Fix navigation after ionia opt redirection. * Fix update gift cards list. * Add payment status update for ionia. * Add usage instruction to gift card. * Add copy for ionia gift card info. * Change version for Cake Wallet ios. * Add localisation (#414) * Fixes for fiat amounts for ionia. * CW-128 marketplace screen text changes (#416) * Change text on marketplace * fix build issues * fix build * UI fixes for ionia. * UI fixes for ionia. (#421) * CW-129 ionia welcome screen text changes (#418) * update welcome text * Update localization * Cw 133 (#422) * UI fixes for ionia. * Fixes for display card item on gift cards screen. * Fix signup page (#419) * Changed tips for ionia. * Cw 132 (#425) * UI fixes for ionia. * Changed tips for ionia. * Cw 131 (#426) * UI fixes for ionia. * Changed tips for ionia. * Fixes for IoniaBuyGiftCardDetailPage screen. Renamed 'Manage Cards' to 'Gift Cards'. Hide discount badge label for 0 discount. * Change ionia heading font style (#427) * Fix for AddressResolver in di * Changed build number for Cake Wallet ios. * fix currency format for card details and routing for mark as redeemed (#431) * fix terms and condition overflow in ionia (#430) * fix terms and condition scroll * fix color issues * reuse * refactor widget * Remove IoniaTokenService * Change api for ionia to staging * Update versions for Cake Wallet for android and ios. * Fixes for instructions. Remove diplay error on payment status screen. * Change build versions for Cake Wallet * Add ionia sign in. * Update for discounts and statuses for ionia merch. * Fixes for qr/barcode on ionia gift card screen. * Fixed formatting for display ionia discounts. * Fix merchant.discount.toStringAsFixed issue * Add savingsPercentage to ionia merch discount. * Change build number for Cake Wallet ios and android. * Disable ionia for haven (#440) Co-authored-by: Godwin Asuquo <41484542+godilite@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import 'package:cake_wallet/ionia/ionia_merchant.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_service.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
|
||||
|
||||
part 'ionia_account_view_model.g.dart';
|
||||
|
||||
class IoniaAccountViewModel = IoniaAccountViewModelBase with _$IoniaAccountViewModel;
|
||||
|
||||
abstract class IoniaAccountViewModelBase with Store {
|
||||
IoniaAccountViewModelBase({this.ioniaService}) {
|
||||
email = '';
|
||||
giftCards = [];
|
||||
ioniaService.getUserEmail().then((email) => this.email = email);
|
||||
updateUserGiftCards();
|
||||
}
|
||||
|
||||
final IoniaService ioniaService;
|
||||
|
||||
@observable
|
||||
String email;
|
||||
|
||||
@observable
|
||||
List<IoniaGiftCard> giftCards;
|
||||
|
||||
@computed
|
||||
int get countOfMerch => giftCards.where((giftCard) => !giftCard.isEmpty).length;
|
||||
|
||||
@computed
|
||||
List<IoniaGiftCard> get activeMechs => giftCards.where((giftCard) => !giftCard.isEmpty).toList();
|
||||
|
||||
@computed
|
||||
List<IoniaGiftCard> get redeemedMerchs => giftCards.where((giftCard) => giftCard.isEmpty).toList();
|
||||
|
||||
@action
|
||||
void logout() {
|
||||
ioniaService.logout();
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> updateUserGiftCards() async {
|
||||
giftCards = await ioniaService.getCurrentUserGiftCardSummaries();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import 'package:cake_wallet/ionia/ionia_create_state.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_service.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
part 'ionia_auth_view_model.g.dart';
|
||||
|
||||
class IoniaAuthViewModel = IoniaAuthViewModelBase with _$IoniaAuthViewModel;
|
||||
|
||||
abstract class IoniaAuthViewModelBase with Store {
|
||||
|
||||
IoniaAuthViewModelBase({this.ioniaService}):
|
||||
createUserState = IoniaInitialCreateState(),
|
||||
signInState = IoniaInitialCreateState(),
|
||||
otpState = IoniaOtpSendDisabled();
|
||||
|
||||
final IoniaService ioniaService;
|
||||
|
||||
@observable
|
||||
IoniaCreateAccountState createUserState;
|
||||
|
||||
@observable
|
||||
IoniaCreateAccountState signInState;
|
||||
|
||||
@observable
|
||||
IoniaOtpState otpState;
|
||||
|
||||
@observable
|
||||
String email;
|
||||
|
||||
@observable
|
||||
String otp;
|
||||
|
||||
@action
|
||||
Future<void> verifyEmail(String code) async {
|
||||
try {
|
||||
otpState = IoniaOtpValidating();
|
||||
await ioniaService.verifyEmail(code);
|
||||
otpState = IoniaOtpSuccess();
|
||||
} catch (_) {
|
||||
otpState = IoniaOtpFailure(error: 'Invalid OTP. Try again');
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> createUser(String email) async {
|
||||
try {
|
||||
createUserState = IoniaCreateStateLoading();
|
||||
await ioniaService.createUser(email);
|
||||
createUserState = IoniaCreateStateSuccess();
|
||||
} catch (e) {
|
||||
createUserState = IoniaCreateStateFailure(error: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@action
|
||||
Future<void> signIn(String email) async {
|
||||
try {
|
||||
signInState = IoniaCreateStateLoading();
|
||||
await ioniaService.signIn(email);
|
||||
signInState = IoniaCreateStateSuccess();
|
||||
} catch (e) {
|
||||
signInState = IoniaCreateStateFailure(error: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:cake_wallet/ionia/ionia_merchant.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
part 'ionia_buy_card_view_model.g.dart';
|
||||
|
||||
class IoniaBuyCardViewModel = IoniaBuyCardViewModelBase with _$IoniaBuyCardViewModel;
|
||||
|
||||
abstract class IoniaBuyCardViewModelBase with Store {
|
||||
IoniaBuyCardViewModelBase({this.ioniaMerchant}) {
|
||||
isEnablePurchase = false;
|
||||
amount = 0;
|
||||
}
|
||||
|
||||
final IoniaMerchant ioniaMerchant;
|
||||
|
||||
@observable
|
||||
double amount;
|
||||
|
||||
@observable
|
||||
bool isEnablePurchase;
|
||||
|
||||
@action
|
||||
void onAmountChanged(String input) {
|
||||
if (input.isEmpty) return;
|
||||
amount = double.parse(input.replaceAll(',', '.'));
|
||||
final min = ioniaMerchant.minimumCardPurchase;
|
||||
final max = ioniaMerchant.maximumCardPurchase;
|
||||
|
||||
isEnablePurchase = amount >= min && amount <= max;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'package:cake_wallet/ionia/ionia_category.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
part 'ionia_filter_view_model.g.dart';
|
||||
|
||||
class IoniaFilterViewModel = IoniaFilterViewModelBase with _$IoniaFilterViewModel;
|
||||
|
||||
abstract class IoniaFilterViewModelBase with Store {
|
||||
IoniaFilterViewModelBase() {
|
||||
selectedIndices = ObservableList<int>();
|
||||
ioniaCategories = IoniaCategory.allCategories;
|
||||
}
|
||||
|
||||
List<IoniaCategory> get selectedCategories => ioniaCategories.where(_isSelected).toList();
|
||||
|
||||
@observable
|
||||
ObservableList<int> selectedIndices;
|
||||
|
||||
@observable
|
||||
List<IoniaCategory> ioniaCategories;
|
||||
|
||||
@action
|
||||
void selectFilter(IoniaCategory ioniaCategory) {
|
||||
if (ioniaCategory == IoniaCategory.all && !selectedIndices.contains(0)) {
|
||||
selectedIndices.clear();
|
||||
selectedIndices.add(0);
|
||||
return;
|
||||
}
|
||||
if (selectedIndices.contains(ioniaCategory.index) && ioniaCategory.index != 0) {
|
||||
selectedIndices.remove(ioniaCategory.index);
|
||||
return;
|
||||
}
|
||||
selectedIndices.add(ioniaCategory.index);
|
||||
selectedIndices.remove(0);
|
||||
}
|
||||
|
||||
@action
|
||||
void onSearchFilter(String text) {
|
||||
if (text.isEmpty) {
|
||||
ioniaCategories = IoniaCategory.allCategories;
|
||||
} else {
|
||||
ioniaCategories = IoniaCategory.allCategories
|
||||
.where(
|
||||
(e) => e.title.toLowerCase().contains(text.toLowerCase()),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
void setSelectedCategories(List<IoniaCategory> selectedCategories) {
|
||||
selectedIndices = ObservableList.of(selectedCategories.map((e) => e.index));
|
||||
}
|
||||
|
||||
bool _isSelected(IoniaCategory ioniaCategory) {
|
||||
return selectedIndices.contains(ioniaCategory.index);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_service.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
part 'ionia_gift_card_details_view_model.g.dart';
|
||||
|
||||
class IoniaGiftCardDetailsViewModel = IoniaGiftCardDetailsViewModelBase with _$IoniaGiftCardDetailsViewModel;
|
||||
|
||||
abstract class IoniaGiftCardDetailsViewModelBase with Store {
|
||||
|
||||
IoniaGiftCardDetailsViewModelBase({this.ioniaService, this.giftCard}) {
|
||||
redeemState = InitialExecutionState();
|
||||
}
|
||||
|
||||
final IoniaService ioniaService;
|
||||
|
||||
@observable
|
||||
IoniaGiftCard giftCard;
|
||||
|
||||
@observable
|
||||
ExecutionState redeemState;
|
||||
|
||||
@action
|
||||
Future<void> redeem() async {
|
||||
try {
|
||||
redeemState = IsExecutingState();
|
||||
await ioniaService.redeem(giftCard);
|
||||
giftCard = await ioniaService.getGiftCard(id: giftCard.id);
|
||||
redeemState = ExecutedSuccessfullyState();
|
||||
} catch(e) {
|
||||
redeemState = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
import 'package:cake_wallet/ionia/ionia_category.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_service.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_create_state.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_merchant.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_virtual_card.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
part 'ionia_gift_cards_list_view_model.g.dart';
|
||||
|
||||
class IoniaGiftCardsListViewModel = IoniaGiftCardsListViewModelBase with _$IoniaGiftCardsListViewModel;
|
||||
|
||||
abstract class IoniaGiftCardsListViewModelBase with Store {
|
||||
IoniaGiftCardsListViewModelBase({
|
||||
@required this.ioniaService,
|
||||
}) :
|
||||
cardState = IoniaNoCardState(),
|
||||
ioniaMerchants = [],
|
||||
scrollOffsetFromTop = 0.0 {
|
||||
selectedFilters = [];
|
||||
_getAuthStatus().then((value) => isLoggedIn = value);
|
||||
|
||||
_getMerchants();
|
||||
}
|
||||
|
||||
final IoniaService ioniaService;
|
||||
|
||||
List<IoniaMerchant> ioniaMerchantList;
|
||||
|
||||
String searchString;
|
||||
|
||||
List<IoniaCategory> selectedFilters;
|
||||
|
||||
@observable
|
||||
double scrollOffsetFromTop;
|
||||
|
||||
@observable
|
||||
IoniaCreateCardState createCardState;
|
||||
|
||||
@observable
|
||||
IoniaFetchCardState cardState;
|
||||
|
||||
@observable
|
||||
List<IoniaMerchant> ioniaMerchants;
|
||||
|
||||
@observable
|
||||
bool isLoggedIn;
|
||||
|
||||
Future<bool> _getAuthStatus() async {
|
||||
return await ioniaService.isLogined();
|
||||
}
|
||||
|
||||
@action
|
||||
Future<IoniaVirtualCard> createCard() async {
|
||||
createCardState = IoniaCreateCardLoading();
|
||||
try {
|
||||
final card = await ioniaService.createCard();
|
||||
createCardState = IoniaCreateCardSuccess();
|
||||
return card;
|
||||
} on Exception catch (e) {
|
||||
createCardState = IoniaCreateCardFailure(error: e.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@action
|
||||
void searchMerchant(String text) {
|
||||
if (text.isEmpty) {
|
||||
ioniaMerchants = ioniaMerchantList;
|
||||
return;
|
||||
}
|
||||
searchString = text;
|
||||
ioniaService.getMerchantsByFilter(search: searchString).then((value) {
|
||||
ioniaMerchants = value;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _getCard() async {
|
||||
cardState = IoniaFetchingCard();
|
||||
try {
|
||||
final card = await ioniaService.getCard();
|
||||
|
||||
cardState = IoniaCardSuccess(card: card);
|
||||
} catch (_) {
|
||||
cardState = IoniaFetchCardFailure();
|
||||
}
|
||||
}
|
||||
|
||||
void _getMerchants() {
|
||||
ioniaService.getMerchantsByFilter(categories: selectedFilters).then((value) {
|
||||
ioniaMerchants = ioniaMerchantList = value;
|
||||
});
|
||||
}
|
||||
|
||||
@action
|
||||
void setSelectedFilter(List<IoniaCategory> filters) {
|
||||
selectedFilters = filters;
|
||||
_getMerchants();
|
||||
}
|
||||
|
||||
void setScrollOffsetFromTop(double scrollOffset) {
|
||||
scrollOffsetFromTop = scrollOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'dart:async';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_service.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
|
||||
import 'package:cake_wallet/anypay/any_pay_payment_committed_info.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_any_pay_payment_info.dart';
|
||||
|
||||
part 'ionia_payment_status_view_model.g.dart';
|
||||
|
||||
class IoniaPaymentStatusViewModel = IoniaPaymentStatusViewModelBase with _$IoniaPaymentStatusViewModel;
|
||||
|
||||
abstract class IoniaPaymentStatusViewModelBase with Store {
|
||||
IoniaPaymentStatusViewModelBase(
|
||||
this.ioniaService,{
|
||||
@required this.paymentInfo,
|
||||
@required this.committedInfo}) {
|
||||
_timer = Timer.periodic(updateTime, (timer) async {
|
||||
await updatePaymentStatus();
|
||||
|
||||
if (giftCard != null) {
|
||||
timer?.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static const updateTime = Duration(seconds: 3);
|
||||
|
||||
final IoniaService ioniaService;
|
||||
final IoniaAnyPayPaymentInfo paymentInfo;
|
||||
final AnyPayPaymentCommittedInfo committedInfo;
|
||||
|
||||
@observable
|
||||
IoniaGiftCard giftCard;
|
||||
|
||||
@observable
|
||||
String error;
|
||||
|
||||
Timer get timer => _timer;
|
||||
|
||||
Timer _timer;
|
||||
|
||||
@action
|
||||
Future<void> updatePaymentStatus() async {
|
||||
try {
|
||||
final giftCardId = await ioniaService.getPaymentStatus(
|
||||
orderId: paymentInfo.ioniaOrder.id,
|
||||
paymentId: paymentInfo.ioniaOrder.paymentId);
|
||||
|
||||
if (giftCardId != null) {
|
||||
giftCard = await ioniaService.getGiftCard(id: giftCardId);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
error = e.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/anypay/any_pay_payment.dart';
|
||||
import 'package:cake_wallet/anypay/any_pay_payment_committed_info.dart';
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_anypay.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_merchant.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_tip.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_any_pay_payment_info.dart';
|
||||
|
||||
part 'ionia_purchase_merch_view_model.g.dart';
|
||||
|
||||
class IoniaMerchPurchaseViewModel = IoniaMerchPurchaseViewModelBase with _$IoniaMerchPurchaseViewModel;
|
||||
|
||||
abstract class IoniaMerchPurchaseViewModelBase with Store {
|
||||
IoniaMerchPurchaseViewModelBase({
|
||||
@required this.ioniaAnyPayService,
|
||||
@required this.amount,
|
||||
@required this.ioniaMerchant,
|
||||
}) {
|
||||
tipAmount = 0.0;
|
||||
percentage = 0.0;
|
||||
tips = <IoniaTip>[
|
||||
IoniaTip(percentage: 0, originalAmount: amount),
|
||||
IoniaTip(percentage: 15, originalAmount: amount),
|
||||
IoniaTip(percentage: 18, originalAmount: amount),
|
||||
IoniaTip(percentage: 20, originalAmount: amount),
|
||||
];
|
||||
selectedTip = tips.first;
|
||||
}
|
||||
|
||||
final double amount;
|
||||
|
||||
List<IoniaTip> tips;
|
||||
|
||||
@observable
|
||||
IoniaTip selectedTip;
|
||||
|
||||
final IoniaMerchant ioniaMerchant;
|
||||
|
||||
final IoniaAnyPay ioniaAnyPayService;
|
||||
|
||||
IoniaAnyPayPaymentInfo paymentInfo;
|
||||
|
||||
AnyPayPayment get invoice => paymentInfo?.anyPayPayment;
|
||||
|
||||
AnyPayPaymentCommittedInfo committedInfo;
|
||||
|
||||
@observable
|
||||
ExecutionState invoiceCreationState;
|
||||
|
||||
@observable
|
||||
ExecutionState invoiceCommittingState;
|
||||
|
||||
@observable
|
||||
double percentage;
|
||||
|
||||
@computed
|
||||
double get giftCardAmount => double.parse((amount + tipAmount).toStringAsFixed(2));
|
||||
|
||||
@computed
|
||||
double get billAmount => double.parse((giftCardAmount * (1 - (ioniaMerchant.discount / 100))).toStringAsFixed(2));
|
||||
|
||||
@observable
|
||||
double tipAmount;
|
||||
|
||||
@action
|
||||
void addTip(IoniaTip tip) {
|
||||
tipAmount = tip.additionalAmount;
|
||||
selectedTip = tip;
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> createInvoice() async {
|
||||
try {
|
||||
invoiceCreationState = IsExecutingState();
|
||||
paymentInfo = await ioniaAnyPayService.purchase(merchId: ioniaMerchant.id.toString(), amount: giftCardAmount);
|
||||
invoiceCreationState = ExecutedSuccessfullyState();
|
||||
} catch (e) {
|
||||
invoiceCreationState = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> commitPaymentInvoice() async {
|
||||
try {
|
||||
invoiceCommittingState = IsExecutingState();
|
||||
committedInfo = await ioniaAnyPayService.commitInvoice(invoice);
|
||||
invoiceCommittingState = ExecutedSuccessfullyState(payload: committedInfo);
|
||||
} catch (e) {
|
||||
invoiceCommittingState = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,11 +222,11 @@ abstract class SendViewModelBase with Store {
|
||||
case WalletType.bitcoin:
|
||||
final priority = _settingsStore.priority[_wallet.type];
|
||||
|
||||
return bitcoin.createBitcoinTransactionCredentials(outputs, priority);
|
||||
return bitcoin.createBitcoinTransactionCredentials(outputs, priority: priority);
|
||||
case WalletType.litecoin:
|
||||
final priority = _settingsStore.priority[_wallet.type];
|
||||
|
||||
return bitcoin.createBitcoinTransactionCredentials(outputs, priority);
|
||||
return bitcoin.createBitcoinTransactionCredentials(outputs, priority: priority);
|
||||
case WalletType.monero:
|
||||
final priority = _settingsStore.priority[_wallet.type];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user