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