Skip to content

Commit

Permalink
Persist chainId (#22)
Browse files Browse the repository at this point in the history
* Persist chainId

* add chainid to store item

* use persisted chainId
  • Loading branch information
vcoolish authored Sep 30, 2020
1 parent 98a170d commit dac3a66
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ open class WCClient (

var remotePeerId: String? = null
private set

var chainId: String? = null
private set

var isConnected: Boolean = false
private set
Expand Down Expand Up @@ -155,7 +158,7 @@ open class WCClient (
check(handshakeId > 0) { "handshakeId must be greater than 0 on session approve" }

val result = WCApproveSessionResponse(
chainId = chainId,
chainId = this.chainId?.toIntOrNull() ?: chainId,
accounts = accounts,
peerId = peerId,
peerMeta = peerMeta
Expand All @@ -175,7 +178,7 @@ open class WCClient (
params = listOf(
WCSessionUpdate(
approved = approved,
chainId = chainId,
chainId = this.chainId?.toIntOrNull() ?: chainId,
accounts = accounts
)
)
Expand Down Expand Up @@ -257,6 +260,7 @@ open class WCClient (
.firstOrNull() ?: throw InvalidJsonRpcParamsException(request.id)
handshakeId = request.id
remotePeerId = param.peerId
chainId = param.chainId
onSessionRequest(request.id, param.peerMeta)
}
WCMethod.SESSION_UPDATE -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.util.*

data class WCSessionStoreItem(
val session: WCSession,
val chainId: Int,
val peerId: String,
val remotePeerId: String,
val remotePeerMeta: WCPeerMeta,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class WCSessionStoreTests {
fun test_store() {
val topic = "topic_1"
val session = WCSession.from("wc:$topic@1?bridge=https%3A%2F%2Fbridge.walletconnect.org&key=some_key")!!
val item = WCSessionStoreItem(session, "peerId", "remotePeerId", WCPeerMeta(name = "Some DApp", url = "https://dapp.com"))
val item = WCSessionStoreItem(session, 56, "peerId", "remotePeerId", WCPeerMeta(name = "Some DApp", url = "https://dapp.com"))

storage.session = item
Assert.assertNotNull(sharedPreferences.getString(SESSION_KEY, null))
Expand All @@ -42,7 +42,7 @@ class WCSessionStoreTests {
fun test_remove() {
val topic = "topic_1"
val session = WCSession.from("wc:$topic@1?bridge=https%3A%2F%2Fbridge.walletconnect.org&key=some_key")!!
val item = WCSessionStoreItem(session, "peerId","remotePeerId", WCPeerMeta(name = "Some DApp", url = "https://dapp.com"))
val item = WCSessionStoreItem(session, 56, "peerId","remotePeerId", WCPeerMeta(name = "Some DApp", url = "https://dapp.com"))

storage.session = item
storage.session = null
Expand Down

0 comments on commit dac3a66

Please sign in to comment.