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