From 25389f2aa7d6cb72b34688117a65768ed03d9afb Mon Sep 17 00:00:00 2001 From: HashEngineering Date: Thu, 6 Feb 2025 08:23:08 -0800 Subject: [PATCH] fix: eliminate crash when reset -> create/restore wallet (#1347) * fix: fix crash where old wallet was used during sync after create/restore wallet * fix: correct the costing of names rule for the UI --- .../de/schildbach/wallet/ui/dashpay/PlatformRepo.kt | 12 +++--------- .../ui/username/voting/RequestUserNameViewModel.kt | 8 ++++---- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/wallet/src/de/schildbach/wallet/ui/dashpay/PlatformRepo.kt b/wallet/src/de/schildbach/wallet/ui/dashpay/PlatformRepo.kt index 340654e68f..4bbc501344 100644 --- a/wallet/src/de/schildbach/wallet/ui/dashpay/PlatformRepo.kt +++ b/wallet/src/de/schildbach/wallet/ui/dashpay/PlatformRepo.kt @@ -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? { @@ -947,7 +948,7 @@ 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 @@ -955,14 +956,7 @@ class PlatformRepo @Inject constructor( 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) diff --git a/wallet/src/de/schildbach/wallet/ui/username/voting/RequestUserNameViewModel.kt b/wallet/src/de/schildbach/wallet/ui/username/voting/RequestUserNameViewModel.kt index cfda278daf..407f8c4c52 100644 --- a/wallet/src/de/schildbach/wallet/ui/username/voting/RequestUserNameViewModel.kt +++ b/wallet/src/de/schildbach/wallet/ui/username/voting/RequestUserNameViewModel.kt @@ -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 {