Skip to content

Commit

Permalink
add version query in api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
arentant committed Sep 5, 2023
1 parent 96b959a commit 02d3af1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ type Transaction = {

export default function DataTable() {
const fetcher = (url: string) => fetch(url).then(r => r.json())
const { data, error, isLoading } = useSWR<ApiResponse<Swap[]>>(`${AppSettings.LayerswapApiUri}/api/explorer/?statuses=1&statuses=4`, fetcher, { dedupingInterval: 60000 });
const version = process.env.NEXT_PUBLIC_API_VERSION
const { data, error, isLoading } = useSWR<ApiResponse<Swap[]>>(`${AppSettings.LayerswapApiUri}/api/explorer/?statuses=1&statuses=4&version=${version}`, fetcher, { dedupingInterval: 60000 });
const swapsData = data?.data;
const settings = useSettingsState();
const router = useRouter();
Expand Down
3 changes: 2 additions & 1 deletion app/[searchParam]/SearchData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ export default function SearchData({ searchParam }: { searchParam: string }) {
const router = useRouter();
const pathname = usePathname();
const basePath = process.env.NEXT_PUBLIC_APP_BASE_PATH
const version = process.env.NEXT_PUBLIC_API_VERSION
const fetcher = (url: string) => fetch(url).then(r => r.json())
const { data, error, isLoading } = useSWR<ApiResponse<Swap[]>>(`${AppSettings.LayerswapApiUri}/api/explorer/${searchParam}`, fetcher, { dedupingInterval: 60000 });
const { data, error, isLoading } = useSWR<ApiResponse<Swap[]>>(`${AppSettings.LayerswapApiUri}/api/explorer/${searchParam}?version=${version}`, fetcher, { dedupingInterval: 60000 });
const swap = data?.data?.[0];

const input_transaction = swap?.transactions?.find(t => t?.type == TransactionType.Input);
Expand Down
6 changes: 3 additions & 3 deletions context/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use client'
import { mapNetworkCurrencies } from '@/helpers/settingsHelper';

import LayerSwapApiClient from '@/lib/layerSwapApiClient';
import { ApiResponse } from '@/models/ApiResponse';
import { LayerSwapAppSettings } from '@/models/LayerSwapAppSettings';
import { LayerSwapSettings } from '@/models/LayerSwapSettings';
import React, { FC, ReactNode, useEffect, useState } from 'react'
import React, { FC, ReactNode } from 'react'
import useSWR from 'swr';

const SettingsStateContext = React.createContext<LayerSwapAppSettings | null>(null);
Expand All @@ -13,7 +13,7 @@ export const SettingsProvider: FC<{ children: ReactNode }> = ({ children }) => {

const fetcher = (url: string) => fetch(url).then(r => r.json());
const version = process.env.NEXT_PUBLIC_API_VERSION;
const { data: settings, error, isLoading } = useSWR<ApiResponse<LayerSwapSettings>>(`${LayerSwapApiClient.apiBaseEndpoint}/api/settings?version=${version}`, fetcher, { dedupingInterval: 60000 });
const { data: settings } = useSWR<ApiResponse<LayerSwapSettings>>(`${LayerSwapApiClient.apiBaseEndpoint}/api/settings?version=${version}`, fetcher, { dedupingInterval: 60000 });

let appSettings = new LayerSwapAppSettings(settings?.data);

Expand Down

0 comments on commit 02d3af1

Please sign in to comment.