Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed sample app for 0.9.8 #40

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
'minSdk' : 14,
'compileSdk' : 28,
'buildTools' : '28.0.3',
'androidPlugin' : '3.4.0',
'androidPlugin' : '4.0.0',

androidx_app_compat : '1.0.2',
androidx_card_view : '1.0.0',
Expand All @@ -28,14 +28,18 @@ buildscript {
'gradlePlugin': "com.android.tools.build:gradle:${versions.androidPlugin}",
]
]
versions.kotlin = '1.3.72'
}

repositories {
google()
jcenter()
gradlePluginPortal()
mavenCentral()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.38.0'
// How can we move this to the sample folder
Expand Down
4 changes: 3 additions & 1 deletion lib/src/main/kotlin/org/walletconnect/Session.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ interface Session {
val key: String,
val protocol: String = "wc",
val version: Int = 1
)
) {
fun toWCUri() = "wc:$handshakeTopic@$version?bridge=${URLEncoder.encode(bridge, "UTF-8")}&key=$key"
}

data class Config(
val handshakeTopic: String,
Expand Down
15 changes: 15 additions & 0 deletions sample/app/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Fri May 21 10:30:53 SAST 2021
android.enableJetifier=true
android.useAndroidX=true
3 changes: 2 additions & 1 deletion sample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:name=".ExampleApplication">
android:name=".ExampleApplication"
android:networkSecurityConfig="@xml/network_config">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class ExampleApplication : MultiDexApplication() {
private lateinit var moshi: Moshi
private lateinit var bridge: BridgeServer
private lateinit var storage: WCSessionStore
lateinit var config: Session.Config
lateinit var config: Session.FullyQualifiedConfig
lateinit var session: Session

fun resetSession() {
nullOnThrow { session }?.clearCallbacks()
val key = ByteArray(32).also { Random().nextBytes(it) }.toNoPrefixHexString()
config = Session.Config(UUID.randomUUID().toString(), "http://localhost:${BridgeServer.PORT}", key)
config = Session.FullyQualifiedConfig(UUID.randomUUID().toString(), "http://localhost:${BridgeServer.PORT}", key)
session = WCSession(config,
MoshiPayloadAdapter(moshi),
storage,
Expand Down
21 changes: 17 additions & 4 deletions sample/app/src/main/java/io/walletconnect/example/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class MainActivity : Activity(), Session.Callback {
when(status) {
Session.Status.Approved -> sessionApproved()
Session.Status.Closed -> sessionClosed()
Session.Status.Connected,
Session.Status.Connected -> {
requestConnectionToWallet()
}
Session.Status.Disconnected,
is Session.Status.Error -> {
// Do Stuff
Expand All @@ -32,6 +34,19 @@ class MainActivity : Activity(), Session.Callback {

override fun onMethodCall(call: Session.MethodCall) {
}

private fun requestConnectionToWallet() {
val i = Intent(Intent.ACTION_VIEW)
i.data = Uri.parse(ExampleApplication.config.toWCUri())
startActivity(i)
}

private fun navigateToWallet() {
val i = Intent(Intent.ACTION_VIEW)
i.data = Uri.parse("wc:")
startActivity(i)
}

private fun sessionApproved() {
uiScope.launch {
screen_main_status.text = "Connected: ${ExampleApplication.session.approvedAccounts()}"
Expand Down Expand Up @@ -61,9 +76,6 @@ class MainActivity : Activity(), Session.Callback {
screen_main_connect_button.setOnClickListener {
ExampleApplication.resetSession()
ExampleApplication.session.addCallback(this)
val i = Intent(Intent.ACTION_VIEW)
i.data = Uri.parse(ExampleApplication.config.toWCUri())
startActivity(i)
}
screen_main_disconnect_button.setOnClickListener {
ExampleApplication.session.kill()
Expand All @@ -86,6 +98,7 @@ class MainActivity : Activity(), Session.Callback {
::handleResponse
)
this.txRequest = txRequest
navigateToWallet()
JavonneM marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import java.util.concurrent.ConcurrentHashMap

class BridgeServer(moshi: Moshi) : WebSocketServer(InetSocketAddress(PORT)) {

private val adapter = moshi.adapter<Map<String, String>>(
private val adapter = moshi.adapter<Map<String, Any>>(
Types.newParameterizedType(
Map::class.java,
String::class.java,
String::class.java
Any::class.java
)
)

Expand All @@ -41,8 +41,8 @@ class BridgeServer(moshi: Moshi) : WebSocketServer(InetSocketAddress(PORT)) {
conn ?: error("Unknown socket")
message?.also {
val msg = adapter.fromJson(it) ?: error("Invalid message")
val type: String = msg["type"] ?: error("Type not found")
val topic: String = msg["topic"] ?: error("Topic not found")
val type: String = msg["type"] as String? ?: error("Type not found")
val topic: String = msg["topic"] as String? ?: error("Topic not found")
when (type) {
"pub" -> {
var sendMessage = false
Expand Down
8 changes: 8 additions & 0 deletions sample/app/src/main/res/xml/network_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">sslip.io</domain>
<domain includeSubdomains="false">localhost</domain>
</domain-config>
<base-config cleartextTrafficPermitted="false" />
</network-security-config>
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include ':lib' //, ':sample:app'
include ':lib', ':sample:app'