Skip to content

Commit

Permalink
Expect getting firebase token to fail
Browse files Browse the repository at this point in the history
When called for the first time and there is no internet connection,
the token is not returned.
  • Loading branch information
Radiokot committed Nov 25, 2024
1 parent bd5daa1 commit 8a4db20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- Crash on launch when Google Play Services is disabled
- Inconsistent transaction fee for invoke smart contract
- Crashing when first launching the app offline

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class UpdateNotificationsSubscriptionUseCase(
private val accountRepository: AccountRepository,
private val notificationsPreferences: NotificationsPreferences,
private val notificationsBackend: NotificationsBackend,
private val application: Application
private val application: Application,
) {
constructor(application: Application) : this(
accountRepository = WalletDatabase.getDatabase(application).accountDao()
Expand All @@ -31,16 +31,28 @@ class UpdateNotificationsSubscriptionUseCase(
application = application
)

/**
* @return **true** on successful update
*/
suspend operator fun invoke(
isCcdTxEnabled: Boolean = notificationsPreferences.areCcdTxNotificationsEnabled,
isCis2TxEnabled: Boolean = notificationsPreferences.areCis2TxNotificationsEnabled
isCis2TxEnabled: Boolean = notificationsPreferences.areCis2TxNotificationsEnabled,
): Boolean {
val googleApiAvailability = GoogleApiAvailability.getInstance()
val resultCode = googleApiAvailability.isGooglePlayServicesAvailable(application)
var fcmToken = ""
val fcmToken = when (googleApiAvailability.isGooglePlayServicesAvailable(application)) {
ConnectionResult.SUCCESS -> {
try {
FirebaseMessaging.getInstance().token.await()
} catch (e: Exception) {
Log.e("token_not_available", e)
return false
}
}

if (resultCode == ConnectionResult.SUCCESS) {
fcmToken = FirebaseMessaging.getInstance().token.await()
else -> {
Log.e("google_api_not_available")
return false
}
}

val accounts = accountRepository.getAllDone()
Expand Down

0 comments on commit 8a4db20

Please sign in to comment.