@wagmi/connectors 1.0.0-next.4 → 1.0.0-next.6
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/dist/base-a11da01a.d.ts +132 -0
- package/dist/chunk-K4TVWOJP.js +370 -0
- package/dist/chunk-OQILYQDO.js +15 -0
- package/dist/chunk-QYMCVNHT.js +68 -0
- package/dist/chunk-ZCAPXGBX.js +26 -0
- package/dist/coinbaseWallet.d.ts +831 -1
- package/dist/coinbaseWallet.js +215 -0
- package/dist/index.d.ts +19 -1
- package/dist/index.js +12 -0
- package/dist/injected.d.ts +833 -1
- package/dist/injected.js +9 -0
- package/dist/ledger.d.ts +810 -1
- package/dist/ledger.js +192 -0
- package/dist/metaMask.d.ts +37 -1
- package/dist/metaMask.js +139 -0
- package/dist/mock/index.d.ts +1578 -1
- package/dist/mock/index.js +202 -0
- package/dist/safe.d.ts +822 -1
- package/dist/safe.js +128 -0
- package/dist/walletConnect.d.ts +917 -1
- package/dist/walletConnect.js +311 -0
- package/dist/walletConnectLegacy.d.ts +811 -1
- package/dist/walletConnectLegacy.js +178 -0
- package/package.json +9 -9
package/dist/safe.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
|
|
15
|
+
// src/safe.ts
|
|
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
|
+
var _provider, _sdk;
|
|
20
|
+
var SafeConnector = class extends Connector {
|
|
21
|
+
constructor({
|
|
22
|
+
chains,
|
|
23
|
+
options: options_
|
|
24
|
+
}) {
|
|
25
|
+
const options = {
|
|
26
|
+
shimDisconnect: false,
|
|
27
|
+
...options_
|
|
28
|
+
};
|
|
29
|
+
super({ chains, options });
|
|
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
|
+
}
|
|
41
|
+
async connect() {
|
|
42
|
+
const provider = await this.getProvider();
|
|
43
|
+
if (!provider)
|
|
44
|
+
throw new ConnectorNotFoundError();
|
|
45
|
+
if (provider.on) {
|
|
46
|
+
provider.on("accountsChanged", this.onAccountsChanged);
|
|
47
|
+
provider.on("chainChanged", this.onChainChanged);
|
|
48
|
+
provider.on("disconnect", this.onDisconnect);
|
|
49
|
+
}
|
|
50
|
+
this.emit("message", { type: "connecting" });
|
|
51
|
+
const account = await this.getAccount();
|
|
52
|
+
const id = await this.getChainId();
|
|
53
|
+
if (this.options.shimDisconnect)
|
|
54
|
+
this.storage?.setItem(this.shimDisconnectKey, true);
|
|
55
|
+
return {
|
|
56
|
+
account,
|
|
57
|
+
chain: { id, unsupported: this.isChainUnsupported(id) }
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async disconnect() {
|
|
61
|
+
const provider = await this.getProvider();
|
|
62
|
+
if (!provider?.removeListener)
|
|
63
|
+
return;
|
|
64
|
+
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
65
|
+
provider.removeListener("chainChanged", this.onChainChanged);
|
|
66
|
+
provider.removeListener("disconnect", this.onDisconnect);
|
|
67
|
+
if (this.options.shimDisconnect)
|
|
68
|
+
this.storage?.removeItem(this.shimDisconnectKey);
|
|
69
|
+
}
|
|
70
|
+
async getAccount() {
|
|
71
|
+
const provider = await this.getProvider();
|
|
72
|
+
if (!provider)
|
|
73
|
+
throw new ConnectorNotFoundError();
|
|
74
|
+
const accounts = await provider.request({
|
|
75
|
+
method: "eth_accounts"
|
|
76
|
+
});
|
|
77
|
+
return getAddress(accounts[0]);
|
|
78
|
+
}
|
|
79
|
+
async getChainId() {
|
|
80
|
+
const provider = await this.getProvider();
|
|
81
|
+
if (!provider)
|
|
82
|
+
throw new ConnectorNotFoundError();
|
|
83
|
+
return normalizeChainId(provider.chainId);
|
|
84
|
+
}
|
|
85
|
+
async getProvider() {
|
|
86
|
+
if (!__privateGet(this, _provider)) {
|
|
87
|
+
const safe = await __privateGet(this, _sdk).safe.getInfo();
|
|
88
|
+
if (!safe)
|
|
89
|
+
throw new Error("Could not load Safe information");
|
|
90
|
+
__privateSet(this, _provider, new SafeAppProvider(safe, __privateGet(this, _sdk)));
|
|
91
|
+
}
|
|
92
|
+
return __privateGet(this, _provider);
|
|
93
|
+
}
|
|
94
|
+
async getWalletClient({ chainId } = {}) {
|
|
95
|
+
const provider = await this.getProvider();
|
|
96
|
+
const account = await this.getAccount();
|
|
97
|
+
const chain = this.chains.find((x) => x.id === chainId) || this.chains[0];
|
|
98
|
+
if (!provider)
|
|
99
|
+
throw new Error("provider is required.");
|
|
100
|
+
return createWalletClient({
|
|
101
|
+
account,
|
|
102
|
+
chain,
|
|
103
|
+
transport: custom(provider)
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async isAuthorized() {
|
|
107
|
+
try {
|
|
108
|
+
if (this.options.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey))
|
|
109
|
+
return false;
|
|
110
|
+
const account = await this.getAccount();
|
|
111
|
+
return !!account;
|
|
112
|
+
} catch {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
onAccountsChanged(_accounts) {
|
|
117
|
+
}
|
|
118
|
+
onChainChanged(_chainId) {
|
|
119
|
+
}
|
|
120
|
+
onDisconnect() {
|
|
121
|
+
this.emit("disconnect");
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
_provider = new WeakMap();
|
|
125
|
+
_sdk = new WeakMap();
|
|
126
|
+
export {
|
|
127
|
+
SafeConnector
|
|
128
|
+
};
|