@gardenfi/react-hooks 0.0.1-beta.12 → 0.0.1-beta.13
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 +1 -1
- package/dist/index2.js +22 -22
- package/package.json +1 -1
package/dist/index2.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),p=require("wagmi"),u=require("@gardenfi/core"),s=require("@catalogfi/utils"),h=require("@gardenfi/orderbook"),B=require("@catalogfi/wallets"),P=require("@gardenfi/utils"),x=require("./index5.cjs"),k=t.createContext({}),z=({children:d,config:o})=>{const[n,U]=t.useState(),[a,m]=t.useState(),[l,S]=t.useState(),[G,q]=t.useState(),[y,O]=t.useState(0),[c,M]=t.useState(),v=new u.Quote(o.quoteUrl),{data:r}=p.useWalletClient();console.log("auth :",l),console.log("secretManager :",n),console.log("garden :",a),console.log("orderbook :",c);const b=t.useMemo(()=>new B.BitcoinProvider(o.bitcoinNetwork,o.bitcoinRPCUrl),[o.bitcoinNetwork,o.bitcoinRPCUrl]),R=async e=>{if(console.log("secretManager inside swap:",n,a,c),!a||!c||!r||!l)return s.Err("Garden not initialized");if(!n){const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),p=require("wagmi"),u=require("@gardenfi/core"),s=require("@catalogfi/utils"),h=require("@gardenfi/orderbook"),B=require("@catalogfi/wallets"),P=require("@gardenfi/utils"),x=require("./index5.cjs"),k=t.createContext({}),z=({children:d,config:o})=>{const[n,U]=t.useState(),[a,m]=t.useState(),[l,S]=t.useState(),[G,q]=t.useState(),[y,O]=t.useState(0),[c,M]=t.useState(),v=new u.Quote(o.quoteUrl),{data:r}=p.useWalletClient();console.log("walletClient :",r),console.log("auth :",l),console.log("secretManager :",n),console.log("garden :",a),console.log("orderbook :",c);const b=t.useMemo(()=>new B.BitcoinProvider(o.bitcoinNetwork,o.bitcoinRPCUrl),[o.bitcoinNetwork,o.bitcoinRPCUrl]),R=async e=>{if(console.log("secretManager inside swap:",n,a,c),!a||!c||!r||!l)return s.Err("Garden not initialized");if(!n){const E=await f();if(E.error)return s.Err(E.error)}const i=await a.swap(e);if(i.error)return s.Err(i.error);if(h.isBitcoin(i.val.source_swap.chain))return s.Ok(i.val);const w=await u.switchOrAddNetwork(e.fromAsset.chain,r);if(w.error)return s.Err("Failed to switch network: "+w.error);const C=await new u.EvmRelay(i.val,o.orderBookUrl,l).init(r);return C.error?s.Err(C.error):s.Ok(i.val)},W=async({fromAsset:e,toAsset:i,amount:w,isExactOut:g=!1})=>await v.getQuote(x.constructOrderpair(e,i),w,g),f=async()=>{if(!r)return s.Err("WalletClient not initialized");const e=await u.SecretManager.fromWalletClient(r);return e.error?s.Err(e.error):(U(e.val),e)};return t.useEffect(()=>{if(!r)return;const e=new P.Siwe(new P.Url(o.orderBookUrl),r,{store:o.store});S(e)},[r]),t.useEffect(()=>{if(!r||!o.orderBookUrl||!l)return;console.log("walletClient :",r);const e=new h.Orderbook({url:o.orderBookUrl,walletClient:r,auth:l});console.log("orderbook initialized"),M(e)},[r,o.orderBookUrl]),t.useEffect(()=>{if(!n)return;const e=B.BitcoinWallet.fromPrivateKey(n.getMasterPrivKey(),b);q(e)},[n,b]),t.useEffect(()=>{if(!n||!r||!c||!l)return;const e=new u.Garden({orderbookURl:o.orderBookUrl,secretManager:n,quote:v,auth:l,wallets:{evmWallet:r,btcWallet:G}});m(e)},[n,r,c]),t.useEffect(()=>{a&&(a.execute(),a.on("onPendingOrdersChanged",e=>{O(e.length)}))},[a]),t.createElement(k.Provider,{value:{orderBookUrl:o.orderBookUrl,initializeSecretManager:f,orderBook:c,swap:R,pendingOrdersCount:y,getQuote:W}},d)},A=()=>{const d=t.useContext(k);if(!d)throw new Error("useGarden must be used within a GardenProvider");return d};exports.GardenContext=k;exports.GardenProvider=z;exports.useGarden=A;
|
package/dist/index2.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import
|
|
1
|
+
import C, { createContext as E, useState as c, useMemo as S, useEffect as d } from "react";
|
|
2
2
|
import { useWalletClient as z } from "wagmi";
|
|
3
3
|
import { Quote as A, Garden as N, switchOrAddNetwork as Q, EvmRelay as q, SecretManager as K } from "@gardenfi/core";
|
|
4
|
-
import { Err as
|
|
4
|
+
import { Err as l, Ok as p } from "@catalogfi/utils";
|
|
5
5
|
import { Orderbook as F, isBitcoin as _ } from "@gardenfi/orderbook";
|
|
6
6
|
import { BitcoinProvider as j, BitcoinWallet as D } from "@catalogfi/wallets";
|
|
7
7
|
import { Siwe as H, Url as I } from "@gardenfi/utils";
|
|
8
8
|
import { constructOrderpair as J } from "./index5.js";
|
|
9
|
-
const
|
|
9
|
+
const h = E({}), er = ({
|
|
10
10
|
children: u,
|
|
11
11
|
config: o
|
|
12
12
|
}) => {
|
|
13
|
-
const [t,
|
|
14
|
-
console.log("auth :", i), console.log("secretManager :", t), console.log("garden :", n), console.log("orderbook :",
|
|
13
|
+
const [t, B] = c(), [n, U] = c(), [i, P] = c(), [y, G] = c(), [M, O] = c(0), [s, R] = c(), m = new A(o.quoteUrl), { data: e } = z();
|
|
14
|
+
console.log("walletClient :", e), console.log("auth :", i), console.log("secretManager :", t), console.log("garden :", n), console.log("orderbook :", s);
|
|
15
15
|
const k = S(
|
|
16
16
|
() => new j(o.bitcoinNetwork, o.bitcoinRPCUrl),
|
|
17
17
|
[o.bitcoinNetwork, o.bitcoinRPCUrl]
|
|
18
18
|
), W = async (r) => {
|
|
19
|
-
if (console.log("secretManager inside swap:", t, n,
|
|
20
|
-
return
|
|
19
|
+
if (console.log("secretManager inside swap:", t, n, s), !n || !s || !e || !i)
|
|
20
|
+
return l("Garden not initialized");
|
|
21
21
|
if (!t) {
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
22
|
+
const g = await f();
|
|
23
|
+
if (g.error) return l(g.error);
|
|
24
24
|
}
|
|
25
25
|
const a = await n.swap(r);
|
|
26
|
-
if (a.error) return
|
|
27
|
-
if (_(a.val.source_swap.chain)) return
|
|
26
|
+
if (a.error) return l(a.error);
|
|
27
|
+
if (_(a.val.source_swap.chain)) return p(a.val);
|
|
28
28
|
const w = await Q(
|
|
29
29
|
r.fromAsset.chain,
|
|
30
30
|
e
|
|
31
31
|
);
|
|
32
32
|
if (w.error)
|
|
33
|
-
return
|
|
33
|
+
return l("Failed to switch network: " + w.error);
|
|
34
34
|
const b = await new q(a.val, o.orderBookUrl, i).init(e);
|
|
35
|
-
return b.error ?
|
|
35
|
+
return b.error ? l(b.error) : p(a.val);
|
|
36
36
|
}, x = async ({
|
|
37
37
|
fromAsset: r,
|
|
38
38
|
toAsset: a,
|
|
@@ -43,9 +43,9 @@ const B = E({}), er = ({
|
|
|
43
43
|
w,
|
|
44
44
|
v
|
|
45
45
|
), f = async () => {
|
|
46
|
-
if (!e) return
|
|
46
|
+
if (!e) return l("WalletClient not initialized");
|
|
47
47
|
const r = await K.fromWalletClient(e);
|
|
48
|
-
return r.error ?
|
|
48
|
+
return r.error ? l(r.error) : (B(r.val), r);
|
|
49
49
|
};
|
|
50
50
|
return d(() => {
|
|
51
51
|
if (!e) return;
|
|
@@ -70,7 +70,7 @@ const B = E({}), er = ({
|
|
|
70
70
|
);
|
|
71
71
|
G(r);
|
|
72
72
|
}, [t, k]), d(() => {
|
|
73
|
-
if (!t || !e || !
|
|
73
|
+
if (!t || !e || !s || !i) return;
|
|
74
74
|
const r = new N({
|
|
75
75
|
orderbookURl: o.orderBookUrl,
|
|
76
76
|
secretManager: t,
|
|
@@ -82,17 +82,17 @@ const B = E({}), er = ({
|
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
U(r);
|
|
85
|
-
}, [t, e,
|
|
85
|
+
}, [t, e, s]), d(() => {
|
|
86
86
|
n && (n.execute(), n.on("onPendingOrdersChanged", (r) => {
|
|
87
87
|
O(r.length);
|
|
88
88
|
}));
|
|
89
|
-
}, [n]), /* @__PURE__ */
|
|
90
|
-
|
|
89
|
+
}, [n]), /* @__PURE__ */ C.createElement(
|
|
90
|
+
h.Provider,
|
|
91
91
|
{
|
|
92
92
|
value: {
|
|
93
93
|
orderBookUrl: o.orderBookUrl,
|
|
94
94
|
initializeSecretManager: f,
|
|
95
|
-
orderBook:
|
|
95
|
+
orderBook: s,
|
|
96
96
|
swap: W,
|
|
97
97
|
pendingOrdersCount: M,
|
|
98
98
|
getQuote: x
|
|
@@ -101,13 +101,13 @@ const B = E({}), er = ({
|
|
|
101
101
|
u
|
|
102
102
|
);
|
|
103
103
|
}, or = () => {
|
|
104
|
-
const u =
|
|
104
|
+
const u = C.useContext(h);
|
|
105
105
|
if (!u)
|
|
106
106
|
throw new Error("useGarden must be used within a GardenProvider");
|
|
107
107
|
return u;
|
|
108
108
|
};
|
|
109
109
|
export {
|
|
110
|
-
|
|
110
|
+
h as GardenContext,
|
|
111
111
|
er as GardenProvider,
|
|
112
112
|
or as useGarden
|
|
113
113
|
};
|