Skip to content

Commit

Permalink
v1.0.8-beta
Browse files Browse the repository at this point in the history
- Actual fix for issues with MetaMask login
  • Loading branch information
iPaulPro committed Feb 24, 2023
1 parent e0fd741 commit 6db376c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"manifest_version": 3,
"name": "Focalize - Post on Lens Protocol",
"short_name": "Focalize",
"version": "1.0.7",
"version_name": "1.0.7-beta",
"version": "1.0.8",
"version_name": "1.0.8-beta",
"description": "Extension for Publishing on Lens Protocol",
"permissions": [
"activeTab",
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,7 +1,7 @@
{
"name": "focalize",
"private": true,
"version": "1.0.7",
"version": "1.0.8",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
23 changes: 17 additions & 6 deletions src/lib/ethers-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,20 @@ const getProviderFromWeb3Modal = async (): Promise<Web3Provider> => {
};

export const getAccounts = async (): Promise<string[]> => {
if (!provider) throw ('Provider is null. You must call initEthers() first');
let accounts: string[];
try {
accounts = await provider.listAccounts();
} catch (e) {
accounts = await provider.send('eth_requestAccounts', []);
if (!provider) {
provider = await getProviderFromWeb3Modal();
}

let accounts = await provider.send('eth_requestAccounts', []);

if (!accounts || accounts.length === 0) {
try {
accounts = await provider.listAccounts();
} catch (e) {
console.error('getAccounts: Unable to get accounts from provider', e)
}
}

return accounts;
}

Expand All @@ -157,3 +164,7 @@ export const signTypedData = (
omitDeep(value, ['__typename'])
);
}

export const clearProvider = () => {
web3Modal.clearCachedProvider();
}
19 changes: 14 additions & 5 deletions src/lib/lens-auth.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import {Lens} from "lens-protocol";
import {decodeJwt} from "jose";
import {Duration} from "luxon";
import {getAccounts} from "./ethers-service";

export const authenticate = async () => {
const {getSigner} = await import('./ethers-service');
const {getSigner, getAccounts, clearProvider} = await import('./ethers-service');

const signer = getSigner();
let address: string | undefined;

let address: string | undefined;
try {
address = await signer.getAddress();
} catch (e) {
const accounts = await getAccounts();
address = accounts[0];
console.warn(e);
}

if (!address) {
try {
const accounts = await getAccounts();
address = accounts[0];
} catch (e) {
clearProvider();
console.error(e);
}
}

if (!address) throw 'No address found';
Expand Down

0 comments on commit 6db376c

Please sign in to comment.