Skip to content

Commit

Permalink
Merge pull request #94 from getsafle/feat-fix-UI
Browse files Browse the repository at this point in the history
Fix for widget closing
  • Loading branch information
sshubhamagg authored Nov 3, 2023
2 parents 42ee4fa + efa3348 commit 8b2b7fc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 49 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@getsafle/safle-keyless-js",
"version": "2.0.1",
"version": "2.0.2",
"description": "",
"main": "dist/index.js",
"scripts": {
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 8b2b7fc

Please sign in to comment.