Skip to content

Commit

Permalink
Handles ENS error (spruceid#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
w4ll3 authored Nov 22, 2021
1 parent d4bd21d commit efba483
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions examples/notepad/src/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ import { ethers } from 'ethers';
import Mousetrap from 'mousetrap';
import { SignatureType, SiweMessage } from 'siwe';

declare global {
interface Window {
ethereum: { request: (opt: { method: string }) => Promise<Array<string>> };
web3: unknown;
}
}

const enum Providers {
METAMASK = 'metamask',
WALLET_CONNECT = 'walletconnect',
}

//eslint-disable-next-line
const metamask = (window as any).ethereum;
const metamask = window.ethereum;
let walletconnect: WalletConnect;

let metamaskButton: HTMLButtonElement;
Expand All @@ -26,7 +33,7 @@ let unsaved: HTMLParagraphElement;
*/

const signIn = async (connector: Providers) => {
let provider;
let provider: ethers.providers.Web3Provider;

/**
* Connects to the wallet and starts a etherjs provider.
Expand Down Expand Up @@ -56,7 +63,12 @@ const signIn = async (connector: Providers) => {
/**
* Try to resolve address ENS and updates the title accordingly.
*/
const ens = await provider.lookupAddress(address);
let ens: string;
try {
ens = await provider.lookupAddress(address);
} catch (error) {
console.error(error);
}

updateTitle(ens ?? address);

Expand Down Expand Up @@ -121,7 +133,7 @@ const signOut = async () => {
/**
* Saves the current content of our notepad
*/
const save = async (e?: Mousetrap.ExtendedKeyboardEvent) => {
const save = async (e?: Mousetrap.ExtendedKeyboardEvent | MouseEvent) => {
e?.preventDefault();
const text = notepad.value;
if (Buffer.byteLength(JSON.stringify({ text })) > 43610) {
Expand Down

0 comments on commit efba483

Please sign in to comment.