@gardenfi/react-hooks 0.0.1-beta.35 → 0.0.1-beta.37

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