Skip to content

Commit 03f135b

Browse files
authored
Merge pull request #82 from WalletConnect/develop
Beta 04
2 parents c12dfa2 + 7a85b5e commit 03f135b

File tree

50 files changed

+1441
-578
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1441
-578
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
Kotlin implementation of WalletConnect v2 protocol for Android applications.
66

7+
[![](https://jitpack.io/v/WalletConnect/WalletConnectKotlinV2.svg)](https://jitpack.io/#WalletConnect/WalletConnectKotlinV2)
8+
9+
710
## Requirements
811
* Android min SDK 23
912
* Java 11
@@ -22,7 +25,7 @@ allprojects {
2225
app/build.gradle
2326

2427
```gradle
25-
implementation("com.github.WalletConnect:WalletConnectKotlinV2:1.0.0-beta02")
28+
implementation("com.github.WalletConnect:WalletConnectKotlinV2:release_version")
2629
```
2730

2831
 
@@ -318,7 +321,7 @@ val pairingTopic: String? = /* Optional parameter, use it when the pairing betw
318321
fun WalletConnectClient.connect(sessionPermissions, pairingTopic): String?
319322
```
320323

321-
The `WalletConnect.connect` method returns the pairing URI that is shared with wallet out of bound, as qr code or mobile linking. The pairing
324+
The `WalletConnectClient.connect` method returns the pairing URI that is shared with wallet out of bound, as qr code or mobile linking. The pairing
322325
URI is null when there is already an established pairing between peers. To establish a session, pass the existing pairing's topic to the connect
323326
method. The SDK will send the SessionProposal for the given topic.
324327

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ fun DependencyHandlerScope.bouncyCastle() {
7070
}
7171

7272
fun DependencyHandlerScope.sqlDelight() {
73+
val sqlCipherVersion = "4.5.0@aar"
7374
"implementation"("com.squareup.sqldelight:android-driver:$sqlDelightVersion")
7475
"implementation"("com.squareup.sqldelight:coroutines-extensions-jvm:$sqlDelightVersion")
76+
"implementation"("net.zetetic:android-database-sqlcipher:$sqlCipherVersion")
7577

7678
"testImplementation"("com.squareup.sqldelight:sqlite-driver:$sqlDelightVersion")
7779
"testImplementation"("org.xerial:sqlite-jdbc:3.8.10.2") {
@@ -100,7 +102,7 @@ fun DependencyHandlerScope.jUnit5() {
100102
}
101103

102104
fun DependencyHandlerScope.androidXTest() {
103-
val androidxTestVersion ="1.4.0"
105+
val androidxTestVersion = "1.4.0"
104106

105107
"testImplementation"("androidx.test.ext:junit-ktx:1.1.3")
106108
"testImplementation"("androidx.test:core-ktx:$androidxTestVersion")

licenses/SQLCipher

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2008-2020 Zetetic LLC
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above copyright
9+
notice, this list of conditions and the following disclaimer in the
10+
documentation and/or other materials provided with the distribution.
11+
* Neither the name of the ZETETIC LLC nor the
12+
names of its contributors may be used to endorse or promote products
13+
derived from this software without specific prior written permission.
14+
15+
THIS SOFTWARE IS PROVIDED BY ZETETIC LLC ''AS IS'' AND ANY
16+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
DISCLAIMED. IN NO EVENT SHALL ZETETIC LLC BE LIABLE FOR ANY
19+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

sample/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ android {
99

1010
defaultConfig {
1111
applicationId = "com.walletconnect.sample"
12-
minSdk = 23
12+
minSdk = 24
1313
targetSdk = 30
1414
versionCode = 1
1515
versionName = "1.0"

sample/src/main/java/com/walletconnect/sample/dapp/DappFragment.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class DappFragment : Fragment(R.layout.dapp_fragment), WalletConnectClient.DappD
2222
setupToolbar()
2323

2424
//TODO: Improve the dApp sample app. Code below is only for test purposes!
25-
2625
// val connectParams = WalletConnect.Params.Connect(
2726
// permissions = WalletConnect.Model.SessionPermissions(
2827
// WalletConnect.Model.Blockchain(listOf("eip155:69")),
@@ -55,6 +54,9 @@ class DappFragment : Fragment(R.layout.dapp_fragment), WalletConnectClient.DappD
5554
override fun onSessionUpgrade(upgradedSession: WalletConnect.Model.UpgradedSession) {
5655
}
5756

57+
override fun onSessionDelete(deletedSession: WalletConnect.Model.DeletedSession) {
58+
}
59+
5860
override fun onPairingUpdated(pairing: WalletConnect.Model.SettledPairing) {
5961
}
6062
}

sample/src/main/java/com/walletconnect/sample/wallet/WalletFragment.kt

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import android.view.View
55
import android.widget.Toast
66
import androidx.fragment.app.Fragment
77
import androidx.fragment.app.activityViewModels
8-
import androidx.lifecycle.lifecycleScope
98
import androidx.navigation.fragment.findNavController
109
import com.walletconnect.sample.R
1110
import com.walletconnect.sample.databinding.WalletFragmentBinding
1211
import com.walletconnect.sample.wallet.ui.*
13-
import kotlinx.coroutines.launch
1412
import com.walletconnect.sample.wallet.ui.dialog.SessionDetailsDialog
1513
import com.walletconnect.sample.wallet.ui.dialog.SessionProposalDialog
1614
import com.walletconnect.sample.wallet.ui.dialog.SessionRequestDialog
@@ -31,39 +29,37 @@ class WalletFragment : Fragment(R.layout.wallet_fragment), SessionActionListener
3129
setupToolbar()
3230
binding.sessions.adapter = sessionAdapter
3331

34-
lifecycleScope.launch {
35-
viewModel.eventFlow.observe(viewLifecycleOwner) { event ->
36-
when (event) {
37-
is InitSessionsList -> sessionAdapter.updateList(event.sessions)
38-
is ShowSessionProposalDialog -> {
39-
proposalDialog = SessionProposalDialog(
40-
requireContext(),
41-
viewModel::approve,
42-
viewModel::reject,
43-
event.proposal
44-
)
45-
proposalDialog?.show()
46-
}
47-
is ShowSessionRequestDialog -> {
48-
requestDialog = SessionRequestDialog(
49-
requireContext(),
50-
{ sessionRequest -> viewModel.respondRequest(sessionRequest) },
51-
{ sessionRequest -> viewModel.rejectRequest(sessionRequest) },
52-
event.sessionRequest,
53-
event.session
54-
)
55-
requestDialog?.show()
56-
}
57-
is UpdateActiveSessions -> {
58-
proposalDialog?.dismiss()
59-
sessionAdapter.updateList(event.sessions)
60-
event.message?.let {
61-
Toast.makeText(requireContext(), it, Toast.LENGTH_SHORT).show()
62-
}
32+
viewModel.eventFlow.observe(viewLifecycleOwner) { event ->
33+
when (event) {
34+
is InitSessionsList -> sessionAdapter.updateList(event.sessions)
35+
is ShowSessionProposalDialog -> {
36+
proposalDialog = SessionProposalDialog(
37+
requireContext(),
38+
viewModel::approve,
39+
viewModel::reject,
40+
event.proposal
41+
)
42+
proposalDialog?.show()
43+
}
44+
is ShowSessionRequestDialog -> {
45+
requestDialog = SessionRequestDialog(
46+
requireContext(),
47+
{ sessionRequest -> viewModel.respondRequest(sessionRequest) },
48+
{ sessionRequest -> viewModel.rejectRequest(sessionRequest) },
49+
event.sessionRequest,
50+
event.session
51+
)
52+
requestDialog?.show()
53+
}
54+
is UpdateActiveSessions -> {
55+
proposalDialog?.dismiss()
56+
sessionAdapter.updateList(event.sessions)
57+
event.message?.let {
58+
Toast.makeText(requireContext(), it, Toast.LENGTH_SHORT).show()
6359
}
64-
is RejectSession -> proposalDialog?.dismiss()
65-
is PingSuccess -> Toast.makeText(requireContext(), "Successful session ping", Toast.LENGTH_SHORT).show()
6660
}
61+
is RejectSession -> proposalDialog?.dismiss()
62+
is PingSuccess -> Toast.makeText(requireContext(), "Successful session ping", Toast.LENGTH_SHORT).show()
6763
}
6864
}
6965
}

sample/src/main/java/com/walletconnect/sample/wallet/WalletViewModel.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class WalletViewModel : ViewModel(), WalletConnectClient.WalletDelegate {
3838
val approve = WalletConnect.Params.Approve(proposal, accounts)
3939

4040
WalletConnectClient.approve(approve, object : WalletConnect.Listeners.SessionApprove {
41+
4142
override fun onSuccess(settledSession: WalletConnect.Model.SettledSession) {
4243
viewModelScope.launch { _eventFlow.emit(UpdateActiveSessions(WalletConnectClient.getListOfSettledSessions())) }
4344
}
@@ -64,8 +65,12 @@ class WalletViewModel : ViewModel(), WalletConnectClient.WalletDelegate {
6465
})
6566
}
6667

67-
fun disconnect(topic: String, reason: String = "Reason") {
68-
val disconnect = WalletConnect.Params.Disconnect(topic, reason)
68+
fun disconnect(topic: String) {
69+
val disconnect = WalletConnect.Params.Disconnect(
70+
sessionTopic = topic,
71+
reason = "User disconnects",
72+
reasonCode = 1000
73+
)
6974

7075
WalletConnectClient.disconnect(disconnect, object : WalletConnect.Listeners.SessionDelete {
7176
override fun onSuccess(deletedSession: WalletConnect.Model.DeletedSession) {
@@ -113,7 +118,7 @@ class WalletViewModel : ViewModel(), WalletConnectClient.WalletDelegate {
113118
fun sessionUpdate(session: WalletConnect.Model.SettledSession) {
114119
val update = WalletConnect.Params.Update(
115120
sessionTopic = session.topic,
116-
sessionState = WalletConnect.Model.SessionState(accounts = listOf("eip155:8001:0xa0A6c118b1B25207A8A764E1CAe1635339bedE62"))
121+
sessionState = WalletConnect.Model.SessionState(accounts = listOf("${proposal.chains[0]}:0xa0A6c118b1B25207A8A764E1CAe1635339bedE62"))
117122
)
118123

119124
WalletConnectClient.update(update, object : WalletConnect.Listeners.SessionUpdate {

walletconnectv2/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ android {
1414
compileSdk = 30
1515

1616
defaultConfig {
17-
minSdk = 23
17+
minSdk = 24
1818
targetSdk = 30
1919

2020
testInstrumentationRunner = "com.walletconnect.walletconnectv2.WCTestRunner"

walletconnectv2/src/main/kotlin/com/walletconnect/walletconnectv2/client/WalletConnect.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.walletconnect.walletconnectv2.client
22

33
import android.app.Application
44
import android.net.Uri
5-
import com.walletconnect.walletconnectv2.core.model.type.ControllerType
5+
import com.walletconnect.walletconnectv2.core.model.type.enums.ControllerType
66
import com.walletconnect.walletconnectv2.storage.history.model.JsonRpcStatus
77
import java.net.URI
88

@@ -59,16 +59,14 @@ object WalletConnect {
5959
val icons: List<URI>,
6060
val chains: List<String>,
6161
val methods: List<String>,
62-
val types: List<String>,
62+
val types: List<String>? = null,
6363
val topic: String,
6464
val proposerPublicKey: String,
6565
val isController: Boolean,
6666
val ttl: Long,
6767
val accounts: List<String>,
6868
val relayProtocol: String
69-
) : Model() {
70-
val icon: String = icons.first().toString()
71-
}
69+
) : Model()
7270

7371
data class SessionRequest(
7472
val topic: String,
@@ -99,7 +97,7 @@ object WalletConnect {
9997

10098
data class JsonRpc(val methods: List<String>)
10199

102-
data class Notifications(val types: List<String>)
100+
data class Notifications(val types: List<String>?)
103101
}
104102
}
105103

@@ -120,7 +118,7 @@ object WalletConnect {
120118

121119
data class UpgradedSession(val topic: String, val permissions: SessionPermissions) : Model()
122120

123-
data class SessionPermissions(val blockchain: Blockchain, val jsonRpc: Jsonrpc, val notification: Notification? = null) : Model()
121+
data class SessionPermissions(val blockchain: Blockchain, val jsonRpc: Jsonrpc, val notification: Notifications? = null) : Model()
124122

125123
data class Blockchain(val chains: List<String>) : Model()
126124

@@ -156,7 +154,7 @@ object WalletConnect {
156154
) : JsonRpcResponse()
157155

158156
data class Error(
159-
val code: Long,
157+
val code: Int,
160158
val message: String
161159
)
162160
}
@@ -244,7 +242,7 @@ object WalletConnect {
244242

245243
data class Reject(val rejectionReason: String, val proposalTopic: String) : Params()
246244

247-
data class Disconnect(val sessionTopic: String, val reason: String) : Params()
245+
data class Disconnect(val sessionTopic: String, val reason: String, val reasonCode: Int) : Params()
248246

249247
data class Response(val sessionTopic: String, val jsonRpcResponse: Model.JsonRpcResponse) : Params()
250248

walletconnectv2/src/main/kotlin/com/walletconnect/walletconnectv2/client/WalletConnectClient.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.walletconnect.walletconnectv2.client
22

33
import com.walletconnect.walletconnectv2.client.mapper.*
4-
import com.walletconnect.walletconnectv2.core.exceptions.WalletConnectException
4+
import com.walletconnect.walletconnectv2.core.exceptions.client.WalletConnectException
55
import com.walletconnect.walletconnectv2.core.model.vo.TopicVO
66
import com.walletconnect.walletconnectv2.core.scope.scope
77
import com.walletconnect.walletconnectv2.di.*
@@ -68,6 +68,7 @@ object WalletConnectClient {
6868
is EngineDO.SessionApproved -> delegate.onSessionApproved(event.toClientSessionApproved())
6969
is EngineDO.SessionUpdate -> delegate.onSessionUpdate(event.toClientSessionsUpdate())
7070
is EngineDO.SessionUpgrade -> delegate.onSessionUpgrade(event.toClientSessionsUpgrade())
71+
is EngineDO.SessionDelete -> delegate.onSessionDelete(event.toClientDeletedSession())
7172
}
7273
}
7374
}
@@ -189,7 +190,7 @@ object WalletConnectClient {
189190
"WalletConnectClient needs to be initialized first using the initialize function"
190191
}
191192

192-
engineInteractor.disconnect(disconnect.sessionTopic, disconnect.reason,
193+
engineInteractor.disconnect(disconnect.sessionTopic, disconnect.reason, disconnect.reasonCode,
193194
{ (topic, reason) -> listener?.onSuccess(WalletConnect.Model.DeletedSession(topic, reason)) },
194195
{ error -> listener?.onError(error) })
195196
}
@@ -255,5 +256,6 @@ object WalletConnectClient {
255256
fun onSessionRejected(rejectedSession: WalletConnect.Model.RejectedSession)
256257
fun onSessionUpdate(updatedSession: WalletConnect.Model.UpdatedSession)
257258
fun onSessionUpgrade(upgradedSession: WalletConnect.Model.UpgradedSession)
259+
fun onSessionDelete(deletedSession: WalletConnect.Model.DeletedSession)
258260
}
259261
}

0 commit comments

Comments
 (0)