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