@gardenfi/react-hooks 0.0.1-beta.98 → 0.0.2-beta.0

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/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index2.cjs"),r=require("./index3.cjs"),o=require("./index4.cjs"),t=require("@catalogfi/wallets");exports.GardenProvider=e.GardenProvider;exports.useGarden=e.useGarden;exports.useOrderbook=r.useOrderbook;exports.useSecretManager=o.useSecretManager;Object.defineProperty(exports,"BitcoinNetwork",{enumerable:!0,get:()=>t.BitcoinNetwork});
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index2.cjs"),o=require("./index3.cjs"),n=require("@catalogfi/wallets"),r=require("./index4.cjs");exports.GardenProvider=e.GardenProvider;exports.useGarden=e.useGarden;exports.useOrderbook=o.useOrderbook;Object.defineProperty(exports,"BitcoinNetwork",{enumerable:!0,get:()=>n.BitcoinNetwork});exports.GARDEN_CONFIG=r.GARDEN_CONFIG;exports.environment=r.environment;
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
- import { GardenProvider as o, useGarden as t } from "./index2.js";
2
- import { useOrderbook as d } from "./index3.js";
3
- import { useSecretManager as m } from "./index4.js";
4
- import { BitcoinNetwork as p } from "@catalogfi/wallets";
1
+ import { GardenProvider as e, useGarden as t } from "./index2.js";
2
+ import { useOrderbook as m } from "./index3.js";
3
+ import { BitcoinNetwork as f } from "@catalogfi/wallets";
4
+ import { GARDEN_CONFIG as p, environment as x } from "./index4.js";
5
5
  export {
6
- p as BitcoinNetwork,
7
- o as GardenProvider,
6
+ f as BitcoinNetwork,
7
+ p as GARDEN_CONFIG,
8
+ e as GardenProvider,
9
+ x as environment,
8
10
  t as useGarden,
9
- d as useOrderbook,
10
- m as useSecretManager
11
+ m as useOrderbook
11
12
  };
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"),d=require("@gardenfi/core"),n=require("@catalogfi/utils"),G=require("@gardenfi/orderbook"),v=require("@catalogfi/wallets"),q=require("@gardenfi/utils"),K=require("./index5.cjs"),R=a.createContext({isExecuting:!1}),Q=({children:b,config:r})=>{const[c,S]=a.useState(),[l,U]=a.useState(),[i,g]=a.useState(),[C,y]=a.useState(),N=a.useMemo(()=>!!(c&&l&&i&&C),[c,l,i,C]),h=a.useMemo(()=>new d.Quote(r.quoteUrl),[r.quoteUrl]),O=a.useMemo(()=>{const e=r.network===v.BitcoinNetwork.Mainnet?"mainnet":r.network===v.BitcoinNetwork.Testnet?"testnet":void 0;return r.blockNumberFetcherUrl&&e?new d.BlockNumberFetcher(r.blockNumberFetcherUrl,e):void 0},[r.blockNumberFetcherUrl,r.network]),P=a.useMemo(()=>new v.BitcoinProvider(r.network,r.bitcoinRPCUrl),[r.network,r.bitcoinRPCUrl]),{data:s}=x.useWalletClient(),{initializeSecretManager:M}=z.useSecretManager(S),{orderbook:m}=A.useOrderbook(r.orderBookUrl,i,y,O),f=async()=>{if(!s||!i)return n.Err("WalletClient or auth not initialized");const e=await M();if(e.error)return n.Err(e.error);const o=v.BitcoinWallet.fromPrivateKey(e.val.getMasterPrivKey(),P),t=new d.Garden({orderbookURl:r.orderBookUrl,secretManager:e.val,quote:h,auth:i,wallets:{evmWallet:s,btcWallet:o},blockNumberFetcher:O});return U(t),n.Ok(t)},W=async e=>{if(!m||!s||!i)return n.Err("Orderbook or walletClient or auth not initialized");let o=l;if(!c||!o){const B=await f();if(B.error)return n.Err(B.error);o=B.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 u=await d.switchOrAddNetwork(e.fromAsset.chain,s);if(u.error)return n.Err("Failed to switch network: "+u.error);const p=u.val.walletClient,w=await new d.EvmRelay(t.val,r.orderBookUrl,i).init(p);if(w.error)return n.Err(w.error);const k={...t.val,source_swap:{...t.val.source_swap,initiate_tx_hash:w.val}};return n.Ok(k)},_=async e=>{if(console.log("walletClient inside evmInitiate :",s),!s||!i)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 k=await f();if(k.error)return n.Err(k.error);o=k.val}const t=await d.switchOrAddNetwork(e.source_swap.chain,s);if(t.error)return n.Err("Failed to switch network: "+t.error);const u=t.val.walletClient;console.log("newWalletClient :",u);const E=await new d.EvmRelay(e,r.orderBookUrl,i).init(u);if(E.error)return n.Err(E.error);const w={...e,source_swap:{...e.source_swap,initiate_tx_hash:E.val}};return n.Ok(w)},F=async({fromAsset:e,toAsset:o,amount:t,isExactOut:u=!1})=>await h.getQuote(K.constructOrderpair(e,o),t,u);return a.useEffect(()=>{if(!s)return;const e=new q.Siwe(new q.Url(r.orderBookUrl),s,{store:r.store});g(e)},[s]),a.useEffect(()=>{if(!c||!s||!m||!i)return;const e=v.BitcoinWallet.fromPrivateKey(c.getMasterPrivKey(),P),o=new d.Garden({orderbookURl:r.orderBookUrl,secretManager:c,quote:h,auth:i,wallets:{evmWallet:s,btcWallet:e},blockNumberFetcher:O});U(o)},[c,s,m,i]),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:M,orderBook:m,swap:W,pendingOrders:C,getQuote:F,secretManager:c,garden:l,isExecuting:N,evmInitiate:_,quote:h}},b)},$=()=>{const b=a.useContext(R);if(!b)throw new Error("useGarden must be used within a GardenProvider");return b};exports.GardenContext=R;exports.GardenProvider=Q;exports.useGarden=$;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),m=require("./index3.cjs"),n=require("@gardenfi/core"),a=require("@catalogfi/utils"),q=require("@gardenfi/orderbook"),G=require("./index5.cjs"),w=s.createContext({isExecuting:!1,isExecutorRequired:!1}),x=({children:u,config:i})=>{const[e,v]=s.useState(),{pendingOrders:d}=m.useOrderbook(e),C=s.useMemo(()=>!!(e!=null&&e.secretManager.isInitialized),[e]),O=s.useMemo(()=>!!d.find(r=>{const t=r.status;return t===n.OrderStatus.InitiateDetected||t===n.OrderStatus.Initiated||t===n.OrderStatus.CounterPartyInitiateDetected||t===n.OrderStatus.CounterPartyInitiated||t===n.OrderStatus.RedeemDetected||t===n.OrderStatus.Expired}),[d]),E=s.useMemo(()=>async({fromAsset:r,toAsset:t,amount:o,isExactOut:l=!1})=>{if(e)return await e.quote.getQuote(G.constructOrderpair(r,t),o,l)},[e]),f=async r=>{if(!e||!i.walletClient)return a.Err("Garden not initialized");const t=await e.swap(r);if(t.error)return a.Err(t.error);if(q.isBitcoin(t.val.source_swap.chain))return a.Ok(t.val);const o=await n.switchOrAddNetwork(r.fromAsset.chain,i.walletClient);if(o.error)return a.Err("Failed to switch network: "+o.error);const l=o.val.walletClient,c=await e.evmRelay.init(l,t.val);if(c.error)return a.Err(c.error);const h={...t.val,source_swap:{...t.val.source_swap,initiate_tx_hash:c.val}};return a.Ok(h)};return s.useEffect(()=>{var r;if(i.walletClient){if(!((r=i.walletClient.account)!=null&&r.address))throw new Error("WalletClient doesn't have an account");v(new n.Garden({environment:i.environment,evmWallet:i.walletClient}))}},[i.walletClient]),s.createElement(w.Provider,{value:{orderBook:e==null?void 0:e.orderbook,quote:e==null?void 0:e.quote,swapAndInitiate:f,pendingOrders:d,getQuote:E,garden:e,isExecuting:C,isExecutorRequired:O}},u)},k=()=>{const u=s.useContext(w);if(!u)throw new Error("useGarden must be used within a GardenProvider");return u};exports.GardenContext=w;exports.GardenProvider=x;exports.useGarden=k;
package/dist/index2.js CHANGED
@@ -1,179 +1,92 @@
1
- import E, { createContext as T, useState as k, useMemo as b, useEffect as R } from "react";
2
- import { useWalletClient as V } from "wagmi";
3
- import { useSecretManager as j } from "./index4.js";
4
- import { useOrderbook as D } from "./index3.js";
5
- import { Quote as H, BlockNumberFetcher as J, Garden as F, switchOrAddNetwork as G, EvmRelay as N } from "@gardenfi/core";
6
- import { Err as i, Ok as p } from "@catalogfi/utils";
7
- import { isBitcoin as W } from "@gardenfi/orderbook";
8
- import { BitcoinNetwork as x, BitcoinProvider as L, BitcoinWallet as g } from "@catalogfi/wallets";
9
- import { Siwe as X, Url as Y } from "@gardenfi/utils";
10
- import { constructOrderpair as Z } from "./index5.js";
11
- const S = T({
12
- isExecuting: !1
13
- }), ce = ({
14
- children: w,
15
- config: r
1
+ import m, { createContext as G, useState as O, useMemo as d, useEffect as R } from "react";
2
+ import { useOrderbook as k } from "./index3.js";
3
+ import { OrderStatus as i, Garden as I, switchOrAddNetwork as q } from "@gardenfi/core";
4
+ import { Err as s, Ok as w } from "@catalogfi/utils";
5
+ import { isBitcoin as y } from "@gardenfi/orderbook";
6
+ import { constructOrderpair as P } from "./index5.js";
7
+ const f = G({
8
+ isExecuting: !1,
9
+ isExecutorRequired: !1
10
+ }), B = ({
11
+ children: a,
12
+ config: n
16
13
  }) => {
17
- const [l, z] = k(), [s, B] = k(), [a, K] = k(), [f, P] = k(), q = b(
18
- () => !!(l && s && a && f),
19
- [l, s, a, f]
20
- ), m = b(() => new H(r.quoteUrl), [r.quoteUrl]), C = b(() => {
21
- const e = r.network === x.Mainnet ? "mainnet" : r.network === x.Testnet ? "testnet" : void 0;
22
- return r.blockNumberFetcherUrl && e ? new J(
23
- r.blockNumberFetcherUrl,
24
- e
25
- ) : void 0;
26
- }, [r.blockNumberFetcherUrl, r.network]), y = b(
27
- () => new L(r.network, r.bitcoinRPCUrl),
28
- [r.network, r.bitcoinRPCUrl]
29
- ), { data: n } = V(), { initializeSecretManager: O } = j(z), { orderbook: v } = D(
30
- r.orderBookUrl,
31
- a,
32
- P,
33
- C
34
- ), M = async () => {
35
- if (!n || !a)
36
- return i("WalletClient or auth not initialized");
37
- const e = await O();
38
- if (e.error) return i(e.error);
39
- const o = g.fromPrivateKey(
40
- e.val.getMasterPrivKey(),
41
- y
42
- ), t = new F({
43
- orderbookURl: r.orderBookUrl,
44
- secretManager: e.val,
45
- quote: m,
46
- auth: a,
47
- wallets: {
48
- evmWallet: n,
49
- btcWallet: o
50
- },
51
- blockNumberFetcher: C
52
- });
53
- return B(t), p(t);
54
- }, A = async (e) => {
55
- if (!v || !n || !a)
56
- return i("Orderbook or walletClient or auth not initialized");
57
- let o = s;
58
- if (!l || !o) {
59
- const U = await M();
60
- if (U.error) return i(U.error);
61
- o = U.val;
62
- }
63
- const t = await o.swap(e);
64
- if (t.error) return i(t.error);
65
- if (W(t.val.source_swap.chain)) return p(t.val);
66
- const c = await G(
67
- e.fromAsset.chain,
68
- n
14
+ const [e, v] = O(), { pendingOrders: u } = k(e), p = d(() => !!(e != null && e.secretManager.isInitialized), [e]), C = d(() => !!u.find((r) => {
15
+ const t = r.status;
16
+ return t === i.InitiateDetected || t === i.Initiated || t === i.CounterPartyInitiateDetected || t === i.CounterPartyInitiated || t === i.RedeemDetected || t === i.Expired;
17
+ }), [u]), h = d(
18
+ () => async ({
19
+ fromAsset: r,
20
+ toAsset: t,
21
+ amount: o,
22
+ isExactOut: l = !1
23
+ }) => {
24
+ if (e)
25
+ return await e.quote.getQuote(
26
+ P(r, t),
27
+ o,
28
+ l
29
+ );
30
+ },
31
+ [e]
32
+ ), x = async (r) => {
33
+ if (!e || !n.walletClient) return s("Garden not initialized");
34
+ const t = await e.swap(r);
35
+ if (t.error) return s(t.error);
36
+ if (y(t.val.source_swap.chain)) return w(t.val);
37
+ const o = await q(
38
+ r.fromAsset.chain,
39
+ n.walletClient
69
40
  );
70
- if (c.error)
71
- return i("Failed to switch network: " + c.error);
72
- const _ = c.val.walletClient, u = await new N(t.val, r.orderBookUrl, a).init(_);
73
- if (u.error) return i(u.error);
74
- const d = {
41
+ if (o.error)
42
+ return s("Failed to switch network: " + o.error);
43
+ const l = o.val.walletClient, c = await e.evmRelay.init(l, t.val);
44
+ if (c.error) return s(c.error);
45
+ const E = {
75
46
  ...t.val,
76
47
  source_swap: {
77
48
  ...t.val.source_swap,
78
- initiate_tx_hash: u.val
79
- }
80
- };
81
- return p(d);
82
- }, Q = async (e) => {
83
- if (console.log("walletClient inside evmInitiate :", n), !n || !a)
84
- return i("Orderbook or walletClient or auth not initialized");
85
- if (W(e.source_swap.chain))
86
- return i("Not an EVM order: sourceSwap.chain is Bitcoin");
87
- let o = s;
88
- if (!l || !o) {
89
- const d = await M();
90
- if (d.error) return i(d.error);
91
- o = d.val;
92
- }
93
- const t = await G(
94
- e.source_swap.chain,
95
- n
96
- );
97
- if (t.error)
98
- return i("Failed to switch network: " + t.error);
99
- const c = t.val.walletClient;
100
- console.log("newWalletClient :", c);
101
- const h = await new N(e, r.orderBookUrl, a).init(c);
102
- if (h.error) return i(h.error);
103
- const u = {
104
- ...e,
105
- source_swap: {
106
- ...e.source_swap,
107
- initiate_tx_hash: h.val
49
+ initiate_tx_hash: c.val
108
50
  }
109
51
  };
110
- return p(u);
111
- }, I = async ({
112
- fromAsset: e,
113
- toAsset: o,
114
- amount: t,
115
- isExactOut: c = !1
116
- }) => await m.getQuote(
117
- Z(e, o),
118
- t,
119
- c
120
- );
52
+ return w(E);
53
+ };
121
54
  return R(() => {
122
- if (!n) return;
123
- const e = new X(new Y(r.orderBookUrl), n, {
124
- store: r.store
125
- });
126
- K(e);
127
- }, [n]), R(() => {
128
- if (!l || !n || !v || !a) return;
129
- const e = g.fromPrivateKey(
130
- l.getMasterPrivKey(),
131
- y
132
- ), o = new F({
133
- orderbookURl: r.orderBookUrl,
134
- secretManager: l,
135
- quote: m,
136
- auth: a,
137
- wallets: {
138
- evmWallet: n,
139
- btcWallet: e
140
- },
141
- blockNumberFetcher: C
142
- });
143
- B(o);
144
- }, [l, n, v, a]), R(() => {
145
- if (!s) return;
146
- const e = s.execute(), o = (t) => P(t);
147
- return s.on("onPendingOrdersChanged", o), () => {
148
- (async () => (await e)())(), s.off("onPendingOrdersChanged", o);
149
- };
150
- }, [s]), /* @__PURE__ */ E.createElement(
151
- S.Provider,
55
+ var r;
56
+ if (n.walletClient) {
57
+ if (!((r = n.walletClient.account) != null && r.address))
58
+ throw new Error("WalletClient doesn't have an account");
59
+ v(
60
+ new I({
61
+ environment: n.environment,
62
+ evmWallet: n.walletClient
63
+ })
64
+ );
65
+ }
66
+ }, [n.walletClient]), /* @__PURE__ */ m.createElement(
67
+ f.Provider,
152
68
  {
153
69
  value: {
154
- orderBookUrl: r.orderBookUrl,
155
- initializeSecretManager: O,
156
- orderBook: v,
157
- swap: A,
158
- pendingOrders: f,
159
- getQuote: I,
160
- secretManager: l,
161
- garden: s,
162
- isExecuting: q,
163
- evmInitiate: Q,
164
- quote: m
70
+ orderBook: e == null ? void 0 : e.orderbook,
71
+ quote: e == null ? void 0 : e.quote,
72
+ swapAndInitiate: x,
73
+ pendingOrders: u,
74
+ getQuote: h,
75
+ garden: e,
76
+ isExecuting: p,
77
+ isExecutorRequired: C
165
78
  }
166
79
  },
167
- w
80
+ a
168
81
  );
169
- }, ue = () => {
170
- const w = E.useContext(S);
171
- if (!w)
82
+ }, M = () => {
83
+ const a = m.useContext(f);
84
+ if (!a)
172
85
  throw new Error("useGarden must be used within a GardenProvider");
173
- return w;
86
+ return a;
174
87
  };
175
88
  export {
176
- S as GardenContext,
177
- ce as GardenProvider,
178
- ue as useGarden
89
+ f as GardenContext,
90
+ B as GardenProvider,
91
+ M as useGarden
179
92
  };
package/dist/index3.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@gardenfi/core"),m=require("@gardenfi/orderbook"),i=require("react"),w=require("wagmi"),S=(o,s,b,n)=>{const[t,k]=i.useState(),{data:u}=w.useWalletClient();return i.useEffect(()=>{if(!u||!o||!s)return;const r=new m.Orderbook({url:o,walletClient:u,auth:s});k(r)},[u,o,s]),i.useEffect(()=>{!t||!n||n.fetchBlockNumbers().then(r=>{if(r.error)return;const{val:c}=r;t.fetchOrders(!0,!0,{per_page:500}).then(a=>{if(a.error)return;const O=f.filterDeadlineExpiredOrders(a.val.data).map(e=>{const d=c[e.source_swap.chain],l=c[e.destination_swap.chain];if(!d||!l)return;const p=f.ParseOrderStatus(e,d,l);return{...e,status:p}}).filter(e=>e!==void 0);b(O)})})},[t,n]),{orderbook:t}};exports.useOrderbook=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@gardenfi/core"),o=require("react"),f=e=>{const[b,c]=o.useState([]);return o.useEffect(()=>{if(!e||!e.secretManager.isInitialized)return;console.log("started executor",e.secretManager.isInitialized);const n=e.execute(),r=s=>c(s);return e.on("onPendingOrdersChanged",r),()=>{(async()=>(await n)())(),e.off("onPendingOrdersChanged",r)}},[e]),o.useEffect(()=>{e&&e.blockNumberFetcher.fetchBlockNumbers().then(n=>{if(n.error)return;const{val:r}=n;e.orderbook.fetchOrders(!0,!0,{per_page:500}).then(s=>{if(s.error)return;const l=a.filterDeadlineExpiredOrders(s.val.data).map(t=>{const i=r[t.source_swap.chain],u=r[t.destination_swap.chain];if(!i||!u)return;const d=a.ParseOrderStatus(t,i,u);return{...t,status:d}}).filter(t=>t!==void 0);c(l)})})},[e]),{pendingOrders:b}};exports.useOrderbook=f;
package/dist/index3.js CHANGED
@@ -1,43 +1,40 @@
1
- import { filterDeadlineExpiredOrders as O, ParseOrderStatus as k } from "@gardenfi/core";
2
- import { Orderbook as w } from "@gardenfi/orderbook";
3
- import { useState as h, useEffect as l } from "react";
4
- import { useWalletClient as v } from "wagmi";
5
- const E = (o, n, m, s) => {
6
- const [r, p] = h(), { data: i } = v();
7
- return l(() => {
8
- if (!i || !o || !n) return;
9
- const e = new w({
10
- url: o,
11
- walletClient: i,
12
- auth: n
13
- });
14
- p(e);
15
- }, [i, o, n]), l(() => {
16
- !r || !s || s.fetchBlockNumbers().then((e) => {
17
- if (e.error) return;
18
- const { val: a } = e;
19
- r.fetchOrders(!0, !0, {
1
+ import { filterDeadlineExpiredOrders as l, ParseOrderStatus as d } from "@gardenfi/core";
2
+ import { useState as h, useEffect as u } from "react";
3
+ const O = (e) => {
4
+ const [a, o] = h([]);
5
+ return u(() => {
6
+ if (!e || !e.secretManager.isInitialized) return;
7
+ console.log("started executor", e.secretManager.isInitialized);
8
+ const s = e.execute(), r = (n) => o(n);
9
+ return e.on("onPendingOrdersChanged", r), () => {
10
+ (async () => (await s)())(), e.off("onPendingOrdersChanged", r);
11
+ };
12
+ }, [e]), u(() => {
13
+ e && e.blockNumberFetcher.fetchBlockNumbers().then((s) => {
14
+ if (s.error) return;
15
+ const { val: r } = s;
16
+ e.orderbook.fetchOrders(!0, !0, {
20
17
  per_page: 500
21
- }).then((u) => {
22
- if (u.error) return;
23
- const d = O(u.val.data).map((t) => {
24
- const c = a[t.source_swap.chain], f = a[t.destination_swap.chain];
25
- if (!c || !f) return;
26
- const b = k(
18
+ }).then((n) => {
19
+ if (n.error) return;
20
+ const b = l(n.val.data).map((t) => {
21
+ const i = r[t.source_swap.chain], c = r[t.destination_swap.chain];
22
+ if (!i || !c) return;
23
+ const f = d(
27
24
  t,
28
- c,
29
- f
25
+ i,
26
+ c
30
27
  );
31
28
  return {
32
29
  ...t,
33
- status: b
30
+ status: f
34
31
  };
35
32
  }).filter((t) => t !== void 0);
36
- m(d);
33
+ o(b);
37
34
  });
38
35
  });
39
- }, [r, s]), { orderbook: r };
36
+ }, [e]), { pendingOrders: a };
40
37
  };
41
38
  export {
42
- E as useOrderbook
39
+ O as useOrderbook
43
40
  };
package/dist/index4.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@catalogfi/utils"),n=require("@gardenfi/core"),a=require("wagmi"),l=i=>{const{data:r}=a.useWalletClient();return{initializeSecretManager:async()=>{if(!r)return t.Err("WalletClient not initialized");const e=await n.SecretManager.fromWalletClient(r);return e.error?t.Err(e.error):(i(e.val),e)}}};exports.useSecretManager=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("@catalogfi/wallets");var t=(e=>(e.mainnet="mainnet",e.testnet="testnet",e))(t||{});const r={testnet:{orderBookUrl:"https://evm-swapper-relay.onrender.com",quoteUrl:"https://quote-knrp.onrender.com",bitcoinRPCUrl:"https://mempool.space/testnet4/api",blockNumberFetcherUrl:"https://prod-mainnet-virtual-balance-pr-5.onrender.com"},mainnet:{orderBookUrl:"https://orderbookv2.garden.finance/",quoteUrl:"https://quotev2.garden.finance",bitcoinRPCUrl:"https://mempool.space/api",blockNumberFetcherUrl:"https://info-8ocl.onrender.com"}};exports.GARDEN_CONFIG=r;exports.environment=t;
package/dist/index4.js CHANGED
@@ -1,14 +1,20 @@
1
- import { Err as t } from "@catalogfi/utils";
2
- import { SecretManager as a } from "@gardenfi/core";
3
- import { useWalletClient as n } from "wagmi";
4
- const s = (i) => {
5
- const { data: r } = n();
6
- return { initializeSecretManager: async () => {
7
- if (!r) return t("WalletClient not initialized");
8
- const e = await a.fromWalletClient(r);
9
- return e.error ? t(e.error) : (i(e.val), e);
10
- } };
1
+ import "@catalogfi/wallets";
2
+ var t = /* @__PURE__ */ ((e) => (e.mainnet = "mainnet", e.testnet = "testnet", e))(t || {});
3
+ const o = {
4
+ testnet: {
5
+ orderBookUrl: "https://evm-swapper-relay.onrender.com",
6
+ quoteUrl: "https://quote-knrp.onrender.com",
7
+ bitcoinRPCUrl: "https://mempool.space/testnet4/api",
8
+ blockNumberFetcherUrl: "https://prod-mainnet-virtual-balance-pr-5.onrender.com"
9
+ },
10
+ mainnet: {
11
+ orderBookUrl: "https://orderbookv2.garden.finance/",
12
+ quoteUrl: "https://quotev2.garden.finance",
13
+ bitcoinRPCUrl: "https://mempool.space/api",
14
+ blockNumberFetcherUrl: "https://info-8ocl.onrender.com"
15
+ }
11
16
  };
12
17
  export {
13
- s as useSecretManager
18
+ o as GARDEN_CONFIG,
19
+ t as environment
14
20
  };
@@ -1,4 +1,4 @@
1
1
  export { GardenProvider, useGarden } from './lib/context/GardenProvider';
2
2
  export { useOrderbook } from './lib/hooks/useOrderbook';
3
- export { useSecretManager } from './lib/hooks/useSecretManager';
4
3
  export { BitcoinNetwork } from '@catalogfi/wallets';
4
+ export { environment, GARDEN_CONFIG } from './lib/gardenConfig';
@@ -1,16 +1,10 @@
1
- import { OrderWithStatus, IGardenJS, IQuote, ISecretManager, QuoteResponse, SecretManager, SwapParams } from '@gardenfi/core';
2
- import { AsyncResult } from '@catalogfi/utils';
3
- import { BitcoinNetwork } from '@catalogfi/wallets';
1
+ import { WalletClient } from 'viem';
2
+ import { OrderWithStatus, IGardenJS, IQuote, QuoteResponse, SwapParams } from '@gardenfi/core';
3
+ import { AsyncResult, Result } from '@catalogfi/utils';
4
4
  import { Asset, IOrderbook, MatchedOrder } from '@gardenfi/orderbook';
5
- import { IStore } from '@gardenfi/utils';
5
+ import { Environment, IStore } from '@gardenfi/utils';
6
6
 
7
7
  export type GardenContextType = {
8
- orderBookUrl?: string;
9
- /**
10
- * Initializing secretManager is necessary for executing orders.
11
- * @returns {AsyncResult<SecretManager, string>} - The secret manager instance.
12
- */
13
- initializeSecretManager?: () => AsyncResult<SecretManager, string>;
14
8
  /**
15
9
  * The orderbook instance.
16
10
  * @returns {IOrderbook}
@@ -21,7 +15,7 @@ export type GardenContextType = {
21
15
  * @params {SwapParams} - The parameters for creating the order.
22
16
  * @returns {AsyncResult<string, string>} - create order ID.
23
17
  */
24
- swap?: (params: SwapParams) => AsyncResult<MatchedOrder, string>;
18
+ swapAndInitiate?: (params: SwapParams) => AsyncResult<MatchedOrder, string>;
25
19
  /**
26
20
  * Get all the pending orders of the user. This will return all the orders that are yet to be initiated, redeemed, or refunded.
27
21
  * It will not return orders that have expired (deadline expiry).
@@ -33,28 +27,20 @@ export type GardenContextType = {
33
27
  * @param params
34
28
  * @returns
35
29
  */
36
- getQuote?: (params: QuoteParams) => AsyncResult<QuoteResponse, string>;
37
- /**
38
- * The secret manager instance.
39
- * @returns {ISecretManager}
40
- */
41
- secretManager?: ISecretManager;
30
+ getQuote?: (params: QuoteParams) => Promise<Result<QuoteResponse, string> | undefined>;
42
31
  /**
43
32
  * The garden instance.
44
33
  * @returns {IGardenJS}
45
34
  */
46
35
  garden?: IGardenJS;
47
- /**
48
- * Initiates the order in the EVM chain. This can be useful if the initiation is failed when `swap` function is called.
49
- * @param order - The order to initiate.
50
- * @returns {AsyncResult<MatchedOrder, string>} - The initiated order.
51
- * @NOTE This is only required if the source chain is EVM.
52
- */
53
- evmInitiate?: (order: MatchedOrder) => AsyncResult<MatchedOrder, string>;
54
36
  /**
55
37
  * Indicates if the orders are executing.
56
38
  */
57
39
  isExecuting: boolean;
40
+ /**
41
+ * Indicates if the executor is required based on pending orders.
42
+ */
43
+ isExecutorRequired: boolean;
58
44
  /**
59
45
  * The quote instance.
60
46
  * @returns {IQuote}
@@ -64,10 +50,11 @@ export type GardenContextType = {
64
50
  export type GardenProviderProps = {
65
51
  children: React.ReactNode;
66
52
  config: {
67
- orderBookUrl: string;
68
- quoteUrl: string;
69
53
  store: IStore;
70
- network: BitcoinNetwork;
54
+ environment: Environment;
55
+ walletClient?: WalletClient;
56
+ orderBookUrl?: string;
57
+ quoteUrl?: string;
71
58
  bitcoinRPCUrl?: string;
72
59
  blockNumberFetcherUrl?: string;
73
60
  };
@@ -0,0 +1,15 @@
1
+ import { BitcoinNetwork } from '@catalogfi/wallets';
2
+
3
+ export type GardenConfigType = {
4
+ orderBookUrl: string;
5
+ quoteUrl: string;
6
+ bitcoinRPCUrl: string;
7
+ blockNumberFetcherUrl: string;
8
+ };
9
+ export declare enum environment {
10
+ mainnet = "mainnet",
11
+ testnet = "testnet"
12
+ }
13
+ export declare const GARDEN_CONFIG: Partial<Record<environment, GardenConfigType>>;
14
+ export declare const getConfigForNetwork: (network: environment) => GardenConfigType;
15
+ export declare const getBitcoinNetwork: (network: environment) => BitcoinNetwork;
@@ -1,7 +1,5 @@
1
- import { IBlockNumberFetcher, OrderWithStatus } from '@gardenfi/core';
2
- import { IOrderbook } from '@gardenfi/orderbook';
3
- import { IAuth } from '@gardenfi/utils';
1
+ import { IGardenJS, OrderWithStatus } from '@gardenfi/core';
4
2
 
5
- export declare const useOrderbook: (orderBookUrl: string, auth: IAuth | undefined, setPendingOrders: React.Dispatch<React.SetStateAction<OrderWithStatus[] | undefined>>, blockNumberFetcher?: IBlockNumberFetcher) => {
6
- orderbook: IOrderbook | undefined;
3
+ export declare const useOrderbook: (garden: IGardenJS | undefined) => {
4
+ pendingOrders: OrderWithStatus[];
7
5
  };
@@ -1,6 +0,0 @@
1
- import { ISecretManager, SecretManager } from '@gardenfi/core';
2
- import { SetStateAction } from 'react';
3
-
4
- export declare const useSecretManager: (setSecretManager: React.Dispatch<SetStateAction<ISecretManager | undefined>>) => {
5
- initializeSecretManager: () => Promise<import('@catalogfi/utils').Result<never, string> | import('@catalogfi/utils').Result<SecretManager, never>>;
6
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/react-hooks",
3
- "version": "0.0.1-beta.98",
3
+ "version": "0.0.2-beta.0",
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.51",
31
- "@gardenfi/core": "^0.2.0-beta.77",
32
- "@gardenfi/orderbook": "^0.2.0-beta.19",
33
- "@gardenfi/utils": "^0.0.1-beta.18",
31
+ "@gardenfi/core": "^0.3.0-beta.15",
32
+ "@gardenfi/orderbook": "^0.2.0-beta.42",
33
+ "@gardenfi/utils": "^0.0.1-beta.20",
34
34
  "react": "^18.3.1",
35
35
  "viem": "^2.21.15",
36
36
  "wagmi": "^2.12.16"