From 0b60a03e745d4ad53ce193e7bd118a893722d12a Mon Sep 17 00:00:00 2001 From: M Date: Tue, 26 Jul 2022 12:54:41 +0100 Subject: [PATCH] Remove IoniaTokenService --- lib/di.dart | 3 -- lib/ionia/ionia_token_service.dart | 72 ------------------------------ 2 files changed, 75 deletions(-) delete mode 100644 lib/ionia/ionia_token_service.dart diff --git a/lib/di.dart b/lib/di.dart index 0ffc2a233..9b2d70b38 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -141,7 +141,6 @@ import 'package:cake_wallet/entities/template.dart'; import 'package:cake_wallet/exchange/exchange_template.dart'; import 'package:cake_wallet/.secrets.g.dart' as secrets; import 'package:cake_wallet/src/screens/dashboard/widgets/address_page.dart'; -import 'package:cake_wallet/ionia/ionia_token_service.dart'; import 'package:cake_wallet/anypay/anypay_api.dart'; import 'package:cake_wallet/view_model/ionia/ionia_gift_card_details_view_model.dart'; import 'package:cake_wallet/src/screens/ionia/cards/ionia_payment_status_page.dart'; @@ -250,8 +249,6 @@ Future setup( getIt.get(), (WalletType type) => getIt.get(param1: type))); - getIt.registerFactory(() => IoniaTokenService(getIt.get())); - getIt.registerFactoryParam((type, _) => WalletNewVM(getIt.get(), getIt.get(param1: type), _walletInfoSource, diff --git a/lib/ionia/ionia_token_service.dart b/lib/ionia/ionia_token_service.dart deleted file mode 100644 index 191595995..000000000 --- a/lib/ionia/ionia_token_service.dart +++ /dev/null @@ -1,72 +0,0 @@ -import 'dart:convert'; -import 'package:http/http.dart'; -import 'package:flutter_secure_storage/flutter_secure_storage.dart'; -import 'package:cake_wallet/ionia/ionia_token_data.dart'; -import 'package:cake_wallet/.secrets.g.dart'; - -String basicAuth(String username, String password) => - 'Basic ' + base64Encode(utf8.encode('$username:$password')); - -abstract class TokenService { - TokenService(this.flutterSecureStorage); - - String get serviceName; - String get oauthUrl; - final FlutterSecureStorage flutterSecureStorage; - - String get _storeKey => '${serviceName}_oauth_token'; - - Future getToken() async { - final storedTokenJson = await flutterSecureStorage.read(key: _storeKey); - IoniaTokenData token; - - if (storedTokenJson != null) { - token = IoniaTokenData.fromJson(storedTokenJson); - } else { - token = await _fetchNewToken(); - await _storeToken(token); - } - - if (token.isExpired) { - token = await _fetchNewToken(); - await _storeToken(token); - } - - return token; - } - - Future _fetchNewToken() async { - final basic = basicAuth(ioniaClientId, ioniaClientSecret); - final body = {'grant_type': 'client_credentials', 'scope': 'cake_dev'}; - final response = await post( - oauthUrl, - headers: { - 'Authorization': basic, - 'Content-Type': 'application/x-www-form-urlencoded'}, - encoding: Encoding.getByName('utf-8'), - body: body); - - if (response.statusCode != 200) { - // throw exception - return null; - } - - return IoniaTokenData.fromJson(response.body); - } - - Future _storeToken(IoniaTokenData token) async { - await flutterSecureStorage.write(key: _storeKey, value: token.toJson()); - } - -} - -class IoniaTokenService extends TokenService { - IoniaTokenService(FlutterSecureStorage flutterSecureStorage) - : super(flutterSecureStorage); - - @override - String get serviceName => 'Ionia'; - - @override - String get oauthUrl => 'https://auth.craypay.com/connect/token'; -} \ No newline at end of file