Skip to content

Commit 3537289

Browse files
authored
Merge pull request #1280 from WalletConnect/feat/notify/sbs_in_responses
[Notify/Wallet Sample] Notify Client Refactor
2 parents 029c4f7 + 67dfafa commit 3537289

File tree

61 files changed

+759
-1452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+759
-1452
lines changed

protocol/notify/src/androidTest/kotlin/com/walletconnect/notify/test/scenario/ClientInstrumentedActivityScenario.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ class ClientInstrumentedActivityScenario : TestRule, ActivityScenario() {
5454
val isPrimaryReady = MutableStateFlow(false)
5555
val isSecondaryReady = MutableStateFlow(false)
5656

57-
TestClient.Primary.notifyClient.unregister(Notify.Params.Unregistration(TestClient.caip10account), { identityKey ->
57+
TestClient.Primary.notifyClient.unregister(Notify.Params.Unregister(TestClient.caip10account), { identityKey ->
5858
Timber.d("Primary unregister: $identityKey")
5959
isPrimaryReady.value = true
6060
}, { error ->
6161
Timber.e(error.throwable)
6262
})
63-
TestClient.Secondary.notifyClient.unregister(Notify.Params.Unregistration(TestClient.caip10account), { identityKey ->
63+
TestClient.Secondary.notifyClient.unregister(Notify.Params.Unregister(TestClient.caip10account), { identityKey ->
6464
Timber.d("Secondary unregister: $identityKey")
6565
isSecondaryReady.value = true
6666
}, { error ->

protocol/notify/src/main/kotlin/com/walletconnect/notify/client/Notify.kt

Lines changed: 19 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,6 @@ import com.walletconnect.foundation.common.model.PrivateKey
1010
object Notify {
1111

1212
sealed class Model {
13-
14-
@Deprecated("We renamed sealed class to Notification for consistency")
15-
sealed class Message : Model() {
16-
abstract val title: String
17-
abstract val body: String
18-
19-
data class Simple(
20-
override val title: String,
21-
override val body: String,
22-
) : Message()
23-
24-
data class Decrypted(
25-
override val title: String,
26-
override val body: String,
27-
val icon: String?,
28-
val url: String?,
29-
val type: String,
30-
val topic: String,
31-
) : Message()
32-
}
33-
3413
sealed class Notification : Model() {
3514
abstract val title: String
3615
abstract val body: String
@@ -50,9 +29,6 @@ object Notify {
5029
) : Notification()
5130
}
5231

53-
@Deprecated("We renamed data class to NotificationRecord for consistency")
54-
data class MessageRecord(val id: String, val topic: String, val publishedAt: Long, val message: Message) : Model()
55-
5632
data class NotificationRecord(val id: String, val topic: String, val publishedAt: Long, val message: Notification, val metadata: Core.Model.AppMetaData) : Model()
5733

5834
data class Subscription(
@@ -90,29 +66,27 @@ object Notify {
9066
}
9167

9268
sealed class Event {
69+
data class Notification (val notification: Model.NotificationRecord) : Event()
9370

94-
@Deprecated("We renamed data class to Notification for consistency")
95-
data class Message(val message: Model.MessageRecord) : Event()
96-
97-
data class Notification(val notification: Model.NotificationRecord) : Event()
98-
99-
data class Delete(val topic: String) : Event()
100-
101-
sealed class Subscription : Event() {
102-
103-
data class Result(val subscription: Model.Subscription) : Subscription()
71+
data class SubscriptionsChanged(val subscriptions: List<Model.Subscription>) : Event()
72+
}
10473

105-
data class Error(val id: Long, val reason: String) : Subscription()
74+
// todo: move to model
75+
sealed interface Result {
76+
sealed interface Subscribe {
77+
data class Success(val subscription: Model.Subscription) : Subscribe
78+
data class Error(val error: Model.Error) : Subscribe
10679
}
10780

108-
sealed class Update : Event() {
109-
110-
data class Result(val subscription: Model.Subscription) : Update()
111-
112-
data class Error(val id: Long, val reason: String) : Update()
81+
sealed interface UpdateSubscription {
82+
data class Success(val subscription: Model.Subscription) : UpdateSubscription
83+
data class Error(val error: Model.Error) : UpdateSubscription
11384
}
11485

115-
data class SubscriptionsChanged(val subscriptions: List<Model.Subscription>) : Event()
86+
sealed interface DeleteSubscription {
87+
data class Success(val topic: String) : DeleteSubscription
88+
data class Error(val error: Model.Error) : DeleteSubscription
89+
}
11690
}
11791

11892
sealed class Params {
@@ -121,36 +95,22 @@ object Notify {
12195

12296
data class Subscribe(val appDomain: Uri, val account: String) : Params()
12397

124-
data class Update(val topic: String, val scope: List<String>) : Params()
125-
126-
data class NotificationTypes(val appDomain: String) : Params()
98+
data class UpdateSubscription(val topic: String, val scope: List<String>) : Params()
12799

128-
@Deprecated("We renamed function to getNotificationHistory for consistency")
129-
data class MessageHistory(val topic: String) : Params()
100+
data class GetNotificationTypes(val appDomain: String) : Params()
130101

131-
data class NotificationHistory(val topic: String) : Params()
102+
data class GetNotificationHistory(val topic: String) : Params()
132103

133104
data class DeleteSubscription(val topic: String) : Params()
134105

135-
@Deprecated("We renamed function to deleteNotification for consistency")
136-
data class DeleteMessage(val id: Long) : Params()
137-
138-
data class DeleteNotification(val id: Long) : Params()
139-
140-
@Deprecated("We renamed function to decryptNotification for consistency")
141-
data class DecryptMessage(val topic: String, val encryptedMessage: String) : Params()
142-
143106
data class DecryptNotification(val topic: String, val encryptedMessage: String) : Params()
144107

145-
@Deprecated("We changed the registration flow to be more secure. Please use PrepareRegistration and Register instead")
146-
data class Registration(val account: String, val domain: String, val onSign: (String) -> Model.Cacao.Signature?, val isLimited: Boolean = false) : Params()
147-
148108
data class PrepareRegistration(val account: String, val domain: String, val allApps: Boolean = true) : Params()
149109

150110
data class Register(val cacaoPayloadWithIdentityPrivateKey: Model.CacaoPayloadWithIdentityPrivateKey, val signature: Model.Cacao.Signature) : Params()
151111

152112
data class IsRegistered(val account: String, val domain: String, val allApps: Boolean = true) : Params()
153113

154-
data class Unregistration(val account: String) : Params()
114+
data class Unregister (val account: String) : Params()
155115
}
156116
}

protocol/notify/src/main/kotlin/com/walletconnect/notify/client/NotifyInterface.kt

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,9 @@ package com.walletconnect.notify.client
22

33
interface NotifyInterface {
44
interface Delegate {
5-
6-
fun onNotifySubscription(notifySubscribe: Notify.Event.Subscription)
7-
8-
@Deprecated("We renamed this function to onNotifyMessage for consistency. Using both onNotifyMessage and onNotifyNotification will result in duplicate notifications")
9-
fun onNotifyMessage(notifyMessage: Notify.Event.Message)
10-
5+
//todo: migration guide and remove all deprecations
116
fun onNotifyNotification(notifyNotification: Notify.Event.Notification)
127

13-
fun onNotifyDelete(notifyDelete: Notify.Event.Delete)
14-
15-
fun onNotifyUpdate(notifyUpdate: Notify.Event.Update)
16-
178
fun onError(error: Notify.Model.Error)
189

1910
fun onSubscriptionsChanged(subscriptionsChanged: Notify.Event.SubscriptionsChanged)
@@ -23,51 +14,45 @@ interface NotifyInterface {
2314

2415
fun setDelegate(delegate: Delegate)
2516

26-
fun subscribe(params: Notify.Params.Subscribe, onSuccess: () -> Unit, onError: (Notify.Model.Error) -> Unit)
27-
28-
fun update(params: Notify.Params.Update, onSuccess: () -> Unit, onError: (Notify.Model.Error) -> Unit)
29-
3017
/**
3118
* Caution: This function is blocking and runs on the current thread.
3219
* It is advised that this function be called from background operation
3320
*/
34-
fun getNotificationTypes(params: Notify.Params.NotificationTypes): Map<String, Notify.Model.NotificationType>
21+
fun subscribe(params: Notify.Params.Subscribe) : Notify.Result.Subscribe
3522

3623
/**
3724
* Caution: This function is blocking and runs on the current thread.
3825
* It is advised that this function be called from background operation
3926
*/
40-
fun getActiveSubscriptions(): Map<String, Notify.Model.Subscription>
27+
fun updateSubscription(params: Notify.Params.UpdateSubscription) : Notify.Result.UpdateSubscription
4128

4229
/**
4330
* Caution: This function is blocking and runs on the current thread.
4431
* It is advised that this function be called from background operation
4532
*/
46-
@Deprecated("We renamed this function to getNotificationHistory for consistency")
47-
fun getMessageHistory(params: Notify.Params.MessageHistory): Map<Long, Notify.Model.MessageRecord>
48-
33+
fun deleteSubscription(params: Notify.Params.DeleteSubscription): Notify.Result.DeleteSubscription
4934

5035
/**
5136
* Caution: This function is blocking and runs on the current thread.
5237
* It is advised that this function be called from background operation
5338
*/
54-
fun getNotificationHistory(params: Notify.Params.NotificationHistory): Map<Long, Notify.Model.NotificationRecord>
55-
56-
fun deleteSubscription(params: Notify.Params.DeleteSubscription, onSuccess: () -> Unit, onError: (Notify.Model.Error) -> Unit)
39+
fun getNotificationTypes(params: Notify.Params.GetNotificationTypes): Map<String, Notify.Model.NotificationType>
5740

58-
@Deprecated("We renamed this function to deleteNotification for consistency")
59-
fun deleteNotifyMessage(params: Notify.Params.DeleteMessage, onSuccess: () -> Unit, onError: (Notify.Model.Error) -> Unit)
41+
/**
42+
* Caution: This function is blocking and runs on the current thread.
43+
* It is advised that this function be called from background operation
44+
*/
45+
fun getActiveSubscriptions(): Map<String, Notify.Model.Subscription>
6046

61-
fun deleteNotification(params: Notify.Params.DeleteNotification, onSuccess: () -> Unit, onError: (Notify.Model.Error) -> Unit)
47+
/**
48+
* Caution: This function is blocking and runs on the current thread.
49+
* It is advised that this function be called from background operation
50+
*/
51+
fun getNotificationHistory(params: Notify.Params.GetNotificationHistory): Map<Long, Notify.Model.NotificationRecord>
6252

63-
@Deprecated("We renamed this function to decryptNotification for consistency")
64-
fun decryptMessage(params: Notify.Params.DecryptMessage, onSuccess: (Notify.Model.Message.Decrypted) -> Unit, onError: (Notify.Model.Error) -> Unit)
6553

6654
fun decryptNotification(params: Notify.Params.DecryptNotification, onSuccess: (Notify.Model.Notification.Decrypted) -> Unit, onError: (Notify.Model.Error) -> Unit)
6755

68-
@Deprecated("We changed the registration flow to be more secure. Please use prepareRegistration and register instead")
69-
fun register(params: Notify.Params.Registration, onSuccess: (String) -> Unit, onError: (Notify.Model.Error) -> Unit)
70-
7156
fun register(params: Notify.Params.Register, onSuccess: (String) -> Unit, onError: (Notify.Model.Error) -> Unit)
7257

7358
fun prepareRegistration(params: Notify.Params.PrepareRegistration, onSuccess: (Notify.Model.CacaoPayloadWithIdentityPrivateKey, String) -> Unit, onError: (Notify.Model.Error) -> Unit)
@@ -78,5 +63,5 @@ interface NotifyInterface {
7863
*/
7964
fun isRegistered(params: Notify.Params.IsRegistered): Boolean
8065

81-
fun unregister(params: Notify.Params.Unregistration, onSuccess: (String) -> Unit, onError: (Notify.Model.Error) -> Unit)
66+
fun unregister(params: Notify.Params.Unregister, onSuccess: (String) -> Unit, onError: (Notify.Model.Error) -> Unit)
8267
}

protocol/notify/src/main/kotlin/com/walletconnect/notify/client/NotifyMessageService.kt

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)