@shogun-sdk/swap 0.0.2-test.2 → 0.0.2-test.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/index.cjs CHANGED
@@ -853,22 +853,23 @@ function useQuote(params, options) {
853
853
  const autoRefreshMs = options?.autoRefreshMs;
854
854
  const abortRef = (0, import_react3.useRef)(null);
855
855
  const debounceRef = (0, import_react3.useRef)(null);
856
- const mountedRef = (0, import_react3.useRef)(true);
856
+ const mounted = (0, import_react3.useRef)(false);
857
857
  (0, import_react3.useEffect)(() => {
858
+ mounted.current = true;
858
859
  return () => {
859
- mountedRef.current = false;
860
+ mounted.current = false;
860
861
  abortRef.current?.abort();
861
862
  if (debounceRef.current) clearTimeout(debounceRef.current);
862
863
  };
863
864
  }, []);
864
865
  const fetchQuote = (0, import_react3.useCallback)(
865
- async (signal) => {
866
+ async () => {
866
867
  if (!params) return;
867
868
  try {
868
869
  setLoading(true);
869
870
  setWarning(null);
870
- const result = await getQuote({ ...params, signal });
871
- if (!mountedRef.current) return;
871
+ const result = await getQuote(params);
872
+ if (!mounted.current) return;
872
873
  setData((prev) => {
873
874
  if (JSON.stringify(prev) === JSON.stringify(result)) return prev;
874
875
  return result;
@@ -877,10 +878,10 @@ function useQuote(params, options) {
877
878
  setError(null);
878
879
  } catch (err) {
879
880
  if (err.name === "AbortError") return;
880
- const e = err instanceof Error ? err : new Error(String(err));
881
- if (mountedRef.current) setError(e);
881
+ console.error("[useQuote] fetch error:", err);
882
+ if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
882
883
  } finally {
883
- if (mountedRef.current) setLoading(false);
884
+ if (mounted.current) setLoading(false);
884
885
  }
885
886
  },
886
887
  [params]
@@ -888,25 +889,14 @@ function useQuote(params, options) {
888
889
  (0, import_react3.useEffect)(() => {
889
890
  if (!params) return;
890
891
  if (debounceRef.current) clearTimeout(debounceRef.current);
891
- abortRef.current?.abort();
892
- const controller = new AbortController();
893
- abortRef.current = controller;
894
892
  debounceRef.current = setTimeout(() => {
895
- fetchQuote(controller.signal);
893
+ fetchQuote();
896
894
  }, debounceMs);
897
895
  return () => {
898
- controller.abort();
899
896
  if (debounceRef.current) clearTimeout(debounceRef.current);
897
+ abortRef.current?.abort();
900
898
  };
901
- }, [
902
- params?.tokenIn?.address,
903
- params?.tokenOut?.address,
904
- params?.sourceChainId,
905
- params?.destChainId,
906
- params?.amount,
907
- debounceMs,
908
- fetchQuote
909
- ]);
899
+ }, [params, debounceMs, fetchQuote]);
910
900
  (0, import_react3.useEffect)(() => {
911
901
  if (!autoRefreshMs || !params) return;
912
902
  const interval = setInterval(() => fetchQuote(), autoRefreshMs);
@@ -914,15 +904,10 @@ function useQuote(params, options) {
914
904
  }, [autoRefreshMs, params, fetchQuote]);
915
905
  return (0, import_react3.useMemo)(
916
906
  () => ({
917
- /** Latest quote data */
918
907
  data,
919
- /** Whether a fetch is ongoing */
920
908
  loading,
921
- /** Error (if any) */
922
909
  error,
923
- /** Warning (e.g. high slippage alert) */
924
910
  warning,
925
- /** Manual refetch */
926
911
  refetch: () => fetchQuote()
927
912
  }),
928
913
  [data, loading, error, warning, fetchQuote]
package/dist/index.js CHANGED
@@ -822,22 +822,23 @@ function useQuote(params, options) {
822
822
  const autoRefreshMs = options?.autoRefreshMs;
823
823
  const abortRef = useRef3(null);
824
824
  const debounceRef = useRef3(null);
825
- const mountedRef = useRef3(true);
825
+ const mounted = useRef3(false);
826
826
  useEffect3(() => {
827
+ mounted.current = true;
827
828
  return () => {
828
- mountedRef.current = false;
829
+ mounted.current = false;
829
830
  abortRef.current?.abort();
830
831
  if (debounceRef.current) clearTimeout(debounceRef.current);
831
832
  };
832
833
  }, []);
833
834
  const fetchQuote = useCallback2(
834
- async (signal) => {
835
+ async () => {
835
836
  if (!params) return;
836
837
  try {
837
838
  setLoading(true);
838
839
  setWarning(null);
839
- const result = await getQuote({ ...params, signal });
840
- if (!mountedRef.current) return;
840
+ const result = await getQuote(params);
841
+ if (!mounted.current) return;
841
842
  setData((prev) => {
842
843
  if (JSON.stringify(prev) === JSON.stringify(result)) return prev;
843
844
  return result;
@@ -846,10 +847,10 @@ function useQuote(params, options) {
846
847
  setError(null);
847
848
  } catch (err) {
848
849
  if (err.name === "AbortError") return;
849
- const e = err instanceof Error ? err : new Error(String(err));
850
- if (mountedRef.current) setError(e);
850
+ console.error("[useQuote] fetch error:", err);
851
+ if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
851
852
  } finally {
852
- if (mountedRef.current) setLoading(false);
853
+ if (mounted.current) setLoading(false);
853
854
  }
854
855
  },
855
856
  [params]
@@ -857,25 +858,14 @@ function useQuote(params, options) {
857
858
  useEffect3(() => {
858
859
  if (!params) return;
859
860
  if (debounceRef.current) clearTimeout(debounceRef.current);
860
- abortRef.current?.abort();
861
- const controller = new AbortController();
862
- abortRef.current = controller;
863
861
  debounceRef.current = setTimeout(() => {
864
- fetchQuote(controller.signal);
862
+ fetchQuote();
865
863
  }, debounceMs);
866
864
  return () => {
867
- controller.abort();
868
865
  if (debounceRef.current) clearTimeout(debounceRef.current);
866
+ abortRef.current?.abort();
869
867
  };
870
- }, [
871
- params?.tokenIn?.address,
872
- params?.tokenOut?.address,
873
- params?.sourceChainId,
874
- params?.destChainId,
875
- params?.amount,
876
- debounceMs,
877
- fetchQuote
878
- ]);
868
+ }, [params, debounceMs, fetchQuote]);
879
869
  useEffect3(() => {
880
870
  if (!autoRefreshMs || !params) return;
881
871
  const interval = setInterval(() => fetchQuote(), autoRefreshMs);
@@ -883,15 +873,10 @@ function useQuote(params, options) {
883
873
  }, [autoRefreshMs, params, fetchQuote]);
884
874
  return useMemo2(
885
875
  () => ({
886
- /** Latest quote data */
887
876
  data,
888
- /** Whether a fetch is ongoing */
889
877
  loading,
890
- /** Error (if any) */
891
878
  error,
892
- /** Warning (e.g. high slippage alert) */
893
879
  warning,
894
- /** Manual refetch */
895
880
  refetch: () => fetchQuote()
896
881
  }),
897
882
  [data, loading, error, warning, fetchQuote]
package/dist/react.cjs CHANGED
@@ -698,22 +698,23 @@ function useQuote(params, options) {
698
698
  const autoRefreshMs = options?.autoRefreshMs;
699
699
  const abortRef = (0, import_react3.useRef)(null);
700
700
  const debounceRef = (0, import_react3.useRef)(null);
701
- const mountedRef = (0, import_react3.useRef)(true);
701
+ const mounted = (0, import_react3.useRef)(false);
702
702
  (0, import_react3.useEffect)(() => {
703
+ mounted.current = true;
703
704
  return () => {
704
- mountedRef.current = false;
705
+ mounted.current = false;
705
706
  abortRef.current?.abort();
706
707
  if (debounceRef.current) clearTimeout(debounceRef.current);
707
708
  };
708
709
  }, []);
709
710
  const fetchQuote = (0, import_react3.useCallback)(
710
- async (signal) => {
711
+ async () => {
711
712
  if (!params) return;
712
713
  try {
713
714
  setLoading(true);
714
715
  setWarning(null);
715
- const result = await getQuote({ ...params, signal });
716
- if (!mountedRef.current) return;
716
+ const result = await getQuote(params);
717
+ if (!mounted.current) return;
717
718
  setData((prev) => {
718
719
  if (JSON.stringify(prev) === JSON.stringify(result)) return prev;
719
720
  return result;
@@ -722,10 +723,10 @@ function useQuote(params, options) {
722
723
  setError(null);
723
724
  } catch (err) {
724
725
  if (err.name === "AbortError") return;
725
- const e = err instanceof Error ? err : new Error(String(err));
726
- if (mountedRef.current) setError(e);
726
+ console.error("[useQuote] fetch error:", err);
727
+ if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
727
728
  } finally {
728
- if (mountedRef.current) setLoading(false);
729
+ if (mounted.current) setLoading(false);
729
730
  }
730
731
  },
731
732
  [params]
@@ -733,25 +734,14 @@ function useQuote(params, options) {
733
734
  (0, import_react3.useEffect)(() => {
734
735
  if (!params) return;
735
736
  if (debounceRef.current) clearTimeout(debounceRef.current);
736
- abortRef.current?.abort();
737
- const controller = new AbortController();
738
- abortRef.current = controller;
739
737
  debounceRef.current = setTimeout(() => {
740
- fetchQuote(controller.signal);
738
+ fetchQuote();
741
739
  }, debounceMs);
742
740
  return () => {
743
- controller.abort();
744
741
  if (debounceRef.current) clearTimeout(debounceRef.current);
742
+ abortRef.current?.abort();
745
743
  };
746
- }, [
747
- params?.tokenIn?.address,
748
- params?.tokenOut?.address,
749
- params?.sourceChainId,
750
- params?.destChainId,
751
- params?.amount,
752
- debounceMs,
753
- fetchQuote
754
- ]);
744
+ }, [params, debounceMs, fetchQuote]);
755
745
  (0, import_react3.useEffect)(() => {
756
746
  if (!autoRefreshMs || !params) return;
757
747
  const interval = setInterval(() => fetchQuote(), autoRefreshMs);
@@ -759,15 +749,10 @@ function useQuote(params, options) {
759
749
  }, [autoRefreshMs, params, fetchQuote]);
760
750
  return (0, import_react3.useMemo)(
761
751
  () => ({
762
- /** Latest quote data */
763
752
  data,
764
- /** Whether a fetch is ongoing */
765
753
  loading,
766
- /** Error (if any) */
767
754
  error,
768
- /** Warning (e.g. high slippage alert) */
769
755
  warning,
770
- /** Manual refetch */
771
756
  refetch: () => fetchQuote()
772
757
  }),
773
758
  [data, loading, error, warning, fetchQuote]
package/dist/react.d.cts CHANGED
@@ -92,44 +92,20 @@ declare function useExecuteOrder(): {
92
92
  };
93
93
 
94
94
  /**
95
- * useQuote — React hook for fetching live swap quotes (single or cross-chain).
95
+ * useQuote — React hook for fetching live swap quotes.
96
96
  *
97
- * @example
98
- * ```tsx
99
- * import { useQuote } from "@shogun-sdk/swap/react"
100
- *
101
- * export function SwapQuote({ params }) {
102
- * const { data, loading, error, warning, refetch } = useQuote(params, { debounceMs: 300 })
103
- *
104
- * if (loading) return <p>Fetching quote...</p>
105
- * if (error) return <p style={{ color: "red" }}>{error.message}</p>
106
- * if (warning) return <p style={{ color: "orange" }}>{warning}</p>
107
- *
108
- * return (
109
- * <div>
110
- * <p>Output: {data?.amountOut.toString()}</p>
111
- * <p>Reduced (after slippage): {data?.internal?.estimatedAmountOutReduced?.toString()}</p>
112
- * <button onClick={refetch}>Refresh</button>
113
- * </div>
114
- * )
115
- * }
116
- * ```
97
+ * - Supports debounce and auto-refresh.
98
+ * - Safe for React 18+ (no double fetch).
99
+ * - Compatible with AbortController.
117
100
  */
118
- declare function useQuote(params: SwapQuoteParams | null, options?: {
119
- /** Debounce duration (ms) for reactive fetches. Default: 250 */
101
+ declare function useQuote(params: SwapQuoteParams, options?: {
120
102
  debounceMs?: number;
121
- /** Optional polling interval (ms) for auto refresh */
122
103
  autoRefreshMs?: number;
123
104
  }): {
124
- /** Latest quote data */
125
105
  data: SwapQuoteResponse | null;
126
- /** Whether a fetch is ongoing */
127
106
  loading: boolean;
128
- /** Error (if any) */
129
107
  error: Error | null;
130
- /** Warning (e.g. high slippage alert) */
131
108
  warning: string | null;
132
- /** Manual refetch */
133
109
  refetch: () => Promise<void>;
134
110
  };
135
111
 
package/dist/react.d.ts CHANGED
@@ -92,44 +92,20 @@ declare function useExecuteOrder(): {
92
92
  };
93
93
 
94
94
  /**
95
- * useQuote — React hook for fetching live swap quotes (single or cross-chain).
95
+ * useQuote — React hook for fetching live swap quotes.
96
96
  *
97
- * @example
98
- * ```tsx
99
- * import { useQuote } from "@shogun-sdk/swap/react"
100
- *
101
- * export function SwapQuote({ params }) {
102
- * const { data, loading, error, warning, refetch } = useQuote(params, { debounceMs: 300 })
103
- *
104
- * if (loading) return <p>Fetching quote...</p>
105
- * if (error) return <p style={{ color: "red" }}>{error.message}</p>
106
- * if (warning) return <p style={{ color: "orange" }}>{warning}</p>
107
- *
108
- * return (
109
- * <div>
110
- * <p>Output: {data?.amountOut.toString()}</p>
111
- * <p>Reduced (after slippage): {data?.internal?.estimatedAmountOutReduced?.toString()}</p>
112
- * <button onClick={refetch}>Refresh</button>
113
- * </div>
114
- * )
115
- * }
116
- * ```
97
+ * - Supports debounce and auto-refresh.
98
+ * - Safe for React 18+ (no double fetch).
99
+ * - Compatible with AbortController.
117
100
  */
118
- declare function useQuote(params: SwapQuoteParams | null, options?: {
119
- /** Debounce duration (ms) for reactive fetches. Default: 250 */
101
+ declare function useQuote(params: SwapQuoteParams, options?: {
120
102
  debounceMs?: number;
121
- /** Optional polling interval (ms) for auto refresh */
122
103
  autoRefreshMs?: number;
123
104
  }): {
124
- /** Latest quote data */
125
105
  data: SwapQuoteResponse | null;
126
- /** Whether a fetch is ongoing */
127
106
  loading: boolean;
128
- /** Error (if any) */
129
107
  error: Error | null;
130
- /** Warning (e.g. high slippage alert) */
131
108
  warning: string | null;
132
- /** Manual refetch */
133
109
  refetch: () => Promise<void>;
134
110
  };
135
111
 
package/dist/react.js CHANGED
@@ -677,22 +677,23 @@ function useQuote(params, options) {
677
677
  const autoRefreshMs = options?.autoRefreshMs;
678
678
  const abortRef = useRef3(null);
679
679
  const debounceRef = useRef3(null);
680
- const mountedRef = useRef3(true);
680
+ const mounted = useRef3(false);
681
681
  useEffect3(() => {
682
+ mounted.current = true;
682
683
  return () => {
683
- mountedRef.current = false;
684
+ mounted.current = false;
684
685
  abortRef.current?.abort();
685
686
  if (debounceRef.current) clearTimeout(debounceRef.current);
686
687
  };
687
688
  }, []);
688
689
  const fetchQuote = useCallback2(
689
- async (signal) => {
690
+ async () => {
690
691
  if (!params) return;
691
692
  try {
692
693
  setLoading(true);
693
694
  setWarning(null);
694
- const result = await getQuote({ ...params, signal });
695
- if (!mountedRef.current) return;
695
+ const result = await getQuote(params);
696
+ if (!mounted.current) return;
696
697
  setData((prev) => {
697
698
  if (JSON.stringify(prev) === JSON.stringify(result)) return prev;
698
699
  return result;
@@ -701,10 +702,10 @@ function useQuote(params, options) {
701
702
  setError(null);
702
703
  } catch (err) {
703
704
  if (err.name === "AbortError") return;
704
- const e = err instanceof Error ? err : new Error(String(err));
705
- if (mountedRef.current) setError(e);
705
+ console.error("[useQuote] fetch error:", err);
706
+ if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
706
707
  } finally {
707
- if (mountedRef.current) setLoading(false);
708
+ if (mounted.current) setLoading(false);
708
709
  }
709
710
  },
710
711
  [params]
@@ -712,25 +713,14 @@ function useQuote(params, options) {
712
713
  useEffect3(() => {
713
714
  if (!params) return;
714
715
  if (debounceRef.current) clearTimeout(debounceRef.current);
715
- abortRef.current?.abort();
716
- const controller = new AbortController();
717
- abortRef.current = controller;
718
716
  debounceRef.current = setTimeout(() => {
719
- fetchQuote(controller.signal);
717
+ fetchQuote();
720
718
  }, debounceMs);
721
719
  return () => {
722
- controller.abort();
723
720
  if (debounceRef.current) clearTimeout(debounceRef.current);
721
+ abortRef.current?.abort();
724
722
  };
725
- }, [
726
- params?.tokenIn?.address,
727
- params?.tokenOut?.address,
728
- params?.sourceChainId,
729
- params?.destChainId,
730
- params?.amount,
731
- debounceMs,
732
- fetchQuote
733
- ]);
723
+ }, [params, debounceMs, fetchQuote]);
734
724
  useEffect3(() => {
735
725
  if (!autoRefreshMs || !params) return;
736
726
  const interval = setInterval(() => fetchQuote(), autoRefreshMs);
@@ -738,15 +728,10 @@ function useQuote(params, options) {
738
728
  }, [autoRefreshMs, params, fetchQuote]);
739
729
  return useMemo2(
740
730
  () => ({
741
- /** Latest quote data */
742
731
  data,
743
- /** Whether a fetch is ongoing */
744
732
  loading,
745
- /** Error (if any) */
746
733
  error,
747
- /** Warning (e.g. high slippage alert) */
748
734
  warning,
749
- /** Manual refetch */
750
735
  refetch: () => fetchQuote()
751
736
  }),
752
737
  [data, loading, error, warning, fetchQuote]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shogun-sdk/swap",
3
- "version": "0.0.2-test.2",
3
+ "version": "0.0.2-test.3",
4
4
  "type": "module",
5
5
  "description": "Shogun Network Swap utilities and helpers",
6
6
  "author": "Shogun Network",