@gardenfi/react-hooks 0.0.1-beta.38 → 0.0.1-beta.39

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