Skip to content
This repository was archived by the owner on Aug 27, 2025. It is now read-only.

Commit cd0d237

Browse files
committed
feat: optimize experience for locked metamask
no popup when open twitter
1 parent b89b852 commit cd0d237

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/common/wallet.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ export async function connect(force = false) {
3737
},
3838
],
3939
});
40-
} else {
41-
await metaMaskProvider.request({
42-
method: 'eth_requestAccounts',
43-
});
4440
}
4541

4642
return metaMaskProvider;

src/content-script/hooks/twitter.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,17 @@ class TwitterHook {
241241
this.main.xlog('info', 'Detect status...');
242242
const settings = await getSettings();
243243
// this.main.xlog('info', 'Settings is', settings);
244-
const unidata = await this.main.getUnidata();
245-
// this.main.xlog('info', 'Now address is: '+ this.main.address);
246244
let newStatus = '';
245+
try {
246+
await this.main.getUnidata();
247+
} catch (e: any) {
248+
newStatus = e.message;
249+
this.main.xlog('warn', newStatus);
250+
settings.syncing = newStatus;
251+
await bucket.set(settings);
252+
return;
253+
}
254+
// this.main.xlog('info', 'Now address is: '+ this.main.address);
247255
if (settings.syncing !== false && settings.address && this.main.address) {
248256
if (settings.address.toLowerCase() !== this.main.address?.toLowerCase()) {
249257
newStatus = 'Address changed.';

src/content-script/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class CrossSyncContentScript {
5656
method: 'eth_accounts',
5757
})
5858
)?.[0];
59+
if (!this.address) {
60+
throw new Error('No address found, MetaMask might be locked.');
61+
}
5962
// this.xlog('info', 'Init unidata with address: ', this.address);
6063
this.unidata = new Unidata({
6164
ethereumProvider: provider,
@@ -65,6 +68,7 @@ class CrossSyncContentScript {
6568
}
6669
} catch (e: any) {
6770
this.xlog('error', 'Failed to initialize Unidata', e);
71+
throw e;
6872
}
6973
}
7074
});

0 commit comments

Comments
 (0)