Skip to content

Commit

Permalink
fix(WalletConnect): fix walletconnect login
Browse files Browse the repository at this point in the history
The reason behind using `patch-package`: WalletConnect/walletconnect-utils#3
  • Loading branch information
Jakub Sydor committed Oct 15, 2021
1 parent 358e273 commit 4201fcb
Show file tree
Hide file tree
Showing 7 changed files with 34,404 additions and 3,392 deletions.
Expand Up @@ -30,15 +30,16 @@ the connection. See [MYEN-625](https://energyweb.atlassian.net/browse/MYEN-625)

### constructor

**new ControllableWalletConnect**(`connectorOpts`)
**new ControllableWalletConnect**(`connectorOpts`, `pushServerOpts?`)

#### Parameters

| Name | Type |
| :------ | :------ |
| `connectorOpts` | `IWalletConnectOptions` |
| `pushServerOpts?` | `IPushServerOptions` |

#### Overrides
#### Inherited from

WalletConnect.constructor

Expand Down
37,725 changes: 34,348 additions & 3,377 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -9,6 +9,7 @@
"dist"
],
"scripts": {
"postinstall": "patch-package",
"lint": "npx eslint ./src/**/*.ts ./test/**/*.ts",
"prebuild": "rimraf dist ethers",
"build": "npm run build:contracts && npm run build:ts && copyfiles \"ethers/**/*.d.ts\" dist",
Expand Down Expand Up @@ -60,6 +61,7 @@
"npm": ">= 6.0.0"
},
"dependencies": {
"@babel/plugin-transform-runtime": "^7.15.8",
"@babel/runtime": "^7.12.5",
"@energyweb/iam-contracts": "^3.1.0",
"@ensdomains/ens": "^0.4.5",
Expand All @@ -73,7 +75,7 @@
"@ew-did-registry/proxyidentity": "0.6.1",
"@gnosis.pm/safe-apps-sdk": "1.0.3",
"@metamask/detect-provider": "^1.2.0",
"@walletconnect/web3-provider": "1.0.0-rc.4",
"@walletconnect/ethereum-provider": "^1.6.6",
"axios": "^0.21.1",
"base64url": "^3.0.1",
"concurrently": "^6.1.0",
Expand All @@ -82,6 +84,7 @@
"js-sha3": "^0.8.0",
"lodash.difference": "^4.5.0",
"nats.ws": "^1.3.0",
"patch-package": "^6.4.7",
"qs": "^6.9.4",
"tslib": "^2.0.3",
"uuid": "^7.0.3"
Expand Down
40 changes: 40 additions & 0 deletions patches/@walletconnect+jsonrpc-provider+1.0.0.patch
@@ -0,0 +1,40 @@
diff --git a/node_modules/@walletconnect/jsonrpc-provider/dist/cjs/provider.js b/node_modules/@walletconnect/jsonrpc-provider/dist/cjs/provider.js
index 86c27ae..4dd3bb8 100644
--- a/node_modules/@walletconnect/jsonrpc-provider/dist/cjs/provider.js
+++ b/node_modules/@walletconnect/jsonrpc-provider/dist/cjs/provider.js
@@ -48,6 +48,15 @@ class JsonRpcProvider extends jsonrpc_utils_1.IJsonRpcProvider {
reject(e);
}
}
+ this.connection.on("payload", response => {
+ if (response.id !== request.id) return;
+ if (isJsonRpcError(response)) {
+ reject(response.error.message);
+ }
+ else {
+ resolve(response.result);
+ }
+ });
this.events.on(`${request.id}`, response => {
if (jsonrpc_utils_1.isJsonRpcError(response)) {
reject(response.error.message);
diff --git a/node_modules/@walletconnect/jsonrpc-provider/dist/esm/provider.js b/node_modules/@walletconnect/jsonrpc-provider/dist/esm/provider.js
index 6271b24..f540878 100644
--- a/node_modules/@walletconnect/jsonrpc-provider/dist/esm/provider.js
+++ b/node_modules/@walletconnect/jsonrpc-provider/dist/esm/provider.js
@@ -37,6 +37,15 @@ export class JsonRpcProvider extends IJsonRpcProvider {
reject(e);
}
}
+ this.connection.on("payload", response => {
+ if (response.id !== request.id) return;
+ if (isJsonRpcError(response)) {
+ reject(response.error.message);
+ }
+ else {
+ resolve(response.result);
+ }
+ });
this.events.on(`${request.id}`, response => {
if (isJsonRpcError(response)) {
reject(response.error.message);
6 changes: 3 additions & 3 deletions src/iam/iam-base.ts
Expand Up @@ -343,17 +343,17 @@ export class IAMBase {
case "accountChanged": {
isMetamask
? this._metamaskProvider?.on("accountsChanged", eventHandler)
: this._walletConnectService.getProvider().wc.on("session_update", eventHandler);
: this._walletConnectService.getProvider().on("session_update", eventHandler);
break;
}
case "disconnected": {
isMetamask === false && this._walletConnectService.getProvider()?.wc.on("disconnect", eventHandler);
isMetamask === false && this._walletConnectService.getProvider()?.on("disconnect", eventHandler);
break;
}
case "networkChanged": {
isMetamask
? this._metamaskProvider?.on("networkChanged", eventHandler)
: this._walletConnectService.getProvider().wc.on("session_update", eventHandler);
: this._walletConnectService.getProvider().on("session_update", eventHandler);
break;
}
default:
Expand Down
6 changes: 1 addition & 5 deletions src/walletconnect/ControllableWalletConnect.ts
@@ -1,5 +1,5 @@
import WalletConnect from "@walletconnect/client";
import { IWalletConnectOptions, ICreateSessionOptions } from "@walletconnect/types";
import { ICreateSessionOptions } from "@walletconnect/types";

/**
* Extension of WalletConnect client that allows session creation to be disabled
Expand All @@ -9,10 +9,6 @@ import { IWalletConnectOptions, ICreateSessionOptions } from "@walletconnect/typ
export class ControllableWalletConnect extends WalletConnect {
public canCreateSession = true;

constructor(connectorOpts: IWalletConnectOptions) {
super(connectorOpts);
}

public async createSession(opts?: ICreateSessionOptions): Promise<void> {
if (this.canCreateSession) {
super.createSession(opts);
Expand Down
9 changes: 5 additions & 4 deletions src/walletconnect/WalletConnectService.ts
@@ -1,4 +1,4 @@
import WalletConnectProvider from "@walletconnect/web3-provider";
import WalletConnectProvider from "@walletconnect/ethereum-provider";
import QRCodeModal from "@walletconnect/qrcode-modal";
import { ControllableWalletConnect } from "./ControllableWalletConnect";
import { WalletProvider } from "../types/WalletProvider";
Expand Down Expand Up @@ -32,16 +32,16 @@ export class WalletConnectService {

this._walletConnectProvider = new WalletConnectProvider({
rpc,
infuraId: this._infuraId,
connector: this._walletConnectClient,
infuraId: this._infuraId,
});

if (walletProvider === WalletProvider.EwKeyManager) {
if (!this._ewKeyManagerUrl) {
throw Error("EwKeyManager provider type specified but no url was provided.");
}
const ewKeyManagerUrl = this._ewKeyManagerUrl;
this._walletConnectProvider.wc.on("display_uri", (err, payload) => {
this._walletConnectProvider.on("display_uri", (err, payload) => {
// uri is expected to be WalletConnect Standard URI https://eips.ethereum.org/EIPS/eip-1328
const wcUri = payload.params[0];

Expand All @@ -53,6 +53,7 @@ export class WalletConnectService {
}

await this._walletConnectProvider.enable();
// await this._walletConnectProvider.connector.connect();
}

/**
Expand All @@ -73,7 +74,7 @@ export class WalletConnectService {
this._walletConnectClient.canCreateSession = false;
}
if (this._walletConnectProvider) {
await this._walletConnectProvider.close();
await this._walletConnectProvider.disconnect();
}
}

Expand Down

0 comments on commit 4201fcb

Please sign in to comment.