@web3-react/metamask
Advanced tools
Comparing version 8.0.5-alpha.0 to 8.0.6-alpha.0
@@ -8,6 +8,6 @@ import { Connector, Actions } from '@web3-react/types'; | ||
private readonly options?; | ||
private providerPromise?; | ||
constructor(actions: Actions, options?: NonNullable<Parameters<typeof detectEthereumProvider>[0]>, connectEagerly?: boolean); | ||
private startListening; | ||
private eagerConnection?; | ||
constructor(actions: Actions, connectEagerly?: boolean, options?: Parameters<typeof detectEthereumProvider>[0]); | ||
private initialize; | ||
activate(): Promise<void>; | ||
} |
@@ -22,14 +22,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
export class MetaMask extends Connector { | ||
constructor(actions, options, connectEagerly = true) { | ||
constructor(actions, connectEagerly = true, options) { | ||
super(actions); | ||
this.options = options; | ||
if (connectEagerly) { | ||
this.providerPromise = this.startListening(connectEagerly); | ||
this.eagerConnection = this.initialize(true); | ||
} | ||
} | ||
startListening(connectEagerly) { | ||
initialize(connectEagerly) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield import('@metamask/detect-provider') | ||
.then((m) => m.default) | ||
.then((detectEthereumProvider) => detectEthereumProvider(this.options)) | ||
return import('@metamask/detect-provider') | ||
.then((m) => m.default(this.options)) | ||
.then((provider) => { | ||
@@ -57,3 +56,3 @@ var _a; | ||
.then(([chainId, accounts]) => { | ||
if (accounts.length > 0) { | ||
if (accounts.length) { | ||
this.actions.update({ chainId: parseChainId(chainId), accounts }); | ||
@@ -73,8 +72,8 @@ } | ||
this.actions.startActivation(); | ||
if (!this.providerPromise) { | ||
this.providerPromise = this.startListening(false); | ||
if (!this.eagerConnection) { | ||
this.eagerConnection = this.initialize(false); | ||
} | ||
yield this.providerPromise; | ||
yield this.eagerConnection; | ||
if (this.provider) { | ||
yield Promise.all([ | ||
return Promise.all([ | ||
this.provider.request({ method: 'eth_chainId' }), | ||
@@ -84,3 +83,3 @@ this.provider.request({ method: 'eth_requestAccounts' }), | ||
.then(([chainId, accounts]) => { | ||
this.actions.update({ chainId: Number.parseInt(chainId, 16), accounts }); | ||
this.actions.update({ chainId: parseChainId(chainId), accounts }); | ||
}) | ||
@@ -87,0 +86,0 @@ .catch((error) => { |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "8.0.5-alpha.0", | ||
"version": "8.0.6-alpha.0", | ||
"type": "module", | ||
@@ -18,5 +18,5 @@ "exports": "./dist/index.js", | ||
"@metamask/detect-provider": "^1.2.0", | ||
"@web3-react/types": "^8.0.5-alpha.0" | ||
"@web3-react/types": "^8.0.6-alpha.0" | ||
}, | ||
"gitHead": "b66d6733ff21e2ede6f6d5f05f9be4909d3c9ef0" | ||
"gitHead": "b32f036ca775ecf65861b2c4a4bae09e7cb26718" | ||
} |
@@ -17,10 +17,6 @@ import { Connector, Actions, Provider } from '@web3-react/types' | ||
export class MetaMask extends Connector { | ||
private readonly options?: NonNullable<Parameters<typeof detectEthereumProvider>[0]> | ||
private providerPromise?: Promise<void> | ||
private readonly options?: Parameters<typeof detectEthereumProvider>[0] | ||
private eagerConnection?: Promise<void> | ||
constructor( | ||
actions: Actions, | ||
options?: NonNullable<Parameters<typeof detectEthereumProvider>[0]>, | ||
connectEagerly = true | ||
) { | ||
constructor(actions: Actions, connectEagerly = true, options?: Parameters<typeof detectEthereumProvider>[0]) { | ||
super(actions) | ||
@@ -30,10 +26,9 @@ this.options = options | ||
if (connectEagerly) { | ||
this.providerPromise = this.startListening(connectEagerly) | ||
this.eagerConnection = this.initialize(true) | ||
} | ||
} | ||
private async startListening(connectEagerly: boolean): Promise<void> { | ||
await import('@metamask/detect-provider') | ||
.then((m) => m.default) | ||
.then((detectEthereumProvider) => detectEthereumProvider(this.options)) | ||
private async initialize(connectEagerly: boolean): Promise<void> { | ||
return import('@metamask/detect-provider') | ||
.then((m) => m.default(this.options)) | ||
.then((provider) => { | ||
@@ -62,3 +57,3 @@ this.provider = (provider as Provider) ?? undefined | ||
.then(([chainId, accounts]) => { | ||
if (accounts.length > 0) { | ||
if (accounts.length) { | ||
this.actions.update({ chainId: parseChainId(chainId), accounts }) | ||
@@ -78,9 +73,9 @@ } | ||
if (!this.providerPromise) { | ||
this.providerPromise = this.startListening(false) | ||
if (!this.eagerConnection) { | ||
this.eagerConnection = this.initialize(false) | ||
} | ||
await this.providerPromise | ||
await this.eagerConnection | ||
if (this.provider) { | ||
await Promise.all([ | ||
return Promise.all([ | ||
this.provider.request({ method: 'eth_chainId' }) as Promise<string>, | ||
@@ -90,3 +85,3 @@ this.provider.request({ method: 'eth_requestAccounts' }) as Promise<string[]>, | ||
.then(([chainId, accounts]) => { | ||
this.actions.update({ chainId: Number.parseInt(chainId, 16), accounts }) | ||
this.actions.update({ chainId: parseChainId(chainId), accounts }) | ||
}) | ||
@@ -93,0 +88,0 @@ .catch((error) => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43238
189