getUserPhone static method

Future<int?> getUserPhone()

Logged-in user's phone: the verified user's phone first, then gkUserPhone. gkUserPhone is written when the OTP is sent, so on its own it can hold a number that was typed but never verified.

Implementation

static Future<int?> getUserPhone() async {
  final results = await Future.wait([
    cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkUserPhone)!),
    cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkVerifiedUserKey)!),
  ]);
  final storedPhone = results[0];
  final verifiedUser = results[1];

  int? verifiedPhone;
  try {
    final user = jsonDecode(verifiedUser ?? '{}');
    if (user is Map) verifiedPhone = toPhoneValue(user['phone']);
  } catch (_) {}

  return verifiedPhone ?? toPhoneValue(storedPhone);
}