@cordystackx/cordy_minikit 3.0.10 → 3.1.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/README.md +11 -8
- package/dist/client/authTypes.d.ts +13 -0
- package/dist/client/authTypes.d.ts.map +1 -0
- package/dist/client/authTypes.js +1 -0
- package/dist/client/cons.d.ts +31 -0
- package/dist/client/cons.d.ts.map +1 -0
- package/dist/client/cons.js +63 -0
- package/dist/client/consRuntime.d.ts +5 -0
- package/dist/client/consRuntime.d.ts.map +1 -0
- package/dist/client/consRuntime.js +32 -0
- package/dist/client/useConsSession.d.ts +3 -0
- package/dist/client/useConsSession.d.ts.map +1 -0
- package/dist/client/useConsSession.js +36 -0
- package/dist/client.d.ts +3 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -1
- package/dist/client__provider.d.ts +2 -1
- package/dist/client__provider.d.ts.map +1 -1
- package/dist/client__provider.js +4 -2
- package/dist/components/Connect_wallet_bt.d.ts.map +1 -1
- package/dist/components/Connect_wallet_bt.js +2 -10
- package/dist/components/UI_Comp.d.ts.map +1 -1
- package/dist/components/UI_Comp.js +118 -4
- package/dist/config/walletConfig.d.ts.map +1 -1
- package/dist/config/walletConfig.js +17 -1
- package/dist/controllers/DisConnect.d.ts.map +1 -1
- package/dist/controllers/DisConnect.js +8 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/package.json +4 -1
- package/dist/server/cons.d.ts +67 -0
- package/dist/server/cons.d.ts.map +1 -0
- package/dist/server/cons.js +383 -0
- package/dist/server/jwt.d.ts +0 -17
- package/dist/server/jwt.d.ts.map +1 -1
- package/dist/server/jwt.js +1 -35
- package/dist/server.d.ts +3 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +2 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/wagmi__providers.d.ts +11 -1
- package/dist/wagmi__providers.d.ts.map +1 -1
- package/dist/wagmi__providers.js +98 -11
- package/package.json +4 -1
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { ReactNode, Dispatch, SetStateAction } from "react";
|
|
2
2
|
import { type Config } from "wagmi";
|
|
3
|
+
import type { ConsSignedResult } from "./client/authTypes";
|
|
3
4
|
type WalletContextType = {
|
|
4
5
|
openModal: (options?: {
|
|
5
6
|
consSession?: boolean;
|
|
7
|
+
navigate?: string;
|
|
6
8
|
}) => void;
|
|
7
9
|
closeModal: () => void;
|
|
8
10
|
consSession: boolean;
|
|
11
|
+
consSessionEnabled: boolean;
|
|
12
|
+
consPath: string;
|
|
13
|
+
navigate?: string;
|
|
14
|
+
signedResult?: ConsSignedResult;
|
|
15
|
+
setSignedResult: Dispatch<SetStateAction<ConsSignedResult | undefined>>;
|
|
16
|
+
authError?: string;
|
|
17
|
+
setAuthError: Dispatch<SetStateAction<string | undefined>>;
|
|
9
18
|
};
|
|
10
19
|
type StellarWalletState = {
|
|
11
20
|
address: string | null;
|
|
@@ -13,9 +22,10 @@ type StellarWalletState = {
|
|
|
13
22
|
balance?: string;
|
|
14
23
|
manuallyDisconnected?: boolean;
|
|
15
24
|
};
|
|
16
|
-
export default function WalletProviders({ children, config: walletConfig }: {
|
|
25
|
+
export default function WalletProviders({ children, config: walletConfig, consPath }: {
|
|
17
26
|
children: ReactNode;
|
|
18
27
|
config?: Config;
|
|
28
|
+
consPath?: string;
|
|
19
29
|
}): import("react").JSX.Element;
|
|
20
30
|
export declare function useWalletModal(): WalletContextType;
|
|
21
31
|
export declare function useStellarWallet(): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wagmi__providers.d.ts","sourceRoot":"","sources":["../wagmi__providers.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"wagmi__providers.d.ts","sourceRoot":"","sources":["../wagmi__providers.tsx"],"names":[],"mappings":"AACA,OAAO,EAAuE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE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Ac,CAAC,kBAAkB,CAAC,CAAC;wBAC1C,MAAM,IAAI;EA6L/B"}
|
package/dist/wagmi__providers.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useCallback, useContext, useEffect, useState } from "react";
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
4
4
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
5
|
-
import { WagmiProvider } from "wagmi";
|
|
5
|
+
import { WagmiProvider, useAccount } from "wagmi";
|
|
6
6
|
import { config } from "./config/walletConfig";
|
|
7
7
|
import { UI_Comp } from "./components";
|
|
8
|
+
import { getConsUrl, requestConsDisconnect } from "./client/consRuntime";
|
|
9
|
+
import { WatchWalletChanges } from "@stellar/freighter-api";
|
|
8
10
|
const WalletContext = createContext(null);
|
|
9
11
|
const StellarWalletContext = createContext(null);
|
|
10
12
|
const queryClient = new QueryClient();
|
|
11
13
|
const STELLAR_WALLET_STORAGE_KEY = "cordy_minikit_stellar_wallet";
|
|
12
14
|
const ACTIVE_WALLET_SESSION_KEY = "cordy_minikit_active_wallet_session";
|
|
15
|
+
const DEFAULT_CONS_PATH = "/services/cons";
|
|
13
16
|
function readStellarWallet() {
|
|
14
17
|
if (typeof window === "undefined") {
|
|
15
18
|
return { address: null };
|
|
@@ -30,17 +33,34 @@ function readStellarWallet() {
|
|
|
30
33
|
return { address: null };
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
|
-
export default function WalletProviders({ children, config: walletConfig = config }) {
|
|
36
|
+
export default function WalletProviders({ children, config: walletConfig = config, consPath = DEFAULT_CONS_PATH }) {
|
|
34
37
|
const [open, setOpen] = useState(false);
|
|
35
38
|
const [consSession, setConsSession] = useState(false);
|
|
39
|
+
const [consSessionEnabled, setConsSessionEnabled] = useState(false);
|
|
40
|
+
const [navigate, setNavigate] = useState();
|
|
41
|
+
const [signedResult, setSignedResult] = useState();
|
|
42
|
+
const [authError, setAuthError] = useState();
|
|
36
43
|
const [stellarWallet, setStellarWallet] = useState(() => readStellarWallet());
|
|
44
|
+
const clearStellarWallet = useCallback(() => {
|
|
45
|
+
if (typeof window !== "undefined") {
|
|
46
|
+
window.localStorage.removeItem(STELLAR_WALLET_STORAGE_KEY);
|
|
47
|
+
window.localStorage.removeItem(ACTIVE_WALLET_SESSION_KEY);
|
|
48
|
+
}
|
|
49
|
+
setStellarWallet({ address: null, manuallyDisconnected: true });
|
|
50
|
+
}, []);
|
|
37
51
|
const openWalletModal = useCallback((options) => {
|
|
38
52
|
setConsSession(options?.consSession ?? false);
|
|
53
|
+
if (options?.consSession)
|
|
54
|
+
setConsSessionEnabled(true);
|
|
55
|
+
setNavigate(options?.navigate);
|
|
56
|
+
setAuthError(undefined);
|
|
57
|
+
setSignedResult(undefined);
|
|
39
58
|
setOpen(true);
|
|
40
59
|
}, []);
|
|
41
60
|
const closeWalletModal = useCallback(() => {
|
|
42
61
|
setOpen(false);
|
|
43
62
|
setConsSession(false);
|
|
63
|
+
setNavigate(undefined);
|
|
44
64
|
}, []);
|
|
45
65
|
useEffect(() => {
|
|
46
66
|
const handleStellarDisconnect = () => {
|
|
@@ -51,6 +71,18 @@ export default function WalletProviders({ children, config: walletConfig = confi
|
|
|
51
71
|
window.addEventListener("cordy:disconnect-stellar-wallet", handleStellarDisconnect);
|
|
52
72
|
return () => window.removeEventListener("cordy:disconnect-stellar-wallet", handleStellarDisconnect);
|
|
53
73
|
}, []);
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
const handleSessionAuthenticated = () => setConsSessionEnabled(true);
|
|
76
|
+
const handleSessionCleared = () => setConsSessionEnabled(false);
|
|
77
|
+
window.addEventListener("cordy:cons-session-authenticated", handleSessionAuthenticated);
|
|
78
|
+
window.addEventListener("cordy:cons-session-active", handleSessionAuthenticated);
|
|
79
|
+
window.addEventListener("cordy:cons-session-cleared", handleSessionCleared);
|
|
80
|
+
return () => {
|
|
81
|
+
window.removeEventListener("cordy:cons-session-authenticated", handleSessionAuthenticated);
|
|
82
|
+
window.removeEventListener("cordy:cons-session-active", handleSessionAuthenticated);
|
|
83
|
+
window.removeEventListener("cordy:cons-session-cleared", handleSessionCleared);
|
|
84
|
+
};
|
|
85
|
+
}, []);
|
|
54
86
|
useEffect(() => {
|
|
55
87
|
if (typeof window === "undefined")
|
|
56
88
|
return;
|
|
@@ -64,17 +96,72 @@ export default function WalletProviders({ children, config: walletConfig = confi
|
|
|
64
96
|
openModal: openWalletModal,
|
|
65
97
|
closeModal: closeWalletModal,
|
|
66
98
|
consSession,
|
|
99
|
+
consSessionEnabled,
|
|
100
|
+
consPath,
|
|
101
|
+
navigate,
|
|
102
|
+
signedResult,
|
|
103
|
+
setSignedResult,
|
|
104
|
+
authError,
|
|
105
|
+
setAuthError,
|
|
67
106
|
}, children: _jsxs(StellarWalletContext.Provider, { value: {
|
|
68
107
|
stellarWallet,
|
|
69
108
|
setStellarWallet,
|
|
70
|
-
clearStellarWallet
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
109
|
+
clearStellarWallet,
|
|
110
|
+
}, children: [children, open && _jsx(UI_Comp, {}), " ", _jsx(WalletSessionDisconnectWatcher, { consPath: consPath, enabled: consSessionEnabled })] }) }) }) }));
|
|
111
|
+
}
|
|
112
|
+
function WalletSessionDisconnectWatcher({ consPath, enabled }) {
|
|
113
|
+
const { isConnected } = useAccount();
|
|
114
|
+
const { stellarWallet, clearStellarWallet } = useStellarWallet();
|
|
115
|
+
const [authenticated, setAuthenticated] = useState(false);
|
|
116
|
+
const previouslyConnected = useRef(Boolean(isConnected || stellarWallet.address));
|
|
117
|
+
const connected = Boolean(isConnected || stellarWallet.address);
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!enabled)
|
|
120
|
+
return;
|
|
121
|
+
let active = true;
|
|
122
|
+
void fetch(getConsUrl("session", consPath), { credentials: "same-origin", cache: "no-store" })
|
|
123
|
+
.then((response) => response.json())
|
|
124
|
+
.then((body) => { if (active)
|
|
125
|
+
setAuthenticated(body?.success === true); })
|
|
126
|
+
.catch(() => { if (active)
|
|
127
|
+
setAuthenticated(false); });
|
|
128
|
+
const markAuthenticated = () => setAuthenticated(true);
|
|
129
|
+
const markCleared = () => setAuthenticated(false);
|
|
130
|
+
window.addEventListener("cordy:cons-session-authenticated", markAuthenticated);
|
|
131
|
+
window.addEventListener("cordy:cons-session-cleared", markCleared);
|
|
132
|
+
return () => {
|
|
133
|
+
active = false;
|
|
134
|
+
window.removeEventListener("cordy:cons-session-authenticated", markAuthenticated);
|
|
135
|
+
window.removeEventListener("cordy:cons-session-cleared", markCleared);
|
|
136
|
+
};
|
|
137
|
+
}, [consPath, enabled]);
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
if (!stellarWallet.address)
|
|
140
|
+
return;
|
|
141
|
+
const watcher = new WatchWalletChanges();
|
|
142
|
+
watcher.watch(({ address, error }) => {
|
|
143
|
+
if (error || address || !stellarWallet.address)
|
|
144
|
+
return;
|
|
145
|
+
clearStellarWallet();
|
|
146
|
+
});
|
|
147
|
+
return () => watcher.stop();
|
|
148
|
+
}, [clearStellarWallet, stellarWallet.address]);
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (!enabled)
|
|
151
|
+
return;
|
|
152
|
+
if (connected) {
|
|
153
|
+
previouslyConnected.current = true;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (previouslyConnected.current) {
|
|
157
|
+
previouslyConnected.current = false;
|
|
158
|
+
void requestConsDisconnect(consPath).then(() => setAuthenticated(false));
|
|
159
|
+
}
|
|
160
|
+
else if (!authenticated) {
|
|
161
|
+
previouslyConnected.current = false;
|
|
162
|
+
}
|
|
163
|
+
}, [authenticated, connected, consPath, enabled]);
|
|
164
|
+
return null;
|
|
78
165
|
}
|
|
79
166
|
export function useWalletModal() {
|
|
80
167
|
const ctx = useContext(WalletContext);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cordystackx/cordy_minikit",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -36,8 +36,11 @@
|
|
|
36
36
|
"@tanstack/react-query": "^5.104.5",
|
|
37
37
|
"@walletconnect/ethereum-provider": "^2.26.0",
|
|
38
38
|
"ethers": "^6.17.0",
|
|
39
|
+
"jose": "^6.2.15",
|
|
39
40
|
"next": "^16.4.3",
|
|
40
41
|
"react-icons": "^5.7.0",
|
|
42
|
+
"server-only": "0.0.1",
|
|
43
|
+
"siwe": "^3.0.0",
|
|
41
44
|
"viem": "^2.57.11"
|
|
42
45
|
},
|
|
43
46
|
"devDependencies": {
|