From 341994e505412c6c1106f5124b57ee3a5bd04520 Mon Sep 17 00:00:00 2001 From: davotoula Date: Mon, 6 Oct 2025 12:50:13 +0200 Subject: [PATCH 1/3] The putOrRemove(key: String, event: Any?) signature loses type information. When JsonMapper.toJson() tries to serialize, it sees Any? and can't find the serializer for Nip47URI, causing: SerializationException: Serializer for class 'Any' is not found --- .../java/com/vitorpamplona/amethyst/LocalPreferences.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt index 8a48aca824..1ba92a1df1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt @@ -325,7 +325,13 @@ object LocalPreferences { PrefKeys.DEFAULT_DISCOVERY_FOLLOW_LIST, settings.defaultDiscoveryFollowList.value, ) - putOrRemove(PrefKeys.ZAP_PAYMENT_REQUEST_SERVER, settings.zapPaymentRequest.value?.denormalize()) + + val nwcToBeSaved = settings.zapPaymentRequest.value?.denormalize() + if (nwcToBeSaved != null) { + putString(PrefKeys.ZAP_PAYMENT_REQUEST_SERVER, JsonMapper.toJson(nwcToBeSaved)) + } else { + remove(PrefKeys.ZAP_PAYMENT_REQUEST_SERVER) + } putOrRemove(PrefKeys.LATEST_CONTACT_LIST, settings.backupContactList) From 701acb004f07c5ec250538a0167d05db4f2b5451 Mon Sep 17 00:00:00 2001 From: davotoula Date: Mon, 6 Oct 2025 18:52:14 +0200 Subject: [PATCH 2/3] remove unnecessary suspend --- .../main/java/com/vitorpamplona/amethyst/LocalPreferences.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt index 1ba92a1df1..8ffd0646ea 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt @@ -389,7 +389,7 @@ object LocalPreferences { suspend fun loadAccountConfigFromEncryptedStorage(): AccountSettings? = currentAccount()?.let { loadAccountConfigFromEncryptedStorage(it) } - suspend fun saveSharedSettings( + fun saveSharedSettings( sharedSettings: UiSettings, prefs: SharedPreferences = encryptedPreferences(), ) { @@ -399,7 +399,7 @@ object LocalPreferences { } } - suspend fun loadSharedSettings(prefs: SharedPreferences = encryptedPreferences()): UiSettings? { + fun loadSharedSettings(prefs: SharedPreferences = encryptedPreferences()): UiSettings? { Log.d("LocalPreferences", "Load shared settings") with(prefs) { return try { From 1fdf869c05af10a632ea3117f5a0db0bcc2f9c50 Mon Sep 17 00:00:00 2001 From: davotoula Date: Mon, 6 Oct 2025 18:56:12 +0200 Subject: [PATCH 3/3] create putOrRemove overload for Nip47URI? --- .../vitorpamplona/amethyst/LocalPreferences.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt index 8ffd0646ea..77abdf80a0 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt @@ -326,12 +326,7 @@ object LocalPreferences { settings.defaultDiscoveryFollowList.value, ) - val nwcToBeSaved = settings.zapPaymentRequest.value?.denormalize() - if (nwcToBeSaved != null) { - putString(PrefKeys.ZAP_PAYMENT_REQUEST_SERVER, JsonMapper.toJson(nwcToBeSaved)) - } else { - remove(PrefKeys.ZAP_PAYMENT_REQUEST_SERVER) - } + putOrRemove(PrefKeys.ZAP_PAYMENT_REQUEST_SERVER, settings.zapPaymentRequest.value?.denormalize()) putOrRemove(PrefKeys.LATEST_CONTACT_LIST, settings.backupContactList) @@ -589,4 +584,15 @@ object LocalPreferences { remove(key) } } + + fun SharedPreferences.Editor.putOrRemove( + key: String, + nwc: Nip47WalletConnect.Nip47URI?, + ) { + if (nwc != null) { + putString(key, JsonMapper.toJson(nwc)) + } else { + remove(key) + } + } }