@gardenfi/react-hooks 2.5.3-beta.9 → 3.0.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/dist/index2.cjs +1 -1
- package/dist/index2.js +41 -41
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +4 -2
- package/dist/src/lib/utils.d.ts +3 -0
- package/package.json +4 -4
package/dist/index2.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),
|
|
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,88 +1,88 @@
|
|
|
1
|
-
import
|
|
1
|
+
import h, { useState as k, useMemo as m, useEffect as K, createContext as x } from "react";
|
|
2
2
|
import { useOrderbook as A } from "./index3.js";
|
|
3
|
-
import { resolveApiConfig as
|
|
4
|
-
import { hasAnyValidValue as
|
|
5
|
-
import { useDigestKey as
|
|
6
|
-
import { Err as v, Ok as
|
|
7
|
-
import { PENDING_ORDERS_STORE as
|
|
8
|
-
const
|
|
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
|
-
}),
|
|
10
|
+
}), b = ({
|
|
11
11
|
children: i,
|
|
12
12
|
config: e,
|
|
13
13
|
store: u,
|
|
14
|
-
setRedeemServiceEnabled:
|
|
14
|
+
setRedeemServiceEnabled: o = !0
|
|
15
15
|
}) => {
|
|
16
|
-
const [
|
|
17
|
-
const { api: t } =
|
|
18
|
-
return e.quote ?? new
|
|
19
|
-
}, [e.environment, e.quote]), q = m(
|
|
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(
|
|
20
20
|
() => async ({
|
|
21
21
|
fromAsset: t,
|
|
22
22
|
toAsset: r,
|
|
23
23
|
amount: a,
|
|
24
|
-
isExactOut:
|
|
24
|
+
isExactOut: n = !1,
|
|
25
25
|
options: d
|
|
26
|
-
}) => await (
|
|
26
|
+
}) => await (s ? s.quote : p).getQuoteFromAssets({
|
|
27
27
|
fromAsset: t,
|
|
28
28
|
toAsset: r,
|
|
29
29
|
amount: a,
|
|
30
|
-
isExactOut:
|
|
30
|
+
isExactOut: n,
|
|
31
31
|
options: d
|
|
32
32
|
}),
|
|
33
|
-
[
|
|
33
|
+
[s, p]
|
|
34
34
|
), _ = async (t) => {
|
|
35
|
-
if (!
|
|
36
|
-
const r = await
|
|
35
|
+
if (!s) return v("Garden not initialized");
|
|
36
|
+
const r = await s.createSwap(t);
|
|
37
37
|
if (!r.val) return v(r.error || "Unknown error occurred");
|
|
38
|
-
if (
|
|
38
|
+
if (o)
|
|
39
39
|
try {
|
|
40
|
-
const a = u.getItem(
|
|
41
|
-
typeof r.val == "string" ?
|
|
42
|
-
const d = Array.from(new Set(
|
|
43
|
-
u.setItem(
|
|
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
44
|
} catch (a) {
|
|
45
45
|
console.error("Failed to persist pending order id", a);
|
|
46
46
|
}
|
|
47
|
-
return
|
|
47
|
+
return P(r.val);
|
|
48
48
|
};
|
|
49
|
-
return
|
|
49
|
+
return K(() => {
|
|
50
50
|
if (!("wallets" in e) && !("htlc" in e)) return;
|
|
51
51
|
let t;
|
|
52
|
-
if ("wallets" in e && Object.keys(e.wallets ?? {}).length > 0 &&
|
|
52
|
+
if ("wallets" in e && Object.keys(e.wallets ?? {}).length > 0 && y(e.wallets ?? {}))
|
|
53
53
|
t = c.fromWallets({
|
|
54
54
|
...e,
|
|
55
|
-
digestKey:
|
|
56
|
-
}).setRedeemServiceEnabled(
|
|
57
|
-
else if ("htlc" in e && Object.keys(e.htlc ?? {}).length > 0 &&
|
|
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
58
|
t = new c({
|
|
59
59
|
...e,
|
|
60
|
-
digestKey:
|
|
61
|
-
}).setRedeemServiceEnabled(
|
|
60
|
+
digestKey: o ? void 0 : l
|
|
61
|
+
}).setRedeemServiceEnabled(o);
|
|
62
62
|
else
|
|
63
63
|
return;
|
|
64
64
|
O(t);
|
|
65
|
-
}, [e, l,
|
|
66
|
-
|
|
65
|
+
}, [e, l, o]), /* @__PURE__ */ h.createElement(
|
|
66
|
+
f.Provider,
|
|
67
67
|
{
|
|
68
68
|
value: {
|
|
69
69
|
swap: _,
|
|
70
70
|
pendingOrders: G,
|
|
71
71
|
getQuote: q,
|
|
72
|
-
garden:
|
|
73
|
-
orderBook:
|
|
72
|
+
garden: s,
|
|
73
|
+
orderBook: s
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
76
|
i
|
|
77
77
|
);
|
|
78
|
-
},
|
|
79
|
-
const i =
|
|
78
|
+
}, z = () => {
|
|
79
|
+
const i = h.useContext(f);
|
|
80
80
|
if (!i)
|
|
81
81
|
throw new Error("useGarden must be used within a GardenProvider");
|
|
82
82
|
return i;
|
|
83
83
|
};
|
|
84
84
|
export {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
f as GardenContext,
|
|
86
|
+
b as GardenProvider,
|
|
87
|
+
z as useGarden
|
|
88
88
|
};
|
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/src/lib/utils.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/react-hooks",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
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.0",
|
|
31
|
+
"@gardenfi/orderbook": "3.0.0",
|
|
32
|
+
"@gardenfi/utils": "3.0.0",
|
|
33
33
|
"react": "^18.3.1",
|
|
34
34
|
"starknet": "7.6.4"
|
|
35
35
|
},
|