Skip to content

Commit

Permalink
chore: refactor rm unnessary catch (#2126)
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh authored Jul 28, 2023
1 parent 1489e06 commit 3540215
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
22 changes: 9 additions & 13 deletions src/hooks/useBasicChartData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ const fetchKyberDataSWR = async (url: string) => {
}

const fetchKyberDataSWRWithHeader = async (url: string) => {
const res = await KyberOauth2Api.get(url, {
const res = await KyberOauth2Api.get(url, undefined, {
timeout: 5000,
headers: {
'accept-version': 'Latest',
},
}).catch(error => {
throw error
})

if (res.status === 204) {
Expand All @@ -93,16 +91,14 @@ const fetchCoingeckoDataSWR = async ([tokenAddresses, chainIds, timeFrame, coing
]): Promise<any> => {
return await Promise.all(
[tokenAddresses[0], tokenAddresses[1]].map((address, i) =>
KyberOauth2Api.get(generateCoingeckoUrl(coingeckoAPI, chainIds[i], address, timeFrame), { timeout: 5000 })
.then(res => {
if (res.status === 204) {
throw new Error('No content')
}
return res.data
})
.catch(error => {
throw error
}),
KyberOauth2Api.get(generateCoingeckoUrl(coingeckoAPI, chainIds[i], address, timeFrame), undefined, {
timeout: 5000,
}).then(res => {
if (res.status === 204) {
throw new Error('No content')
}
return res.data
}),
),
)
}
Expand Down
16 changes: 6 additions & 10 deletions src/hooks/useTokenInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@ export default function useTokenInfo(token: Token | undefined): { data: TokenInf
const coingeckoAPI = useCoingeckoAPI()
const fetcher = (url: string) =>
url
? KyberOauth2Api.get(url)
.then(res => {
if (res.status === 204) {
throw new Error('No content')
}
return res.data
})
.catch(error => {
throw error
})
? KyberOauth2Api.get(url).then(res => {
if (res.status === 204) {
throw new Error('No content')
}
return res.data
})
: Promise.reject({ data: {}, error: '' })

const tokenAddress = isSolana ? token?.address || '' : (token?.address || '').toLowerCase()
Expand Down

0 comments on commit 3540215

Please sign in to comment.