@gardenfi/react-hooks 2.0.1 → 2.0.3
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"),G=require("./index3.cjs"),a=require("@gardenfi/core"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),G=require("./index3.cjs"),a=require("@gardenfi/core"),i=require("@catalogfi/utils"),v=require("@gardenfi/orderbook"),q=require("./index5.cjs"),w=s.createContext({isExecuting:!1,isExecutorRequired:!1}),x=({children:c,config:n})=>{const[t,h]=s.useState(),[O,C]=s.useState(),{pendingOrders:d,isExecuting:E}=G.useOrderbook(t),p=s.useMemo(()=>!!d.find(r=>{const e=r.status;return e===a.OrderStatus.InitiateDetected||e===a.OrderStatus.Initiated||e===a.OrderStatus.CounterPartyInitiateDetected||e===a.OrderStatus.CounterPartyInitiated||e===a.OrderStatus.RedeemDetected||e===a.OrderStatus.Expired}),[d]),f=async r=>{if(!t||!n.walletClient)return i.Err("Garden not initialized");const e=await t.swap(r);if(e.error)return i.Err(e.error);if(v.isBitcoin(e.val.source_swap.chain))return i.Ok(e.val);const o=await a.switchOrAddNetwork(r.fromAsset.chain,n.walletClient);if(o.error)return i.Err("Failed to switch network: "+o.error);const u=o.val.walletClient,l=await t.evmRelay.init(u,e.val);if(l.error)return i.Err(l.error);const k={...e.val,source_swap:{...e.val.source_swap,initiate_tx_hash:l.val}};return i.Ok(k)},m=async r=>{if(!t||!n.walletClient)return i.Err("garden not initialized");if(v.isBitcoin(r.source_swap.chain))return i.Err("Not an EVM order: sourceSwap.chain is Bitcoin");const e=await a.switchOrAddNetwork(r.source_swap.chain,n.walletClient);if(e.error)return i.Err("Failed to switch network: "+e.error);const o=e.val.walletClient,u=await t.evmRelay.init(o,r);if(u.error)return i.Err(u.error);const l={...r,source_swap:{...r.source_swap,initiate_tx_hash:u.val}};return i.Ok(l)};return s.useEffect(()=>{var r;if(n.walletClient){if(!((r=n.walletClient.account)!=null&&r.address))throw new Error("WalletClient doesn't have an account");h(new a.Garden({environment:n.environment,evmWallet:n.walletClient,siweOpts:n.siweOpts??{domain:window.location.hostname,store:n.store}}))}},[n.walletClient]),s.useEffect(()=>{t&&C(()=>async({fromAsset:r,toAsset:e,amount:o,isExactOut:u=!1})=>await t.quote.getQuote(q.constructOrderpair(r,e),o,u))},[t]),s.createElement(w.Provider,{value:{orderBook:t==null?void 0:t.orderbook,quote:t==null?void 0:t.quote,swapAndInitiate:f,pendingOrders:d,getQuote:O,garden:t,isExecuting:E,isExecutorRequired:p,evmInitiate:m}},c)},S=()=>{const c=s.useContext(w);if(!c)throw new Error("useGarden must be used within a GardenProvider");return c};exports.GardenContext=w;exports.GardenProvider=x;exports.useGarden=S;
|
package/dist/index2.js
CHANGED
|
@@ -11,10 +11,10 @@ const C = y({
|
|
|
11
11
|
children: u,
|
|
12
12
|
config: n
|
|
13
13
|
}) => {
|
|
14
|
-
const [t, f] = d(), [x, E] = d(), { pendingOrders: c, isExecuting: _ } = q(t),
|
|
14
|
+
const [t, f] = d(), [x, E] = d(), { pendingOrders: c, isExecuting: _ } = q(t), O = I(() => !!c.find((r) => {
|
|
15
15
|
const e = r.status;
|
|
16
16
|
return e === s.InitiateDetected || e === s.Initiated || e === s.CounterPartyInitiateDetected || e === s.CounterPartyInitiated || e === s.RedeemDetected || e === s.Expired;
|
|
17
|
-
}), [c]),
|
|
17
|
+
}), [c]), R = async (r) => {
|
|
18
18
|
if (!t || !n.walletClient) return i("Garden not initialized");
|
|
19
19
|
const e = await t.swap(r);
|
|
20
20
|
if (e.error) return i(e.error);
|
|
@@ -35,7 +35,7 @@ const C = y({
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
return w(k);
|
|
38
|
-
},
|
|
38
|
+
}, G = async (r) => {
|
|
39
39
|
if (!t || !n.walletClient) return i("garden not initialized");
|
|
40
40
|
if (v(r.source_swap.chain))
|
|
41
41
|
return i("Not an EVM order: sourceSwap.chain is Bitcoin");
|
|
@@ -65,7 +65,7 @@ const C = y({
|
|
|
65
65
|
new P({
|
|
66
66
|
environment: n.environment,
|
|
67
67
|
evmWallet: n.walletClient,
|
|
68
|
-
siweOpts: {
|
|
68
|
+
siweOpts: n.siweOpts ?? {
|
|
69
69
|
domain: window.location.hostname,
|
|
70
70
|
store: n.store
|
|
71
71
|
}
|
|
@@ -91,13 +91,13 @@ const C = y({
|
|
|
91
91
|
value: {
|
|
92
92
|
orderBook: t == null ? void 0 : t.orderbook,
|
|
93
93
|
quote: t == null ? void 0 : t.quote,
|
|
94
|
-
swapAndInitiate:
|
|
94
|
+
swapAndInitiate: R,
|
|
95
95
|
pendingOrders: c,
|
|
96
96
|
getQuote: x,
|
|
97
97
|
garden: t,
|
|
98
98
|
isExecuting: _,
|
|
99
|
-
isExecutorRequired:
|
|
100
|
-
evmInitiate:
|
|
99
|
+
isExecutorRequired: O,
|
|
100
|
+
evmInitiate: G
|
|
101
101
|
}
|
|
102
102
|
},
|
|
103
103
|
u
|
|
@@ -2,7 +2,7 @@ import { WalletClient } from 'viem';
|
|
|
2
2
|
import { OrderWithStatus, IGardenJS, IQuote, QuoteResponse, SwapParams } from '@gardenfi/core';
|
|
3
3
|
import { AsyncResult, Result } from '@catalogfi/utils';
|
|
4
4
|
import { Asset, IOrderbook, MatchedOrder } from '@gardenfi/orderbook';
|
|
5
|
-
import { Environment, IStore } from '@gardenfi/utils';
|
|
5
|
+
import { Environment, IStore, SiweOpts } from '@gardenfi/utils';
|
|
6
6
|
|
|
7
7
|
export type GardenContextType = {
|
|
8
8
|
/**
|
|
@@ -64,6 +64,7 @@ export type GardenProviderProps = {
|
|
|
64
64
|
quoteUrl?: string;
|
|
65
65
|
bitcoinRPCUrl?: string;
|
|
66
66
|
blockNumberFetcherUrl?: string;
|
|
67
|
+
siweOpts?: SiweOpts;
|
|
67
68
|
};
|
|
68
69
|
};
|
|
69
70
|
export type QuoteParams = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/react-hooks",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -32,8 +32,7 @@
|
|
|
32
32
|
"@gardenfi/orderbook": "^2.0.0",
|
|
33
33
|
"@gardenfi/utils": "^2.0.0",
|
|
34
34
|
"react": "^18.3.1",
|
|
35
|
-
"viem": "^2.21.15"
|
|
36
|
-
"wagmi": "^2.12.16"
|
|
35
|
+
"viem": "^2.21.15"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
38
|
"@types/react": "^18",
|
|
File without changes
|