load currency on modal

This commit is contained in:
Blake Kaufman
2026-07-01 09:59:30 -04:00
parent 235675c781
commit 7acd15fee1
9 changed files with 60 additions and 11 deletions
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { FlatList, StyleSheet, TouchableOpacity, View } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { useTranslation } from 'react-i18next';
@@ -21,6 +21,9 @@ import {
HIDDEN_OPACITY,
INSET_WINDOW_WIDTH,
} from '../../../../constants/theme';
import FullLoadingScreen from '../../../../functions/CustomElements/loadingScreen';
import loadNewFiatData from '../../../../functions/saveAndUpdateFiatData';
import { useKeysContext } from '../../../../../context-store/keys';
export default function DisplayCurrencySelect({
currentCurrency,
@@ -33,29 +36,58 @@ export default function DisplayCurrencySelect({
const { masterInfoObject } = useGlobalContextProvider();
const { theme, darkModeType } = useGlobalThemeContext();
const { screenDimensions } = useAppStatus();
const { contactsPrivateKey, publicKey } = useKeysContext();
const { backgroundColor, backgroundOffset, textColor } = GetThemeColors();
const normalizedCurrentCurrency = normalizeDisplayCurrency(currentCurrency);
const deviceCurrency = (
masterInfoObject?.fiatCurrency || 'USD'
).toUpperCase();
const [isLoadingNewRate, setIsLoadingNewRate] = useState(false);
const isMounted = useRef(false);
const hasSelected = useRef(false);
const cardBackground =
theme && darkModeType ? backgroundColor : backgroundOffset;
const coinBackground =
theme && darkModeType ? backgroundOffset : backgroundColor;
useEffect(() => {
isMounted.current = true;
return () => {
isMounted.current = false;
};
}, []);
useEffect(() => {
setContentHeight(screenDimensions.height * 0.6);
}, [setContentHeight, screenDimensions.height]);
const onSelect = useCallback(
currency => {
async currency => {
if (hasSelected.current) return;
hasSelected.current = true;
setIsLoadingNewRate(true);
const normalizedCode = normalizeDisplayCurrency(currency);
await loadNewFiatData(
normalizedCode,
contactsPrivateKey,
publicKey,
masterInfoObject,
);
if (!isMounted.current) return;
handleBackPressFunction(() => {
navigate.goBack();
onSelectCurrency?.(currency);
});
},
[handleBackPressFunction, navigate, onSelectCurrency],
[
handleBackPressFunction,
navigate,
onSelectCurrency,
contactsPrivateKey,
publicKey,
masterInfoObject,
],
);
const pinnedRows = useMemo(() => {
@@ -273,6 +305,15 @@ export default function DisplayCurrencySelect({
</>
);
if (isLoadingNewRate) {
return (
<FullLoadingScreen
textStyles={{ textAlign: 'center' }}
text={t('settings.fiatCurrency.loadingCurrencyRate')}
/>
);
}
return (
<FlatList
style={styles.list}
+2 -1
View File
@@ -1824,7 +1824,8 @@
"yourCurrencies": "Ihre Währungen",
"moreCurrencies": "Weitere Währungen",
"currencyCount": "{{count}}+ unterstützte Währungen",
"saveCurrencyError": "Wir konnten die ausgewählte Standardwährung nicht speichern, bitte versuchen Sie es erneut."
"saveCurrencyError": "Wir konnten die ausgewählte Standardwährung nicht speichern, bitte versuchen Sie es erneut.",
"loadingCurrencyRate": "Aktueller Fiat-Wechselkurs wird geladen"
},
"feeInformation": {
"title": "",
+2 -1
View File
@@ -1824,7 +1824,8 @@
"yourCurrencies": "Your currencies",
"moreCurrencies": "More currencies",
"currencyCount": "{{count}}+ supported",
"saveCurrencyError": "We were unable to save the selected currency, please try again."
"saveCurrencyError": "We were unable to save the selected currency, please try again.",
"loadingCurrencyRate": "Loading the current fiat rate"
},
"feeInformation": {
"title": "",
+2 -1
View File
@@ -1821,7 +1821,8 @@
"yourCurrencies": "Tus monedas",
"moreCurrencies": "Más monedas",
"currencyCount": "{{count}}+ admitidas",
"saveCurrencyError": "No pudimos guardar la moneda seleccionada, por favor intenta de nuevo."
"saveCurrencyError": "No pudimos guardar la moneda seleccionada, por favor intenta de nuevo.",
"loadingCurrencyRate": "Cargando el tipo de cambio actual"
},
"feeInformation": {
"title": "",
+2 -1
View File
@@ -1824,7 +1824,8 @@
"yourCurrencies": "Vos devises",
"moreCurrencies": "Plus de devises",
"currencyCount": "{{count}}+ prises en charge",
"saveCurrencyError": "Nous n'avons pas pu enregistrer la devise sélectionnée, veuillez réessayer."
"saveCurrencyError": "Nous n'avons pas pu enregistrer la devise sélectionnée, veuillez réessayer.",
"loadingCurrencyRate": "Chargement du taux de change actuel"
},
"feeInformation": {
"title": "",
+2 -1
View File
@@ -1824,7 +1824,8 @@
"yourCurrencies": "Le tue valute",
"moreCurrencies": "Altre valute",
"currencyCount": "{{count}}+ valute supportate",
"saveCurrencyError": "Non siamo riusciti a salvare la valuta selezionata, riprova."
"saveCurrencyError": "Non siamo riusciti a salvare la valuta selezionata, riprova.",
"loadingCurrencyRate": "Caricamento del tasso di cambio attuale"
},
"feeInformation": {
"title": "",
+2 -1
View File
@@ -1823,7 +1823,8 @@
"yourCurrencies": "Suas moedas",
"moreCurrencies": "Mais moedas",
"currencyCount": "{{count}}+ disponíveis",
"saveCurrencyError": "Não foi possível salvar a moeda selecionada, tente novamente."
"saveCurrencyError": "Não foi possível salvar a moeda selecionada, tente novamente.",
"loadingCurrencyRate": "Carregando a cotação atual da moeda fiduciária"
},
"feeInformation": {
"title": "",
+2 -1
View File
@@ -1825,7 +1825,8 @@
"yourCurrencies": "Ваши валюты",
"moreCurrencies": "Другие валюты",
"currencyCount": "{{count}}+ поддерживаемых валют",
"saveCurrencyError": "Не удалось сохранить валюту, попробуйте снова."
"saveCurrencyError": "Не удалось сохранить валюту, попробуйте снова.",
"loadingCurrencyRate": "Загрузка текущего обменного курса фиатной валюты"
},
"feeInformation": {
"title": "",
+2 -1
View File
@@ -1824,7 +1824,8 @@
"yourCurrencies": "Dina valutor",
"moreCurrencies": "Fler valutor",
"currencyCount": "{{count}}+ stöds",
"saveCurrencyError": "Vi kunde inte spara den valda valutan, vänligen försök igen."
"saveCurrencyError": "Vi kunde inte spara den valda valutan, vänligen försök igen.",
"loadingCurrencyRate": "Laddar aktuell valutakurs"
},
"feeInformation": {
"title": "",