@omnity/ree-client-ts-sdk 0.5.2 → 0.5.3
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/dist/{ree-sdk.cjs.js → index.cjs.js} +1 -1
- package/dist/{ree-sdk.es.js → index.es.js} +1 -1
- package/dist/react.cjs.js +1 -0
- package/dist/react.d.ts +691 -0
- package/dist/react.es.js +322 -0
- package/package.json +15 -5
package/dist/react.es.js
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { jsx as x } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as E, useState as u, useCallback as g, useMemo as w, useContext as P, useEffect as y } from "react";
|
|
3
|
+
import { ReeClient as p } from "./index.es.js";
|
|
4
|
+
import { Network as W, utils as X } from "./index.es.js";
|
|
5
|
+
const v = E(null);
|
|
6
|
+
function U({ children: e, config: n }) {
|
|
7
|
+
if (!n)
|
|
8
|
+
throw new Error("ReeProvider: config is required");
|
|
9
|
+
if (!n.network)
|
|
10
|
+
throw new Error("ReeProvider: config.network is required");
|
|
11
|
+
if (!n.maestroApiKey)
|
|
12
|
+
throw new Error("ReeProvider: config.maestroApiKey is required");
|
|
13
|
+
if (!n.exchangeIdlFactory)
|
|
14
|
+
throw new Error("ReeProvider: config.exchangeIdlFactory is required");
|
|
15
|
+
if (!n.exchangeCanisterId)
|
|
16
|
+
throw new Error("ReeProvider: config.exchangeCanisterId is required");
|
|
17
|
+
const [r, a] = u({
|
|
18
|
+
address: "",
|
|
19
|
+
paymentAddress: "",
|
|
20
|
+
publicKey: "",
|
|
21
|
+
paymentPublicKey: ""
|
|
22
|
+
}), s = g((l) => {
|
|
23
|
+
a((f) => ({ ...f, ...l }));
|
|
24
|
+
}, []), t = w(() => new p(n), [n]), d = g(
|
|
25
|
+
async (l) => {
|
|
26
|
+
if (!t) throw new Error("Client not available");
|
|
27
|
+
if (!r.address || !r.paymentAddress)
|
|
28
|
+
throw new Error("Wallet not connected");
|
|
29
|
+
return t.createTransaction({
|
|
30
|
+
address: r.address,
|
|
31
|
+
paymentAddress: r.paymentAddress,
|
|
32
|
+
feeRate: l?.feeRate,
|
|
33
|
+
mergeSelfRuneBtcOutputs: l?.mergeSelfRuneBtcOutputs
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
[t, r]
|
|
37
|
+
), o = w(
|
|
38
|
+
() => ({
|
|
39
|
+
client: t,
|
|
40
|
+
...r,
|
|
41
|
+
exchange: t.exchange,
|
|
42
|
+
updateWallet: s,
|
|
43
|
+
createTransaction: d
|
|
44
|
+
}),
|
|
45
|
+
[t, r, s, d]
|
|
46
|
+
);
|
|
47
|
+
return /* @__PURE__ */ x(v.Provider, { value: o, children: e });
|
|
48
|
+
}
|
|
49
|
+
function m() {
|
|
50
|
+
const e = P(v);
|
|
51
|
+
if (!e)
|
|
52
|
+
throw new Error("useRee must be used within ReeProvider");
|
|
53
|
+
return e;
|
|
54
|
+
}
|
|
55
|
+
function b(e = {}) {
|
|
56
|
+
const { refreshInterval: n = 0, autoRefresh: r = !0 } = e, { client: a, paymentAddress: s } = m(), [t, d] = u(null), [o, l] = u(!1), [f, h] = u(null), c = g(async () => {
|
|
57
|
+
if (!s) {
|
|
58
|
+
d(null), h("Payment address not set");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
l(!0), h(null);
|
|
62
|
+
try {
|
|
63
|
+
const i = await a.getBtcBalance(s);
|
|
64
|
+
d(i);
|
|
65
|
+
} catch (i) {
|
|
66
|
+
h(
|
|
67
|
+
i instanceof Error ? i.message : "Failed to fetch BTC balance"
|
|
68
|
+
), d(null);
|
|
69
|
+
} finally {
|
|
70
|
+
l(!1);
|
|
71
|
+
}
|
|
72
|
+
}, [a, s]);
|
|
73
|
+
return y(() => {
|
|
74
|
+
r && c();
|
|
75
|
+
}, [s, c, r]), y(() => {
|
|
76
|
+
if (n > 0) {
|
|
77
|
+
const i = setInterval(c, n);
|
|
78
|
+
return () => clearInterval(i);
|
|
79
|
+
}
|
|
80
|
+
}, [n, s, c]), {
|
|
81
|
+
balance: t,
|
|
82
|
+
loading: o,
|
|
83
|
+
error: f,
|
|
84
|
+
refetch: c
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function L(e, n = {}) {
|
|
88
|
+
const { refreshInterval: r = 0, autoRefresh: a = !0 } = n, { client: s, address: t } = m(), [d, o] = u(null), [l, f] = u(!1), [h, c] = u(null), i = g(async () => {
|
|
89
|
+
if (!t) {
|
|
90
|
+
o(null), c("Address not set");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (!e) {
|
|
94
|
+
o(null), c("Rune ID is required");
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
f(!0), c(null);
|
|
98
|
+
try {
|
|
99
|
+
const R = await s.getRuneBalance(t, e);
|
|
100
|
+
o(R ?? null);
|
|
101
|
+
} catch (R) {
|
|
102
|
+
c(
|
|
103
|
+
R instanceof Error ? R.message : "Failed to fetch rune balance"
|
|
104
|
+
), o(null);
|
|
105
|
+
} finally {
|
|
106
|
+
f(!1);
|
|
107
|
+
}
|
|
108
|
+
}, [s, t, e]);
|
|
109
|
+
return y(() => {
|
|
110
|
+
a && e && i();
|
|
111
|
+
}, [t, e, i, a]), y(() => {
|
|
112
|
+
if (r > 0 && e) {
|
|
113
|
+
const R = setInterval(i, r);
|
|
114
|
+
return () => clearInterval(R);
|
|
115
|
+
}
|
|
116
|
+
}, [r, t, e, i]), {
|
|
117
|
+
balance: d,
|
|
118
|
+
loading: l,
|
|
119
|
+
error: h,
|
|
120
|
+
refetch: i
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function q(e = {}) {
|
|
124
|
+
const { refreshInterval: n = 0, autoRefresh: r = !0 } = e, { client: a, paymentAddress: s } = m(), [t, d] = u([]), [o, l] = u(!1), [f, h] = u(null), c = g(async () => {
|
|
125
|
+
if (!s) {
|
|
126
|
+
d([]), h("Payment address not set");
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
l(!0), h(null);
|
|
130
|
+
try {
|
|
131
|
+
const i = await a.getBtcUtxos(s);
|
|
132
|
+
d(i);
|
|
133
|
+
} catch (i) {
|
|
134
|
+
h(
|
|
135
|
+
i instanceof Error ? i.message : "Failed to fetch BTC UTXOs"
|
|
136
|
+
), d([]);
|
|
137
|
+
} finally {
|
|
138
|
+
l(!1);
|
|
139
|
+
}
|
|
140
|
+
}, [a, s]);
|
|
141
|
+
return y(() => {
|
|
142
|
+
r && s && c();
|
|
143
|
+
}, [s, c, r]), y(() => {
|
|
144
|
+
if (n > 0 && s) {
|
|
145
|
+
const i = setInterval(c, n);
|
|
146
|
+
return () => clearInterval(i);
|
|
147
|
+
}
|
|
148
|
+
}, [n, s, c]), {
|
|
149
|
+
utxos: t,
|
|
150
|
+
loading: o,
|
|
151
|
+
error: f,
|
|
152
|
+
refetch: c
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function C(e, n = {}) {
|
|
156
|
+
const { refreshInterval: r = 0, autoRefresh: a = !0 } = n, { client: s, address: t } = m(), [d, o] = u([]), [l, f] = u(!1), [h, c] = u(null), i = g(async () => {
|
|
157
|
+
if (!t) {
|
|
158
|
+
o([]), c("Address not set");
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (!e) {
|
|
162
|
+
o([]), c("Rune ID is required");
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
f(!0), c(null);
|
|
166
|
+
try {
|
|
167
|
+
const R = await s.getRuneUtxos(t, e);
|
|
168
|
+
o(R);
|
|
169
|
+
} catch (R) {
|
|
170
|
+
c(
|
|
171
|
+
R instanceof Error ? R.message : "Failed to fetch rune UTXOs"
|
|
172
|
+
), o([]);
|
|
173
|
+
} finally {
|
|
174
|
+
f(!1);
|
|
175
|
+
}
|
|
176
|
+
}, [s, t, e]);
|
|
177
|
+
return y(() => {
|
|
178
|
+
a && t && e && i();
|
|
179
|
+
}, [t, e, i, a]), y(() => {
|
|
180
|
+
if (r > 0 && t && e) {
|
|
181
|
+
const R = setInterval(i, r);
|
|
182
|
+
return () => clearInterval(R);
|
|
183
|
+
}
|
|
184
|
+
}, [r, t, e, i]), {
|
|
185
|
+
utxos: d,
|
|
186
|
+
loading: l,
|
|
187
|
+
error: h,
|
|
188
|
+
refetch: i
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function A() {
|
|
192
|
+
const { client: e } = m();
|
|
193
|
+
return g(
|
|
194
|
+
async (r) => {
|
|
195
|
+
const a = r;
|
|
196
|
+
if (!a)
|
|
197
|
+
throw new Error("Search keyword is required");
|
|
198
|
+
return await e.searchRunes(a);
|
|
199
|
+
},
|
|
200
|
+
[e]
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
function T(e) {
|
|
204
|
+
const { client: n } = m(), [r, a] = u(null), [s, t] = u(!1), [d, o] = u(null), l = g(async () => {
|
|
205
|
+
if (!e) {
|
|
206
|
+
a(null), o("Rune ID is required");
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
t(!0), o(null);
|
|
210
|
+
try {
|
|
211
|
+
const f = await n.getRuneInfo(e);
|
|
212
|
+
a(f || null);
|
|
213
|
+
} catch (f) {
|
|
214
|
+
o(
|
|
215
|
+
f instanceof Error ? f.message : "Failed to fetch rune info"
|
|
216
|
+
), a(null);
|
|
217
|
+
} finally {
|
|
218
|
+
t(!1);
|
|
219
|
+
}
|
|
220
|
+
}, [n, e]);
|
|
221
|
+
return {
|
|
222
|
+
runeInfo: r,
|
|
223
|
+
loading: s,
|
|
224
|
+
error: d,
|
|
225
|
+
refetch: l
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function k() {
|
|
229
|
+
const { client: e } = m(), [n, r] = u([]), [a, s] = u(!1), [t, d] = u(null), o = g(async () => {
|
|
230
|
+
s(!0), d(null);
|
|
231
|
+
try {
|
|
232
|
+
const l = await e.getPoolList();
|
|
233
|
+
r(l);
|
|
234
|
+
} catch (l) {
|
|
235
|
+
d(
|
|
236
|
+
l instanceof Error ? l.message : "Failed to fetch pool list"
|
|
237
|
+
), r([]);
|
|
238
|
+
} finally {
|
|
239
|
+
s(!1);
|
|
240
|
+
}
|
|
241
|
+
}, [e]);
|
|
242
|
+
return y(() => {
|
|
243
|
+
o();
|
|
244
|
+
}, [o]), {
|
|
245
|
+
pools: n,
|
|
246
|
+
loading: a,
|
|
247
|
+
error: t,
|
|
248
|
+
refetch: o
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function S(e) {
|
|
252
|
+
const { client: n } = m(), [r, a] = u(null), [s, t] = u(!1), [d, o] = u(null), l = g(async () => {
|
|
253
|
+
if (!e) {
|
|
254
|
+
a(null), o("Pool address is required");
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
t(!0), o(null);
|
|
258
|
+
try {
|
|
259
|
+
const f = await n.getPoolInfo(e);
|
|
260
|
+
a(f);
|
|
261
|
+
} catch (f) {
|
|
262
|
+
o(
|
|
263
|
+
f instanceof Error ? f.message : "Failed to fetch pool info"
|
|
264
|
+
), a(null);
|
|
265
|
+
} finally {
|
|
266
|
+
t(!1);
|
|
267
|
+
}
|
|
268
|
+
}, [n, e]);
|
|
269
|
+
return y(() => {
|
|
270
|
+
l();
|
|
271
|
+
}, [e]), {
|
|
272
|
+
poolInfo: r,
|
|
273
|
+
loading: s,
|
|
274
|
+
error: d,
|
|
275
|
+
refetch: l
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function K(e = {}) {
|
|
279
|
+
const { refreshInterval: n = 0, autoRefresh: r = !0 } = e, { client: a } = m(), [s, t] = u(
|
|
280
|
+
null
|
|
281
|
+
), [d, o] = u(!1), [l, f] = u(null), h = g(async () => {
|
|
282
|
+
o(!0), f(null);
|
|
283
|
+
try {
|
|
284
|
+
const c = await a.getRecommendedFeeRate();
|
|
285
|
+
t(c);
|
|
286
|
+
} catch (c) {
|
|
287
|
+
f(
|
|
288
|
+
c instanceof Error ? c.message : "Failed to fetch recommended fee rate"
|
|
289
|
+
), t(null);
|
|
290
|
+
} finally {
|
|
291
|
+
o(!1);
|
|
292
|
+
}
|
|
293
|
+
}, [a]);
|
|
294
|
+
return y(() => {
|
|
295
|
+
r && h();
|
|
296
|
+
}, [r, h]), y(() => {
|
|
297
|
+
if (n > 0) {
|
|
298
|
+
const c = setInterval(h, n);
|
|
299
|
+
return () => clearInterval(c);
|
|
300
|
+
}
|
|
301
|
+
}, [n, h]), {
|
|
302
|
+
feeRate: s,
|
|
303
|
+
loading: d,
|
|
304
|
+
error: l,
|
|
305
|
+
refetch: h
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
export {
|
|
309
|
+
W as Network,
|
|
310
|
+
U as ReeProvider,
|
|
311
|
+
b as useBtcBalance,
|
|
312
|
+
q as useBtcUtxos,
|
|
313
|
+
S as usePoolInfo,
|
|
314
|
+
k as usePoolList,
|
|
315
|
+
K as useRecommendedFeeRate,
|
|
316
|
+
m as useRee,
|
|
317
|
+
L as useRuneBalance,
|
|
318
|
+
T as useRuneInfo,
|
|
319
|
+
C as useRuneUtxos,
|
|
320
|
+
A as useSearchRunes,
|
|
321
|
+
X as utils
|
|
322
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnity/ree-client-ts-sdk",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "A TypeScript SDK for interacting with the Ree protocol on Bitcoin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bitcoin",
|
|
@@ -25,14 +25,24 @@
|
|
|
25
25
|
"README.md",
|
|
26
26
|
"LICENSE"
|
|
27
27
|
],
|
|
28
|
-
"main": "./dist/
|
|
29
|
-
"module": "./dist/
|
|
28
|
+
"main": "./dist/index.cjs.js",
|
|
29
|
+
"module": "./dist/index.es.js",
|
|
30
30
|
"types": "./dist/index.d.ts",
|
|
31
31
|
"exports": {
|
|
32
32
|
".": {
|
|
33
33
|
"types": "./dist/index.d.ts",
|
|
34
|
-
"import": "./dist/
|
|
35
|
-
"require": "./dist/
|
|
34
|
+
"import": "./dist/index.es.js",
|
|
35
|
+
"require": "./dist/index.cjs.js"
|
|
36
|
+
},
|
|
37
|
+
"./react": {
|
|
38
|
+
"types": "./dist/react.d.ts",
|
|
39
|
+
"import": "./dist/react.es.js",
|
|
40
|
+
"require": "./dist/react.cjs.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"typesVersions": {
|
|
44
|
+
"*": {
|
|
45
|
+
"react": ["./dist/react.d.ts"]
|
|
36
46
|
}
|
|
37
47
|
},
|
|
38
48
|
"peerDependencies": {
|