Skip to content

Commit

Permalink
fix: fix issues with UserAlerts after app upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
HashEngineering committed Aug 10, 2024
1 parent aff521c commit 4882e17
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ data class BlockchainIdentityData(var creationState: CreationState = CreationSta
DONE,
DONE_AND_DISMISS // this should always be the last value
}

fun finishRestoration() {
this.restoring = false
this.creationStateErrorMessage = null
}
}

@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,9 @@ class PlatformSynchronizationService @Inject constructor(
}

// first check to see if there is a blockchain identity
if (blockchainIdentityDataDao.load() == null) {
// or if the previous restore is incomplete
val identityData = blockchainIdentityDataDao.load()
if (identityData == null || identityData.restoring) {
log.info("PreDownloadBlocks: checking for existing associated identity")

val identity = platformRepo.getIdentityFromPublicKeyId()
Expand Down
3 changes: 1 addition & 2 deletions wallet/src/de/schildbach/wallet/ui/SearchUserActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ class SearchUserActivity : LockScreenActivity(), OnItemClickListener, OnContactR

lifecycleScope.launch {
val enough = dashPayViewModel.hasEnoughCredits()
// TODO: before merging remove this
val shouldWarn = true // enough.isBalanceWarning()
val shouldWarn = enough.isBalanceWarning()
val isEmpty = enough.isBalanceWarning()

if (shouldWarn || isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import de.schildbach.wallet.security.SecurityFunctions
import de.schildbach.wallet.security.SecurityGuard
import de.schildbach.wallet.service.CoinJoinMode
import de.schildbach.wallet.service.platform.PlatformSyncService
import de.schildbach.wallet.ui.dashpay.UserAlert.Companion.INVITATION_NOTIFICATION_ICON
import de.schildbach.wallet.ui.dashpay.UserAlert.Companion.INVITATION_NOTIFICATION_TEXT
import de.schildbach.wallet.ui.dashpay.work.SendContactRequestOperation
import de.schildbach.wallet_test.R
import io.grpc.Status
import io.grpc.StatusRuntimeException
import kotlinx.coroutines.*
Expand Down Expand Up @@ -626,10 +627,8 @@ class CreateIdentityService : LifecycleService() {

// this alert will be shown or not based on the current balance and will be
// managed by NotificationsLiveData
val userAlert = UserAlert(R.string.invitation_notification_text,
R.drawable.ic_invitation)
val userAlert = UserAlert(INVITATION_NOTIFICATION_TEXT, INVITATION_NOTIFICATION_ICON)
userAlertDao.insert(userAlert)

}
}

Expand All @@ -656,7 +655,7 @@ class CreateIdentityService : LifecycleService() {
val creditFundingTransaction: AssetLockTransaction? = cftxs.find { it.identityId.bytes!!.contentEquals(identity) }

val existingBlockchainIdentityData = blockchainIdentityDataDao.load()
if (existingBlockchainIdentityData != null) {
if (existingBlockchainIdentityData != null && !(existingBlockchainIdentityData.restoring /*&& existingBlockchainIdentityData.creationStateErrorMessage != null*/)) {
log.info("Attempting restore of existing identity and username; save credit funding txid")
val blockchainIdentity = platformRepo.blockchainIdentity
blockchainIdentity.assetLockTransaction = creditFundingTransaction
Expand Down Expand Up @@ -732,7 +731,8 @@ class CreateIdentityService : LifecycleService() {

// We are finished recovering
platformRepo.updateIdentityCreationState(blockchainIdentityData, CreationState.DONE)

blockchainIdentityData.finishRestoration()
platformRepo.updateBlockchainIdentityData(blockchainIdentityData)
// Complete the entire process
platformRepo.updateIdentityCreationState(blockchainIdentityData, CreationState.DONE_AND_DISMISS)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ open class NotificationsLiveData(

val userAlert = userAlertDao.load(0L)
if (userAlert != null && platformRepo.shouldShowAlert()) {
results.add(NotificationItemUserAlert(userAlert.stringResId, userAlert.iconResId))
results.add(NotificationItemUserAlert(userAlert.stringResourceId, userAlert.iconResourceId))
}

val contactRequests = platformRepo.searchContacts(query, UsernameSortOrderBy.DATE_ADDED)
Expand Down
25 changes: 22 additions & 3 deletions wallet/src/de/schildbach/wallet/ui/dashpay/UserAlert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,28 @@ import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.room.Entity
import androidx.room.PrimaryKey
import de.schildbach.wallet_test.R
import java.util.*

@Entity(tableName = "user_alerts")
data class UserAlert(@PrimaryKey @StringRes val stringResId: Int,
@DrawableRes val iconResId: Int, var dismissed: Boolean = false,
val createdAt: Long = Date().time)
data class UserAlert(
@PrimaryKey val stringResId: Int,
@DrawableRes val iconResId: Int,
var dismissed: Boolean = false,
val createdAt: Long = Date().time)
{
companion object {
const val INVITATION_NOTIFICATION_TEXT = 1
val textMap = hashMapOf(INVITATION_NOTIFICATION_TEXT to R.string.invitation_notification_text)


const val INVITATION_NOTIFICATION_ICON = 1000
val iconMap = hashMapOf(INVITATION_NOTIFICATION_ICON to R.drawable.ic_invitation)
}


val stringResourceId: Int
get() = textMap[stringResId] ?: INVITATION_NOTIFICATION_TEXT
val iconResourceId: Int
get() = iconMap[iconResId] ?: INVITATION_NOTIFICATION_ICON
}

0 comments on commit 4882e17

Please sign in to comment.