handle wc links to use with mobile dapps
This commit is contained in:
parent
2f643b53f1
commit
a6746bbc2e
|
@ -32,12 +32,19 @@
|
|||
<activity android:name=".ui.ReinstallActivity" />
|
||||
<activity
|
||||
android:name=".ui.MainActivity"
|
||||
android:label="@string/app_name">
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTask"
|
||||
android:alwaysRetainTaskState="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="wc" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.komputing.khex.extensions.toHexString
|
|||
import org.komputing.khex.extensions.toNoPrefixHexString
|
||||
import org.komputing.khex.model.HexString
|
||||
import org.walletconnect.Session
|
||||
import org.walletconnect.Session.Config.Companion.fromWCUri
|
||||
import org.walletconnect.impls.FileWCSessionStore
|
||||
import org.walletconnect.impls.MoshiPayloadAdapter
|
||||
import org.walletconnect.impls.OkHttpTransport
|
||||
|
@ -212,12 +211,12 @@ class WalletConnect(var sessionStatusListener : Session.Callback, var bip32Path:
|
|||
uiAction = this::nop
|
||||
}
|
||||
|
||||
fun connect(uri: String) {
|
||||
fun connect(uri: Session.FullyQualifiedConfig) {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
session?.kill()
|
||||
|
||||
session = WCSession(
|
||||
fromWCUri(uri).toFullyQualifiedConfig(),
|
||||
uri,
|
||||
MoshiPayloadAdapter(moshi),
|
||||
sessionStore,
|
||||
OkHttpTransport.Builder(okHttpClient, moshi),
|
||||
|
|
|
@ -16,6 +16,7 @@ import im.status.keycard.connect.Registry
|
|||
import im.status.keycard.connect.card.*
|
||||
import im.status.keycard.connect.data.*
|
||||
import org.walletconnect.Session
|
||||
import org.walletconnect.Session.Config.Companion.fromWCUri
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class MainActivity : AppCompatActivity(), ScriptListener, Session.Callback {
|
||||
|
@ -32,6 +33,8 @@ class MainActivity : AppCompatActivity(), ScriptListener, Session.Callback {
|
|||
setContentView(viewSwitcher)
|
||||
Registry.init(this, this, this)
|
||||
Registry.scriptExecutor.defaultScript = cardCheckupScript()
|
||||
|
||||
handleIntent(intent)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
@ -44,6 +47,21 @@ class MainActivity : AppCompatActivity(), ScriptListener, Session.Callback {
|
|||
Registry.nfcAdapter.disableReaderMode(this)
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
handleIntent(intent)
|
||||
}
|
||||
|
||||
private fun handleIntent(intent: Intent?) {
|
||||
if (intent?.action == Intent.ACTION_VIEW) {
|
||||
handleWCURI(intent.data?.toString())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
moveTaskToBack(false)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
|
||||
|
@ -137,10 +155,15 @@ class MainActivity : AppCompatActivity(), ScriptListener, Session.Callback {
|
|||
private fun qrCodeScanned(resultCode: Int, data: Intent?) {
|
||||
if (resultCode != Activity.RESULT_OK || data == null) return
|
||||
|
||||
val uri: String? = data.getStringExtra(Intents.Scan.RESULT)
|
||||
handleWCURI(data.getStringExtra(Intents.Scan.RESULT))
|
||||
|
||||
if (uri != null && uri.startsWith("wc:")) {
|
||||
Registry.walletConnect.connect(uri)
|
||||
}
|
||||
|
||||
private fun handleWCURI(uri: String?) {
|
||||
if (uri != null) {
|
||||
try {
|
||||
Registry.walletConnect.connect(fromWCUri(uri).toFullyQualifiedConfig())
|
||||
} catch (e: Exception) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue