Skip to content

Commit

Permalink
refactor: improve connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Jan 26, 2025
1 parent 0d2d736 commit a16afc5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
8 changes: 2 additions & 6 deletions apps/ui/src/helpers/connectors/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@ export default class {
this.type = type;
}

async connect(): Promise<void> {
return;
}
async connect(): Promise<void> {}

async autoConnect(): Promise<void> {
return this.connect();
}

async disconnect(): Promise<void> {
return;
}
async disconnect(): Promise<void> {}

async isConnected(): Promise<boolean> {
return true;
Expand Down
8 changes: 5 additions & 3 deletions apps/ui/src/helpers/connectors/walletconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ export default class extends Connector {
removeHashFromLocalStorage() {
if (!localStorage) return;

const wcKeys: string[] = [];
const keys: string[] = [];

for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i) as string;

if (key.startsWith('wc@2:')) {
wcKeys.push(key);
keys.push(key);
}
}

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

async disconnect() {
Expand Down
33 changes: 17 additions & 16 deletions apps/ui/src/helpers/connectors/walletlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,26 @@ export default class extends Connector {
await this.provider.enable();
} catch (e) {
console.error(e);
return;
}
}

async disconnect() {
if (localStorage) {
localStorage.removeItem(
'-walletlink:https://www.walletlink.org:session:id'
);
localStorage.removeItem(
'-walletlink:https://www.walletlink.org:session:secret'
);
localStorage.removeItem(
'-walletlink:https://www.walletlink.org:session:linked'
);
localStorage.removeItem(
'-walletlink:https://www.walletlink.org:Addresses'
);
removeHashFromLocalStorage() {
if (!localStorage) return;

const keys: string[] = [];

for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i) as string;

if (key.startsWith('-walletlink:')) {
keys.push(key);
}
}
return;

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

async disconnect() {
this.removeHashFromLocalStorage();
}
}

0 comments on commit a16afc5

Please sign in to comment.