-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring and Improving Price related API Route #290
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
08ebf57
done refactoring fetch-token
Aliiiu 5429df6
done refactoring gas-price api route
Aliiiu 666237b
done refactoring protocol api route
Aliiiu ec64e6c
done refactoring token-info api route
Aliiiu dcfa30e
done refactoring price related api routes to use custom cache headers
Aliiiu 4922fa2
done resolving infinite loading state
Aliiiu 0e729b5
add social-data api route
Aliiiu 34c6a01
biome linting
Aliiiu a332851
working on twitter follower api route
Aliiiu 63c8663
done converting social api call to api-route
Aliiiu 4f7346e
done resolving follower api
Aliiiu 335074c
clear consoles
Aliiiu b5b9a39
remove redundant cache setup
Aliiiu 6d66d6b
convert showdata to a react component
Aliiiu 9514f5e
refactor setCacheHeaders
Aliiiu 6f7383d
consolidate showdata refactor
Aliiiu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,15 @@ import React from 'react' | |
|
||
const GraphPeriodButton = (props: { label: string } & UseRadioProps) => { | ||
const { label, ...radioProps } = props | ||
const { state, getInputProps, getCheckboxProps, htmlProps, getLabelProps } = | ||
const { state, getInputProps, getRadioProps, htmlProps, getLabelProps } = | ||
useRadio(radioProps) | ||
return ( | ||
<chakra.label | ||
{...htmlProps} | ||
cursor={state.isDisabled ? 'not-allowed' : 'pointer'} | ||
> | ||
<input {...getInputProps({})} hidden /> | ||
<Box {...getCheckboxProps()}> | ||
<Box {...getRadioProps()}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missed this, why radio props? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getCheckboxProps is deprecated |
||
<Box | ||
bg={state.isChecked ? 'brandText' : 'transparent'} | ||
border="solid 1px" | ||
|
@@ -38,5 +38,4 @@ const GraphPeriodButton = (props: { label: string } & UseRadioProps) => { | |
</chakra.label> | ||
) | ||
} | ||
|
||
export default GraphPeriodButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,47 @@ | ||
import config from '@/config' | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
import { ResponseData } from '@/types/TreasuryTokenType' | ||
import { setCacheHeaders } from '@/utils/cache' | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<ResponseData>, | ||
) { | ||
const { walletAddress } = req.query | ||
if (!walletAddress) { | ||
res.setHeader('Cache-Control', `s-maxage=${config.CACHE_DURATION_SECONDS}`) | ||
if (req.method !== 'GET') { | ||
return res | ||
.status(400) | ||
.json({ status: false, message: 'Wallet address are needed' }) | ||
.status(405) | ||
.json({ status: false, message: 'Method not allowed' }) | ||
} | ||
try { | ||
const { walletAddress } = req.query | ||
if (!walletAddress) { | ||
return res | ||
.status(400) | ||
.json({ status: false, message: 'Wallet address are needed' }) | ||
} | ||
const url = `https://pro-openapi.debank.com/v1/user/all_token_list?id=${walletAddress}&is_all=true` | ||
const result = await fetch(url, { | ||
headers: { | ||
Accept: 'application/json', | ||
Accesskey: `${config.debankApiKey}`, | ||
}, | ||
}) | ||
|
||
setCacheHeaders(res) | ||
return res.status(200).json({ | ||
response: await result.json(), | ||
status: true, | ||
message: 'token details successfully fetched', | ||
}) | ||
} catch (error) { | ||
console.error('Fetch token error:', error) | ||
|
||
return res.status(500).json({ | ||
status: false, | ||
message: | ||
error instanceof Error | ||
? error.message | ||
: 'Failed to fetch token details', | ||
}) | ||
} | ||
const url = `https://pro-openapi.debank.com/v1/user/all_token_list?id=${walletAddress}&is_all=true` | ||
const result = await fetch(url, { | ||
headers: { | ||
Accept: 'application/json', | ||
Accesskey: `${config.debankApiKey}`, | ||
}, | ||
}) | ||
res.setHeader('Cache-Control', `s-maxage=${config.CACHE_DURATION_SECONDS}`) | ||
return res.status(200).json({ | ||
response: await result.json(), | ||
status: true, | ||
message: 'token details successfully fetched', | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,47 @@ | ||
import config from '@/config' | ||
import { ResponseData } from '@/types/TreasuryTokenType' | ||
import { setCacheHeaders } from '@/utils/cache' | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<ResponseData>, | ||
) { | ||
const { protocolId, id } = req.query | ||
if (!protocolId || !id) { | ||
res.setHeader('Cache-Control', `s-maxage=${config.CACHE_DURATION_SECONDS}`) | ||
return res.status(400).json({ | ||
if (req.method !== 'GET') { | ||
return res | ||
.status(405) | ||
.json({ status: false, message: 'Method not allowed' }) | ||
} | ||
try { | ||
const { protocolId, id } = req.query | ||
if (!protocolId || !id) { | ||
return res.status(400).json({ | ||
status: false, | ||
message: 'protocol id and wallet address are needed', | ||
}) | ||
} | ||
const url = `https://pro-openapi.debank.com/v1/user/protocol?protocol_id=${protocolId}&id=${id}&is_all=true` | ||
const result = await fetch(url, { | ||
headers: { | ||
Accept: 'application/json', | ||
Accesskey: `${config.debankApiKey}`, | ||
}, | ||
}) | ||
setCacheHeaders(res) | ||
return res.status(200).json({ | ||
response: await result.json(), | ||
status: true, | ||
message: 'protocol details successfully fetched', | ||
}) | ||
} catch (error) { | ||
console.error('Fetch protocol details error:', error) | ||
|
||
return res.status(500).json({ | ||
status: false, | ||
message: 'protocol id and wallet address are needed', | ||
message: | ||
error instanceof Error | ||
? error.message | ||
: 'Failed to fetch protocol details', | ||
}) | ||
} | ||
const url = `https://pro-openapi.debank.com/v1/user/protocol?protocol_id=${protocolId}&id=${id}&is_all=true` | ||
const result = await fetch(url, { | ||
headers: { | ||
Accept: 'application/json', | ||
Accesskey: `${config.debankApiKey}`, | ||
}, | ||
}) | ||
res.setHeader('Cache-Control', `s-maxage=${config.CACHE_DURATION_SECONDS}`) | ||
return res.status(200).json({ | ||
response: await result.json(), | ||
status: true, | ||
message: 'protocol details successfully fetched', | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename this to
Also, we could handle the isFailedToFetchData inside it not outside, i.e