forked from polkadot-cloud/polkadot-staking-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
ef0af54
commit 4297fd4
Showing
11 changed files
with
43 additions
and
50 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
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
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,43 +1,36 @@ | ||
// Copyright 2024 @paritytech/polkadot-staking-dashboard authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
// import { NetworkList } from 'config/networks'; | ||
// import { useNetwork } from 'contexts/Network'; | ||
import { NetworkList } from 'config/networks'; | ||
import { useNetwork } from 'contexts/Network'; | ||
|
||
export const useUnitPrice = () => { | ||
// const { network } = useNetwork(); | ||
|
||
const fetchUnitPrice = () => | ||
// const endpoint = `https://api.binance.com/api/v3/ticker/24hr?symbol=`; | ||
|
||
// const urls = [`${endpoint}${NetworkList[network].api.priceTicker}`]; | ||
|
||
// const responses = await Promise.all( | ||
// urls.map((u) => fetch(u, { method: 'GET' })) | ||
// ); | ||
// const texts = await Promise.all(responses.map((res) => res.json())); | ||
// const newPrice = texts[0]; | ||
|
||
// if ( | ||
// newPrice.lastPrice !== undefined && | ||
// newPrice.priceChangePercent !== undefined | ||
// ) { | ||
// const price: string = (Math.ceil(newPrice.lastPrice * 100) / 100).toFixed( | ||
// 2 | ||
// ); | ||
|
||
// return { | ||
// lastPrice: price, | ||
// change: (Math.round(newPrice.priceChangePercent * 100) / 100).toFixed( | ||
// 2 | ||
// ), | ||
// }; | ||
// } | ||
|
||
({ | ||
lastPrice: '0', | ||
change: 0, | ||
}); | ||
const { network } = useNetwork(); | ||
|
||
const fetchUnitPrice = async () => { | ||
const endpoint = `https://api.coingecko.com/api/v3/simple/price`; | ||
|
||
const urls = [ | ||
`${endpoint}?ids=${NetworkList[network].api.id}&vs_currencies=usd&include_24hr_change=true`, | ||
]; | ||
|
||
const responses = await Promise.all( | ||
urls.map((u) => fetch(u, { method: 'GET' })) | ||
); | ||
const texts = await Promise.all(responses.map((res) => res.json())); | ||
const newPrice = texts[0][NetworkList[network].api.id]; | ||
|
||
if (newPrice.usd !== undefined && newPrice.usd_24h_change !== undefined) { | ||
const price: string = (Math.ceil(newPrice.usd * 100) / 100).toFixed(2); | ||
|
||
return { | ||
lastPrice: price, | ||
change: (Math.round(newPrice.usd_24h_change * 100) / 100).toFixed(2), | ||
}; | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
return fetchUnitPrice; | ||
}; |
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
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
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