@omnity/ree-client-ts-sdk 0.7.9 → 0.8.1
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/index.cjs.js +21 -21
- package/dist/index.d.ts +3 -1
- package/dist/index.es.js +2978 -2930
- package/dist/react.cjs.js +1 -1
- package/dist/react.d.ts +3 -1
- package/dist/react.es.js +31 -30
- package/package.json +1 -1
package/dist/react.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),e=require("react"),m=require("./index.cjs.js"),v=e.createContext(null);function w({children:t,config:o}){if(!o)throw new Error("ReeProvider: config is required");if(!o.network)throw new Error("ReeProvider: config.network is required");if(!o.xverseApiKey)throw new Error("ReeProvider: config.xverseApiKey is required");if(!o.exchangeIdlFactory)throw new Error("ReeProvider: config.exchangeIdlFactory is required");if(!o.exchangeCanisterId)throw new Error("ReeProvider: config.exchangeCanisterId is required");const[r,i]=e.useState({address:"",paymentAddress:"",publicKey:"",paymentPublicKey:""}),s=e.useCallback(a=>{i(d=>({...d,...a}))},[]),n=e.useMemo(()=>new m.ReeClient(o),[o]),f=e.useCallback(async a=>{if(!n)throw new Error("Client not available");if(!r.address||!r.paymentAddress)throw new Error("Wallet not connected");return n.createTransaction({address:r.address,paymentAddress:r.paymentAddress,feeRate:a?.feeRate,publicKey:r.publicKey,paymentPublicKey:r.paymentPublicKey,mergeSelfRuneBtcOutputs:a?.mergeSelfRuneBtcOutputs,clientInfo:a?.clientInfo,manualBuild:a?.manualBuild})},[n,r]),u=e.useMemo(()=>({client:n,...r,exchange:n.exchange,updateWallet:s,createTransaction:f}),[n,r,s,f]);return E.jsx(v.Provider,{value:u,children:t})}function R(){const t=e.useContext(v);if(!t)throw new Error("useRee must be used within ReeProvider");return t}function x(t={}){const{refreshInterval:o=0,autoRefresh:r=!0}=t,{client:i,paymentAddress:s}=R(),[n,f]=e.useState(null),[u,a]=e.useState(!1),[d,h]=e.useState(null),l=e.useCallback(async()=>{if(!s){f(null),h("Payment address not set");return}a(!0),h(null);try{const c=await i.getBtcBalance(s);f(c)}catch(c){h(c instanceof Error?c.message:"Failed to fetch BTC balance"),f(null)}finally{a(!1)}},[i,s]);return e.useEffect(()=>{r&&l()},[s,l,r]),e.useEffect(()=>{if(o>0){const c=setInterval(l,o);return()=>clearInterval(c)}},[o,s,l]),{balance:n,loading:u,error:d,refetch:l}}function b(t,o={}){const{refreshInterval:r=0,autoRefresh:i=!0}=o,{client:s,address:n,publicKey:f}=R(),[u,a]=e.useState(null),[d,h]=e.useState(!1),[l,c]=e.useState(null),y=e.useCallback(async()=>{if(!n){a(null),c("Address not set");return}if(!t){a(null),c("Rune ID is required");return}h(!0),c(null);try{const g=await s.getRuneBalance(n,t,f);a(g??null)}catch(g){c(g instanceof Error?g.message:"Failed to fetch rune balance"),a(null)}finally{h(!1)}},[s,n,t]);return e.useEffect(()=>{i&&t&&y()},[n,t,y,i]),e.useEffect(()=>{if(r>0&&t){const g=setInterval(y,r);return()=>clearInterval(g)}},[r,n,t,y]),{balance:u,loading:d,error:l,refetch:y}}function P(t={}){const{refreshInterval:o=0,autoRefresh:r=!0}=t,{client:i,paymentAddress:s}=R(),[n,f]=e.useState([]),[u,a]=e.useState(!1),[d,h]=e.useState(null),l=e.useCallback(async()=>{if(!s){f([]),h("Payment address not set");return}a(!0),h(null);try{const c=await i.getBtcUtxos(s);f(c)}catch(c){h(c instanceof Error?c.message:"Failed to fetch BTC UTXOs"),f([])}finally{a(!1)}},[i,s]);return e.useEffect(()=>{r&&s&&l()},[s,l,r]),e.useEffect(()=>{if(o>0&&s){const c=setInterval(l,o);return()=>clearInterval(c)}},[o,s,l]),{utxos:n,loading:u,error:d,refetch:l}}function S(t,o={}){const{refreshInterval:r=0,autoRefresh:i=!0}=o,{client:s,address:n}=R(),[f,u]=e.useState([]),[a,d]=e.useState(!1),[h,l]=e.useState(null),c=e.useCallback(async()=>{if(!n){u([]),l("Address not set");return}if(!t){u([]),l("Rune ID is required");return}d(!0),l(null);try{const y=await s.getRuneUtxos(n,t);u(y)}catch(y){l(y instanceof Error?y.message:"Failed to fetch rune UTXOs"),u([])}finally{d(!1)}},[s,n,t]);return e.useEffect(()=>{i&&n&&t&&c()},[n,t,c,i]),e.useEffect(()=>{if(r>0&&n&&t){const y=setInterval(c,r);return()=>clearInterval(y)}},[r,n,t,c]),{utxos:f,loading:a,error:h,refetch:c}}function B(){const{client:t}=R(),[o,r]=e.useState([]),[i,s]=e.useState(!1),[n,f]=e.useState(null),u=e.useCallback(async()=>{s(!0),f(null);try{const a=await t.getPoolList();r(a)}catch(a){f(a instanceof Error?a.message:"Failed to fetch pool list"),r([])}finally{s(!1)}},[t]);return e.useEffect(()=>{u()},[u]),{pools:o,loading:i,error:n,refetch:u}}function p(t){const{client:o}=R(),[r,i]=e.useState(null),[s,n]=e.useState(!1),[f,u]=e.useState(null),a=e.useCallback(async()=>{if(!t){i(null),u("Pool address is required");return}n(!0),u(null);try{const d=await o.getPoolInfo(t);i(d)}catch(d){u(d instanceof Error?d.message:"Failed to fetch pool info"),i(null)}finally{n(!1)}},[o,t]);return e.useEffect(()=>{a()},[t]),{poolInfo:r,loading:s,error:f,refetch:a}}function C(t={}){const{refreshInterval:o=0,autoRefresh:r=!0}=t,{client:i}=R(),[s,n]=e.useState(null),[f,u]=e.useState(!1),[a,d]=e.useState(null),h=e.useCallback(async()=>{u(!0),d(null);try{const l=await i.getRecommendedFeeRate();n(l)}catch(l){d(l instanceof Error?l.message:"Failed to fetch recommended fee rate"),n(null)}finally{u(!1)}},[i]);return e.useEffect(()=>{r&&h()},[r,h]),e.useEffect(()=>{if(o>0){const l=setInterval(h,o);return()=>clearInterval(l)}},[o,h]),{feeRate:s,loading:f,error:a,refetch:h}}exports.Network=m.Network;exports.utils=m.utils;exports.ReeProvider=w;exports.useBtcBalance=x;exports.useBtcUtxos=P;exports.usePoolInfo=p;exports.usePoolList=B;exports.useRecommendedFeeRate=C;exports.useRee=R;exports.useRuneBalance=b;exports.useRuneUtxos=S;
|
package/dist/react.d.ts
CHANGED
|
@@ -208,10 +208,11 @@ declare class ReeClient {
|
|
|
208
208
|
* @param params.involvedRuneId - Optional rune ID for rune swaps
|
|
209
209
|
* @returns Transaction instance
|
|
210
210
|
*/
|
|
211
|
-
createTransaction({ address, paymentAddress, publicKey, feeRate, mergeSelfRuneBtcOutputs, clientInfo, manualBuild, }: {
|
|
211
|
+
createTransaction({ address, paymentAddress, publicKey, paymentPublicKey, feeRate, mergeSelfRuneBtcOutputs, clientInfo, manualBuild, }: {
|
|
212
212
|
address: string;
|
|
213
213
|
paymentAddress: string;
|
|
214
214
|
publicKey?: string;
|
|
215
|
+
paymentPublicKey?: string;
|
|
215
216
|
feeRate?: number;
|
|
216
217
|
mergeSelfRuneBtcOutputs?: boolean;
|
|
217
218
|
clientInfo?: string;
|
|
@@ -485,6 +486,7 @@ declare interface TransactionConfig {
|
|
|
485
486
|
address: string;
|
|
486
487
|
paymentAddress: string;
|
|
487
488
|
publicKey?: string;
|
|
489
|
+
paymentPublicKey?: string;
|
|
488
490
|
clientInfo?: string;
|
|
489
491
|
/** Optional manual fee rate in satoshis per virtual byte */
|
|
490
492
|
feeRate?: number;
|
package/dist/react.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as E } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as p, useState as u, useCallback as
|
|
3
|
-
import { ReeClient as
|
|
2
|
+
import { createContext as p, useState as u, useCallback as g, useMemo as w, useContext as P, useEffect as m } from "react";
|
|
3
|
+
import { ReeClient as B } from "./index.es.js";
|
|
4
4
|
import { Network as W, utils as D } from "./index.es.js";
|
|
5
5
|
const x = p(null);
|
|
6
6
|
function U({ children: e, config: o }) {
|
|
@@ -19,9 +19,9 @@ function U({ children: e, config: o }) {
|
|
|
19
19
|
paymentAddress: "",
|
|
20
20
|
publicKey: "",
|
|
21
21
|
paymentPublicKey: ""
|
|
22
|
-
}), n =
|
|
22
|
+
}), n = g((s) => {
|
|
23
23
|
i((d) => ({ ...d, ...s }));
|
|
24
|
-
}, []), t = w(() => new
|
|
24
|
+
}, []), t = w(() => new B(o), [o]), f = g(
|
|
25
25
|
async (s) => {
|
|
26
26
|
if (!t) throw new Error("Client not available");
|
|
27
27
|
if (!r.address || !r.paymentAddress)
|
|
@@ -31,6 +31,7 @@ function U({ children: e, config: o }) {
|
|
|
31
31
|
paymentAddress: r.paymentAddress,
|
|
32
32
|
feeRate: s?.feeRate,
|
|
33
33
|
publicKey: r.publicKey,
|
|
34
|
+
paymentPublicKey: r.paymentPublicKey,
|
|
34
35
|
mergeSelfRuneBtcOutputs: s?.mergeSelfRuneBtcOutputs,
|
|
35
36
|
clientInfo: s?.clientInfo,
|
|
36
37
|
manualBuild: s?.manualBuild
|
|
@@ -50,13 +51,13 @@ function U({ children: e, config: o }) {
|
|
|
50
51
|
return /* @__PURE__ */ E(x.Provider, { value: c, children: e });
|
|
51
52
|
}
|
|
52
53
|
function R() {
|
|
53
|
-
const e =
|
|
54
|
+
const e = P(x);
|
|
54
55
|
if (!e)
|
|
55
56
|
throw new Error("useRee must be used within ReeProvider");
|
|
56
57
|
return e;
|
|
57
58
|
}
|
|
58
59
|
function C(e = {}) {
|
|
59
|
-
const { refreshInterval: o = 0, autoRefresh: r = !0 } = e, { client: i, paymentAddress: n } = R(), [t, f] = u(null), [c, s] = u(!1), [d, h] = u(null), a =
|
|
60
|
+
const { refreshInterval: o = 0, autoRefresh: r = !0 } = e, { client: i, paymentAddress: n } = R(), [t, f] = u(null), [c, s] = u(!1), [d, h] = u(null), a = g(async () => {
|
|
60
61
|
if (!n) {
|
|
61
62
|
f(null), h("Payment address not set");
|
|
62
63
|
return;
|
|
@@ -73,9 +74,9 @@ function C(e = {}) {
|
|
|
73
74
|
s(!1);
|
|
74
75
|
}
|
|
75
76
|
}, [i, n]);
|
|
76
|
-
return
|
|
77
|
+
return m(() => {
|
|
77
78
|
r && a();
|
|
78
|
-
}, [n, a, r]),
|
|
79
|
+
}, [n, a, r]), m(() => {
|
|
79
80
|
if (o > 0) {
|
|
80
81
|
const l = setInterval(a, o);
|
|
81
82
|
return () => clearInterval(l);
|
|
@@ -88,7 +89,7 @@ function C(e = {}) {
|
|
|
88
89
|
};
|
|
89
90
|
}
|
|
90
91
|
function L(e, o = {}) {
|
|
91
|
-
const { refreshInterval: r = 0, autoRefresh: i = !0 } = o, { client: n, address: t, publicKey: f } = R(), [c, s] = u(null), [d, h] = u(!1), [a, l] = u(null), y =
|
|
92
|
+
const { refreshInterval: r = 0, autoRefresh: i = !0 } = o, { client: n, address: t, publicKey: f } = R(), [c, s] = u(null), [d, h] = u(!1), [a, l] = u(null), y = g(async () => {
|
|
92
93
|
if (!t) {
|
|
93
94
|
s(null), l("Address not set");
|
|
94
95
|
return;
|
|
@@ -113,9 +114,9 @@ function L(e, o = {}) {
|
|
|
113
114
|
h(!1);
|
|
114
115
|
}
|
|
115
116
|
}, [n, t, e]);
|
|
116
|
-
return
|
|
117
|
+
return m(() => {
|
|
117
118
|
i && e && y();
|
|
118
|
-
}, [t, e, y, i]),
|
|
119
|
+
}, [t, e, y, i]), m(() => {
|
|
119
120
|
if (r > 0 && e) {
|
|
120
121
|
const v = setInterval(y, r);
|
|
121
122
|
return () => clearInterval(v);
|
|
@@ -127,8 +128,8 @@ function L(e, o = {}) {
|
|
|
127
128
|
refetch: y
|
|
128
129
|
};
|
|
129
130
|
}
|
|
130
|
-
function
|
|
131
|
-
const { refreshInterval: o = 0, autoRefresh: r = !0 } = e, { client: i, paymentAddress: n } = R(), [t, f] = u([]), [c, s] = u(!1), [d, h] = u(null), a =
|
|
131
|
+
function K(e = {}) {
|
|
132
|
+
const { refreshInterval: o = 0, autoRefresh: r = !0 } = e, { client: i, paymentAddress: n } = R(), [t, f] = u([]), [c, s] = u(!1), [d, h] = u(null), a = g(async () => {
|
|
132
133
|
if (!n) {
|
|
133
134
|
f([]), h("Payment address not set");
|
|
134
135
|
return;
|
|
@@ -145,9 +146,9 @@ function q(e = {}) {
|
|
|
145
146
|
s(!1);
|
|
146
147
|
}
|
|
147
148
|
}, [i, n]);
|
|
148
|
-
return
|
|
149
|
+
return m(() => {
|
|
149
150
|
r && n && a();
|
|
150
|
-
}, [n, a, r]),
|
|
151
|
+
}, [n, a, r]), m(() => {
|
|
151
152
|
if (o > 0 && n) {
|
|
152
153
|
const l = setInterval(a, o);
|
|
153
154
|
return () => clearInterval(l);
|
|
@@ -159,8 +160,8 @@ function q(e = {}) {
|
|
|
159
160
|
refetch: a
|
|
160
161
|
};
|
|
161
162
|
}
|
|
162
|
-
function
|
|
163
|
-
const { refreshInterval: r = 0, autoRefresh: i = !0 } = o, { client: n, address: t } = R(), [f, c] = u([]), [s, d] = u(!1), [h, a] = u(null), l =
|
|
163
|
+
function q(e, o = {}) {
|
|
164
|
+
const { refreshInterval: r = 0, autoRefresh: i = !0 } = o, { client: n, address: t } = R(), [f, c] = u([]), [s, d] = u(!1), [h, a] = u(null), l = g(async () => {
|
|
164
165
|
if (!t) {
|
|
165
166
|
c([]), a("Address not set");
|
|
166
167
|
return;
|
|
@@ -181,9 +182,9 @@ function A(e, o = {}) {
|
|
|
181
182
|
d(!1);
|
|
182
183
|
}
|
|
183
184
|
}, [n, t, e]);
|
|
184
|
-
return
|
|
185
|
+
return m(() => {
|
|
185
186
|
i && t && e && l();
|
|
186
|
-
}, [t, e, l, i]),
|
|
187
|
+
}, [t, e, l, i]), m(() => {
|
|
187
188
|
if (r > 0 && t && e) {
|
|
188
189
|
const y = setInterval(l, r);
|
|
189
190
|
return () => clearInterval(y);
|
|
@@ -195,8 +196,8 @@ function A(e, o = {}) {
|
|
|
195
196
|
refetch: l
|
|
196
197
|
};
|
|
197
198
|
}
|
|
198
|
-
function
|
|
199
|
-
const { client: e } = R(), [o, r] = u([]), [i, n] = u(!1), [t, f] = u(null), c =
|
|
199
|
+
function A() {
|
|
200
|
+
const { client: e } = R(), [o, r] = u([]), [i, n] = u(!1), [t, f] = u(null), c = g(async () => {
|
|
200
201
|
n(!0), f(null);
|
|
201
202
|
try {
|
|
202
203
|
const s = await e.getPoolList();
|
|
@@ -209,7 +210,7 @@ function K() {
|
|
|
209
210
|
n(!1);
|
|
210
211
|
}
|
|
211
212
|
}, [e]);
|
|
212
|
-
return
|
|
213
|
+
return m(() => {
|
|
213
214
|
c();
|
|
214
215
|
}, [c]), {
|
|
215
216
|
pools: o,
|
|
@@ -219,7 +220,7 @@ function K() {
|
|
|
219
220
|
};
|
|
220
221
|
}
|
|
221
222
|
function T(e) {
|
|
222
|
-
const { client: o } = R(), [r, i] = u(null), [n, t] = u(!1), [f, c] = u(null), s =
|
|
223
|
+
const { client: o } = R(), [r, i] = u(null), [n, t] = u(!1), [f, c] = u(null), s = g(async () => {
|
|
223
224
|
if (!e) {
|
|
224
225
|
i(null), c("Pool address is required");
|
|
225
226
|
return;
|
|
@@ -236,7 +237,7 @@ function T(e) {
|
|
|
236
237
|
t(!1);
|
|
237
238
|
}
|
|
238
239
|
}, [o, e]);
|
|
239
|
-
return
|
|
240
|
+
return m(() => {
|
|
240
241
|
s();
|
|
241
242
|
}, [e]), {
|
|
242
243
|
poolInfo: r,
|
|
@@ -248,7 +249,7 @@ function T(e) {
|
|
|
248
249
|
function k(e = {}) {
|
|
249
250
|
const { refreshInterval: o = 0, autoRefresh: r = !0 } = e, { client: i } = R(), [n, t] = u(
|
|
250
251
|
null
|
|
251
|
-
), [f, c] = u(!1), [s, d] = u(null), h =
|
|
252
|
+
), [f, c] = u(!1), [s, d] = u(null), h = g(async () => {
|
|
252
253
|
c(!0), d(null);
|
|
253
254
|
try {
|
|
254
255
|
const a = await i.getRecommendedFeeRate();
|
|
@@ -261,9 +262,9 @@ function k(e = {}) {
|
|
|
261
262
|
c(!1);
|
|
262
263
|
}
|
|
263
264
|
}, [i]);
|
|
264
|
-
return
|
|
265
|
+
return m(() => {
|
|
265
266
|
r && h();
|
|
266
|
-
}, [r, h]),
|
|
267
|
+
}, [r, h]), m(() => {
|
|
267
268
|
if (o > 0) {
|
|
268
269
|
const a = setInterval(h, o);
|
|
269
270
|
return () => clearInterval(a);
|
|
@@ -279,12 +280,12 @@ export {
|
|
|
279
280
|
W as Network,
|
|
280
281
|
U as ReeProvider,
|
|
281
282
|
C as useBtcBalance,
|
|
282
|
-
|
|
283
|
+
K as useBtcUtxos,
|
|
283
284
|
T as usePoolInfo,
|
|
284
|
-
|
|
285
|
+
A as usePoolList,
|
|
285
286
|
k as useRecommendedFeeRate,
|
|
286
287
|
R as useRee,
|
|
287
288
|
L as useRuneBalance,
|
|
288
|
-
|
|
289
|
+
q as useRuneUtxos,
|
|
289
290
|
D as utils
|
|
290
291
|
};
|