@web3-react/url
Advanced tools
Comparing version 8.0.23-beta.0 to 8.0.24-beta.0
@@ -6,2 +6,9 @@ import type { JsonRpcProvider } from '@ethersproject/providers'; | ||
declare type url = string | ConnectionInfo; | ||
/** | ||
* @param url - An RPC url or a JsonRpcProvider. | ||
*/ | ||
export interface UrlConstructorArgs { | ||
actions: Actions; | ||
url: url | JsonRpcProvider; | ||
} | ||
export declare class Url extends Connector { | ||
@@ -11,15 +18,5 @@ /** {@inheritdoc Connector.provider} */ | ||
/** {@inheritdoc Connector.customProvider} */ | ||
customProvider: JsonRpcProvider | undefined; | ||
private eagerConnection?; | ||
customProvider?: JsonRpcProvider; | ||
private readonly url; | ||
/** | ||
* @param url - An RPC url or a JsonRpcProvider. | ||
* @param connectEagerly - A flag indicating whether connection should be initiated when the class is constructed. | ||
*/ | ||
constructor({ actions, url, connectEagerly, }: { | ||
actions: Actions; | ||
url: url | JsonRpcProvider; | ||
connectEagerly?: boolean; | ||
}); | ||
private isomorphicInitialize; | ||
constructor({ actions, url }: UrlConstructorArgs); | ||
/** {@inheritdoc Connector.activate} */ | ||
@@ -26,0 +23,0 @@ activate(): Promise<void>; |
@@ -41,41 +41,24 @@ "use strict"; | ||
class Url extends types_1.Connector { | ||
/** | ||
* @param url - An RPC url or a JsonRpcProvider. | ||
* @param connectEagerly - A flag indicating whether connection should be initiated when the class is constructed. | ||
*/ | ||
constructor({ actions, url, connectEagerly = false, }) { | ||
constructor({ actions, url }) { | ||
super(actions); | ||
if (connectEagerly && this.serverSide) { | ||
throw new Error('connectEagerly = true is invalid for SSR, instead use the activate method in a useEffect'); | ||
} | ||
this.url = url; | ||
if (connectEagerly) | ||
void this.activate(); | ||
} | ||
isomorphicInitialize() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.eagerConnection) | ||
return this.eagerConnection; | ||
if (!isUrl(this.url)) | ||
return this.url; | ||
return (this.eagerConnection = Promise.resolve().then(() => __importStar(require('@ethersproject/providers'))).then(({ JsonRpcProvider }) => { | ||
return new JsonRpcProvider(this.url); | ||
})); | ||
}); | ||
} | ||
/** {@inheritdoc Connector.activate} */ | ||
activate() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.customProvider) | ||
this.actions.startActivation(); | ||
yield this.isomorphicInitialize() | ||
.then((customProvider) => __awaiter(this, void 0, void 0, function* () { | ||
this.customProvider = customProvider; | ||
const { chainId } = yield this.customProvider.getNetwork(); | ||
this.actions.update({ chainId, accounts: [] }); | ||
})) | ||
.catch((error) => { | ||
this.actions.resetState(); | ||
throw error; | ||
}); | ||
if (!this.customProvider) { | ||
const cancelActivation = this.actions.startActivation(); | ||
if (!isUrl(this.url)) | ||
this.customProvider = this.url; | ||
yield Promise.resolve().then(() => __importStar(require('@ethersproject/providers'))).then(({ JsonRpcProvider }) => { | ||
this.customProvider = new JsonRpcProvider(this.url); | ||
}) | ||
.catch((error) => { | ||
cancelActivation(); | ||
throw error; | ||
}); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const { chainId } = yield this.customProvider.getNetwork(); | ||
this.actions.update({ chainId, accounts: [] }); | ||
}); | ||
@@ -82,0 +65,0 @@ } |
@@ -12,3 +12,3 @@ { | ||
}, | ||
"version": "8.0.23-beta.0", | ||
"version": "8.0.24-beta.0", | ||
"files": [ | ||
@@ -28,8 +28,8 @@ "dist/*" | ||
"@ethersproject/providers": "^5", | ||
"@web3-react/types": "^8.0.18-beta.0" | ||
"@web3-react/types": "^8.0.19-beta.0" | ||
}, | ||
"devDependencies": { | ||
"@web3-react/store": "^8.0.23-beta.0" | ||
"@web3-react/store": "^8.0.24-beta.0" | ||
}, | ||
"gitHead": "b497295f7f4aeecf86845551e8fd0ee53d27d202" | ||
"gitHead": "9a5d6207c54457de7081755d5d69e5bd7c9fda31" | ||
} |
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
39759
89