From f550a5f426a41d488d6f74affba97f2963eaf9c4 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 8 Apr 2026 18:43:31 +0000 Subject: [PATCH] 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 --- .../actions/paymentTargets/PaymentTargetsViewModel.kt | 10 ++++++++-- .../amethyst/ui/note/UpdateZapAmountViewModel.kt | 8 +++++++- .../ui/screen/loggedIn/settings/NIP47SetupScreen.kt | 8 +++++--- .../ui/screen/loggedIn/wallet/WalletViewModel.kt | 10 +++++++--- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/paymentTargets/PaymentTargetsViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/paymentTargets/PaymentTargetsViewModel.kt index 37c63c9ec3..362df0c9cc 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/paymentTargets/PaymentTargetsViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/paymentTargets/PaymentTargetsViewModel.kt @@ -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() + } + } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UpdateZapAmountViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UpdateZapAmountViewModel.kt index 5125b31e9c..33a0903733 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UpdateZapAmountViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UpdateZapAmountViewModel.kt @@ -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("") } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/NIP47SetupScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/NIP47SetupScreen.kt index cfb2b6870c..eab38a6378 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/NIP47SetupScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/NIP47SetupScreen.kt @@ -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() }, ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletViewModel.kt index 2c22a44a68..ce8ceddfff 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletViewModel.kt @@ -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) {