@gardenfi/react-hooks 0.0.1-beta.73 → 0.0.1-beta.74

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