@gardenfi/react-hooks 2.0.28-beta.22 → 2.0.28-beta.24
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 o=require("react"),f=require("./index3.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),f=require("./index3.cjs"),k=require("@gardenfi/core"),n=require("./index4.cjs"),c=require("@gardenfi/orderbook"),C=require("./index5.cjs"),E=require("./index6.cjs"),v=o.createContext({pendingOrders:[]}),G=({children:d,config:a})=>{const[e,p]=o.useState(),{digestKey:u}=E.useDigestKey(),{pendingOrders:w}=f.useOrderbook(e,u),h=o.useMemo(()=>async({fromAsset:i,toAsset:r,amount:s,isExactOut:l=!1,request:t})=>e&&await e.quote.getQuote(C.constructOrderpair(i,r),s,l,t),[e]),T=async i=>{if(!e)return n.Err("Garden not initialized");const r=await e.swap(i);if(r.error)return n.Err(r.error);if(c.isBitcoin(r.val.source_swap.chain))return n.Ok(r.val);let s;switch(c.getBlockchainType(r.val.source_swap.chain)){case c.BlockchainType.EVM:{if(!e.evmHTLC)return n.Err("EVM HTLC not initialized: Please provide evmHTLC");const t=await e.evmHTLC.initiate(r.val);if(t.error)return n.Err(t.error);s=t.val;break}case c.BlockchainType.Starknet:{if(!e.starknetHTLC)return n.Err("Starknet HTLC not initialized: Please provide starknetHTLC");const t=await e.starknetHTLC.initiate(r.val);if(t.error)return n.Err(t.error);s=t.val;break}case c.BlockchainType.Bitcoin:s=r.val.source_swap.initiate_tx_hash;break;default:return n.Err("Unsupported chain")}const l={...r.val,source_swap:{...r.val.source_swap,initiate_tx_hash:s}};return n.Ok(l)};return o.useEffect(()=>{if(!window||!u||!("wallets"in a)&&!("htlc"in a))return;let i;if("wallets"in a)i=k.Garden.fromWallets({...a,digestKey:u});else if("htlc"in a)i=new k.Garden({...a,digestKey:u});else return;p(i)},[a,u]),o.createElement(v.Provider,{value:{swapAndInitiate:T,pendingOrders:w,getQuote:h,garden:e,orderBook:e==null?void 0:e.orderbook}},d)},y=()=>{const d=o.useContext(v);if(!d)throw new Error("useGarden must be used within a GardenProvider");return d};exports.GardenContext=v;exports.GardenProvider=G;exports.useGarden=y;
|
package/dist/index2.js
CHANGED
|
@@ -3,61 +3,63 @@ import { useOrderbook as H } from "./index3.js";
|
|
|
3
3
|
import { Garden as l } from "@gardenfi/core";
|
|
4
4
|
import { Err as i, Ok as p } from "./index4.js";
|
|
5
5
|
import { isBitcoin as L, getBlockchainType as x, BlockchainType as d } from "@gardenfi/orderbook";
|
|
6
|
-
import { constructOrderpair as
|
|
7
|
-
import { useDigestKey as
|
|
8
|
-
const w = G({
|
|
6
|
+
import { constructOrderpair as b } from "./index5.js";
|
|
7
|
+
import { useDigestKey as y } from "./index6.js";
|
|
8
|
+
const w = G({
|
|
9
|
+
pendingOrders: []
|
|
10
|
+
}), S = ({
|
|
9
11
|
children: u,
|
|
10
12
|
config: a
|
|
11
13
|
}) => {
|
|
12
|
-
const [
|
|
14
|
+
const [e, v] = C(), { digestKey: o } = y(), { pendingOrders: f } = H(e, o), h = _(
|
|
13
15
|
() => async ({
|
|
14
16
|
fromAsset: n,
|
|
15
|
-
toAsset:
|
|
17
|
+
toAsset: r,
|
|
16
18
|
amount: s,
|
|
17
19
|
isExactOut: c = !1,
|
|
18
20
|
request: t
|
|
19
|
-
}) =>
|
|
20
|
-
|
|
21
|
+
}) => e && await e.quote.getQuote(
|
|
22
|
+
b(n, r),
|
|
21
23
|
s,
|
|
22
24
|
c,
|
|
23
25
|
t
|
|
24
26
|
),
|
|
25
|
-
[
|
|
27
|
+
[e]
|
|
26
28
|
), k = async (n) => {
|
|
27
|
-
if (!
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
if (L(
|
|
29
|
+
if (!e) return i("Garden not initialized");
|
|
30
|
+
const r = await e.swap(n);
|
|
31
|
+
if (r.error) return i(r.error);
|
|
32
|
+
if (L(r.val.source_swap.chain)) return p(r.val);
|
|
31
33
|
let s;
|
|
32
|
-
switch (x(
|
|
34
|
+
switch (x(r.val.source_swap.chain)) {
|
|
33
35
|
case d.EVM: {
|
|
34
|
-
if (!
|
|
36
|
+
if (!e.evmHTLC)
|
|
35
37
|
return i("EVM HTLC not initialized: Please provide evmHTLC");
|
|
36
|
-
const t = await
|
|
38
|
+
const t = await e.evmHTLC.initiate(r.val);
|
|
37
39
|
if (t.error) return i(t.error);
|
|
38
40
|
s = t.val;
|
|
39
41
|
break;
|
|
40
42
|
}
|
|
41
43
|
case d.Starknet: {
|
|
42
|
-
if (!
|
|
44
|
+
if (!e.starknetHTLC)
|
|
43
45
|
return i(
|
|
44
46
|
"Starknet HTLC not initialized: Please provide starknetHTLC"
|
|
45
47
|
);
|
|
46
|
-
const t = await
|
|
48
|
+
const t = await e.starknetHTLC.initiate(r.val);
|
|
47
49
|
if (t.error) return i(t.error);
|
|
48
50
|
s = t.val;
|
|
49
51
|
break;
|
|
50
52
|
}
|
|
51
53
|
case d.Bitcoin:
|
|
52
|
-
s =
|
|
54
|
+
s = r.val.source_swap.initiate_tx_hash;
|
|
53
55
|
break;
|
|
54
56
|
default:
|
|
55
57
|
return i("Unsupported chain");
|
|
56
58
|
}
|
|
57
59
|
const c = {
|
|
58
|
-
...
|
|
60
|
+
...r.val,
|
|
59
61
|
source_swap: {
|
|
60
|
-
...
|
|
62
|
+
...r.val.source_swap,
|
|
61
63
|
initiate_tx_hash: s
|
|
62
64
|
}
|
|
63
65
|
};
|
|
@@ -86,12 +88,13 @@ const w = G({}), R = ({
|
|
|
86
88
|
swapAndInitiate: k,
|
|
87
89
|
pendingOrders: f,
|
|
88
90
|
getQuote: h,
|
|
89
|
-
garden:
|
|
91
|
+
garden: e,
|
|
92
|
+
orderBook: e == null ? void 0 : e.orderbook
|
|
90
93
|
}
|
|
91
94
|
},
|
|
92
95
|
u
|
|
93
96
|
);
|
|
94
|
-
},
|
|
97
|
+
}, g = () => {
|
|
95
98
|
const u = m.useContext(w);
|
|
96
99
|
if (!u)
|
|
97
100
|
throw new Error("useGarden must be used within a GardenProvider");
|
|
@@ -99,6 +102,6 @@ const w = G({}), R = ({
|
|
|
99
102
|
};
|
|
100
103
|
export {
|
|
101
104
|
w as GardenContext,
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
S as GardenProvider,
|
|
106
|
+
g as useGarden
|
|
104
107
|
};
|
|
@@ -19,7 +19,7 @@ export type GardenContextType = {
|
|
|
19
19
|
* It will not return orders that have expired (deadline expiry).
|
|
20
20
|
* @returns {MatchedOrder[]} - The pending orders of the user.
|
|
21
21
|
*/
|
|
22
|
-
pendingOrders
|
|
22
|
+
pendingOrders: OrderWithStatus[];
|
|
23
23
|
/**
|
|
24
24
|
* Get the quote for the given parameters. This will also return USD values of the assets.
|
|
25
25
|
* @param params
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/react-hooks",
|
|
3
|
-
"version": "2.0.28-beta.
|
|
3
|
+
"version": "2.0.28-beta.24",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@catalogfi/wallets": "^0.2.59",
|
|
30
|
-
"@gardenfi/core": "2.0.25-beta.
|
|
30
|
+
"@gardenfi/core": "2.0.25-beta.22",
|
|
31
31
|
"@gardenfi/orderbook": "2.0.9-beta.17",
|
|
32
32
|
"@gardenfi/utils": "2.0.6-beta.14",
|
|
33
33
|
"react": "^18.3.1",
|