mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 09:50:15 +01:00
ADD: Rate information
This commit is contained in:
parent
e3cf5cc814
commit
04b3d5a4ca
@ -85,14 +85,13 @@ async function updateExchangeRate() {
|
||||
let rate;
|
||||
try {
|
||||
rate = await getFiatRate(preferredFiatCurrency.endPointKey);
|
||||
exchangeRates[LAST_UPDATED] = +new Date();
|
||||
exchangeRates['BTC_' + preferredFiatCurrency.endPointKey] = rate;
|
||||
await AsyncStorage.setItem(EXCHANGE_RATES_STORAGE_KEY, JSON.stringify(exchangeRates));
|
||||
} catch (Err) {
|
||||
console.log('Error encountered when attempting to update exchange rate...');
|
||||
console.warn(Err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
exchangeRates[LAST_UPDATED] = +new Date();
|
||||
exchangeRates['BTC_' + preferredFiatCurrency.endPointKey] = rate;
|
||||
await AsyncStorage.setItem(EXCHANGE_RATES_STORAGE_KEY, JSON.stringify(exchangeRates));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -337,6 +337,7 @@
|
||||
"groundcontrol_explanation": "GroundControl is a free, open-source push notifications server for Bitcoin wallets. You can install your own GroundControl server and put its URL here to not rely on BlueWallet’s infrastructure. Leave blank to use GroundControl’s default server.",
|
||||
"header": "Settings",
|
||||
"language": "Language",
|
||||
"last_updated": "Last Updated",
|
||||
"language_isRTL": "Restarting BlueWallet is required for the language orientation to take effect.",
|
||||
"lightning_error_lndhub_uri": "Invalid LNDHub URI",
|
||||
"lightning_saved": "Your changes have been saved successfully.",
|
||||
@ -363,6 +364,7 @@
|
||||
"privacy_do_not_track": "Disable Analytics",
|
||||
"privacy_do_not_track_explanation": "Performance and reliability information will not be submitted for analysis.",
|
||||
"push_notifications": "Push Notifications",
|
||||
"rate": "Rate",
|
||||
"retype_password": "Re-type password",
|
||||
"selfTest": "Self-Test",
|
||||
"save": "Save",
|
||||
|
@ -3,18 +3,21 @@ import { FlatList, ActivityIndicator, View, StyleSheet } from 'react-native';
|
||||
import { useTheme } from '@react-navigation/native';
|
||||
|
||||
import navigationStyle from '../../components/navigationStyle';
|
||||
import { SafeBlueArea, BlueListItem, BlueText, BlueCard } from '../../BlueComponents';
|
||||
import { SafeBlueArea, BlueListItem, BlueText, BlueCard, BlueSpacing10 } from '../../BlueComponents';
|
||||
import { FiatUnit, FiatUnitSource } from '../../models/fiatUnit';
|
||||
import loc from '../../loc';
|
||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import dayjs from 'dayjs';
|
||||
dayjs.extend(require('dayjs/plugin/calendar'));
|
||||
const currency = require('../../blue_modules/currency');
|
||||
|
||||
const data = Object.values(FiatUnit);
|
||||
|
||||
const Currency = () => {
|
||||
const { setPreferredFiatCurrency } = useContext(BlueStorageContext);
|
||||
const [isSavingNewPreferredCurrency, setIsSavingNewPreferredCurrency] = useState(false);
|
||||
const [selectedCurrency, setSelectedCurrency] = useState(null);
|
||||
const [currencyRate, setCurrencyRate] = useState({ LastUpdated: null, Rate: null });
|
||||
const { colors } = useTheme();
|
||||
const styles = StyleSheet.create({
|
||||
flex: {
|
||||
@ -29,18 +32,32 @@ const Currency = () => {
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const fetchCurrency = async () => {
|
||||
try {
|
||||
const preferredCurrency = await currency.getPreferredCurrency();
|
||||
if (preferredCurrency === null) {
|
||||
throw Error();
|
||||
}
|
||||
setSelectedCurrency(preferredCurrency);
|
||||
} catch (_error) {
|
||||
setSelectedCurrency(FiatUnit.USD);
|
||||
const fetchCurrency = async () => {
|
||||
let preferredCurrency = FiatUnit.USD;
|
||||
try {
|
||||
preferredCurrency = await currency.getPreferredCurrency();
|
||||
if (preferredCurrency === null) {
|
||||
throw Error();
|
||||
}
|
||||
};
|
||||
setSelectedCurrency(preferredCurrency);
|
||||
} catch (_error) {
|
||||
setSelectedCurrency(preferredCurrency);
|
||||
}
|
||||
AsyncStorage.getItem(currency.EXCHANGE_RATES).then(currencyInformation => {
|
||||
const formatter = new Intl.NumberFormat(preferredCurrency.locale, {
|
||||
style: 'currency',
|
||||
currency: preferredCurrency.endPointKey,
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 8,
|
||||
});
|
||||
setCurrencyRate({
|
||||
LastUpdated: currencyInformation[currency.LAST_UPDATED],
|
||||
Rate: formatter.format(JSON.parse(currencyInformation)[`BTC_${preferredCurrency.endPointKey}`]),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchCurrency();
|
||||
}, []);
|
||||
|
||||
@ -66,6 +83,7 @@ const Currency = () => {
|
||||
await currency.init(true);
|
||||
setIsSavingNewPreferredCurrency(false);
|
||||
setPreferredFiatCurrency();
|
||||
fetchCurrency();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
@ -75,6 +93,14 @@ const Currency = () => {
|
||||
<BlueText>
|
||||
{loc.settings.currency_source} {selectedCurrency.source ?? FiatUnitSource.CoinDesk}
|
||||
</BlueText>
|
||||
<BlueSpacing10 />
|
||||
<BlueText>
|
||||
{loc.settings.rate}: {currencyRate.Rate ?? loc._.never}
|
||||
</BlueText>
|
||||
<BlueSpacing10 />
|
||||
<BlueText>
|
||||
{loc.settings.last_updated}: {dayjs(currencyRate.LastUpdated).calendar() ?? loc._.never}
|
||||
</BlueText>
|
||||
</BlueCard>
|
||||
</SafeBlueArea>
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user