@gardenfi/react-hooks 0.0.1-beta.80 → 0.0.1-beta.82
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 +54 -51
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +15 -14
- package/package.json +2 -2
package/dist/index2.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),z=require("wagmi"),A=require("./index4.cjs"),K=require("./index3.cjs"),d=require("@gardenfi/core"),n=require("@catalogfi/utils"),q=require("@gardenfi/orderbook"),v=require("@catalogfi/wallets"),S=require("@gardenfi/utils"),Q=require("./index5.cjs"),B=a.createContext({isExecuting:!1}),$=({children:b,config:r})=>{const[l,_]=a.useState(),[c,O]=a.useState(),[s,N]=a.useState(),[R,U]=a.useState(),W=a.useMemo(()=>!!(l&&c&&s&&R),[l,c,s,R]),h=a.useMemo(()=>new d.Quote(r.quoteUrl),[r.quoteUrl]),{data:i}=z.useWalletClient(),{initializeSecretManager:C}=A.useSecretManager(_),{orderbook:m}=K.useOrderbook(r.orderBookUrl,s,U),M=r.network===v.BitcoinNetwork.Mainnet?"mainnet":r.network===v.BitcoinNetwork.Testnet?"testnet":void 0,P=r.blockNumberFetcherUrl&&M?{url:r.blockNumberFetcherUrl,network:M}:void 0,f=a.useMemo(()=>new v.BitcoinProvider(r.network,r.bitcoinRPCUrl),[r.network,r.bitcoinRPCUrl]),p=async()=>{if(!i||!s)return n.Err("WalletClient or auth not initialized");const e=await C();if(e.error)return n.Err(e.error);const o=v.BitcoinWallet.fromPrivateKey(e.val.getMasterPrivKey(),f),t=new d.Garden({orderbookURl:r.orderBookUrl,secretManager:e.val,quote:h,auth:s,wallets:{evmWallet:i,btcWallet:o},blockNumberFetcher:P});return O(t),n.Ok(t)},x=async e=>{if(!m||!i||!s)return n.Err("Orderbook or walletClient or auth not initialized");let o=c;if(!l||!o){const y=await p();if(y.error)return n.Err(y.error);o=y.val}const t=await o.swap(e);if(t.error)return n.Err(t.error);if(q.isBitcoin(t.val.source_swap.chain))return n.Ok(t.val);const u=await d.switchOrAddNetwork(e.fromAsset.chain,i);if(u.error)return n.Err("Failed to switch network: "+u.error);const G=u.val.walletClient,w=await new d.EvmRelay(t.val,r.orderBookUrl,s).init(G);if(w.error)return n.Err(w.error);const k={...t.val,source_swap:{...t.val.source_swap,initiate_tx_hash:w.val}};return n.Ok(k)},g=async e=>{if(!i||!s)return n.Err("Orderbook or walletClient or auth not initialized");let o=c;if(!l||!o){const k=await p();if(k.error)return n.Err(k.error);o=k.val}if(q.isBitcoin(e.source_swap.chain))return n.Err("Not an EVM order: sourceSwap.chain is Bitcoin");const t=await d.switchOrAddNetwork(e.source_swap.chain,i);if(t.error)return n.Err("Failed to switch network: "+t.error);const u=t.val.walletClient,E=await new d.EvmRelay(e,r.orderBookUrl,s).init(u);if(E.error)return n.Err(E.error);const w={...e,source_swap:{...e.source_swap,initiate_tx_hash:E.val}};return n.Ok(w)},F=async({fromAsset:e,toAsset:o,amount:t,isExactOut:u=!1})=>await h.getQuote(Q.constructOrderpair(e,o),t,u);return a.useEffect(()=>{if(!i)return;const e=new S.Siwe(new S.Url(r.orderBookUrl),i,{store:r.store});N(e)},[i]),a.useEffect(()=>{if(!l||!i||!m||!s)return;const e=v.BitcoinWallet.fromPrivateKey(l.getMasterPrivKey(),f),o=new d.Garden({orderbookURl:r.orderBookUrl,secretManager:l,quote:h,auth:s,wallets:{evmWallet:i,btcWallet:e},blockNumberFetcher:P});O(o)},[l,i,m,s]),a.useEffect(()=>{if(!c)return;const e=c.execute();return c.on("onPendingOrdersChanged",o=>{U(o)}),()=>{(async()=>(await e)())()}},[c]),a.createElement(B.Provider,{value:{orderBookUrl:r.orderBookUrl,initializeSecretManager:C,orderBook:m,swap:x,pendingOrders:R,getQuote:F,secretManager:l,garden:c,isExecuting:W,evmInitiate:g,quote:h}},b)},T=()=>{const b=a.useContext(B);if(!b)throw new Error("useGarden must be used within a GardenProvider");return b};exports.GardenContext=B;exports.GardenProvider=$;exports.useGarden=T;
|
package/dist/index2.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import z, { createContext as V, useState as h, useMemo as
|
|
1
|
+
import z, { createContext as V, useState as h, useMemo as R, useEffect as U } from "react";
|
|
2
2
|
import { useWalletClient as j } from "wagmi";
|
|
3
3
|
import { useSecretManager as D } from "./index4.js";
|
|
4
4
|
import { useOrderbook as H } from "./index3.js";
|
|
5
5
|
import { Quote as J, Garden as x, switchOrAddNetwork as W, EvmRelay as E } from "@gardenfi/core";
|
|
6
|
-
import { Err as
|
|
6
|
+
import { Err as i, Ok as b } from "@catalogfi/utils";
|
|
7
7
|
import { isBitcoin as F } from "@gardenfi/orderbook";
|
|
8
8
|
import { BitcoinNetwork as N, BitcoinProvider as L, BitcoinWallet as S } from "@catalogfi/wallets";
|
|
9
9
|
import { Siwe as X, Url as Y } from "@gardenfi/utils";
|
|
@@ -14,56 +14,59 @@ const g = V({
|
|
|
14
14
|
children: w,
|
|
15
15
|
config: r
|
|
16
16
|
}) => {
|
|
17
|
-
const [s, K] = h(), [l,
|
|
17
|
+
const [s, K] = h(), [l, C] = h(), [n, q] = h(), [p, y] = h(), A = R(
|
|
18
|
+
() => !!(s && l && n && p),
|
|
19
|
+
[s, l, n, p]
|
|
20
|
+
), m = R(() => new J(r.quoteUrl), [r.quoteUrl]), { data: a } = j(), { initializeSecretManager: B } = D(K), { orderbook: v } = H(
|
|
18
21
|
r.orderBookUrl,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
),
|
|
22
|
+
n,
|
|
23
|
+
y
|
|
24
|
+
), P = r.network === N.Mainnet ? "mainnet" : r.network === N.Testnet ? "testnet" : void 0, M = r.blockNumberFetcherUrl && P ? {
|
|
22
25
|
url: r.blockNumberFetcherUrl,
|
|
23
|
-
network:
|
|
24
|
-
} : void 0,
|
|
26
|
+
network: P
|
|
27
|
+
} : void 0, O = R(
|
|
25
28
|
() => new L(r.network, r.bitcoinRPCUrl),
|
|
26
29
|
[r.network, r.bitcoinRPCUrl]
|
|
27
|
-
),
|
|
28
|
-
if (!
|
|
29
|
-
return
|
|
30
|
-
const e = await
|
|
31
|
-
if (e.error) return
|
|
30
|
+
), _ = async () => {
|
|
31
|
+
if (!a || !n)
|
|
32
|
+
return i("WalletClient or auth not initialized");
|
|
33
|
+
const e = await B();
|
|
34
|
+
if (e.error) return i(e.error);
|
|
32
35
|
const o = S.fromPrivateKey(
|
|
33
36
|
e.val.getMasterPrivKey(),
|
|
34
|
-
|
|
37
|
+
O
|
|
35
38
|
), t = new x({
|
|
36
39
|
orderbookURl: r.orderBookUrl,
|
|
37
40
|
secretManager: e.val,
|
|
38
41
|
quote: m,
|
|
39
|
-
auth:
|
|
42
|
+
auth: n,
|
|
40
43
|
wallets: {
|
|
41
|
-
evmWallet:
|
|
44
|
+
evmWallet: a,
|
|
42
45
|
btcWallet: o
|
|
43
46
|
},
|
|
44
|
-
blockNumberFetcher:
|
|
47
|
+
blockNumberFetcher: M
|
|
45
48
|
});
|
|
46
|
-
return
|
|
49
|
+
return C(t), b(t);
|
|
47
50
|
}, Q = async (e) => {
|
|
48
|
-
if (!v || !
|
|
49
|
-
return
|
|
51
|
+
if (!v || !a || !n)
|
|
52
|
+
return i("Orderbook or walletClient or auth not initialized");
|
|
50
53
|
let o = l;
|
|
51
54
|
if (!s || !o) {
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
o =
|
|
55
|
+
const f = await _();
|
|
56
|
+
if (f.error) return i(f.error);
|
|
57
|
+
o = f.val;
|
|
55
58
|
}
|
|
56
59
|
const t = await o.swap(e);
|
|
57
|
-
if (t.error) return
|
|
60
|
+
if (t.error) return i(t.error);
|
|
58
61
|
if (F(t.val.source_swap.chain)) return b(t.val);
|
|
59
62
|
const c = await W(
|
|
60
63
|
e.fromAsset.chain,
|
|
61
|
-
|
|
64
|
+
a
|
|
62
65
|
);
|
|
63
66
|
if (c.error)
|
|
64
|
-
return
|
|
65
|
-
const
|
|
66
|
-
if (u.error) return
|
|
67
|
+
return i("Failed to switch network: " + c.error);
|
|
68
|
+
const G = c.val.walletClient, u = await new E(t.val, r.orderBookUrl, n).init(G);
|
|
69
|
+
if (u.error) return i(u.error);
|
|
67
70
|
const d = {
|
|
68
71
|
...t.val,
|
|
69
72
|
source_swap: {
|
|
@@ -73,24 +76,24 @@ const g = V({
|
|
|
73
76
|
};
|
|
74
77
|
return b(d);
|
|
75
78
|
}, I = async (e) => {
|
|
76
|
-
if (!
|
|
77
|
-
return
|
|
79
|
+
if (!a || !n)
|
|
80
|
+
return i("Orderbook or walletClient or auth not initialized");
|
|
78
81
|
let o = l;
|
|
79
82
|
if (!s || !o) {
|
|
80
|
-
const d = await
|
|
81
|
-
if (d.error) return
|
|
83
|
+
const d = await _();
|
|
84
|
+
if (d.error) return i(d.error);
|
|
82
85
|
o = d.val;
|
|
83
86
|
}
|
|
84
87
|
if (F(e.source_swap.chain))
|
|
85
|
-
return
|
|
88
|
+
return i("Not an EVM order: sourceSwap.chain is Bitcoin");
|
|
86
89
|
const t = await W(
|
|
87
90
|
e.source_swap.chain,
|
|
88
|
-
|
|
91
|
+
a
|
|
89
92
|
);
|
|
90
93
|
if (t.error)
|
|
91
|
-
return
|
|
92
|
-
const c = t.val.walletClient, k = await new E(e, r.orderBookUrl,
|
|
93
|
-
if (k.error) return
|
|
94
|
+
return i("Failed to switch network: " + t.error);
|
|
95
|
+
const c = t.val.walletClient, k = await new E(e, r.orderBookUrl, n).init(c);
|
|
96
|
+
if (k.error) return i(k.error);
|
|
94
97
|
const u = {
|
|
95
98
|
...e,
|
|
96
99
|
source_swap: {
|
|
@@ -109,34 +112,34 @@ const g = V({
|
|
|
109
112
|
t,
|
|
110
113
|
c
|
|
111
114
|
);
|
|
112
|
-
return
|
|
113
|
-
if (!
|
|
114
|
-
const e = new X(new Y(r.orderBookUrl),
|
|
115
|
+
return U(() => {
|
|
116
|
+
if (!a) return;
|
|
117
|
+
const e = new X(new Y(r.orderBookUrl), a, {
|
|
115
118
|
store: r.store
|
|
116
119
|
});
|
|
117
120
|
q(e);
|
|
118
|
-
}, [
|
|
119
|
-
if (!s || !
|
|
121
|
+
}, [a]), U(() => {
|
|
122
|
+
if (!s || !a || !v || !n) return;
|
|
120
123
|
const e = S.fromPrivateKey(
|
|
121
124
|
s.getMasterPrivKey(),
|
|
122
|
-
|
|
125
|
+
O
|
|
123
126
|
), o = new x({
|
|
124
127
|
orderbookURl: r.orderBookUrl,
|
|
125
128
|
secretManager: s,
|
|
126
129
|
quote: m,
|
|
127
|
-
auth:
|
|
130
|
+
auth: n,
|
|
128
131
|
wallets: {
|
|
129
|
-
evmWallet:
|
|
132
|
+
evmWallet: a,
|
|
130
133
|
btcWallet: e
|
|
131
134
|
},
|
|
132
|
-
blockNumberFetcher:
|
|
135
|
+
blockNumberFetcher: M
|
|
133
136
|
});
|
|
134
|
-
|
|
135
|
-
}, [s,
|
|
137
|
+
C(o);
|
|
138
|
+
}, [s, a, v, n]), U(() => {
|
|
136
139
|
if (!l) return;
|
|
137
140
|
const e = l.execute();
|
|
138
141
|
return l.on("onPendingOrdersChanged", (o) => {
|
|
139
|
-
|
|
142
|
+
y(o);
|
|
140
143
|
}), () => {
|
|
141
144
|
(async () => (await e)())();
|
|
142
145
|
};
|
|
@@ -145,10 +148,10 @@ const g = V({
|
|
|
145
148
|
{
|
|
146
149
|
value: {
|
|
147
150
|
orderBookUrl: r.orderBookUrl,
|
|
148
|
-
initializeSecretManager:
|
|
151
|
+
initializeSecretManager: B,
|
|
149
152
|
orderBook: v,
|
|
150
153
|
swap: Q,
|
|
151
|
-
pendingOrders:
|
|
154
|
+
pendingOrders: p,
|
|
152
155
|
getQuote: T,
|
|
153
156
|
secretManager: s,
|
|
154
157
|
garden: l,
|
package/dist/index3.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@gardenfi/core"),d=require("@gardenfi/orderbook"),s=require("react"),l=require("wagmi"),b=(e,r,i)=>{const{data:t}=l.useWalletClient(),[u,c]=s.useState();return s.useEffect(()=>{if(!t||!e||!r)return;const n=new d.Orderbook({url:e,walletClient:t,auth:r});c(n),n.fetchOrders(!0,!0,{per_page:500}).then(o=>{!o.error&&o.val&&i(a.filterDeadlineExpiredOrders(o.val.data))})},[t,e,r]),{orderbook:u}};exports.useOrderbook=b;
|
package/dist/index3.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { filterDeadlineExpiredOrders as l } from "@gardenfi/core";
|
|
2
|
+
import { Orderbook as s } from "@gardenfi/orderbook";
|
|
3
|
+
import { useState as m, useEffect as p } from "react";
|
|
4
|
+
import { useWalletClient as d } from "wagmi";
|
|
5
|
+
const k = (e, r, n) => {
|
|
6
|
+
const { data: t } = d(), [f, a] = m();
|
|
7
|
+
return p(() => {
|
|
8
|
+
if (!t || !e || !r) return;
|
|
9
|
+
const i = new s({
|
|
9
10
|
url: e,
|
|
10
|
-
walletClient:
|
|
11
|
-
auth:
|
|
11
|
+
walletClient: t,
|
|
12
|
+
auth: r
|
|
12
13
|
});
|
|
13
|
-
|
|
14
|
+
a(i), i.fetchOrders(!0, !0, {
|
|
14
15
|
per_page: 500
|
|
15
16
|
}).then((o) => {
|
|
16
|
-
!o.error && o.val &&
|
|
17
|
+
!o.error && o.val && n(l(o.val.data));
|
|
17
18
|
});
|
|
18
|
-
}, [
|
|
19
|
+
}, [t, e, r]), { orderbook: f };
|
|
19
20
|
};
|
|
20
21
|
export {
|
|
21
|
-
|
|
22
|
+
k as useOrderbook
|
|
22
23
|
};
|
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.82",
|
|
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.51",
|
|
31
|
-
"@gardenfi/core": "^0.2.0-beta.
|
|
31
|
+
"@gardenfi/core": "^0.2.0-beta.61",
|
|
32
32
|
"@gardenfi/orderbook": "^0.2.0-beta.14",
|
|
33
33
|
"@gardenfi/utils": "^0.0.1-beta.18",
|
|
34
34
|
"react": "^18.3.1",
|