@gardenfi/react-hooks 3.0.6-beta.8 → 3.0.6-beta.9

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 a=require("react"),g=require("./index3.cjs"),d=require("@gardenfi/core"),v=require("./index4.cjs"),k=require("./index5.cjs"),p=require("@gardenfi/utils"),q=require("./index6.cjs"),w=a.createContext({pendingOrders:[]}),E=({children:i,config:e,store:l,setRedeemServiceEnabled:n=!0})=>{const[s,G]=a.useState(),{digestKey:c}=k.useDigestKey(n),{pendingOrders:O}=g.useOrderbook(s,l),h=a.useMemo(()=>{const{api:t}=d.resolveApiConfig(e.environment);return e.quote??new d.Quote(t.baseurl,v.resolveAuth(e.apiKey))},[e.environment,e.quote,e.apiKey]),_=a.useMemo(()=>async({fromAsset:t,toAsset:r,amount:u,isExactOut:o=!1,options:y})=>await(s?s.quote:h).getQuoteFromAssets({fromAsset:t,toAsset:r,amount:u,isExactOut:o,options:y}),[s,h]),m=async t=>{if(!s)return p.Err("Garden not initialized");const r=await s.createSwap(t);if(!r.val)return p.Err(r.error||"Unknown error occurred");if(n)try{const u=l.getItem(q.PENDING_ORDERS_STORE),o=u?JSON.parse(u):[];typeof r.val=="string"?o.includes(r.val)||o.push(r.val):r.val&&typeof r.val.order_id=="string"&&(o.includes(r.val.order_id)||o.push(r.val.order_id));const y=Array.from(new Set(o));l.setItem(q.PENDING_ORDERS_STORE,JSON.stringify(y))}catch(u){console.error("Failed to persist pending order id",u)}return p.Ok(r.val)};return a.useEffect(()=>{if(!("wallets"in e)&&!("htlc"in e))return;let t;if("wallets"in e&&Object.keys(e.wallets??{}).length>0&&v.hasAnyValidValue(e.wallets??{}))t=d.Garden.fromWallets({...e,digestKey:n?void 0:c}).setRedeemServiceEnabled(n);else if("htlc"in e&&Object.keys(e.htlc??{}).length>0&&v.hasAnyValidValue(e.htlc??{}))t=new d.Garden({...e,digestKey:n?void 0:c}).setRedeemServiceEnabled(n);else return;G(t)},[e,c,n]),a.createElement(w.Provider,{value:{swap:m,pendingOrders:O,getQuote:_,garden:s,orderBook:s}},i)},K=()=>{const i=a.useContext(w);if(!i)throw new Error("useGarden must be used within a GardenProvider");return i};exports.GardenContext=w;exports.GardenProvider=E;exports.useGarden=K;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),k=require("./index3.cjs"),d=require("@gardenfi/core"),v=require("./index4.cjs"),E=require("./index5.cjs"),p=require("@gardenfi/utils"),G=require("./index6.cjs"),w=a.createContext({pendingOrders:[]}),K=({children:i,config:e,store:l,setRedeemServiceEnabled:n=!0})=>{const[s,O]=a.useState(),{digestKey:c}=E.useDigestKey(n),{pendingOrders:_}=k.useOrderbook(s,l),h=a.useMemo(()=>{const{api:t}=d.resolveApiConfig(e.environment);return e.quote??new d.Quote(t.baseurl,v.resolveAuth(e.apiKey))},[e.environment,e.quote,e.apiKey]),m=a.useMemo(()=>async({fromAsset:t,toAsset:y,amount:r,isExactOut:u=!1,options:o})=>await(s?s.quote:h).getQuoteFromAssets({fromAsset:t,toAsset:y,amount:r,isExactOut:u,options:o}),[s,h]),g=async(t,y)=>{if(!s)return p.Err("Garden not initialized");const r=await s.createSwap(t,y);if(!r.val)return p.Err(r.error||"Unknown error occurred");if(n)try{const u=l.getItem(G.PENDING_ORDERS_STORE),o=u?JSON.parse(u):[];typeof r.val=="string"?o.includes(r.val)||o.push(r.val):r.val&&typeof r.val.order_id=="string"&&(o.includes(r.val.order_id)||o.push(r.val.order_id));const q=Array.from(new Set(o));l.setItem(G.PENDING_ORDERS_STORE,JSON.stringify(q))}catch(u){console.error("Failed to persist pending order id",u)}return p.Ok(r.val)};return a.useEffect(()=>{if(!("wallets"in e)&&!("htlc"in e))return;let t;if("wallets"in e&&Object.keys(e.wallets??{}).length>0&&v.hasAnyValidValue(e.wallets??{}))t=d.Garden.fromWallets({...e,digestKey:n?void 0:c}).setRedeemServiceEnabled(n);else if("htlc"in e&&Object.keys(e.htlc??{}).length>0&&v.hasAnyValidValue(e.htlc??{}))t=new d.Garden({...e,digestKey:n?void 0:c}).setRedeemServiceEnabled(n);else return;O(t)},[e,c,n]),a.createElement(w.Provider,{value:{swap:g,pendingOrders:_,getQuote:m,garden:s,orderBook:s}},i)},P=()=>{const i=a.useContext(w);if(!i)throw new Error("useGarden must be used within a GardenProvider");return i};exports.GardenContext=w;exports.GardenProvider=K;exports.useGarden=P;
package/dist/index2.js CHANGED
@@ -1,11 +1,11 @@
1
- import h, { useState as k, useMemo as m, useEffect as K, createContext as x } from "react";
2
- import { useOrderbook as A } from "./index3.js";
3
- import { resolveApiConfig as g, Quote as C, Garden as c } from "@gardenfi/core";
4
- import { resolveAuth as I, hasAnyValidValue as y } from "./index4.js";
5
- import { useDigestKey as N } from "./index5.js";
6
- import { Err as v, Ok as P } from "@gardenfi/utils";
7
- import { PENDING_ORDERS_STORE as w } from "./index6.js";
8
- const f = x({
1
+ import f, { useState as K, useMemo as c, useEffect as x, createContext as A } from "react";
2
+ import { useOrderbook as g } from "./index3.js";
3
+ import { resolveApiConfig as C, Quote as I, Garden as y } from "@gardenfi/core";
4
+ import { resolveAuth as N, hasAnyValidValue as v } from "./index4.js";
5
+ import { useDigestKey as P } from "./index5.js";
6
+ import { Err as w, Ok as D } from "@gardenfi/utils";
7
+ import { PENDING_ORDERS_STORE as h } from "./index6.js";
8
+ const O = A({
9
9
  pendingOrders: []
10
10
  }), b = ({
11
11
  children: i,
@@ -13,62 +13,62 @@ const f = x({
13
13
  store: u,
14
14
  setRedeemServiceEnabled: o = !0
15
15
  }) => {
16
- const [s, O] = k(), { digestKey: l } = N(o), { pendingOrders: G } = A(s, u), p = m(() => {
17
- const { api: t } = g(e.environment);
18
- return e.quote ?? new C(t.baseurl, I(e.apiKey));
19
- }, [e.environment, e.quote, e.apiKey]), q = m(
16
+ const [s, G] = K(), { digestKey: l } = P(o), { pendingOrders: q } = g(s, u), p = c(() => {
17
+ const { api: t } = C(e.environment);
18
+ return e.quote ?? new I(t.baseurl, N(e.apiKey));
19
+ }, [e.environment, e.quote, e.apiKey]), _ = c(
20
20
  () => async ({
21
21
  fromAsset: t,
22
- toAsset: r,
23
- amount: a,
24
- isExactOut: n = !1,
25
- options: d
22
+ toAsset: d,
23
+ amount: r,
24
+ isExactOut: a = !1,
25
+ options: n
26
26
  }) => await (s ? s.quote : p).getQuoteFromAssets({
27
27
  fromAsset: t,
28
- toAsset: r,
29
- amount: a,
30
- isExactOut: n,
31
- options: d
28
+ toAsset: d,
29
+ amount: r,
30
+ isExactOut: a,
31
+ options: n
32
32
  }),
33
33
  [s, p]
34
- ), _ = async (t) => {
35
- if (!s) return v("Garden not initialized");
36
- const r = await s.createSwap(t);
37
- if (!r.val) return v(r.error || "Unknown error occurred");
34
+ ), k = async (t, d) => {
35
+ if (!s) return w("Garden not initialized");
36
+ const r = await s.createSwap(t, d);
37
+ if (!r.val) return w(r.error || "Unknown error occurred");
38
38
  if (o)
39
39
  try {
40
- const a = u.getItem(w), n = a ? JSON.parse(a) : [];
40
+ const a = u.getItem(h), n = a ? JSON.parse(a) : [];
41
41
  typeof r.val == "string" ? n.includes(r.val) || n.push(r.val) : r.val && typeof r.val.order_id == "string" && (n.includes(r.val.order_id) || n.push(r.val.order_id));
42
- const d = Array.from(new Set(n));
43
- u.setItem(w, JSON.stringify(d));
42
+ const m = Array.from(new Set(n));
43
+ u.setItem(h, JSON.stringify(m));
44
44
  } catch (a) {
45
45
  console.error("Failed to persist pending order id", a);
46
46
  }
47
- return P(r.val);
47
+ return D(r.val);
48
48
  };
49
- return K(() => {
49
+ return x(() => {
50
50
  if (!("wallets" in e) && !("htlc" in e)) return;
51
51
  let t;
52
- if ("wallets" in e && Object.keys(e.wallets ?? {}).length > 0 && y(e.wallets ?? {}))
53
- t = c.fromWallets({
52
+ if ("wallets" in e && Object.keys(e.wallets ?? {}).length > 0 && v(e.wallets ?? {}))
53
+ t = y.fromWallets({
54
54
  ...e,
55
55
  digestKey: o ? void 0 : l
56
56
  }).setRedeemServiceEnabled(o);
57
- else if ("htlc" in e && Object.keys(e.htlc ?? {}).length > 0 && y(e.htlc ?? {}))
58
- t = new c({
57
+ else if ("htlc" in e && Object.keys(e.htlc ?? {}).length > 0 && v(e.htlc ?? {}))
58
+ t = new y({
59
59
  ...e,
60
60
  digestKey: o ? void 0 : l
61
61
  }).setRedeemServiceEnabled(o);
62
62
  else
63
63
  return;
64
- O(t);
65
- }, [e, l, o]), /* @__PURE__ */ h.createElement(
66
- f.Provider,
64
+ G(t);
65
+ }, [e, l, o]), /* @__PURE__ */ f.createElement(
66
+ O.Provider,
67
67
  {
68
68
  value: {
69
- swap: _,
70
- pendingOrders: G,
71
- getQuote: q,
69
+ swap: k,
70
+ pendingOrders: q,
71
+ getQuote: _,
72
72
  garden: s,
73
73
  orderBook: s
74
74
  }
@@ -76,13 +76,13 @@ const f = x({
76
76
  i
77
77
  );
78
78
  }, z = () => {
79
- const i = h.useContext(f);
79
+ const i = f.useContext(O);
80
80
  if (!i)
81
81
  throw new Error("useGarden must be used within a GardenProvider");
82
82
  return i;
83
83
  };
84
84
  export {
85
- f as GardenContext,
85
+ O as GardenContext,
86
86
  b as GardenProvider,
87
87
  z as useGarden
88
88
  };
@@ -1,4 +1,4 @@
1
- import { OrderWithStatus, QuoteParamsForAssets, IGardenJS, QuoteResponse, SwapParams, GardenConfigWithHTLCs, GardenConfigWithWallets } from '@gardenfi/core';
1
+ import { OrderWithStatus, QuoteParamsForAssets, OrderCreationStatus, IGardenJS, QuoteResponse, SwapParams, GardenConfigWithHTLCs, GardenConfigWithWallets } from '@gardenfi/core';
2
2
  import { CreateOrderResponse, IOrderbook } from '@gardenfi/orderbook';
3
3
  import { AsyncResult, IStore } from '@gardenfi/utils';
4
4
 
@@ -11,9 +11,10 @@ export type GardenContextType = {
11
11
  /**
12
12
  * Create an order and wait until its matched and then initiates if source chain is EVM.
13
13
  * @params {SwapParams} - The parameters for creating the order.
14
+ * @params onProgress - Optional callback for progress messages: 'order created', 'order initiating', 'order initiated'.
14
15
  * @returns {AsyncResult<string, string>} - create order ID.
15
16
  */
16
- swap?: (params: SwapParams) => AsyncResult<CreateOrderResponse | string, string>;
17
+ swap?: (params: SwapParams, onProgress?: (status: OrderCreationStatus) => void) => AsyncResult<CreateOrderResponse | string, string>;
17
18
  /**
18
19
  * Get all the pending orders of the user. This will return all the orders that are yet to be initiated, redeemed, or refunded.
19
20
  * It will not return orders that have expired (deadline expiry).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/react-hooks",
3
- "version": "3.0.6-beta.8",
3
+ "version": "3.0.6-beta.9",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "registry": "https://registry.npmjs.org/"
28
28
  },
29
29
  "dependencies": {
30
- "@gardenfi/core": "3.0.6-beta.12",
30
+ "@gardenfi/core": "3.0.6-beta.13",
31
31
  "@gardenfi/orderbook": "3.0.5-beta.9",
32
32
  "@gardenfi/utils": "3.0.0-beta.2",
33
33
  "react": "^18.3.1",