@shogun-sdk/swap 0.0.2-test.3 → 0.0.2-test.5
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 +31 -29
- package/dist/index.js +31 -29
- package/dist/react.cjs +31 -29
- package/dist/react.d.cts +1 -5
- package/dist/react.d.ts +1 -5
- package/dist/react.js +31 -29
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -854,6 +854,10 @@ function useQuote(params, options) {
|
|
|
854
854
|
const abortRef = (0, import_react3.useRef)(null);
|
|
855
855
|
const debounceRef = (0, import_react3.useRef)(null);
|
|
856
856
|
const mounted = (0, import_react3.useRef)(false);
|
|
857
|
+
const paramsKey = (0, import_react3.useMemo)(
|
|
858
|
+
() => params ? JSON.stringify(serializeBigIntsToStrings(params)) : null,
|
|
859
|
+
[params]
|
|
860
|
+
);
|
|
857
861
|
(0, import_react3.useEffect)(() => {
|
|
858
862
|
mounted.current = true;
|
|
859
863
|
return () => {
|
|
@@ -862,32 +866,30 @@ function useQuote(params, options) {
|
|
|
862
866
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
863
867
|
};
|
|
864
868
|
}, []);
|
|
865
|
-
const fetchQuote = (0, import_react3.useCallback)(
|
|
866
|
-
async () => {
|
|
867
|
-
if (!params) return;
|
|
868
|
-
try {
|
|
869
|
-
setLoading(true);
|
|
870
|
-
setWarning(null);
|
|
871
|
-
const result = await getQuote(params);
|
|
872
|
-
if (!mounted.current) return;
|
|
873
|
-
setData((prev) => {
|
|
874
|
-
if (JSON.stringify(prev) === JSON.stringify(result)) return prev;
|
|
875
|
-
return result;
|
|
876
|
-
});
|
|
877
|
-
setWarning(result.warning ?? null);
|
|
878
|
-
setError(null);
|
|
879
|
-
} catch (err) {
|
|
880
|
-
if (err.name === "AbortError") return;
|
|
881
|
-
console.error("[useQuote] fetch error:", err);
|
|
882
|
-
if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
|
|
883
|
-
} finally {
|
|
884
|
-
if (mounted.current) setLoading(false);
|
|
885
|
-
}
|
|
886
|
-
},
|
|
887
|
-
[params]
|
|
888
|
-
);
|
|
889
|
-
(0, import_react3.useEffect)(() => {
|
|
869
|
+
const fetchQuote = (0, import_react3.useCallback)(async () => {
|
|
890
870
|
if (!params) return;
|
|
871
|
+
try {
|
|
872
|
+
setLoading(true);
|
|
873
|
+
setWarning(null);
|
|
874
|
+
const result = await getQuote(params);
|
|
875
|
+
const serializeResult = serializeBigIntsToStrings(result);
|
|
876
|
+
if (!mounted.current) return;
|
|
877
|
+
setData((prev) => {
|
|
878
|
+
if (JSON.stringify(prev) === JSON.stringify(serializeResult)) return prev;
|
|
879
|
+
return serializeResult;
|
|
880
|
+
});
|
|
881
|
+
setWarning(result.warning ?? null);
|
|
882
|
+
setError(null);
|
|
883
|
+
} catch (err) {
|
|
884
|
+
if (err.name === "AbortError") return;
|
|
885
|
+
console.error("[useQuote] fetch error:", err);
|
|
886
|
+
if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
|
|
887
|
+
} finally {
|
|
888
|
+
if (mounted.current) setLoading(false);
|
|
889
|
+
}
|
|
890
|
+
}, [paramsKey]);
|
|
891
|
+
(0, import_react3.useEffect)(() => {
|
|
892
|
+
if (!paramsKey) return;
|
|
891
893
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
892
894
|
debounceRef.current = setTimeout(() => {
|
|
893
895
|
fetchQuote();
|
|
@@ -896,19 +898,19 @@ function useQuote(params, options) {
|
|
|
896
898
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
897
899
|
abortRef.current?.abort();
|
|
898
900
|
};
|
|
899
|
-
}, [
|
|
901
|
+
}, [paramsKey, debounceMs, fetchQuote]);
|
|
900
902
|
(0, import_react3.useEffect)(() => {
|
|
901
|
-
if (!autoRefreshMs || !
|
|
903
|
+
if (!autoRefreshMs || !paramsKey) return;
|
|
902
904
|
const interval = setInterval(() => fetchQuote(), autoRefreshMs);
|
|
903
905
|
return () => clearInterval(interval);
|
|
904
|
-
}, [autoRefreshMs,
|
|
906
|
+
}, [autoRefreshMs, paramsKey, fetchQuote]);
|
|
905
907
|
return (0, import_react3.useMemo)(
|
|
906
908
|
() => ({
|
|
907
909
|
data,
|
|
908
910
|
loading,
|
|
909
911
|
error,
|
|
910
912
|
warning,
|
|
911
|
-
refetch:
|
|
913
|
+
refetch: fetchQuote
|
|
912
914
|
}),
|
|
913
915
|
[data, loading, error, warning, fetchQuote]
|
|
914
916
|
);
|
package/dist/index.js
CHANGED
|
@@ -823,6 +823,10 @@ function useQuote(params, options) {
|
|
|
823
823
|
const abortRef = useRef3(null);
|
|
824
824
|
const debounceRef = useRef3(null);
|
|
825
825
|
const mounted = useRef3(false);
|
|
826
|
+
const paramsKey = useMemo2(
|
|
827
|
+
() => params ? JSON.stringify(serializeBigIntsToStrings(params)) : null,
|
|
828
|
+
[params]
|
|
829
|
+
);
|
|
826
830
|
useEffect3(() => {
|
|
827
831
|
mounted.current = true;
|
|
828
832
|
return () => {
|
|
@@ -831,32 +835,30 @@ function useQuote(params, options) {
|
|
|
831
835
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
832
836
|
};
|
|
833
837
|
}, []);
|
|
834
|
-
const fetchQuote = useCallback2(
|
|
835
|
-
async () => {
|
|
836
|
-
if (!params) return;
|
|
837
|
-
try {
|
|
838
|
-
setLoading(true);
|
|
839
|
-
setWarning(null);
|
|
840
|
-
const result = await getQuote(params);
|
|
841
|
-
if (!mounted.current) return;
|
|
842
|
-
setData((prev) => {
|
|
843
|
-
if (JSON.stringify(prev) === JSON.stringify(result)) return prev;
|
|
844
|
-
return result;
|
|
845
|
-
});
|
|
846
|
-
setWarning(result.warning ?? null);
|
|
847
|
-
setError(null);
|
|
848
|
-
} catch (err) {
|
|
849
|
-
if (err.name === "AbortError") return;
|
|
850
|
-
console.error("[useQuote] fetch error:", err);
|
|
851
|
-
if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
|
|
852
|
-
} finally {
|
|
853
|
-
if (mounted.current) setLoading(false);
|
|
854
|
-
}
|
|
855
|
-
},
|
|
856
|
-
[params]
|
|
857
|
-
);
|
|
858
|
-
useEffect3(() => {
|
|
838
|
+
const fetchQuote = useCallback2(async () => {
|
|
859
839
|
if (!params) return;
|
|
840
|
+
try {
|
|
841
|
+
setLoading(true);
|
|
842
|
+
setWarning(null);
|
|
843
|
+
const result = await getQuote(params);
|
|
844
|
+
const serializeResult = serializeBigIntsToStrings(result);
|
|
845
|
+
if (!mounted.current) return;
|
|
846
|
+
setData((prev) => {
|
|
847
|
+
if (JSON.stringify(prev) === JSON.stringify(serializeResult)) return prev;
|
|
848
|
+
return serializeResult;
|
|
849
|
+
});
|
|
850
|
+
setWarning(result.warning ?? null);
|
|
851
|
+
setError(null);
|
|
852
|
+
} catch (err) {
|
|
853
|
+
if (err.name === "AbortError") return;
|
|
854
|
+
console.error("[useQuote] fetch error:", err);
|
|
855
|
+
if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
|
|
856
|
+
} finally {
|
|
857
|
+
if (mounted.current) setLoading(false);
|
|
858
|
+
}
|
|
859
|
+
}, [paramsKey]);
|
|
860
|
+
useEffect3(() => {
|
|
861
|
+
if (!paramsKey) return;
|
|
860
862
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
861
863
|
debounceRef.current = setTimeout(() => {
|
|
862
864
|
fetchQuote();
|
|
@@ -865,19 +867,19 @@ function useQuote(params, options) {
|
|
|
865
867
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
866
868
|
abortRef.current?.abort();
|
|
867
869
|
};
|
|
868
|
-
}, [
|
|
870
|
+
}, [paramsKey, debounceMs, fetchQuote]);
|
|
869
871
|
useEffect3(() => {
|
|
870
|
-
if (!autoRefreshMs || !
|
|
872
|
+
if (!autoRefreshMs || !paramsKey) return;
|
|
871
873
|
const interval = setInterval(() => fetchQuote(), autoRefreshMs);
|
|
872
874
|
return () => clearInterval(interval);
|
|
873
|
-
}, [autoRefreshMs,
|
|
875
|
+
}, [autoRefreshMs, paramsKey, fetchQuote]);
|
|
874
876
|
return useMemo2(
|
|
875
877
|
() => ({
|
|
876
878
|
data,
|
|
877
879
|
loading,
|
|
878
880
|
error,
|
|
879
881
|
warning,
|
|
880
|
-
refetch:
|
|
882
|
+
refetch: fetchQuote
|
|
881
883
|
}),
|
|
882
884
|
[data, loading, error, warning, fetchQuote]
|
|
883
885
|
);
|
package/dist/react.cjs
CHANGED
|
@@ -699,6 +699,10 @@ function useQuote(params, options) {
|
|
|
699
699
|
const abortRef = (0, import_react3.useRef)(null);
|
|
700
700
|
const debounceRef = (0, import_react3.useRef)(null);
|
|
701
701
|
const mounted = (0, import_react3.useRef)(false);
|
|
702
|
+
const paramsKey = (0, import_react3.useMemo)(
|
|
703
|
+
() => params ? JSON.stringify(serializeBigIntsToStrings(params)) : null,
|
|
704
|
+
[params]
|
|
705
|
+
);
|
|
702
706
|
(0, import_react3.useEffect)(() => {
|
|
703
707
|
mounted.current = true;
|
|
704
708
|
return () => {
|
|
@@ -707,32 +711,30 @@ function useQuote(params, options) {
|
|
|
707
711
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
708
712
|
};
|
|
709
713
|
}, []);
|
|
710
|
-
const fetchQuote = (0, import_react3.useCallback)(
|
|
711
|
-
async () => {
|
|
712
|
-
if (!params) return;
|
|
713
|
-
try {
|
|
714
|
-
setLoading(true);
|
|
715
|
-
setWarning(null);
|
|
716
|
-
const result = await getQuote(params);
|
|
717
|
-
if (!mounted.current) return;
|
|
718
|
-
setData((prev) => {
|
|
719
|
-
if (JSON.stringify(prev) === JSON.stringify(result)) return prev;
|
|
720
|
-
return result;
|
|
721
|
-
});
|
|
722
|
-
setWarning(result.warning ?? null);
|
|
723
|
-
setError(null);
|
|
724
|
-
} catch (err) {
|
|
725
|
-
if (err.name === "AbortError") return;
|
|
726
|
-
console.error("[useQuote] fetch error:", err);
|
|
727
|
-
if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
|
|
728
|
-
} finally {
|
|
729
|
-
if (mounted.current) setLoading(false);
|
|
730
|
-
}
|
|
731
|
-
},
|
|
732
|
-
[params]
|
|
733
|
-
);
|
|
734
|
-
(0, import_react3.useEffect)(() => {
|
|
714
|
+
const fetchQuote = (0, import_react3.useCallback)(async () => {
|
|
735
715
|
if (!params) return;
|
|
716
|
+
try {
|
|
717
|
+
setLoading(true);
|
|
718
|
+
setWarning(null);
|
|
719
|
+
const result = await getQuote(params);
|
|
720
|
+
const serializeResult = serializeBigIntsToStrings(result);
|
|
721
|
+
if (!mounted.current) return;
|
|
722
|
+
setData((prev) => {
|
|
723
|
+
if (JSON.stringify(prev) === JSON.stringify(serializeResult)) return prev;
|
|
724
|
+
return serializeResult;
|
|
725
|
+
});
|
|
726
|
+
setWarning(result.warning ?? null);
|
|
727
|
+
setError(null);
|
|
728
|
+
} catch (err) {
|
|
729
|
+
if (err.name === "AbortError") return;
|
|
730
|
+
console.error("[useQuote] fetch error:", err);
|
|
731
|
+
if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
|
|
732
|
+
} finally {
|
|
733
|
+
if (mounted.current) setLoading(false);
|
|
734
|
+
}
|
|
735
|
+
}, [paramsKey]);
|
|
736
|
+
(0, import_react3.useEffect)(() => {
|
|
737
|
+
if (!paramsKey) return;
|
|
736
738
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
737
739
|
debounceRef.current = setTimeout(() => {
|
|
738
740
|
fetchQuote();
|
|
@@ -741,19 +743,19 @@ function useQuote(params, options) {
|
|
|
741
743
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
742
744
|
abortRef.current?.abort();
|
|
743
745
|
};
|
|
744
|
-
}, [
|
|
746
|
+
}, [paramsKey, debounceMs, fetchQuote]);
|
|
745
747
|
(0, import_react3.useEffect)(() => {
|
|
746
|
-
if (!autoRefreshMs || !
|
|
748
|
+
if (!autoRefreshMs || !paramsKey) return;
|
|
747
749
|
const interval = setInterval(() => fetchQuote(), autoRefreshMs);
|
|
748
750
|
return () => clearInterval(interval);
|
|
749
|
-
}, [autoRefreshMs,
|
|
751
|
+
}, [autoRefreshMs, paramsKey, fetchQuote]);
|
|
750
752
|
return (0, import_react3.useMemo)(
|
|
751
753
|
() => ({
|
|
752
754
|
data,
|
|
753
755
|
loading,
|
|
754
756
|
error,
|
|
755
757
|
warning,
|
|
756
|
-
refetch:
|
|
758
|
+
refetch: fetchQuote
|
|
757
759
|
}),
|
|
758
760
|
[data, loading, error, warning, fetchQuote]
|
|
759
761
|
);
|
package/dist/react.d.cts
CHANGED
|
@@ -93,12 +93,8 @@ declare function useExecuteOrder(): {
|
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
95
|
* useQuote — React hook for fetching live swap quotes.
|
|
96
|
-
*
|
|
97
|
-
* - Supports debounce and auto-refresh.
|
|
98
|
-
* - Safe for React 18+ (no double fetch).
|
|
99
|
-
* - Compatible with AbortController.
|
|
100
96
|
*/
|
|
101
|
-
declare function useQuote(params: SwapQuoteParams, options?: {
|
|
97
|
+
declare function useQuote(params: SwapQuoteParams | null, options?: {
|
|
102
98
|
debounceMs?: number;
|
|
103
99
|
autoRefreshMs?: number;
|
|
104
100
|
}): {
|
package/dist/react.d.ts
CHANGED
|
@@ -93,12 +93,8 @@ declare function useExecuteOrder(): {
|
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
95
|
* useQuote — React hook for fetching live swap quotes.
|
|
96
|
-
*
|
|
97
|
-
* - Supports debounce and auto-refresh.
|
|
98
|
-
* - Safe for React 18+ (no double fetch).
|
|
99
|
-
* - Compatible with AbortController.
|
|
100
96
|
*/
|
|
101
|
-
declare function useQuote(params: SwapQuoteParams, options?: {
|
|
97
|
+
declare function useQuote(params: SwapQuoteParams | null, options?: {
|
|
102
98
|
debounceMs?: number;
|
|
103
99
|
autoRefreshMs?: number;
|
|
104
100
|
}): {
|
package/dist/react.js
CHANGED
|
@@ -678,6 +678,10 @@ function useQuote(params, options) {
|
|
|
678
678
|
const abortRef = useRef3(null);
|
|
679
679
|
const debounceRef = useRef3(null);
|
|
680
680
|
const mounted = useRef3(false);
|
|
681
|
+
const paramsKey = useMemo2(
|
|
682
|
+
() => params ? JSON.stringify(serializeBigIntsToStrings(params)) : null,
|
|
683
|
+
[params]
|
|
684
|
+
);
|
|
681
685
|
useEffect3(() => {
|
|
682
686
|
mounted.current = true;
|
|
683
687
|
return () => {
|
|
@@ -686,32 +690,30 @@ function useQuote(params, options) {
|
|
|
686
690
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
687
691
|
};
|
|
688
692
|
}, []);
|
|
689
|
-
const fetchQuote = useCallback2(
|
|
690
|
-
async () => {
|
|
691
|
-
if (!params) return;
|
|
692
|
-
try {
|
|
693
|
-
setLoading(true);
|
|
694
|
-
setWarning(null);
|
|
695
|
-
const result = await getQuote(params);
|
|
696
|
-
if (!mounted.current) return;
|
|
697
|
-
setData((prev) => {
|
|
698
|
-
if (JSON.stringify(prev) === JSON.stringify(result)) return prev;
|
|
699
|
-
return result;
|
|
700
|
-
});
|
|
701
|
-
setWarning(result.warning ?? null);
|
|
702
|
-
setError(null);
|
|
703
|
-
} catch (err) {
|
|
704
|
-
if (err.name === "AbortError") return;
|
|
705
|
-
console.error("[useQuote] fetch error:", err);
|
|
706
|
-
if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
|
|
707
|
-
} finally {
|
|
708
|
-
if (mounted.current) setLoading(false);
|
|
709
|
-
}
|
|
710
|
-
},
|
|
711
|
-
[params]
|
|
712
|
-
);
|
|
713
|
-
useEffect3(() => {
|
|
693
|
+
const fetchQuote = useCallback2(async () => {
|
|
714
694
|
if (!params) return;
|
|
695
|
+
try {
|
|
696
|
+
setLoading(true);
|
|
697
|
+
setWarning(null);
|
|
698
|
+
const result = await getQuote(params);
|
|
699
|
+
const serializeResult = serializeBigIntsToStrings(result);
|
|
700
|
+
if (!mounted.current) return;
|
|
701
|
+
setData((prev) => {
|
|
702
|
+
if (JSON.stringify(prev) === JSON.stringify(serializeResult)) return prev;
|
|
703
|
+
return serializeResult;
|
|
704
|
+
});
|
|
705
|
+
setWarning(result.warning ?? null);
|
|
706
|
+
setError(null);
|
|
707
|
+
} catch (err) {
|
|
708
|
+
if (err.name === "AbortError") return;
|
|
709
|
+
console.error("[useQuote] fetch error:", err);
|
|
710
|
+
if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
|
|
711
|
+
} finally {
|
|
712
|
+
if (mounted.current) setLoading(false);
|
|
713
|
+
}
|
|
714
|
+
}, [paramsKey]);
|
|
715
|
+
useEffect3(() => {
|
|
716
|
+
if (!paramsKey) return;
|
|
715
717
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
716
718
|
debounceRef.current = setTimeout(() => {
|
|
717
719
|
fetchQuote();
|
|
@@ -720,19 +722,19 @@ function useQuote(params, options) {
|
|
|
720
722
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
721
723
|
abortRef.current?.abort();
|
|
722
724
|
};
|
|
723
|
-
}, [
|
|
725
|
+
}, [paramsKey, debounceMs, fetchQuote]);
|
|
724
726
|
useEffect3(() => {
|
|
725
|
-
if (!autoRefreshMs || !
|
|
727
|
+
if (!autoRefreshMs || !paramsKey) return;
|
|
726
728
|
const interval = setInterval(() => fetchQuote(), autoRefreshMs);
|
|
727
729
|
return () => clearInterval(interval);
|
|
728
|
-
}, [autoRefreshMs,
|
|
730
|
+
}, [autoRefreshMs, paramsKey, fetchQuote]);
|
|
729
731
|
return useMemo2(
|
|
730
732
|
() => ({
|
|
731
733
|
data,
|
|
732
734
|
loading,
|
|
733
735
|
error,
|
|
734
736
|
warning,
|
|
735
|
-
refetch:
|
|
737
|
+
refetch: fetchQuote
|
|
736
738
|
}),
|
|
737
739
|
[data, loading, error, warning, fetchQuote]
|
|
738
740
|
);
|