@gardenfi/react-hooks 0.0.1-beta.51 → 0.0.1-beta.53
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 +59 -55
- 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 t=require("react"),M=require("wagmi"),W=require("./index4.cjs"),x=require("./index3.cjs"),d=require("@gardenfi/core"),i=require("@catalogfi/utils"),_=require("@gardenfi/orderbook"),g=require("@catalogfi/wallets"),y=require("@gardenfi/utils"),K=require("./index5.cjs"),h=t.createContext({}),A=({children:w,config:e})=>{const[l,B]=t.useState(),[c,m]=t.useState(),[a,G]=t.useState(),[O,C]=t.useState(),k=new d.Quote(e.quoteUrl),{data:n}=M.useWalletClient(),{initializeSecretManager:S}=W.useSecretManager(B),{orderbook:v}=x.useOrderbook(e.orderBookUrl,a,C),U=t.useMemo(()=>new g.BitcoinProvider(e.bitcoinNetwork,e.bitcoinRPCUrl),[e.bitcoinNetwork,e.bitcoinRPCUrl]),f=async o=>{if(!v||!n||!a)return i.Err("Orderbook or walletClient or auth not initialized");let r=c;if(!l||!r){const b=await S();if(b.error)return i.Err(b.error);const p=g.BitcoinWallet.fromPrivateKey(b.val.getMasterPrivKey(),U);r=new d.Garden({orderbookURl:e.orderBookUrl,secretManager:b.val,quote:k,auth:a,wallets:{evmWallet:n,btcWallet:p}}),m(r)}const s=await r.swap(o);if(s.error)return i.Err(s.error);if(_.isBitcoin(s.val.source_swap.chain))return i.Ok(s.val);const u=await d.switchOrAddNetwork(o.fromAsset.chain,n);if(u.error)return i.Err("Failed to switch network: "+u.error);const q=u.val.walletClient;console.log("newWalletClient :",q);const P=await new d.EvmRelay(s.val,e.orderBookUrl,a).init(q);if(P.error)return i.Err(P.error);const R={...s.val,source_swap:{...s.val.source_swap,initiate_tx_hash:P.val}};return i.Ok(R)},E=async({fromAsset:o,toAsset:r,amount:s,isExactOut:u=!1})=>await k.getQuote(K.constructOrderpair(o,r),s,u);return t.useEffect(()=>{if(!n)return;const o=new y.Siwe(new y.Url(e.orderBookUrl),n,{store:e.store});G(o)},[n]),t.useEffect(()=>{if(!l||!n||!v||!a)return;const o=g.BitcoinWallet.fromPrivateKey(l.getMasterPrivKey(),U),r=new d.Garden({orderbookURl:e.orderBookUrl,secretManager:l,quote:k,auth:a,wallets:{evmWallet:n,btcWallet:o}});m(r)},[l,n,v,a]),t.useEffect(()=>{if(!c)return;const o=c.execute();return console.log("ℹ️ Started executing orders..."),c.on("onPendingOrdersChanged",r=>{C(r)}),()=>{console.log("🟣 Stopped executing orders..."),(async()=>(await o)())()}},[c]),t.createElement(h.Provider,{value:{orderBookUrl:e.orderBookUrl,initializeSecretManager:S,orderBook:v,swap:f,pendingOrders:O,getQuote:E,secretManager:l,garden:c}},w)},F=()=>{const w=t.useContext(h);if(!w)throw new Error("useGarden must be used within a GardenProvider");return w};exports.GardenContext=h;exports.GardenProvider=A;exports.useGarden=F;
|
package/dist/index2.js
CHANGED
|
@@ -1,113 +1,117 @@
|
|
|
1
|
-
import
|
|
1
|
+
import g, { createContext as _, useState as m, useMemo as K, useEffect as b } from "react";
|
|
2
2
|
import { useWalletClient as A } from "wagmi";
|
|
3
|
-
import { useSecretManager as
|
|
4
|
-
import { useOrderbook as
|
|
5
|
-
import { Quote as
|
|
3
|
+
import { useSecretManager as F } from "./index4.js";
|
|
4
|
+
import { useOrderbook as N } from "./index3.js";
|
|
5
|
+
import { Quote as Q, Garden as C, switchOrAddNetwork as q, EvmRelay as z } from "@gardenfi/core";
|
|
6
6
|
import { Err as c, Ok as B } from "@catalogfi/utils";
|
|
7
7
|
import { isBitcoin as j } from "@gardenfi/orderbook";
|
|
8
8
|
import { BitcoinProvider as D, BitcoinWallet as R } from "@catalogfi/wallets";
|
|
9
9
|
import { Siwe as H, Url as I } from "@gardenfi/utils";
|
|
10
10
|
import { constructOrderpair as J } from "./index5.js";
|
|
11
|
-
const
|
|
11
|
+
const y = _({}), ne = ({
|
|
12
12
|
children: d,
|
|
13
13
|
config: e
|
|
14
14
|
}) => {
|
|
15
|
-
const [s,
|
|
15
|
+
const [s, O] = m(), [i, k] = m(), [a, x] = m(), [G, f] = m(), v = new Q(e.quoteUrl), { data: o } = A(), { initializeSecretManager: h } = F(O), { orderbook: u } = N(
|
|
16
16
|
e.orderBookUrl,
|
|
17
17
|
a,
|
|
18
|
-
|
|
18
|
+
f
|
|
19
19
|
), P = K(
|
|
20
20
|
() => new D(e.bitcoinNetwork, e.bitcoinRPCUrl),
|
|
21
21
|
[e.bitcoinNetwork, e.bitcoinRPCUrl]
|
|
22
|
-
),
|
|
23
|
-
if (!u || !
|
|
22
|
+
), M = async (t) => {
|
|
23
|
+
if (!u || !o || !a)
|
|
24
24
|
return c("Orderbook or walletClient or auth not initialized");
|
|
25
|
-
let
|
|
26
|
-
if (!s || !
|
|
27
|
-
const w = await
|
|
25
|
+
let r = i;
|
|
26
|
+
if (!s || !r) {
|
|
27
|
+
const w = await h();
|
|
28
28
|
if (w.error) return c(w.error);
|
|
29
29
|
const E = R.fromPrivateKey(
|
|
30
30
|
w.val.getMasterPrivKey(),
|
|
31
31
|
P
|
|
32
32
|
);
|
|
33
|
-
|
|
33
|
+
r = new C({
|
|
34
34
|
orderbookURl: e.orderBookUrl,
|
|
35
35
|
secretManager: w.val,
|
|
36
36
|
quote: v,
|
|
37
37
|
auth: a,
|
|
38
38
|
wallets: {
|
|
39
|
-
evmWallet:
|
|
39
|
+
evmWallet: o,
|
|
40
40
|
btcWallet: E
|
|
41
41
|
}
|
|
42
|
-
}),
|
|
42
|
+
}), k(r);
|
|
43
43
|
}
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
if (j(
|
|
47
|
-
const l = await
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
const n = await r.swap(t);
|
|
45
|
+
if (n.error) return c(n.error);
|
|
46
|
+
if (j(n.val.source_swap.chain)) return B(n.val);
|
|
47
|
+
const l = await q(
|
|
48
|
+
t.fromAsset.chain,
|
|
49
|
+
o
|
|
50
50
|
);
|
|
51
51
|
if (l.error)
|
|
52
52
|
return c("Failed to switch network: " + l.error);
|
|
53
53
|
const U = l.val.walletClient;
|
|
54
54
|
console.log("newWalletClient :", U);
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
55
|
+
const p = await new z(n.val, e.orderBookUrl, a).init(U);
|
|
56
|
+
if (p.error) return c(p.error);
|
|
57
57
|
const S = {
|
|
58
|
-
...
|
|
58
|
+
...n.val,
|
|
59
59
|
source_swap: {
|
|
60
|
-
...
|
|
61
|
-
initiate_tx_hash:
|
|
60
|
+
...n.val.source_swap,
|
|
61
|
+
initiate_tx_hash: p.val
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
return B(S);
|
|
65
|
-
},
|
|
66
|
-
fromAsset:
|
|
67
|
-
toAsset:
|
|
68
|
-
amount:
|
|
65
|
+
}, W = async ({
|
|
66
|
+
fromAsset: t,
|
|
67
|
+
toAsset: r,
|
|
68
|
+
amount: n,
|
|
69
69
|
isExactOut: l = !1
|
|
70
70
|
}) => await v.getQuote(
|
|
71
|
-
J(
|
|
72
|
-
|
|
71
|
+
J(t, r),
|
|
72
|
+
n,
|
|
73
73
|
l
|
|
74
74
|
);
|
|
75
|
-
return
|
|
76
|
-
if (!
|
|
77
|
-
const
|
|
75
|
+
return b(() => {
|
|
76
|
+
if (!o) return;
|
|
77
|
+
const t = new H(new I(e.orderBookUrl), o, {
|
|
78
78
|
store: e.store
|
|
79
79
|
});
|
|
80
|
-
|
|
81
|
-
}, [
|
|
82
|
-
if (!s || !
|
|
83
|
-
const
|
|
80
|
+
x(t);
|
|
81
|
+
}, [o]), b(() => {
|
|
82
|
+
if (!s || !o || !u || !a) return;
|
|
83
|
+
const t = R.fromPrivateKey(
|
|
84
84
|
s.getMasterPrivKey(),
|
|
85
85
|
P
|
|
86
|
-
),
|
|
86
|
+
), r = new C({
|
|
87
87
|
orderbookURl: e.orderBookUrl,
|
|
88
88
|
secretManager: s,
|
|
89
89
|
quote: v,
|
|
90
90
|
auth: a,
|
|
91
91
|
wallets: {
|
|
92
|
-
evmWallet:
|
|
93
|
-
btcWallet:
|
|
92
|
+
evmWallet: o,
|
|
93
|
+
btcWallet: t
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
|
-
|
|
97
|
-
}, [s,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
k(r);
|
|
97
|
+
}, [s, o, u, a]), b(() => {
|
|
98
|
+
if (!i) return;
|
|
99
|
+
const t = i.execute();
|
|
100
|
+
return console.log("ℹ️ Started executing orders..."), i.on("onPendingOrdersChanged", (r) => {
|
|
101
|
+
f(r);
|
|
102
|
+
}), () => {
|
|
103
|
+
console.log("🟣 Stopped executing orders..."), (async () => (await t)())();
|
|
104
|
+
};
|
|
105
|
+
}, [i]), /* @__PURE__ */ g.createElement(
|
|
106
|
+
y.Provider,
|
|
103
107
|
{
|
|
104
108
|
value: {
|
|
105
109
|
orderBookUrl: e.orderBookUrl,
|
|
106
|
-
initializeSecretManager:
|
|
110
|
+
initializeSecretManager: h,
|
|
107
111
|
orderBook: u,
|
|
108
|
-
swap:
|
|
109
|
-
pendingOrders:
|
|
110
|
-
getQuote:
|
|
112
|
+
swap: M,
|
|
113
|
+
pendingOrders: G,
|
|
114
|
+
getQuote: W,
|
|
111
115
|
secretManager: s,
|
|
112
116
|
garden: i
|
|
113
117
|
}
|
|
@@ -115,13 +119,13 @@ const O = _({}), ne = ({
|
|
|
115
119
|
d
|
|
116
120
|
);
|
|
117
121
|
}, ae = () => {
|
|
118
|
-
const d =
|
|
122
|
+
const d = g.useContext(y);
|
|
119
123
|
if (!d)
|
|
120
124
|
throw new Error("useGarden must be used within a GardenProvider");
|
|
121
125
|
return d;
|
|
122
126
|
};
|
|
123
127
|
export {
|
|
124
|
-
|
|
128
|
+
y as GardenContext,
|
|
125
129
|
ne as GardenProvider,
|
|
126
130
|
ae as useGarden
|
|
127
131
|
};
|
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.53",
|
|
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.50",
|
|
31
|
-
"@gardenfi/core": "^0.2.0-beta.
|
|
31
|
+
"@gardenfi/core": "^0.2.0-beta.34",
|
|
32
32
|
"@gardenfi/orderbook": "^0.2.0-beta.11",
|
|
33
33
|
"@gardenfi/utils": "^0.0.1-beta.18",
|
|
34
34
|
"react": "^18.3.1",
|