Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WalletConnect push setup #3853

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ dependencies {
implementation platform("com.walletconnect:android-bom:1.12.0")
implementation "com.walletconnect:android-core"
implementation "com.walletconnect:web3wallet"
implementation "com.walletconnect:push"

implementation "com.github.TrustWallet:wallet-connect-kotlin:1.5.6"
implementation 'com.github.salomonbrys.kotson:kotson:2.5.0'
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,13 @@
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name=".tip.wc.WCFirebaseService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name=".job.MyJobService"
android:exported="true"
Expand Down
34 changes: 34 additions & 0 deletions app/src/main/java/one/mixin/android/tip/wc/WCFirebaseService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package one.mixin.android.tip.wc

import android.annotation.SuppressLint
import com.google.firebase.messaging.RemoteMessage
import com.walletconnect.push.common.Push
import com.walletconnect.push.wallet.client.PushMessageService
import timber.log.Timber

@SuppressLint("MissingFirebaseInstanceTokenRefresh")
class WCFirebaseService : PushMessageService() {
companion object {
const val TAG = "WCFirebaseService"
}

override fun newToken(token: String) {
Timber.d("$TAG newToken $token")
}

override fun onDefaultBehavior(message: RemoteMessage) {
Timber.d("$TAG onDefaultBehavior $message")
}

override fun onError(throwable: Throwable, defaultMessage: RemoteMessage) {
Timber.d("$TAG onError $defaultMessage, ${throwable.stackTraceToString()}")
}

override fun onMessage(message: Push.Model.Message, originalMessage: RemoteMessage) {
Timber.d("$TAG onMessage $message")
}

override fun registeringFailed(token: String, throwable: Throwable) {
Timber.d("$TAG registeringFailed $token, ${throwable.stackTraceToString()}")
}
}
49 changes: 44 additions & 5 deletions app/src/main/java/one/mixin/android/tip/wc/WalletConnectV2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import com.walletconnect.android.Core
import com.walletconnect.android.CoreClient
import com.walletconnect.android.internal.common.exception.GenericException
import com.walletconnect.android.relay.ConnectionType
import com.walletconnect.push.common.Push
import com.walletconnect.push.wallet.client.PushWalletClient
import com.walletconnect.web3.wallet.client.Wallet
import com.walletconnect.web3.wallet.client.Web3Wallet
import one.mixin.android.BuildConfig
Expand Down Expand Up @@ -67,18 +69,25 @@ object WalletConnectV2 : WalletConnect() {
RxBus.publish(WCErrorEvent(WCError(error.throwable)))
},
)
val initParams = Wallet.Params.Init(core = CoreClient)
Web3Wallet.initialize(initParams) { error ->
val web3InitParams = Wallet.Params.Init(core = CoreClient)
Web3Wallet.initialize(web3InitParams) { error ->
Timber.d("$TAG Web3Wallet init error: $error")
RxBus.publish(WCErrorEvent(WCError(error.throwable)))
}

val pushInitParams = Push.Wallet.Params.Init(core = CoreClient)
PushWalletClient.initialize(pushInitParams) { error ->
Timber.d("$TAG PushWalletClient init error: $error")
RxBus.publish(WCErrorEvent(WCError(error.throwable)))
}

val coreDelegate = object : CoreClient.CoreDelegate {
override fun onPairingDelete(deletedPairing: Core.Model.DeletedPairing) {
Timber.d("$TAG onPairingDelete $deletedPairing")
[email protected](deletedPairing)
}
}
CoreClient.setDelegate(coreDelegate)

val walletDelegate = object : Web3Wallet.WalletDelegate {
override fun onAuthRequest(authRequest: Wallet.Model.AuthRequest) {
Expand All @@ -93,7 +102,7 @@ object WalletConnectV2 : WalletConnect() {
}

override fun onError(error: Wallet.Model.Error) {
Timber.d("$TAG onError $error")
Timber.d("$TAG walletDelegate onError $error")
RxBus.publish(WCErrorEvent(WCError(error.throwable)))
}

Expand Down Expand Up @@ -126,9 +135,39 @@ object WalletConnectV2 : WalletConnect() {
[email protected](sessionUpdateResponse)
}
}

CoreClient.setDelegate(coreDelegate)
Web3Wallet.setWalletDelegate(walletDelegate)

val pushDelegate = object : PushWalletClient.Delegate {
override fun onError(error: Push.Model.Error) {
Timber.d("$TAG pushDelegate onError $error")
RxBus.publish(WCErrorEvent(WCError(error.throwable)))
}

override fun onPushDelete(pushDelete: Push.Wallet.Event.Delete) {
Timber.d("$TAG onPushDelete $pushDelete")
}

override fun onPushMessage(pushMessage: Push.Wallet.Event.Message) {
Timber.d("$TAG onPushMessage $pushMessage")
}

override fun onPushProposal(pushProposal: Push.Wallet.Event.Proposal) {
Timber.d("$TAG onPushProposal $pushProposal")
}

override fun onPushRequest(pushRequest: Push.Wallet.Event.Request) {
Timber.d("$TAG onPushRequest $pushRequest")
}

override fun onPushSubscription(pushSubscribe: Push.Wallet.Event.Subscription) {
Timber.d("$TAG onPushSubscription $pushSubscribe")
}

override fun onPushUpdate(pushUpdate: Push.Wallet.Event.Update) {
Timber.d("$TAG onPushUpdate $pushUpdate")
}
}
PushWalletClient.setDelegate(pushDelegate)
}

fun pair(uri: String) {
Expand Down