@gardenfi/react-hooks 0.0.1-beta.11 → 0.0.1-beta.13

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