@gardenfi/react-hooks 0.0.1-beta.4 → 0.0.1-beta.7

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/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index2.cjs"),r=require("./index3.cjs"),o=require("./index4.cjs");exports.GardenProvider=e.GardenProvider;exports.useGarden=e.useGarden;exports.useOrderbook=r.useOrderbook;exports.useSecretManager=o.useSecretManager;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index2.cjs"),r=require("./index3.cjs"),o=require("./index4.cjs"),t=require("@catalogfi/wallets");exports.GardenProvider=e.GardenProvider;exports.useGarden=e.useGarden;exports.useOrderbook=r.useOrderbook;exports.useSecretManager=o.useSecretManager;Object.defineProperty(exports,"BitcoinNetwork",{enumerable:!0,get:()=>t.BitcoinNetwork});
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
- import { GardenProvider as o, useGarden as a } from "./index2.js";
2
- import { useOrderbook as t } from "./index3.js";
1
+ import { GardenProvider as o, useGarden as t } from "./index2.js";
2
+ import { useOrderbook as d } from "./index3.js";
3
3
  import { useSecretManager as m } from "./index4.js";
4
+ import { BitcoinNetwork as p } from "@catalogfi/wallets";
4
5
  export {
6
+ p as BitcoinNetwork,
5
7
  o as GardenProvider,
6
- a as useGarden,
7
- t as useOrderbook,
8
+ t as useGarden,
9
+ d as useOrderbook,
8
10
  m as useSecretManager
9
11
  };
package/dist/index2.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),U=require("wagmi"),y=require("./index4.cjs"),f=require("./index3.cjs"),S=require("@gardenfi/core"),u=require("@catalogfi/utils"),w=require("@gardenfi/orderbook"),p=require("@catalogfi/wallets"),b=r.createContext({}),g=({children:l,config:e})=>{const[t,q]=r.useState(),[i,E]=r.useState(),[k,O]=r.useState(),{data:s}=U.useWalletClient(),{initializeSecretManager:C}=y.useSecretManager(q),{orderbook:a}=f.useOrderbook(e.orderBookUrl,e.store),v=r.useMemo(()=>new p.BitcoinProvider(e.bitcoinNetwork,e.bitcoinRPCUrl),[e.bitcoinNetwork,e.bitcoinRPCUrl]),M=async o=>{if(!i||!a||!t||!s)return u.Err("Garden not initialized");const n=await i.swap(o);if(n.error)return u.Err(n.error);if(w.isBitcoin(n.val.source_swap.chain))return u.Ok(n.val);const c=await new S.OrderExecutor(n.val,e.orderBookUrl,t,{store:e.store}).init(s,0);return c.error?u.Err(c.error):u.Ok(n.val)};return r.useEffect(()=>{if(!t)return;const o=p.BitcoinWallet.fromPrivateKey(t.getMasterPrivKey(),v);O(o)},[t,v]),r.useEffect(()=>{if(!t||!s||!a)return;const o=new S.Garden(a,t,e.orderBookUrl,e.quoteUrl,{store:e.store});E(o)},[t,s,a]),r.useEffect(()=>{if(!i)return;let o;return(async()=>{const B=async c=>{const d=c.getOrder(),x=w.isBitcoin(d.source_swap.chain)?k:s,G=w.isBitcoin(d.destination_swap.chain)?k:s;if(!x||!G)return;console.log("executing order:",d.create_order.create_id);const P=await c.execute({wallets:{source:x,destination:G}});console.log("execute result :",P.val),console.log("execute error: ",P.error)};o=await i.subscribeOrders(B)})(),()=>{o()}},[i]),r.createElement(b.Provider,{value:{orderBookUrl:e.orderBookUrl,initializeSecretManager:C,orderBook:a,swap:M}},l)},h=()=>{const l=r.useContext(b);if(!l)throw new Error("useGarden must be used within a GardenProvider");return l};exports.GardenContext=b;exports.GardenProvider=g;exports.useGarden=h;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),M=require("wagmi"),R=require("./index4.cjs"),g=require("./index3.cjs"),d=require("@gardenfi/core"),s=require("@catalogfi/utils"),W=require("@gardenfi/orderbook"),E=require("@catalogfi/wallets"),S=require("@gardenfi/utils"),w=e.createContext({}),x=({children:c,config:r})=>{const[n,q]=e.useState(),[a,B]=e.useState(),[u,C]=e.useState(),[G,U]=e.useState(),[m,O]=e.useState(0),{data:o}=M.useWalletClient(),{initializeSecretManager:k}=R.useSecretManager(q),{orderbook:l}=g.useOrderbook(r.orderBookUrl,u),v=new d.Quote(r.quoteUrl),b=e.useMemo(()=>new E.BitcoinProvider(r.bitcoinNetwork,r.bitcoinRPCUrl),[r.bitcoinNetwork,r.bitcoinRPCUrl]),y=async t=>{if(!a||!l||!o||!u)return s.Err("Garden not initialized");if(!n){const h=await k();if(h.error)return s.Err(h.error)}const i=await a.swap(t);if(i.error)return s.Err(i.error);if(W.isBitcoin(i.val.source_swap.chain))return s.Ok(i.val);const f=await d.switchOrAddNetwork(t.fromAsset.chain,o);if(f.error)return s.Err("Failed to switch network: "+f.error);const P=await new d.EvmRelay(i.val,r.orderBookUrl,u).init(o);return P.error?s.Err(P.error):s.Ok(i.val)};return e.useEffect(()=>{if(!o)return;const t=new S.Siwe(new S.Url(r.orderBookUrl),o,{store:r.store});C(t)},[o]),e.useEffect(()=>{if(!n)return;const t=E.BitcoinWallet.fromPrivateKey(n.getMasterPrivKey(),b);U(t)},[n,b]),e.useEffect(()=>{if(!n||!o||!l||!u)return;const t=new d.Garden({orderbookURl:r.orderBookUrl,secretManager:n,quote:v,auth:u,wallets:{evmWallet:o,btcWallet:G}});B(t)},[n,o,l]),e.useEffect(()=>{a&&(a.execute(),a.on("onPendingOrdersChanged",t=>{O(t.length)}))},[a]),e.createElement(w.Provider,{value:{orderBookUrl:r.orderBookUrl,initializeSecretManager:k,orderBook:l,swap:y,pendingOrdersCount:m,quote:v}},c)},p=()=>{const c=e.useContext(w);if(!c)throw new Error("useGarden must be used within a GardenProvider");return c};exports.GardenContext=w;exports.GardenProvider=x;exports.useGarden=p;
package/dist/index2.js CHANGED
@@ -1,91 +1,90 @@
1
- import P, { createContext as S, useState as u, useMemo as W, useEffect as d } from "react";
2
- import { useWalletClient as y } from "wagmi";
3
- import { useSecretManager as E } from "./index4.js";
4
- import { useOrderbook as _ } from "./index3.js";
5
- import { Garden as R, OrderExecutor as g } from "@gardenfi/core";
6
- import { Err as m, Ok as f } from "@catalogfi/utils";
7
- import { isBitcoin as w } from "@gardenfi/orderbook";
8
- import { BitcoinProvider as z, BitcoinWallet as K } from "@catalogfi/wallets";
9
- const G = S({}), J = ({
1
+ import b, { createContext as W, useState as s, useMemo as x, useEffect as u } from "react";
2
+ import { useWalletClient as E } from "wagmi";
3
+ import { useSecretManager as S } from "./index4.js";
4
+ import { useOrderbook as g } from "./index3.js";
5
+ import { Quote as A, Garden as N, switchOrAddNetwork as q, EvmRelay as z } from "@gardenfi/core";
6
+ import { Err as l, Ok as h } from "@catalogfi/utils";
7
+ import { isBitcoin as K } from "@gardenfi/orderbook";
8
+ import { BitcoinProvider as F, BitcoinWallet as Q } from "@catalogfi/wallets";
9
+ import { Siwe as _, Url as j } from "@gardenfi/utils";
10
+ const B = W({}), $ = ({
10
11
  children: c,
11
- config: e
12
+ config: r
12
13
  }) => {
13
- const [r, U] = u(), [s, C] = u(), [p, h] = u(), { data: n } = y(), { initializeSecretManager: M } = E(U), { orderbook: i } = _(e.orderBookUrl, e.store), b = W(
14
- () => new z(e.bitcoinNetwork, e.bitcoinRPCUrl),
15
- [e.bitcoinNetwork, e.bitcoinRPCUrl]
16
- ), O = async (t) => {
17
- if (!s || !i || !r || !n)
18
- return m("Garden not initialized");
19
- const o = await s.swap(t);
20
- if (o.error) return m(o.error);
21
- if (w(o.val.source_swap.chain)) return f(o.val);
22
- const a = await new g(
23
- o.val,
24
- e.orderBookUrl,
25
- r,
26
- { store: e.store }
27
- ).init(n, 0);
28
- return a.error ? m(a.error) : f(o.val);
14
+ const [o, P] = s(), [n, U] = s(), [a, C] = s(), [G, R] = s(), [y, M] = s(0), { data: t } = E(), { initializeSecretManager: w } = S(P), { orderbook: d } = g(r.orderBookUrl, a), m = new A(r.quoteUrl), v = x(
15
+ () => new F(r.bitcoinNetwork, r.bitcoinRPCUrl),
16
+ [r.bitcoinNetwork, r.bitcoinRPCUrl]
17
+ ), O = async (e) => {
18
+ if (!n || !d || !t || !a)
19
+ return l("Garden not initialized");
20
+ if (!o) {
21
+ const p = await w();
22
+ if (p.error) return l(p.error);
23
+ }
24
+ const i = await n.swap(e);
25
+ if (i.error) return l(i.error);
26
+ if (K(i.val.source_swap.chain)) return h(i.val);
27
+ const f = await q(
28
+ e.fromAsset.chain,
29
+ t
30
+ );
31
+ if (f.error)
32
+ return l("Failed to switch network: " + f.error);
33
+ const k = await new z(i.val, r.orderBookUrl, a).init(t);
34
+ return k.error ? l(k.error) : h(i.val);
29
35
  };
30
- return d(() => {
31
- if (!r) return;
32
- const t = K.fromPrivateKey(
33
- r.getMasterPrivKey(),
34
- b
36
+ return u(() => {
37
+ if (!t) return;
38
+ const e = new _(new j(r.orderBookUrl), t, {
39
+ store: r.store
40
+ });
41
+ C(e);
42
+ }, [t]), u(() => {
43
+ if (!o) return;
44
+ const e = Q.fromPrivateKey(
45
+ o.getMasterPrivKey(),
46
+ v
35
47
  );
36
- h(t);
37
- }, [r, b]), d(() => {
38
- if (!r || !n || !i) return;
39
- const t = new R(
40
- i,
41
- r,
42
- e.orderBookUrl,
43
- e.quoteUrl,
44
- {
45
- store: e.store
48
+ R(e);
49
+ }, [o, v]), u(() => {
50
+ if (!o || !t || !d || !a) return;
51
+ const e = new N({
52
+ orderbookURl: r.orderBookUrl,
53
+ secretManager: o,
54
+ quote: m,
55
+ auth: a,
56
+ wallets: {
57
+ evmWallet: t,
58
+ btcWallet: G
46
59
  }
47
- );
48
- C(t);
49
- }, [r, n, i]), d(() => {
50
- if (!s) return;
51
- let t;
52
- return (async () => {
53
- const v = async (a) => {
54
- const l = a.getOrder(), k = w(l.source_swap.chain) ? p : n, x = w(l.destination_swap.chain) ? p : n;
55
- if (!k || !x) return;
56
- console.log("executing order:", l.create_order.create_id);
57
- const B = await a.execute({
58
- wallets: {
59
- source: k,
60
- destination: x
61
- }
62
- });
63
- console.log("execute result :", B.val), console.log("execute error: ", B.error);
64
- };
65
- t = await s.subscribeOrders(v);
66
- })(), () => {
67
- t();
68
- };
69
- }, [s]), /* @__PURE__ */ P.createElement(
70
- G.Provider,
60
+ });
61
+ U(e);
62
+ }, [o, t, d]), u(() => {
63
+ n && (n.execute(), n.on("onPendingOrdersChanged", (e) => {
64
+ M(e.length);
65
+ }));
66
+ }, [n]), /* @__PURE__ */ b.createElement(
67
+ B.Provider,
71
68
  {
72
69
  value: {
73
- orderBookUrl: e.orderBookUrl,
74
- initializeSecretManager: M,
75
- orderBook: i,
76
- swap: O
70
+ orderBookUrl: r.orderBookUrl,
71
+ initializeSecretManager: w,
72
+ orderBook: d,
73
+ swap: O,
74
+ pendingOrdersCount: y,
75
+ quote: m
77
76
  }
78
77
  },
79
78
  c
80
79
  );
81
- }, L = () => {
82
- const c = P.useContext(G);
80
+ }, rr = () => {
81
+ const c = b.useContext(B);
83
82
  if (!c)
84
83
  throw new Error("useGarden must be used within a GardenProvider");
85
84
  return c;
86
85
  };
87
86
  export {
88
- G as GardenContext,
89
- J as GardenProvider,
90
- L as useGarden
87
+ B as GardenContext,
88
+ $ as GardenProvider,
89
+ rr as useGarden
91
90
  };
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,r)=>{const{data:o}=b.useWalletClient(),[s,n]=t.useState();return t.useEffect(()=>{if(!o||!e)return;const u=new c.Orderbook({url:e,walletClient:o,opts:{store:r}});n(u)},[o,e]),{orderbook:s}};exports.useOrderbook=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@gardenfi/orderbook"),t=require("react"),b=require("wagmi"),i=(e,r)=>{const{data:o}=b.useWalletClient(),[s,n]=t.useState();return t.useEffect(()=>{if(!o||!e||!r)return;const u=new c.Orderbook({url:e,walletClient:o,auth:r});n(u)},[o,e]),{orderbook:s}};exports.useOrderbook=i;
package/dist/index3.js CHANGED
@@ -1,20 +1,18 @@
1
- import { Orderbook as u } from "@gardenfi/orderbook";
2
- import { useState as f, useEffect as i } from "react";
3
- import { useWalletClient as m } from "wagmi";
4
- const l = (t, o) => {
5
- const { data: e } = m(), [r, s] = f();
6
- return i(() => {
7
- if (!e || !t) return;
8
- const n = new u({
9
- url: t,
10
- walletClient: e,
11
- opts: {
12
- store: o
13
- }
1
+ import { Orderbook as f } from "@gardenfi/orderbook";
2
+ import { useState as i, useEffect as m } from "react";
3
+ import { useWalletClient as u } from "wagmi";
4
+ const a = (e, o) => {
5
+ const { data: t } = u(), [r, n] = i();
6
+ return m(() => {
7
+ if (!t || !e || !o) return;
8
+ const s = new f({
9
+ url: e,
10
+ walletClient: t,
11
+ auth: o
14
12
  });
15
- s(n);
16
- }, [e, t]), { orderbook: r };
13
+ n(s);
14
+ }, [t, e]), { orderbook: r };
17
15
  };
18
16
  export {
19
- l as useOrderbook
17
+ a as useOrderbook
20
18
  };
@@ -1,3 +1,4 @@
1
1
  export { GardenProvider, useGarden } from './lib/context/GardenProvider';
2
2
  export { useOrderbook } from './lib/hooks/useOrderbook';
3
3
  export { useSecretManager } from './lib/hooks/useSecretManager';
4
+ export { BitcoinNetwork } from '@catalogfi/wallets';
@@ -1,6 +1,6 @@
1
1
  import { AsyncResult } from '@catalogfi/utils';
2
2
  import { BitcoinNetwork } from '@catalogfi/wallets';
3
- import { SecretManager, SwapParams } from '@gardenfi/core';
3
+ import { IQuote, SecretManager, SwapParams } from '@gardenfi/core';
4
4
  import { IOrderbook, MatchedOrder } from '@gardenfi/orderbook';
5
5
  import { IStore } from '@gardenfi/utils';
6
6
 
@@ -14,6 +14,9 @@ export type GardenContextType = {
14
14
  * @returns {AsyncResult<string, string>} - create order ID.
15
15
  */
16
16
  swap?: (params: SwapParams) => AsyncResult<MatchedOrder, string>;
17
+ pendingOrders?: number;
18
+ quote?: IQuote;
19
+ pendingOrdersCount?: number;
17
20
  };
18
21
  export type GardenProviderProps = {
19
22
  children: React.ReactNode;
@@ -1,6 +1,6 @@
1
1
  import { IOrderbook } from '@gardenfi/orderbook';
2
- import { IStore } from '@gardenfi/utils';
2
+ import { IAuth } from '@gardenfi/utils';
3
3
 
4
- export declare const useOrderbook: (orderBookUrl: string, store: IStore) => {
4
+ export declare const useOrderbook: (orderBookUrl: string, auth: IAuth | undefined) => {
5
5
  orderbook: IOrderbook | undefined;
6
6
  };
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/react-hooks",
3
- "version": "0.0.1-beta.4",
3
+ "version": "0.0.1-beta.7",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -28,9 +28,9 @@
28
28
  "dependencies": {
29
29
  "@catalogfi/utils": "^0.1.6",
30
30
  "@catalogfi/wallets": "^0.2.49",
31
- "@gardenfi/core": "^0.2.0-beta.4",
32
- "@gardenfi/orderbook": "^0.2.0-beta.4",
33
- "@gardenfi/utils": "^0.0.1-beta.4",
31
+ "@gardenfi/core": "^0.2.0-beta.5",
32
+ "@gardenfi/orderbook": "^0.2.0-beta.6",
33
+ "@gardenfi/utils": "^0.0.1-beta.13",
34
34
  "react": "^18.3.1",
35
35
  "viem": "^2.21.15",
36
36
  "wagmi": "^2.12.16"