Skip to content

Commit 05e96cd

Browse files
authored
Merge pull request #1459 from WalletConnect/improve_manula_redirect_flow
Improve siwe fallback experience
2 parents 2af1492 + 338b749 commit 05e96cd

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/engine/Web3ModalEngine.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ internal class Web3ModalEngine(
166166
}
167167
}
168168

169-
private fun openWalletApp(topic: String, onError: (Throwable) -> Unit) {
169+
private fun openWalletApp(topic: String, onError: (RedirectMissingThrowable) -> Unit) {
170170
val redirect = SignClient.getActiveSessionByTopic(topic)?.redirect ?: String.Empty
171171
try {
172172
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(redirect))
173173
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
174174
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
175175
wcKoinApp.koin.get<Context>().startActivity(intent)
176176
} catch (e: Throwable) {
177-
onError(e)
177+
onError(RedirectMissingThrowable("Please redirect to a wallet manually"))
178178
}
179179
}
180180

@@ -348,4 +348,6 @@ internal class Web3ModalEngine(
348348
"Coinbase Client needs to be initialized first using the initialize function"
349349
}
350350
}
351+
352+
internal class RedirectMissingThrowable(message: String) : Throwable(message)
351353
}

product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectViewModel.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,20 @@ internal class ConnectViewModel : ViewModel(), Navigator by NavigatorImpl(), Par
102102
val issuer = "did:pkh:${account.chain.id}:${account.address}"
103103
val siweMessage = web3ModalEngine.formatSIWEMessage(Web3Modal.authPayloadParams!!, issuer)
104104
val msg = siweMessage.encodeToByteArray().joinToString(separator = "", prefix = "0x") { eachByte -> "%02x".format(eachByte) }
105-
val body = "[\"$msg\", \"$account\"]"
105+
val body = "[\"$msg\", \"${account.address}\"]"
106106
web3ModalEngine.request(
107107
request = Request("personal_sign", body),
108108
onSuccess = { sendRequest ->
109109
logger.log("SIWE sent successfully")
110110
web3ModalEngine.siweRequestIdWithMessage = Pair((sendRequest as SentRequestResult.WalletConnect).requestId, siweMessage)
111111
},
112112
onError = {
113-
web3ModalEngine.shouldDisconnect = true
113+
if (it !is Web3ModalEngine.RedirectMissingThrowable) {
114+
web3ModalEngine.shouldDisconnect = true
115+
}
116+
114117
_isConfirmLoading.value = false
115-
showError(it.localizedMessage)
118+
showError(it.message)
116119
},
117120
)
118121
}

sample/modal/src/main/kotlin/com/walletconnect/sample/modal/ui/LabScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import com.walletconnect.web3.modal.client.Modal
2424
import com.walletconnect.web3.modal.client.Web3Modal
2525
import com.walletconnect.web3.modal.client.models.request.Request
2626
import com.walletconnect.web3.modal.client.models.request.SentRequestResult
27-
import com.walletconnect.web3.modal.ui.components.button.AccountButtonType
2827
import com.walletconnect.web3.modal.ui.Web3ModalTheme
28+
import com.walletconnect.web3.modal.ui.components.button.AccountButtonType
2929
import com.walletconnect.web3.modal.ui.components.button.NetworkButton
3030
import com.walletconnect.web3.modal.ui.components.button.Web3Button
3131
import com.walletconnect.web3.modal.ui.components.button.rememberWeb3ModalState

0 commit comments

Comments
 (0)