@gardenfi/react-hooks 0.0.1-beta.51 → 0.0.1-beta.53

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