@dropfi/xrpl-react 0.1.0 → 0.1.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.
- package/package.json +3 -1
- package/dist/index.d.ts +0 -30
- package/dist/index.js +0 -132
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dropfi/xrpl-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "React hooks + provider for DropFi XRPL wallet (extension & mobile)",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/react": "^18.3.23",
|
|
36
|
+
"react": "^18.0.0",
|
|
37
|
+
"react-dom": "^18.0.0",
|
|
36
38
|
"tsup": "^8.5.0",
|
|
37
39
|
"typescript": "^5.8.3"
|
|
38
40
|
},
|
package/dist/index.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
interface XrplProviderConfig {
|
|
4
|
-
}
|
|
5
|
-
interface XrplProviderProps {
|
|
6
|
-
config?: XrplProviderConfig;
|
|
7
|
-
children: React.ReactNode;
|
|
8
|
-
}
|
|
9
|
-
declare const XrplProvider: React.FC<XrplProviderProps>;
|
|
10
|
-
|
|
11
|
-
declare function useXrplReact(): {
|
|
12
|
-
address: string | undefined;
|
|
13
|
-
wallet: string | undefined;
|
|
14
|
-
isConnected: boolean;
|
|
15
|
-
connect: () => Promise<string>;
|
|
16
|
-
disconnect: () => Promise<void>;
|
|
17
|
-
sendTransaction: (tx: any) => Promise<any>;
|
|
18
|
-
changeNetwork: (network: string) => Promise<any>;
|
|
19
|
-
connectedAccounts: string[];
|
|
20
|
-
network: string;
|
|
21
|
-
error: string | null;
|
|
22
|
-
isConnecting: boolean;
|
|
23
|
-
signMessage: (message: string) => Promise<{
|
|
24
|
-
signature: string;
|
|
25
|
-
error?: string;
|
|
26
|
-
}>;
|
|
27
|
-
initialized: boolean;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export { XrplProvider, useXrplReact };
|
package/dist/index.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
XrplProvider: () => XrplProvider,
|
|
24
|
-
useXrplReact: () => useXrplReact
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(src_exports);
|
|
27
|
-
|
|
28
|
-
// src/provider.tsx
|
|
29
|
-
var import_react = require("react");
|
|
30
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
|
-
var XrplContext = (0, import_react.createContext)(null);
|
|
32
|
-
var XrplProvider = ({ config, children }) => {
|
|
33
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(XrplContext.Provider, { value: { config }, children });
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// src/useXrplReact.tsx
|
|
37
|
-
var import_react2 = require("react");
|
|
38
|
-
function useXrplReact() {
|
|
39
|
-
const context = (0, import_react2.useContext)(XrplContext);
|
|
40
|
-
if (!context) {
|
|
41
|
-
throw new Error("useXrplReact must be used within a XrplProvider");
|
|
42
|
-
}
|
|
43
|
-
const [address, setAddress] = (0, import_react2.useState)();
|
|
44
|
-
const [connectedAccounts, setConnectedAccounts] = (0, import_react2.useState)([]);
|
|
45
|
-
const [network, setNetwork] = (0, import_react2.useState)("mainnet");
|
|
46
|
-
const [initialized, setInitialized] = (0, import_react2.useState)(false);
|
|
47
|
-
const [error, setError] = (0, import_react2.useState)(null);
|
|
48
|
-
const [isConnecting, setIsConnecting] = (0, import_react2.useState)(false);
|
|
49
|
-
(0, import_react2.useEffect)(() => {
|
|
50
|
-
if (typeof window === "undefined" || !window.xrpl)
|
|
51
|
-
return;
|
|
52
|
-
window.xrpl?.initialize?.();
|
|
53
|
-
setInitialized(true);
|
|
54
|
-
}, []);
|
|
55
|
-
(0, import_react2.useEffect)(() => {
|
|
56
|
-
if (typeof window === "undefined" || !window.xrpl)
|
|
57
|
-
return;
|
|
58
|
-
const handleSelectedNetwork = (val) => setNetwork(val);
|
|
59
|
-
const handleSelectedAddress = (val) => setAddress(val);
|
|
60
|
-
const handleConnectedAccounts = (val) => setConnectedAccounts(val);
|
|
61
|
-
window.xrpl?.on?.("xrpl_selectedNetwork", handleSelectedNetwork);
|
|
62
|
-
window.xrpl?.on?.("xrpl_selectedAddress", handleSelectedAddress);
|
|
63
|
-
window.xrpl?.on?.("xrpl_connectedAccounts", handleConnectedAccounts);
|
|
64
|
-
return () => {
|
|
65
|
-
window.xrpl?.off?.("xrpl_selectedNetwork", handleSelectedNetwork);
|
|
66
|
-
window.xrpl?.off?.("xrpl_selectedAddress", handleSelectedAddress);
|
|
67
|
-
window.xrpl?.off?.("xrpl_connectedAccounts", handleConnectedAccounts);
|
|
68
|
-
};
|
|
69
|
-
}, []);
|
|
70
|
-
const connect = async () => {
|
|
71
|
-
setIsConnecting(true);
|
|
72
|
-
try {
|
|
73
|
-
if (!window.xrpl)
|
|
74
|
-
throw new Error("No window.xrpl found");
|
|
75
|
-
const response = await window.xrpl.connect();
|
|
76
|
-
setAddress(response);
|
|
77
|
-
return response;
|
|
78
|
-
} catch (err) {
|
|
79
|
-
setError(err.message);
|
|
80
|
-
throw err;
|
|
81
|
-
} finally {
|
|
82
|
-
setIsConnecting(false);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
const disconnect = async () => {
|
|
86
|
-
if (!window.xrpl)
|
|
87
|
-
throw new Error("No window.xrpl found");
|
|
88
|
-
await window.xrpl.disconnect(address);
|
|
89
|
-
setAddress(void 0);
|
|
90
|
-
};
|
|
91
|
-
const sendTransaction = async (tx) => {
|
|
92
|
-
if (!window.xrpl)
|
|
93
|
-
throw new Error("No window.xrpl found");
|
|
94
|
-
return await window.xrpl.sendTransaction(tx);
|
|
95
|
-
};
|
|
96
|
-
const changeNetwork = async (network2) => {
|
|
97
|
-
if (!window.xrpl)
|
|
98
|
-
throw new Error("No window.xrpl found");
|
|
99
|
-
return await window.xrpl.changeNetwork(network2);
|
|
100
|
-
};
|
|
101
|
-
const signMessage = async (message) => {
|
|
102
|
-
if (!window.xrpl)
|
|
103
|
-
throw new Error("No window.xrpl found");
|
|
104
|
-
const res = await window.xrpl.signMessage(message);
|
|
105
|
-
if (res.error)
|
|
106
|
-
throw new Error(res.error);
|
|
107
|
-
return res;
|
|
108
|
-
};
|
|
109
|
-
return (0, import_react2.useMemo)(
|
|
110
|
-
() => ({
|
|
111
|
-
address,
|
|
112
|
-
wallet: address,
|
|
113
|
-
isConnected: connectedAccounts.includes(address || ""),
|
|
114
|
-
connect,
|
|
115
|
-
disconnect,
|
|
116
|
-
sendTransaction,
|
|
117
|
-
changeNetwork,
|
|
118
|
-
connectedAccounts,
|
|
119
|
-
network,
|
|
120
|
-
error,
|
|
121
|
-
isConnecting,
|
|
122
|
-
signMessage,
|
|
123
|
-
initialized
|
|
124
|
-
}),
|
|
125
|
-
[address, connectedAccounts, network, error, isConnecting, initialized]
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
-
0 && (module.exports = {
|
|
130
|
-
XrplProvider,
|
|
131
|
-
useXrplReact
|
|
132
|
-
});
|