Skip to content

Commit fbb51e7

Browse files
committed
comment wallet core.
1 parent 25871ff commit fbb51e7

File tree

5 files changed

+100
-29
lines changed

5 files changed

+100
-29
lines changed

.idea/runConfigurations.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

app/build.gradle

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,12 @@ dependencies {
3939
implementation "com.google.code.gson:gson:2.8.8"
4040

4141
implementation "com.github.TrustWallet:wallet-connect-kotlin:1.5.4"
42-
implementation "com.trustwallet:wallet-core:2.6.33"
42+
//implementation "com.trustwallet:wallet-core:2.6.33"
43+
44+
// Bar code scanning
45+
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
46+
implementation 'com.google.zxing:core:3.4.1'
47+
48+
implementation 'org.web3j:core:5.0.0'
49+
4350
}

app/src/main/java/com/trustwallet/walletconnect/sample/MainActivity.kt

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.trustwallet.walletconnect.sample
22

3+
import android.content.Intent
34
import android.os.Bundle
5+
import android.util.Log
6+
import android.widget.Toast
7+
import androidx.activity.result.ActivityResultCallback
48
import androidx.appcompat.app.AlertDialog
59
import androidx.appcompat.app.AppCompatActivity
610
import com.google.gson.GsonBuilder
@@ -19,18 +23,29 @@ import com.trustwallet.walletconnect.models.session.WCSession
1923
import kotlinx.android.synthetic.main.activity_main.*
2024
import kotlinx.android.synthetic.main.activity_main.view.*
2125
import 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

2539
class 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
}

app/src/main/res/layout/activity_main.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,20 @@
103103
app:layout_constraintEnd_toEndOf="parent"
104104
style="@style/Widget.AppCompat.Button.Colored"
105105
/>
106+
107+
<com.google.android.material.button.MaterialButton
108+
android:id="@+id/scanButton"
109+
style="@style/Widget.AppCompat.Button.Colored"
110+
android:layout_width="match_parent"
111+
android:layout_height="wrap_content"
112+
android:layout_marginStart="16dp"
113+
android:layout_marginTop="96dp"
114+
android:layout_marginEnd="16dp"
115+
android:paddingTop="12dp"
116+
android:paddingBottom="12dp"
117+
android:text="Scan QR-Code"
118+
app:layout_constraintEnd_toEndOf="parent"
119+
app:layout_constraintHorizontal_bias="0.0"
120+
app:layout_constraintStart_toStartOf="parent"
121+
app:layout_constraintTop_toBottomOf="@id/content" />
106122
</androidx.constraintlayout.widget.ConstraintLayout>

build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ allprojects {
2222
jcenter()
2323
mavenCentral()
2424
maven { url 'https://jitpack.io' }
25-
maven {
26-
url = uri("https://maven.pkg.github.com/trustwallet/wallet-core")
27-
credentials {
28-
username = System.getenv('GITHUB_USER')
29-
password = System.getenv('GITHUB_TOKEN')
30-
}
31-
}
25+
// maven {
26+
// url = uri("https://maven.pkg.github.com/trustwallet/wallet-core")
27+
// credentials {
28+
// username = System.getenv('GITHUB_USER')
29+
// password = System.getenv('GITHUB_TOKEN')
30+
// }
31+
// }
3232
}
3333
}
3434

0 commit comments

Comments
 (0)