@gardenfi/react-hooks 0.0.2-beta.1 → 0.0.2-beta.10
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 +36 -35
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +34 -27
- package/package.json +3 -3
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 n=require("react"),q=require("./index3.cjs"),s=require("@gardenfi/core"),i=require("@catalogfi/utils"),m=require("@gardenfi/orderbook"),x=require("./index5.cjs"),w=n.createContext({isExecuting:!1,isExecutorRequired:!1}),S=({children:u,config:a})=>{const[e,v]=n.useState(),[C,O]=n.useState(),{pendingOrders:d}=q.useOrderbook(e),E=n.useMemo(()=>!!(e!=null&&e.secretManager.isInitialized),[e]),f=n.useMemo(()=>!!d.find(r=>{const t=r.status;return t===s.OrderStatus.InitiateDetected||t===s.OrderStatus.Initiated||t===s.OrderStatus.CounterPartyInitiateDetected||t===s.OrderStatus.CounterPartyInitiated||t===s.OrderStatus.RedeemDetected||t===s.OrderStatus.Expired}),[d]),G=async r=>{if(!e||!a.walletClient)return i.Err("Garden not initialized");const t=await e.swap(r);if(t.error)return i.Err(t.error);if(m.isBitcoin(t.val.source_swap.chain))return i.Ok(t.val);const o=await s.switchOrAddNetwork(r.fromAsset.chain,a.walletClient);if(o.error)return i.Err("Failed to switch network: "+o.error);const l=o.val.walletClient,c=await e.evmRelay.init(l,t.val);if(c.error)return i.Err(c.error);const h={...t.val,source_swap:{...t.val.source_swap,initiate_tx_hash:c.val}};return i.Ok(h)};return n.useEffect(()=>{var r;if(a.walletClient){if(!((r=a.walletClient.account)!=null&&r.address))throw new Error("WalletClient doesn't have an account");v(new s.Garden({environment:a.environment,evmWallet:a.walletClient}))}},[a.walletClient]),n.useEffect(()=>{e&&O(()=>async({fromAsset:r,toAsset:t,amount:o,isExactOut:l=!1})=>await e.quote.getQuote(x.constructOrderpair(r,t),o,l))},[e]),n.createElement(w.Provider,{value:{orderBook:e==null?void 0:e.orderbook,quote:e==null?void 0:e.quote,swapAndInitiate:G,pendingOrders:d,getQuote:C,garden:e,isExecuting:E,isExecutorRequired:f}},u)},k=()=>{const u=n.useContext(w);if(!u)throw new Error("useGarden must be used within a GardenProvider");return u};exports.GardenContext=w;exports.GardenProvider=S;exports.useGarden=k;
|
package/dist/index2.js
CHANGED
|
@@ -1,37 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useOrderbook as
|
|
3
|
-
import { OrderStatus as i, Garden as
|
|
4
|
-
import { Err as s, Ok as
|
|
5
|
-
import { isBitcoin as
|
|
6
|
-
import { constructOrderpair as
|
|
7
|
-
const
|
|
1
|
+
import v, { createContext as k, useState as d, useMemo as w, useEffect as m } from "react";
|
|
2
|
+
import { useOrderbook as I } from "./index3.js";
|
|
3
|
+
import { OrderStatus as i, Garden as q, switchOrAddNetwork as y } from "@gardenfi/core";
|
|
4
|
+
import { Err as s, Ok as f } from "@catalogfi/utils";
|
|
5
|
+
import { isBitcoin as P } from "@gardenfi/orderbook";
|
|
6
|
+
import { constructOrderpair as _ } from "./index5.js";
|
|
7
|
+
const p = k({
|
|
8
8
|
isExecuting: !1,
|
|
9
9
|
isExecutorRequired: !1
|
|
10
10
|
}), B = ({
|
|
11
11
|
children: a,
|
|
12
12
|
config: n
|
|
13
13
|
}) => {
|
|
14
|
-
const [e,
|
|
14
|
+
const [e, C] = d(), [h, x] = d(), { pendingOrders: u } = I(e), E = w(() => !!(e != null && e.secretManager.isInitialized), [e]), G = w(() => !!u.find((r) => {
|
|
15
15
|
const t = r.status;
|
|
16
16
|
return t === i.InitiateDetected || t === i.Initiated || t === i.CounterPartyInitiateDetected || t === i.CounterPartyInitiated || t === i.RedeemDetected || t === i.Expired;
|
|
17
|
-
}), [u]),
|
|
18
|
-
() => async ({
|
|
19
|
-
fromAsset: r,
|
|
20
|
-
toAsset: t,
|
|
21
|
-
amount: o,
|
|
22
|
-
isExactOut: l = !1
|
|
23
|
-
}) => await e.quote.getQuote(
|
|
24
|
-
P(r, t),
|
|
25
|
-
o,
|
|
26
|
-
l
|
|
27
|
-
),
|
|
28
|
-
[e]
|
|
29
|
-
), x = async (r) => {
|
|
17
|
+
}), [u]), O = async (r) => {
|
|
30
18
|
if (!e || !n.walletClient) return s("Garden not initialized");
|
|
31
19
|
const t = await e.swap(r);
|
|
32
20
|
if (t.error) return s(t.error);
|
|
33
|
-
if (
|
|
34
|
-
const o = await
|
|
21
|
+
if (P(t.val.source_swap.chain)) return f(t.val);
|
|
22
|
+
const o = await y(
|
|
35
23
|
r.fromAsset.chain,
|
|
36
24
|
n.walletClient
|
|
37
25
|
);
|
|
@@ -39,51 +27,64 @@ const v = G({
|
|
|
39
27
|
return s("Failed to switch network: " + o.error);
|
|
40
28
|
const l = o.val.walletClient, c = await e.evmRelay.init(l, t.val);
|
|
41
29
|
if (c.error) return s(c.error);
|
|
42
|
-
const
|
|
30
|
+
const R = {
|
|
43
31
|
...t.val,
|
|
44
32
|
source_swap: {
|
|
45
33
|
...t.val.source_swap,
|
|
46
34
|
initiate_tx_hash: c.val
|
|
47
35
|
}
|
|
48
36
|
};
|
|
49
|
-
return
|
|
37
|
+
return f(R);
|
|
50
38
|
};
|
|
51
|
-
return
|
|
39
|
+
return m(() => {
|
|
52
40
|
var r;
|
|
53
41
|
if (n.walletClient) {
|
|
54
42
|
if (!((r = n.walletClient.account) != null && r.address))
|
|
55
43
|
throw new Error("WalletClient doesn't have an account");
|
|
56
|
-
|
|
57
|
-
new
|
|
44
|
+
C(
|
|
45
|
+
new q({
|
|
58
46
|
environment: n.environment,
|
|
59
47
|
evmWallet: n.walletClient
|
|
60
48
|
})
|
|
61
49
|
);
|
|
62
50
|
}
|
|
63
|
-
}, [n.walletClient]),
|
|
64
|
-
|
|
51
|
+
}, [n.walletClient]), m(() => {
|
|
52
|
+
e && x(
|
|
53
|
+
() => async ({
|
|
54
|
+
fromAsset: r,
|
|
55
|
+
toAsset: t,
|
|
56
|
+
amount: o,
|
|
57
|
+
isExactOut: l = !1
|
|
58
|
+
}) => await e.quote.getQuote(
|
|
59
|
+
_(r, t),
|
|
60
|
+
o,
|
|
61
|
+
l
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
}, [e]), /* @__PURE__ */ v.createElement(
|
|
65
|
+
p.Provider,
|
|
65
66
|
{
|
|
66
67
|
value: {
|
|
67
68
|
orderBook: e == null ? void 0 : e.orderbook,
|
|
68
69
|
quote: e == null ? void 0 : e.quote,
|
|
69
|
-
swapAndInitiate:
|
|
70
|
+
swapAndInitiate: O,
|
|
70
71
|
pendingOrders: u,
|
|
71
72
|
getQuote: h,
|
|
72
73
|
garden: e,
|
|
73
|
-
isExecuting:
|
|
74
|
-
isExecutorRequired:
|
|
74
|
+
isExecuting: E,
|
|
75
|
+
isExecutorRequired: G
|
|
75
76
|
}
|
|
76
77
|
},
|
|
77
78
|
a
|
|
78
79
|
);
|
|
79
80
|
}, M = () => {
|
|
80
|
-
const a =
|
|
81
|
+
const a = v.useContext(p);
|
|
81
82
|
if (!a)
|
|
82
83
|
throw new Error("useGarden must be used within a GardenProvider");
|
|
83
84
|
return a;
|
|
84
85
|
};
|
|
85
86
|
export {
|
|
86
|
-
|
|
87
|
+
p as GardenContext,
|
|
87
88
|
B as GardenProvider,
|
|
88
89
|
M as useGarden
|
|
89
90
|
};
|
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 f=require("@gardenfi/core"),n=require("react"),O=e=>{const[l,c]=n.useState([]),[o,b]=n.useState(!1);return n.useEffect(()=>{if(!e)return;const t=()=>{e.secretManager.isInitialized&&b(!0)};return t(),e.secretManager.on("initialized",t),()=>{e.secretManager.off("initialized",t)}},[e]),n.useEffect(()=>{if(!e||!o)return;const t=e.execute(),s=i=>c(i);return e.on("onPendingOrdersChanged",s),()=>{(async()=>(await t)())(),e.off("onPendingOrdersChanged",s)}},[e,o]),n.useEffect(()=>{e&&e.blockNumberFetcher.fetchBlockNumbers().then(t=>{if(t.error)return;const{val:s}=t;e.orderbook.fetchOrders(!0,!0,{per_page:500}).then(i=>{if(i.error)return;const d=f.filterDeadlineExpiredOrders(i.val.data).map(r=>{const u=s[r.source_swap.chain],a=s[r.destination_swap.chain];if(!u||!a)return;const h=f.ParseOrderStatus(r,u,a);return{...r,status:h}}).filter(r=>r!==void 0);c(d)})})},[e]),{pendingOrders:l}};exports.useOrderbook=O;
|
package/dist/index3.js
CHANGED
|
@@ -1,40 +1,47 @@
|
|
|
1
|
-
import { filterDeadlineExpiredOrders as
|
|
2
|
-
import { useState as
|
|
3
|
-
const
|
|
4
|
-
const [
|
|
5
|
-
return
|
|
6
|
-
if (!e
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return e.on("onPendingOrdersChanged", r), () => {
|
|
10
|
-
(async () => (await s)())(), e.off("onPendingOrdersChanged", r);
|
|
1
|
+
import { filterDeadlineExpiredOrders as m, ParseOrderStatus as p } from "@gardenfi/core";
|
|
2
|
+
import { useState as f, useEffect as s } from "react";
|
|
3
|
+
const z = (e) => {
|
|
4
|
+
const [l, o] = f([]), [c, b] = f(!1);
|
|
5
|
+
return s(() => {
|
|
6
|
+
if (!e) return;
|
|
7
|
+
const t = () => {
|
|
8
|
+
e.secretManager.isInitialized && b(!0);
|
|
11
9
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
return t(), e.secretManager.on("initialized", t), () => {
|
|
11
|
+
e.secretManager.off("initialized", t);
|
|
12
|
+
};
|
|
13
|
+
}, [e]), s(() => {
|
|
14
|
+
if (!e || !c) return;
|
|
15
|
+
const t = e.execute(), i = (n) => o(n);
|
|
16
|
+
return e.on("onPendingOrdersChanged", i), () => {
|
|
17
|
+
(async () => (await t)())(), e.off("onPendingOrdersChanged", i);
|
|
18
|
+
};
|
|
19
|
+
}, [e, c]), s(() => {
|
|
20
|
+
e && e.blockNumberFetcher.fetchBlockNumbers().then((t) => {
|
|
21
|
+
if (t.error) return;
|
|
22
|
+
const { val: i } = t;
|
|
16
23
|
e.orderbook.fetchOrders(!0, !0, {
|
|
17
24
|
per_page: 500
|
|
18
25
|
}).then((n) => {
|
|
19
26
|
if (n.error) return;
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
if (!
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
const d = m(n.val.data).map((r) => {
|
|
28
|
+
const u = i[r.source_swap.chain], a = i[r.destination_swap.chain];
|
|
29
|
+
if (!u || !a) return;
|
|
30
|
+
const h = p(
|
|
31
|
+
r,
|
|
32
|
+
u,
|
|
33
|
+
a
|
|
27
34
|
);
|
|
28
35
|
return {
|
|
29
|
-
...
|
|
30
|
-
status:
|
|
36
|
+
...r,
|
|
37
|
+
status: h
|
|
31
38
|
};
|
|
32
|
-
}).filter((
|
|
33
|
-
o(
|
|
39
|
+
}).filter((r) => r !== void 0);
|
|
40
|
+
o(d);
|
|
34
41
|
});
|
|
35
42
|
});
|
|
36
|
-
}, [e]), { pendingOrders:
|
|
43
|
+
}, [e]), { pendingOrders: l };
|
|
37
44
|
};
|
|
38
45
|
export {
|
|
39
|
-
|
|
46
|
+
z as useOrderbook
|
|
40
47
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/react-hooks",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@catalogfi/utils": "^0.1.6",
|
|
30
30
|
"@catalogfi/wallets": "^0.2.51",
|
|
31
|
-
"@gardenfi/core": "^0.3.0-beta.
|
|
31
|
+
"@gardenfi/core": "^0.3.0-beta.18",
|
|
32
32
|
"@gardenfi/orderbook": "^0.2.0-beta.42",
|
|
33
|
-
"@gardenfi/utils": "^0.0.1-beta.
|
|
33
|
+
"@gardenfi/utils": "^0.0.1-beta.21",
|
|
34
34
|
"react": "^18.3.1",
|
|
35
35
|
"viem": "^2.21.15",
|
|
36
36
|
"wagmi": "^2.12.16"
|