@shogun-sdk/swap 0.0.2-test.2 → 0.0.2-test.4

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,34 +853,36 @@ 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
+ const serializeResult = serializeBigIntsToStrings(result);
873
+ if (!mounted.current) return;
872
874
  setData((prev) => {
873
- if (JSON.stringify(prev) === JSON.stringify(result)) return prev;
874
- return result;
875
+ if (JSON.stringify(prev) === JSON.stringify(serializeResult)) return prev;
876
+ return serializeResult;
875
877
  });
876
878
  setWarning(result.warning ?? null);
877
879
  setError(null);
878
880
  } catch (err) {
879
881
  if (err.name === "AbortError") return;
880
- const e = err instanceof Error ? err : new Error(String(err));
881
- if (mountedRef.current) setError(e);
882
+ console.error("[useQuote] fetch error:", err);
883
+ if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
882
884
  } finally {
883
- if (mountedRef.current) setLoading(false);
885
+ if (mounted.current) setLoading(false);
884
886
  }
885
887
  },
886
888
  [params]
@@ -888,25 +890,14 @@ function useQuote(params, options) {
888
890
  (0, import_react3.useEffect)(() => {
889
891
  if (!params) return;
890
892
  if (debounceRef.current) clearTimeout(debounceRef.current);
891
- abortRef.current?.abort();
892
- const controller = new AbortController();
893
- abortRef.current = controller;
894
893
  debounceRef.current = setTimeout(() => {
895
- fetchQuote(controller.signal);
894
+ fetchQuote();
896
895
  }, debounceMs);
897
896
  return () => {
898
- controller.abort();
899
897
  if (debounceRef.current) clearTimeout(debounceRef.current);
898
+ abortRef.current?.abort();
900
899
  };
901
- }, [
902
- params?.tokenIn?.address,
903
- params?.tokenOut?.address,
904
- params?.sourceChainId,
905
- params?.destChainId,
906
- params?.amount,
907
- debounceMs,
908
- fetchQuote
909
- ]);
900
+ }, [params, debounceMs, fetchQuote]);
910
901
  (0, import_react3.useEffect)(() => {
911
902
  if (!autoRefreshMs || !params) return;
912
903
  const interval = setInterval(() => fetchQuote(), autoRefreshMs);
@@ -914,15 +905,10 @@ function useQuote(params, options) {
914
905
  }, [autoRefreshMs, params, fetchQuote]);
915
906
  return (0, import_react3.useMemo)(
916
907
  () => ({
917
- /** Latest quote data */
918
908
  data,
919
- /** Whether a fetch is ongoing */
920
909
  loading,
921
- /** Error (if any) */
922
910
  error,
923
- /** Warning (e.g. high slippage alert) */
924
911
  warning,
925
- /** Manual refetch */
926
912
  refetch: () => fetchQuote()
927
913
  }),
928
914
  [data, loading, error, warning, fetchQuote]
package/dist/index.js CHANGED
@@ -822,34 +822,36 @@ 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
+ const serializeResult = serializeBigIntsToStrings(result);
842
+ if (!mounted.current) return;
841
843
  setData((prev) => {
842
- if (JSON.stringify(prev) === JSON.stringify(result)) return prev;
843
- return result;
844
+ if (JSON.stringify(prev) === JSON.stringify(serializeResult)) return prev;
845
+ return serializeResult;
844
846
  });
845
847
  setWarning(result.warning ?? null);
846
848
  setError(null);
847
849
  } catch (err) {
848
850
  if (err.name === "AbortError") return;
849
- const e = err instanceof Error ? err : new Error(String(err));
850
- if (mountedRef.current) setError(e);
851
+ console.error("[useQuote] fetch error:", err);
852
+ if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
851
853
  } finally {
852
- if (mountedRef.current) setLoading(false);
854
+ if (mounted.current) setLoading(false);
853
855
  }
854
856
  },
855
857
  [params]
@@ -857,25 +859,14 @@ function useQuote(params, options) {
857
859
  useEffect3(() => {
858
860
  if (!params) return;
859
861
  if (debounceRef.current) clearTimeout(debounceRef.current);
860
- abortRef.current?.abort();
861
- const controller = new AbortController();
862
- abortRef.current = controller;
863
862
  debounceRef.current = setTimeout(() => {
864
- fetchQuote(controller.signal);
863
+ fetchQuote();
865
864
  }, debounceMs);
866
865
  return () => {
867
- controller.abort();
868
866
  if (debounceRef.current) clearTimeout(debounceRef.current);
867
+ abortRef.current?.abort();
869
868
  };
870
- }, [
871
- params?.tokenIn?.address,
872
- params?.tokenOut?.address,
873
- params?.sourceChainId,
874
- params?.destChainId,
875
- params?.amount,
876
- debounceMs,
877
- fetchQuote
878
- ]);
869
+ }, [params, debounceMs, fetchQuote]);
879
870
  useEffect3(() => {
880
871
  if (!autoRefreshMs || !params) return;
881
872
  const interval = setInterval(() => fetchQuote(), autoRefreshMs);
@@ -883,15 +874,10 @@ function useQuote(params, options) {
883
874
  }, [autoRefreshMs, params, fetchQuote]);
884
875
  return useMemo2(
885
876
  () => ({
886
- /** Latest quote data */
887
877
  data,
888
- /** Whether a fetch is ongoing */
889
878
  loading,
890
- /** Error (if any) */
891
879
  error,
892
- /** Warning (e.g. high slippage alert) */
893
880
  warning,
894
- /** Manual refetch */
895
881
  refetch: () => fetchQuote()
896
882
  }),
897
883
  [data, loading, error, warning, fetchQuote]
package/dist/react.cjs CHANGED
@@ -698,34 +698,36 @@ 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
+ const serializeResult = serializeBigIntsToStrings(result);
718
+ if (!mounted.current) return;
717
719
  setData((prev) => {
718
- if (JSON.stringify(prev) === JSON.stringify(result)) return prev;
719
- return result;
720
+ if (JSON.stringify(prev) === JSON.stringify(serializeResult)) return prev;
721
+ return serializeResult;
720
722
  });
721
723
  setWarning(result.warning ?? null);
722
724
  setError(null);
723
725
  } catch (err) {
724
726
  if (err.name === "AbortError") return;
725
- const e = err instanceof Error ? err : new Error(String(err));
726
- if (mountedRef.current) setError(e);
727
+ console.error("[useQuote] fetch error:", err);
728
+ if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
727
729
  } finally {
728
- if (mountedRef.current) setLoading(false);
730
+ if (mounted.current) setLoading(false);
729
731
  }
730
732
  },
731
733
  [params]
@@ -733,25 +735,14 @@ function useQuote(params, options) {
733
735
  (0, import_react3.useEffect)(() => {
734
736
  if (!params) return;
735
737
  if (debounceRef.current) clearTimeout(debounceRef.current);
736
- abortRef.current?.abort();
737
- const controller = new AbortController();
738
- abortRef.current = controller;
739
738
  debounceRef.current = setTimeout(() => {
740
- fetchQuote(controller.signal);
739
+ fetchQuote();
741
740
  }, debounceMs);
742
741
  return () => {
743
- controller.abort();
744
742
  if (debounceRef.current) clearTimeout(debounceRef.current);
743
+ abortRef.current?.abort();
745
744
  };
746
- }, [
747
- params?.tokenIn?.address,
748
- params?.tokenOut?.address,
749
- params?.sourceChainId,
750
- params?.destChainId,
751
- params?.amount,
752
- debounceMs,
753
- fetchQuote
754
- ]);
745
+ }, [params, debounceMs, fetchQuote]);
755
746
  (0, import_react3.useEffect)(() => {
756
747
  if (!autoRefreshMs || !params) return;
757
748
  const interval = setInterval(() => fetchQuote(), autoRefreshMs);
@@ -759,15 +750,10 @@ function useQuote(params, options) {
759
750
  }, [autoRefreshMs, params, fetchQuote]);
760
751
  return (0, import_react3.useMemo)(
761
752
  () => ({
762
- /** Latest quote data */
763
753
  data,
764
- /** Whether a fetch is ongoing */
765
754
  loading,
766
- /** Error (if any) */
767
755
  error,
768
- /** Warning (e.g. high slippage alert) */
769
756
  warning,
770
- /** Manual refetch */
771
757
  refetch: () => fetchQuote()
772
758
  }),
773
759
  [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,34 +677,36 @@ 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
+ const serializeResult = serializeBigIntsToStrings(result);
697
+ if (!mounted.current) return;
696
698
  setData((prev) => {
697
- if (JSON.stringify(prev) === JSON.stringify(result)) return prev;
698
- return result;
699
+ if (JSON.stringify(prev) === JSON.stringify(serializeResult)) return prev;
700
+ return serializeResult;
699
701
  });
700
702
  setWarning(result.warning ?? null);
701
703
  setError(null);
702
704
  } catch (err) {
703
705
  if (err.name === "AbortError") return;
704
- const e = err instanceof Error ? err : new Error(String(err));
705
- if (mountedRef.current) setError(e);
706
+ console.error("[useQuote] fetch error:", err);
707
+ if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
706
708
  } finally {
707
- if (mountedRef.current) setLoading(false);
709
+ if (mounted.current) setLoading(false);
708
710
  }
709
711
  },
710
712
  [params]
@@ -712,25 +714,14 @@ function useQuote(params, options) {
712
714
  useEffect3(() => {
713
715
  if (!params) return;
714
716
  if (debounceRef.current) clearTimeout(debounceRef.current);
715
- abortRef.current?.abort();
716
- const controller = new AbortController();
717
- abortRef.current = controller;
718
717
  debounceRef.current = setTimeout(() => {
719
- fetchQuote(controller.signal);
718
+ fetchQuote();
720
719
  }, debounceMs);
721
720
  return () => {
722
- controller.abort();
723
721
  if (debounceRef.current) clearTimeout(debounceRef.current);
722
+ abortRef.current?.abort();
724
723
  };
725
- }, [
726
- params?.tokenIn?.address,
727
- params?.tokenOut?.address,
728
- params?.sourceChainId,
729
- params?.destChainId,
730
- params?.amount,
731
- debounceMs,
732
- fetchQuote
733
- ]);
724
+ }, [params, debounceMs, fetchQuote]);
734
725
  useEffect3(() => {
735
726
  if (!autoRefreshMs || !params) return;
736
727
  const interval = setInterval(() => fetchQuote(), autoRefreshMs);
@@ -738,15 +729,10 @@ function useQuote(params, options) {
738
729
  }, [autoRefreshMs, params, fetchQuote]);
739
730
  return useMemo2(
740
731
  () => ({
741
- /** Latest quote data */
742
732
  data,
743
- /** Whether a fetch is ongoing */
744
733
  loading,
745
- /** Error (if any) */
746
734
  error,
747
- /** Warning (e.g. high slippage alert) */
748
735
  warning,
749
- /** Manual refetch */
750
736
  refetch: () => fetchQuote()
751
737
  }),
752
738
  [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.4",
4
4
  "type": "module",
5
5
  "description": "Shogun Network Swap utilities and helpers",
6
6
  "author": "Shogun Network",