Skip to content

Commit

Permalink
Merge pull request #49 from akropolisio/use-unknown-in-provider-type
Browse files Browse the repository at this point in the history
fix: fix ethereum provider type
  • Loading branch information
in19farkt authored May 11, 2022
2 parents 8da3af3 + 30a6e70 commit 148d8a3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/clover-connector/src/@types/extend-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type CloverProvider = Provider & {

declare global {
interface Window {
ethereum?: CloverProvider;
clover?: CloverProvider;
ethereum?: unknown;
clover?: unknown;
}
}
2 changes: 1 addition & 1 deletion packages/clover-connector/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface CloverConnectionPayload extends DefaultConnectionPayload {
}
export class CloverConnector extends AbstractConnector<CloverConnectionPayload> {
public async connect(): Promise<CloverConnectionPayload> {
const provider = window.clover || window.ethereum;
const provider: CloverProvider = window.clover || window.ethereum;

if (!provider?.isClover) {
throw new Error(
Expand Down
4 changes: 2 additions & 2 deletions packages/inpage-connector/src/@types/extend-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export type InpageProvider = Provider & {
declare global {
interface Window {
web3?: {
currentProvider?: InpageProvider;
currentProvider?: unknown;
};
ethereum?: InpageProvider;
ethereum?: unknown;
}
}
18 changes: 8 additions & 10 deletions packages/inpage-connector/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ export interface InpageConnectionPayload extends DefaultConnectionPayload {

export class InpageConnector extends AbstractConnector<InpageConnectionPayload> {
public async connect(): Promise<InpageConnectionPayload> {
let provider: InpageProvider;

if (window.ethereum) {
// edge case if Metamask and Coinbase extensions are both installed
const { providers } = window.ethereum;
provider =
(Array.isArray(providers) && providers.find((x) => x.isMetaMask)) || window.ethereum;
} else if (window.web3?.currentProvider) {
provider = window.web3.currentProvider;
} else {
let provider: InpageProvider = window.ethereum || window.web3?.currentProvider;

// edge case if Metamask and Coinbase extensions are both installed
if (Array.isArray(provider?.providers)) {
provider = provider.providers.find((x: InpageProvider) => x.isMetaMask) || provider;
}

if (!provider) {
throw new Error(
'Web3 provider not found! Please install the Web3 extension (e.g. Metamask) or use the Web3 browser (e.g. TrustWallet on your mobile device).',
);
Expand Down

0 comments on commit 148d8a3

Please sign in to comment.