@graphprotocol/graph-auth-kit 7.8.1
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/README.md +303 -0
- package/dist/Components/ConnectModal.d.ts +2 -0
- package/dist/Components/ConnectModal.d.ts.map +1 -0
- package/dist/Components/Connected.d.ts +33 -0
- package/dist/Components/Connected.d.ts.map +1 -0
- package/dist/Components/ConnectorOption.d.ts +7 -0
- package/dist/Components/ConnectorOption.d.ts.map +1 -0
- package/dist/Components/Disconnected.d.ts +28 -0
- package/dist/Components/Disconnected.d.ts.map +1 -0
- package/dist/Components/MultisigSignerOptions.d.ts +2 -0
- package/dist/Components/MultisigSignerOptions.d.ts.map +1 -0
- package/dist/Components/PrimaryConnectOptions.d.ts +2 -0
- package/dist/Components/PrimaryConnectOptions.d.ts.map +1 -0
- package/dist/Components/SafeInputForm.d.ts +2 -0
- package/dist/Components/SafeInputForm.d.ts.map +1 -0
- package/dist/Components/SafeSelection.d.ts +2 -0
- package/dist/Components/SafeSelection.d.ts.map +1 -0
- package/dist/Components/SwitchChain.d.ts +24 -0
- package/dist/Components/SwitchChain.d.ts.map +1 -0
- package/dist/Components/index.d.ts +4 -0
- package/dist/Components/index.d.ts.map +1 -0
- package/dist/GraphAuthKit.context.d.ts +130 -0
- package/dist/GraphAuthKit.context.d.ts.map +1 -0
- package/dist/GraphAuthKitInner.context-B3nCqd7x.js +629 -0
- package/dist/client.d.ts +12519 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/constants.d.ts +366 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/ens/hooks/index.d.ts +5 -0
- package/dist/ens/hooks/index.d.ts.map +1 -0
- package/dist/ens/hooks/useGraphAuthKitAvatar.d.ts +55 -0
- package/dist/ens/hooks/useGraphAuthKitAvatar.d.ts.map +1 -0
- package/dist/ens/hooks/useGraphAuthKitAvatars.d.ts +29 -0
- package/dist/ens/hooks/useGraphAuthKitAvatars.d.ts.map +1 -0
- package/dist/ens/hooks/useGraphAuthKitEnsName.d.ts +52 -0
- package/dist/ens/hooks/useGraphAuthKitEnsName.d.ts.map +1 -0
- package/dist/ens/hooks/useGraphAuthKitEnsNames.d.ts +28 -0
- package/dist/ens/hooks/useGraphAuthKitEnsNames.d.ts.map +1 -0
- package/dist/ens/index.d.ts +2 -0
- package/dist/ens/index.d.ts.map +1 -0
- package/dist/ens/index.js +7 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/hooks-D5Hw1GuR.js +511 -0
- package/dist/hooks.d.ts +125 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +141 -0
- package/dist/inner/GraphAuthKitInner.context.d.ts +121 -0
- package/dist/inner/GraphAuthKitInner.context.d.ts.map +1 -0
- package/dist/inner/hooks.d.ts +13 -0
- package/dist/inner/hooks.d.ts.map +1 -0
- package/dist/inner/index.d.ts +3 -0
- package/dist/inner/index.d.ts.map +1 -0
- package/dist/safe/SafeEthersSigner.d.ts +39 -0
- package/dist/safe/SafeEthersSigner.d.ts.map +1 -0
- package/dist/safe/SafeMinimal.abi.d.ts +80 -0
- package/dist/safe/SafeMinimal.abi.d.ts.map +1 -0
- package/dist/safe/constants.d.ts +27 -0
- package/dist/safe/constants.d.ts.map +1 -0
- package/dist/safe/index.d.ts +5 -0
- package/dist/safe/index.d.ts.map +1 -0
- package/dist/safe/index.js +19 -0
- package/dist/safe/safeViemActions.d.ts +4 -0
- package/dist/safe/safeViemActions.d.ts.map +1 -0
- package/dist/safe/useWaitForSafeTransaction.d.ts +10 -0
- package/dist/safe/useWaitForSafeTransaction.d.ts.map +1 -0
- package/dist/safe/utils.d.ts +51 -0
- package/dist/safe/utils.d.ts.map +1 -0
- package/dist/test-harness/MockGraphAuthKit.context.d.ts +103 -0
- package/dist/test-harness/MockGraphAuthKit.context.d.ts.map +1 -0
- package/dist/test-harness/index.d.ts +3 -0
- package/dist/test-harness/index.d.ts.map +1 -0
- package/dist/test-harness/index.js +6 -0
- package/dist/test-harness/utils.d.ts +135 -0
- package/dist/test-harness/utils.d.ts.map +1 -0
- package/dist/types.d.ts +37 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/useGraphAuthKitEnsNames-DHMYvwgX.js +211 -0
- package/dist/useWaitForSafeTransaction-YeFsJ9A5.js +46 -0
- package/dist/utils-Br1fBg8o.js +897 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +98 -0
|
@@ -0,0 +1,897 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
4
|
+
import { useConfig, WagmiProvider, useDisconnect, createConfig, createStorage, cookieStorage, cookieToInitialState } from "wagmi";
|
|
5
|
+
import { injected, walletConnect, coinbaseWallet, mock } from "wagmi/connectors";
|
|
6
|
+
import { K as useGraphAuthKitInnerContext, w as GraphAuthKitConnector, o as L2Chain, a as SafeSupportedNetworkNames, j as buildPublicClient, L as L1Chain, n as L1ChainTestnet, d as isValidSafe, S as SafeSupportedNetworks, P as GraphAuthKitInnerContextProvider, p as L2ChainTestnet, m as AUTH_STORAGE_KEY, x as chainIsSupportedChain, D as DefChain, l as buildClient, Q as GraphAuthKitInnerContext, T as defInnerState, R as RequiredInfuraKey, O as OptionalGatewayApiKey, q as SupportedClientChainId } from "./GraphAuthKitInner.context-B3nCqd7x.js";
|
|
7
|
+
import { useState, useReducer, useId, useEffect, createContext, useContext } from "react";
|
|
8
|
+
import { Icon, ExperimentalModal, ExperimentalButton, Alert, Link, ExperimentalLoadingIndicator, ExperimentalSelect, ExperimentalInput, Divider, List } from "@graphprotocol/gds";
|
|
9
|
+
import { addrShortener } from "@graphprotocol/common";
|
|
10
|
+
import { isAddress } from "viem";
|
|
11
|
+
import { NetworkIcon } from "@graphprotocol/go";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { buildEnsResolver } from "@graphprotocol/ens";
|
|
14
|
+
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
|
|
15
|
+
function usePrimaryConnectOptions() {
|
|
16
|
+
const { connectors } = useConfig();
|
|
17
|
+
const ctx = useGraphAuthKitInnerContext();
|
|
18
|
+
const configuredConnectors = connectors.filter((c) => c.type === injected.type && c.name !== "Injected" || c.type !== injected.type).reduce((map, curr) => {
|
|
19
|
+
const connector = GraphAuthKitConnector.safeParse(curr.type);
|
|
20
|
+
return {
|
|
21
|
+
...map,
|
|
22
|
+
[curr.name]: {
|
|
23
|
+
id: curr.id,
|
|
24
|
+
title: curr.name,
|
|
25
|
+
connector: connector.success ? connector.data : curr.type,
|
|
26
|
+
installed: curr.type === injected.type,
|
|
27
|
+
Image: correctConnectOptionIcon(curr),
|
|
28
|
+
async onConnect() {
|
|
29
|
+
void ctx._connect(curr);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}, {});
|
|
34
|
+
return [
|
|
35
|
+
...Object.values(configuredConnectors).sort((a, b) => {
|
|
36
|
+
if (a.installed === b.installed) {
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
return a.installed ? -1 : 1;
|
|
40
|
+
}),
|
|
41
|
+
{
|
|
42
|
+
id: "multisig",
|
|
43
|
+
title: "Safe",
|
|
44
|
+
connector: "multisig",
|
|
45
|
+
installed: false,
|
|
46
|
+
Image: /* @__PURE__ */ jsx(Icon.LogoSafeColor, { size: "24px" }),
|
|
47
|
+
onConnect() {
|
|
48
|
+
ctx._setModalState("safe_entry");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
function useMultisigConnectOptions() {
|
|
54
|
+
const { connectors } = useConfig();
|
|
55
|
+
const ctx = useGraphAuthKitInnerContext();
|
|
56
|
+
const configuredConnectors = connectors.filter((c) => c.type === injected.type && c.name !== "Injected" || c.type !== injected.type).reduce((map, curr) => {
|
|
57
|
+
const connector = GraphAuthKitConnector.safeParse(curr.type);
|
|
58
|
+
return {
|
|
59
|
+
...map,
|
|
60
|
+
[curr.name]: {
|
|
61
|
+
id: curr.id,
|
|
62
|
+
title: curr.name,
|
|
63
|
+
connector: connector.success ? connector.data : curr.type,
|
|
64
|
+
installed: curr.type === injected.type,
|
|
65
|
+
Image: correctConnectOptionIcon(curr),
|
|
66
|
+
async onConnect() {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
void ctx._connectMultisig({
|
|
69
|
+
connector: curr,
|
|
70
|
+
address: ((_a = ctx._enteredMultisigInfo) == null ? void 0 : _a.address) || "0x",
|
|
71
|
+
network: ((_b = ctx._enteredMultisigInfo) == null ? void 0 : _b.network) || L2Chain.id
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}, {});
|
|
77
|
+
return Object.values(configuredConnectors).sort((a, b) => {
|
|
78
|
+
if (a.installed === b.installed) {
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
return a.installed ? -1 : 1;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function correctConnectOptionIcon(conn) {
|
|
85
|
+
if (conn.icon != null) {
|
|
86
|
+
return /* @__PURE__ */ jsx("img", { src: conn.icon, alt: conn.name, className: "size-6" });
|
|
87
|
+
}
|
|
88
|
+
switch (conn.type) {
|
|
89
|
+
case coinbaseWallet.type: {
|
|
90
|
+
return /* @__PURE__ */ jsx(Icon.LogoCoinbaseWallet, { size: "24px" });
|
|
91
|
+
}
|
|
92
|
+
case walletConnect.type: {
|
|
93
|
+
return /* @__PURE__ */ jsx(Icon.LogoWalletConnectColor, { size: "24px" });
|
|
94
|
+
}
|
|
95
|
+
default: {
|
|
96
|
+
return /* @__PURE__ */ jsx(Icon.LogoMetaMaskColor, { size: "24px" });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function ConnectorOption(props) {
|
|
101
|
+
return /* @__PURE__ */ jsxs(
|
|
102
|
+
"button",
|
|
103
|
+
{
|
|
104
|
+
className: "flex w-full cursor-pointer items-center justify-between gap-x-2 rounded-4 border border-white/8 bg-white/4 p-3 text-white/48 hover:bg-white/8 hover:text-white aria-selected:border-purple aria-selected:text-white",
|
|
105
|
+
style: {
|
|
106
|
+
WebkitBackfaceVisibility: "hidden"
|
|
107
|
+
},
|
|
108
|
+
onClick: () => void props.onConnect(),
|
|
109
|
+
disabled: props.disabled,
|
|
110
|
+
children: [
|
|
111
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
112
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col items-center justify-center", children: props.Image }),
|
|
113
|
+
/* @__PURE__ */ jsx("h6", { className: "text-h16 whitespace-nowrap text-inherit", children: props.title })
|
|
114
|
+
] }),
|
|
115
|
+
props.installed ? /* @__PURE__ */ jsx("p", { className: "text-p12 text-white/48", children: "Installed" }) : null
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
function MultisigSignerOptions() {
|
|
121
|
+
const config = useConfig();
|
|
122
|
+
const authKit = useGraphAuthKit();
|
|
123
|
+
const ctx = useGraphAuthKitInnerContext();
|
|
124
|
+
const multisigConnectOpts = useMultisigConnectOptions();
|
|
125
|
+
const [selectedConnector, setSelectedConnector] = useState(null);
|
|
126
|
+
if (ctx._enteredMultisigInfo == null || !ctx._enteredMultisigInfo.address) {
|
|
127
|
+
return /* @__PURE__ */ jsxs(ExperimentalModal.Step, { children: [
|
|
128
|
+
/* @__PURE__ */ jsx(ExperimentalModal.Header, { title: "Multisig Connection" }),
|
|
129
|
+
/* @__PURE__ */ jsx(ExperimentalModal.Body, { children: /* @__PURE__ */ jsx("h3", { className: "text-p18 text-center text-white/64", children: "No Safe address entered." }) }),
|
|
130
|
+
/* @__PURE__ */ jsx(
|
|
131
|
+
ExperimentalModal.Footer,
|
|
132
|
+
{
|
|
133
|
+
primaryButton: /* @__PURE__ */ jsx(ExperimentalButton, { iconBefore: /* @__PURE__ */ jsx(Icon.ArrowLeft, {}), onClick: () => ctx._setModalState("safe_entry"), children: "Enter Safe" }),
|
|
134
|
+
secondaryButton: /* @__PURE__ */ jsx(ExperimentalButton, { onClick: () => authKit.closeConnectModal(), children: "Cancel" })
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
] });
|
|
138
|
+
}
|
|
139
|
+
return /* @__PURE__ */ jsxs(ExperimentalModal.Step, { children: [
|
|
140
|
+
/* @__PURE__ */ jsx(ExperimentalModal.Header, { title: "Select a signing wallet" }),
|
|
141
|
+
/* @__PURE__ */ jsxs(ExperimentalModal.Body, { children: [
|
|
142
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
143
|
+
/* @__PURE__ */ jsx(Icon.LogoSafeColor, { size: "16px" }),
|
|
144
|
+
/* @__PURE__ */ jsx("p", { className: "text-p12 text-white/64", children: addrShortener(ctx._enteredMultisigInfo.address) }),
|
|
145
|
+
/* @__PURE__ */ jsx(
|
|
146
|
+
ExperimentalButton,
|
|
147
|
+
{
|
|
148
|
+
variant: "tertiary",
|
|
149
|
+
size: "xsmall",
|
|
150
|
+
onClick: () => {
|
|
151
|
+
ctx._setSafeInfo(void 0);
|
|
152
|
+
ctx._setModalState("safe_entry");
|
|
153
|
+
},
|
|
154
|
+
children: "Change"
|
|
155
|
+
}
|
|
156
|
+
)
|
|
157
|
+
] }),
|
|
158
|
+
/* @__PURE__ */ jsxs("div", { className: "mt-6", children: [
|
|
159
|
+
ctx._connectFailureMessage ? /* @__PURE__ */ jsx(
|
|
160
|
+
Alert,
|
|
161
|
+
{
|
|
162
|
+
severity: "error",
|
|
163
|
+
title: ctx._connectFailureMessage.title,
|
|
164
|
+
description: ctx._connectFailureMessage.description,
|
|
165
|
+
className: "mb-6"
|
|
166
|
+
}
|
|
167
|
+
) : null,
|
|
168
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: multisigConnectOpts.map((opt) => /* @__PURE__ */ jsx(
|
|
169
|
+
ConnectorOption,
|
|
170
|
+
{
|
|
171
|
+
...opt,
|
|
172
|
+
disabled: ctx._authenticating,
|
|
173
|
+
selected: selectedConnector != null && selectedConnector.id === opt.id,
|
|
174
|
+
onConnect: () => {
|
|
175
|
+
const selected = config.connectors.find((c) => c.id === opt.id);
|
|
176
|
+
if (selected != null) {
|
|
177
|
+
setSelectedConnector(selected);
|
|
178
|
+
void opt.onConnect();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
opt.id
|
|
183
|
+
)) })
|
|
184
|
+
] })
|
|
185
|
+
] }),
|
|
186
|
+
/* @__PURE__ */ jsx(ExperimentalModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
187
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
188
|
+
/* @__PURE__ */ jsx("p", { className: "text-p14", children: "Wallet didn't open?" }),
|
|
189
|
+
/* @__PURE__ */ jsxs(
|
|
190
|
+
Link.Secondary,
|
|
191
|
+
{
|
|
192
|
+
size: "14px",
|
|
193
|
+
onClick: () => {
|
|
194
|
+
if (selectedConnector == null || ctx._enteredMultisigInfo == null || !isAddress(ctx._enteredMultisigInfo.address)) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
void ctx._connectMultisig({
|
|
198
|
+
connector: selectedConnector,
|
|
199
|
+
network: ctx._enteredMultisigInfo.network,
|
|
200
|
+
address: ctx._enteredMultisigInfo.address
|
|
201
|
+
});
|
|
202
|
+
},
|
|
203
|
+
children: [
|
|
204
|
+
"Try again ",
|
|
205
|
+
/* @__PURE__ */ jsx(Icon.RotateLeft, { size: "14px" })
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
)
|
|
209
|
+
] }),
|
|
210
|
+
/* @__PURE__ */ jsx(ExperimentalButton, { variant: "tertiary", className: "hidden md:inline", onClick: () => authKit.closeConnectModal(), children: "Cancel" })
|
|
211
|
+
] }) })
|
|
212
|
+
] });
|
|
213
|
+
}
|
|
214
|
+
function PrimaryConnectOptions() {
|
|
215
|
+
const ctx = useGraphAuthKitInnerContext();
|
|
216
|
+
const primaryConnectOpts = usePrimaryConnectOptions();
|
|
217
|
+
const [selectedConnector, setSelectedConnector] = useState(null);
|
|
218
|
+
return /* @__PURE__ */ jsxs(ExperimentalModal.Step, { children: [
|
|
219
|
+
/* @__PURE__ */ jsx(
|
|
220
|
+
ExperimentalModal.Header,
|
|
221
|
+
{
|
|
222
|
+
title: ctx._modalTitle,
|
|
223
|
+
buttonBefore: ctx._authenticating ? /* @__PURE__ */ jsx(ExperimentalLoadingIndicator, {}) : void 0
|
|
224
|
+
}
|
|
225
|
+
),
|
|
226
|
+
/* @__PURE__ */ jsxs(
|
|
227
|
+
ExperimentalModal.Body,
|
|
228
|
+
{
|
|
229
|
+
"aria-busy": ctx._authenticating ? "true" : void 0,
|
|
230
|
+
className: "aria-busy:opacity-64 aria-busy:pointer-events-none",
|
|
231
|
+
children: [
|
|
232
|
+
ctx._connectFailureMessage ? /* @__PURE__ */ jsx(
|
|
233
|
+
Alert,
|
|
234
|
+
{
|
|
235
|
+
severity: "error",
|
|
236
|
+
title: ctx._connectFailureMessage.title,
|
|
237
|
+
description: ctx._connectFailureMessage.description,
|
|
238
|
+
className: "mb-6"
|
|
239
|
+
}
|
|
240
|
+
) : null,
|
|
241
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: primaryConnectOpts.map((opt) => /* @__PURE__ */ jsx(
|
|
242
|
+
ConnectorOption,
|
|
243
|
+
{
|
|
244
|
+
...opt,
|
|
245
|
+
disabled: ctx._authenticating,
|
|
246
|
+
selected: selectedConnector != null && selectedConnector === opt.id,
|
|
247
|
+
onConnect: () => {
|
|
248
|
+
setSelectedConnector(opt.connector);
|
|
249
|
+
void opt.onConnect();
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
opt.id
|
|
253
|
+
)) })
|
|
254
|
+
]
|
|
255
|
+
}
|
|
256
|
+
),
|
|
257
|
+
/* @__PURE__ */ jsx(ExperimentalModal.Footer, { children: /* @__PURE__ */ jsxs("p", { className: "text-p12 text-white/64", children: [
|
|
258
|
+
"By connecting a wallet, you agree to The Graph's",
|
|
259
|
+
" ",
|
|
260
|
+
/* @__PURE__ */ jsx(Link.Inline, { href: "https://thegraph.com/terms-of-service/", target: "_blank", children: "Terms of Service" }),
|
|
261
|
+
" ",
|
|
262
|
+
"and acknowledge that you have read and understood the disclaimers therein."
|
|
263
|
+
] }) })
|
|
264
|
+
] });
|
|
265
|
+
}
|
|
266
|
+
z.union([
|
|
267
|
+
z.object({
|
|
268
|
+
action: z.literal("SET_NETWORK"),
|
|
269
|
+
payload: z.custom(
|
|
270
|
+
(val) => val != null && typeof val === "number" && SafeSupportedNetworks.safeParse(val).success
|
|
271
|
+
)
|
|
272
|
+
}),
|
|
273
|
+
z.object({
|
|
274
|
+
action: z.literal("SET_SAFE_ADDRESS"),
|
|
275
|
+
payload: z.string().min(42)
|
|
276
|
+
}),
|
|
277
|
+
z.object({
|
|
278
|
+
action: z.literal("SET_SAFE_VALID"),
|
|
279
|
+
payload: z.boolean().optional()
|
|
280
|
+
}),
|
|
281
|
+
z.object({
|
|
282
|
+
action: z.literal("RESET")
|
|
283
|
+
})
|
|
284
|
+
]);
|
|
285
|
+
function SafeInputFormReducer(state, action) {
|
|
286
|
+
switch (action.action) {
|
|
287
|
+
case "SET_NETWORK": {
|
|
288
|
+
return {
|
|
289
|
+
...state,
|
|
290
|
+
network: action.payload
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
case "SET_SAFE_VALID": {
|
|
294
|
+
return {
|
|
295
|
+
...state,
|
|
296
|
+
enteredSafeIsValid: action.payload
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
case "SET_SAFE_ADDRESS": {
|
|
300
|
+
return {
|
|
301
|
+
...state,
|
|
302
|
+
address: action.payload
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
default: {
|
|
306
|
+
return {
|
|
307
|
+
...state,
|
|
308
|
+
enteredSafeIsValid: void 0,
|
|
309
|
+
network: L2Chain.id,
|
|
310
|
+
address: "0x"
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function SafeInputForm() {
|
|
316
|
+
const ctx = useGraphAuthKitInnerContext();
|
|
317
|
+
const previouslyUsedSafes = usePreviouslyUsedSafes();
|
|
318
|
+
const [state, dispatch] = useReducer(SafeInputFormReducer, {
|
|
319
|
+
network: L2Chain.id,
|
|
320
|
+
address: ""
|
|
321
|
+
});
|
|
322
|
+
async function validateMultisigSchema(_state) {
|
|
323
|
+
if (!isAddress(_state.address)) {
|
|
324
|
+
return dispatch({ action: "SET_SAFE_VALID", payload: false });
|
|
325
|
+
}
|
|
326
|
+
const client = buildPublicClient({
|
|
327
|
+
chain: _state.network === L2Chain.id ? L2Chain : _state.network === L1Chain.id ? L1Chain : L1ChainTestnet,
|
|
328
|
+
infuraKey: ctx._infuraKey
|
|
329
|
+
});
|
|
330
|
+
const valid = await isValidSafe({
|
|
331
|
+
clientOrBuildClientArgs: client,
|
|
332
|
+
chain: _state.network,
|
|
333
|
+
safeAddress: _state.address
|
|
334
|
+
});
|
|
335
|
+
dispatch({ action: "SET_SAFE_VALID", payload: valid });
|
|
336
|
+
}
|
|
337
|
+
const handleMultisigAddressChange = (entered) => {
|
|
338
|
+
var _a;
|
|
339
|
+
let networkId = void 0;
|
|
340
|
+
if (entered.includes(":")) {
|
|
341
|
+
const [shortName, address] = entered.split(":");
|
|
342
|
+
networkId = (_a = Object.values(SafeSupportedNetworkNames).find((supported) => supported.shortName === shortName)) == null ? void 0 : _a.id;
|
|
343
|
+
entered = address ?? "";
|
|
344
|
+
if (networkId) {
|
|
345
|
+
dispatch({ action: "SET_NETWORK", payload: networkId });
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
dispatch({ action: "SET_SAFE_ADDRESS", payload: entered });
|
|
349
|
+
void validateMultisigSchema({ ...state, network: networkId || state.network, address: entered });
|
|
350
|
+
};
|
|
351
|
+
const formId = useId();
|
|
352
|
+
const isSubmitDisabled = !state.address || !state.enteredSafeIsValid;
|
|
353
|
+
return /* @__PURE__ */ jsxs(ExperimentalModal.Step, { children: [
|
|
354
|
+
/* @__PURE__ */ jsx(ExperimentalModal.Header, { title: "Safe Multisig" }),
|
|
355
|
+
/* @__PURE__ */ jsx(ExperimentalModal.Body, { children: /* @__PURE__ */ jsxs(
|
|
356
|
+
"form",
|
|
357
|
+
{
|
|
358
|
+
id: formId,
|
|
359
|
+
noValidate: true,
|
|
360
|
+
onSubmit: (event) => {
|
|
361
|
+
event.preventDefault();
|
|
362
|
+
if (state.enteredSafeIsValid && state.address) {
|
|
363
|
+
previouslyUsedSafes.save(state.network, state.address);
|
|
364
|
+
}
|
|
365
|
+
ctx._setSafeInfo(state);
|
|
366
|
+
ctx._setModalState("safe_eoa_signer");
|
|
367
|
+
},
|
|
368
|
+
children: [
|
|
369
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
370
|
+
/* @__PURE__ */ jsx(
|
|
371
|
+
ExperimentalSelect,
|
|
372
|
+
{
|
|
373
|
+
placeholder: "Select Safe Network",
|
|
374
|
+
value: state.network,
|
|
375
|
+
onChange: (selected) => {
|
|
376
|
+
dispatch({ action: "SET_NETWORK", payload: selected });
|
|
377
|
+
void validateMultisigSchema({ ...state, network: selected });
|
|
378
|
+
},
|
|
379
|
+
valueLabel: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
380
|
+
/* @__PURE__ */ jsx(NetworkIcon, { network: { caip2Id: `eip155:${state.network}` } }),
|
|
381
|
+
SafeSupportedNetworkNames[state.network].name
|
|
382
|
+
] }),
|
|
383
|
+
children: Object.values(SafeSupportedNetworkNames).sort((a, b) => {
|
|
384
|
+
if (a.id === L2Chain.id) {
|
|
385
|
+
return -1;
|
|
386
|
+
} else if (b.id === L2Chain.id) {
|
|
387
|
+
return 1;
|
|
388
|
+
}
|
|
389
|
+
return a.id - b.id;
|
|
390
|
+
}).map((n) => /* @__PURE__ */ jsx(ExperimentalSelect.Option, { value: n.id, children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
391
|
+
/* @__PURE__ */ jsx(NetworkIcon, { network: { caip2Id: `eip155:${n.id}` } }),
|
|
392
|
+
n.name
|
|
393
|
+
] }) }, n.id))
|
|
394
|
+
}
|
|
395
|
+
),
|
|
396
|
+
/* @__PURE__ */ jsx(
|
|
397
|
+
ExperimentalInput,
|
|
398
|
+
{
|
|
399
|
+
id: "multisigAddress",
|
|
400
|
+
name: "multisigAddress",
|
|
401
|
+
label: "Multisig Address",
|
|
402
|
+
value: state.address || "",
|
|
403
|
+
onChange: handleMultisigAddressChange,
|
|
404
|
+
placeholder: "0x...",
|
|
405
|
+
status: state.enteredSafeIsValid !== void 0 && !state.enteredSafeIsValid && state.address ? "error" : state.enteredSafeIsValid ? "success" : void 0,
|
|
406
|
+
message: state.enteredSafeIsValid !== void 0 && !state.enteredSafeIsValid && state.address ? "Invalid Safe Adrress" : state.enteredSafeIsValid ? "Valid Safe Address" : void 0
|
|
407
|
+
}
|
|
408
|
+
)
|
|
409
|
+
] }),
|
|
410
|
+
previouslyUsedSafes.values.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
411
|
+
/* @__PURE__ */ jsx(Divider, { className: "my-6" }),
|
|
412
|
+
/* @__PURE__ */ jsx("p", { className: "text-c12 text-white/64", children: "Previously used:" }),
|
|
413
|
+
/* @__PURE__ */ jsx(List.Bullets, { className: "mt-2", children: previouslyUsedSafes.values.map((safeAddress) => /* @__PURE__ */ jsx(List.Item, { children: /* @__PURE__ */ jsxs(
|
|
414
|
+
Link,
|
|
415
|
+
{
|
|
416
|
+
size: "12px",
|
|
417
|
+
autoIcon: false,
|
|
418
|
+
style: { transform: "translateY(-2.5px)" },
|
|
419
|
+
onClick: () => {
|
|
420
|
+
var _a;
|
|
421
|
+
const [shortName, address] = safeAddress.address.split(":");
|
|
422
|
+
const networkId = (_a = Object.values(SafeSupportedNetworkNames).find(
|
|
423
|
+
(supported) => supported.shortName === shortName
|
|
424
|
+
)) == null ? void 0 : _a.id;
|
|
425
|
+
if (networkId) {
|
|
426
|
+
ctx._setSafeInfo({ network: networkId, address: address ?? "", enteredSafeIsValid: true });
|
|
427
|
+
ctx._setModalState("safe_eoa_signer");
|
|
428
|
+
} else {
|
|
429
|
+
handleMultisigAddressChange(safeAddress.address);
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
children: [
|
|
433
|
+
/* @__PURE__ */ jsx("span", { className: "inline md:hidden", children: shortenMultisigAddress(safeAddress.address) }),
|
|
434
|
+
/* @__PURE__ */ jsx("span", { className: "hidden md:inline", children: safeAddress.address })
|
|
435
|
+
]
|
|
436
|
+
}
|
|
437
|
+
) }, `${safeAddress.address}__${safeAddress.timestamp}`)) })
|
|
438
|
+
] }) : null
|
|
439
|
+
]
|
|
440
|
+
}
|
|
441
|
+
) }),
|
|
442
|
+
/* @__PURE__ */ jsx(
|
|
443
|
+
ExperimentalModal.Footer,
|
|
444
|
+
{
|
|
445
|
+
primaryButton: /* @__PURE__ */ jsx(ExperimentalButton, { type: "submit", form: formId, disabled: isSubmitDisabled, iconAfter: /* @__PURE__ */ jsx(Icon.ArrowRight, { size: "16px" }), children: "Continue" }),
|
|
446
|
+
secondaryButton: /* @__PURE__ */ jsx(
|
|
447
|
+
ExperimentalButton,
|
|
448
|
+
{
|
|
449
|
+
onClick: () => {
|
|
450
|
+
dispatch({ action: "RESET" });
|
|
451
|
+
ctx._setModalState("primary");
|
|
452
|
+
},
|
|
453
|
+
children: "Back"
|
|
454
|
+
}
|
|
455
|
+
)
|
|
456
|
+
}
|
|
457
|
+
)
|
|
458
|
+
] });
|
|
459
|
+
}
|
|
460
|
+
function shortenMultisigAddress(multisig) {
|
|
461
|
+
const [shortName, address] = multisig.split(":");
|
|
462
|
+
return `${shortName}:${addrShortener(address)}`;
|
|
463
|
+
}
|
|
464
|
+
function usePreviouslyUsedSafes() {
|
|
465
|
+
const SIZE = 3;
|
|
466
|
+
function safesDb(onSuccess) {
|
|
467
|
+
const openRequest = window.indexedDB.open("previouslyUsedSafes", 1);
|
|
468
|
+
openRequest.onerror = () => {
|
|
469
|
+
};
|
|
470
|
+
openRequest.onupgradeneeded = function() {
|
|
471
|
+
const db = this.result;
|
|
472
|
+
const store = db.createObjectStore("previouslyUsedSafes", { keyPath: "address" });
|
|
473
|
+
store.createIndex("timestamp", "timestamp", { unique: false });
|
|
474
|
+
};
|
|
475
|
+
openRequest.onsuccess = onSuccess;
|
|
476
|
+
}
|
|
477
|
+
const [previouslyUsedSafes, setPreviouslyUsedSafes] = useState([]);
|
|
478
|
+
useEffect(() => {
|
|
479
|
+
if (typeof window === "undefined" || !window.indexedDB) return;
|
|
480
|
+
safesDb(function() {
|
|
481
|
+
const db = this.result;
|
|
482
|
+
if (!db) return;
|
|
483
|
+
const transaction = db.transaction("previouslyUsedSafes", "readonly");
|
|
484
|
+
const objectStore = transaction.objectStore("previouslyUsedSafes");
|
|
485
|
+
const index = objectStore.index("timestamp");
|
|
486
|
+
const cursorRequest = index.openCursor(null, "prev");
|
|
487
|
+
const entries = [];
|
|
488
|
+
cursorRequest.onsuccess = function() {
|
|
489
|
+
const cursor = this.result;
|
|
490
|
+
if (cursor && entries.length < SIZE) {
|
|
491
|
+
entries.push(cursor.value);
|
|
492
|
+
cursor.continue();
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
transaction.oncomplete = function() {
|
|
496
|
+
setPreviouslyUsedSafes(entries);
|
|
497
|
+
};
|
|
498
|
+
});
|
|
499
|
+
}, []);
|
|
500
|
+
return {
|
|
501
|
+
values: [...new Set(previouslyUsedSafes)],
|
|
502
|
+
save(network, safeAddress) {
|
|
503
|
+
if (typeof window === "undefined" || !window.indexedDB || previouslyUsedSafes.some((entry2) => entry2.address === safeAddress)) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const shortName = SafeSupportedNetworkNames[network].shortName;
|
|
507
|
+
const entry = {
|
|
508
|
+
address: `${shortName}:${safeAddress}`,
|
|
509
|
+
timestamp: (/* @__PURE__ */ new Date()).getTime()
|
|
510
|
+
};
|
|
511
|
+
setPreviouslyUsedSafes((prev) => [...prev, entry].slice(0, SIZE));
|
|
512
|
+
safesDb(function() {
|
|
513
|
+
const db = this.result;
|
|
514
|
+
if (!db) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
const transaction = db.transaction("previouslyUsedSafes", "readwrite");
|
|
518
|
+
const objectStore = transaction.objectStore("previouslyUsedSafes");
|
|
519
|
+
objectStore.put(entry);
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
function ConnectModal() {
|
|
525
|
+
const ctx = useGraphAuthKitInnerContext();
|
|
526
|
+
const steps = ["primary", "safe_entry", "safe_eoa_signer"];
|
|
527
|
+
const currentStep = ctx._modalState;
|
|
528
|
+
return /* @__PURE__ */ jsx(
|
|
529
|
+
ExperimentalModal,
|
|
530
|
+
{
|
|
531
|
+
open: ctx._connectModalOpen,
|
|
532
|
+
onClose: ctx._setConnectModalOpen,
|
|
533
|
+
steps: currentStep === "primary" ? [currentStep] : steps,
|
|
534
|
+
currentStep,
|
|
535
|
+
onCurrentStepChange: ctx._setModalState,
|
|
536
|
+
suppressHydrationWarning: true,
|
|
537
|
+
children: /* @__PURE__ */ jsx(ExperimentalModal.Step, { children: (() => {
|
|
538
|
+
switch (currentStep) {
|
|
539
|
+
case "primary":
|
|
540
|
+
return /* @__PURE__ */ jsx(PrimaryConnectOptions, {});
|
|
541
|
+
case "safe_entry":
|
|
542
|
+
return /* @__PURE__ */ jsx(SafeInputForm, {});
|
|
543
|
+
case "safe_eoa_signer":
|
|
544
|
+
return /* @__PURE__ */ jsx(MultisigSignerOptions, {});
|
|
545
|
+
}
|
|
546
|
+
})() })
|
|
547
|
+
}
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
const GraphAuthKitContext = createContext({
|
|
551
|
+
openConnectModal() {
|
|
552
|
+
},
|
|
553
|
+
closeConnectModal() {
|
|
554
|
+
},
|
|
555
|
+
disconnect() {
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
function useGraphAuthKit() {
|
|
559
|
+
return useContext(GraphAuthKitContext);
|
|
560
|
+
}
|
|
561
|
+
function GraphAuthKitProvider(props) {
|
|
562
|
+
const queryClient = props.queryClient ?? new QueryClient({
|
|
563
|
+
defaultOptions: {
|
|
564
|
+
queries: {
|
|
565
|
+
staleTime: 60 * 1e3
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
return /* @__PURE__ */ jsx(WagmiProvider, { config: props.config, children: /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx(
|
|
570
|
+
GraphAuthKitInnerContextProvider,
|
|
571
|
+
{
|
|
572
|
+
config: props.config,
|
|
573
|
+
infuraKey: props.infuraKey,
|
|
574
|
+
gatewayApiKey: props.gatewayApiKey,
|
|
575
|
+
safeApiKey: props.safeApiKey,
|
|
576
|
+
children: /* @__PURE__ */ jsx(GraphAuthKitContent, { config: props.config, children: props.children })
|
|
577
|
+
}
|
|
578
|
+
) }) });
|
|
579
|
+
}
|
|
580
|
+
function GraphAuthKitContent({
|
|
581
|
+
config,
|
|
582
|
+
children
|
|
583
|
+
}) {
|
|
584
|
+
const { disconnect: disconnectAccount } = useDisconnect({ config });
|
|
585
|
+
const innerContext = useGraphAuthKitInnerContext();
|
|
586
|
+
return /* @__PURE__ */ jsxs(
|
|
587
|
+
GraphAuthKitContext.Provider,
|
|
588
|
+
{
|
|
589
|
+
value: {
|
|
590
|
+
openConnectModal(props) {
|
|
591
|
+
innerContext._reset();
|
|
592
|
+
innerContext._setConnectModalOpen(true);
|
|
593
|
+
innerContext._setModalTitle((props == null ? void 0 : props.title) ?? "Connect your wallet");
|
|
594
|
+
innerContext._setModalSubtitle(props == null ? void 0 : props.subtitle);
|
|
595
|
+
innerContext._setAfterConnectUrl(props == null ? void 0 : props.afterConnectUrl);
|
|
596
|
+
},
|
|
597
|
+
closeConnectModal() {
|
|
598
|
+
innerContext._setConnectModalOpen(false);
|
|
599
|
+
},
|
|
600
|
+
disconnect() {
|
|
601
|
+
disconnectAccount();
|
|
602
|
+
innerContext._reset();
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
children: [
|
|
606
|
+
/* @__PURE__ */ jsx(ConnectModal, {}),
|
|
607
|
+
children
|
|
608
|
+
]
|
|
609
|
+
}
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
function MockGraphAuthKitProvider(props) {
|
|
613
|
+
const mockConfig = createConfig({
|
|
614
|
+
chains: [L2Chain, L2ChainTestnet, L1Chain, L1ChainTestnet],
|
|
615
|
+
connectors: [mock(props.mockConnectorParams)],
|
|
616
|
+
client(params) {
|
|
617
|
+
const chain = chainIsSupportedChain(params.chain) ? params.chain : DefChain;
|
|
618
|
+
return buildClient({ chain, infuraKey: props.infuraKey });
|
|
619
|
+
},
|
|
620
|
+
storage: createStorage({
|
|
621
|
+
storage: cookieStorage,
|
|
622
|
+
key: AUTH_STORAGE_KEY
|
|
623
|
+
})
|
|
624
|
+
});
|
|
625
|
+
const queryClient = new QueryClient({
|
|
626
|
+
defaultOptions: {
|
|
627
|
+
queries: {
|
|
628
|
+
retry: false
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
const initialState = props.initialState == null ? void 0 : typeof props.initialState === "string" ? cookieToInitialState(mockConfig, props.initialState) : props.initialState;
|
|
633
|
+
return /* @__PURE__ */ jsx(WagmiProvider, { config: mockConfig, initialState, children: /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx(GraphAuthKitInnerContext.Provider, { value: props.innerCtxState ?? defInnerState, children: /* @__PURE__ */ jsx(MockGraphAuthKitContent, { children: props.children }) }) }) });
|
|
634
|
+
}
|
|
635
|
+
function MockGraphAuthKitContent({ children }) {
|
|
636
|
+
const { disconnect } = useDisconnect();
|
|
637
|
+
const innerContext = useGraphAuthKitInnerContext();
|
|
638
|
+
return /* @__PURE__ */ jsx(
|
|
639
|
+
GraphAuthKitContext.Provider,
|
|
640
|
+
{
|
|
641
|
+
value: {
|
|
642
|
+
openConnectModal(props) {
|
|
643
|
+
innerContext._reset();
|
|
644
|
+
innerContext._setConnectModalOpen(true);
|
|
645
|
+
innerContext._setModalTitle((props == null ? void 0 : props.title) ?? "Connect your wallet");
|
|
646
|
+
innerContext._setModalSubtitle(props == null ? void 0 : props.subtitle);
|
|
647
|
+
},
|
|
648
|
+
closeConnectModal() {
|
|
649
|
+
innerContext._setConnectModalOpen(false);
|
|
650
|
+
},
|
|
651
|
+
disconnect() {
|
|
652
|
+
disconnect(
|
|
653
|
+
{},
|
|
654
|
+
{
|
|
655
|
+
onSettled() {
|
|
656
|
+
innerContext._reset();
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
},
|
|
662
|
+
children
|
|
663
|
+
}
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
z.union([
|
|
667
|
+
RequiredInfuraKey.merge(OptionalGatewayApiKey).extend({ status: z.literal("disconnected") }),
|
|
668
|
+
RequiredInfuraKey.merge(OptionalGatewayApiKey).extend({
|
|
669
|
+
status: z.literal("connected"),
|
|
670
|
+
account: z.union([
|
|
671
|
+
z.object({ type: z.literal("generated") }),
|
|
672
|
+
z.object({
|
|
673
|
+
type: z.literal("provided"),
|
|
674
|
+
/** If the specified connection is with a multisig, this is the multisig address */
|
|
675
|
+
address: z.custom((val) => val != null && typeof val === "string" && isAddress(val)),
|
|
676
|
+
chain: SupportedClientChainId.optional().default(L2Chain.id),
|
|
677
|
+
connector: z.union([
|
|
678
|
+
z.object({
|
|
679
|
+
type: z.union([
|
|
680
|
+
z.literal(injected.type),
|
|
681
|
+
z.literal(coinbaseWallet.type),
|
|
682
|
+
z.literal(walletConnect.type)
|
|
683
|
+
])
|
|
684
|
+
}),
|
|
685
|
+
/** If specified as a multsig, provide the EoA and Safe supported chain */
|
|
686
|
+
z.object({
|
|
687
|
+
type: z.literal("multisig"),
|
|
688
|
+
eoa: z.custom((val) => val != null && typeof val === "string" && isAddress(val)),
|
|
689
|
+
network: SafeSupportedNetworks.optional().default(L2Chain.id)
|
|
690
|
+
})
|
|
691
|
+
])
|
|
692
|
+
})
|
|
693
|
+
])
|
|
694
|
+
})
|
|
695
|
+
]);
|
|
696
|
+
function buildMockProviderState(args) {
|
|
697
|
+
if (args.status === "disconnected") {
|
|
698
|
+
return {
|
|
699
|
+
props: {
|
|
700
|
+
infuraKey: args.infuraKey,
|
|
701
|
+
gatewayApiKey: args.gatewayApiKey,
|
|
702
|
+
initialState: void 0,
|
|
703
|
+
innerCtxState: {
|
|
704
|
+
...defInnerState,
|
|
705
|
+
_infuraKey: args.infuraKey,
|
|
706
|
+
_gatewayApiKey: args.gatewayApiKey,
|
|
707
|
+
_ensResolver: buildEnsResolver({ infuraKey: args.infuraKey, gatewayApiKey: args.gatewayApiKey })
|
|
708
|
+
},
|
|
709
|
+
mockConnectorParams: {
|
|
710
|
+
accounts: ["0x"]
|
|
711
|
+
}
|
|
712
|
+
},
|
|
713
|
+
connectedAddress: null,
|
|
714
|
+
connector: null,
|
|
715
|
+
graphAuthKitConnector: null,
|
|
716
|
+
chain: null
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
const getConnectorFunctions = (address, chain) => {
|
|
720
|
+
return {
|
|
721
|
+
getAccounts: async () => {
|
|
722
|
+
return [{ address }];
|
|
723
|
+
},
|
|
724
|
+
getChainId: async () => {
|
|
725
|
+
return chain;
|
|
726
|
+
},
|
|
727
|
+
getProvider: async () => {
|
|
728
|
+
return {
|
|
729
|
+
request: async () => {
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
};
|
|
735
|
+
if (args.account.type === "generated") {
|
|
736
|
+
const privKey = generatePrivateKey();
|
|
737
|
+
const account = privateKeyToAccount(privKey);
|
|
738
|
+
const address = account.address;
|
|
739
|
+
const connector2 = selectedTypeToMockConnector("injected");
|
|
740
|
+
return {
|
|
741
|
+
props: {
|
|
742
|
+
infuraKey: args.infuraKey,
|
|
743
|
+
gatewayApiKey: args.gatewayApiKey,
|
|
744
|
+
initialState: {
|
|
745
|
+
status: "connected",
|
|
746
|
+
chainId: L2Chain.id,
|
|
747
|
+
connections: /* @__PURE__ */ new Map([
|
|
748
|
+
[
|
|
749
|
+
connector2.uid,
|
|
750
|
+
{
|
|
751
|
+
accounts: [address],
|
|
752
|
+
chainId: L2Chain.id,
|
|
753
|
+
connector: {
|
|
754
|
+
...connector2,
|
|
755
|
+
...getConnectorFunctions(address, L2Chain.id)
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
]
|
|
759
|
+
]),
|
|
760
|
+
current: connector2.uid
|
|
761
|
+
},
|
|
762
|
+
innerCtxState: {
|
|
763
|
+
...defInnerState,
|
|
764
|
+
_infuraKey: args.infuraKey,
|
|
765
|
+
_gatewayApiKey: args.gatewayApiKey,
|
|
766
|
+
_ensResolver: buildEnsResolver({ infuraKey: args.infuraKey, gatewayApiKey: args.gatewayApiKey })
|
|
767
|
+
},
|
|
768
|
+
mockConnectorParams: {
|
|
769
|
+
accounts: [address]
|
|
770
|
+
}
|
|
771
|
+
},
|
|
772
|
+
connectedAddress: address,
|
|
773
|
+
connector: connector2,
|
|
774
|
+
graphAuthKitConnector: "injected",
|
|
775
|
+
chain: L2Chain.id
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
if (args.account.connector.type === "multisig") {
|
|
779
|
+
const connector2 = selectedTypeToMockConnector("injected");
|
|
780
|
+
return {
|
|
781
|
+
props: {
|
|
782
|
+
infuraKey: args.infuraKey,
|
|
783
|
+
gatewayApiKey: args.gatewayApiKey,
|
|
784
|
+
initialState: {
|
|
785
|
+
status: "connected",
|
|
786
|
+
chainId: args.account.connector.network,
|
|
787
|
+
connections: /* @__PURE__ */ new Map([
|
|
788
|
+
[
|
|
789
|
+
connector2.uid,
|
|
790
|
+
{
|
|
791
|
+
accounts: [args.account.connector.eoa],
|
|
792
|
+
chainId: args.account.connector.network,
|
|
793
|
+
connector: {
|
|
794
|
+
...connector2,
|
|
795
|
+
...getConnectorFunctions(args.account.connector.eoa, args.account.connector.network)
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
]
|
|
799
|
+
]),
|
|
800
|
+
current: connector2.uid
|
|
801
|
+
},
|
|
802
|
+
innerCtxState: {
|
|
803
|
+
...defInnerState,
|
|
804
|
+
_infuraKey: args.infuraKey,
|
|
805
|
+
_gatewayApiKey: args.gatewayApiKey,
|
|
806
|
+
_ensResolver: buildEnsResolver({ infuraKey: args.infuraKey, gatewayApiKey: args.gatewayApiKey }),
|
|
807
|
+
_enteredMultisigInfo: {
|
|
808
|
+
address: args.account.address,
|
|
809
|
+
network: args.account.connector.network,
|
|
810
|
+
enteredSafeIsValid: true
|
|
811
|
+
}
|
|
812
|
+
},
|
|
813
|
+
mockConnectorParams: {
|
|
814
|
+
accounts: [args.account.address, args.account.connector.eoa]
|
|
815
|
+
}
|
|
816
|
+
},
|
|
817
|
+
connectedAddress: args.account.address,
|
|
818
|
+
connector: connector2,
|
|
819
|
+
graphAuthKitConnector: "multisig",
|
|
820
|
+
chain: args.account.connector.network
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
const connector = selectedTypeToMockConnector(args.account.connector.type);
|
|
824
|
+
return {
|
|
825
|
+
props: {
|
|
826
|
+
infuraKey: args.infuraKey,
|
|
827
|
+
gatewayApiKey: args.gatewayApiKey,
|
|
828
|
+
initialState: {
|
|
829
|
+
status: "connected",
|
|
830
|
+
chainId: args.account.chain,
|
|
831
|
+
connections: /* @__PURE__ */ new Map([
|
|
832
|
+
[
|
|
833
|
+
connector.uid,
|
|
834
|
+
{
|
|
835
|
+
accounts: [args.account.address],
|
|
836
|
+
chainId: args.account.chain,
|
|
837
|
+
connector: {
|
|
838
|
+
...connector,
|
|
839
|
+
...getConnectorFunctions(args.account.address, args.account.chain)
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
]
|
|
843
|
+
]),
|
|
844
|
+
current: connector.uid
|
|
845
|
+
},
|
|
846
|
+
innerCtxState: {
|
|
847
|
+
...defInnerState,
|
|
848
|
+
_infuraKey: args.infuraKey,
|
|
849
|
+
_gatewayApiKey: args.gatewayApiKey,
|
|
850
|
+
_ensResolver: buildEnsResolver({ infuraKey: args.infuraKey, gatewayApiKey: args.gatewayApiKey })
|
|
851
|
+
},
|
|
852
|
+
mockConnectorParams: {
|
|
853
|
+
accounts: [args.account.address]
|
|
854
|
+
}
|
|
855
|
+
},
|
|
856
|
+
connectedAddress: args.account.address,
|
|
857
|
+
connector,
|
|
858
|
+
graphAuthKitConnector: args.account.connector.type,
|
|
859
|
+
chain: args.account.chain
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
const disconnectedMockState = buildMockProviderState({
|
|
863
|
+
infuraKey: "doesnotmatter.notconnected",
|
|
864
|
+
status: "disconnected"
|
|
865
|
+
});
|
|
866
|
+
function selectedTypeToMockConnector(connector) {
|
|
867
|
+
switch (connector) {
|
|
868
|
+
case "coinbaseWallet": {
|
|
869
|
+
return {
|
|
870
|
+
id: "coinbaseWalletSDK",
|
|
871
|
+
name: "Coinbase Wallet",
|
|
872
|
+
uid: "192a483cf83",
|
|
873
|
+
type: "coinbaseWallet"
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
case "walletConnect": {
|
|
877
|
+
return {
|
|
878
|
+
id: "walletConnect",
|
|
879
|
+
name: "WalletConnect",
|
|
880
|
+
uid: "92a483cf83b",
|
|
881
|
+
type: "walletConnect"
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
case "multisig":
|
|
885
|
+
default: {
|
|
886
|
+
return { id: "io.metamask", name: "MetaMask", type: "injected", uid: "27cbd81134e" };
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
export {
|
|
891
|
+
GraphAuthKitContext as G,
|
|
892
|
+
MockGraphAuthKitProvider as M,
|
|
893
|
+
GraphAuthKitProvider as a,
|
|
894
|
+
buildMockProviderState as b,
|
|
895
|
+
disconnectedMockState as d,
|
|
896
|
+
useGraphAuthKit as u
|
|
897
|
+
};
|