-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/FlatWhiteWithSugar/chain-…
- Loading branch information
Showing
68 changed files
with
2,005 additions
and
2,445 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,43 @@ | ||
import fs from 'fs/promises'; | ||
|
||
const COINGECKO_API_URL = 'https://api.coingecko.com/api/v3/coins/list'; | ||
const COINGECKO_JSON_PATH = './state/coingecko.json'; | ||
|
||
export const coingecko_data = { | ||
api_response: null, | ||
state: { | ||
coingecko_data: [] | ||
} | ||
} | ||
export let coingecko_api_response = {}; | ||
|
||
export async function fetchCoingeckoData() { | ||
console.log("fetching CoinGecko data..."); | ||
try { | ||
const response = await fetch(COINGECKO_API_URL); | ||
coingecko_data.api_response = await response.json(); | ||
} catch (error) { | ||
console.error('Error fetching Coingecko data:', error); | ||
} | ||
} | ||
|
||
export async function loadCoingeckoState() { | ||
try { | ||
const data = await fs.readFile(COINGECKO_JSON_PATH, 'utf8'); | ||
return JSON.parse(data); | ||
} catch (error) { | ||
if (error.code === 'ENOENT') { | ||
return { coingecko_data: [] }; // Return empty structure if file doesn't exist | ||
} | ||
throw error; | ||
} | ||
} | ||
|
||
export async function saveCoingeckoState(data) { | ||
await fs.writeFile(COINGECKO_JSON_PATH, JSON.stringify(data, null, 2)); | ||
} | ||
|
||
function main() { | ||
return; | ||
} | ||
|
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
Oops, something went wrong.