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