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