mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
Delete CakePay Auth-token if the API returns 401 (#3538)
* delete cakepay auth token on 401 * fix cakepay auth refresh * fix Cake Pay error handling
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cake_wallet/cake_pay/src/cake_pay_exceptions.dart';
|
||||
import 'package:cake_wallet/order/order_provider_description.dart';
|
||||
import 'package:cake_wallet/order/order.dart';
|
||||
import 'package:cake_wallet/order/order_source_description.dart';
|
||||
@@ -221,6 +222,8 @@ abstract class CakePayBuyCardViewModelBase with Store {
|
||||
orders.add(orderRecord);
|
||||
updateRemainingTime();
|
||||
_startExpirationTimer();
|
||||
} on CakePayUnauthorizedException {
|
||||
rethrow;
|
||||
} catch (e) {
|
||||
sendViewModel.state = FailureState(
|
||||
sendViewModel.translateErrorMessage(e, walletType, sendViewModel.wallet.currency));
|
||||
@@ -275,8 +278,6 @@ abstract class CakePayBuyCardViewModelBase with Store {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> logout() async => await _cakePayService.logout();
|
||||
|
||||
void _startExpirationTimer() {
|
||||
_timer?.cancel();
|
||||
_timer = Timer.periodic(Duration(seconds: 1), (_) {
|
||||
|
||||
@@ -78,7 +78,6 @@ abstract class CakePayCardsListViewModelBase with Store {
|
||||
};
|
||||
|
||||
String searchString;
|
||||
String? username;
|
||||
int page;
|
||||
|
||||
late Country _initialSelectedCountry;
|
||||
@@ -87,6 +86,9 @@ abstract class CakePayCardsListViewModelBase with Store {
|
||||
late bool _initialDisplayDenominationsCards;
|
||||
late bool _initialDisplayCustomValueCards;
|
||||
|
||||
@observable
|
||||
String? username;
|
||||
|
||||
@observable
|
||||
List<CakePayCard> userCards;
|
||||
|
||||
@@ -189,12 +191,9 @@ abstract class CakePayCardsListViewModelBase with Store {
|
||||
|
||||
@action
|
||||
Future<void> checkAuth() async {
|
||||
authFuture = ObservableFuture(cakePayService.isLogged());
|
||||
|
||||
final logged = await authFuture!;
|
||||
if (logged) {
|
||||
username = await cakePayService.getUserEmail();
|
||||
}
|
||||
final logged = await cakePayService.isLogged();
|
||||
username = logged ? await cakePayService.getUserEmail() : null;
|
||||
authFuture = ObservableFuture.value(logged);
|
||||
}
|
||||
|
||||
@action
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cake_wallet/buy/buy_provider_description.dart';
|
||||
import 'package:cake_wallet/cake_pay/src/cake_pay_exceptions.dart';
|
||||
import 'package:cake_wallet/cake_pay/src/models/cake_pay_order.dart';
|
||||
import 'package:cake_wallet/cake_pay/src/services/cake_pay_service.dart';
|
||||
import 'package:cake_wallet/core/utilities.dart';
|
||||
@@ -64,6 +65,9 @@ abstract class OrderDetailsViewModelBase with Store {
|
||||
@observable
|
||||
ObservableList<StandartListItem> items;
|
||||
|
||||
@observable
|
||||
bool isCakePaySessionExpired = false;
|
||||
|
||||
final CakePayService cakePayService;
|
||||
final Box<Order> orders;
|
||||
OrderProvider? _provider;
|
||||
@@ -74,7 +78,9 @@ abstract class OrderDetailsViewModelBase with Store {
|
||||
@action
|
||||
Future<void> _updateOrder() async {
|
||||
try {
|
||||
if (_provider == null) return;
|
||||
if (_provider == null || isCakePaySessionExpired) {
|
||||
return;
|
||||
}
|
||||
|
||||
final updatedOrderObj = await _provider!.findOrderById(order.id);
|
||||
final updatedOrder = updatedOrderObj.$1;
|
||||
@@ -95,6 +101,9 @@ abstract class OrderDetailsViewModelBase with Store {
|
||||
}
|
||||
|
||||
_updateItems();
|
||||
} on CakePayUnauthorizedException {
|
||||
timer?.cancel();
|
||||
isCakePaySessionExpired = true;
|
||||
} catch (e) {
|
||||
printV(e.toString());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user