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