From e417af93fad57e3021890219ef147260a283090c Mon Sep 17 00:00:00 2001 From: Brord van Wierst Date: Thu, 2 Jan 2025 15:09:06 +0100 Subject: [PATCH] Using choreo with matrix token (2) (#1242) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * using choreo with matrixç * removed old stuff * removed old stuff2 * merge and removed matrix-access-token header --------- Co-authored-by: ggurdin <46800240+ggurdin@users.noreply.github.com> Co-authored-by: ggurdin --- .env | 8 ++++++++ README.md | 1 + assets/.env | 14 +++++++++++--- lib/pangea/config/environment.dart | 8 -------- lib/pangea/controllers/user_controller.dart | 4 ---- lib/pangea/network/requests.dart | 8 ++------ lib/pangea/network/urls.dart | 5 +---- lib/pangea/repo/subscription_repo.dart | 20 ++++++++------------ 8 files changed, 31 insertions(+), 37 deletions(-) diff --git a/.env b/.env index dd7ed3cd8f..8a6acb7a42 100644 --- a/.env +++ b/.env @@ -3,4 +3,12 @@ CHOREO_API = 'https://api.staging.pangea.chat' FRONTEND_URL='https://app.staging.pangea.chat' SYNAPSE_URL = 'matrix.staging.pangea.chat' CHOREO_API_KEY = 'e6fa9fa97031ba0c852efe78457922f278a2fbc109752fe18e465337699e9873' + +RC_GOOGLE_KEY = 'goog_paQMrzFKGzuWZvcMTPkkvIsifJe' +RC_IOS_KEY = 'appl_DUPqnxuLjkBLzhBPTWeDjqNENuv' +RC_STRIPE_KEY = 'strp_YWZxWUeEfvagiefDNoofinaRCOl' +RC_OFFERING_NAME = 'test' + +STRIPE_MANAGEMENT_LINK = 'https://billing.stripe.com/p/login/test_9AQaI8d3O9lmaXe5kk' + SUPPORT_SPACE_ID = '!gqSNSkvwTpgumyjLsV:staging.pangea.chat' \ No newline at end of file diff --git a/README.md b/README.md index 3e3a4d53ac..0642b7dcf8 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ * Download Android File Transfer here: ​​https://www.android.com/filetransfer/ * To run the app from VSCode terminal: * On web, run `flutter run -d chrome –hot` + * Or as a web server (Usage with WSL or remote connect) `flutter run --release -d web-server -web-port=3000` * On mobile device or simulator, run `flutter run –hot -d ` # Special thanks diff --git a/assets/.env b/assets/.env index dd7ed3cd8f..b3fcafe965 100644 --- a/assets/.env +++ b/assets/.env @@ -1,6 +1,14 @@ -BASE_API='https://api.staging.pangea.chat/api/v1' CHOREO_API = 'https://api.staging.pangea.chat' -FRONTEND_URL='https://app.staging.pangea.chat' +FRONTEND_URL = 'https://app.staging.pangea.chat' + SYNAPSE_URL = 'matrix.staging.pangea.chat' CHOREO_API_KEY = 'e6fa9fa97031ba0c852efe78457922f278a2fbc109752fe18e465337699e9873' -SUPPORT_SPACE_ID = '!gqSNSkvwTpgumyjLsV:staging.pangea.chat' \ No newline at end of file + +RC_GOOGLE_KEY = 'goog_paQMrzFKGzuWZvcMTPkkvIsifJe' +RC_IOS_KEY = 'appl_DUPqnxuLjkBLzhBPTWeDjqNENuv' +RC_STRIPE_KEY = 'strp_YWZxWUeEfvagiefDNoofinaRCOl' +RC_OFFERING_NAME = 'test' + +STRIPE_MANAGEMENT_LINK = 'https://billing.stripe.com/p/login/test_9AQaI8d3O9lmaXe5kk' + +SUPPORT_SPACE_ID = '!gqSNSkvwTpgumyjLsV:staging.pangea.chat' diff --git a/lib/pangea/config/environment.dart b/lib/pangea/config/environment.dart index 77002fc28e..b042f3ff28 100644 --- a/lib/pangea/config/environment.dart +++ b/lib/pangea/config/environment.dart @@ -46,14 +46,6 @@ class Environment { 'https://c2fd19ab2cdc4ebb939a32d01c0e9fa1@o225078.ingest.sentry.io/1376295'; } - static String get rcProjectId { - return dotenv.env["RC_PROJECT"] ?? 'a499dc21'; - } - - static String get rcKey { - return dotenv.env["RC_KEY"] ?? 'sk_eVGBdPyInaOfJrKlPBgFVnRynqKJB'; - } - static String get rcGoogleKey { return dotenv.env["RC_GOOGLE_KEY"] ?? 'goog_paQMrzFKGzuWZvcMTPkkvIsifJe'; } diff --git a/lib/pangea/controllers/user_controller.dart b/lib/pangea/controllers/user_controller.dart index f6ed36e374..6a66532b48 100644 --- a/lib/pangea/controllers/user_controller.dart +++ b/lib/pangea/controllers/user_controller.dart @@ -21,10 +21,6 @@ class UserController extends BaseController { /// Convenience function that returns the user ID currently stored in the client. String? get userId => _pangeaController.matrixState.client.userID; - /// Convenience function that returns the accessToken currently stored in the client. - String? get _matrixAccessToken => - _pangeaController.matrixState.client.accessToken; - /// Cached version of the user profile, so it doesn't have /// to be read in from client's account data each time it is accessed. Profile? _cachedProfile; diff --git a/lib/pangea/network/requests.dart b/lib/pangea/network/requests.dart index 5cad3cf6c1..f08a6c2c6f 100644 --- a/lib/pangea/network/requests.dart +++ b/lib/pangea/network/requests.dart @@ -1,20 +1,18 @@ import 'dart:convert'; import 'package:flutter/material.dart'; - import 'package:http/http.dart' as http; import 'package:sentry_flutter/sentry_flutter.dart'; class Requests { late String? baseUrl; + // Matrix access token late String? accessToken; - late String? matrixAccessToken; late String? choreoApiKey; //Question: How can we make baseUrl optional? Requests({ this.accessToken, this.baseUrl = '', - this.matrixAccessToken, this.choreoApiKey, }); @@ -134,9 +132,7 @@ class Requests { }; if (accessToken != null) { headers["Authorization"] = 'Bearer ${accessToken!}'; - } - if (matrixAccessToken != null) { - headers["Matrix-Access-Token"] = matrixAccessToken!; + //headers["Matrix-Access-Token"] = accessToken!; } if (choreoApiKey != null) { headers['api_key'] = choreoApiKey!; diff --git a/lib/pangea/network/urls.dart b/lib/pangea/network/urls.dart index 10e2162c80..76ac4d4d5f 100644 --- a/lib/pangea/network/urls.dart +++ b/lib/pangea/network/urls.dart @@ -67,12 +67,9 @@ class PApiUrls { static String lemmaDictionary = "${PApiUrls.choreoEndpoint}/lemma_definition"; ///-------------------------------- revenue cat -------------------------- - - static String rcApiV1 = "https://api.revenuecat.com/v1"; - static String rcAppsChoreo = "${PApiUrls.subscriptionEndpoint}/app_ids"; static String rcProductsChoreo = "${PApiUrls.subscriptionEndpoint}/all_products"; - static String rcSubscription = "$rcApiV1/subscribers"; + static String rcSubscription = PApiUrls.subscriptionEndpoint; } diff --git a/lib/pangea/repo/subscription_repo.dart b/lib/pangea/repo/subscription_repo.dart index 4ca735123b..cc7d084aa9 100644 --- a/lib/pangea/repo/subscription_repo.dart +++ b/lib/pangea/repo/subscription_repo.dart @@ -64,16 +64,12 @@ class SubscriptionRepo { String? userId, List? allProducts, ) async { - final Map stripeHeaders = { - 'Content-type': 'application/json', - 'Accept': 'application/json', - 'Authorization': 'Bearer ${Environment.rcStripeKey}', - }; - final String url = "${PApiUrls.rcSubscription}/$userId"; - final http.Response res = await http.get( - Uri.parse(url), - headers: stripeHeaders, + final Requests req = Requests( + choreoApiKey: Environment.choreoApiKey, + accessToken: MatrixState.pangeaController.userController.accessToken, ); + + final http.Response res = await req.get(url: PApiUrls.rcSubscription); final Map json = jsonDecode(res.body); final RCSubscriptionResponseModel resp = RCSubscriptionResponseModel.fromJson( @@ -156,7 +152,7 @@ class RCSubscriptionResponseModel { final String currentSubscriptionId = activeEntitlements[0]; final Map currentSubscriptionMetadata = - json['subscriber']['subscriptions'][currentSubscriptionId]; + json['subscriptions'][currentSubscriptionId]; final DateTime expirationDate = DateTime.parse( currentSubscriptionMetadata['expires_date'], @@ -185,7 +181,7 @@ class RCSubscriptionResponseModel { } static List getActiveEntitlements(Map json) { - return json['subscriber']['entitlements'] + return json['entitlements'] .entries .where( (MapEntry entitlement) => DateTime.parse( @@ -201,7 +197,7 @@ class RCSubscriptionResponseModel { } static List getAllEntitlements(Map json) { - return json['subscriber']['entitlements'] + return json['entitlements'] .entries .map( (MapEntry entitlement) =>