@edgeandnode/graph-auth-kit 0.3.1 → 0.3.2
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.
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type SupportedClientChains } from '../constants';
|
|
2
|
+
export type SwitchChainProps<chains extends readonly [SupportedClientChains, ...SupportedClientChains[]]> = {
|
|
3
|
+
/** The chain to switch to. Must be one of the available chains in the registered config */
|
|
4
|
+
requestedChain: chains[number];
|
|
5
|
+
};
|
|
6
|
+
export declare function SwitchChain<const chains extends readonly [SupportedClientChains, ...SupportedClientChains[]]>(props: SwitchChainProps<chains>): import("react").JSX.Element | null;
|
|
7
|
+
//# sourceMappingURL=SwitchChain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwitchChain.d.ts","sourceRoot":"","sources":["../../src/Components/SwitchChain.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAGzD,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,SAAS,CAAC,qBAAqB,EAAE,GAAG,qBAAqB,EAAE,CAAC,IAAI;IAC1G,2FAA2F;IAC3F,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;CAC/B,CAAA;AACD,wBAAgB,WAAW,CAAC,KAAK,CAAC,MAAM,SAAS,SAAS,CAAC,qBAAqB,EAAE,GAAG,qBAAqB,EAAE,CAAC,EAC3G,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,sCAgChC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACrE,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -8,11 +8,13 @@ import { j as j2, A, D, g as g2, h as h2, L, e, M, a as a2, S, k as k2, l as l2,
|
|
|
8
8
|
import { useMutation } from "@tanstack/react-query";
|
|
9
9
|
import { useMemo } from "react";
|
|
10
10
|
import { encodeFunctionData, getAddress } from "viem";
|
|
11
|
-
import { useChainId, useConnectorClient, useAccount, useWalletClient, useConfig } from "wagmi";
|
|
11
|
+
import { useChainId, useConnectorClient, useAccount, useWalletClient, useConfig, useSwitchChain } from "wagmi";
|
|
12
12
|
import { writeContractMutationOptions } from "wagmi/query";
|
|
13
13
|
import { VoidSigner } from "@ethersproject/abstract-signer";
|
|
14
14
|
import { OperationType } from "@safe-global/safe-core-sdk-types";
|
|
15
15
|
import { utils, BigNumber } from "ethers";
|
|
16
|
+
import { jsx, jsxs } from "@theme-ui/core/jsx-runtime";
|
|
17
|
+
import { Alert, ExperimentalButton } from "@edgeandnode/gds";
|
|
16
18
|
const createLibAddress = "0x7cbB62EaA69F79e6873cD1ecB2392971036cFAa4";
|
|
17
19
|
const createLibInterface = new utils.Interface([
|
|
18
20
|
{
|
|
@@ -429,6 +431,39 @@ function Disconnected({ children }) {
|
|
|
429
431
|
}
|
|
430
432
|
return null;
|
|
431
433
|
}
|
|
434
|
+
function SwitchChain(props) {
|
|
435
|
+
const account = useGraphAuthKitAccount();
|
|
436
|
+
const { switchChain, error } = useSwitchChain();
|
|
437
|
+
if (account.connector == null || account.chainId === props.requestedChain.id) {
|
|
438
|
+
return null;
|
|
439
|
+
}
|
|
440
|
+
return /* @__PURE__ */ jsx(
|
|
441
|
+
Alert,
|
|
442
|
+
{
|
|
443
|
+
severity: "warning",
|
|
444
|
+
title: `Switch to ${props.requestedChain.name} network`,
|
|
445
|
+
description: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
446
|
+
/* @__PURE__ */ jsxs("p", { className: "text-p16", children: [
|
|
447
|
+
"You need to be connected to the ",
|
|
448
|
+
props.requestedChain.name,
|
|
449
|
+
" network to perform this action."
|
|
450
|
+
] }),
|
|
451
|
+
error != null ? /* @__PURE__ */ jsx("p", { className: "text-c14 normal-case text-red/88", children: error.message }) : null
|
|
452
|
+
] }),
|
|
453
|
+
PrimaryCTA: /* @__PURE__ */ jsxs(
|
|
454
|
+
ExperimentalButton,
|
|
455
|
+
{
|
|
456
|
+
variant: "secondary",
|
|
457
|
+
onClick: () => switchChain({ chainId: props.requestedChain.id, connector: account.connector }),
|
|
458
|
+
children: [
|
|
459
|
+
"Switch to ",
|
|
460
|
+
props.requestedChain.name
|
|
461
|
+
]
|
|
462
|
+
}
|
|
463
|
+
)
|
|
464
|
+
}
|
|
465
|
+
);
|
|
466
|
+
}
|
|
432
467
|
export {
|
|
433
468
|
j2 as AUTH_STORAGE_KEY,
|
|
434
469
|
A as ApiKitUrlMap,
|
|
@@ -452,6 +487,7 @@ export {
|
|
|
452
487
|
S as SafeSupportedNetworks,
|
|
453
488
|
k2 as SupportedClientChainId,
|
|
454
489
|
l2 as SupportedClientChains,
|
|
490
|
+
SwitchChain,
|
|
455
491
|
b as buildClient,
|
|
456
492
|
f as buildInfuraHttpTransport,
|
|
457
493
|
g as buildPublicClient,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgeandnode/graph-auth-kit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Wallet authentication connect kit in The Graph suite of applications",
|
|
6
6
|
"author": "Edge & Node",
|
|
@@ -69,10 +69,10 @@
|
|
|
69
69
|
"ts-node": "^10.9.2",
|
|
70
70
|
"viem": "2.19.3",
|
|
71
71
|
"wagmi": "2.12.5",
|
|
72
|
-
"@edgeandnode/
|
|
73
|
-
"@edgeandnode/go": "^6.42.0",
|
|
72
|
+
"@edgeandnode/common": "^6.18.0",
|
|
74
73
|
"@edgeandnode/gds": "^5.27.0",
|
|
75
|
-
"@edgeandnode/
|
|
74
|
+
"@edgeandnode/go": "^6.42.0",
|
|
75
|
+
"@edgeandnode/test-utils": "^2.0.0"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"zod": "^3.23.8"
|