@gardenfi/react-hooks 0.0.1-beta.49 → 0.0.1-beta.50
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 +19 -19
- package/package.json +1 -1
package/dist/index2.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),W=require("wagmi"),p=require("./index4.cjs"),x=require("./index3.cjs"),d=require("@gardenfi/core"),i=require("@catalogfi/utils"),_=require("@gardenfi/orderbook"),h=require("@catalogfi/wallets"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),W=require("wagmi"),p=require("./index4.cjs"),x=require("./index3.cjs"),d=require("@gardenfi/core"),i=require("@catalogfi/utils"),_=require("@gardenfi/orderbook"),h=require("@catalogfi/wallets"),G=require("@gardenfi/utils"),K=require("./index5.cjs"),m=r.createContext({}),A=({children:w,config:e})=>{const[l,O]=r.useState(),[c,C]=r.useState(),[s,S]=r.useState(),[f,U]=r.useState(),b=new d.Quote(e.quoteUrl),{data:o}=W.useWalletClient(),{initializeSecretManager:g}=p.useSecretManager(O),{orderbook:v}=x.useOrderbook(e.orderBookUrl,s,U),q=r.useMemo(()=>new h.BitcoinProvider(e.bitcoinNetwork,e.bitcoinRPCUrl),[e.bitcoinNetwork,e.bitcoinRPCUrl]),y=async t=>{if(!v||!o||!s)return i.Err("Orderbook or walletClient or auth not initialized");let a=c;if(!l||!a){const k=await g();if(k.error)return i.Err(k.error);const M=h.BitcoinWallet.fromPrivateKey(k.val.getMasterPrivKey(),q);a=new d.Garden({orderbookURl:e.orderBookUrl,secretManager:k.val,quote:b,auth:s,wallets:{evmWallet:o,btcWallet:M}}),C(a)}const n=await a.swap(t);if(n.error)return i.Err(n.error);if(_.isBitcoin(n.val.source_swap.chain))return i.Ok(n.val);const u=await d.switchOrAddNetwork(t.fromAsset.chain,o);if(u.error)return i.Err("Failed to switch network: "+u.error);const B=u.val.walletClient;console.log("newWalletClient :",B);const P=await new d.EvmRelay(n.val,e.orderBookUrl,s).init(B);if(P.error)return i.Err(P.error);const R={...n.val,source_swap:{...n.val.source_swap,initiate_tx_hash:P.val}};return i.Ok(R)},E=async({fromAsset:t,toAsset:a,amount:n,isExactOut:u=!1})=>await b.getQuote(K.constructOrderpair(t,a),n,u);return r.useEffect(()=>{if(!o)return;const t=new G.Siwe(new G.Url(e.orderBookUrl),o,{store:e.store});S(t)},[o]),r.useEffect(()=>{if(!l||!o||!v||!s)return;const t=h.BitcoinWallet.fromPrivateKey(l.getMasterPrivKey(),q),a=new d.Garden({orderbookURl:e.orderBookUrl,secretManager:l,quote:b,auth:s,wallets:{evmWallet:o,btcWallet:t}});C(a)},[l,o,v,s]),r.useEffect(()=>{c&&(c.execute(),console.log("ℹ️ Started executing orders..."),c.on("onPendingOrdersChanged",t=>{U(t)}))},[c]),r.createElement(m.Provider,{value:{orderBookUrl:e.orderBookUrl,initializeSecretManager:g,orderBook:v,swap:y,pendingOrders:f,getQuote:E,secretManager:l,garden:c}},w)},N=()=>{const w=r.useContext(m);if(!w)throw new Error("useGarden must be used within a GardenProvider");return w};exports.GardenContext=m;exports.GardenProvider=A;exports.useGarden=N;
|
package/dist/index2.js
CHANGED
|
@@ -12,21 +12,21 @@ const O = _({}), ne = ({
|
|
|
12
12
|
children: d,
|
|
13
13
|
config: e
|
|
14
14
|
}) => {
|
|
15
|
-
const [
|
|
15
|
+
const [s, g] = m(), [i, f] = m(), [a, G] = m(), [M, h] = m(), v = new q(e.quoteUrl), { data: t } = A(), { initializeSecretManager: b } = N(g), { orderbook: u } = Q(
|
|
16
16
|
e.orderBookUrl,
|
|
17
17
|
a,
|
|
18
18
|
h
|
|
19
19
|
), P = K(
|
|
20
20
|
() => new D(e.bitcoinNetwork, e.bitcoinRPCUrl),
|
|
21
21
|
[e.bitcoinNetwork, e.bitcoinRPCUrl]
|
|
22
|
-
),
|
|
22
|
+
), W = async (r) => {
|
|
23
23
|
if (!u || !t || !a)
|
|
24
24
|
return c("Orderbook or walletClient or auth not initialized");
|
|
25
|
-
let n =
|
|
26
|
-
if (!
|
|
25
|
+
let n = i;
|
|
26
|
+
if (!s || !n) {
|
|
27
27
|
const w = await b();
|
|
28
28
|
if (w.error) return c(w.error);
|
|
29
|
-
const
|
|
29
|
+
const E = R.fromPrivateKey(
|
|
30
30
|
w.val.getMasterPrivKey(),
|
|
31
31
|
P
|
|
32
32
|
);
|
|
@@ -37,7 +37,7 @@ const O = _({}), ne = ({
|
|
|
37
37
|
auth: a,
|
|
38
38
|
wallets: {
|
|
39
39
|
evmWallet: t,
|
|
40
|
-
btcWallet:
|
|
40
|
+
btcWallet: E
|
|
41
41
|
}
|
|
42
42
|
}), f(n);
|
|
43
43
|
}
|
|
@@ -54,14 +54,14 @@ const O = _({}), ne = ({
|
|
|
54
54
|
console.log("newWalletClient :", U);
|
|
55
55
|
const k = await new F(o.val, e.orderBookUrl, a).init(U);
|
|
56
56
|
if (k.error) return c(k.error);
|
|
57
|
-
const
|
|
57
|
+
const S = {
|
|
58
58
|
...o.val,
|
|
59
59
|
source_swap: {
|
|
60
60
|
...o.val.source_swap,
|
|
61
61
|
initiate_tx_hash: k.val
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
|
-
return B(
|
|
64
|
+
return B(S);
|
|
65
65
|
}, x = async ({
|
|
66
66
|
fromAsset: r,
|
|
67
67
|
toAsset: n,
|
|
@@ -77,15 +77,15 @@ const O = _({}), ne = ({
|
|
|
77
77
|
const r = new H(new I(e.orderBookUrl), t, {
|
|
78
78
|
store: e.store
|
|
79
79
|
});
|
|
80
|
-
|
|
80
|
+
G(r);
|
|
81
81
|
}, [t]), p(() => {
|
|
82
|
-
if (!
|
|
82
|
+
if (!s || !t || !u || !a) return;
|
|
83
83
|
const r = R.fromPrivateKey(
|
|
84
|
-
|
|
84
|
+
s.getMasterPrivKey(),
|
|
85
85
|
P
|
|
86
86
|
), n = new C({
|
|
87
87
|
orderbookURl: e.orderBookUrl,
|
|
88
|
-
secretManager:
|
|
88
|
+
secretManager: s,
|
|
89
89
|
quote: v,
|
|
90
90
|
auth: a,
|
|
91
91
|
wallets: {
|
|
@@ -94,22 +94,22 @@ const O = _({}), ne = ({
|
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
96
|
f(n);
|
|
97
|
-
}, [
|
|
98
|
-
|
|
97
|
+
}, [s, t, u, a]), p(() => {
|
|
98
|
+
i && (i.execute(), console.log("ℹ️ Started executing orders..."), i.on("onPendingOrdersChanged", (r) => {
|
|
99
99
|
h(r);
|
|
100
100
|
}));
|
|
101
|
-
}, [
|
|
101
|
+
}, [i]), /* @__PURE__ */ y.createElement(
|
|
102
102
|
O.Provider,
|
|
103
103
|
{
|
|
104
104
|
value: {
|
|
105
105
|
orderBookUrl: e.orderBookUrl,
|
|
106
106
|
initializeSecretManager: b,
|
|
107
107
|
orderBook: u,
|
|
108
|
-
swap:
|
|
109
|
-
pendingOrders:
|
|
108
|
+
swap: W,
|
|
109
|
+
pendingOrders: M,
|
|
110
110
|
getQuote: x,
|
|
111
|
-
secretManager:
|
|
112
|
-
garden:
|
|
111
|
+
secretManager: s,
|
|
112
|
+
garden: i
|
|
113
113
|
}
|
|
114
114
|
},
|
|
115
115
|
d
|