Skip to content

Commit

Permalink
Using choreo with matrix token (2) (#1242)
Browse files Browse the repository at this point in the history
* using choreo with matrixç

* removed old stuff

* removed old stuff2

* merge and removed matrix-access-token header

---------

Co-authored-by: ggurdin <[email protected]>
Co-authored-by: ggurdin <[email protected]>
  • Loading branch information
3 people authored Jan 2, 2025
1 parent 2c88e60 commit e417af9
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 37 deletions.
8 changes: 8 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <DEVICE_NAME>`

# Special thanks
Expand Down
14 changes: 11 additions & 3 deletions assets/.env
Original file line number Diff line number Diff line change
@@ -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'

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'
8 changes: 0 additions & 8 deletions lib/pangea/config/environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ class Environment {
'https://[email protected]/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';
}
Expand Down
4 changes: 0 additions & 4 deletions lib/pangea/controllers/user_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions lib/pangea/network/requests.dart
Original file line number Diff line number Diff line change
@@ -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,
});

Expand Down Expand Up @@ -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!;
Expand Down
5 changes: 1 addition & 4 deletions lib/pangea/network/urls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
20 changes: 8 additions & 12 deletions lib/pangea/repo/subscription_repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,12 @@ class SubscriptionRepo {
String? userId,
List<SubscriptionDetails>? allProducts,
) async {
final Map<String, String> 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<String, dynamic> json = jsonDecode(res.body);
final RCSubscriptionResponseModel resp =
RCSubscriptionResponseModel.fromJson(
Expand Down Expand Up @@ -156,7 +152,7 @@ class RCSubscriptionResponseModel {
final String currentSubscriptionId = activeEntitlements[0];

final Map<String, dynamic> currentSubscriptionMetadata =
json['subscriber']['subscriptions'][currentSubscriptionId];
json['subscriptions'][currentSubscriptionId];

final DateTime expirationDate = DateTime.parse(
currentSubscriptionMetadata['expires_date'],
Expand Down Expand Up @@ -185,7 +181,7 @@ class RCSubscriptionResponseModel {
}

static List<String> getActiveEntitlements(Map<String, dynamic> json) {
return json['subscriber']['entitlements']
return json['entitlements']
.entries
.where(
(MapEntry<String, dynamic> entitlement) => DateTime.parse(
Expand All @@ -201,7 +197,7 @@ class RCSubscriptionResponseModel {
}

static List<String> getAllEntitlements(Map<String, dynamic> json) {
return json['subscriber']['entitlements']
return json['entitlements']
.entries
.map(
(MapEntry<String, dynamic> entitlement) =>
Expand Down

0 comments on commit e417af9

Please sign in to comment.