Skip to content

Commit

Permalink
done converting social api call to api-route
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliiiu committed Jan 13, 2025
1 parent a332851 commit 63c8663
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 73 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@emotion/react": "^11",
"@emotion/styled": "^11",
"@ensdomains/ens-avatar": "^0.1.6",
"@everipedia/iq-utils": "^2.4.0",
"@everipedia/wagmi-magic-connector": "^1.0.0",
"@metamask/detect-provider": "^1.2.0",
"@radix-ui/react-dropdown-menu": "^2.1.2",
Expand Down
25 changes: 16 additions & 9 deletions src/pages/api/social-data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { setCacheHeaders } from '@/utils/cache'
import { NextApiRequest, NextApiResponse } from 'next/types'
import { sendTwitterApiRequest } from '@everipedia/iq-utils'

export default async function handler(
req: NextApiRequest,
Expand All @@ -13,18 +12,26 @@ export default async function handler(
}

try {
// const redditResponse = await fetch(
// 'https://www.reddit.com/r/everipedia/about.json',
// )
const twitterResponse = await sendTwitterApiRequest(
'https://api.twitter.com/2/users/IQWIKI/followers',
'GET',
const url =
'https://twitter-api45.p.rapidapi.com/followers.php?screenname=IQWIKI'
const options = {
method: 'GET',
headers: {
'x-rapidapi-key': '141412b455mshd09467584258910p14bf05jsn949a29def245',
'x-rapidapi-host': 'twitter-api45.p.rapidapi.com',
},
}

const redditResponse = await fetch(
'https://www.reddit.com/r/everipedia/about.json',
)
console.log({ twitterResponse })
const twitterResponse = await fetch(url, options)

const { followers_count: twitterFollowers } = await twitterResponse.json()
// const redditData = await redditResponse.json()
const redditData = await redditResponse.json()
const data = {
twitterFollowers,
redditFollowers: redditData.data.subscribers,
}

setCacheHeaders(res)
Expand Down
24 changes: 5 additions & 19 deletions src/utils/stats-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import hiIQABI from '@/abis/hiIQABI.abi'
import IQABI from '@/abis/IQABI.abi'
import { useGetHIIQHoldersCountQuery } from '@/services/holders'

const CACHE_DURATION_SECONDS = 12 * 60 * 60 // 12 hours

const getEosSupplyUsingGreymassAPI = async () => {
try {
const response = await axios.post(
Expand Down Expand Up @@ -330,26 +328,14 @@ const getEpData = async () => {
}

const getSocialData = async () => {
const options = {
method: 'GET',
headers: {
'cache-control': `public, s-maxage=${CACHE_DURATION_SECONDS}, stale-while-revalidate=${
2 * CACHE_DURATION_SECONDS
}`,
},
}
try {
const redditResponse = await fetch(
'https://www.reddit.com/r/everipedia/about.json',
)
const twitterResponse = await fetch('social-data', options)
console.log({ twitterResponse })
const { followers_count } = await twitterResponse.json()
const redditData = await redditResponse.json()
const twitterResponse = await fetch('/api/social-data')
const { twitterFollowers, redditFollowers } = await twitterResponse.json()
console.log({ twitterFollowers, redditFollowers })
return {
social: {
twitter: followers_count,
reddit: redditData.data.subscribers,
twitter: twitterFollowers ?? 132000,
reddit: redditFollowers,
},
}
} catch (err) {
Expand Down
44 changes: 0 additions & 44 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2129,16 +2129,6 @@
"@ethersproject/properties" "^5.7.0"
"@ethersproject/strings" "^5.7.0"

"@everipedia/iq-utils@^2.4.0":
version "2.4.0"
resolved "https://registry.yarnpkg.com/@everipedia/iq-utils/-/iq-utils-2.4.0.tgz#caaa5f0c6872e27f5972bf5cb40c62dbdebb3520"
integrity sha512-8AKNzsAxinxoBTfSXa5+P2uevrFiFKN40x4SApi51oU48PxtlOPZ+zf9g6OB++kFsWIj254wO9D0whGPtZYhZQ==
dependencies:
axios "^1.7.7"
oauth-1.0a "^2.2.6"
quick-lru "^7.0.0"
zod "^3.23.8"

"@everipedia/wagmi-magic-connector@^1.0.0":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@everipedia/wagmi-magic-connector/-/wagmi-magic-connector-1.0.2.tgz#75c06d0fb1dc07f45ee941447521188598691e6b"
Expand Down Expand Up @@ -3986,15 +3976,6 @@ axios@^0.27.2:
follow-redirects "^1.14.9"
form-data "^4.0.0"

axios@^1.7.7:
version "1.7.9"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.9.tgz#d7d071380c132a24accda1b2cfc1535b79ec650a"
integrity sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

babel-plugin-macros@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/babel-plugin-macros/-/babel-plugin-macros-3.1.0.tgz#9ef6dc74deb934b4db344dc973ee851d148c50c1"
Expand Down Expand Up @@ -5584,11 +5565,6 @@ follow-redirects@^1.14.7, follow-redirects@^1.14.8, follow-redirects@^1.14.9:
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==

follow-redirects@^1.15.6:
version "1.15.9"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1"
integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==

for-each@^0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e"
Expand Down Expand Up @@ -7056,11 +7032,6 @@ [email protected]:
bn.js "4.11.6"
strip-hex-prefix "1.0.0"

oauth-1.0a@^2.2.6:
version "2.2.6"
resolved "https://registry.yarnpkg.com/oauth-1.0a/-/oauth-1.0a-2.2.6.tgz#eadbccdb3bceea412d24586e6f39b2b412f0e491"
integrity sha512-6bkxv3N4Gu5lty4viIcIAnq5GbxECviMBeKR3WX/q87SPQ8E8aursPZUtsXDnxCs787af09WPRBLqYrf/lwoYQ==

object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
Expand Down Expand Up @@ -7512,11 +7483,6 @@ [email protected]:
resolved "https://registry.yarnpkg.com/proxy-compare/-/proxy-compare-2.5.1.tgz#17818e33d1653fbac8c2ec31406bce8a2966f600"
integrity sha512-oyfc0Tx87Cpwva5ZXezSp5V9vht1c7dZBhvuV/y3ctkgMVUmiAGDVeeB0dKhGSyT0v1ZTEQYpe/RXlBVBNuCLA==

proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
Expand Down Expand Up @@ -7588,11 +7554,6 @@ quick-lru@^6.1.1:
resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-6.1.1.tgz#f8e5bf9010376c126c80c1a62827a526c0e60adf"
integrity sha512-S27GBT+F0NTRiehtbrgaSE1idUAJ5bX8dPAQTdylEyNlrdcH5X4Lz7Edz3DYzecbsCluD5zO8ZNEe04z3D3u6Q==

quick-lru@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-7.0.0.tgz#447f6925b33ae4d2d637e211967d74bae4b99c3f"
integrity sha512-MX8gB7cVYTrYcFfAnfLlhRd0+Toyl8yX8uBx1MrX7K0jegiz9TumwOK27ldXrgDlHRdVi+MqU9Ssw6dr4BNreg==

randombytes@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a"
Expand Down Expand Up @@ -9420,11 +9381,6 @@ [email protected]:
resolved "https://registry.yarnpkg.com/zod/-/zod-3.21.4.tgz#10882231d992519f0a10b5dd58a38c9dabbb64db"
integrity sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==

zod@^3.23.8:
version "3.24.1"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.24.1.tgz#27445c912738c8ad1e9de1bea0359fa44d9d35ee"
integrity sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A==

zustand@^4.3.1:
version "4.3.8"
resolved "https://registry.yarnpkg.com/zustand/-/zustand-4.3.8.tgz#37113df8e9e1421b0be1b2dca02b49b76210e7c4"
Expand Down

0 comments on commit 63c8663

Please sign in to comment.