diff --git a/CHANGELOG.md b/CHANGELOG.md index 0620bdb..9deda88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,3 +69,9 @@ ### 2.0.1 (2023-10-26) * Close widget on cross icon click and UI fixes. + +### 2.0.2 (2023-11-03) + +* Goto dashboard on successful transaction. + +* Handle widget closing on transaction complete \ No newline at end of file diff --git a/README.md b/README.md index 6f1fa4b..2813cda 100644 --- a/README.md +++ b/README.md @@ -42,63 +42,55 @@ npm install --save @getsafle/safle-keyless-js Import the package into your project using, ```js -import { getNetworks, KeylessWeb3 } from '@getsafle/safle-keyless-js'; +import Keyless from "@getsafle/safle-keyless-js"; ``` ## **Functions** -> Get the list of supported chains and networks - -```js -const networks = await getNetworks(); -``` - > Initialising Initialise the constructor using, ```js -const keyless = new KeylessWeb3({ blockchain }); +let keyless = new Keyless("mumbaitestnet"); ``` -`blockchain` - An array of objects containing supported blockchains from `getNetworks()`. +`mumbaitestnet` - The name of the network supported in keyless. Default is ethereum mainnet with the name `mainnet` -> Initialize web3 instance +> Once the constructor is intialized, call `init()` to initialize login. ```js -import Web3 from 'web3'; - -const w3 = new Web3(keyless.provider); + await keyless2.init(true); ``` -> Check the Keyless class connection to a dApp - -The following function verifies whether the sdk is connected to the provider or not: +> Use `onLogin()` to manage the state of the dApp when the user is loggedIn from Keyless. ```js -keyless.isConnected(); + keyless.onLogin((userAddress, chainDetails) => { + // Any function you want to call to manage the state + }); ``` -The following function disconnects Web3 from Keyless. It returns true/false if disconnected: +> Once the user is loggedIn, update the chain details in Keyless object ```js -keyless.disconnect(); + keyless = await keyless.updateWeb3(chainDetails); ``` -> Initialize the login widget - -To initialize the login screen, you have to use the following function: +> Initialize web3 instance ```js -keyless.login(); +import Web3 from 'web3'; + +const w3 = new Web3(keyless.provider); ``` -Event handlers for login status +> Check the Keyless class connection to a dApp + +The following function disconnects Web3 from Keyless. It returns true/false if disconnected: ```js -w3.currentProvider.on('connect', () => {} ); -w3.currentProvider.on('disconnect', () => {} ); -w3.currentProvider.on('login successful', () => {} ); +keyless.disconnect(); ``` > Chain/Account Selection @@ -117,18 +109,6 @@ To get the selected account, you can use the web3 functions const accounts = await w3.eth.getAccounts(); ``` -Event handler for chain selection - -```js -w3.currentProvider.on('chainChanged', () => {} ); -``` - -Event handler for account selection - -```js -w3.currentProvider.on('accountsChanged', () => {} ); -``` - > Open Dashboard To open the dashboard, you have to make sure that you are logged in. In order for you to do that, you have to use the following command diff --git a/package-lock.json b/package-lock.json index a2d868e..773e7e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@getsafle/safle-keyless-js", - "version": "2.0.1", + "version": "2.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@getsafle/safle-keyless-js", - "version": "2.0.1", + "version": "2.0.2", "license": "ISC", "dependencies": { "ethereumjs-util": "^5.2.0", diff --git a/package.json b/package.json index 95c1cf5..d0c23ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@getsafle/safle-keyless-js", - "version": "2.0.1", + "version": "2.0.2", "description": "", "main": "dist/index.js", "scripts": { diff --git a/src/web3Manager.ts b/src/web3Manager.ts index 08438f4..51a6806 100644 --- a/src/web3Manager.ts +++ b/src/web3Manager.ts @@ -212,12 +212,12 @@ export default class Web3Manager { console.log("signMessageHooked", widgetCommunication); const params = { ...msgParams, messageStandard: "signMessage" }; widgetCommunication.signData(params).then((result: any) => { - this._sendHideWidget(); console.log(result); let error: any = null; if (result.success) { this._signature = result.resp.sign_resp; - cb(error, result.resp?.sign_resp); + // this._sendHideWidget(); + cb(error, result.resp?.sign_resp); } else { error = result.error; cb(error, result.error?.message); @@ -235,12 +235,12 @@ export default class Web3Manager { widgetCommunication .processTransaction(msgParams) .then((result: any) => { - this._sendHideWidget(); console.log(result); let error: any = null; if (result.success) { //this._signature = result.resp.sign_resp; - cb(error, result.resp); + // this._sendHideWidget(); + cb(error, result.resp); } else { error = result.error; cb(error, result.resp); @@ -254,9 +254,9 @@ export default class Web3Manager { txParams ); cb(error, result); - setTimeout(() => { - this._sendHideWidget(); - }, 5000); + // setTimeout(() => { + // this._sendHideWidget(); + // }, 5000); }, estimateGas: async (txParams: any, cb: ProviderCallback) => { const gas = await getTxGas(query, txParams);