Skip to content

Commit

Permalink
Merge pull request #68 from pangeachat/trial-ui
Browse files Browse the repository at this point in the history
updates to subscription paywall flow
  • Loading branch information
wcjord authored Feb 19, 2024
2 parents 1baaa0e + fb07dc7 commit 7ad50e0
Show file tree
Hide file tree
Showing 17 changed files with 562 additions and 390 deletions.
7 changes: 6 additions & 1 deletion assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3927,5 +3927,10 @@
"placeholders": {
"sender": {}
}
}
},
"subscriptionPopupTitle": "This sentence could have a grammar mistake...",
"subscriptionPopupDesc": "Subscribe today to unlock translation and grammar correction!",
"seeOptions": "See options",
"continuedWithoutSubscription": "Continue without subscribing",
"trialPeriodExpired": "Your trial period has expired"
}
39 changes: 21 additions & 18 deletions lib/pangea/choreographer/controllers/choreographer.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import 'dart:async';
import 'dart:developer';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'package:sentry_flutter/sentry_flutter.dart';

import 'package:fluffychat/pages/chat/chat.dart';
import 'package:fluffychat/pangea/choreographer/controllers/alternative_translator.dart';
import 'package:fluffychat/pangea/choreographer/controllers/igc_controller.dart';
import 'package:fluffychat/pangea/choreographer/controllers/message_options.dart';
import 'package:fluffychat/pangea/constants/language_keys.dart';
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
import 'package:fluffychat/pangea/controllers/subscription_controller.dart';
import 'package:fluffychat/pangea/enum/edit_type.dart';
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
import 'package:fluffychat/pangea/models/class_model.dart';
Expand All @@ -21,6 +17,12 @@ import 'package:fluffychat/pangea/models/message_data_models.dart';
import 'package:fluffychat/pangea/models/widget_measurement.dart';
import 'package:fluffychat/pangea/utils/any_state_holder.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:fluffychat/pangea/utils/overlay.dart';
import 'package:fluffychat/pangea/widgets/igc/paywall_card.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

import '../../../widgets/matrix.dart';
import '../../enum/use_type.dart';
import '../../models/choreo_record.dart';
Expand Down Expand Up @@ -51,8 +53,6 @@ class Choreographer {
ChoreoMode choreoMode = ChoreoMode.igc;
final StreamController stateListener = StreamController();

bool toldToPay = false;

Choreographer(this.pangeaController, this.chatController) {
_initialize();
}
Expand All @@ -71,9 +71,14 @@ class Choreographer {
void send(BuildContext context) {
if (isFetching) return;

if (!pangeaController.subscriptionController.isSubscribed && !toldToPay) {
toldToPay = true;
pangeaController.subscriptionController.showPaywall(context);
if (pangeaController.subscriptionController.canSendStatus ==
CanSendStatus.showPaywall) {
OverlayUtil.showPositionedCard(
context: context,
cardToShow: const PaywallCard(),
cardSize: const Size(325, 375),
transformTargetId: inputTransformTargetKey,
);
return;
}

Expand Down Expand Up @@ -199,22 +204,20 @@ class Choreographer {
Future<void> getLanguageHelp([bool tokensOnly = false]) async {
try {
if (errorService.isError) return;
if (!pangeaController.subscriptionController.isSubscribed &&
pangeaController.subscriptionController.initialized) {
debugPrint('setting not subscribed error');
errorService.setErrorAndLock(
ChoreoError(
type: ChoreoErrorType.unsubscribed,
),
);
final CanSendStatus canSendStatus =
pangeaController.subscriptionController.canSendStatus;

if (canSendStatus != CanSendStatus.subscribed) {
return;
}

startLoading();
if (choreoMode == ChoreoMode.it &&
itController.isTranslationDone &&
!tokensOnly) {
debugger(when: kDebugMode);
}

await (choreoMode == ChoreoMode.it && !itController.isTranslationDone
? itController.getTranslationData(_useCustomInput)
: igc.getIGCTextData(tokensOnly: tokensOnly));
Expand Down
9 changes: 1 addition & 8 deletions lib/pangea/choreographer/controllers/error_service.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart';
import 'package:flutter/material.dart';

import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart';
import '../../utils/error_handler.dart';

enum ChoreoErrorType {
unknown,
classDisabled,
userDisabled,
unsubscribed,
}

class ChoreoError {
Expand All @@ -22,8 +21,6 @@ class ChoreoError {
return "Class Disabled";
case ChoreoErrorType.userDisabled:
return "User Disabled";
case ChoreoErrorType.unsubscribed:
return "Unsubscribed";
default:
return ErrorCopy(context, raw).title;
}
Expand All @@ -35,8 +32,6 @@ class ChoreoError {
return "Class Disabled";
case ChoreoErrorType.userDisabled:
return "User Disabled";
case ChoreoErrorType.unsubscribed:
return "Unsubscribed";
default:
return ErrorCopy(context, raw).body;
}
Expand All @@ -48,8 +43,6 @@ class ChoreoError {
return Icons.history_edu_outlined;
case ChoreoErrorType.userDisabled:
return Icons.history_edu_outlined;
case ChoreoErrorType.unsubscribed:
return Icons.lock_outline;
default:
return Icons.error_outline;
}
Expand Down
2 changes: 0 additions & 2 deletions lib/pangea/choreographer/widgets/has_error_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class ChoreographerHasErrorButton extends StatelessWidget {
),
),
);
} else if (error.type == ChoreoErrorType.unsubscribed) {
pangeaController.subscriptionController.showPaywall(context);
}
},
mini: true,
Expand Down
2 changes: 2 additions & 0 deletions lib/pangea/constants/local.key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ class PLocalKey {

// making this a random string so that it's harder to guess
static const String activatedTrialKey = '7C4EuKIsph';
static const String dismissedPaywall = 'dismissedPaywall';
static const String paywallBackoff = 'paywallBackoff';
}
9 changes: 0 additions & 9 deletions lib/pangea/controllers/class_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,6 @@ class ClassController extends BaseController {
(error, stackTrace) =>
ClassCodeUtil.messageSnack(context, ErrorCopy(context, error).body),
);
} else {
try {
//question for gabby: why do we need this in two places?
if (!_pangeaController.subscriptionController.isSubscribed) {
await _pangeaController.subscriptionController.showPaywall(context);
}
} catch (err) {
debugger(when: kDebugMode);
}
}
}

Expand Down
Loading

0 comments on commit 7ad50e0

Please sign in to comment.