@gardenfi/react-hooks 2.5.3 → 3.0.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/index2.cjs +1 -1
- package/dist/index2.js +71 -115
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +136 -11
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +4 -2
- package/dist/index5.cjs +1 -1
- package/dist/index5.js +32 -26
- package/dist/index6.cjs +1 -1
- package/dist/index6.js +4 -3
- package/dist/src/lib/constants.d.ts +1 -0
- package/dist/src/lib/context/gardenProvider.types.d.ts +13 -6
- package/dist/src/lib/hooks/useDigestKey.d.ts +1 -1
- package/dist/src/lib/hooks/useOrderbook.d.ts +2 -1
- package/dist/src/lib/utils.d.ts +2 -2
- package/package.json +4 -4
package/dist/index2.cjs
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 a=require("react"),g=require("./index3.cjs"),d=require("@gardenfi/core"),v=require("./index4.cjs"),k=require("./index5.cjs"),p=require("@gardenfi/utils"),q=require("./index6.cjs"),w=a.createContext({pendingOrders:[]}),E=({children:i,config:e,store:l,setRedeemServiceEnabled:n=!0})=>{const[s,G]=a.useState(),{digestKey:c}=k.useDigestKey(n),{pendingOrders:O}=g.useOrderbook(s,l),h=a.useMemo(()=>{const{api:t}=d.resolveApiConfig(e.environment);return e.quote??new d.Quote(t.baseurl,v.resolveAuth(e.apiKey))},[e.environment,e.quote,e.apiKey]),_=a.useMemo(()=>async({fromAsset:t,toAsset:r,amount:u,isExactOut:o=!1,options:y})=>await(s?s.quote:h).getQuoteFromAssets({fromAsset:t,toAsset:r,amount:u,isExactOut:o,options:y}),[s,h]),m=async t=>{if(!s)return p.Err("Garden not initialized");const r=await s.createSwap(t);if(!r.val)return p.Err(r.error||"Unknown error occurred");if(n)try{const u=l.getItem(q.PENDING_ORDERS_STORE),o=u?JSON.parse(u):[];typeof r.val=="string"?o.includes(r.val)||o.push(r.val):r.val&&typeof r.val.order_id=="string"&&(o.includes(r.val.order_id)||o.push(r.val.order_id));const y=Array.from(new Set(o));l.setItem(q.PENDING_ORDERS_STORE,JSON.stringify(y))}catch(u){console.error("Failed to persist pending order id",u)}return p.Ok(r.val)};return a.useEffect(()=>{if(!("wallets"in e)&&!("htlc"in e))return;let t;if("wallets"in e&&Object.keys(e.wallets??{}).length>0&&v.hasAnyValidValue(e.wallets??{}))t=d.Garden.fromWallets({...e,digestKey:n?void 0:c}).setRedeemServiceEnabled(n);else if("htlc"in e&&Object.keys(e.htlc??{}).length>0&&v.hasAnyValidValue(e.htlc??{}))t=new d.Garden({...e,digestKey:n?void 0:c}).setRedeemServiceEnabled(n);else return;G(t)},[e,c,n]),a.createElement(w.Provider,{value:{swap:m,pendingOrders:O,getQuote:_,garden:s,orderBook:s}},i)},K=()=>{const i=a.useContext(w);if(!i)throw new Error("useGarden must be used within a GardenProvider");return i};exports.GardenContext=w;exports.GardenProvider=E;exports.useGarden=K;
|
package/dist/index2.js
CHANGED
|
@@ -1,132 +1,88 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useOrderbook as
|
|
3
|
-
import { resolveApiConfig as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
const
|
|
1
|
+
import h, { useState as k, useMemo as m, useEffect as K, createContext as x } from "react";
|
|
2
|
+
import { useOrderbook as A } from "./index3.js";
|
|
3
|
+
import { resolveApiConfig as g, Quote as C, Garden as c } from "@gardenfi/core";
|
|
4
|
+
import { resolveAuth as I, hasAnyValidValue as y } from "./index4.js";
|
|
5
|
+
import { useDigestKey as N } from "./index5.js";
|
|
6
|
+
import { Err as v, Ok as P } from "@gardenfi/utils";
|
|
7
|
+
import { PENDING_ORDERS_STORE as w } from "./index6.js";
|
|
8
|
+
const f = x({
|
|
9
9
|
pendingOrders: []
|
|
10
|
-
}),
|
|
11
|
-
children:
|
|
12
|
-
config:
|
|
13
|
-
|
|
10
|
+
}), b = ({
|
|
11
|
+
children: i,
|
|
12
|
+
config: e,
|
|
13
|
+
store: u,
|
|
14
|
+
setRedeemServiceEnabled: o = !0
|
|
14
15
|
}) => {
|
|
15
|
-
const [
|
|
16
|
-
const { api:
|
|
17
|
-
return
|
|
18
|
-
}, [
|
|
16
|
+
const [s, O] = k(), { digestKey: l } = N(o), { pendingOrders: G } = A(s, u), p = m(() => {
|
|
17
|
+
const { api: t } = g(e.environment);
|
|
18
|
+
return e.quote ?? new C(t.baseurl, I(e.apiKey));
|
|
19
|
+
}, [e.environment, e.quote, e.apiKey]), q = m(
|
|
19
20
|
() => async ({
|
|
20
|
-
fromAsset:
|
|
21
|
-
toAsset:
|
|
22
|
-
amount:
|
|
23
|
-
isExactOut:
|
|
24
|
-
options:
|
|
25
|
-
}) => await (
|
|
26
|
-
fromAsset:
|
|
27
|
-
toAsset:
|
|
28
|
-
amount:
|
|
29
|
-
isExactOut:
|
|
30
|
-
options:
|
|
21
|
+
fromAsset: t,
|
|
22
|
+
toAsset: r,
|
|
23
|
+
amount: a,
|
|
24
|
+
isExactOut: n = !1,
|
|
25
|
+
options: d
|
|
26
|
+
}) => await (s ? s.quote : p).getQuoteFromAssets({
|
|
27
|
+
fromAsset: t,
|
|
28
|
+
toAsset: r,
|
|
29
|
+
amount: a,
|
|
30
|
+
isExactOut: n,
|
|
31
|
+
options: d
|
|
31
32
|
}),
|
|
32
|
-
[
|
|
33
|
-
),
|
|
34
|
-
if (!
|
|
35
|
-
const
|
|
36
|
-
if (!
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
s = t.val;
|
|
46
|
-
break;
|
|
33
|
+
[s, p]
|
|
34
|
+
), _ = async (t) => {
|
|
35
|
+
if (!s) return v("Garden not initialized");
|
|
36
|
+
const r = await s.createSwap(t);
|
|
37
|
+
if (!r.val) return v(r.error || "Unknown error occurred");
|
|
38
|
+
if (o)
|
|
39
|
+
try {
|
|
40
|
+
const a = u.getItem(w), n = a ? JSON.parse(a) : [];
|
|
41
|
+
typeof r.val == "string" ? n.includes(r.val) || n.push(r.val) : r.val && typeof r.val.order_id == "string" && (n.includes(r.val.order_id) || n.push(r.val.order_id));
|
|
42
|
+
const d = Array.from(new Set(n));
|
|
43
|
+
u.setItem(w, JSON.stringify(d));
|
|
44
|
+
} catch (a) {
|
|
45
|
+
console.error("Failed to persist pending order id", a);
|
|
47
46
|
}
|
|
48
|
-
|
|
49
|
-
if (!e.starknetHTLC)
|
|
50
|
-
return i(
|
|
51
|
-
"Starknet HTLC not initialized: Please provide starknetHTLC"
|
|
52
|
-
);
|
|
53
|
-
const t = await e.starknetHTLC.initiate(a.val);
|
|
54
|
-
if (!t.ok) return i(t.error);
|
|
55
|
-
s = t.val;
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
case l.Solana: {
|
|
59
|
-
if (!e.solanaHTLC)
|
|
60
|
-
return i("Solana HTLC not initialized: Please provide solanaHTLC");
|
|
61
|
-
const t = await e.solanaHTLC.initiate(a.val);
|
|
62
|
-
if (!t.ok) return i(t.error);
|
|
63
|
-
s = t.val;
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
case l.Sui: {
|
|
67
|
-
if (!e.suiHTLC)
|
|
68
|
-
return i("Sui HTLC not initialized: Please provide suiHTLC");
|
|
69
|
-
const t = await e.suiHTLC.initiate(a.val);
|
|
70
|
-
if (!t.ok) return i(t.error);
|
|
71
|
-
s = t.val;
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
case l.Bitcoin:
|
|
75
|
-
s = a.val.source_swap.initiate_tx_hash;
|
|
76
|
-
break;
|
|
77
|
-
default:
|
|
78
|
-
return i("Unsupported chain");
|
|
79
|
-
}
|
|
80
|
-
const c = {
|
|
81
|
-
...a.val,
|
|
82
|
-
source_swap: {
|
|
83
|
-
...a.val.source_swap,
|
|
84
|
-
initiate_tx_hash: s
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
return m(c);
|
|
47
|
+
return P(r.val);
|
|
88
48
|
};
|
|
89
|
-
return
|
|
90
|
-
if (!
|
|
91
|
-
let
|
|
92
|
-
if ("wallets" in
|
|
93
|
-
|
|
94
|
-
...
|
|
95
|
-
digestKey:
|
|
96
|
-
}).
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
digestKey: d
|
|
103
|
-
}).handleSecretManagement(
|
|
104
|
-
o || !1
|
|
105
|
-
);
|
|
49
|
+
return K(() => {
|
|
50
|
+
if (!("wallets" in e) && !("htlc" in e)) return;
|
|
51
|
+
let t;
|
|
52
|
+
if ("wallets" in e && Object.keys(e.wallets ?? {}).length > 0 && y(e.wallets ?? {}))
|
|
53
|
+
t = c.fromWallets({
|
|
54
|
+
...e,
|
|
55
|
+
digestKey: o ? void 0 : l
|
|
56
|
+
}).setRedeemServiceEnabled(o);
|
|
57
|
+
else if ("htlc" in e && Object.keys(e.htlc ?? {}).length > 0 && y(e.htlc ?? {}))
|
|
58
|
+
t = new c({
|
|
59
|
+
...e,
|
|
60
|
+
digestKey: o ? void 0 : l
|
|
61
|
+
}).setRedeemServiceEnabled(o);
|
|
106
62
|
else
|
|
107
63
|
return;
|
|
108
|
-
|
|
109
|
-
}, [
|
|
110
|
-
|
|
64
|
+
O(t);
|
|
65
|
+
}, [e, l, o]), /* @__PURE__ */ h.createElement(
|
|
66
|
+
f.Provider,
|
|
111
67
|
{
|
|
112
68
|
value: {
|
|
113
|
-
|
|
114
|
-
pendingOrders:
|
|
115
|
-
getQuote:
|
|
116
|
-
garden:
|
|
117
|
-
orderBook:
|
|
69
|
+
swap: _,
|
|
70
|
+
pendingOrders: G,
|
|
71
|
+
getQuote: q,
|
|
72
|
+
garden: s,
|
|
73
|
+
orderBook: s
|
|
118
74
|
}
|
|
119
75
|
},
|
|
120
|
-
|
|
76
|
+
i
|
|
121
77
|
);
|
|
122
|
-
},
|
|
123
|
-
const
|
|
124
|
-
if (!
|
|
78
|
+
}, z = () => {
|
|
79
|
+
const i = h.useContext(f);
|
|
80
|
+
if (!i)
|
|
125
81
|
throw new Error("useGarden must be used within a GardenProvider");
|
|
126
|
-
return
|
|
82
|
+
return i;
|
|
127
83
|
};
|
|
128
84
|
export {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
85
|
+
f as GardenContext,
|
|
86
|
+
b as GardenProvider,
|
|
87
|
+
z as useGarden
|
|
132
88
|
};
|
package/dist/index3.cjs
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 h=require("@gardenfi/orderbook"),i=require("react"),R=require("./index6.cjs"),k=(e,u)=>{const[N,y]=i.useState([]),O=i.useRef(null),E=i.useRef(!1),S=i.useRef(!1),T=5e3,m=i.useCallback(()=>{var n,o,f,a,d,s,t,l,c,A;if(!e)return[];const r=new Set;try{[(o=(n=e.htlcs)==null?void 0:n.evm)==null?void 0:o.htlcActorAddress,(a=(f=e.htlcs)==null?void 0:f.sui)==null?void 0:a.htlcActorAddress,(s=(d=e.htlcs)==null?void 0:d.solana)==null?void 0:s.htlcActorAddress,(l=(t=e.htlcs)==null?void 0:t.starknet)==null?void 0:l.htlcActorAddress,(A=(c=e.htlcs)==null?void 0:c.bitcoin)==null?void 0:A.htlcActorAddress].filter(g=>!!g&&g.length>0).forEach(g=>r.add(g.toLowerCase()))}catch(b){console.error("Error getting HTLC addresses:",b)}return Array.from(r)},[e]),C=i.useCallback(async()=>{if(e)try{const r=m();if(r.length===0){console.log("No HTLC addresses found for initial pending orders fetch");return}const n=r.map(async s=>{try{const[t,l]=await Promise.all([e.getOrders({address:s,status:h.OrderLifecycle.pending,per_page:500}),e.getOrders({address:s,status:h.OrderLifecycle.notInitiated,per_page:500})]),c=[];return t.ok?c.push(...t.val.data):console.error(`Failed to fetch pending orders for address ${s}:`,t.error),l.ok?c.push(...l.val.data):console.error(`Failed to fetch notInitiated orders for address ${s}:`,l.error),c}catch(t){return console.error(`Error fetching orders for address ${s}:`,t),[]}}),a=(await Promise.all(n)).flat().map(s=>s.order_id),d=Array.from(new Set(a));if(d.length>0)try{u.setItem(R.PENDING_ORDERS_STORE,JSON.stringify(d))}catch(s){console.error("Error saving initial pending order IDs to localStorage",s)}}catch(r){console.error("Error fetching initial pending orders:",r)}},[e,u,m]),I=i.useCallback(async()=>{if(e)try{const r=u.getItem(R.PENDING_ORDERS_STORE),n=r?JSON.parse(r):[],o=Array.from(new Set(n));if(o.length===0){y([]);return}const f=await Promise.all(o.map(t=>e.getOrder(t))),a=[],d=[];f.forEach((t,l)=>{if(!t.ok){d.push(o[l]);return}const c=t.val;c.status===h.OrderStatus.Redeemed||c.status===h.OrderStatus.Refunded||c.status===h.OrderStatus.Expired||(a.push(c),d.push(o[l]))});const s=Array.from(new Set(d));try{u.setItem(R.PENDING_ORDERS_STORE,JSON.stringify(s))}catch(t){console.error("Error persisting remaining pending order ids",t)}y(a)}catch(r){console.error("Error fetching pending orders:",r)}},[e,u]),p=i.useMemo(()=>{try{return m().join(",")}catch(r){return console.error("Error computing HTLC addresses:",r),""}},[m]),P=i.useRef("");return i.useEffect(()=>{if(!e||!e.redeemServiceEnabled||!p)return;P.current!==p&&(S.current=!1,P.current=p),S.current||(C(),S.current=!0)},[e,p,C]),i.useEffect(()=>{if(e)if(e.redeemServiceEnabled){let r=!1;const n=()=>{r||(O.current=setTimeout(o,T))},o=async()=>{if(!r){if(E.current){n();return}E.current=!0;try{await I()}finally{E.current=!1}n()}};return o(),()=>{r=!0,O.current&&(clearTimeout(O.current),O.current=null)}}else{const r=n=>y(n);return e.on("onPendingOrdersChanged",r),()=>{e.off("onPendingOrdersChanged",r)}}},[e,I]),{pendingOrders:N}};exports.useOrderbook=k;
|
package/dist/index3.js
CHANGED
|
@@ -1,14 +1,139 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { OrderLifecycle as T, OrderStatus as S } from "@gardenfi/orderbook";
|
|
2
|
+
import { useState as k, useRef as g, useCallback as C, useMemo as F, useEffect as L } from "react";
|
|
3
|
+
import { PENDING_ORDERS_STORE as I } from "./index6.js";
|
|
4
|
+
const q = (r, a) => {
|
|
5
|
+
const [N, O] = k([]), f = g(null), y = g(!1), A = g(!1), b = 5e3, h = C(() => {
|
|
6
|
+
var n, o, u, l, i, s, t, d, c, E;
|
|
7
|
+
if (!r) return [];
|
|
8
|
+
const e = /* @__PURE__ */ new Set();
|
|
9
|
+
try {
|
|
10
|
+
[
|
|
11
|
+
(o = (n = r.htlcs) == null ? void 0 : n.evm) == null ? void 0 : o.htlcActorAddress,
|
|
12
|
+
(l = (u = r.htlcs) == null ? void 0 : u.sui) == null ? void 0 : l.htlcActorAddress,
|
|
13
|
+
(s = (i = r.htlcs) == null ? void 0 : i.solana) == null ? void 0 : s.htlcActorAddress,
|
|
14
|
+
(d = (t = r.htlcs) == null ? void 0 : t.starknet) == null ? void 0 : d.htlcActorAddress,
|
|
15
|
+
(E = (c = r.htlcs) == null ? void 0 : c.bitcoin) == null ? void 0 : E.htlcActorAddress
|
|
16
|
+
].filter((p) => !!p && p.length > 0).forEach((p) => e.add(p.toLowerCase()));
|
|
17
|
+
} catch (v) {
|
|
18
|
+
console.error("Error getting HTLC addresses:", v);
|
|
19
|
+
}
|
|
20
|
+
return Array.from(e);
|
|
21
|
+
}, [r]), P = C(async () => {
|
|
22
|
+
if (r)
|
|
23
|
+
try {
|
|
24
|
+
const e = h();
|
|
25
|
+
if (e.length === 0) {
|
|
26
|
+
console.log("No HTLC addresses found for initial pending orders fetch");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const n = e.map(async (s) => {
|
|
30
|
+
try {
|
|
31
|
+
const [t, d] = await Promise.all([
|
|
32
|
+
r.getOrders({
|
|
33
|
+
address: s,
|
|
34
|
+
status: T.pending,
|
|
35
|
+
per_page: 500
|
|
36
|
+
}),
|
|
37
|
+
r.getOrders({
|
|
38
|
+
address: s,
|
|
39
|
+
status: T.notInitiated,
|
|
40
|
+
per_page: 500
|
|
41
|
+
})
|
|
42
|
+
]), c = [];
|
|
43
|
+
return t.ok ? c.push(...t.val.data) : console.error(
|
|
44
|
+
`Failed to fetch pending orders for address ${s}:`,
|
|
45
|
+
t.error
|
|
46
|
+
), d.ok ? c.push(...d.val.data) : console.error(
|
|
47
|
+
`Failed to fetch notInitiated orders for address ${s}:`,
|
|
48
|
+
d.error
|
|
49
|
+
), c;
|
|
50
|
+
} catch (t) {
|
|
51
|
+
return console.error(`Error fetching orders for address ${s}:`, t), [];
|
|
52
|
+
}
|
|
53
|
+
}), l = (await Promise.all(n)).flat().map((s) => s.order_id), i = Array.from(new Set(l));
|
|
54
|
+
if (i.length > 0)
|
|
55
|
+
try {
|
|
56
|
+
a.setItem(I, JSON.stringify(i));
|
|
57
|
+
} catch (s) {
|
|
58
|
+
console.error(
|
|
59
|
+
"Error saving initial pending order IDs to localStorage",
|
|
60
|
+
s
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
} catch (e) {
|
|
64
|
+
console.error("Error fetching initial pending orders:", e);
|
|
65
|
+
}
|
|
66
|
+
}, [r, a, h]), R = C(async () => {
|
|
67
|
+
if (r)
|
|
68
|
+
try {
|
|
69
|
+
const e = a.getItem(I), n = e ? JSON.parse(e) : [], o = Array.from(new Set(n));
|
|
70
|
+
if (o.length === 0) {
|
|
71
|
+
O([]);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const u = await Promise.all(
|
|
75
|
+
o.map((t) => r.getOrder(t))
|
|
76
|
+
), l = [], i = [];
|
|
77
|
+
u.forEach((t, d) => {
|
|
78
|
+
if (!t.ok) {
|
|
79
|
+
i.push(o[d]);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const c = t.val;
|
|
83
|
+
c.status === S.Redeemed || c.status === S.Refunded || c.status === S.Expired || (l.push(c), i.push(o[d]));
|
|
84
|
+
});
|
|
85
|
+
const s = Array.from(new Set(i));
|
|
86
|
+
try {
|
|
87
|
+
a.setItem(I, JSON.stringify(s));
|
|
88
|
+
} catch (t) {
|
|
89
|
+
console.error("Error persisting remaining pending order ids", t);
|
|
90
|
+
}
|
|
91
|
+
O(l);
|
|
92
|
+
} catch (e) {
|
|
93
|
+
console.error("Error fetching pending orders:", e);
|
|
94
|
+
}
|
|
95
|
+
}, [r, a]), m = F(() => {
|
|
96
|
+
try {
|
|
97
|
+
return h().join(",");
|
|
98
|
+
} catch (e) {
|
|
99
|
+
return console.error("Error computing HTLC addresses:", e), "";
|
|
100
|
+
}
|
|
101
|
+
}, [h]), w = g("");
|
|
102
|
+
return L(() => {
|
|
103
|
+
if (!r || !r.redeemServiceEnabled || !m) return;
|
|
104
|
+
w.current !== m && (A.current = !1, w.current = m), A.current || (P(), A.current = !0);
|
|
105
|
+
}, [r, m, P]), L(() => {
|
|
106
|
+
if (r)
|
|
107
|
+
if (r.redeemServiceEnabled) {
|
|
108
|
+
let e = !1;
|
|
109
|
+
const n = () => {
|
|
110
|
+
e || (f.current = setTimeout(o, b));
|
|
111
|
+
}, o = async () => {
|
|
112
|
+
if (!e) {
|
|
113
|
+
if (y.current) {
|
|
114
|
+
n();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
y.current = !0;
|
|
118
|
+
try {
|
|
119
|
+
await R();
|
|
120
|
+
} finally {
|
|
121
|
+
y.current = !1;
|
|
122
|
+
}
|
|
123
|
+
n();
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
return o(), () => {
|
|
127
|
+
e = !0, f.current && (clearTimeout(f.current), f.current = null);
|
|
128
|
+
};
|
|
129
|
+
} else {
|
|
130
|
+
const e = (n) => O(n);
|
|
131
|
+
return r.on("onPendingOrdersChanged", e), () => {
|
|
132
|
+
r.off("onPendingOrdersChanged", e);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}, [r, R]), { pendingOrders: N };
|
|
11
136
|
};
|
|
12
137
|
export {
|
|
13
|
-
|
|
138
|
+
q as useOrderbook
|
|
14
139
|
};
|
package/dist/index4.cjs
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 r=require("@gardenfi/utils"),s=e=>Object.values(e).some(t=>t!==void 0),l=e=>typeof e=="string"?new r.ApiKey(e):e;exports.hasAnyValidValue=s;exports.resolveAuth=l;
|
package/dist/index4.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { ApiKey as o } from "@gardenfi/utils";
|
|
2
|
+
const n = (e) => Object.values(e).some((r) => r !== void 0), s = (e) => typeof e == "string" ? new o(e) : e;
|
|
2
3
|
export {
|
|
3
|
-
|
|
4
|
+
n as hasAnyValidValue,
|
|
5
|
+
s as resolveAuth
|
|
4
6
|
};
|
package/dist/index5.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@gardenfi/utils"),e=require("./index6.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@gardenfi/utils"),e=require("./index6.cjs"),y=require("react"),f=(a=!0)=>{const[E,g]=y.useState();return y.useEffect(()=>{if(a)return;if(!indexedDB){console.error("IndexedDB is not supported in this browser");return}let o;const d=indexedDB.open(e.DB_NAME,e.VERSION);d.onerror=s=>{console.error("IndexedDB error:",s.target.error)},d.onupgradeneeded=s=>{const n=s.target.result;n.objectStoreNames.contains(e.STORE_NAME)||n.createObjectStore(e.STORE_NAME,{keyPath:"id"})},d.onsuccess=s=>{if(o=s.target.result,!o.objectStoreNames.contains(e.STORE_NAME)){o.close();const r=indexedDB.open(e.DB_NAME,o.version+1);r.onupgradeneeded=n=>{n.target.result.createObjectStore(e.STORE_NAME,{keyPath:"id"})},r.onsuccess=()=>{l(r.result)};return}l(o)};function l(s){try{const r=s.transaction(e.STORE_NAME,"readwrite"),n=r.objectStore(e.STORE_NAME),c=n.get(e.DIGEST_KEY);c.onsuccess=()=>{if(c.result){const i=u.DigestKey.from(c.result.value);if(!i.error){g(i.val);return}}const t=u.DigestKey.generateRandom();if(!t.ok){console.error("Error generating new digest key:",t.error);return}if(a)g(u.DigestKey.from(t.val.digestKey).val);else{const i=n.put({id:e.DIGEST_KEY,value:t.val.digestKey});i.onsuccess=()=>{g(u.DigestKey.from(t.val.digestKey).val)},i.onerror=D=>{console.error("Error storing new digest key:",D)}}},c.onerror=t=>{console.error("Error retrieving digest key:",t)},r.oncomplete=()=>{},r.onerror=t=>{console.error("Error in digestKey transaction:",t)}}catch(r){console.error("Transaction error:",r)}}return()=>{o&&o.close()}},[a]),{digestKey:E}};exports.useDigestKey=f;
|
package/dist/index5.js
CHANGED
|
@@ -1,61 +1,67 @@
|
|
|
1
|
-
import { DigestKey as
|
|
2
|
-
import { DB_NAME as f, VERSION as
|
|
3
|
-
import { useState as
|
|
4
|
-
const
|
|
5
|
-
const [
|
|
1
|
+
import { DigestKey as a } from "@gardenfi/utils";
|
|
2
|
+
import { DB_NAME as f, VERSION as m, STORE_NAME as n, DIGEST_KEY as y } from "./index6.js";
|
|
3
|
+
import { useState as K, useEffect as E } from "react";
|
|
4
|
+
const S = (u = !0) => {
|
|
5
|
+
const [p, d] = K();
|
|
6
6
|
return E(() => {
|
|
7
|
+
if (u)
|
|
8
|
+
return;
|
|
7
9
|
if (!indexedDB) {
|
|
8
10
|
console.error("IndexedDB is not supported in this browser");
|
|
9
11
|
return;
|
|
10
12
|
}
|
|
11
13
|
let t;
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
+
const g = indexedDB.open(f, m);
|
|
15
|
+
g.onerror = (o) => {
|
|
14
16
|
console.error(
|
|
15
17
|
"IndexedDB error:",
|
|
16
18
|
o.target.error
|
|
17
19
|
);
|
|
18
|
-
},
|
|
20
|
+
}, g.onupgradeneeded = (o) => {
|
|
19
21
|
const s = o.target.result;
|
|
20
22
|
s.objectStoreNames.contains(n) || s.createObjectStore(n, { keyPath: "id" });
|
|
21
|
-
},
|
|
23
|
+
}, g.onsuccess = (o) => {
|
|
22
24
|
if (t = o.target.result, !t.objectStoreNames.contains(n)) {
|
|
23
25
|
t.close();
|
|
24
26
|
const e = indexedDB.open(f, t.version + 1);
|
|
25
27
|
e.onupgradeneeded = (s) => {
|
|
26
28
|
s.target.result.createObjectStore(n, { keyPath: "id" });
|
|
27
29
|
}, e.onsuccess = () => {
|
|
28
|
-
|
|
30
|
+
l(e.result);
|
|
29
31
|
};
|
|
30
32
|
return;
|
|
31
33
|
}
|
|
32
|
-
|
|
34
|
+
l(t);
|
|
33
35
|
};
|
|
34
|
-
function
|
|
36
|
+
function l(o) {
|
|
35
37
|
try {
|
|
36
|
-
const e = o.transaction(n, "readwrite"), s = e.objectStore(n), c = s.get(
|
|
38
|
+
const e = o.transaction(n, "readwrite"), s = e.objectStore(n), c = s.get(y);
|
|
37
39
|
c.onsuccess = () => {
|
|
38
40
|
if (c.result) {
|
|
39
|
-
const i =
|
|
41
|
+
const i = a.from(c.result.value);
|
|
40
42
|
if (!i.error) {
|
|
41
43
|
d(i.val);
|
|
42
44
|
return;
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
|
-
const r =
|
|
47
|
+
const r = a.generateRandom();
|
|
46
48
|
if (!r.ok) {
|
|
47
49
|
console.error("Error generating new digest key:", r.error);
|
|
48
50
|
return;
|
|
49
51
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
if (u)
|
|
53
|
+
d(a.from(r.val.digestKey).val);
|
|
54
|
+
else {
|
|
55
|
+
const i = s.put({
|
|
56
|
+
id: y,
|
|
57
|
+
value: r.val.digestKey
|
|
58
|
+
});
|
|
59
|
+
i.onsuccess = () => {
|
|
60
|
+
d(a.from(r.val.digestKey).val);
|
|
61
|
+
}, i.onerror = (D) => {
|
|
62
|
+
console.error("Error storing new digest key:", D);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
59
65
|
}, c.onerror = (r) => {
|
|
60
66
|
console.error("Error retrieving digest key:", r);
|
|
61
67
|
}, e.oncomplete = () => {
|
|
@@ -69,8 +75,8 @@ const v = () => {
|
|
|
69
75
|
return () => {
|
|
70
76
|
t && t.close();
|
|
71
77
|
};
|
|
72
|
-
}, []), { digestKey:
|
|
78
|
+
}, [u]), { digestKey: p };
|
|
73
79
|
};
|
|
74
80
|
export {
|
|
75
|
-
|
|
81
|
+
S as useDigestKey
|
|
76
82
|
};
|
package/dist/index6.cjs
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="garden-finance-db",e="garden-finance-store",n="digest-key",t=1,o="orders-in-progress";exports.DB_NAME=E;exports.DIGEST_KEY=n;exports.PENDING_ORDERS_STORE=o;exports.STORE_NAME=e;exports.VERSION=t;
|
package/dist/index6.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
const n = "garden-finance-db", e = "garden-finance-store",
|
|
1
|
+
const n = "garden-finance-db", e = "garden-finance-store", s = "digest-key", o = 1, E = "orders-in-progress";
|
|
2
2
|
export {
|
|
3
3
|
n as DB_NAME,
|
|
4
|
-
|
|
4
|
+
s as DIGEST_KEY,
|
|
5
|
+
E as PENDING_ORDERS_STORE,
|
|
5
6
|
e as STORE_NAME,
|
|
6
|
-
|
|
7
|
+
o as VERSION
|
|
7
8
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OrderWithStatus, QuoteParamsForAssets, IGardenJS, QuoteResponse, SwapParams, GardenConfigWithHTLCs, GardenConfigWithWallets } from '@gardenfi/core';
|
|
2
|
-
import {
|
|
3
|
-
import { AsyncResult,
|
|
2
|
+
import { CreateOrderResponse, IOrderbook } from '@gardenfi/orderbook';
|
|
3
|
+
import { AsyncResult, IStore } from '@gardenfi/utils';
|
|
4
4
|
|
|
5
5
|
export type GardenContextType = {
|
|
6
6
|
/**
|
|
@@ -13,11 +13,11 @@ export type GardenContextType = {
|
|
|
13
13
|
* @params {SwapParams} - The parameters for creating the order.
|
|
14
14
|
* @returns {AsyncResult<string, string>} - create order ID.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
swap?: (params: SwapParams) => AsyncResult<CreateOrderResponse | string, string>;
|
|
17
17
|
/**
|
|
18
18
|
* Get all the pending orders of the user. This will return all the orders that are yet to be initiated, redeemed, or refunded.
|
|
19
19
|
* It will not return orders that have expired (deadline expiry).
|
|
20
|
-
* @returns {
|
|
20
|
+
* @returns {Order[]} - The pending orders of the user.
|
|
21
21
|
*/
|
|
22
22
|
pendingOrders: OrderWithStatus[];
|
|
23
23
|
/**
|
|
@@ -25,7 +25,7 @@ export type GardenContextType = {
|
|
|
25
25
|
* @param params
|
|
26
26
|
* @returns
|
|
27
27
|
*/
|
|
28
|
-
getQuote?: (params: QuoteParamsForAssets) =>
|
|
28
|
+
getQuote?: (params: QuoteParamsForAssets) => AsyncResult<QuoteResponse[], string> | undefined;
|
|
29
29
|
/**
|
|
30
30
|
* The garden instance.
|
|
31
31
|
* @returns {IGardenJS}
|
|
@@ -35,5 +35,12 @@ export type GardenContextType = {
|
|
|
35
35
|
export type GardenProviderProps = {
|
|
36
36
|
children: React.ReactNode;
|
|
37
37
|
config: Omit<GardenConfigWithHTLCs, 'digestKey'> | Omit<GardenConfigWithWallets, 'digestKey'>;
|
|
38
|
-
|
|
38
|
+
store: IStore;
|
|
39
|
+
/**
|
|
40
|
+
* Controls whether the redeem service is enabled.
|
|
41
|
+
* - When `true` (default): Manual order fetching with digestKey required
|
|
42
|
+
* - When `false`: Event-based order updates, no digestKey required
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
setRedeemServiceEnabled?: boolean;
|
|
39
46
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IGardenJS, OrderWithStatus } from '@gardenfi/core';
|
|
2
|
+
import { IStore } from '@gardenfi/utils';
|
|
2
3
|
|
|
3
|
-
export declare const useOrderbook: (garden: IGardenJS | undefined) => {
|
|
4
|
+
export declare const useOrderbook: (garden: IGardenJS | undefined, store: IStore) => {
|
|
4
5
|
pendingOrders: OrderWithStatus[];
|
|
5
6
|
};
|
package/dist/src/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IAuth } from '@gardenfi/utils';
|
|
2
2
|
|
|
3
|
-
export declare const constructOrderpair: (fromAsset: Asset, toAsset: Asset) => string;
|
|
4
3
|
export declare const hasAnyValidValue: (obj: Record<string, any>) => boolean;
|
|
4
|
+
export declare const resolveAuth: (auth: string | IAuth) => IAuth;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/react-hooks",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"registry": "https://registry.npmjs.org/"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@gardenfi/core": "
|
|
31
|
-
"@gardenfi/orderbook": "
|
|
32
|
-
"@gardenfi/utils": "
|
|
30
|
+
"@gardenfi/core": "3.0.1",
|
|
31
|
+
"@gardenfi/orderbook": "3.0.1",
|
|
32
|
+
"@gardenfi/utils": "3.0.0",
|
|
33
33
|
"react": "^18.3.1",
|
|
34
34
|
"starknet": "7.6.4"
|
|
35
35
|
},
|