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

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