Skip to content

Commit

Permalink
Resolve signMessage on walletconnect for substrate account
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiendekaco committed Feb 22, 2024
1 parent 5222eea commit 051008e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
6 changes: 3 additions & 3 deletions packages/demo/src/web3-onboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const injected = injectedModule({


const walletConnectPolkadot = walletConnectPolkadotModule({
projectId: '59b5826141a56b204e9e0a3f7e46641d',
dappUrl: 'https://thiendekaco.github.io/SubConnect'
projectId: '762e91498a11e0acc664cdd0fd2af181',
dappUrl: 'https://w3o-demo.subwallet.app/'
})
const metamaskSDKWallet = metamaskSDK({
options: {
Expand Down Expand Up @@ -66,7 +66,7 @@ export default init({
enabled: false
}
},
projectId : '59b5826141a56b204e9e0a3f7e46641d',
projectId : '762e91498a11e0acc664cdd0fd2af181',

// An array of wallet modules that you would like to be presented to the user to select from when connecting a wallet.
wallets: [
Expand Down
33 changes: 20 additions & 13 deletions packages/walletconnectPolkadot/src/walletConnect.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { isHexString } from './index.js'
import {isHexString} from './index.js'

import type { JQueryStyleEventEmitter } from 'rxjs/internal/observable/fromEvent'
import type {JQueryStyleEventEmitter} from 'rxjs/internal/observable/fromEvent'
import type {WalletConnectOptions} from './types.js'
import type { CoreTypes } from '@walletconnect/types'
import type {
Chain,
ProviderAccounts,
WalletInit,
SubstrateProvider
} from '@subwallet_connect/common'
import {UniversalProviderOpts, RequestArguments} from "@walletconnect/universal-provider";
import { Signer } from '@polkadot/types/types/extrinsic.js'
import type {CoreTypes} from '@walletconnect/types'
import type {Chain, ProviderAccounts, SubstrateProvider, WalletInit} from '@subwallet_connect/common'
import {ProviderRpcErrorCode} from "@subwallet_connect/common";
import {RequestArguments, UniversalProviderOpts} from "@walletconnect/universal-provider";
import {Signer} from '@polkadot/types/types/extrinsic.js'

// methods that require user interaction
const methods = [
Expand Down Expand Up @@ -274,7 +270,8 @@ function walletConnect(options: WalletConnectOptions): WalletInit {


async signDummy(address: string, data: string, wallet?: Signer | undefined) {
const result = await this.request({method: 'polkadot_signMessage', params: {
const result = await this.request({
method: 'polkadot_signMessage', params: {
address,
data,
type: 'bytes'
Expand Down Expand Up @@ -355,11 +352,21 @@ function walletConnect(options: WalletConnectOptions): WalletInit {
}

try {
if(!params || !(Array.isArray(params) && params.length === 2 )) {
throw new ProviderRpcError({
code: ProviderRpcErrorCode.INVALID_PARAMS,
message: 'Your params is invalid to request this method'
})
}
const result = await this.connector?.client.request({
topic: this.connector.session.topic,
request: {
method: 'polkadot_signMessage',
params
params: {
address: params[0],
message: params[1],
type: 'bytes'
}
},
chainId: `polkadot:${chains[0].id}`
})
Expand Down

0 comments on commit 051008e

Please sign in to comment.