diff --git a/src/components/Availability/AvailabilityReservations.tsx b/src/components/Availability/AvailabilityReservations.tsx index c996ed1..8e788f4 100644 --- a/src/components/Availability/AvailabilityReservations.tsx +++ b/src/components/Availability/AvailabilityReservations.tsx @@ -38,7 +38,7 @@ export function AvailabilityReservations({ error, } = useQuery({ queryFn: () => - CodexSdk.marketplace + CodexSdk.marketplace() .reservations(availability!.id) .then((s) => Promises.rejectOnError(s)), queryKey: ["reservations"], diff --git a/src/components/Availability/useAvailabilityMutation.ts b/src/components/Availability/useAvailabilityMutation.ts index d1f4bba..5e3f6ab 100644 --- a/src/components/Availability/useAvailabilityMutation.ts +++ b/src/components/Availability/useAvailabilityMutation.ts @@ -27,18 +27,17 @@ export function useAvailabilityMutation( ...input }: AvailabilityState) => { const unit = totalSizeUnit === "gb" ? GB : TB; - const marketplace = CodexSdk.marketplace; const time = Times.toSeconds(duration, durationUnit); const fn: ( input: Omit ) => Promise = input.id - ? (input) => - marketplace + ? (input) => + CodexSdk.marketplace() .updateAvailability({ ...input, id: input.id || "" }) .then((s) => Promises.rejectOnError(s)) - : (input) => - marketplace + : (input) => + CodexSdk.marketplace() .createAvailability(input) .then((s) => Promises.rejectOnError(s)); diff --git a/src/components/Debug/Debug.tsx b/src/components/Debug/Debug.tsx index fb01fca..29f6216 100644 --- a/src/components/Debug/Debug.tsx +++ b/src/components/Debug/Debug.tsx @@ -6,7 +6,10 @@ import { CircleX } from "lucide-react"; export function Debug() { const { data, isPending, isError, error } = useQuery({ - queryFn: () => CodexSdk.debug.info().then((s) => Promises.rejectOnError(s)), + queryFn: () => + CodexSdk.debug() + .info() + .then((s) => Promises.rejectOnError(s)), queryKey: ["debug"], // No need to retry because if the connection to the node diff --git a/src/components/LogLevel/LogLevel.tsx b/src/components/LogLevel/LogLevel.tsx index 201ec40..c2f3978 100644 --- a/src/components/LogLevel/LogLevel.tsx +++ b/src/components/LogLevel/LogLevel.tsx @@ -15,7 +15,9 @@ export function LogLevel() { const [level, setLevel] = useState("DEBUG"); const { mutateAsync, isPending } = useMutation({ mutationFn: (level: CodexLogLevel) => - CodexSdk.debug.setLogLevel(level).then((s) => Promises.rejectOnError(s)), + CodexSdk.debug() + .setLogLevel(level) + .then((s) => Promises.rejectOnError(s)), onSuccess: () => { setToast({ message: "The log level has been updated successfully.", diff --git a/src/components/NodeIndicator/NodeIndicator.tsx b/src/components/NodeIndicator/NodeIndicator.tsx index dd81e41..d2319d5 100644 --- a/src/components/NodeIndicator/NodeIndicator.tsx +++ b/src/components/NodeIndicator/NodeIndicator.tsx @@ -19,8 +19,11 @@ export function NodeIndicator() { const { data, isError } = useQuery({ queryKey: ["spr"], - queryFn: async () => - CodexSdk.node.spr().then((data) => Promises.rejectOnError(data, report)), + queryFn: async () => { + return CodexSdk.node() + .spr() + .then((data) => Promises.rejectOnError(data, report)); + }, refetchInterval: 5000, // No need to retry because we defined a refetch interval diff --git a/src/components/NodeSpaceAllocation/NodeSpaceAllocation.tsx b/src/components/NodeSpaceAllocation/NodeSpaceAllocation.tsx index d3534e7..e5cca39 100644 --- a/src/components/NodeSpaceAllocation/NodeSpaceAllocation.tsx +++ b/src/components/NodeSpaceAllocation/NodeSpaceAllocation.tsx @@ -14,7 +14,10 @@ const defaultSpace = { export function NodeSpaceAllocation() { const { data: space, isPending } = useQuery({ - queryFn: () => CodexSdk.data.space().then((s) => Promises.rejectOnError(s)), + queryFn: () => + CodexSdk.data() + .space() + .then((s) => Promises.rejectOnError(s)), queryKey: ["space"], initialData: defaultSpace, diff --git a/src/components/StorageRequestSetup/StorageRequestFileChooser.tsx b/src/components/StorageRequestSetup/StorageRequestFileChooser.tsx index 23a2fea..e5f7321 100644 --- a/src/components/StorageRequestSetup/StorageRequestFileChooser.tsx +++ b/src/components/StorageRequestSetup/StorageRequestFileChooser.tsx @@ -95,7 +95,7 @@ export function StorageRequestFileChooser({ onSuccess={onSuccess} editable={false} onDeleteItem={onDelete} - codexData={CodexSdk.data} + codexData={CodexSdk.data()} successMessage={"Success, the CID has been copied to the field on top."} /> diff --git a/src/components/StorageRequestSetup/useStorageRequestMutation.ts b/src/components/StorageRequestSetup/useStorageRequestMutation.ts index 1c30393..1c349a6 100644 --- a/src/components/StorageRequestSetup/useStorageRequestMutation.ts +++ b/src/components/StorageRequestSetup/useStorageRequestMutation.ts @@ -18,7 +18,7 @@ export function useStorageRequestMutation( const { mutateAsync } = useMutation({ mutationFn: (input: CodexCreateStorageRequestInput) => - CodexSdk.marketplace + CodexSdk.marketplace() .createStorageRequest(input) .then((s) => Promises.rejectOnError(s)), onSuccess: async () => { diff --git a/src/hooks/useData.tsx b/src/hooks/useData.tsx index bc95da1..19e7b52 100644 --- a/src/hooks/useData.tsx +++ b/src/hooks/useData.tsx @@ -7,7 +7,9 @@ export function useData() { const { data = { content: [] } satisfies CodexDataResponse } = useQuery({ queryFn: () => - CodexSdk.data.cids().then((res) => Promises.rejectOnError(res)), + CodexSdk.data() + .cids() + .then((res) => Promises.rejectOnError(res)), queryKey: ["cids"], initialData: { content: [] } satisfies CodexDataResponse, diff --git a/src/proxy.ts b/src/proxy.ts index a5b0eaf..04a8f54 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -179,6 +179,6 @@ class CodexMarketplaceMock extends CodexMarketplace { export const CodexSdk = { ...Sdk, - marketplace: new CodexMarketplaceMock(import.meta.env.VITE_CODEX_API_URL), - data: new CodexDataMock(import.meta.env.VITE_CODEX_API_URL), + marketplace: () => new CodexMarketplaceMock(CodexSdk.url()), + data: () => new CodexDataMock(CodexSdk.url()), }; diff --git a/src/routes/dashboard/availabilities.tsx b/src/routes/dashboard/availabilities.tsx index b22ac83..334f80f 100644 --- a/src/routes/dashboard/availabilities.tsx +++ b/src/routes/dashboard/availabilities.tsx @@ -21,7 +21,7 @@ export function Availabilities() { // Error will be catched in ErrorBounday const { data: availabilities = [], isPending } = useQuery({ queryFn: () => - CodexSdk.marketplace + CodexSdk.marketplace() .availabilities() .then((s) => Promises.rejectOnError(s)) .then((res) => res.sort((a, b) => b.totalSize - a.totalSize)), @@ -47,7 +47,9 @@ export function Availabilities() { // Error will be catched in ErrorBounday const { data: space = defaultSpace } = useQuery({ queryFn: () => - CodexSdk.data.space().then((s) => Promises.rejectOnError(s)), + CodexSdk.data() + .space() + .then((s) => Promises.rejectOnError(s)), queryKey: ["space"], initialData: defaultSpace, diff --git a/src/routes/dashboard/index.tsx b/src/routes/dashboard/index.tsx index 4832997..25ffa1f 100644 --- a/src/routes/dashboard/index.tsx +++ b/src/routes/dashboard/index.tsx @@ -18,6 +18,8 @@ function About() { queryClient.invalidateQueries({ queryKey: ["cids"] }); }; + console.info(CodexSdk.data); + return ( <>
@@ -29,7 +31,11 @@ function About() { /> )}> - + diff --git a/src/routes/dashboard/purchases.tsx b/src/routes/dashboard/purchases.tsx index 842b355..ccbe06f 100644 --- a/src/routes/dashboard/purchases.tsx +++ b/src/routes/dashboard/purchases.tsx @@ -20,7 +20,9 @@ import { ErrorBoundary } from "@sentry/react"; const Purchases = () => { const { data, isPending } = useQuery({ queryFn: () => - CodexSdk.marketplace.purchases().then((s) => Promises.rejectOnError(s)), + CodexSdk.marketplace() + .purchases() + .then((s) => Promises.rejectOnError(s)), queryKey: ["purchases"], // No need to retry because if the connection to the node diff --git a/src/sdk/codex.ts b/src/sdk/codex.ts index 491afeb..d4660f7 100644 --- a/src/sdk/codex.ts +++ b/src/sdk/codex.ts @@ -23,11 +23,19 @@ export const CodexSdk = { return WebStorage.set("codex-node-url", url); }, - debug: client.debug, + debug() { + return client.debug + }, - data: client.data, + data() { + return client.data + }, - node: client.node, + node() { + return client.node + }, - marketplace: client.marketplace, + marketplace() { + return client.marketplace + }, };