Skip to content

Commit

Permalink
fix: register for beta later if user had tried when coord was down
Browse files Browse the repository at this point in the history
Previously, if a user tried to register for beta and the coordinator was down, upon opening the app the next time, they would have a wallet but would not be registered for beta. This commit ensures that they are registered for the beta program regardless.
  • Loading branch information
Restioson committed Jun 4, 2024
1 parent 31cf415 commit dc9a5f4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mobile/lib/features/welcome/loading_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:get_10101/features/welcome/error_screen.dart';
import 'package:get_10101/features/welcome/onboarding.dart';
import 'package:get_10101/features/trade/trade_screen.dart';
import 'package:get_10101/features/wallet/wallet_screen.dart';
import 'package:get_10101/features/welcome/welcome_screen.dart';
import 'package:get_10101/logger/logger.dart';
import 'package:get_10101/util/preferences.dart';
import 'package:get_10101/util/file.dart';
Expand Down Expand Up @@ -41,7 +42,6 @@ class _LoadingScreenState extends State<LoadingScreen> {
final task = widget.task!;
logger.e(task.errorTitle, error: error, stackTrace: stackTrace);

// TODO why does this still not trigger onboarding flow after failing here?
await showDialog(
context: rootNavigatorKey.currentContext!,
builder: (context) =>
Expand All @@ -58,14 +58,22 @@ class _LoadingScreenState extends State<LoadingScreen> {
return;
}

final [position, seedPresent, backupRequired] = await Future.wait<dynamic>([
final [position, seedPresent, backupRequired, registeredForBeta] = await Future.wait<dynamic>([
Preferences.instance.getOpenPosition(),
isSeedFilePresent(),
Preferences.instance.isFullBackupRequired(),
Preferences.instance.isRegisteredForBeta(),
]);
FlutterNativeSplash.remove();

if (seedPresent) {
if (!registeredForBeta) {
logger.w("Registering for beta program despite having a seed; "
"onboarding flow was probably previously interrupted");
setState(() => message = "Registering for beta program");
await resumeRegisterForBeta();
}

if (backupRequired) {
setState(() => message = "Creating initial backup!");
fullBackup().then((value) {
Expand Down
11 changes: 11 additions & 0 deletions mobile/lib/features/welcome/welcome_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ class _WelcomeScreenState extends State<WelcomeScreen> {
logger.i("Successfully stored the contact: $_contact .");
await api.initNewMnemonic(targetSeedFilePath: seedPath);
logger.d("Registering user with $_contact & $_referralCode");

await Preferences.instance.setReferralCode(_referralCode);
await api.registerBeta(contact: _contact, referralCode: _referralCode);
await Preferences.instance.setRegisteredForBeta();
}

@override
Expand All @@ -280,3 +283,11 @@ class _WelcomeScreenState extends State<WelcomeScreen> {
}));
}
}

/// Resume a previously incomplete onboarding flow by registering for beta
Future<void> resumeRegisterForBeta() async {
await api.registerBeta(
contact: await Preferences.instance.getContactDetails(),
referralCode: await Preferences.instance.getReferralCode());
await Preferences.instance.setRegisteredForBeta();
}
24 changes: 24 additions & 0 deletions mobile/lib/util/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class Preferences {
static const fullBackup = "fullBackup";
static const logLevelTrace = "logLevelTrace";
static const _hasSeenReferralDialogTimePassed = "hasSeenReferralDialogTimePassed";
static const registeredForBeta = "registeredForBeta";

/// The referral code that the user signed up with
static const referralCode = "referralCode";

Future<bool> setLogLevelTrace(bool trace) async {
SharedPreferences preferences = await SharedPreferences.getInstance();
Expand Down Expand Up @@ -54,6 +58,26 @@ class Preferences {
preferences.remove(openPosition);
}

Future<bool> setRegisteredForBeta() async {
SharedPreferences preferences = await SharedPreferences.getInstance();
return preferences.setBool(registeredForBeta, true);
}

Future<bool> isRegisteredForBeta() async {
SharedPreferences preferences = await SharedPreferences.getInstance();
return preferences.getBool(registeredForBeta) ?? false;
}

Future<bool> setReferralCode(String code) async {
SharedPreferences preferences = await SharedPreferences.getInstance();
return preferences.setString(referralCode, code);
}

Future<String> getReferralCode() async {
SharedPreferences preferences = await SharedPreferences.getInstance();
return preferences.getString(referralCode) ?? "";
}

Future<bool> setContactDetails(String value) async {
SharedPreferences preferences = await SharedPreferences.getInstance();
return preferences.setString(contactDetails, value);
Expand Down

0 comments on commit dc9a5f4

Please sign in to comment.