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