@gardenfi/react-hooks 0.0.1-beta.40 → 0.0.1-beta.41

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