Skip to content

Commit

Permalink
feat(walletconnect): migrate wc 1.x to 2.x (#96)
Browse files Browse the repository at this point in the history
* feat(walletconnect): migrate wc 1.x to 2.x

* chore(packages update): update packages

* chore(deps): update wallet connect dependencies

* fix(package): remove dev scaffolds
  • Loading branch information
Todmy authored Jun 28, 2023
1 parent 2886d97 commit 8885a31
Show file tree
Hide file tree
Showing 3 changed files with 795 additions and 314 deletions.
34 changes: 24 additions & 10 deletions connectors/walletconnect.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import LockConnector from '../src/connector';

let provider: any;
export default class Connector extends LockConnector {
async connect() {
let provider;
try {

let WalletConnectProvider = await import(
"@walletconnect/web3-provider/dist/umd/index.min.js"!
const imports = await import(
"@walletconnect/ethereum-provider"!
);
if (WalletConnectProvider?.default) WalletConnectProvider = WalletConnectProvider.default;
if (WalletConnectProvider?.default) WalletConnectProvider = WalletConnectProvider.default;
provider = new WalletConnectProvider(this.options);
const { EthereumProvider } = imports;

provider = await EthereumProvider.init(this.options);
await provider.enable();
} catch (e) {
console.error(e);
Expand All @@ -20,11 +19,26 @@ export default class Connector extends LockConnector {
return provider;
}

removeHashFromLocalStorage() {
if (!localStorage) return;

const wcKeys: string[] = [];
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i) as string;
if (key.startsWith('wc@2:')) {
wcKeys.push(key);
}
}

wcKeys.forEach(key => localStorage.removeItem(key));
}

logout() {
if (localStorage) {
localStorage.removeItem('walletconnect');
if ('disconnect' in provider) {
provider.disconnect().catch(this.removeHashFromLocalStorage);
provider = null;
} else {
this.removeHashFromLocalStorage();
}
return;
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snapshot-labs/lock",
"version": "0.1.1018",
"version": "0.1.1019",
"repository": "snapshot-labs/lock",
"license": "MIT",
"main": "dist/lock.cjs.js",
Expand All @@ -12,7 +12,8 @@
"@gnosis.pm/safe-apps-sdk": "^7.8.0",
"@portis/web3": "^4.0.6",
"@toruslabs/torus-embed": "^1.12.1",
"@walletconnect/web3-provider": "^1.8.0",
"@walletconnect/ethereum-provider": "^2.8.3",
"@walletconnect/modal": "^2.5.4",
"fortmatic": "^2.2.1"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 8885a31

Please sign in to comment.