From 163e02cbf00c6b1591d16c9a108f1112f3d8f28f Mon Sep 17 00:00:00 2001 From: Archit Date: Tue, 13 Jun 2023 16:46:43 +0530 Subject: [PATCH 1/3] fix switch chain in plugins --- demo/react-app/package-lock.json | 117 ++++++++++++------ demo/react-app/package.json | 1 + demo/react-app/src/components/Main.tsx | 8 +- demo/react-app/src/services/web3auth.tsx | 51 +++++++- .../src/plugin.ts | 2 +- .../src/plugin.ts | 2 +- 6 files changed, 137 insertions(+), 44 deletions(-) diff --git a/demo/react-app/package-lock.json b/demo/react-app/package-lock.json index 4193db07a..3496eee8b 100644 --- a/demo/react-app/package-lock.json +++ b/demo/react-app/package-lock.json @@ -17,6 +17,7 @@ "@web3auth/modal": "file:../../packages/modal", "@web3auth/openlogin-adapter": "file:../../packages/adapters/openlogin-adapter", "@web3auth/solana-provider": "file:../../packages/providers/solana-provider", + "@web3auth/torus-wallet-connector-plugin": "file:../../packages/plugins/torus-wallet-connector-plugin", "path-browserify": "^1.0.1", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -43,13 +44,13 @@ }, "../../packages/adapters/openlogin-adapter": { "name": "@web3auth/openlogin-adapter", - "version": "5.2.1", + "version": "6.0.0", "license": "ISC", "dependencies": { - "@toruslabs/openlogin": "^4.5.2", + "@toruslabs/openlogin": "^4.5.4", "@toruslabs/openlogin-utils": "^4.5.1", - "@web3auth/base": "^5.2.0", - "@web3auth/base-provider": "^5.2.0", + "@web3auth/base": "^6.0.0", + "@web3auth/base-provider": "^6.0.0", "lodash.merge": "^4.6.2" }, "devDependencies": { @@ -66,11 +67,11 @@ }, "../../packages/base": { "name": "@web3auth/base", - "version": "5.2.0", + "version": "6.0.0", "license": "ISC", "dependencies": { "@toruslabs/http-helpers": "^4.0.0", - "@toruslabs/openlogin": "^4.5.2", + "@toruslabs/openlogin": "^4.5.4", "@toruslabs/openlogin-jrpc": "^4.5.1", "@toruslabs/openlogin-utils": "^4.5.1", "jwt-decode": "^3.1.2", @@ -87,21 +88,21 @@ }, "../../packages/modal": { "name": "@web3auth/modal", - "version": "5.2.1", + "version": "6.0.0", "license": "ISC", "dependencies": { - "@web3auth/base": "^5.2.0", - "@web3auth/base-provider": "^5.2.0", - "@web3auth/ethereum-provider": "^5.2.0", - "@web3auth/metamask-adapter": "^5.2.0", - "@web3auth/no-modal": "^5.2.0", - "@web3auth/openlogin-adapter": "^5.2.1", - "@web3auth/phantom-adapter": "^5.2.0", - "@web3auth/solana-provider": "^5.2.0", - "@web3auth/torus-evm-adapter": "^5.2.0", - "@web3auth/torus-solana-adapter": "^5.2.0", - "@web3auth/ui": "^5.2.0", - "@web3auth/wallet-connect-v2-adapter": "^5.2.0" + "@web3auth/base": "^6.0.0", + "@web3auth/base-provider": "^6.0.0", + "@web3auth/ethereum-provider": "^6.0.0", + "@web3auth/metamask-adapter": "^6.0.0", + "@web3auth/no-modal": "^6.0.0", + "@web3auth/openlogin-adapter": "^6.0.0", + "@web3auth/phantom-adapter": "^6.0.0", + "@web3auth/solana-provider": "^6.0.0", + "@web3auth/torus-evm-adapter": "^6.0.0", + "@web3auth/torus-solana-adapter": "^6.0.0", + "@web3auth/ui": "^6.0.0", + "@web3auth/wallet-connect-v2-adapter": "^6.0.0" }, "devDependencies": { "@svgr/webpack": "^8.0.1", @@ -122,17 +123,38 @@ "@solana/web3.js": "^1.x" } }, + "../../packages/plugins/torus-wallet-connector-plugin": { + "version": "6.0.0", + "license": "ISC", + "dependencies": { + "@toruslabs/torus-embed": "^2.1.1", + "@web3auth/base": "^6.0.0", + "@web3auth/base-plugin": "^6.0.0", + "@web3auth/no-modal": "^6.0.0", + "loglevel": "^1.8.1" + }, + "devDependencies": { + "eth-rpc-errors": "^4.0.3" + }, + "engines": { + "node": ">=16.18.1", + "npm": ">=8.x" + }, + "peerDependencies": { + "@babel/runtime": "^7.x" + } + }, "../../packages/providers/solana-provider": { "name": "@web3auth/solana-provider", - "version": "5.2.0", + "version": "6.0.0", "license": "ISC", "dependencies": { "@toruslabs/base-controllers": "^3.0.3", "@toruslabs/openlogin-ed25519": "^4.2.0", "@toruslabs/openlogin-jrpc": "^4.5.1", "@toruslabs/tweetnacl-js": "^1.0.4", - "@web3auth/base": "^5.2.0", - "@web3auth/base-provider": "^5.2.0", + "@web3auth/base": "^6.0.0", + "@web3auth/base-provider": "^6.0.0", "bn.js": "^5.2.1", "bs58": "^5.0.0", "eth-rpc-errors": "^4.0.3", @@ -5127,6 +5149,10 @@ "resolved": "../../packages/providers/solana-provider", "link": true }, + "node_modules/@web3auth/torus-wallet-connector-plugin": { + "resolved": "../../packages/plugins/torus-wallet-connector-plugin", + "link": true + }, "node_modules/@webassemblyjs/ast": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz", @@ -24980,7 +25006,7 @@ "version": "file:../../packages/base", "requires": { "@toruslabs/http-helpers": "^4.0.0", - "@toruslabs/openlogin": "^4.5.2", + "@toruslabs/openlogin": "^4.5.4", "@toruslabs/openlogin-jrpc": "^4.5.1", "@toruslabs/openlogin-utils": "^4.5.1", "jwt-decode": "^3.1.2", @@ -24994,18 +25020,18 @@ "@svgr/webpack": "^8.0.1", "@toruslabs/isomorphic-style-loader": "^5.3.3", "@toruslabs/openlogin-utils": "^4.5.1", - "@web3auth/base": "^5.2.0", - "@web3auth/base-provider": "^5.2.0", - "@web3auth/ethereum-provider": "^5.2.0", - "@web3auth/metamask-adapter": "^5.2.0", - "@web3auth/no-modal": "^5.2.0", - "@web3auth/openlogin-adapter": "^5.2.1", - "@web3auth/phantom-adapter": "^5.2.0", - "@web3auth/solana-provider": "^5.2.0", - "@web3auth/torus-evm-adapter": "^5.2.0", - "@web3auth/torus-solana-adapter": "^5.2.0", - "@web3auth/ui": "^5.2.0", - "@web3auth/wallet-connect-v2-adapter": "^5.2.0", + "@web3auth/base": "^6.0.0", + "@web3auth/base-provider": "^6.0.0", + "@web3auth/ethereum-provider": "^6.0.0", + "@web3auth/metamask-adapter": "^6.0.0", + "@web3auth/no-modal": "^6.0.0", + "@web3auth/openlogin-adapter": "^6.0.0", + "@web3auth/phantom-adapter": "^6.0.0", + "@web3auth/solana-provider": "^6.0.0", + "@web3auth/torus-evm-adapter": "^6.0.0", + "@web3auth/torus-solana-adapter": "^6.0.0", + "@web3auth/ui": "^6.0.0", + "@web3auth/wallet-connect-v2-adapter": "^6.0.0", "css-loader": "^6.8.1", "postcss-prefix-selector": "^1.16.0", "style-loader": "^3.3.3", @@ -25016,11 +25042,11 @@ "@web3auth/openlogin-adapter": { "version": "file:../../packages/adapters/openlogin-adapter", "requires": { - "@toruslabs/openlogin": "^4.5.2", + "@toruslabs/openlogin": "^4.5.4", "@toruslabs/openlogin-utils": "^4.5.1", "@types/lodash.merge": "^4.6.7", - "@web3auth/base": "^5.2.0", - "@web3auth/base-provider": "^5.2.0", + "@web3auth/base": "^6.0.0", + "@web3auth/base-provider": "^6.0.0", "lodash.merge": "^4.6.2" } }, @@ -25036,14 +25062,25 @@ "@types/bn.js": "^5.1.1", "@types/bs58": "^4.0.1", "@types/json-rpc-random-id": "^1.0.1", - "@web3auth/base": "^5.2.0", - "@web3auth/base-provider": "^5.2.0", + "@web3auth/base": "^6.0.0", + "@web3auth/base-provider": "^6.0.0", "bn.js": "^5.2.1", "bs58": "^5.0.0", "eth-rpc-errors": "^4.0.3", "json-rpc-random-id": "^1.0.1" } }, + "@web3auth/torus-wallet-connector-plugin": { + "version": "file:../../packages/plugins/torus-wallet-connector-plugin", + "requires": { + "@toruslabs/torus-embed": "^2.1.1", + "@web3auth/base": "^6.0.0", + "@web3auth/base-plugin": "^6.0.0", + "@web3auth/no-modal": "^6.0.0", + "eth-rpc-errors": "^4.0.3", + "loglevel": "^1.8.1" + } + }, "@webassemblyjs/ast": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz", diff --git a/demo/react-app/package.json b/demo/react-app/package.json index 4f5183301..04c5d6475 100644 --- a/demo/react-app/package.json +++ b/demo/react-app/package.json @@ -12,6 +12,7 @@ "@web3auth/openlogin-adapter": "file:../../packages/adapters/openlogin-adapter", "@web3auth/solana-provider": "file:../../packages/providers/solana-provider", "@web3auth/modal": "file:../../packages/modal", + "@web3auth/torus-wallet-connector-plugin": "file:../../packages/plugins/torus-wallet-connector-plugin", "path-browserify": "^1.0.1", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/demo/react-app/src/components/Main.tsx b/demo/react-app/src/components/Main.tsx index 3800d7d3c..dd81fdbf1 100644 --- a/demo/react-app/src/components/Main.tsx +++ b/demo/react-app/src/components/Main.tsx @@ -3,7 +3,7 @@ import { useWeb3Auth } from "../services/web3auth"; import styles from "../styles/Home.module.css"; const Main = () => { - const { provider, login, logout, getUserInfo, getAccounts, getBalance, signMessage, signTransaction, signAndSendTransaction, web3Auth, chain } = useWeb3Auth(); + const { provider, login, logout, getUserInfo, getAccounts, getBalance, signMessage, signTransaction, signAndSendTransaction, web3Auth, chain, addChain, switchChain } = useWeb3Auth(); const loggedInView = ( <> @@ -19,6 +19,12 @@ const Main = () => { + + { (web3Auth?.connectedAdapterName === WALLET_ADAPTERS.OPENLOGIN || chain === "solana") && (