Skip to content

Commit

Permalink
Fix for widget closing
Browse files Browse the repository at this point in the history
  • Loading branch information
surajsingla333 committed Nov 2, 2023
1 parent 42ee4fa commit 70fa5cd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 46 deletions.
58 changes: 19 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/web3Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 70fa5cd

Please sign in to comment.