Skip to content

Commit

Permalink
fix: eliminate crash when reset -> create/restore wallet (#1347)
Browse files Browse the repository at this point in the history
* fix: fix crash where old wallet was used during sync after create/restore wallet

* fix: correct the costing of names rule for the UI
  • Loading branch information
HashEngineering authored Feb 6, 2025
1 parent ed0cc3a commit 25389f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
12 changes: 3 additions & 9 deletions wallet/src/de/schildbach/wallet/ui/dashpay/PlatformRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ class PlatformRepo @Inject constructor(
if (includeInvitations) {
invitationsDao.clear()
}
authenticationGroupExtension = null // remove references to current wallet
}

fun getBlockchainIdentityKey(index: Int, keyParameter: KeyParameter?): IDeterministicKey? {
Expand All @@ -947,22 +948,15 @@ class PlatformRepo @Inject constructor(
} else {
authenticationChain
}
val key = decryptedChain.getKey(index) // watchingKey
val key = decryptedChain.getKey(index)
Preconditions.checkState(key.path.last().isHardened)
return key

}

fun getIdentityFromPublicKeyId(): Identity? {
val encryptionKey = getWalletEncryptionKey()
val firstIdentityKey = try {
getBlockchainIdentityKey(0, encryptionKey) ?: return null
} catch (e: KeyCrypterException.InvalidCipherText) {
log.info("failure to decrypt identity keychain", e)
log.info("attempt again to obtain the wallet encryption key and the identity")
val encryptionKeyTwo = getWalletEncryptionKey()
getBlockchainIdentityKey(0, encryptionKeyTwo) ?: return null
}
val firstIdentityKey = getBlockchainIdentityKey(0, encryptionKey) ?: return null

return try {
platform.stateRepository.fetchIdentityFromPubKeyHash(firstIdentityKey.pubKeyHash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ class RequestUserNameViewModel @Inject constructor(
val identityBalance = _identityBalance.value
val walletBalance = _walletBalance.value
val enoughBalance = when {
identityBalance > 0L && contestable -> Coin.valueOf(identityBalance / 1000) + walletBalance > Coin.valueOf(CONTEST_DOCUMENT_FEE / 1000)
identityBalance > 0L && !contestable -> Coin.valueOf(identityBalance / 1000) + walletBalance > Coin.valueOf(NON_CONTEST_DOCUMENT_FEE / 1000)
identityBalance == 0L && contestable -> walletBalance > Constants.DASH_PAY_FEE_CONTESTED
identityBalance == 0L && !contestable -> walletBalance > Constants.DASH_PAY_FEE
identityBalance > 0L && contestable -> (Coin.valueOf(identityBalance / 1000) + walletBalance) > Coin.valueOf(CONTEST_DOCUMENT_FEE / 1000)
identityBalance > 0L && !contestable -> (Coin.valueOf(identityBalance / 1000) + walletBalance) > Coin.valueOf(NON_CONTEST_DOCUMENT_FEE / 1000)
identityBalance == 0L && contestable -> walletBalance >= Constants.DASH_PAY_FEE_CONTESTED
identityBalance == 0L && !contestable -> walletBalance >= Constants.DASH_PAY_FEE
else -> false // how can we get here?
}
_uiState.update {
Expand Down

0 comments on commit 25389f2

Please sign in to comment.