@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"),
|
|
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
|
|
2
|
-
import { useWalletClient as
|
|
3
|
-
import { useSecretManager as
|
|
4
|
-
import { useOrderbook as
|
|
5
|
-
import { Quote as
|
|
6
|
-
import { Err as c, Ok as
|
|
7
|
-
import { isBitcoin as
|
|
8
|
-
import { BitcoinProvider as
|
|
9
|
-
import { Siwe as
|
|
10
|
-
import { constructOrderpair as
|
|
11
|
-
const
|
|
12
|
-
children:
|
|
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,
|
|
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
|
-
|
|
19
|
-
), P =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
30
|
+
const w = await U();
|
|
28
31
|
if (w.error) return c(w.error);
|
|
29
|
-
const
|
|
32
|
+
const K = M.fromPrivateKey(
|
|
30
33
|
w.val.getMasterPrivKey(),
|
|
31
|
-
|
|
34
|
+
f
|
|
32
35
|
);
|
|
33
36
|
r = new C({
|
|
34
37
|
orderbookURl: e.orderBookUrl,
|
|
35
38
|
secretManager: w.val,
|
|
36
|
-
quote:
|
|
39
|
+
quote: k,
|
|
37
40
|
auth: a,
|
|
38
41
|
wallets: {
|
|
39
42
|
evmWallet: o,
|
|
40
|
-
btcWallet:
|
|
41
|
-
}
|
|
42
|
-
|
|
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 (
|
|
47
|
-
const l = await
|
|
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
|
|
54
|
-
console.log("newWalletClient :",
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
57
|
-
const
|
|
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:
|
|
65
|
+
initiate_tx_hash: v.val
|
|
62
66
|
}
|
|
63
67
|
};
|
|
64
|
-
return
|
|
65
|
-
},
|
|
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
|
|
71
|
-
|
|
74
|
+
}) => await k.getQuote(
|
|
75
|
+
V(t, r),
|
|
72
76
|
n,
|
|
73
77
|
l
|
|
74
78
|
);
|
|
75
|
-
return
|
|
79
|
+
return b(() => {
|
|
76
80
|
if (!o) return;
|
|
77
|
-
const t = new
|
|
81
|
+
const t = new J(new L(e.orderBookUrl), o, {
|
|
78
82
|
store: e.store
|
|
79
83
|
});
|
|
80
|
-
|
|
81
|
-
}, [o]),
|
|
82
|
-
if (!s || !o || !
|
|
83
|
-
const t =
|
|
84
|
+
F(t);
|
|
85
|
+
}, [o]), b(() => {
|
|
86
|
+
if (!s || !o || !d || !a) return;
|
|
87
|
+
const t = M.fromPrivateKey(
|
|
84
88
|
s.getMasterPrivKey(),
|
|
85
|
-
|
|
89
|
+
f
|
|
86
90
|
), r = new C({
|
|
87
91
|
orderbookURl: e.orderBookUrl,
|
|
88
92
|
secretManager: s,
|
|
89
|
-
quote:
|
|
93
|
+
quote: k,
|
|
90
94
|
auth: a,
|
|
91
95
|
wallets: {
|
|
92
96
|
evmWallet: o,
|
|
93
97
|
btcWallet: t
|
|
94
98
|
}
|
|
95
99
|
});
|
|
96
|
-
|
|
97
|
-
}, [s, o,
|
|
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
|
-
|
|
105
|
+
p(r);
|
|
102
106
|
}), () => {
|
|
103
107
|
(async () => (await t)())();
|
|
104
108
|
};
|
|
105
|
-
}, [i]), /* @__PURE__ */
|
|
106
|
-
|
|
109
|
+
}, [i]), /* @__PURE__ */ O.createElement(
|
|
110
|
+
G.Provider,
|
|
107
111
|
{
|
|
108
112
|
value: {
|
|
109
113
|
orderBookUrl: e.orderBookUrl,
|
|
110
|
-
initializeSecretManager:
|
|
111
|
-
orderBook:
|
|
112
|
-
swap:
|
|
113
|
-
pendingOrders:
|
|
114
|
-
getQuote:
|
|
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
|
-
|
|
123
|
+
u
|
|
120
124
|
);
|
|
121
|
-
},
|
|
122
|
-
const
|
|
123
|
-
if (!
|
|
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
|
|
129
|
+
return u;
|
|
126
130
|
};
|
|
127
131
|
export {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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",
|