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