11package com.trustwallet.walletconnect.sample
22
3+ import android.content.Intent
34import android.os.Bundle
5+ import android.util.Log
6+ import android.widget.Toast
7+ import androidx.activity.result.ActivityResultCallback
48import androidx.appcompat.app.AlertDialog
59import androidx.appcompat.app.AppCompatActivity
610import com.google.gson.GsonBuilder
@@ -19,18 +23,29 @@ import com.trustwallet.walletconnect.models.session.WCSession
1923import kotlinx.android.synthetic.main.activity_main.*
2024import kotlinx.android.synthetic.main.activity_main.view.*
2125import okhttp3.OkHttpClient
22- import wallet.core.jni.CoinType
23- import wallet.core.jni.PrivateKey
26+ import com.journeyapps.barcodescanner.ScanContract
27+
28+ import com.journeyapps.barcodescanner.ScanOptions
29+
30+ import androidx.activity.result.ActivityResultLauncher
31+ import com.google.zxing.client.android.Intents
32+ import com.journeyapps.barcodescanner.ScanIntentResult
33+ import org.web3j.protocol.Web3j
34+
35+
36+ // import wallet.core.jni.CoinType
37+ // import wallet.core.jni.PrivateKey
2438
2539class MainActivity : AppCompatActivity () {
2640
2741 private val wcClient by lazy {
2842 WCClient (GsonBuilder (), OkHttpClient ())
2943 }
3044
31- val privateKey = PrivateKey (" ba005cd605d8a02e3d5dfd04234cef3a3ee4f76bfbad2722d1fb5af8e12e6764" .decodeHex())
32- val address = CoinType .ETHEREUM .deriveAddress(privateKey)
33-
45+ // val privateKey = PrivateKey("ba005cd605d8a02e3d5dfd04234cef3a3ee4f76bfbad2722d1fb5af8e12e6764".decodeHex())
46+ // val address = CoinType.ETHEREUM.deriveAddress(privateKey)
47+ val privateKey= " " ;
48+ val address= " 0x87c309b999b9c15db773fcf371539537b130791e" ;
3449 private val peerMeta = WCPeerMeta (name = " Example" , url = " https://example.com" )
3550
3651 private lateinit var wcSession: WCSession
@@ -66,6 +81,41 @@ class MainActivity : AppCompatActivity() {
6681 connectButton.setOnClickListener {
6782 connect(uriInput.editText?.text?.toString() ? : return @setOnClickListener)
6883 }
84+ scanButton.setOnClickListener {
85+ barcodeLauncher.launch(ScanOptions ())
86+ }
87+ }
88+ }
89+ private val barcodeLauncher = registerForActivityResult(
90+ ScanContract ()
91+ ) { result: ScanIntentResult ->
92+ if (result.contents == null ) {
93+ val originalIntent: Intent ? = result.originalIntent
94+ if (originalIntent == null ) {
95+ Log .d(" MainActivity" , " Cancelled scan" )
96+ Toast .makeText(this @MainActivity, " Cancelled" , Toast .LENGTH_LONG ).show()
97+ } else if (originalIntent.hasExtra(Intents .Scan .MISSING_CAMERA_PERMISSION )) {
98+ Log .d(
99+ " MainActivity" ,
100+ " Cancelled scan due to missing camera permission"
101+ )
102+ Toast .makeText(
103+ this @MainActivity,
104+ " Cancelled due to missing camera permission" ,
105+ Toast .LENGTH_LONG
106+ ).show()
107+ }
108+ } else {
109+ Log .d(" MainActivity" , " Scanned" )
110+ val url = result.contents
111+
112+ uriInput.editText?.setText(url)
113+ // processWCURL(url)
114+ Toast .makeText(
115+ this @MainActivity,
116+ " Scanned: " + result.contents,
117+ Toast .LENGTH_LONG
118+ ).show()
69119 }
70120 }
71121
@@ -137,7 +187,17 @@ class MainActivity : AppCompatActivity() {
137187 .setTitle(message.type.name)
138188 .setMessage(message.data)
139189 .setPositiveButton(" Sign" ) { _, _ ->
140- wcClient.approveRequest(id, privateKey.sign(message.data.decodeHex(), CoinType .ETHEREUM .curve()))
190+ Log .e(" Sign:" , message.raw.toString());
191+ Log .e(" Sign:" , message.data);
192+ Log .e(" Sign:" , message.data.decodeHex().toString());
193+ val message = " \\ x19Ethereum Signed Message:\n ${message.data.length} "
194+
195+ Log .e(" Sign:" , message);
196+ val web3j = Web3j .build();
197+ // web3j.si
198+ // "\u0019Ethereum Signed Message:\n"
199+ // val data: ByteArray = ArrayUtils.addAll(message.toByteArray(), messageData)
200+ // wcClient.approveRequest(id, privateKey.sign(message.data.decodeHex(), CoinType.ETHEREUM.curve()))
141201 }
142202 .setNegativeButton(" Cancel" ) { _, _ ->
143203 rejectRequest(id)
@@ -176,8 +236,8 @@ class MainActivity : AppCompatActivity() {
176236 }
177237
178238 companion object {
179- init {
180- System .loadLibrary(" TrustWalletCore" )
181- }
239+ // init {
240+ // System.loadLibrary("TrustWalletCore")
241+ // }
182242 }
183243}
0 commit comments