generated from defientco/CRE8ORS-UI
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #13 from SweetmanTech/sameer/useIndexer
added url for indexer
- Loading branch information
Showing
4 changed files
with
84 additions
and
11 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
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,57 @@ | ||
const getIndexedData = async (timestamp: number) => { | ||
const graphQLQuery = { | ||
query: `query($timestamp: BigInt!) { | ||
rewardsDeposits(first: 1000, orderBy: "timestamp", orderDirection: "asc", where: {timestamp_gt: $timestamp}) { | ||
id | ||
creator | ||
createReferral | ||
mintReferral | ||
firstMinter | ||
zora | ||
creatorReward | ||
createReferralReward | ||
firstMinterReward | ||
mintReferralReward | ||
zoraReward | ||
timestamp | ||
chain | ||
} | ||
}`, | ||
variables: { | ||
timestamp, | ||
}, | ||
} | ||
const options = { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(graphQLQuery), | ||
} | ||
const results = [] | ||
const response = await fetch("https://ponderer.quickindexer.xyz", options) | ||
|
||
const data = await response.json() | ||
const rewards: Array<any> = data?.data?.rewardsDeposits | ||
results.push(...rewards) | ||
return results | ||
} | ||
|
||
const getAllIndexedData = async (days: number) => { | ||
const now = new Date() | ||
const millisecondsInADay = 24 * 60 * 60 * 1000 | ||
const initialTimestamp = now.getTime() - millisecondsInADay * days | ||
const results = await getIndexedData(Math.floor(initialTimestamp / 1000)) | ||
let hasMoreResults = results.length > 0 | ||
while (hasMoreResults) { | ||
const lastTimestamp = results[results.length - 1].timestamp | ||
// eslint-disable-next-line no-await-in-loop | ||
const newResults = await getIndexedData(lastTimestamp) | ||
hasMoreResults = newResults.length > 0 | ||
results.push(...newResults) | ||
} | ||
|
||
return results | ||
} | ||
|
||
export default getAllIndexedData |
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,18 @@ | ||
import { error } from "console" | ||
import { Get, Query, createHandler } from "next-api-decorators" | ||
import getAllIndexedData from "../../../../lib/getIndexedData" | ||
|
||
class IndexedData { | ||
@Get() | ||
async index(@Query("days") days: number) { | ||
try { | ||
const results = await getAllIndexedData(days) | ||
return results | ||
} catch (e) { | ||
error(e) | ||
return e | ||
} | ||
} | ||
} | ||
|
||
export default createHandler(IndexedData) |