-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
21 additions
and
16 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 |
---|---|---|
@@ -1,22 +1,27 @@ | ||
"use server"; | ||
|
||
import { COINMARKETCAP_API_KEY } from "lib/server-env"; | ||
import { COINGECKO_API_KEY } from "lib/server-env"; | ||
import { unstable_cache } from "next/cache"; | ||
|
||
const COINMARKETCAP_APT_ID = "21794"; | ||
const COINMARKETCAP_ROOT_URL = "https://pro-api.coinmarketcap.com"; | ||
const COINMARKETCAP_ENDPOINT = "v2/cryptocurrency/quotes/latest"; | ||
const COINGECKO_APT_ID = "aptos"; | ||
const COINGECKO_ROOT_URL = "https://pro-api.coingecko.com/api"; | ||
const COINGECKO_ENDPOINT = "v3/simple/price"; | ||
const COINGECKO_PARAMS = "vs_currencies=usd&precision=4"; | ||
|
||
export const getAptPrice = unstable_cache( | ||
async () => | ||
fetch(`${COINMARKETCAP_ROOT_URL}/${COINMARKETCAP_ENDPOINT}?id=${COINMARKETCAP_APT_ID}`, { | ||
headers: { | ||
Accept: "application/json", | ||
"X-CMC_PRO_API_KEY": COINMARKETCAP_API_KEY, | ||
}, | ||
}) | ||
fetch( | ||
`${COINGECKO_ROOT_URL}/${COINGECKO_ENDPOINT}` + | ||
`?ids=${COINGECKO_APT_ID}&${COINGECKO_PARAMS}`, | ||
{ | ||
headers: { | ||
Accept: "application/json", | ||
"x-cg-pro-api-key": COINGECKO_API_KEY, | ||
}, | ||
} | ||
) | ||
.then((r) => r.json()) | ||
.then((r) => r.data[COINMARKETCAP_APT_ID].quote.USD.price as number), | ||
.then((r) => r.aptos.usd as number), | ||
["apt-price"], | ||
{ revalidate: 60 * 10 } // Ten minutes | ||
); |
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