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