From 0643412c05cb83256ee64b65bc3428699451e34d Mon Sep 17 00:00:00 2001
From: JSKitty
Date: Wed, 30 Aug 2023 19:13:04 +0100
Subject: [PATCH] Improve CoinGecko stability, add attribution
---
index.template.html | 2 ++
locale/de/translation.js | 1 +
locale/en/translation.js | 1 +
locale/fr/translation.js | 1 +
locale/ph/translation.js | 1 +
locale/pt-br/translation.js | 1 +
locale/pt-pt/translation.js | 1 +
locale/template/translation.js | 1 +
locale/uwu/translation.js | 1 +
scripts/global.js | 12 +++++++++---
scripts/prices.js | 29 +++++++++++++++++++----------
scripts/settings.js | 29 +++++++++++++++++++----------
12 files changed, 57 insertions(+), 23 deletions(-)
diff --git a/index.template.html b/index.template.html
index 0061247d3..cf5cbea8f 100644
--- a/index.template.html
+++ b/index.template.html
@@ -1207,6 +1207,8 @@ Price data provided by CoinGecko
+
(-)
diff --git a/locale/de/translation.js b/locale/de/translation.js
index 4207519c7..e91678548 100644
--- a/locale/de/translation.js
+++ b/locale/de/translation.js
@@ -169,6 +169,7 @@ export const de_translation = {
// Settings
settingsCurrency: 'Wähle die angezeigte Währung', //Choose a display currency:
+ priceProvidedBy: '', //Price data provided by
settingsDecimals: '', //Balance Decimals:
settingsExplorer: 'Wähle einen Explorer', //Choose an explorer:
settingsLanguage: 'Wähle eine Sprache', //Choose a Language:
diff --git a/locale/en/translation.js b/locale/en/translation.js
index a696278cf..ef291f09a 100644
--- a/locale/en/translation.js
+++ b/locale/en/translation.js
@@ -170,6 +170,7 @@ export const en_translation = {
// Settings
settingsCurrency: 'Choose a display currency:', //
+ priceProvidedBy: 'Price data provided by', //
settingsDecimals: 'Balance Decimals:', //
settingsExplorer: 'Choose an explorer:', //
settingsLanguage: 'Choose a Language:', //
diff --git a/locale/fr/translation.js b/locale/fr/translation.js
index 546df1dcc..42c7aed40 100644
--- a/locale/fr/translation.js
+++ b/locale/fr/translation.js
@@ -168,6 +168,7 @@ export const fr_translation = {
// Settings
settingsCurrency: "Choisissez une devise d'affichage :", //Choose a display currency:
+ priceProvidedBy: '', //Price data provided by
settingsDecimals: 'Solde Décimales :', //Balance Decimals:
settingsExplorer: 'Choisissez un explorateur :', //Choose an explorer:
settingsLanguage: 'Choisissez une langue :', //Choose a Language:
diff --git a/locale/ph/translation.js b/locale/ph/translation.js
index f5abb274c..762354a8d 100644
--- a/locale/ph/translation.js
+++ b/locale/ph/translation.js
@@ -170,6 +170,7 @@ export const ph_translation = {
// Settings
settingsCurrency: 'Pumili ng display currency:', //Choose a display currency:
+ priceProvidedBy: '', //Price data provided by
settingsDecimals: '', //Balance Decimals:
settingsExplorer: 'Pumili ng explorer:', //Choose an explorer:
settingsLanguage: 'Pumili ng Wika:', //Choose a Language:
diff --git a/locale/pt-br/translation.js b/locale/pt-br/translation.js
index 708df094d..32d96e76d 100644
--- a/locale/pt-br/translation.js
+++ b/locale/pt-br/translation.js
@@ -170,6 +170,7 @@ export const pt_br_translation = {
// Settings
settingsCurrency: 'Escolha uma moeda de exibição:', //Choose a display currency:
+ priceProvidedBy: '', //Price data provided by
settingsDecimals: '', //Balance Decimals:
settingsExplorer: 'Escolha um explorador:', //Choose an explorer:
settingsLanguage: 'Escolha um Idioma:', //Choose a Language:
diff --git a/locale/pt-pt/translation.js b/locale/pt-pt/translation.js
index 9c585c706..76ec654e4 100644
--- a/locale/pt-pt/translation.js
+++ b/locale/pt-pt/translation.js
@@ -169,6 +169,7 @@ export const pt_pt_translation = {
// Settings
settingsCurrency: 'Escolha uma moeda de exibição:', //Choose a display currency:
+ priceProvidedBy: '', //Price data provided by
settingsDecimals: '', //Balance Decimals:
settingsExplorer: 'Escolha um explorador:', //Choose an explorer:
settingsLanguage: 'Escolha um Idioma:', //Choose a Language:
diff --git a/locale/template/translation.js b/locale/template/translation.js
index 059cebfb8..02d105807 100644
--- a/locale/template/translation.js
+++ b/locale/template/translation.js
@@ -176,6 +176,7 @@ var translation = {
// Settings
settingsCurrency: '', //Choose a display currency:
+ priceProvidedBy: '', //Price data provided by
settingsDecimals: '', //Balance Decimals:
settingsExplorer: '', //Choose an explorer:
settingsLanguage: '', //Choose a Language:
diff --git a/locale/uwu/translation.js b/locale/uwu/translation.js
index 0d5a014af..2f726475c 100644
--- a/locale/uwu/translation.js
+++ b/locale/uwu/translation.js
@@ -173,6 +173,7 @@ export const uwu_translation = {
// Settings
settingsCurrency: 'Chowose a dispway cuwwency:', //Choose a display currency:
+ priceProvidedBy: 'Pwice data pwovided by', //Price data provided by
settingsDecimals: 'Balance Decimawls:', //Balance Decimals:
settingsExplorer: 'Chowose an expwower:', //Choose an explorer:
settingsLanguage: 'Chowose a Languwuage:', //Choose a Language:
diff --git a/scripts/global.js b/scripts/global.js
index c5292d72f..d3a6f345c 100644
--- a/scripts/global.js
+++ b/scripts/global.js
@@ -653,9 +653,11 @@ export function optimiseCurrencyLocale(nAmount) {
* @param {HTMLElement} domValue
* @param {boolean} fCold
*/
-export function updatePriceDisplay(domValue, fCold = false) {
+export async function updatePriceDisplay(domValue, fCold = false) {
// Update currency values
- cMarket.getPrice(strCurrency).then((nPrice) => {
+ const nPrice = await cMarket.getPrice(strCurrency);
+
+ if (nPrice) {
// Calculate the value
const nCurrencyValue =
((fCold ? getStakingBalance() : getBalance()) / COIN) * nPrice;
@@ -664,7 +666,7 @@ export function updatePriceDisplay(domValue, fCold = false) {
// Update the DOM
domValue.innerText = nValue.toLocaleString('en-gb', cLocale);
- });
+ }
}
export function getBalance(updateGUI = false) {
@@ -1203,6 +1205,10 @@ export function toggleBottomMenu(dom, ani) {
export async function updateAmountInputPair(domCoin, domValue, fCoinEdited) {
// Fetch the price in the user's preferred currency
const nPrice = await cMarket.getPrice(strCurrency);
+
+ // If there is no price loaded, then we just won't do anything
+ if (!nPrice) return;
+
if (fCoinEdited) {
// If the 'Coin' input is edited, then update the 'Value' input with it's converted currency
const nValue = Number(domCoin.value) * nPrice;
diff --git a/scripts/prices.js b/scripts/prices.js
index b17c15868..6a6a4d5c7 100644
--- a/scripts/prices.js
+++ b/scripts/prices.js
@@ -1,4 +1,5 @@
import { getBalance } from './global';
+import { isEmpty } from './misc';
import { cMarket, fillCurrencySelect } from './settings';
/**
@@ -33,7 +34,13 @@ export class MarketSource {
* @returns {Promise