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