@wagmi/connectors 2.3.0-cjs → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coinbaseWallet/package.json +1 -1
- package/dist/{base-0473abd3.d.ts → base-2dd7facf.d.ts} +1 -0
- package/dist/chunk-OQILYQDO.js +4 -4
- package/dist/chunk-QYMCVNHT.js +14 -14
- package/dist/{chunk-4BSCIAHY.js → chunk-Z2P63ELM.js} +75 -73
- package/dist/chunk-ZCAPXGBX.js +10 -10
- package/dist/coinbaseWallet.d.ts +1 -1
- package/dist/coinbaseWallet.js +58 -58
- package/dist/index.d.ts +4 -2
- package/dist/index.js +16 -12
- package/dist/injected.d.ts +1 -1
- package/dist/injected.js +9 -9
- package/dist/ledger.d.ts +33 -6
- package/dist/ledger.js +194 -126
- package/dist/metaMask.d.ts +1 -1
- package/dist/metaMask.js +37 -37
- package/dist/mock/index.d.ts +1 -1
- package/dist/mock/index.js +63 -63
- package/dist/safe.d.ts +1 -1
- package/dist/safe.js +46 -46
- package/dist/walletConnect.d.ts +1 -1
- package/dist/walletConnect.js +105 -105
- package/dist/walletConnectLegacy.d.ts +1 -1
- package/dist/walletConnectLegacy.js +58 -58
- package/injected/package.json +1 -1
- package/ledger/package.json +1 -1
- package/metaMask/package.json +1 -1
- package/mock/package.json +1 -1
- package/package.json +46 -6
- package/safe/package.json +1 -1
- package/walletConnect/package.json +1 -1
- package/walletConnectLegacy/package.json +1 -1
package/dist/mock/index.js
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import {
|
|
2
|
+
normalizeChainId
|
|
3
|
+
} from "../chunk-OQILYQDO.js";
|
|
4
|
+
import {
|
|
5
|
+
Connector,
|
|
6
|
+
__privateAdd,
|
|
7
|
+
__privateGet,
|
|
8
|
+
__privateMethod,
|
|
9
|
+
__privateSet,
|
|
10
|
+
__publicField
|
|
11
|
+
} from "../chunk-QYMCVNHT.js";
|
|
12
12
|
|
|
13
13
|
// src/mock/connector.ts
|
|
14
|
-
|
|
14
|
+
import { getAddress as getAddress2 } from "viem";
|
|
15
15
|
|
|
16
16
|
// src/mock/provider.ts
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
import { default as EventEmitter } from "eventemitter3";
|
|
18
|
+
import { UserRejectedRequestError, getAddress } from "viem";
|
|
19
19
|
var _options, _walletClient;
|
|
20
20
|
var MockProvider = class {
|
|
21
21
|
constructor(options) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
__publicField(this, "events", new EventEmitter());
|
|
23
|
+
__publicField(this, "chainId");
|
|
24
|
+
__privateAdd(this, _options, void 0);
|
|
25
|
+
__privateAdd(this, _walletClient, void 0);
|
|
26
26
|
this.chainId = options.chainId;
|
|
27
|
-
|
|
27
|
+
__privateSet(this, _options, options);
|
|
28
28
|
}
|
|
29
29
|
async enable() {
|
|
30
|
-
if (
|
|
31
|
-
throw new
|
|
32
|
-
if (!
|
|
33
|
-
|
|
34
|
-
const address =
|
|
30
|
+
if (__privateGet(this, _options).flags?.failConnect)
|
|
31
|
+
throw new UserRejectedRequestError(new Error("Failed to connect."));
|
|
32
|
+
if (!__privateGet(this, _walletClient))
|
|
33
|
+
__privateSet(this, _walletClient, __privateGet(this, _options).walletClient);
|
|
34
|
+
const address = __privateGet(this, _walletClient).account.address;
|
|
35
35
|
this.events.emit("accountsChanged", [address]);
|
|
36
36
|
return [address];
|
|
37
37
|
}
|
|
38
38
|
async disconnect() {
|
|
39
39
|
this.events.emit("disconnect");
|
|
40
|
-
|
|
40
|
+
__privateSet(this, _walletClient, void 0);
|
|
41
41
|
}
|
|
42
42
|
async getAccounts() {
|
|
43
|
-
const address =
|
|
43
|
+
const address = __privateGet(this, _walletClient)?.account.address;
|
|
44
44
|
if (!address)
|
|
45
45
|
return [];
|
|
46
|
-
return [
|
|
46
|
+
return [getAddress(address)];
|
|
47
47
|
}
|
|
48
48
|
getWalletClient() {
|
|
49
|
-
const walletClient =
|
|
49
|
+
const walletClient = __privateGet(this, _walletClient);
|
|
50
50
|
if (!walletClient)
|
|
51
51
|
throw new Error("walletClient not found");
|
|
52
52
|
return walletClient;
|
|
53
53
|
}
|
|
54
54
|
async switchChain(chainId) {
|
|
55
|
-
if (
|
|
56
|
-
throw new
|
|
57
|
-
|
|
55
|
+
if (__privateGet(this, _options).flags?.failSwitchChain)
|
|
56
|
+
throw new UserRejectedRequestError(new Error("Failed to switch chain."));
|
|
57
|
+
__privateGet(this, _options).chainId = chainId;
|
|
58
58
|
this.chainId = chainId;
|
|
59
59
|
this.events.emit("chainChanged", chainId);
|
|
60
60
|
}
|
|
61
61
|
async switchWalletClient(walletClient) {
|
|
62
62
|
const address = walletClient.account.address;
|
|
63
|
-
|
|
63
|
+
__privateSet(this, _walletClient, walletClient);
|
|
64
64
|
this.events.emit("accountsChanged", [address]);
|
|
65
65
|
}
|
|
66
66
|
async watchAsset(_asset) {
|
|
67
67
|
return true;
|
|
68
68
|
}
|
|
69
69
|
async request({ method, params }) {
|
|
70
|
-
return
|
|
70
|
+
return __privateGet(this, _walletClient)?.transport.request({ method, params });
|
|
71
71
|
}
|
|
72
72
|
on(event, listener) {
|
|
73
73
|
this.events.on(event, listener);
|
|
@@ -86,7 +86,7 @@ _walletClient = new WeakMap();
|
|
|
86
86
|
|
|
87
87
|
// src/mock/connector.ts
|
|
88
88
|
var _provider, _switchChain, switchChain_fn;
|
|
89
|
-
var MockConnector = class extends
|
|
89
|
+
var MockConnector = class extends Connector {
|
|
90
90
|
constructor({
|
|
91
91
|
chains,
|
|
92
92
|
options
|
|
@@ -95,26 +95,26 @@ var MockConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
95
95
|
chains,
|
|
96
96
|
options: {
|
|
97
97
|
...options,
|
|
98
|
-
chainId:
|
|
98
|
+
chainId: options.chainId ?? chains?.[0]?.id
|
|
99
99
|
}
|
|
100
100
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
__privateAdd(this, _switchChain);
|
|
102
|
+
__publicField(this, "id", "mock");
|
|
103
|
+
__publicField(this, "name", "Mock");
|
|
104
|
+
__publicField(this, "ready", true);
|
|
105
|
+
__privateAdd(this, _provider, void 0);
|
|
106
|
+
__publicField(this, "onAccountsChanged", (accounts) => {
|
|
107
107
|
if (accounts.length === 0)
|
|
108
108
|
this.emit("disconnect");
|
|
109
109
|
else
|
|
110
|
-
this.emit("change", { account:
|
|
110
|
+
this.emit("change", { account: getAddress2(accounts[0]) });
|
|
111
111
|
});
|
|
112
|
-
|
|
113
|
-
const id =
|
|
112
|
+
__publicField(this, "onChainChanged", (chainId) => {
|
|
113
|
+
const id = normalizeChainId(chainId);
|
|
114
114
|
const unsupported = this.isChainUnsupported(id);
|
|
115
115
|
this.emit("change", { chain: { id, unsupported } });
|
|
116
116
|
});
|
|
117
|
-
|
|
117
|
+
__publicField(this, "onDisconnect", () => {
|
|
118
118
|
this.emit("disconnect");
|
|
119
119
|
});
|
|
120
120
|
}
|
|
@@ -125,12 +125,12 @@ var MockConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
125
125
|
provider.on("disconnect", this.onDisconnect);
|
|
126
126
|
this.emit("message", { type: "connecting" });
|
|
127
127
|
const accounts = await provider.enable();
|
|
128
|
-
const account =
|
|
129
|
-
const id =
|
|
128
|
+
const account = getAddress2(accounts[0]);
|
|
129
|
+
const id = normalizeChainId(provider.chainId);
|
|
130
130
|
const unsupported = this.isChainUnsupported(id);
|
|
131
131
|
const data = { account, chain: { id, unsupported }, provider };
|
|
132
|
-
if (!
|
|
133
|
-
this.switchChain =
|
|
132
|
+
if (!this.options.flags?.noSwitchChain)
|
|
133
|
+
this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
|
|
134
134
|
return new Promise(
|
|
135
135
|
(res) => setTimeout(() => res(data), 100)
|
|
136
136
|
);
|
|
@@ -148,19 +148,19 @@ var MockConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
148
148
|
const account = accounts[0];
|
|
149
149
|
if (!account)
|
|
150
150
|
throw new Error("Failed to get account");
|
|
151
|
-
return
|
|
151
|
+
return getAddress2(account);
|
|
152
152
|
}
|
|
153
153
|
async getChainId() {
|
|
154
154
|
const provider = await this.getProvider();
|
|
155
|
-
return
|
|
155
|
+
return normalizeChainId(provider.chainId);
|
|
156
156
|
}
|
|
157
157
|
async getProvider({ chainId } = {}) {
|
|
158
|
-
if (!
|
|
159
|
-
|
|
158
|
+
if (!__privateGet(this, _provider) || chainId)
|
|
159
|
+
__privateSet(this, _provider, new MockProvider({
|
|
160
160
|
...this.options,
|
|
161
|
-
chainId:
|
|
161
|
+
chainId: chainId ?? this.options.chainId ?? this.chains[0].id
|
|
162
162
|
}));
|
|
163
|
-
return
|
|
163
|
+
return __privateGet(this, _provider);
|
|
164
164
|
}
|
|
165
165
|
async getWalletClient() {
|
|
166
166
|
const provider = await this.getProvider();
|
|
@@ -170,8 +170,8 @@ var MockConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
170
170
|
try {
|
|
171
171
|
const provider = await this.getProvider();
|
|
172
172
|
const account = await provider.getAccounts();
|
|
173
|
-
return
|
|
174
|
-
} catch
|
|
173
|
+
return this.options.flags?.isAuthorized ?? !!account;
|
|
174
|
+
} catch {
|
|
175
175
|
return false;
|
|
176
176
|
}
|
|
177
177
|
}
|
|
@@ -188,15 +188,15 @@ _switchChain = new WeakSet();
|
|
|
188
188
|
switchChain_fn = async function(chainId) {
|
|
189
189
|
const provider = await this.getProvider();
|
|
190
190
|
await provider.switchChain(chainId);
|
|
191
|
-
return
|
|
191
|
+
return this.chains.find((x) => x.id === chainId) ?? {
|
|
192
192
|
id: chainId,
|
|
193
193
|
name: `Chain ${chainId}`,
|
|
194
194
|
network: `${chainId}`,
|
|
195
195
|
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
196
196
|
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
197
|
-
}
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
export {
|
|
200
|
+
MockConnector,
|
|
201
|
+
MockProvider
|
|
198
202
|
};
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
exports.MockConnector = MockConnector; exports.MockProvider = MockProvider;
|
package/dist/safe.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as viem from 'viem';
|
|
|
2
2
|
import { SafeAppProvider } from '@safe-global/safe-apps-provider';
|
|
3
3
|
import { Opts } from '@safe-global/safe-apps-sdk';
|
|
4
4
|
import { Chain } from '@wagmi/chains';
|
|
5
|
-
import { C as Connector } from './base-
|
|
5
|
+
import { C as Connector } from './base-2dd7facf.js';
|
|
6
6
|
import 'eventemitter3';
|
|
7
7
|
|
|
8
8
|
type SafeConnectorProvider = SafeAppProvider;
|
package/dist/safe.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import {
|
|
2
|
+
ConnectorNotFoundError
|
|
3
|
+
} from "./chunk-ZCAPXGBX.js";
|
|
4
|
+
import {
|
|
5
|
+
normalizeChainId
|
|
6
|
+
} from "./chunk-OQILYQDO.js";
|
|
7
|
+
import {
|
|
8
|
+
Connector,
|
|
9
|
+
__privateAdd,
|
|
10
|
+
__privateGet,
|
|
11
|
+
__privateSet,
|
|
12
|
+
__publicField
|
|
13
|
+
} from "./chunk-QYMCVNHT.js";
|
|
14
14
|
|
|
15
15
|
// src/safe.ts
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
import { SafeAppProvider } from "@safe-global/safe-apps-provider";
|
|
17
|
+
import { default as SafeAppsSDK } from "@safe-global/safe-apps-sdk";
|
|
18
|
+
import { createWalletClient, custom, getAddress } from "viem";
|
|
19
19
|
var _provider, _sdk;
|
|
20
|
-
var SafeConnector = class extends
|
|
20
|
+
var SafeConnector = class extends Connector {
|
|
21
21
|
constructor({
|
|
22
22
|
chains,
|
|
23
23
|
options: options_
|
|
@@ -27,21 +27,21 @@ var SafeConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
27
27
|
...options_
|
|
28
28
|
};
|
|
29
29
|
super({ chains, options });
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
let SDK =
|
|
37
|
-
if (typeof
|
|
38
|
-
SDK =
|
|
39
|
-
|
|
30
|
+
__publicField(this, "id", "safe");
|
|
31
|
+
__publicField(this, "name", "Safe");
|
|
32
|
+
__publicField(this, "ready", !(typeof window === "undefined") && window?.parent !== window);
|
|
33
|
+
__privateAdd(this, _provider, void 0);
|
|
34
|
+
__privateAdd(this, _sdk, void 0);
|
|
35
|
+
__publicField(this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
|
|
36
|
+
let SDK = SafeAppsSDK;
|
|
37
|
+
if (typeof SafeAppsSDK !== "function" && typeof SafeAppsSDK.default === "function")
|
|
38
|
+
SDK = SafeAppsSDK.default;
|
|
39
|
+
__privateSet(this, _sdk, new SDK(options));
|
|
40
40
|
}
|
|
41
41
|
async connect() {
|
|
42
42
|
const provider = await this.getProvider();
|
|
43
43
|
if (!provider)
|
|
44
|
-
throw new
|
|
44
|
+
throw new ConnectorNotFoundError();
|
|
45
45
|
if (provider.on) {
|
|
46
46
|
provider.on("accountsChanged", this.onAccountsChanged);
|
|
47
47
|
provider.on("chainChanged", this.onChainChanged);
|
|
@@ -51,7 +51,7 @@ var SafeConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
51
51
|
const account = await this.getAccount();
|
|
52
52
|
const id = await this.getChainId();
|
|
53
53
|
if (this.options.shimDisconnect)
|
|
54
|
-
|
|
54
|
+
this.storage?.setItem(this.shimDisconnectKey, true);
|
|
55
55
|
return {
|
|
56
56
|
account,
|
|
57
57
|
chain: { id, unsupported: this.isChainUnsupported(id) }
|
|
@@ -59,37 +59,37 @@ var SafeConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
59
59
|
}
|
|
60
60
|
async disconnect() {
|
|
61
61
|
const provider = await this.getProvider();
|
|
62
|
-
if (!
|
|
62
|
+
if (!provider?.removeListener)
|
|
63
63
|
return;
|
|
64
64
|
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
65
65
|
provider.removeListener("chainChanged", this.onChainChanged);
|
|
66
66
|
provider.removeListener("disconnect", this.onDisconnect);
|
|
67
67
|
if (this.options.shimDisconnect)
|
|
68
|
-
|
|
68
|
+
this.storage?.removeItem(this.shimDisconnectKey);
|
|
69
69
|
}
|
|
70
70
|
async getAccount() {
|
|
71
71
|
const provider = await this.getProvider();
|
|
72
72
|
if (!provider)
|
|
73
|
-
throw new
|
|
73
|
+
throw new ConnectorNotFoundError();
|
|
74
74
|
const accounts = await provider.request({
|
|
75
75
|
method: "eth_accounts"
|
|
76
76
|
});
|
|
77
|
-
return
|
|
77
|
+
return getAddress(accounts[0]);
|
|
78
78
|
}
|
|
79
79
|
async getChainId() {
|
|
80
80
|
const provider = await this.getProvider();
|
|
81
81
|
if (!provider)
|
|
82
|
-
throw new
|
|
83
|
-
return
|
|
82
|
+
throw new ConnectorNotFoundError();
|
|
83
|
+
return normalizeChainId(provider.chainId);
|
|
84
84
|
}
|
|
85
85
|
async getProvider() {
|
|
86
|
-
if (!
|
|
87
|
-
const safe = await
|
|
86
|
+
if (!__privateGet(this, _provider)) {
|
|
87
|
+
const safe = await __privateGet(this, _sdk).safe.getInfo();
|
|
88
88
|
if (!safe)
|
|
89
89
|
throw new Error("Could not load Safe information");
|
|
90
|
-
|
|
90
|
+
__privateSet(this, _provider, new SafeAppProvider(safe, __privateGet(this, _sdk)));
|
|
91
91
|
}
|
|
92
|
-
return
|
|
92
|
+
return __privateGet(this, _provider);
|
|
93
93
|
}
|
|
94
94
|
async getWalletClient({ chainId } = {}) {
|
|
95
95
|
const provider = await this.getProvider();
|
|
@@ -97,19 +97,19 @@ var SafeConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
97
97
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
98
98
|
if (!provider)
|
|
99
99
|
throw new Error("provider is required.");
|
|
100
|
-
return
|
|
100
|
+
return createWalletClient({
|
|
101
101
|
account,
|
|
102
102
|
chain,
|
|
103
|
-
transport:
|
|
103
|
+
transport: custom(provider)
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
async isAuthorized() {
|
|
107
107
|
try {
|
|
108
|
-
if (this.options.shimDisconnect && !
|
|
108
|
+
if (this.options.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey))
|
|
109
109
|
return false;
|
|
110
110
|
const account = await this.getAccount();
|
|
111
111
|
return !!account;
|
|
112
|
-
} catch
|
|
112
|
+
} catch {
|
|
113
113
|
return false;
|
|
114
114
|
}
|
|
115
115
|
}
|
|
@@ -123,6 +123,6 @@ var SafeConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
123
123
|
};
|
|
124
124
|
_provider = new WeakMap();
|
|
125
125
|
_sdk = new WeakMap();
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
export {
|
|
127
|
+
SafeConnector
|
|
128
|
+
};
|
package/dist/walletConnect.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as viem from 'viem';
|
|
|
2
2
|
import { Chain } from '@wagmi/chains';
|
|
3
3
|
import WalletConnectProvider from '@walletconnect/ethereum-provider';
|
|
4
4
|
import { EthereumProviderOptions } from '@walletconnect/ethereum-provider/dist/types/EthereumProvider';
|
|
5
|
-
import { C as Connector } from './base-
|
|
5
|
+
import { C as Connector } from './base-2dd7facf.js';
|
|
6
6
|
import 'eventemitter3';
|
|
7
7
|
|
|
8
8
|
type WalletConnectOptions = {
|