Skip to content

Commit

Permalink
Merge pull request #134 from WalletConnect/develop
Browse files Browse the repository at this point in the history
Beta 100 Release
  • Loading branch information
Talhaali00 authored Apr 21, 2022
2 parents 03f135b + c0acde3 commit 2d85ed0
Show file tree
Hide file tree
Showing 261 changed files with 7,933 additions and 5,057 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,6 @@ lint/tmp/

# Android Profiling
*.hprof

# Project ID
/samples_common/src/main/res/values/project_id.xml
283 changes: 141 additions & 142 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.1.0")
classpath("com.android.tools.build:gradle:7.1.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
classpath("com.squareup.sqldelight:gradle-plugin:$sqlDelightVersion")
}
Expand Down
17 changes: 11 additions & 6 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.gradle.api.JavaVersion
import org.gradle.kotlin.dsl.DependencyHandlerScope

const val kotlinVersion = "1.5.31"
const val kotlinVersion = "1.6.10"
val jvmVersion = JavaVersion.VERSION_11
const val sqlDelightVersion = "1.5.2"

Expand All @@ -22,13 +22,13 @@ fun DependencyHandlerScope.lifecycle() {
val lifecycleVersion = "2.3.1"
"implementation"("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion")
"implementation"("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion")
"implementation"("androidx.lifecycle:lifecycle-runtime-ktx:2.4.0-alpha01")
"implementation"("androidx.lifecycle:lifecycle-runtime-ktx:2.4.1")
}

fun DependencyHandlerScope.navigationComponent() {
val navVersion = "2.3.5"
"implementation"("androidx.navigation:navigation-fragment-ktx:$navVersion")
"implementation"("androidx.navigation:navigation-ui-ktx:$navVersion")
val navVersion = "2.4.1"
"api"("androidx.navigation:navigation-fragment-ktx:$navVersion")
"api"("androidx.navigation:navigation-ui-ktx:$navVersion")
}

fun DependencyHandlerScope.coroutines() {
Expand All @@ -50,7 +50,7 @@ fun DependencyHandlerScope.scarlet() {
}

fun DependencyHandlerScope.moshi() {
val moshiVersion = "1.12.0"
val moshiVersion = "1.13.0"
"implementation"("com.squareup.moshi:moshi-adapters:$moshiVersion")
"implementation"("com.squareup.moshi:moshi-kotlin:$moshiVersion")
"kapt"("com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion")
Expand Down Expand Up @@ -88,6 +88,11 @@ fun DependencyHandlerScope.koin() {
"api"("io.insert-koin:koin-android:$koinVersion")
}

fun DependencyHandlerScope.glide_N_kapt() {
"implementation"("com.github.bumptech.glide:glide:4.12.0")
"kapt"("com.github.bumptech.glide:compiler:4.12.0")
}

fun DependencyHandlerScope.jUnit5() {
val jUnit5Version = "5.7.2"

Expand Down
34 changes: 13 additions & 21 deletions sample/build.gradle.kts → dapp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@ plugins {
}

android {
compileSdk = 30
compileSdk = 32

defaultConfig {
applicationId = "com.walletconnect.sample"
applicationId = "com.walletconnect.dapp"
minSdk = 24
targetSdk = 30
targetSdk = 32
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
viewBinding = true
}

buildTypes {
getByName("release") {
release {
isMinifyEnabled = false
signingConfig = signingConfigs.getByName("debug")
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
Expand All @@ -37,24 +33,20 @@ android {
kotlinOptions {
jvmTarget = jvmVersion.toString()
}

buildFeatures {
viewBinding = true
}
}

dependencies {
implementation(project(":walletconnectv2"))
// implementation("com.github.walletconnect-labs.walletconnectkotlinv2:walletconnectkotlinv2:1.0.0-alpha01")
implementation(project(":samples_common"))

glide_N_kapt()
implementation("com.github.kenglxn.QRGen:android:2.6.0")

coroutines()
navigationComponent()
ktxCore()
lifecycle()
scanner()

implementation("com.github.bumptech.glide:glide:4.12.0")
kapt("com.github.bumptech.glide:compiler:4.12.0")
implementation("androidx.appcompat:appcompat:1.3.1")
implementation("com.google.android.material:material:1.4.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.1")
implementation("androidx.legacy:legacy-support-v4:1.0.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
}
2 changes: 1 addition & 1 deletion sample/proguard-rules.pro → dapp/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.kts.
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
Expand Down
25 changes: 25 additions & 0 deletions dapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.walletconnect.dapp">

<application
android:name=".DappSampleApplication"
android:allowBackup="true"
android:icon="@drawable/ic_walletconnect_circle_blue"
android:label="@string/app_name"
android:roundIcon="@drawable/ic_walletconnect_circle_blue"
android:supportsRtl="true"
android:theme="@style/Theme.WalletConnect">

<activity
android:name="com.walletconnect.dapp.ui.host.DappSampleActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.walletconnect.dapp

import android.app.Application
import com.walletconnect.sample_common.R
import com.walletconnect.sample_common.WALLET_CONNECT_PROD_RELAY_URL
import com.walletconnect.walletconnectv2.client.WalletConnect
import com.walletconnect.walletconnectv2.client.WalletConnectClient

class DappSampleApplication: Application() {

override fun onCreate() {
super.onCreate()

// This is strictly for sample purposes
val projectId = resources.getString(R.string.project_id)

// Sample of how to use parts of a URI to initialize the WalletConnect SDK
// val initParts = WalletConnect.Params.Init(
// application = this,
// useTls = true,
// hostName = WALLET_CONNECT_PROD_RELAY_URL,
// projectId = projectId, //TODO: register at https://walletconnect.com/register to get a project ID
// metadata = WalletConnect.Model.AppMetaData(
// name = "Kotlin Dapp",
// description = "Dapp description",
// url = "example.dapp",
// icons = listOf("https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media")
// )
// )

// Sample of how to use a URI to initialize the WalletConnect SDK
val initString = WalletConnect.Params.Init(
application = this,
relayServerUrl = "wss://$WALLET_CONNECT_PROD_RELAY_URL?projectId=$projectId", //TODO: register at https://walletconnect.com/register to get a project ID
metadata = WalletConnect.Model.AppMetaData(
name = "Kotlin Dapp",
description = "Dapp description",
url = "example.dapp",
icons = listOf("https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media")
)
)

WalletConnectClient.initialize(initString)
}
}
80 changes: 80 additions & 0 deletions dapp/src/main/kotlin/com/walletconnect/dapp/domain/DappDelegate.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.walletconnect.dapp.domain

import com.walletconnect.walletconnectv2.client.WalletConnect
import com.walletconnect.walletconnectv2.client.WalletConnectClient
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch

object DappDelegate : WalletConnectClient.DappDelegate {
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
private val _wcEventModels: MutableSharedFlow<WalletConnect.Model?> = MutableSharedFlow()
val wcEventModels: SharedFlow<WalletConnect.Model?> = _wcEventModels.asSharedFlow()

var selectedSessionTopic: String? = null
private set

init {
WalletConnectClient.setDappDelegate(this)
}

override fun onSessionApproved(approvedSession: WalletConnect.Model.ApprovedSession) {
selectedSessionTopic = approvedSession.topic

scope.launch {
_wcEventModels.emit(approvedSession)
}
}

override fun onSessionRejected(rejectedSession: WalletConnect.Model.RejectedSession) {
scope.launch {
_wcEventModels.emit(rejectedSession)
}
}

override fun onSessionUpdateAccounts(updatedSessionAccounts: WalletConnect.Model.UpdatedSessionAccounts) {
scope.launch {
_wcEventModels.emit(updatedSessionAccounts)
}
}

override fun onSessionUpdateMethods(updatedSessionMethods: WalletConnect.Model.UpdatedSessionMethods) {
scope.launch {
_wcEventModels.emit(updatedSessionMethods)
}
}

override fun onSessionUpdateEvents(updatedSessionEvents: WalletConnect.Model.UpdatedSessionEvents) {
scope.launch {
_wcEventModels.emit(updatedSessionEvents)
}
}

override fun onSessionDelete(deletedSession: WalletConnect.Model.DeletedSession) {
deselectAccountDetails()

scope.launch {
_wcEventModels.emit(deletedSession)
}
}

override fun onUpdateSessionExpiry(session: WalletConnect.Model.Session) {
scope.launch {
_wcEventModels.emit(session)
}
}

override fun onSessionRequestResponse(response: WalletConnect.Model.SessionRequestResponse) {
scope.launch {
_wcEventModels.emit(response)
}
}

fun deselectAccountDetails() {
selectedSessionTopic = null
}
}
22 changes: 22 additions & 0 deletions dapp/src/main/kotlin/com/walletconnect/dapp/ui/SampleDappEvents.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.walletconnect.dapp.ui

sealed class SampleDappEvents {

object SessionApproved : SampleDappEvents()

object SessionRejected : SampleDappEvents()

data class PingSuccess(val topic: String) : SampleDappEvents()

object PingError : SampleDappEvents()

object Disconnect : SampleDappEvents()

data class RequestSuccess(val result: String) : SampleDappEvents()

data class RequestPeerError(val errorMsg: String) : SampleDappEvents()

data class RequestError(val exceptionMsg: String) : SampleDappEvents()

object NoAction : SampleDappEvents()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.walletconnect.dapp.ui.connect

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.walletconnect.dapp.domain.DappDelegate
import com.walletconnect.dapp.ui.SampleDappEvents
import com.walletconnect.dapp.ui.connect.chain_select.ChainSelectionUI
import com.walletconnect.sample_common.EthTestChains
import com.walletconnect.sample_common.tag
import com.walletconnect.walletconnectv2.client.WalletConnect
import com.walletconnect.walletconnectv2.client.WalletConnectClient
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch

class ConnectViewModel : ViewModel() {
private val _listOfChainUI: MutableList<ChainSelectionUI> = mutableListOf()
get() {
return if (field.isEmpty()) {
EthTestChains.values().mapTo(field) {
ChainSelectionUI(it.chainName, it.parentChain, it.chainId, it.icon, it.methods)
}
} else {
field
}
}
val listOfChainUI: List<ChainSelectionUI> = _listOfChainUI

private val navigationChannel = Channel<SampleDappEvents>(Channel.BUFFERED)
val navigation = navigationChannel.receiveAsFlow()

init {
DappDelegate.wcEventModels.map { walletEvent: WalletConnect.Model? ->
when (walletEvent) {
is WalletConnect.Model.ApprovedSession -> SampleDappEvents.SessionApproved
is WalletConnect.Model.RejectedSession -> SampleDappEvents.SessionRejected
else -> SampleDappEvents.NoAction
}
}.onEach { event ->
navigationChannel.trySend(event)
}.launchIn(viewModelScope)
}

fun updateSelectedChainUI(position: Int, isChecked: Boolean) {
_listOfChainUI[position].isSelected = isChecked
}

fun connectToWallet(pairingTopicPosition: Int = -1, onProposedSequence: (WalletConnect.Model.ProposedSequence) -> Unit = {}) {
var pairingTopic: String? = null

if (pairingTopicPosition > -1) {
pairingTopic = WalletConnectClient.getListOfSettledPairings()[pairingTopicPosition].topic
}

val selectedChains: List<ChainSelectionUI> = listOfChainUI.filter { it.isSelected }
val chains = selectedChains.map { "${it.parentChain}:${it.chainId}" }
val methods = selectedChains.flatMap { it.methods }.distinct()

val connectParams = WalletConnect.Params.Connect(
chains = chains,
methods = methods,
events = listOf(),
pairingTopic = pairingTopic)

WalletConnectClient.connect(connectParams,
onProposedSequence = { proposedSequence ->
viewModelScope.launch(Dispatchers.Main) {
onProposedSequence(proposedSequence)
}

},
onFailure = { error -> Log.e(tag(this@ConnectViewModel), error.error.stackTraceToString()) })
}
}
Loading

0 comments on commit 2d85ed0

Please sign in to comment.