problem: value in USD not displayed

This commit is contained in:
Bob
2024-07-17 11:27:24 +08:00
parent 58420ff2d5
commit 553b55b793
2 changed files with 29 additions and 2 deletions

View File

@@ -56,3 +56,16 @@ export function unixToRelativeTime(timestamp: number): string {
return formattedDate;
}
}
export async function getCuckPrice(): Promise<number | Error> {
try {
var url = 'https://api.coindesk.com/v1/bpi/currentprice.json';
var symbol = 'USD';
const data = await fetch(url);
const json = await data.json();
const cuckPrice = parseFloat(json.bpi[symbol].rate.replace(/,/g, ''));
return cuckPrice;
} catch (e) {
return e as Error;
}
}