fix: consolidate wallet setup saves into a single signer call
All three saves (zap settings, lightning address, payment targets) now run sequentially inside one accountViewModel.launchSigner block, so the signer is only invoked once per save instead of three times. - Extract sendPostSuspend() from UpdateZapAmountViewModel.sendPost() - Extract saveLnAddressSuspend() from WalletViewModel.saveLnAddress() - Extract savePaymentTargetsSuspend() from PaymentTargetsViewModel.savePaymentTargets() - NIP47SetupScreen.onPost calls all three suspend fns in one launchSigner https://claude.ai/code/session_017NPhwCnSzCuMn9sTX3ca37
This commit is contained in:
+8
-2
@@ -79,9 +79,15 @@ class PaymentTargetsViewModel : ViewModel() {
|
||||
fun savePaymentTargets() {
|
||||
if (isModified) {
|
||||
accountViewModel.launchSigner {
|
||||
account.savePaymentTargets(_paymentTargets.value)
|
||||
refresh()
|
||||
savePaymentTargetsSuspend()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun savePaymentTargetsSuspend() {
|
||||
if (isModified) {
|
||||
account.savePaymentTargets(_paymentTargets.value)
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -84,6 +84,12 @@ class UpdateZapAmountViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
fun sendPost() {
|
||||
accountViewModel.launchSigner {
|
||||
sendPostSuspend()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun sendPostSuspend() {
|
||||
val nip47Update =
|
||||
if (walletConnectRelay.text.isNotBlank() && walletConnectPubkey.text.isNotBlank()) {
|
||||
val pubkeyHex =
|
||||
@@ -110,7 +116,7 @@ class UpdateZapAmountViewModel : ViewModel() {
|
||||
null
|
||||
}
|
||||
|
||||
accountViewModel.updateZapAmounts(amountSet, selectedZapType, nip47Update)
|
||||
accountViewModel.account.updateZapAmounts(amountSet, selectedZapType, nip47Update)
|
||||
|
||||
nextAmount = TextFieldValue("")
|
||||
}
|
||||
|
||||
+5
-3
@@ -105,9 +105,11 @@ fun NIP47SetupScreen(
|
||||
nav.popBack()
|
||||
},
|
||||
onPost = {
|
||||
postViewModel.sendPost()
|
||||
walletViewModel.saveLnAddress()
|
||||
paymentTargetsViewModel.savePaymentTargets()
|
||||
accountViewModel.launchSigner {
|
||||
postViewModel.sendPostSuspend()
|
||||
walletViewModel.saveLnAddressSuspend()
|
||||
paymentTargetsViewModel.savePaymentTargetsSuspend()
|
||||
}
|
||||
nav.popBack()
|
||||
},
|
||||
)
|
||||
|
||||
+7
-3
@@ -171,13 +171,17 @@ class WalletViewModel : ViewModel() {
|
||||
|
||||
fun saveLnAddress() {
|
||||
val accountVm = accountViewModel ?: return
|
||||
val acc = account ?: return
|
||||
accountVm.launchSigner {
|
||||
val event = acc.userMetadata.sendNewUserMetadata(lnAddress = _lnAddress.value)
|
||||
acc.sendLiterallyEverywhere(event)
|
||||
saveLnAddressSuspend()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun saveLnAddressSuspend() {
|
||||
val acc = account ?: return
|
||||
val event = acc.userMetadata.sendNewUserMetadata(lnAddress = _lnAddress.value)
|
||||
acc.sendLiterallyEverywhere(event)
|
||||
}
|
||||
|
||||
fun fetchBalance() {
|
||||
val acc = account ?: return
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
|
||||
Reference in New Issue
Block a user