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