@gardenfi/react-hooks 0.0.1-beta.100 → 0.0.1-beta.102
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 +37 -39
- package/package.json +3 -3
package/dist/index2.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),x=require("wagmi"),z=require("./index4.cjs"),A=require("./index3.cjs"),u=require("@gardenfi/core"),n=require("@catalogfi/utils"),G=require("@gardenfi/orderbook"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),x=require("wagmi"),z=require("./index4.cjs"),A=require("./index3.cjs"),u=require("@gardenfi/core"),n=require("@catalogfi/utils"),G=require("@gardenfi/orderbook"),b=require("@catalogfi/wallets"),q=require("@gardenfi/utils"),K=require("./index5.cjs"),R=a.createContext({isExecuting:!1}),Q=({children:h,config:r})=>{const[c,S]=a.useState(),[l,U]=a.useState(),[s,N]=a.useState(),[O,y]=a.useState(),_=a.useMemo(()=>!!(c&&l&&s&&O),[c,l,s,O]),w=a.useMemo(()=>new u.Quote(r.quoteUrl),[r.quoteUrl]),B=a.useMemo(()=>{const e=r.network===b.BitcoinNetwork.Mainnet?"mainnet":r.network===b.BitcoinNetwork.Testnet?"testnet":void 0;return r.blockNumberFetcherUrl&&e?new u.BlockNumberFetcher(r.blockNumberFetcherUrl,e):void 0},[r.blockNumberFetcherUrl,r.network]),M=a.useMemo(()=>new b.BitcoinProvider(r.network,r.bitcoinRPCUrl),[r.network,r.bitcoinRPCUrl]),{data:i}=x.useWalletClient(),{initializeSecretManager:P}=z.useSecretManager(S),{orderbook:m}=A.useOrderbook(r.orderBookUrl,s,y,B),f=async()=>{if(!i||!s)return n.Err("WalletClient or auth not initialized");const e=await P();if(e.error)return n.Err(e.error);const o=b.BitcoinWallet.fromPrivateKey(e.val.getMasterPrivKey(),M),t=new u.Garden({orderbookURl:r.orderBookUrl,secretManager:e.val,quote:w,auth:s,wallets:{evmWallet:i,btcWallet:o},blockNumberFetcher:B});return U(t),n.Ok(t)},g=async e=>{if(!m||!i||!s)return n.Err("Orderbook or walletClient or auth not initialized");let o=l;if(!c||!o){const C=await f();if(C.error)return n.Err(C.error);o=C.val}const t=await o.swap(e);if(t.error)return n.Err(t.error);if(G.isBitcoin(t.val.source_swap.chain))return n.Ok(t.val);const d=await u.switchOrAddNetwork(e.fromAsset.chain,i);if(d.error)return n.Err("Failed to switch network: "+d.error);const p=d.val.walletClient,k=await new u.EvmRelay(t.val,r.orderBookUrl,s).init(p);if(k.error)return n.Err(k.error);const v={...t.val,source_swap:{...t.val.source_swap,initiate_tx_hash:k.val}};return n.Ok(v)},F=async e=>{if(!i||!s)return n.Err("Orderbook or walletClient or auth not initialized");if(G.isBitcoin(e.source_swap.chain))return n.Err("Not an EVM order: sourceSwap.chain is Bitcoin");let o=l;if(!c||!o){const v=await f();if(v.error)return n.Err(v.error);o=v.val}const t=await u.switchOrAddNetwork(e.source_swap.chain,i);if(t.error)return n.Err("Failed to switch network: "+t.error);const d=t.val.walletClient,E=await new u.EvmRelay(e,r.orderBookUrl,s).init(d);if(E.error)return n.Err(E.error);const k={...e,source_swap:{...e.source_swap,initiate_tx_hash:E.val}};return n.Ok(k)},W=a.useMemo(()=>async({fromAsset:e,toAsset:o,amount:t,isExactOut:d=!1})=>await w.getQuote(K.constructOrderpair(e,o),t,d),[w]);return a.useEffect(()=>{if(!i)return;const e=new q.Siwe(new q.Url(r.orderBookUrl),i,{store:r.store});N(e)},[i]),a.useEffect(()=>{if(!c||!i||!m||!s)return;const e=b.BitcoinWallet.fromPrivateKey(c.getMasterPrivKey(),M),o=new u.Garden({orderbookURl:r.orderBookUrl,secretManager:c,quote:w,auth:s,wallets:{evmWallet:i,btcWallet:e},blockNumberFetcher:B});U(o)},[c,i,m,s]),a.useEffect(()=>{if(!l)return;const e=l.execute(),o=t=>y(t);return l.on("onPendingOrdersChanged",o),()=>{(async()=>(await e)())(),l.off("onPendingOrdersChanged",o)}},[l]),a.createElement(R.Provider,{value:{orderBookUrl:r.orderBookUrl,initializeSecretManager:P,orderBook:m,swap:g,pendingOrders:O,getQuote:W,secretManager:c,garden:l,isExecuting:_,evmInitiate:F,quote:w}},h)},$=()=>{const h=a.useContext(R);if(!h)throw new Error("useGarden must be used within a GardenProvider");return h};exports.GardenContext=R;exports.GardenProvider=Q;exports.useGarden=$;
|
package/dist/index2.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import S, { createContext as T, useState as
|
|
1
|
+
import S, { createContext as T, useState as b, useMemo as m, useEffect as R } from "react";
|
|
2
2
|
import { useWalletClient as V } from "wagmi";
|
|
3
3
|
import { useSecretManager as j } from "./index4.js";
|
|
4
4
|
import { useOrderbook as D } from "./index3.js";
|
|
@@ -11,22 +11,22 @@ import { constructOrderpair as Z } from "./index5.js";
|
|
|
11
11
|
const g = T({
|
|
12
12
|
isExecuting: !1
|
|
13
13
|
}), ce = ({
|
|
14
|
-
children:
|
|
14
|
+
children: v,
|
|
15
15
|
config: r
|
|
16
16
|
}) => {
|
|
17
|
-
const [l, z] =
|
|
17
|
+
const [l, z] = b(), [s, B] = b(), [n, K] = b(), [f, P] = b(), q = m(
|
|
18
18
|
() => !!(l && s && n && f),
|
|
19
19
|
[l, s, n, f]
|
|
20
|
-
),
|
|
20
|
+
), u = m(() => new H(r.quoteUrl), [r.quoteUrl]), U = m(() => {
|
|
21
21
|
const e = r.network === W.Mainnet ? "mainnet" : r.network === W.Testnet ? "testnet" : void 0;
|
|
22
22
|
return r.blockNumberFetcherUrl && e ? new J(
|
|
23
23
|
r.blockNumberFetcherUrl,
|
|
24
24
|
e
|
|
25
25
|
) : void 0;
|
|
26
|
-
}, [r.blockNumberFetcherUrl, r.network]), y =
|
|
26
|
+
}, [r.blockNumberFetcherUrl, r.network]), y = m(
|
|
27
27
|
() => new L(r.network, r.bitcoinRPCUrl),
|
|
28
28
|
[r.network, r.bitcoinRPCUrl]
|
|
29
|
-
), { data: a } = V(), { initializeSecretManager: O } = j(z), { orderbook:
|
|
29
|
+
), { data: a } = V(), { initializeSecretManager: O } = j(z), { orderbook: h } = D(
|
|
30
30
|
r.orderBookUrl,
|
|
31
31
|
n,
|
|
32
32
|
P,
|
|
@@ -42,7 +42,7 @@ const g = T({
|
|
|
42
42
|
), t = new F({
|
|
43
43
|
orderbookURl: r.orderBookUrl,
|
|
44
44
|
secretManager: e.val,
|
|
45
|
-
quote:
|
|
45
|
+
quote: u,
|
|
46
46
|
auth: n,
|
|
47
47
|
wallets: {
|
|
48
48
|
evmWallet: a,
|
|
@@ -52,7 +52,7 @@ const g = T({
|
|
|
52
52
|
});
|
|
53
53
|
return B(t), p(t);
|
|
54
54
|
}, A = async (e) => {
|
|
55
|
-
if (!
|
|
55
|
+
if (!h || !a || !n)
|
|
56
56
|
return i("Orderbook or walletClient or auth not initialized");
|
|
57
57
|
let o = s;
|
|
58
58
|
if (!l || !o) {
|
|
@@ -69,16 +69,16 @@ const g = T({
|
|
|
69
69
|
);
|
|
70
70
|
if (c.error)
|
|
71
71
|
return i("Failed to switch network: " + c.error);
|
|
72
|
-
const _ = c.val.walletClient,
|
|
73
|
-
if (
|
|
74
|
-
const
|
|
72
|
+
const _ = c.val.walletClient, d = await new N(t.val, r.orderBookUrl, n).init(_);
|
|
73
|
+
if (d.error) return i(d.error);
|
|
74
|
+
const w = {
|
|
75
75
|
...t.val,
|
|
76
76
|
source_swap: {
|
|
77
77
|
...t.val.source_swap,
|
|
78
|
-
initiate_tx_hash:
|
|
78
|
+
initiate_tx_hash: d.val
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
|
-
return p(
|
|
81
|
+
return p(w);
|
|
82
82
|
}, Q = async (e) => {
|
|
83
83
|
if (!a || !n)
|
|
84
84
|
return i("Orderbook or walletClient or auth not initialized");
|
|
@@ -86,9 +86,9 @@ const g = T({
|
|
|
86
86
|
return i("Not an EVM order: sourceSwap.chain is Bitcoin");
|
|
87
87
|
let o = s;
|
|
88
88
|
if (!l || !o) {
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
91
|
-
o =
|
|
89
|
+
const w = await M();
|
|
90
|
+
if (w.error) return i(w.error);
|
|
91
|
+
o = w.val;
|
|
92
92
|
}
|
|
93
93
|
const t = await G(
|
|
94
94
|
e.source_swap.chain,
|
|
@@ -96,25 +96,23 @@ const g = T({
|
|
|
96
96
|
);
|
|
97
97
|
if (t.error)
|
|
98
98
|
return i("Failed to switch network: " + t.error);
|
|
99
|
-
const c = t.val.walletClient,
|
|
100
|
-
if (
|
|
101
|
-
const
|
|
99
|
+
const c = t.val.walletClient, k = await new N(e, r.orderBookUrl, n).init(c);
|
|
100
|
+
if (k.error) return i(k.error);
|
|
101
|
+
const d = {
|
|
102
102
|
...e,
|
|
103
103
|
source_swap: {
|
|
104
104
|
...e.source_swap,
|
|
105
|
-
initiate_tx_hash:
|
|
105
|
+
initiate_tx_hash: k.val
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
|
-
return p(
|
|
109
|
-
}, I =
|
|
110
|
-
fromAsset: e,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
t,
|
|
117
|
-
c
|
|
108
|
+
return p(d);
|
|
109
|
+
}, I = m(
|
|
110
|
+
() => async ({ fromAsset: e, toAsset: o, amount: t, isExactOut: c = !1 }) => await u.getQuote(
|
|
111
|
+
Z(e, o),
|
|
112
|
+
t,
|
|
113
|
+
c
|
|
114
|
+
),
|
|
115
|
+
[u]
|
|
118
116
|
);
|
|
119
117
|
return R(() => {
|
|
120
118
|
if (!a) return;
|
|
@@ -123,14 +121,14 @@ const g = T({
|
|
|
123
121
|
});
|
|
124
122
|
K(e);
|
|
125
123
|
}, [a]), R(() => {
|
|
126
|
-
if (!l || !a || !
|
|
124
|
+
if (!l || !a || !h || !n) return;
|
|
127
125
|
const e = E.fromPrivateKey(
|
|
128
126
|
l.getMasterPrivKey(),
|
|
129
127
|
y
|
|
130
128
|
), o = new F({
|
|
131
129
|
orderbookURl: r.orderBookUrl,
|
|
132
130
|
secretManager: l,
|
|
133
|
-
quote:
|
|
131
|
+
quote: u,
|
|
134
132
|
auth: n,
|
|
135
133
|
wallets: {
|
|
136
134
|
evmWallet: a,
|
|
@@ -139,7 +137,7 @@ const g = T({
|
|
|
139
137
|
blockNumberFetcher: U
|
|
140
138
|
});
|
|
141
139
|
B(o);
|
|
142
|
-
}, [l, a,
|
|
140
|
+
}, [l, a, h, n]), R(() => {
|
|
143
141
|
if (!s) return;
|
|
144
142
|
const e = s.execute(), o = (t) => P(t);
|
|
145
143
|
return s.on("onPendingOrdersChanged", o), () => {
|
|
@@ -151,7 +149,7 @@ const g = T({
|
|
|
151
149
|
value: {
|
|
152
150
|
orderBookUrl: r.orderBookUrl,
|
|
153
151
|
initializeSecretManager: O,
|
|
154
|
-
orderBook:
|
|
152
|
+
orderBook: h,
|
|
155
153
|
swap: A,
|
|
156
154
|
pendingOrders: f,
|
|
157
155
|
getQuote: I,
|
|
@@ -159,16 +157,16 @@ const g = T({
|
|
|
159
157
|
garden: s,
|
|
160
158
|
isExecuting: q,
|
|
161
159
|
evmInitiate: Q,
|
|
162
|
-
quote:
|
|
160
|
+
quote: u
|
|
163
161
|
}
|
|
164
162
|
},
|
|
165
|
-
|
|
163
|
+
v
|
|
166
164
|
);
|
|
167
165
|
}, ue = () => {
|
|
168
|
-
const
|
|
169
|
-
if (!
|
|
166
|
+
const v = S.useContext(g);
|
|
167
|
+
if (!v)
|
|
170
168
|
throw new Error("useGarden must be used within a GardenProvider");
|
|
171
|
-
return
|
|
169
|
+
return v;
|
|
172
170
|
};
|
|
173
171
|
export {
|
|
174
172
|
g as GardenContext,
|
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.102",
|
|
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.51",
|
|
31
|
-
"@gardenfi/core": "^0.2.0-beta.
|
|
32
|
-
"@gardenfi/orderbook": "^0.2.0-beta.
|
|
31
|
+
"@gardenfi/core": "^0.2.0-beta.81",
|
|
32
|
+
"@gardenfi/orderbook": "^0.2.0-beta.20",
|
|
33
33
|
"@gardenfi/utils": "^0.0.1-beta.18",
|
|
34
34
|
"react": "^18.3.1",
|
|
35
35
|
"viem": "^2.21.15",
|