@gardenfi/react-hooks 0.0.1-beta.36 → 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 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 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,121 +1,116 @@
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";
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
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";
9
- import { Siwe as H, Url as I } from "@gardenfi/utils";
10
- import { constructOrderpair as J } from "./index5.js";
11
- const M = K({}), oe = ({
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({}), $ = ({
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 [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(
16
15
  e.orderBookUrl,
17
- a,
18
- f
19
- ), U = Q(
16
+ l,
17
+ p
18
+ ), C = E(
20
19
  () => new F(e.bitcoinNetwork, e.bitcoinRPCUrl),
21
20
  [e.bitcoinNetwork, e.bitcoinRPCUrl]
22
- ), E = async (t) => {
23
- if (!d || !r || !a)
24
- return m("Orderbook or walletClient or auth not initialized");
25
- let n = s;
26
- if (!i || !n) {
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) {
27
26
  const u = await P();
28
- if (u.error) return m(u.error);
29
- const h = C.fromPrivateKey(
27
+ if (u.error) return v(u.error);
28
+ const U = W.fromPrivateKey(
30
29
  u.val.getMasterPrivKey(),
31
- U
30
+ C
32
31
  );
33
- n = new R({
32
+ o = new h({
34
33
  orderbookURl: e.orderBookUrl,
35
34
  secretManager: u.val,
36
35
  quote: w,
37
- auth: a,
36
+ auth: l,
38
37
  wallets: {
39
38
  evmWallet: r,
40
- btcWallet: h
39
+ btcWallet: U
41
40
  }
42
- }), k(n), b(h);
41
+ }), b(o), f(U);
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 s = await q(
45
+ t.fromAsset.chain,
46
+ r
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 ({
58
53
  fromAsset: t,
59
- toAsset: n,
60
- amount: o,
61
- isExactOut: B = !1
54
+ toAsset: o,
55
+ amount: s,
56
+ isExactOut: m = !1
62
57
  }) => await w.getQuote(
63
- J(t, n),
64
- o,
65
- B
58
+ H(t, o),
59
+ s,
60
+ m
66
61
  );
67
- return p(() => {
62
+ return k(() => {
68
63
  if (!r) return;
69
- const t = new H(new I(e.orderBookUrl), r, {
64
+ const t = new j(new D(e.orderBookUrl), r, {
70
65
  store: e.store
71
66
  });
72
- W(t);
73
- }, [r]), p(() => {
74
- if (!i || !r || !d || !a) return;
75
- const t = new R({
67
+ M(t);
68
+ }, [r]), k(() => {
69
+ if (!n || !r || !d || !l) return;
70
+ const t = new h({
76
71
  orderbookURl: e.orderBookUrl,
77
- secretManager: i,
72
+ secretManager: n,
78
73
  quote: w,
79
- auth: a,
74
+ auth: l,
80
75
  wallets: {
81
76
  evmWallet: r,
82
- btcWallet: x
77
+ btcWallet: O
83
78
  }
84
79
  });
85
- k(t);
86
- const n = C.fromPrivateKey(
87
- i.getMasterPrivKey(),
88
- U
80
+ b(t);
81
+ const o = W.fromPrivateKey(
82
+ n.getMasterPrivKey(),
83
+ C
89
84
  );
90
- b(n);
91
- }, [i, r, d, a]), p(() => {
92
- s && (s.execute(), s.on("onPendingOrdersChanged", (t) => {
93
- f(t);
85
+ f(o);
86
+ }, [n, r, d, l]), k(() => {
87
+ a && (a.execute(), a.on("onPendingOrdersChanged", (t) => {
88
+ p(t);
94
89
  }));
95
- }, [s]), /* @__PURE__ */ G.createElement(
96
- M.Provider,
90
+ }, [a]), /* @__PURE__ */ B.createElement(
91
+ g.Provider,
97
92
  {
98
93
  value: {
99
94
  orderBookUrl: e.orderBookUrl,
100
95
  initializeSecretManager: P,
101
96
  orderBook: d,
102
- swap: E,
103
- pendingOrders: g,
104
- getQuote: S,
105
- secretManager: i,
106
- garden: s
97
+ swap: y,
98
+ pendingOrders: R,
99
+ getQuote: x,
100
+ secretManager: n,
101
+ garden: a
107
102
  }
108
103
  },
109
104
  c
110
105
  );
111
- }, ne = () => {
112
- const c = G.useContext(M);
106
+ }, ee = () => {
107
+ const c = B.useContext(g);
113
108
  if (!c)
114
109
  throw new Error("useGarden must be used within a GardenProvider");
115
110
  return c;
116
111
  };
117
112
  export {
118
- M as GardenContext,
119
- oe as GardenProvider,
120
- ne as useGarden
113
+ g as GardenContext,
114
+ $ as GardenProvider,
115
+ ee as useGarden
121
116
  };
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.37",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",