-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from EveripediaNetwork/fix/broken-hiiq-count
chore: created server action to fix hiiq count issue
- Loading branch information
Showing
7 changed files
with
85 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { bscHolders, maticHolders } from '@/data/StatsData' | ||
import { getHIIQHoldersCount } from '@/services/holder' | ||
|
||
export async function getTokenHolders() { | ||
try { | ||
const hiiqCount = await getHIIQHoldersCount() | ||
|
||
const eosDataResponse = await fetch( | ||
'https://www.api.bloks.io/tokens?type=tokenHoldersCount&chain=eos&contract=everipediaiq&symbol=IQ', | ||
{ cache: 'no-store' }, | ||
) | ||
const eosData = await eosDataResponse.text() | ||
|
||
const ethDataResponse = await fetch( | ||
'/api/token-holder-count?address=0x579cea1889991f68acc35ff5c3dd0621ff29b0c9', | ||
{ cache: 'no-store' }, | ||
) | ||
const ethData = await ethDataResponse.json() | ||
|
||
const holdersData = { | ||
holders: { | ||
eos: eosData, | ||
eth: ethData?.response ?? 0, | ||
matic: maticHolders, | ||
bsc: bscHolders, | ||
hiiq: hiiqCount ?? 0, | ||
}, | ||
} | ||
|
||
return holdersData | ||
} catch (err) { | ||
console.error('Error fetching token holders:', err) | ||
return { | ||
holders: { | ||
eos: 0, | ||
eth: 0, | ||
matic: 0, | ||
bsc: 0, | ||
hiiq: 0, | ||
}, | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { GraphQLClient } from 'graphql-request' | ||
import config from '@/config' | ||
|
||
const client = new GraphQLClient(config.graphqlUrl) | ||
|
||
export async function makeGraphQLRequest<T>( | ||
document: string, | ||
variables?: Record<string, any>, | ||
): Promise<T> { | ||
try { | ||
return await client.request<T>(document, variables) | ||
} catch (error) { | ||
console.error('GraphQL request error:', error) | ||
throw error | ||
} | ||
} | ||
|
||
export function getGraphQLClient(): GraphQLClient { | ||
return client | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { makeGraphQLRequest } from '@/lib/graphql-client' | ||
import { HIIQ_HOLDERS_COUNT } from './holders/queries' | ||
|
||
export async function getHIIQHoldersCount() { | ||
try { | ||
const response = await makeGraphQLRequest<{ | ||
hiIQHoldersCount: { amount: number }[] | ||
}>(HIIQ_HOLDERS_COUNT) | ||
return response.hiIQHoldersCount[0].amount | ||
} catch (error) { | ||
console.error('Error fetching HIIQ holders count:', error) | ||
return 0 | ||
} | ||
} |
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