Skip to content

Commit

Permalink
Merge pull request #1459 from WalletConnect/improve_manula_redirect_flow
Browse files Browse the repository at this point in the history
Improve siwe fallback experience
  • Loading branch information
jakubuid authored Jul 26, 2024
2 parents 2af1492 + 338b749 commit 05e96cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ internal class Web3ModalEngine(
}
}

private fun openWalletApp(topic: String, onError: (Throwable) -> Unit) {
private fun openWalletApp(topic: String, onError: (RedirectMissingThrowable) -> Unit) {
val redirect = SignClient.getActiveSessionByTopic(topic)?.redirect ?: String.Empty
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(redirect))
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
wcKoinApp.koin.get<Context>().startActivity(intent)
} catch (e: Throwable) {
onError(e)
onError(RedirectMissingThrowable("Please redirect to a wallet manually"))
}
}

Expand Down Expand Up @@ -348,4 +348,6 @@ internal class Web3ModalEngine(
"Coinbase Client needs to be initialized first using the initialize function"
}
}

internal class RedirectMissingThrowable(message: String) : Throwable(message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,20 @@ internal class ConnectViewModel : ViewModel(), Navigator by NavigatorImpl(), Par
val issuer = "did:pkh:${account.chain.id}:${account.address}"
val siweMessage = web3ModalEngine.formatSIWEMessage(Web3Modal.authPayloadParams!!, issuer)
val msg = siweMessage.encodeToByteArray().joinToString(separator = "", prefix = "0x") { eachByte -> "%02x".format(eachByte) }
val body = "[\"$msg\", \"$account\"]"
val body = "[\"$msg\", \"${account.address}\"]"
web3ModalEngine.request(
request = Request("personal_sign", body),
onSuccess = { sendRequest ->
logger.log("SIWE sent successfully")
web3ModalEngine.siweRequestIdWithMessage = Pair((sendRequest as SentRequestResult.WalletConnect).requestId, siweMessage)
},
onError = {
web3ModalEngine.shouldDisconnect = true
if (it !is Web3ModalEngine.RedirectMissingThrowable) {
web3ModalEngine.shouldDisconnect = true
}

_isConfirmLoading.value = false
showError(it.localizedMessage)
showError(it.message)
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import com.walletconnect.web3.modal.client.Modal
import com.walletconnect.web3.modal.client.Web3Modal
import com.walletconnect.web3.modal.client.models.request.Request
import com.walletconnect.web3.modal.client.models.request.SentRequestResult
import com.walletconnect.web3.modal.ui.components.button.AccountButtonType
import com.walletconnect.web3.modal.ui.Web3ModalTheme
import com.walletconnect.web3.modal.ui.components.button.AccountButtonType
import com.walletconnect.web3.modal.ui.components.button.NetworkButton
import com.walletconnect.web3.modal.ui.components.button.Web3Button
import com.walletconnect.web3.modal.ui.components.button.rememberWeb3ModalState
Expand Down

0 comments on commit 05e96cd

Please sign in to comment.