@gardenfi/react-hooks 2.0.11 → 2.0.13
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 s=require("react"),x=require("./index3.cjs"),n=require("@gardenfi/core"),a=require("./index5.cjs"),h=require("@gardenfi/orderbook"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),x=require("./index3.cjs"),n=require("@gardenfi/core"),a=require("./index5.cjs"),h=require("@gardenfi/orderbook"),y=require("./index6.cjs"),v=s.createContext({isExecuting:!1,isExecutorRequired:!1}),G=({children:d,config:t})=>{const[i,O]=s.useState(),{pendingOrders:c,isExecuting:p}=x.useOrderbook(i),C=s.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]),w=s.useMemo(()=>new n.Quote(t.quoteUrl||n.API[t.environment].quote),[t.quoteUrl,t.environment]),E=s.useMemo(()=>async({fromAsset:r,toAsset:e,amount:o,isExactOut:u=!1,request:l})=>await w.getQuote(y.constructOrderpair(r,e),o,u,l),[w]),m=async r=>{if(!i||!t.walletClient)return a.Err("Garden not initialized");const e=await i.swap(r);if(e.error)return a.Err(e.error);if(h.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 i.evmRelay.init(u,e.val);if(l.error)return a.Err(l.error);const q={...e.val,source_swap:{...e.val.source_swap,initiate_tx_hash:l.val}};return a.Ok(q)},k=async r=>{if(!i||!t.walletClient)return a.Err("garden not initialized");if(h.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 i.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 s.useEffect(()=>{var r;if(t.walletClient){if(!((r=t.walletClient.account)!=null&&r.address))throw new Error("WalletClient doesn't have an account");O(new n.Garden({environment:t.environment,evmWallet:t.walletClient,siweOpts:t.siweOpts??{domain:window.location.hostname,store:t.store},apiKey:t.apiKey}))}},[t.walletClient]),s.createElement(v.Provider,{value:{orderBook:i==null?void 0:i.orderbook,quote:w,swapAndInitiate:m,pendingOrders:c,getQuote:E,garden:i,isExecuting:p,isExecutorRequired:C,evmInitiate:k}},d)},_=()=>{const d=s.useContext(v);if(!d)throw new Error("useGarden must be used within a GardenProvider");return d};exports.GardenContext=v;exports.GardenProvider=G;exports.useGarden=_;
|
package/dist/index2.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import h, { createContext as
|
|
1
|
+
import h, { createContext as G, useState as k, useMemo as d, useEffect as I } from "react";
|
|
2
2
|
import { useOrderbook as q } from "./index3.js";
|
|
3
3
|
import { OrderStatus as l, Quote as P, API as W, Garden as A, switchOrAddNetwork as p } from "@gardenfi/core";
|
|
4
4
|
import { Err as a, Ok as m } from "./index5.js";
|
|
5
5
|
import { isBitcoin as v } from "@gardenfi/orderbook";
|
|
6
6
|
import { constructOrderpair as b } from "./index6.js";
|
|
7
|
-
const C =
|
|
7
|
+
const C = G({
|
|
8
8
|
isExecuting: !1,
|
|
9
9
|
isExecutorRequired: !1
|
|
10
|
-
}),
|
|
10
|
+
}), K = ({
|
|
11
11
|
children: u,
|
|
12
12
|
config: t
|
|
13
13
|
}) => {
|
|
14
|
-
const [n,
|
|
14
|
+
const [n, x] = k(), { pendingOrders: c, isExecuting: E } = q(n), _ = d(() => !!c.find((r) => {
|
|
15
15
|
const e = r.status;
|
|
16
16
|
return e === l.InitiateDetected || e === l.Initiated || e === l.CounterPartyInitiateDetected || e === l.CounterPartyInitiated || e === l.RedeemDetected || e === l.Expired;
|
|
17
|
-
}), [c]), w = d(() => new P(t.quoteUrl || W[t.environment].quote), [t.quoteUrl, t.environment]),
|
|
17
|
+
}), [c]), w = d(() => new P(t.quoteUrl || W[t.environment].quote), [t.quoteUrl, t.environment]), f = d(
|
|
18
18
|
() => async ({
|
|
19
19
|
fromAsset: r,
|
|
20
20
|
toAsset: e,
|
|
@@ -41,14 +41,14 @@ const C = k({
|
|
|
41
41
|
return a("Failed to switch network: " + i.error);
|
|
42
42
|
const o = i.val.walletClient, s = await n.evmRelay.init(o, e.val);
|
|
43
43
|
if (s.error) return a(s.error);
|
|
44
|
-
const
|
|
44
|
+
const y = {
|
|
45
45
|
...e.val,
|
|
46
46
|
source_swap: {
|
|
47
47
|
...e.val.source_swap,
|
|
48
48
|
initiate_tx_hash: s.val
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
return m(
|
|
51
|
+
return m(y);
|
|
52
52
|
}, R = async (r) => {
|
|
53
53
|
if (!n || !t.walletClient) return a("garden not initialized");
|
|
54
54
|
if (v(r.source_swap.chain))
|
|
@@ -75,14 +75,15 @@ const C = k({
|
|
|
75
75
|
if (t.walletClient) {
|
|
76
76
|
if (!((r = t.walletClient.account) != null && r.address))
|
|
77
77
|
throw new Error("WalletClient doesn't have an account");
|
|
78
|
-
|
|
78
|
+
x(
|
|
79
79
|
new A({
|
|
80
80
|
environment: t.environment,
|
|
81
81
|
evmWallet: t.walletClient,
|
|
82
82
|
siweOpts: t.siweOpts ?? {
|
|
83
83
|
domain: window.location.hostname,
|
|
84
84
|
store: t.store
|
|
85
|
-
}
|
|
85
|
+
},
|
|
86
|
+
apiKey: t.apiKey
|
|
86
87
|
})
|
|
87
88
|
);
|
|
88
89
|
}
|
|
@@ -94,16 +95,16 @@ const C = k({
|
|
|
94
95
|
quote: w,
|
|
95
96
|
swapAndInitiate: O,
|
|
96
97
|
pendingOrders: c,
|
|
97
|
-
getQuote:
|
|
98
|
+
getQuote: f,
|
|
98
99
|
garden: n,
|
|
99
|
-
isExecuting:
|
|
100
|
-
isExecutorRequired:
|
|
100
|
+
isExecuting: E,
|
|
101
|
+
isExecutorRequired: _,
|
|
101
102
|
evmInitiate: R
|
|
102
103
|
}
|
|
103
104
|
},
|
|
104
105
|
u
|
|
105
106
|
);
|
|
106
|
-
},
|
|
107
|
+
}, M = () => {
|
|
107
108
|
const u = h.useContext(C);
|
|
108
109
|
if (!u)
|
|
109
110
|
throw new Error("useGarden must be used within a GardenProvider");
|
|
@@ -111,6 +112,6 @@ const C = k({
|
|
|
111
112
|
};
|
|
112
113
|
export {
|
|
113
114
|
C as GardenContext,
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
K as GardenProvider,
|
|
116
|
+
M as useGarden
|
|
116
117
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/react-hooks",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@catalogfi/wallets": "^0.2.51",
|
|
30
|
-
"@gardenfi/core": "^2.0.
|
|
31
|
-
"@gardenfi/orderbook": "^2.0.
|
|
32
|
-
"@gardenfi/utils": "^2.0.
|
|
30
|
+
"@gardenfi/core": "^2.0.10",
|
|
31
|
+
"@gardenfi/orderbook": "^2.0.3",
|
|
32
|
+
"@gardenfi/utils": "^2.0.1",
|
|
33
33
|
"react": "^18.3.1",
|
|
34
|
-
"viem": "^2.21.
|
|
34
|
+
"viem": "^2.21.23"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/react": "^18",
|