Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Walletconnect provider token login - to main (release) #49

Merged
merged 4 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

## [Unreleased]

## [6.6.0]
- [Added signature to walletConnectProvider to handle Token Login #49](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/49)

## [6.5.2]
- [Bugfix - corrected compute hash for transaction with options #44](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/44)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elrondnetwork/erdjs",
"version": "6.5.2",
"version": "6.6.0",
"description": "Smart Contracts interaction framework",
"main": "out/index.js",
"types": "out/index.d.js",
Expand Down
27 changes: 25 additions & 2 deletions src/dapp/walletConnectProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class WalletConnectProvider implements IDappProvider {
provider: IProvider;
walletConnectBridge: string;
address: string = "";
signature: string = "";
walletConnector: WalletClient | undefined;
private onClientConnect: IClientConnect;

Expand Down Expand Up @@ -108,6 +109,18 @@ export class WalletConnectProvider implements IDappProvider {
return this.address;
}

/**
* Fetches the wallet connect signature
*/
async getSignature(): Promise<string> {
if (!this.walletConnector) {
Logger.error("getSignature: Wallet Connect not initialised, call init() first");
throw new Error("Wallet Connect not initialised, call init() first");
}

return this.signature;
}

/**
* Signs and sends a transaction. Returns the transaction hash
* @param transaction
Expand Down Expand Up @@ -200,7 +213,14 @@ export class WalletConnectProvider implements IDappProvider {
accounts: [account],
} = params[0];

this.loginAccount(account);
if (account.includes(".")) {
const address = account.split(".");
if (address.length > 0) {
this.loginAccount(address[0], address[1]);
}
} else {
this.loginAccount(account);
}
}

private async onDisconnect(error: any) {
Expand All @@ -210,9 +230,12 @@ export class WalletConnectProvider implements IDappProvider {
this.onClientConnect.onClientLogout();
}

private async loginAccount(address: string) {
private async loginAccount(address: string, signature?: string) {
if (this.addressIsValid(address)) {
this.address = address;
if (signature) {
this.signature = signature;
}
this.onClientConnect.onClientLogin();
return;
}
Expand Down