Fixed browser provider

This commit is contained in:
Tornado Contrib 2024-10-06 23:04:59 +00:00
parent b9f891644d
commit 901281a59d
Signed by: tornadocontrib
GPG Key ID: 60B4DF1A076C64B1
7 changed files with 34 additions and 34 deletions

18
dist/index.js vendored

@ -477,19 +477,19 @@ class TornadoBrowserProvider extends ethers.BrowserProvider {
} }
getSigner(address) { getSigner(address) {
return __async$g(this, null, function* () { return __async$g(this, null, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _i; var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
const signerAddress = (yield __superGet$2(TornadoBrowserProvider.prototype, this, "getSigner").call(this, address)).address; const signerAddress = (yield __superGet$2(TornadoBrowserProvider.prototype, this, "getSigner").call(this, address)).address;
if (((_a = this.options) == null ? void 0 : _a.webChainId) && ((_b = this.options) == null ? void 0 : _b.connectWallet) && Number(yield __superGet$2(TornadoBrowserProvider.prototype, this, "send").call(this, "eth_chainId", [])) !== Number((_c = this.options) == null ? void 0 : _c.webChainId)) { if (((_a = this.options) == null ? void 0 : _a.netId) && ((_b = this.options) == null ? void 0 : _b.connectWallet) && Number(yield __superGet$2(TornadoBrowserProvider.prototype, this, "send").call(this, "net_version", [])) !== ((_c = this.options) == null ? void 0 : _c.netId)) {
yield this.options.connectWallet(); yield this.options.connectWallet((_d = this.options) == null ? void 0 : _d.netId);
} }
if ((_d = this.options) == null ? void 0 : _d.handleNetworkChanges) { if ((_e = this.options) == null ? void 0 : _e.handleNetworkChanges) {
(_e = window == null ? void 0 : window.ethereum) == null ? void 0 : _e.on("chainChanged", this.options.handleNetworkChanges); (_f = window == null ? void 0 : window.ethereum) == null ? void 0 : _f.on("chainChanged", this.options.handleNetworkChanges);
} }
if ((_f = this.options) == null ? void 0 : _f.handleAccountChanges) { if ((_g = this.options) == null ? void 0 : _g.handleAccountChanges) {
(_g = window == null ? void 0 : window.ethereum) == null ? void 0 : _g.on("accountsChanged", this.options.handleAccountChanges); (_h = window == null ? void 0 : window.ethereum) == null ? void 0 : _h.on("accountsChanged", this.options.handleAccountChanges);
} }
if ((_h = this.options) == null ? void 0 : _h.handleAccountDisconnect) { if ((_i = this.options) == null ? void 0 : _i.handleAccountDisconnect) {
(_i = window == null ? void 0 : window.ethereum) == null ? void 0 : _i.on("disconnect", this.options.handleAccountDisconnect); (_j = window == null ? void 0 : window.ethereum) == null ? void 0 : _j.on("disconnect", this.options.handleAccountDisconnect);
} }
return new TornadoRpcSigner(this, signerAddress, this.options); return new TornadoRpcSigner(this, signerAddress, this.options);
}); });

18
dist/index.mjs vendored

@ -456,19 +456,19 @@ class TornadoBrowserProvider extends BrowserProvider {
} }
getSigner(address) { getSigner(address) {
return __async$g(this, null, function* () { return __async$g(this, null, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _i; var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
const signerAddress = (yield __superGet$2(TornadoBrowserProvider.prototype, this, "getSigner").call(this, address)).address; const signerAddress = (yield __superGet$2(TornadoBrowserProvider.prototype, this, "getSigner").call(this, address)).address;
if (((_a = this.options) == null ? void 0 : _a.webChainId) && ((_b = this.options) == null ? void 0 : _b.connectWallet) && Number(yield __superGet$2(TornadoBrowserProvider.prototype, this, "send").call(this, "eth_chainId", [])) !== Number((_c = this.options) == null ? void 0 : _c.webChainId)) { if (((_a = this.options) == null ? void 0 : _a.netId) && ((_b = this.options) == null ? void 0 : _b.connectWallet) && Number(yield __superGet$2(TornadoBrowserProvider.prototype, this, "send").call(this, "net_version", [])) !== ((_c = this.options) == null ? void 0 : _c.netId)) {
yield this.options.connectWallet(); yield this.options.connectWallet((_d = this.options) == null ? void 0 : _d.netId);
} }
if ((_d = this.options) == null ? void 0 : _d.handleNetworkChanges) { if ((_e = this.options) == null ? void 0 : _e.handleNetworkChanges) {
(_e = window == null ? void 0 : window.ethereum) == null ? void 0 : _e.on("chainChanged", this.options.handleNetworkChanges); (_f = window == null ? void 0 : window.ethereum) == null ? void 0 : _f.on("chainChanged", this.options.handleNetworkChanges);
} }
if ((_f = this.options) == null ? void 0 : _f.handleAccountChanges) { if ((_g = this.options) == null ? void 0 : _g.handleAccountChanges) {
(_g = window == null ? void 0 : window.ethereum) == null ? void 0 : _g.on("accountsChanged", this.options.handleAccountChanges); (_h = window == null ? void 0 : window.ethereum) == null ? void 0 : _h.on("accountsChanged", this.options.handleAccountChanges);
} }
if ((_h = this.options) == null ? void 0 : _h.handleAccountDisconnect) { if ((_i = this.options) == null ? void 0 : _i.handleAccountDisconnect) {
(_i = window == null ? void 0 : window.ethereum) == null ? void 0 : _i.on("disconnect", this.options.handleAccountDisconnect); (_j = window == null ? void 0 : window.ethereum) == null ? void 0 : _j.on("disconnect", this.options.handleAccountDisconnect);
} }
return new TornadoRpcSigner(this, signerAddress, this.options); return new TornadoRpcSigner(this, signerAddress, this.options);
}); });

2
dist/providers.d.ts vendored

@ -75,7 +75,7 @@ export declare class TornadoRpcSigner extends JsonRpcSigner {
export type connectWalletFunc = (...args: any[]) => Promise<void>; export type connectWalletFunc = (...args: any[]) => Promise<void>;
export type handleWalletFunc = (...args: any[]) => void; export type handleWalletFunc = (...args: any[]) => void;
export type TornadoBrowserProviderOptions = TornadoWalletOptions & { export type TornadoBrowserProviderOptions = TornadoWalletOptions & {
webChainId?: NetIdType; netId?: NetIdType;
connectWallet?: connectWalletFunc; connectWallet?: connectWalletFunc;
handleNetworkChanges?: handleWalletFunc; handleNetworkChanges?: handleWalletFunc;
handleAccountChanges?: handleWalletFunc; handleAccountChanges?: handleWalletFunc;

18
dist/tornado.umd.js vendored

@ -72330,19 +72330,19 @@ class TornadoBrowserProvider extends BrowserProvider {
} }
getSigner(address) { getSigner(address) {
return __async(this, null, function* () { return __async(this, null, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _i; var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
const signerAddress = (yield __superGet(TornadoBrowserProvider.prototype, this, "getSigner").call(this, address)).address; const signerAddress = (yield __superGet(TornadoBrowserProvider.prototype, this, "getSigner").call(this, address)).address;
if (((_a = this.options) == null ? void 0 : _a.webChainId) && ((_b = this.options) == null ? void 0 : _b.connectWallet) && Number(yield __superGet(TornadoBrowserProvider.prototype, this, "send").call(this, "eth_chainId", [])) !== Number((_c = this.options) == null ? void 0 : _c.webChainId)) { if (((_a = this.options) == null ? void 0 : _a.netId) && ((_b = this.options) == null ? void 0 : _b.connectWallet) && Number(yield __superGet(TornadoBrowserProvider.prototype, this, "send").call(this, "net_version", [])) !== ((_c = this.options) == null ? void 0 : _c.netId)) {
yield this.options.connectWallet(); yield this.options.connectWallet((_d = this.options) == null ? void 0 : _d.netId);
} }
if ((_d = this.options) == null ? void 0 : _d.handleNetworkChanges) { if ((_e = this.options) == null ? void 0 : _e.handleNetworkChanges) {
(_e = window == null ? void 0 : window.ethereum) == null ? void 0 : _e.on("chainChanged", this.options.handleNetworkChanges); (_f = window == null ? void 0 : window.ethereum) == null ? void 0 : _f.on("chainChanged", this.options.handleNetworkChanges);
} }
if ((_f = this.options) == null ? void 0 : _f.handleAccountChanges) { if ((_g = this.options) == null ? void 0 : _g.handleAccountChanges) {
(_g = window == null ? void 0 : window.ethereum) == null ? void 0 : _g.on("accountsChanged", this.options.handleAccountChanges); (_h = window == null ? void 0 : window.ethereum) == null ? void 0 : _h.on("accountsChanged", this.options.handleAccountChanges);
} }
if ((_h = this.options) == null ? void 0 : _h.handleAccountDisconnect) { if ((_i = this.options) == null ? void 0 : _i.handleAccountDisconnect) {
(_i = window == null ? void 0 : window.ethereum) == null ? void 0 : _i.on("disconnect", this.options.handleAccountDisconnect); (_j = window == null ? void 0 : window.ethereum) == null ? void 0 : _j.on("disconnect", this.options.handleAccountDisconnect);
} }
return new TornadoRpcSigner(this, signerAddress, this.options); return new TornadoRpcSigner(this, signerAddress, this.options);
}); });

File diff suppressed because one or more lines are too long

@ -475,7 +475,7 @@ export type handleWalletFunc = (...args: any[]) => void;
/* eslint-enable @typescript-eslint/no-explicit-any */ /* eslint-enable @typescript-eslint/no-explicit-any */
export type TornadoBrowserProviderOptions = TornadoWalletOptions & { export type TornadoBrowserProviderOptions = TornadoWalletOptions & {
webChainId?: NetIdType; netId?: NetIdType;
connectWallet?: connectWalletFunc; connectWallet?: connectWalletFunc;
handleNetworkChanges?: handleWalletFunc; handleNetworkChanges?: handleWalletFunc;
handleAccountChanges?: handleWalletFunc; handleAccountChanges?: handleWalletFunc;
@ -493,11 +493,11 @@ export class TornadoBrowserProvider extends BrowserProvider {
const signerAddress = (await super.getSigner(address)).address; const signerAddress = (await super.getSigner(address)).address;
if ( if (
this.options?.webChainId && this.options?.netId &&
this.options?.connectWallet && this.options?.connectWallet &&
Number(await super.send('eth_chainId', [])) !== Number(this.options?.webChainId) Number(await super.send('net_version', [])) !== this.options?.netId
) { ) {
await this.options.connectWallet(); await this.options.connectWallet(this.options?.netId);
} }
if (this.options?.handleNetworkChanges) { if (this.options?.handleNetworkChanges) {