@gardenfi/react-hooks 0.0.1-beta.62 → 0.0.1-beta.64

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