@gardenfi/react-hooks 0.0.1-beta.3 → 0.0.1-beta.4
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 r=require("react"),U=require("wagmi"),y=require("./index4.cjs"),f=require("./index3.cjs"),S=require("@gardenfi/core"),u=require("@catalogfi/utils"),w=require("@gardenfi/orderbook"),p=require("@catalogfi/wallets"),b=r.createContext({}),g=({children:l,config:e})=>{const[t,q]=r.useState(),[i,E]=r.useState(),[k,O]=r.useState(),{data:s}=U.useWalletClient(),{initializeSecretManager:C}=y.useSecretManager(q),{orderbook:a}=f.useOrderbook(e.orderBookUrl,e.store),v=r.useMemo(()=>new p.BitcoinProvider(e.bitcoinNetwork,e.bitcoinRPCUrl),[e.bitcoinNetwork,e.bitcoinRPCUrl]),M=async o=>{if(!i||!a||!t||!s)return u.Err("Garden not initialized");const n=await i.swap(o);if(n.error)return u.Err(n.error);if(w.isBitcoin(n.val.source_swap.chain))return u.Ok(n.val);const c=await new S.OrderExecutor(n.val,e.orderBookUrl,t,{store:e.store}).init(s,0);return c.error?u.Err(c.error):u.Ok(n.val)};return r.useEffect(()=>{if(!t)return;const o=p.BitcoinWallet.fromPrivateKey(t.getMasterPrivKey(),v);O(o)},[t,v]),r.useEffect(()=>{if(!t||!s||!a)return;const o=new S.Garden(a,t,e.orderBookUrl,e.quoteUrl,{store:e.store});E(o)},[t,s,a]),r.useEffect(()=>{if(!i)return;let o;return(async()=>{const B=async c=>{const d=c.getOrder(),x=w.isBitcoin(d.source_swap.chain)?k:s,G=w.isBitcoin(d.destination_swap.chain)?k:s;if(!x||!G)return;console.log("executing order:",d.create_order.create_id);const P=await c.execute({wallets:{source:x,destination:G}});console.log("execute result :",P.val),console.log("execute error: ",P.error)};o=await i.subscribeOrders(B)})(),()=>{o()}},[i]),r.createElement(b.Provider,{value:{orderBookUrl:e.orderBookUrl,initializeSecretManager:C,orderBook:a,swap:M}},l)},h=()=>{const l=r.useContext(b);if(!l)throw new Error("useGarden must be used within a GardenProvider");return l};exports.GardenContext=b;exports.GardenProvider=g;exports.useGarden=h;
|
package/dist/index2.js
CHANGED
|
@@ -1,95 +1,91 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useWalletClient as
|
|
3
|
-
import { useSecretManager as
|
|
4
|
-
import { useOrderbook as
|
|
5
|
-
import { Garden as R, OrderExecutor as
|
|
6
|
-
import { Err as m,
|
|
7
|
-
import { isBitcoin as
|
|
8
|
-
import { BitcoinProvider as
|
|
9
|
-
const
|
|
10
|
-
children:
|
|
11
|
-
config:
|
|
1
|
+
import P, { createContext as S, useState as u, useMemo as W, useEffect as d } from "react";
|
|
2
|
+
import { useWalletClient as y } from "wagmi";
|
|
3
|
+
import { useSecretManager as E } from "./index4.js";
|
|
4
|
+
import { useOrderbook as _ } from "./index3.js";
|
|
5
|
+
import { Garden as R, OrderExecutor as g } from "@gardenfi/core";
|
|
6
|
+
import { Err as m, Ok as f } from "@catalogfi/utils";
|
|
7
|
+
import { isBitcoin as w } from "@gardenfi/orderbook";
|
|
8
|
+
import { BitcoinProvider as z, BitcoinWallet as K } from "@catalogfi/wallets";
|
|
9
|
+
const G = S({}), J = ({
|
|
10
|
+
children: c,
|
|
11
|
+
config: e
|
|
12
12
|
}) => {
|
|
13
|
-
const [
|
|
14
|
-
() => new
|
|
15
|
-
[
|
|
16
|
-
),
|
|
17
|
-
if (!
|
|
13
|
+
const [r, U] = u(), [s, C] = u(), [p, h] = u(), { data: n } = y(), { initializeSecretManager: M } = E(U), { orderbook: i } = _(e.orderBookUrl, e.store), b = W(
|
|
14
|
+
() => new z(e.bitcoinNetwork, e.bitcoinRPCUrl),
|
|
15
|
+
[e.bitcoinNetwork, e.bitcoinRPCUrl]
|
|
16
|
+
), O = async (t) => {
|
|
17
|
+
if (!s || !i || !r || !n)
|
|
18
18
|
return m("Garden not initialized");
|
|
19
|
-
const
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
await K(c);
|
|
30
|
-
}
|
|
31
|
-
if (f(e.val.source_swap.chain)) return O(e.val);
|
|
32
|
-
const l = await new z(
|
|
33
|
-
e.val,
|
|
34
|
-
r.orderBookUrl,
|
|
35
|
-
t,
|
|
36
|
-
{ store: r.store }
|
|
37
|
-
).init(s, 0);
|
|
38
|
-
return l.error ? m(l.error) : O(e.val);
|
|
19
|
+
const o = await s.swap(t);
|
|
20
|
+
if (o.error) return m(o.error);
|
|
21
|
+
if (w(o.val.source_swap.chain)) return f(o.val);
|
|
22
|
+
const a = await new g(
|
|
23
|
+
o.val,
|
|
24
|
+
e.orderBookUrl,
|
|
25
|
+
r,
|
|
26
|
+
{ store: e.store }
|
|
27
|
+
).init(n, 0);
|
|
28
|
+
return a.error ? m(a.error) : f(o.val);
|
|
39
29
|
};
|
|
40
|
-
return
|
|
41
|
-
if (!
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
30
|
+
return d(() => {
|
|
31
|
+
if (!r) return;
|
|
32
|
+
const t = K.fromPrivateKey(
|
|
33
|
+
r.getMasterPrivKey(),
|
|
34
|
+
b
|
|
45
35
|
);
|
|
46
|
-
|
|
47
|
-
}, [
|
|
48
|
-
if (!
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
36
|
+
h(t);
|
|
37
|
+
}, [r, b]), d(() => {
|
|
38
|
+
if (!r || !n || !i) return;
|
|
39
|
+
const t = new R(
|
|
40
|
+
i,
|
|
41
|
+
r,
|
|
42
|
+
e.orderBookUrl,
|
|
43
|
+
e.quoteUrl,
|
|
44
|
+
{
|
|
45
|
+
store: e.store
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
C(t);
|
|
49
|
+
}, [r, n, i]), d(() => {
|
|
50
|
+
if (!s) return;
|
|
51
|
+
let t;
|
|
56
52
|
return (async () => {
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
if (!
|
|
60
|
-
console.log("executing order:",
|
|
61
|
-
const
|
|
53
|
+
const v = async (a) => {
|
|
54
|
+
const l = a.getOrder(), k = w(l.source_swap.chain) ? p : n, x = w(l.destination_swap.chain) ? p : n;
|
|
55
|
+
if (!k || !x) return;
|
|
56
|
+
console.log("executing order:", l.create_order.create_id);
|
|
57
|
+
const B = await a.execute({
|
|
62
58
|
wallets: {
|
|
63
|
-
source:
|
|
64
|
-
destination:
|
|
59
|
+
source: k,
|
|
60
|
+
destination: x
|
|
65
61
|
}
|
|
66
62
|
});
|
|
67
|
-
console.log("execute result :",
|
|
63
|
+
console.log("execute result :", B.val), console.log("execute error: ", B.error);
|
|
68
64
|
};
|
|
69
|
-
|
|
65
|
+
t = await s.subscribeOrders(v);
|
|
70
66
|
})(), () => {
|
|
71
|
-
|
|
67
|
+
t();
|
|
72
68
|
};
|
|
73
|
-
}, [
|
|
74
|
-
|
|
69
|
+
}, [s]), /* @__PURE__ */ P.createElement(
|
|
70
|
+
G.Provider,
|
|
75
71
|
{
|
|
76
72
|
value: {
|
|
77
|
-
orderBookUrl:
|
|
78
|
-
initializeSecretManager:
|
|
79
|
-
orderBook:
|
|
80
|
-
swap:
|
|
73
|
+
orderBookUrl: e.orderBookUrl,
|
|
74
|
+
initializeSecretManager: M,
|
|
75
|
+
orderBook: i,
|
|
76
|
+
swap: O
|
|
81
77
|
}
|
|
82
78
|
},
|
|
83
|
-
|
|
79
|
+
c
|
|
84
80
|
);
|
|
85
|
-
},
|
|
86
|
-
const
|
|
87
|
-
if (!
|
|
81
|
+
}, L = () => {
|
|
82
|
+
const c = P.useContext(G);
|
|
83
|
+
if (!c)
|
|
88
84
|
throw new Error("useGarden must be used within a GardenProvider");
|
|
89
|
-
return
|
|
85
|
+
return c;
|
|
90
86
|
};
|
|
91
87
|
export {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
G as GardenContext,
|
|
89
|
+
J as GardenProvider,
|
|
90
|
+
L as useGarden
|
|
95
91
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/react-hooks",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.4",
|
|
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.49",
|
|
31
|
-
"@gardenfi/core": "^0.2.0-beta.
|
|
32
|
-
"@gardenfi/orderbook": "^0.2.0-beta.
|
|
33
|
-
"@gardenfi/utils": "^0.0.1-beta.
|
|
31
|
+
"@gardenfi/core": "^0.2.0-beta.4",
|
|
32
|
+
"@gardenfi/orderbook": "^0.2.0-beta.4",
|
|
33
|
+
"@gardenfi/utils": "^0.0.1-beta.4",
|
|
34
34
|
"react": "^18.3.1",
|
|
35
35
|
"viem": "^2.21.15",
|
|
36
36
|
"wagmi": "^2.12.16"
|