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