@phantom/react-sdk 0.0.10 → 0.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 +475 -165
- package/dist/index.d.ts +72 -15
- package/dist/index.js +311 -17
- package/dist/index.mjs +320 -5
- package/package.json +7 -20
- package/dist/auto-confirm/index.d.ts +0 -44
- package/dist/auto-confirm/index.js +0 -182
- package/dist/auto-confirm/index.mjs +0 -137
- package/dist/chunk-5KSEZ3MC.mjs +0 -25
- package/dist/extension/index.d.ts +0 -5
- package/dist/extension/index.js +0 -68
- package/dist/extension/index.mjs +0 -22
- package/dist/solana/index.d.ts +0 -64
- package/dist/solana/index.js +0 -230
- package/dist/solana/index.mjs +0 -178
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
usePhantom
|
|
3
|
-
} from "../chunk-5KSEZ3MC.mjs";
|
|
4
|
-
|
|
5
|
-
// src/auto-confirm/index.ts
|
|
6
|
-
import "@phantom/browser-sdk/auto-confirm";
|
|
7
|
-
|
|
8
|
-
// src/auto-confirm/useAutoConfirmState.ts
|
|
9
|
-
import * as React from "react";
|
|
10
|
-
|
|
11
|
-
// src/auto-confirm/assertions.ts
|
|
12
|
-
function assertAutoConfirmConfigured(phantom) {
|
|
13
|
-
if (!phantom?.autoConfirm) {
|
|
14
|
-
throw new Error(
|
|
15
|
-
"Phantom auto-confirm plugin not found. Please ensure the auto-confirm plugin is installed and configured properly."
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// src/auto-confirm/useAutoConfirmState.ts
|
|
21
|
-
function useAutoConfirmState() {
|
|
22
|
-
const { phantom, isReady } = usePhantom();
|
|
23
|
-
const isMountedRef = React.useRef(true);
|
|
24
|
-
const isInitializedRef = React.useRef(false);
|
|
25
|
-
const [status, setStatus] = React.useState(null);
|
|
26
|
-
const [supportedChains, setSupportedChains] = React.useState(null);
|
|
27
|
-
const [isLoading, setIsLoading] = React.useState(true);
|
|
28
|
-
const [error, setError] = React.useState(null);
|
|
29
|
-
React.useEffect(() => {
|
|
30
|
-
return () => {
|
|
31
|
-
isMountedRef.current = false;
|
|
32
|
-
};
|
|
33
|
-
}, []);
|
|
34
|
-
const updateState = React.useCallback(async () => {
|
|
35
|
-
if (!isReady || !isMountedRef.current)
|
|
36
|
-
return;
|
|
37
|
-
try {
|
|
38
|
-
assertAutoConfirmConfigured(phantom);
|
|
39
|
-
if (!isMountedRef.current)
|
|
40
|
-
return;
|
|
41
|
-
setError(null);
|
|
42
|
-
if (status === null && isMountedRef.current) {
|
|
43
|
-
setIsLoading(true);
|
|
44
|
-
}
|
|
45
|
-
const [statusResult, supportedChainsResult] = await Promise.all([
|
|
46
|
-
phantom.autoConfirm.autoConfirmStatus(),
|
|
47
|
-
phantom.autoConfirm.autoConfirmSupportedChains()
|
|
48
|
-
]);
|
|
49
|
-
if (!isMountedRef.current)
|
|
50
|
-
return;
|
|
51
|
-
setStatus(statusResult);
|
|
52
|
-
setSupportedChains(supportedChainsResult.chains);
|
|
53
|
-
} catch (err) {
|
|
54
|
-
if (!isMountedRef.current)
|
|
55
|
-
return;
|
|
56
|
-
setError(err instanceof Error ? err : new Error("Failed to fetch auto-confirm state"));
|
|
57
|
-
setStatus(null);
|
|
58
|
-
setSupportedChains(null);
|
|
59
|
-
} finally {
|
|
60
|
-
if (isMountedRef.current) {
|
|
61
|
-
setIsLoading(false);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}, [phantom, isReady, status]);
|
|
65
|
-
React.useEffect(() => {
|
|
66
|
-
if (!isInitializedRef.current && isReady) {
|
|
67
|
-
isInitializedRef.current = true;
|
|
68
|
-
updateState();
|
|
69
|
-
}
|
|
70
|
-
const handleStateChange = () => {
|
|
71
|
-
updateState();
|
|
72
|
-
};
|
|
73
|
-
window.addEventListener("phantomAutoConfirmStateChanged", handleStateChange);
|
|
74
|
-
return () => {
|
|
75
|
-
window.removeEventListener("phantomAutoConfirmStateChanged", handleStateChange);
|
|
76
|
-
};
|
|
77
|
-
}, [updateState, isReady]);
|
|
78
|
-
return {
|
|
79
|
-
status,
|
|
80
|
-
supportedChains,
|
|
81
|
-
isLoading,
|
|
82
|
-
error
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// src/auto-confirm/useAutoConfirmActions.ts
|
|
87
|
-
import * as React2 from "react";
|
|
88
|
-
function useAutoConfirmActions() {
|
|
89
|
-
const { phantom, isReady } = usePhantom();
|
|
90
|
-
const enable = React2.useCallback(
|
|
91
|
-
async (params) => {
|
|
92
|
-
if (!isReady) {
|
|
93
|
-
throw new Error("Phantom is not ready");
|
|
94
|
-
}
|
|
95
|
-
assertAutoConfirmConfigured(phantom);
|
|
96
|
-
const result = await phantom.autoConfirm.autoConfirmEnable(params);
|
|
97
|
-
window.dispatchEvent(new CustomEvent("phantomAutoConfirmStateChanged"));
|
|
98
|
-
return result;
|
|
99
|
-
},
|
|
100
|
-
[phantom, isReady]
|
|
101
|
-
);
|
|
102
|
-
const disable = React2.useCallback(async () => {
|
|
103
|
-
if (!isReady) {
|
|
104
|
-
throw new Error("Phantom is not ready");
|
|
105
|
-
}
|
|
106
|
-
assertAutoConfirmConfigured(phantom);
|
|
107
|
-
const result = await phantom.autoConfirm.autoConfirmDisable();
|
|
108
|
-
window.dispatchEvent(new CustomEvent("phantomAutoConfirmStateChanged"));
|
|
109
|
-
return result;
|
|
110
|
-
}, [phantom, isReady]);
|
|
111
|
-
const getSupportedChains = React2.useCallback(async () => {
|
|
112
|
-
if (!isReady) {
|
|
113
|
-
throw new Error("Phantom is not ready");
|
|
114
|
-
}
|
|
115
|
-
assertAutoConfirmConfigured(phantom);
|
|
116
|
-
const result = await phantom.autoConfirm.autoConfirmSupportedChains();
|
|
117
|
-
return result;
|
|
118
|
-
}, [phantom, isReady]);
|
|
119
|
-
const getStatus = React2.useCallback(async () => {
|
|
120
|
-
if (!isReady) {
|
|
121
|
-
throw new Error("Phantom is not ready");
|
|
122
|
-
}
|
|
123
|
-
assertAutoConfirmConfigured(phantom);
|
|
124
|
-
const result = await phantom.autoConfirm.autoConfirmStatus();
|
|
125
|
-
return result;
|
|
126
|
-
}, [phantom, isReady]);
|
|
127
|
-
return {
|
|
128
|
-
enable,
|
|
129
|
-
disable,
|
|
130
|
-
getSupportedChains,
|
|
131
|
-
getStatus
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
export {
|
|
135
|
-
useAutoConfirmActions,
|
|
136
|
-
useAutoConfirmState
|
|
137
|
-
};
|
package/dist/chunk-5KSEZ3MC.mjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// src/PhantomContext.tsx
|
|
2
|
-
import { createPhantom } from "@phantom/browser-sdk";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
var PhantomContext = React.createContext({ phantom: void 0, isReady: false });
|
|
6
|
-
var PhantomProvider = ({ children, config }) => {
|
|
7
|
-
const [context, setContext] = React.useState({ phantom: void 0, isReady: false });
|
|
8
|
-
React.useEffect(() => {
|
|
9
|
-
const phantom = createPhantom(config);
|
|
10
|
-
setContext({ phantom, isReady: true });
|
|
11
|
-
}, [config]);
|
|
12
|
-
return /* @__PURE__ */ jsx(PhantomContext.Provider, { value: context, children });
|
|
13
|
-
};
|
|
14
|
-
function usePhantom() {
|
|
15
|
-
const context = React.useContext(PhantomContext);
|
|
16
|
-
if (!context) {
|
|
17
|
-
throw new Error("usePhantom must be used within a PhantomProvider");
|
|
18
|
-
}
|
|
19
|
-
return context;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
PhantomProvider,
|
|
24
|
-
usePhantom
|
|
25
|
-
};
|
package/dist/extension/index.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/extension/index.ts
|
|
31
|
-
var extension_exports = {};
|
|
32
|
-
__export(extension_exports, {
|
|
33
|
-
useIsInstalled: () => useIsInstalled
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(extension_exports);
|
|
36
|
-
var import_extension = require("@phantom/browser-sdk/extension");
|
|
37
|
-
|
|
38
|
-
// src/extension/useIsInstalled.ts
|
|
39
|
-
var React2 = __toESM(require("react"));
|
|
40
|
-
|
|
41
|
-
// src/PhantomContext.tsx
|
|
42
|
-
var import_browser_sdk = require("@phantom/browser-sdk");
|
|
43
|
-
var React = __toESM(require("react"));
|
|
44
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
45
|
-
var PhantomContext = React.createContext({ phantom: void 0, isReady: false });
|
|
46
|
-
function usePhantom() {
|
|
47
|
-
const context = React.useContext(PhantomContext);
|
|
48
|
-
if (!context) {
|
|
49
|
-
throw new Error("usePhantom must be used within a PhantomProvider");
|
|
50
|
-
}
|
|
51
|
-
return context;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// src/extension/useIsInstalled.ts
|
|
55
|
-
function useIsInstalled() {
|
|
56
|
-
const { phantom } = usePhantom();
|
|
57
|
-
const isInstalled = React2.useCallback(async () => {
|
|
58
|
-
if (!phantom?.extension) {
|
|
59
|
-
throw new Error("Phantom extension plugin not found.");
|
|
60
|
-
}
|
|
61
|
-
return await phantom.extension.isInstalled();
|
|
62
|
-
}, [phantom]);
|
|
63
|
-
return { isInstalled };
|
|
64
|
-
}
|
|
65
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
-
0 && (module.exports = {
|
|
67
|
-
useIsInstalled
|
|
68
|
-
});
|
package/dist/extension/index.mjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
usePhantom
|
|
3
|
-
} from "../chunk-5KSEZ3MC.mjs";
|
|
4
|
-
|
|
5
|
-
// src/extension/index.ts
|
|
6
|
-
import "@phantom/browser-sdk/extension";
|
|
7
|
-
|
|
8
|
-
// src/extension/useIsInstalled.ts
|
|
9
|
-
import * as React from "react";
|
|
10
|
-
function useIsInstalled() {
|
|
11
|
-
const { phantom } = usePhantom();
|
|
12
|
-
const isInstalled = React.useCallback(async () => {
|
|
13
|
-
if (!phantom?.extension) {
|
|
14
|
-
throw new Error("Phantom extension plugin not found.");
|
|
15
|
-
}
|
|
16
|
-
return await phantom.extension.isInstalled();
|
|
17
|
-
}, [phantom]);
|
|
18
|
-
return { isInstalled };
|
|
19
|
-
}
|
|
20
|
-
export {
|
|
21
|
-
useIsInstalled
|
|
22
|
-
};
|
package/dist/solana/index.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { SolanaSignInData } from '@phantom/browser-sdk/solana';
|
|
2
|
-
import { Transaction } from '@solana/kit';
|
|
3
|
-
import { VersionedTransaction } from '@solana/web3.js';
|
|
4
|
-
|
|
5
|
-
type UseConnectProps = {
|
|
6
|
-
autoConnect?: boolean;
|
|
7
|
-
};
|
|
8
|
-
declare function useConnect({ autoConnect }?: UseConnectProps): {
|
|
9
|
-
connect: () => Promise<string | undefined>;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
declare function useDisconnect(): {
|
|
13
|
-
disconnect: () => Promise<void>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
interface UseSignInResult {
|
|
17
|
-
signIn: (signInData: SolanaSignInData) => Promise<{
|
|
18
|
-
address: string;
|
|
19
|
-
signature: Uint8Array;
|
|
20
|
-
signedMessage: Uint8Array;
|
|
21
|
-
}>;
|
|
22
|
-
}
|
|
23
|
-
declare function useSignIn(): UseSignInResult;
|
|
24
|
-
|
|
25
|
-
interface UseSignAndSendTransactionResult {
|
|
26
|
-
signAndSendTransaction: (transaction: Transaction | VersionedTransaction) => Promise<{
|
|
27
|
-
signature: string;
|
|
28
|
-
publicKey?: string;
|
|
29
|
-
}>;
|
|
30
|
-
}
|
|
31
|
-
declare function useSignAndSendTransaction(): UseSignAndSendTransactionResult;
|
|
32
|
-
|
|
33
|
-
interface UseSignMessageResult {
|
|
34
|
-
signMessage: (message: Uint8Array, display?: "utf8" | "hex") => Promise<{
|
|
35
|
-
signature: Uint8Array;
|
|
36
|
-
address: string;
|
|
37
|
-
}>;
|
|
38
|
-
}
|
|
39
|
-
declare function useSignMessage(): UseSignMessageResult;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* React hook that provides the current account connection status and public key.
|
|
43
|
-
* Automatically updates when the account connects, disconnects, or changes.
|
|
44
|
-
*
|
|
45
|
-
* @returns Object containing status ('connected' | 'disconnected') and address (string | null)
|
|
46
|
-
*/
|
|
47
|
-
declare function useAccount(): string | undefined;
|
|
48
|
-
|
|
49
|
-
type UseAccountEffectParameters = {
|
|
50
|
-
onConnect?(data: {
|
|
51
|
-
publicKey: string;
|
|
52
|
-
}): void;
|
|
53
|
-
onDisconnect?(): void;
|
|
54
|
-
onAccountChanged?(data: {
|
|
55
|
-
publicKey: string;
|
|
56
|
-
}): void;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Hook for listening to account lifecycle events.
|
|
60
|
-
* Provides callbacks for connect, disconnect, and account change events.
|
|
61
|
-
*/
|
|
62
|
-
declare function useAccountEffect(parameters?: UseAccountEffectParameters): void;
|
|
63
|
-
|
|
64
|
-
export { useAccount, useAccountEffect, useConnect, useDisconnect, useSignAndSendTransaction, useSignIn, useSignMessage };
|
package/dist/solana/index.js
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/solana/index.ts
|
|
31
|
-
var solana_exports = {};
|
|
32
|
-
__export(solana_exports, {
|
|
33
|
-
useAccount: () => useAccount,
|
|
34
|
-
useAccountEffect: () => useAccountEffect,
|
|
35
|
-
useConnect: () => useConnect,
|
|
36
|
-
useDisconnect: () => useDisconnect,
|
|
37
|
-
useSignAndSendTransaction: () => useSignAndSendTransaction,
|
|
38
|
-
useSignIn: () => useSignIn,
|
|
39
|
-
useSignMessage: () => useSignMessage
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(solana_exports);
|
|
42
|
-
var import_solana = require("@phantom/browser-sdk/solana");
|
|
43
|
-
|
|
44
|
-
// src/solana/useConnect.ts
|
|
45
|
-
var React2 = __toESM(require("react"));
|
|
46
|
-
|
|
47
|
-
// src/PhantomContext.tsx
|
|
48
|
-
var import_browser_sdk = require("@phantom/browser-sdk");
|
|
49
|
-
var React = __toESM(require("react"));
|
|
50
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
51
|
-
var PhantomContext = React.createContext({ phantom: void 0, isReady: false });
|
|
52
|
-
function usePhantom() {
|
|
53
|
-
const context = React.useContext(PhantomContext);
|
|
54
|
-
if (!context) {
|
|
55
|
-
throw new Error("usePhantom must be used within a PhantomProvider");
|
|
56
|
-
}
|
|
57
|
-
return context;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// src/solana/useConnect.ts
|
|
61
|
-
function useConnect({ autoConnect = false } = {}) {
|
|
62
|
-
const { phantom } = usePhantom();
|
|
63
|
-
const connect = React2.useCallback(async () => {
|
|
64
|
-
if (!phantom?.solana) {
|
|
65
|
-
throw new Error("Phantom solana plugin not found.");
|
|
66
|
-
}
|
|
67
|
-
return await phantom.solana.connect();
|
|
68
|
-
}, [phantom]);
|
|
69
|
-
React2.useEffect(() => {
|
|
70
|
-
if (autoConnect && phantom?.solana) {
|
|
71
|
-
connect();
|
|
72
|
-
}
|
|
73
|
-
}, [autoConnect, connect, phantom?.solana]);
|
|
74
|
-
return { connect };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// src/solana/useDisconnect.ts
|
|
78
|
-
var React3 = __toESM(require("react"));
|
|
79
|
-
function useDisconnect() {
|
|
80
|
-
const { phantom } = usePhantom();
|
|
81
|
-
const disconnect = React3.useCallback(async () => {
|
|
82
|
-
if (!phantom?.solana) {
|
|
83
|
-
throw new Error("Phantom solana disconnect method not found.");
|
|
84
|
-
}
|
|
85
|
-
return await phantom.solana.disconnect();
|
|
86
|
-
}, [phantom]);
|
|
87
|
-
return { disconnect };
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// src/solana/useSignIn.ts
|
|
91
|
-
var import_react = require("react");
|
|
92
|
-
function useSignIn() {
|
|
93
|
-
const { phantom } = usePhantom();
|
|
94
|
-
const signIn = (0, import_react.useCallback)(
|
|
95
|
-
async (signInData) => {
|
|
96
|
-
if (!phantom?.solana) {
|
|
97
|
-
throw new Error("Phantom Solana provider not available.");
|
|
98
|
-
}
|
|
99
|
-
const result = await phantom.solana.signIn(signInData);
|
|
100
|
-
return result;
|
|
101
|
-
},
|
|
102
|
-
[phantom]
|
|
103
|
-
);
|
|
104
|
-
return { signIn };
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// src/solana/useSignAndSendTransaction.ts
|
|
108
|
-
var import_react2 = require("react");
|
|
109
|
-
function useSignAndSendTransaction() {
|
|
110
|
-
const { phantom } = usePhantom();
|
|
111
|
-
const signAndSendTransaction = (0, import_react2.useCallback)(
|
|
112
|
-
async (transaction) => {
|
|
113
|
-
if (!phantom?.solana) {
|
|
114
|
-
throw new Error("Phantom Solana provider not available.");
|
|
115
|
-
}
|
|
116
|
-
const result = await phantom.solana.signAndSendTransaction(transaction);
|
|
117
|
-
return result;
|
|
118
|
-
},
|
|
119
|
-
[phantom]
|
|
120
|
-
);
|
|
121
|
-
return { signAndSendTransaction };
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// src/solana/useSignMessage.ts
|
|
125
|
-
var import_react3 = require("react");
|
|
126
|
-
function useSignMessage() {
|
|
127
|
-
const { phantom } = usePhantom();
|
|
128
|
-
const signMessage = (0, import_react3.useCallback)(
|
|
129
|
-
async (message, display) => {
|
|
130
|
-
if (!phantom?.solana) {
|
|
131
|
-
throw new Error("Phantom Solana provider not available.");
|
|
132
|
-
}
|
|
133
|
-
const result = await phantom.solana.signMessage(message, display);
|
|
134
|
-
return result;
|
|
135
|
-
},
|
|
136
|
-
[phantom]
|
|
137
|
-
);
|
|
138
|
-
return { signMessage };
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// src/solana/useAccount.ts
|
|
142
|
-
var React4 = __toESM(require("react"));
|
|
143
|
-
|
|
144
|
-
// src/solana/assertions.ts
|
|
145
|
-
function assertSolanaConfigured(phantom) {
|
|
146
|
-
if (!phantom?.solana) {
|
|
147
|
-
throw new Error(
|
|
148
|
-
"Phantom solana chain plugin not found. Please ensure the solana chain plugin is installed and configured properly."
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// src/solana/useAccount.ts
|
|
154
|
-
function useAccount() {
|
|
155
|
-
const { phantom, isReady } = usePhantom();
|
|
156
|
-
const [account, setAccount] = React4.useState(void 0);
|
|
157
|
-
React4.useEffect(() => {
|
|
158
|
-
if (!isReady)
|
|
159
|
-
return;
|
|
160
|
-
assertSolanaConfigured(phantom);
|
|
161
|
-
const updateAccount = async () => {
|
|
162
|
-
setAccount(await phantom.solana.getAccount());
|
|
163
|
-
};
|
|
164
|
-
updateAccount();
|
|
165
|
-
phantom.solana.addEventListener("connect", updateAccount);
|
|
166
|
-
phantom.solana.addEventListener("disconnect", updateAccount);
|
|
167
|
-
phantom.solana.addEventListener("accountChanged", updateAccount);
|
|
168
|
-
return () => {
|
|
169
|
-
phantom.solana.removeEventListener("connect", updateAccount);
|
|
170
|
-
phantom.solana.removeEventListener("disconnect", updateAccount);
|
|
171
|
-
phantom.solana.removeEventListener("accountChanged", updateAccount);
|
|
172
|
-
};
|
|
173
|
-
}, [phantom, isReady]);
|
|
174
|
-
return account;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// src/solana/useAccountEffect.ts
|
|
178
|
-
var React5 = __toESM(require("react"));
|
|
179
|
-
function useAccountEffect(parameters = {}) {
|
|
180
|
-
const { onConnect, onDisconnect, onAccountChanged } = parameters;
|
|
181
|
-
const { phantom, isReady } = usePhantom();
|
|
182
|
-
React5.useEffect(() => {
|
|
183
|
-
if (!isReady)
|
|
184
|
-
return;
|
|
185
|
-
assertSolanaConfigured(phantom);
|
|
186
|
-
const handleConnect = (publicKey) => {
|
|
187
|
-
onConnect?.({
|
|
188
|
-
publicKey
|
|
189
|
-
});
|
|
190
|
-
};
|
|
191
|
-
const handleDisconnect = () => {
|
|
192
|
-
onDisconnect?.();
|
|
193
|
-
};
|
|
194
|
-
const handleAccountChanged = (publicKey) => {
|
|
195
|
-
onAccountChanged?.({
|
|
196
|
-
publicKey
|
|
197
|
-
});
|
|
198
|
-
};
|
|
199
|
-
if (onConnect) {
|
|
200
|
-
phantom.solana.addEventListener("connect", handleConnect);
|
|
201
|
-
}
|
|
202
|
-
if (onDisconnect) {
|
|
203
|
-
phantom.solana.addEventListener("disconnect", handleDisconnect);
|
|
204
|
-
}
|
|
205
|
-
if (onAccountChanged) {
|
|
206
|
-
phantom.solana.addEventListener("accountChanged", handleAccountChanged);
|
|
207
|
-
}
|
|
208
|
-
return () => {
|
|
209
|
-
if (onConnect) {
|
|
210
|
-
phantom.solana.removeEventListener("connect", handleConnect);
|
|
211
|
-
}
|
|
212
|
-
if (onDisconnect) {
|
|
213
|
-
phantom.solana.removeEventListener("disconnect", handleDisconnect);
|
|
214
|
-
}
|
|
215
|
-
if (onAccountChanged) {
|
|
216
|
-
phantom.solana.removeEventListener("accountChanged", handleAccountChanged);
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
}, [isReady, phantom, onConnect, onDisconnect, onAccountChanged]);
|
|
220
|
-
}
|
|
221
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
222
|
-
0 && (module.exports = {
|
|
223
|
-
useAccount,
|
|
224
|
-
useAccountEffect,
|
|
225
|
-
useConnect,
|
|
226
|
-
useDisconnect,
|
|
227
|
-
useSignAndSendTransaction,
|
|
228
|
-
useSignIn,
|
|
229
|
-
useSignMessage
|
|
230
|
-
});
|