@gardenfi/react-hooks 2.0.4 → 2.0.6
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 +15 -13
- package/dist/index5.cjs +1 -1
- package/dist/index5.js +46 -2
- package/dist/index6.cjs +1 -0
- package/dist/index6.js +4 -0
- package/dist/src/lib/context/gardenProvider.types.d.ts +2 -1
- package/package.json +2 -3
package/dist/index2.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),G=require("./index3.cjs"),a=require("@gardenfi/core"),i=require("./index5.cjs"),v=require("@gardenfi/orderbook"),S=require("./index6.cjs"),w=s.createContext({isExecuting:!1,isExecutorRequired:!1}),_=({children:d,config:t})=>{const[n,h]=s.useState(),[O,C]=s.useState(),E=s.useMemo(()=>new a.Quote(t.quoteUrl||a.API[t.environment].quote),[t.quoteUrl,t.environment]),{pendingOrders:c,isExecuting:p}=G.useOrderbook(n),m=s.useMemo(()=>!!c.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}),[c]),q=async r=>{if(!n||!t.walletClient)return i.Err("Garden not initialized");const e=await n.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,t.walletClient);if(o.error)return i.Err("Failed to switch network: "+o.error);const u=o.val.walletClient,l=await n.evmRelay.init(u,e.val);if(l.error)return i.Err(l.error);const x={...e.val,source_swap:{...e.val.source_swap,initiate_tx_hash:l.val}};return i.Ok(x)},k=async r=>{if(!n||!t.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,t.walletClient);if(e.error)return i.Err("Failed to switch network: "+e.error);const o=e.val.walletClient,u=await n.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(t.walletClient){if(!((r=t.walletClient.account)!=null&&r.address))throw new Error("WalletClient doesn't have an account");h(new a.Garden({environment:t.environment,evmWallet:t.walletClient,siweOpts:t.siweOpts??{domain:window.location.hostname,store:t.store}}))}},[t.walletClient]),s.useEffect(()=>{n&&C(()=>async({fromAsset:r,toAsset:e,amount:o,isExactOut:u=!1,request:l})=>await n.quote.getQuote(S.constructOrderpair(r,e),o,u,l))},[n]),s.createElement(w.Provider,{value:{orderBook:n==null?void 0:n.orderbook,quote:E,swapAndInitiate:q,pendingOrders:c,getQuote:O,garden:n,isExecuting:p,isExecutorRequired:m,evmInitiate:k}},d)},R=()=>{const d=s.useContext(w);if(!d)throw new Error("useGarden must be used within a GardenProvider");return d};exports.GardenContext=w;exports.GardenProvider=_;exports.useGarden=R;
|
package/dist/index2.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import C, { createContext as I, useState as d, useMemo as m, useEffect as p } from "react";
|
|
2
2
|
import { useOrderbook as P } from "./index3.js";
|
|
3
|
-
import { Quote as
|
|
4
|
-
import { Err as a, Ok as w } from "
|
|
3
|
+
import { Quote as W, API as A, OrderStatus as l, Garden as Q, switchOrAddNetwork as v } from "@gardenfi/core";
|
|
4
|
+
import { Err as a, Ok as w } from "./index5.js";
|
|
5
5
|
import { isBitcoin as h } from "@gardenfi/orderbook";
|
|
6
|
-
import { constructOrderpair as b } from "./
|
|
6
|
+
import { constructOrderpair as b } from "./index6.js";
|
|
7
7
|
const f = I({
|
|
8
8
|
isExecuting: !1,
|
|
9
9
|
isExecutorRequired: !1
|
|
@@ -11,9 +11,9 @@ const f = I({
|
|
|
11
11
|
children: u,
|
|
12
12
|
config: t
|
|
13
13
|
}) => {
|
|
14
|
-
const [n, x] = d(), [E, _] = d(), O = m(() => new
|
|
14
|
+
const [n, x] = d(), [E, _] = d(), O = m(() => new W(t.quoteUrl || A[t.environment].quote), [t.quoteUrl, t.environment]), { pendingOrders: c, isExecuting: R } = P(n), G = m(() => !!c.find((r) => {
|
|
15
15
|
const e = r.status;
|
|
16
|
-
return e ===
|
|
16
|
+
return e === l.InitiateDetected || e === l.Initiated || e === l.CounterPartyInitiateDetected || e === l.CounterPartyInitiated || e === l.RedeemDetected || e === l.Expired;
|
|
17
17
|
}), [c]), k = async (r) => {
|
|
18
18
|
if (!n || !t.walletClient) return a("Garden not initialized");
|
|
19
19
|
const e = await n.swap(r);
|
|
@@ -25,13 +25,13 @@ const f = I({
|
|
|
25
25
|
);
|
|
26
26
|
if (i.error)
|
|
27
27
|
return a("Failed to switch network: " + i.error);
|
|
28
|
-
const o = i.val.walletClient,
|
|
29
|
-
if (
|
|
28
|
+
const o = i.val.walletClient, s = await n.evmRelay.init(o, e.val);
|
|
29
|
+
if (s.error) return a(s.error);
|
|
30
30
|
const y = {
|
|
31
31
|
...e.val,
|
|
32
32
|
source_swap: {
|
|
33
33
|
...e.val.source_swap,
|
|
34
|
-
initiate_tx_hash:
|
|
34
|
+
initiate_tx_hash: s.val
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
return w(y);
|
|
@@ -47,14 +47,14 @@ const f = I({
|
|
|
47
47
|
return a("Failed to switch network: " + e.error);
|
|
48
48
|
const i = e.val.walletClient, o = await n.evmRelay.init(i, r);
|
|
49
49
|
if (o.error) return a(o.error);
|
|
50
|
-
const
|
|
50
|
+
const s = {
|
|
51
51
|
...r,
|
|
52
52
|
source_swap: {
|
|
53
53
|
...r.source_swap,
|
|
54
54
|
initiate_tx_hash: o.val
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
|
-
return w(
|
|
57
|
+
return w(s);
|
|
58
58
|
};
|
|
59
59
|
return p(() => {
|
|
60
60
|
var r;
|
|
@@ -62,7 +62,7 @@ const f = I({
|
|
|
62
62
|
if (!((r = t.walletClient.account) != null && r.address))
|
|
63
63
|
throw new Error("WalletClient doesn't have an account");
|
|
64
64
|
x(
|
|
65
|
-
new
|
|
65
|
+
new Q({
|
|
66
66
|
environment: t.environment,
|
|
67
67
|
evmWallet: t.walletClient,
|
|
68
68
|
siweOpts: t.siweOpts ?? {
|
|
@@ -78,11 +78,13 @@ const f = I({
|
|
|
78
78
|
fromAsset: r,
|
|
79
79
|
toAsset: e,
|
|
80
80
|
amount: i,
|
|
81
|
-
isExactOut: o = !1
|
|
81
|
+
isExactOut: o = !1,
|
|
82
|
+
request: s
|
|
82
83
|
}) => await n.quote.getQuote(
|
|
83
84
|
b(r, e),
|
|
84
85
|
i,
|
|
85
|
-
o
|
|
86
|
+
o,
|
|
87
|
+
s
|
|
86
88
|
)
|
|
87
89
|
);
|
|
88
90
|
}, [n]), /* @__PURE__ */ C.createElement(
|
package/dist/index5.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var u=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)},l=(e,t,r)=>(u(e,t,"read from private field"),r?r.call(e):t.get(e)),f=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},h=(e,t,r,i)=>(u(e,t,"write to private field"),t.set(e,r),r),n,o,a;class s{constructor(t,r,i=void 0){f(this,n,void 0),f(this,o,void 0),f(this,a,void 0),h(this,n,t),h(this,a,i),h(this,o,r)}get ok(){return l(this,n)}get error(){return l(this,a)}get val(){return l(this,o)}}n=new WeakMap,o=new WeakMap,a=new WeakMap;const d=e=>new s(!0,e),v=(e,...t)=>{if(typeof e=="string"&&t&&t.length>0){let r=[e,...t].map(i=>{if(i){if(i instanceof Error)return i.message;if(typeof i=="string")return i;if(i!=null&&i.toString)return i.toString()}});return new s(!1,null,r.filter(i=>i!==void 0).join(" "))}return new s(!1,null,e)};exports.Err=v;exports.Ok=d;exports.Result=s;
|
package/dist/index5.js
CHANGED
|
@@ -1,4 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
var u = (e, t, r) => {
|
|
2
|
+
if (!t.has(e))
|
|
3
|
+
throw TypeError("Cannot " + r);
|
|
4
|
+
}, s = (e, t, r) => (u(e, t, "read from private field"), r ? r.call(e) : t.get(e)), h = (e, t, r) => {
|
|
5
|
+
if (t.has(e))
|
|
6
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
7
|
+
t instanceof WeakSet ? t.add(e) : t.set(e, r);
|
|
8
|
+
}, l = (e, t, r, i) => (u(e, t, "write to private field"), t.set(e, r), r), n, a, o;
|
|
9
|
+
class f {
|
|
10
|
+
constructor(t, r, i = void 0) {
|
|
11
|
+
h(this, n, void 0), h(this, a, void 0), h(this, o, void 0), l(this, n, t), l(this, o, i), l(this, a, r);
|
|
12
|
+
}
|
|
13
|
+
get ok() {
|
|
14
|
+
return s(this, n);
|
|
15
|
+
}
|
|
16
|
+
get error() {
|
|
17
|
+
return s(this, o);
|
|
18
|
+
}
|
|
19
|
+
get val() {
|
|
20
|
+
return s(this, a);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
n = /* @__PURE__ */ new WeakMap(), a = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new WeakMap();
|
|
24
|
+
const d = (e) => new f(!0, e), p = (e, ...t) => {
|
|
25
|
+
if (typeof e == "string" && t && t.length > 0) {
|
|
26
|
+
let r = [e, ...t].map((i) => {
|
|
27
|
+
if (i) {
|
|
28
|
+
if (i instanceof Error)
|
|
29
|
+
return i.message;
|
|
30
|
+
if (typeof i == "string")
|
|
31
|
+
return i;
|
|
32
|
+
if (i != null && i.toString)
|
|
33
|
+
return i.toString();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return new f(
|
|
37
|
+
!1,
|
|
38
|
+
null,
|
|
39
|
+
r.filter((i) => i !== void 0).join(" ")
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return new f(!1, null, e);
|
|
43
|
+
};
|
|
2
44
|
export {
|
|
3
|
-
|
|
45
|
+
p as Err,
|
|
46
|
+
d as Ok,
|
|
47
|
+
f as Result
|
|
4
48
|
};
|
package/dist/index6.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=(r,c)=>`${r.chain}:${r.atomicSwapAddress}::${c.chain}:${c.atomicSwapAddress}`;exports.constructOrderpair=a;
|
package/dist/index6.js
ADDED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WalletClient } from 'viem';
|
|
2
2
|
import { OrderWithStatus, IGardenJS, IQuote, QuoteResponse, SwapParams } from '@gardenfi/core';
|
|
3
|
-
import { AsyncResult, Result } from '@catalogfi/utils';
|
|
3
|
+
import { AsyncResult, Request, Result } from '@catalogfi/utils';
|
|
4
4
|
import { Asset, IOrderbook, MatchedOrder } from '@gardenfi/orderbook';
|
|
5
5
|
import { Environment, IStore, SiweOpts } from '@gardenfi/utils';
|
|
6
6
|
|
|
@@ -72,4 +72,5 @@ export type QuoteParams = {
|
|
|
72
72
|
toAsset: Asset;
|
|
73
73
|
amount: number;
|
|
74
74
|
isExactOut?: boolean;
|
|
75
|
+
request?: Request;
|
|
75
76
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/react-hooks",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -26,9 +26,8 @@
|
|
|
26
26
|
"registry": "https://registry.npmjs.org/"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@catalogfi/utils": "^0.1.6",
|
|
30
29
|
"@catalogfi/wallets": "^0.2.51",
|
|
31
|
-
"@gardenfi/core": "^2.0.
|
|
30
|
+
"@gardenfi/core": "^2.0.5",
|
|
32
31
|
"@gardenfi/orderbook": "^2.0.0",
|
|
33
32
|
"@gardenfi/utils": "^2.0.0",
|
|
34
33
|
"react": "^18.3.1",
|