@gardenfi/react-hooks 2.0.23 → 2.0.25
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 +52 -50
- package/package.json +4 -4
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 i=require("react"),R=require("./index3.cjs"),n=require("@gardenfi/core"),a=require("./index5.cjs"),O=require("@gardenfi/orderbook"),S=require("./index6.cjs"),h=i.createContext({isExecuting:!1,isExecutorRequired:!1}),_=({children:d,config:t})=>{var m,C;const[s,p]=i.useState(),{pendingOrders:c,isExecuting:E,digestKey:w}=R.useOrderbook(s,(C=(m=t.walletClient)==null?void 0:m.account)==null?void 0:C.address),k=i.useMemo(()=>!!c.find(r=>{const e=r.status;return e===n.OrderStatus.InitiateDetected||e===n.OrderStatus.Initiated||e===n.OrderStatus.CounterPartyInitiateDetected||e===n.OrderStatus.CounterPartyInitiated||e===n.OrderStatus.RedeemDetected||e===n.OrderStatus.Expired}),[c]),v=i.useMemo(()=>new n.Quote(t.quoteUrl||n.API[t.environment].quote),[t.quoteUrl,t.environment]),q=i.useMemo(()=>async({fromAsset:r,toAsset:e,amount:o,isExactOut:u=!1,request:l})=>await v.getQuote(S.constructOrderpair(r,e),o,u,l),[v]),y=async r=>{if(!s||!t.walletClient)return a.Err("Garden not initialized");const e=await s.swap(r);if(e.error)return a.Err(e.error);if(O.isBitcoin(e.val.source_swap.chain))return a.Ok(e.val);const o=await n.switchOrAddNetwork(r.fromAsset.chain,t.walletClient);if(o.error)return a.Err("Failed to switch network: "+o.error);const u=o.val.walletClient,l=await s.evmRelay.init(u,e.val);if(l.error)return a.Err(l.error);const G={...e.val,source_swap:{...e.val.source_swap,initiate_tx_hash:l.val}};return a.Ok(G)},x=async r=>{if(!s||!t.walletClient)return a.Err("garden not initialized");if(O.isBitcoin(r.source_swap.chain))return a.Err("Not an EVM order: sourceSwap.chain is Bitcoin");const e=await n.switchOrAddNetwork(r.source_swap.chain,t.walletClient);if(e.error)return a.Err("Failed to switch network: "+e.error);const o=e.val.walletClient,u=await s.evmRelay.init(o,r);if(u.error)return a.Err(u.error);const l={...r,source_swap:{...r.source_swap,initiate_tx_hash:u.val}};return a.Ok(l)};return i.useEffect(()=>{var e;if(!t.walletClient)return;if(!((e=t.walletClient.account)!=null&&e.address))throw new Error("WalletClient doesn't have an account");const r=w?n.SecretManager.fromDigestKey(w):void 0;p(new n.Garden({environment:t.environment,evmWallet:t.walletClient,siweOpts:t.siweOpts??{domain:window.location.hostname,store:t.store},apiKey:t.apiKey,secretManager:r,quote:t.quoteUrl??n.API[t.environment].quote,orderbookURl:t.orderBookUrl??n.API[t.environment].orderbook}))},[t.walletClient,w]),i.createElement(h.Provider,{value:{orderBook:s==null?void 0:s.orderbook,quote:v,swapAndInitiate:y,pendingOrders:c,getQuote:q,garden:s,isExecuting:E,isExecutorRequired:k,evmInitiate:x}},d)},P=()=>{const d=i.useContext(h);if(!d)throw new Error("useGarden must be used within a GardenProvider");return d};exports.GardenContext=h;exports.GardenProvider=_;exports.useGarden=P;
|
package/dist/index2.js
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useOrderbook as
|
|
3
|
-
import { OrderStatus as l, Quote as
|
|
4
|
-
import { Err as a, Ok as
|
|
5
|
-
import { isBitcoin as
|
|
6
|
-
import { constructOrderpair as
|
|
7
|
-
const
|
|
1
|
+
import E, { createContext as P, useState as b, useMemo as m, useEffect as U } from "react";
|
|
2
|
+
import { useOrderbook as W } from "./index3.js";
|
|
3
|
+
import { OrderStatus as l, Quote as A, API as p, SecretManager as B, Garden as D, switchOrAddNetwork as x } from "@gardenfi/core";
|
|
4
|
+
import { Err as a, Ok as v } from "./index5.js";
|
|
5
|
+
import { isBitcoin as y } from "@gardenfi/orderbook";
|
|
6
|
+
import { constructOrderpair as K } from "./index6.js";
|
|
7
|
+
const R = P({
|
|
8
8
|
isExecuting: !1,
|
|
9
9
|
isExecutorRequired: !1
|
|
10
10
|
}), V = ({
|
|
11
11
|
children: u,
|
|
12
12
|
config: t
|
|
13
13
|
}) => {
|
|
14
|
-
var
|
|
15
|
-
const [n, _] =
|
|
14
|
+
var h, C;
|
|
15
|
+
const [n, _] = b(), { pendingOrders: d, isExecuting: k, digestKey: w } = W(
|
|
16
16
|
n,
|
|
17
|
-
(
|
|
18
|
-
), O = m(() => !!
|
|
17
|
+
(C = (h = t.walletClient) == null ? void 0 : h.account) == null ? void 0 : C.address
|
|
18
|
+
), O = m(() => !!d.find((r) => {
|
|
19
19
|
const e = r.status;
|
|
20
20
|
return e === l.InitiateDetected || e === l.Initiated || e === l.CounterPartyInitiateDetected || e === l.CounterPartyInitiated || e === l.RedeemDetected || e === l.Expired;
|
|
21
|
-
}), [
|
|
21
|
+
}), [d]), c = m(() => new A(t.quoteUrl || p[t.environment].quote), [t.quoteUrl, t.environment]), q = m(
|
|
22
22
|
() => async ({
|
|
23
23
|
fromAsset: r,
|
|
24
24
|
toAsset: e,
|
|
25
|
-
amount:
|
|
26
|
-
isExactOut:
|
|
27
|
-
request:
|
|
28
|
-
}) => await
|
|
29
|
-
|
|
25
|
+
amount: o,
|
|
26
|
+
isExactOut: i = !1,
|
|
27
|
+
request: s
|
|
28
|
+
}) => await c.getQuote(
|
|
29
|
+
K(r, e),
|
|
30
|
+
o,
|
|
30
31
|
i,
|
|
31
|
-
s
|
|
32
|
-
o
|
|
32
|
+
s
|
|
33
33
|
),
|
|
34
|
-
[
|
|
34
|
+
[c]
|
|
35
35
|
), G = async (r) => {
|
|
36
36
|
if (!n || !t.walletClient) return a("Garden not initialized");
|
|
37
37
|
const e = await n.swap(r);
|
|
38
38
|
if (e.error) return a(e.error);
|
|
39
|
-
if (
|
|
40
|
-
const
|
|
39
|
+
if (y(e.val.source_swap.chain)) return v(e.val);
|
|
40
|
+
const o = await x(
|
|
41
41
|
r.fromAsset.chain,
|
|
42
42
|
t.walletClient
|
|
43
43
|
);
|
|
44
|
-
if (
|
|
45
|
-
return a("Failed to switch network: " +
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
const
|
|
44
|
+
if (o.error)
|
|
45
|
+
return a("Failed to switch network: " + o.error);
|
|
46
|
+
const i = o.val.walletClient, s = await n.evmRelay.init(i, e.val);
|
|
47
|
+
if (s.error) return a(s.error);
|
|
48
|
+
const f = {
|
|
49
49
|
...e.val,
|
|
50
50
|
source_swap: {
|
|
51
51
|
...e.val.source_swap,
|
|
52
|
-
initiate_tx_hash:
|
|
52
|
+
initiate_tx_hash: s.val
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
|
-
return
|
|
56
|
-
},
|
|
55
|
+
return v(f);
|
|
56
|
+
}, I = async (r) => {
|
|
57
57
|
if (!n || !t.walletClient) return a("garden not initialized");
|
|
58
|
-
if (
|
|
58
|
+
if (y(r.source_swap.chain))
|
|
59
59
|
return a("Not an EVM order: sourceSwap.chain is Bitcoin");
|
|
60
|
-
const e = await
|
|
60
|
+
const e = await x(
|
|
61
61
|
r.source_swap.chain,
|
|
62
62
|
t.walletClient
|
|
63
63
|
);
|
|
64
64
|
if (e.error)
|
|
65
65
|
return a("Failed to switch network: " + e.error);
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
const
|
|
66
|
+
const o = e.val.walletClient, i = await n.evmRelay.init(o, r);
|
|
67
|
+
if (i.error) return a(i.error);
|
|
68
|
+
const s = {
|
|
69
69
|
...r,
|
|
70
70
|
source_swap: {
|
|
71
71
|
...r.source_swap,
|
|
72
|
-
initiate_tx_hash:
|
|
72
|
+
initiate_tx_hash: i.val
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
|
-
return
|
|
75
|
+
return v(s);
|
|
76
76
|
};
|
|
77
|
-
return
|
|
77
|
+
return U(() => {
|
|
78
78
|
var e;
|
|
79
79
|
if (!t.walletClient) return;
|
|
80
80
|
if (!((e = t.walletClient.account) != null && e.address))
|
|
81
81
|
throw new Error("WalletClient doesn't have an account");
|
|
82
|
-
const r =
|
|
82
|
+
const r = w ? B.fromDigestKey(w) : void 0;
|
|
83
83
|
_(
|
|
84
|
-
new
|
|
84
|
+
new D({
|
|
85
85
|
environment: t.environment,
|
|
86
86
|
evmWallet: t.walletClient,
|
|
87
87
|
siweOpts: t.siweOpts ?? {
|
|
@@ -89,34 +89,36 @@ const E = q({
|
|
|
89
89
|
store: t.store
|
|
90
90
|
},
|
|
91
91
|
apiKey: t.apiKey,
|
|
92
|
-
secretManager: r
|
|
92
|
+
secretManager: r,
|
|
93
|
+
quote: t.quoteUrl ?? p[t.environment].quote,
|
|
94
|
+
orderbookURl: t.orderBookUrl ?? p[t.environment].orderbook
|
|
93
95
|
})
|
|
94
96
|
);
|
|
95
|
-
}, [t.walletClient,
|
|
96
|
-
|
|
97
|
+
}, [t.walletClient, w]), /* @__PURE__ */ E.createElement(
|
|
98
|
+
R.Provider,
|
|
97
99
|
{
|
|
98
100
|
value: {
|
|
99
101
|
orderBook: n == null ? void 0 : n.orderbook,
|
|
100
|
-
quote:
|
|
102
|
+
quote: c,
|
|
101
103
|
swapAndInitiate: G,
|
|
102
|
-
pendingOrders:
|
|
103
|
-
getQuote:
|
|
104
|
+
pendingOrders: d,
|
|
105
|
+
getQuote: q,
|
|
104
106
|
garden: n,
|
|
105
|
-
isExecuting:
|
|
107
|
+
isExecuting: k,
|
|
106
108
|
isExecutorRequired: O,
|
|
107
|
-
evmInitiate:
|
|
109
|
+
evmInitiate: I
|
|
108
110
|
}
|
|
109
111
|
},
|
|
110
112
|
u
|
|
111
113
|
);
|
|
112
114
|
}, j = () => {
|
|
113
|
-
const u =
|
|
115
|
+
const u = E.useContext(R);
|
|
114
116
|
if (!u)
|
|
115
117
|
throw new Error("useGarden must be used within a GardenProvider");
|
|
116
118
|
return u;
|
|
117
119
|
};
|
|
118
120
|
export {
|
|
119
|
-
|
|
121
|
+
R as GardenContext,
|
|
120
122
|
V as GardenProvider,
|
|
121
123
|
j as useGarden
|
|
122
124
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/react-hooks",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.25",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@catalogfi/wallets": "^0.2.59",
|
|
30
|
-
"@gardenfi/core": "^2.0.
|
|
31
|
-
"@gardenfi/orderbook": "^2.0.
|
|
32
|
-
"@gardenfi/utils": "^2.0.
|
|
30
|
+
"@gardenfi/core": "^2.0.21",
|
|
31
|
+
"@gardenfi/orderbook": "^2.0.5",
|
|
32
|
+
"@gardenfi/utils": "^2.0.2",
|
|
33
33
|
"react": "^18.3.1",
|
|
34
34
|
"viem": "^2.21.23"
|
|
35
35
|
},
|