mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-10 21:04:53 +00:00
44efd56acb
* display virtual card * fix formatting
105 lines
2.6 KiB
Dart
105 lines
2.6 KiB
Dart
import 'package:cake_wallet/ionia/ionia.dart';
|
|
import 'package:cake_wallet/ionia/ionia_create_state.dart';
|
|
import 'package:cake_wallet/ionia/ionia_merchant.dart';
|
|
import 'package:cake_wallet/ionia/ionia_merchant_service.dart';
|
|
import 'package:cake_wallet/ionia/ionia_virtual_card.dart';
|
|
import 'package:mobx/mobx.dart';
|
|
part 'ionia_view_model.g.dart';
|
|
|
|
class IoniaViewModel = IoniaViewModelBase with _$IoniaViewModel;
|
|
|
|
abstract class IoniaViewModelBase with Store {
|
|
|
|
IoniaViewModelBase({this.ioniaService, this.ioniaMerchantService})
|
|
: createUserState = IoniaCreateStateSuccess(),
|
|
otpState = IoniaOtpSendDisabled(),
|
|
cardState = IoniaNoCardState(), ioniaMerchants = [] {
|
|
_getMerchants().then((value){
|
|
ioniaMerchants = value;
|
|
});
|
|
_getAuthStatus().then((value) => isLoggedIn = value);
|
|
}
|
|
|
|
final IoniaMerchantService ioniaMerchantService;
|
|
|
|
final IoniaService ioniaService;
|
|
|
|
@observable
|
|
IoniaCreateAccountState createUserState;
|
|
|
|
@observable
|
|
IoniaOtpState otpState;
|
|
|
|
@observable
|
|
IoniaCreateCardState createCardState;
|
|
|
|
@observable
|
|
IoniaFetchCardState cardState;
|
|
|
|
@observable
|
|
List<IoniaMerchant> ioniaMerchants;
|
|
|
|
@observable
|
|
String email;
|
|
|
|
@observable
|
|
String otp;
|
|
|
|
@observable
|
|
bool isLoggedIn;
|
|
|
|
@action
|
|
Future<void> createUser(String email) async {
|
|
createUserState = IoniaCreateStateLoading();
|
|
try {
|
|
await ioniaService.createUser(email);
|
|
|
|
createUserState = IoniaCreateStateSuccess();
|
|
} on Exception catch (e) {
|
|
createUserState = IoniaCreateStateFailure(error: e.toString());
|
|
}
|
|
}
|
|
|
|
@action
|
|
Future<void> verifyEmail(String code) async {
|
|
try {
|
|
otpState = IoniaOtpValidating();
|
|
await ioniaService.verifyEmail(code);
|
|
otpState = IoniaOtpSuccess();
|
|
} catch (_) {
|
|
otpState = IoniaOtpFailure(error: 'Invalid OTP. Try again');
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
Future<void> _getCard() async {
|
|
cardState = IoniaFetchingCard();
|
|
try {
|
|
final card = await ioniaService.getCard();
|
|
|
|
cardState = IoniaCardSuccess(card: card);
|
|
} catch (_) {
|
|
cardState = IoniaFetchCardFailure();
|
|
}
|
|
}
|
|
|
|
Future<List<IoniaMerchant>> _getMerchants()async{
|
|
return await ioniaMerchantService.getMerchants();
|
|
}
|
|
}
|