diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt index 913d52454..ec0c89c81 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt @@ -204,7 +204,7 @@ object Web3Modal { fun authenticate( authenticate: Modal.Params.Authenticate, walletAppLink: String? = null, - onSuccess: (String?) -> Unit, + onSuccess: (String) -> Unit, onError: (Modal.Model.Error) -> Unit, ) { diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/engine/Web3ModalEngine.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/engine/Web3ModalEngine.kt index 44847d9c0..e76851cf7 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/engine/Web3ModalEngine.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/engine/Web3ModalEngine.kt @@ -95,7 +95,7 @@ internal class Web3ModalEngine( name: String, method: String, authenticate: Modal.Params.Authenticate, walletAppLink: String? = null, - onSuccess: (String?) -> Unit, + onSuccess: (String) -> Unit, onError: (Throwable) -> Unit ) { connectionEventRepository.saveEvent(name, method) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectViewModel.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectViewModel.kt index ab2921ae5..c20334a88 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectViewModel.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectViewModel.kt @@ -154,7 +154,7 @@ internal class ConnectViewModel : ViewModel(), Navigator by NavigatorImpl(), Par name, method, walletAppLink = linkMode, authParams = if (Web3Modal.selectedChain != null) Web3Modal.authPayloadParams!!.copy(chains = listOf(Web3Modal.selectedChain!!.id)) else Web3Modal.authPayloadParams!!, - onSuccess = { if (!it.isNullOrBlank()) onSuccess(it) }, + onSuccess = { onSuccess(it) }, onError = { sendEventUseCase.send(Props(EventType.TRACK, EventType.Track.CONNECT_ERROR, Properties(message = it.message ?: "Relay error while connecting"))) showError(it.localizedMessage) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ParingController.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ParingController.kt index 130a31e7b..661361db3 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ParingController.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ParingController.kt @@ -20,7 +20,7 @@ internal interface ParingController { name: String, method: String, authParams: Modal.Model.AuthPayloadParams, walletAppLink: String? = null, - onSuccess: (String?) -> Unit, + onSuccess: (String) -> Unit, onError: (Throwable) -> Unit ) @@ -66,7 +66,7 @@ internal class PairingControllerImpl : ParingController { method: String, authParams: Modal.Model.AuthPayloadParams, walletAppLink: String?, - onSuccess: (String?) -> Unit, + onSuccess: (String) -> Unit, onError: (Throwable) -> Unit ) { try { diff --git a/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/utils/dapp/DappSignClient.kt b/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/utils/dapp/DappSignClient.kt index 678d301db..b388c079e 100644 --- a/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/utils/dapp/DappSignClient.kt +++ b/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/utils/dapp/DappSignClient.kt @@ -67,7 +67,7 @@ fun dappClientAuthenticateLinkMode(onPairing: (String) -> Unit) { "https://web3modal-laboratory-git-chore-kotlin-assetlinks-walletconnect1.vercel.app/wallet", onSuccess = { pairingUrl -> Timber.d("DappClient: on sent authenticate success: $pairingUrl") - onPairing(pairingUrl ?: "") + onPairing(pairingUrl) }, onError = ::globalOnError ) diff --git a/protocol/sign/src/main/kotlin/com/walletconnect/sign/client/SignInterface.kt b/protocol/sign/src/main/kotlin/com/walletconnect/sign/client/SignInterface.kt index 2dbdf7745..0be223d60 100644 --- a/protocol/sign/src/main/kotlin/com/walletconnect/sign/client/SignInterface.kt +++ b/protocol/sign/src/main/kotlin/com/walletconnect/sign/client/SignInterface.kt @@ -69,14 +69,7 @@ interface SignInterface { onError: (Sign.Model.Error) -> Unit, ) - fun authenticate(authenticate: Sign.Params.Authenticate, walletAppLink: String?, onSuccess: (String?) -> Unit, onError: (Sign.Model.Error) -> Unit) - - @Deprecated( - "The onSuccess callback has been replaced with a new callback that returns optional Pairing URL", - replaceWith = ReplaceWith("fun authenticate(authenticate: Sign.Params.Authenticate, val walletAppLink: String?, onSuccess: (String?) -> Unit, onError: (Sign.Model.Error) -> Unit)") - ) - fun authenticate(authenticate: Sign.Params.Authenticate, onSuccess: (String) -> Unit, onError: (Sign.Model.Error) -> Unit) - + fun authenticate(authenticate: Sign.Params.Authenticate, walletAppLink: String? = null, onSuccess: (String) -> Unit, onError: (Sign.Model.Error) -> Unit) fun dispatchEnvelope(urlWithEnvelope: String, onError: (Sign.Model.Error) -> Unit) @Deprecated( diff --git a/protocol/sign/src/main/kotlin/com/walletconnect/sign/client/SignProtocol.kt b/protocol/sign/src/main/kotlin/com/walletconnect/sign/client/SignProtocol.kt index 16b6df876..ca5333dcb 100644 --- a/protocol/sign/src/main/kotlin/com/walletconnect/sign/client/SignProtocol.kt +++ b/protocol/sign/src/main/kotlin/com/walletconnect/sign/client/SignProtocol.kt @@ -19,7 +19,6 @@ import com.walletconnect.sign.di.signJsonRpcModule import com.walletconnect.sign.di.storageModule import com.walletconnect.sign.engine.domain.SignEngine import com.walletconnect.sign.engine.model.EngineDO -import com.walletconnect.util.Empty import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch @@ -137,7 +136,7 @@ class SignProtocol(private val koinApp: KoinApplication = wcKoinApp) : SignInter override fun authenticate( authenticate: Sign.Params.Authenticate, walletAppLink: String?, - onSuccess: (String?) -> Unit, + onSuccess: (String) -> Unit, onError: (Sign.Model.Error) -> Unit, ) { checkEngineInitialization() @@ -499,31 +498,6 @@ class SignProtocol(private val koinApp: KoinApplication = wcKoinApp) : SignInter } } - @Deprecated( - "The onSuccess callback has been replaced with a new callback that returns optional Pairing URL", - replaceWith = ReplaceWith("fun authenticate(authenticate: Sign.Params.Authenticate, val walletAppLink: String?, onSuccess: (String?) -> Unit, onError: (Sign.Model.Error) -> Unit)") - ) - @Throws(IllegalStateException::class) - override fun authenticate( - authenticate: Sign.Params.Authenticate, - onSuccess: (String) -> Unit, - onError: (Sign.Model.Error) -> Unit, - ) { - checkEngineInitialization() - scope.launch { - try { - signEngine.authenticate(authenticate.toAuthenticate(), - authenticate.methods, authenticate.pairingTopic, - if (authenticate.expiry == null) null else Expiry(authenticate.expiry), - null, - onSuccess = { url -> onSuccess(url ?: String.Empty) }, - onFailure = { throwable -> onError(Sign.Model.Error(throwable)) }) - } catch (error: Exception) { - onError(Sign.Model.Error(error)) - } - } - } - @Deprecated( "The onSuccess callback has been replaced with a new callback that returns Sign.Model.SentRequest", replaceWith = ReplaceWith("this.request(request, onSuccessWithSentRequest, onError)", "com.walletconnect.sign.client") diff --git a/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/calls/SessionAuthenticateUseCase.kt b/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/calls/SessionAuthenticateUseCase.kt index a08ffeb5d..7d300ab1f 100644 --- a/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/calls/SessionAuthenticateUseCase.kt +++ b/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/calls/SessionAuthenticateUseCase.kt @@ -61,7 +61,7 @@ internal class SessionAuthenticateUseCase( pairingTopic: String?, expiry: Expiry?, walletAppLink: String?, - onSuccess: (String?) -> Unit, + onSuccess: (String) -> Unit, onFailure: (Throwable) -> Unit ) { if (authenticate.chains.isEmpty()) { @@ -75,7 +75,6 @@ internal class SessionAuthenticateUseCase( } val requestExpiry = expiry ?: Expiry(currentTimeInSeconds + oneHourInSeconds) - val pairing = getPairingForSessionAuthenticate(pairingTopic) val optionalNamespaces = getNamespacesFromReCaps(authenticate.chains, if (methods.isNullOrEmpty()) listOf("personal_sign") else methods).toMapOfEngineNamespacesOptional() val externalReCapsJson: String = getExternalReCapsJson(authenticate) val signReCapsJson = getSignReCapsJson(methods, authenticate) @@ -99,14 +98,14 @@ internal class SessionAuthenticateUseCase( val authRequest: SignRpc.SessionAuthenticate = SignRpc.SessionAuthenticate(params = authParams) crypto.setKey(requesterPublicKey, responseTopic.getParticipantTag()) - if (!walletAppLink.isNullOrEmpty() && selfAppMetaData.redirect?.linkMode == true && linkModeStorageRepository.isEnabled(walletAppLink)) { + if (isLinkModeEnabled(walletAppLink)) { try { - linkModeJsonRpcInteractor.triggerRequest(authRequest, appLink = walletAppLink, topic = Topic(generateUUID()), envelopeType = EnvelopeType.TWO) - onSuccess(null) + linkModeJsonRpcInteractor.triggerRequest(authRequest, appLink = walletAppLink!!, topic = Topic(generateUUID()), envelopeType = EnvelopeType.TWO) } catch (e: Error) { onFailure(e) } } else { + val pairing = getPairingForSessionAuthenticate(pairingTopic) logger.log("Session authenticate subscribing on topic: $responseTopic") jsonRpcInteractor.subscribe( responseTopic, @@ -140,6 +139,8 @@ internal class SessionAuthenticateUseCase( } } + private suspend fun isLinkModeEnabled(walletAppLink: String?) = !walletAppLink.isNullOrEmpty() && selfAppMetaData.redirect?.linkMode == true && linkModeStorageRepository.isEnabled(walletAppLink) + private fun getSignReCapsJson(methods: List?, authenticate: EngineDO.Authenticate) = if (!methods.isNullOrEmpty()) { val namespace = SignValidator.getNamespaceKeyFromChainId(authenticate.chains.first()) @@ -228,7 +229,7 @@ internal interface SessionAuthenticateUseCaseInterface { pairingTopic: String?, expiry: Expiry?, walletAppLink: String? = null, - onSuccess: (String?) -> Unit, + onSuccess: (String) -> Unit, onFailure: (Throwable) -> Unit ) } \ No newline at end of file diff --git a/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/calls/SessionRequestUseCase.kt b/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/calls/SessionRequestUseCase.kt index ea9727e3d..47cd09a59 100644 --- a/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/calls/SessionRequestUseCase.kt +++ b/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/calls/SessionRequestUseCase.kt @@ -85,7 +85,6 @@ internal class SessionRequestUseCase( if (session.peerAppLink.isNullOrEmpty()) return@supervisorScope onFailure(IllegalStateException("App link is missing")) try { linkModeJsonRpcInteractor.triggerRequest(sessionPayload, Topic(request.topic), session.peerAppLink) - onSuccess(sessionPayload.id) } catch (e: Exception) { onFailure(e) } diff --git a/sample/dapp/build.gradle.kts b/sample/dapp/build.gradle.kts index c8d039b10..961d2af70 100644 --- a/sample/dapp/build.gradle.kts +++ b/sample/dapp/build.gradle.kts @@ -83,5 +83,5 @@ dependencies { releaseImplementation(platform("com.walletconnect:android-bom:$BOM_VERSION")) releaseImplementation("com.walletconnect:android-core") releaseImplementation("com.walletconnect:walletconnect-modal") - releaseImplementation("com.walletconnect:android-core") + releaseImplementation("com.walletconnect:sign") } diff --git a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/Web3WalletActivity.kt b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/Web3WalletActivity.kt index 6026c6ef4..8d4199700 100644 --- a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/Web3WalletActivity.kt +++ b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/Web3WalletActivity.kt @@ -181,28 +181,35 @@ class Web3WalletActivity : AppCompatActivity() { override fun onNewIntent(intent: Intent?) { super.onNewIntent(intent) - handleAppLink(intent) - when { - intent?.dataString?.startsWith("kotlin-web3wallet:/wc") == true -> { - val uri = intent.dataString?.replace("kotlin-web3wallet:/wc", "kotlin-web3wallet://wc") - intent.setData(uri?.toUri()) + if (intent?.dataString?.contains("wc_ev") == true) { + Web3Wallet.dispatchEnvelope(intent.dataString ?: "") { + lifecycleScope.launch(Dispatchers.Main) { + Toast.makeText(this@Web3WalletActivity, "Error dispatching envelope: ${it.throwable.message}", Toast.LENGTH_SHORT).show() + } } + } else { + when { + intent?.dataString?.startsWith("kotlin-web3wallet:/wc") == true -> { + val uri = intent.dataString?.replace("kotlin-web3wallet:/wc", "kotlin-web3wallet://wc") + intent.setData(uri?.toUri()) + } - intent?.dataString?.startsWith("wc:") == true -> { - val uri = "kotlin-web3wallet://wc?uri=" + URLEncoder.encode(intent.dataString, "UTF-8") - intent.setData(uri.toUri()) + intent?.dataString?.startsWith("wc:") == true -> { + val uri = "kotlin-web3wallet://wc?uri=" + URLEncoder.encode(intent.dataString, "UTF-8") + intent.setData(uri.toUri()) + } } - } - if (intent?.dataString?.startsWith("kotlin-web3wallet://request") == true) { - web3walletViewModel.showRequestLoader(true) - } + if (intent?.dataString?.startsWith("kotlin-web3wallet://request") == true) { + web3walletViewModel.showRequestLoader(true) + } - if (intent?.dataString?.startsWith("kotlin-web3wallet://request") == false - && intent.dataString?.contains("requestId") == false - ) { - navController.handleDeepLink(intent) + if (intent?.dataString?.startsWith("kotlin-web3wallet://request") == false + && intent.dataString?.contains("requestId") == false + ) { + navController.handleDeepLink(intent) + } } }