mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 01:37:54 +00:00
add userID pref and generate it if it isn't set
This commit is contained in:
parent
3b993135da
commit
b4c16ec0b0
2 changed files with 26 additions and 0 deletions
|
@ -317,6 +317,10 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ref
|
||||
.read(prefsChangeNotifierProvider)
|
||||
.userID; // Just reading the ref should set it if it's not already set
|
||||
} catch (e, s) {
|
||||
Logger.print("$e $s", normalLength: false);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:stackwallet/utilities/constants.dart';
|
|||
import 'package:stackwallet/utilities/enums/backup_frequency_type.dart';
|
||||
import 'package:stackwallet/utilities/enums/languages_enum.dart';
|
||||
import 'package:stackwallet/utilities/enums/sync_type_enum.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class Prefs extends ChangeNotifier {
|
||||
Prefs._();
|
||||
|
@ -38,6 +39,7 @@ class Prefs extends ChangeNotifier {
|
|||
_startupWalletId = await _getStartupWalletId();
|
||||
_externalCalls = await _getHasExternalCalls();
|
||||
_familiarity = await _getHasFamiliarity();
|
||||
_userID = await _getUserID();
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
@ -602,4 +604,24 @@ class Prefs extends ChangeNotifier {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
String? _userID;
|
||||
String? get userID => _userID;
|
||||
|
||||
Future<String?> _getUserID() async {
|
||||
String? userID = await DB.instance
|
||||
.get<dynamic>(boxName: DB.boxNamePrefs, key: "userID") as String?;
|
||||
if (userID == null) {
|
||||
userID = const Uuid().v4();
|
||||
await saveUserID(userID);
|
||||
}
|
||||
return userID;
|
||||
}
|
||||
|
||||
Future<void> saveUserID(String userID) async {
|
||||
_userID = userID;
|
||||
await DB.instance
|
||||
.put<dynamic>(boxName: DB.boxNamePrefs, key: "userID", value: _userID);
|
||||
// notifyListeners();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue