Skip to content

Commit

Permalink
add cosmostation walletconnect modal to sample
Browse files Browse the repository at this point in the history
  • Loading branch information
luca992 committed Jan 12, 2023
1 parent 36efbc5 commit 7336479
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
11 changes: 11 additions & 0 deletions kotlin-js-store/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,17 @@
resolved "https://registry.yarnpkg.com/@cosmjs/utils/-/utils-0.29.3.tgz#d7e1f381267e61b7d3219ebd75d46defc397cd43"
integrity sha512-UuKoBN2xiRXcBpz7jzCwagKhOnLOsRmR8mu3IzY+Yx38i8rW52FSXMbxC/yE83X0vLea+zgMQFPwv0gy4QWUJw==

"@cosmostation/wc-modal@^0.0.5":
version "0.0.5"
resolved "https://registry.yarnpkg.com/@cosmostation/wc-modal/-/wc-modal-0.0.5.tgz#1d76e050dcd9eadc133ebc42aa547ee9b8e0c510"
integrity sha512-r/DjNIrmDkncGihLg6/wF9SeqKbPG4er4XPt8hTuHj1FR+MaVfYSpICd4ghagGMKHW9oB4u7kpHzbz3ns4JPxw==
dependencies:
"@walletconnect/browser-utils" "^1.6.5"
"@walletconnect/types" "^1.6.5"
qrcode.react "^1.0.1"
react "^16.14.0"
react-dom "^16.14.0"

"@discoveryjs/json-ext@^0.5.0":
version "0.5.7"
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70"
Expand Down
1 change: 1 addition & 0 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ kotlin {
implementation(npm("@walletconnect/client", "^1.8.0"))
implementation(npm("@keplr-wallet/wc-client", "^0.11.17"))
implementation(npm("@keplr-wallet/wc-qrcode-modal", "^0.11.17"))
implementation(npm("@cosmostation/wc-modal", "^0.0.5"))
implementation(npm("@babel/core", "^7.18.13"))
implementation(npm("events", "^3.3.0"))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@file:JsModule("@cosmostation/wc-modal")
@file:JsNonModule

package jslib.walletconnect

import org.khronos.webgl.*
import org.w3c.dom.*
import org.w3c.dom.events.*
import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.dom.url.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.performance.*
import org.w3c.workers.*
import org.w3c.xhr.*
import kotlin.js.*

external class CosmostationWCModal() : IQRCodeModal {
override fun open(uri: String, cb: Any, opts: Any) = definedExternally
override fun close()
}
32 changes: 24 additions & 8 deletions sample/src/jsMain/kotlin/main.js.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.eqoty.secretk.client.SigningCosmWasmClient
import io.eqoty.wallet.MetaMaskWalletWrapper
import io.eqoty.wallet.OfflineSignerOnlyAminoWalletWrapper
import jslib.walletconnect.*
import jslib.walletconnect.IQRCodeModal
import jslibs.secretjs.MetaMaskWallet
import kotlinx.browser.window
import kotlinx.coroutines.MainScope
Expand All @@ -25,8 +26,8 @@ fun main() {
application {
// val client = getClientWithMetamaskWallet(Chain.Pulsar2)
// val client = setupEthWalletConnectAndGetWallet(Chain.Pulsar2)
val client = getClientWithKeplrWallet(Chain.Pulsar2)
// val client = setupKeplrWalletConnectAndGetWallet(Chain.Secret4)
// val client = getClientWithKeplrWallet(Chain.Pulsar2)
val client = setupCosmosWalletConnectAndGetWallet(Chain.Secret4, WalletConnectModal.Cosmostation)

console.log(client)
onWasmReady {
Expand Down Expand Up @@ -149,16 +150,31 @@ suspend fun getClientWithMetamaskWallet(chain: Chain): SigningCosmWasmClient {
)
}

enum class WalletConnectModal(val signingMethods: Array<String>, val qrcodeModal: IQRCodeModal){
Keplr(
signingMethods = arrayOf(
"keplr_enable_wallet_connect_v1",
"keplr_sign_amino_wallet_connect_v1",
),
qrcodeModal = KeplrQRCodeModalV1()
),
Cosmostation(
signingMethods = arrayOf(
// "cosmostation_enable_wallet_connect_v1",
// "cosmostation_sign_amino_wallet_connect_v1",
"cosmostation_wc_accounts_v1",
"cosmostation_wc_sign_tx_v1",
),
qrcodeModal = CosmostationWCModal()
)
}

suspend fun setupKeplrWalletConnectAndGetWallet(chain: Chain): SigningCosmWasmClient {
suspend fun setupCosmosWalletConnectAndGetWallet(chain: Chain, wcModal: WalletConnectModal): SigningCosmWasmClient {
val connector = WalletConnect(
IWalletConnectOptionsInstance(
bridge = "https://bridge.walletconnect.org", // Required
signingMethods = arrayOf(
"keplr_enable_wallet_connect_v1",
"keplr_sign_amino_wallet_connect_v1",
),
qrcodeModal = KeplrQRCodeModalV1(),
signingMethods = wcModal.signingMethods,
qrcodeModal = wcModal.qrcodeModal,
)
)
val keplr = if (!connector.connected) {
Expand Down

0 comments on commit 7336479

Please sign in to comment.