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