This commit is contained in:
Marcos Rodriguez Velez 2024-10-31 22:25:47 -04:00
parent 2713155ba5
commit 63739dd86a
9 changed files with 63 additions and 128 deletions

View File

@ -28,7 +28,6 @@ let lastTimeUpdateExchangeRateWasCalled: number = 0;
let skipUpdateExchangeRate: boolean = false;
async function setPreferredCurrency(item: FiatUnitType): Promise<void> {
await AsyncStorage.setItem(PREFERRED_CURRENCY_STORAGE_KEY, JSON.stringify(item));
await DefaultPreference.setName(GROUP_IO_BLUEWALLET);
await DefaultPreference.set(PREFERRED_CURRENCY_STORAGE_KEY, item.endPointKey);
await DefaultPreference.set(PREFERRED_CURRENCY_LOCALE_STORAGE_KEY, item.locale.replace('-', '_'));
@ -84,16 +83,15 @@ async function updateExchangeRate(): Promise<void> {
}
async function getPreferredCurrency(): Promise<FiatUnitType> {
const preferredCurrency = await AsyncStorage.getItem(PREFERRED_CURRENCY_STORAGE_KEY);
await DefaultPreference.setName(GROUP_IO_BLUEWALLET);
const preferredCurrency = await DefaultPreference.get(PREFERRED_CURRENCY_STORAGE_KEY);
if (preferredCurrency) {
let parsedPreferredCurrency;
try {
parsedPreferredCurrency = JSON.parse(preferredCurrency);
if (!FiatUnit[parsedPreferredCurrency.endPointKey]) {
if (!FiatUnit[preferredCurrency]) {
throw new Error('Invalid Fiat Unit');
}
preferredFiatCurrency = FiatUnit[parsedPreferredCurrency.endPointKey];
preferredFiatCurrency = FiatUnit[preferredCurrency];
} catch (error) {
await AsyncStorage.removeItem(PREFERRED_CURRENCY_STORAGE_KEY);
@ -143,19 +141,18 @@ async function _restoreSavedExchangeRatesFromStorage(): Promise<void> {
async function _restoreSavedPreferredFiatCurrencyFromStorage(): Promise<void> {
try {
const storedCurrency = await AsyncStorage.getItem(PREFERRED_CURRENCY_STORAGE_KEY);
await DefaultPreference.setName(GROUP_IO_BLUEWALLET);
const storedCurrency = await DefaultPreference.get(PREFERRED_CURRENCY_STORAGE_KEY);
if (!storedCurrency) throw new Error('No Preferred Fiat selected');
let parsedCurrency;
try {
parsedCurrency = JSON.parse(storedCurrency);
if (!FiatUnit[parsedCurrency.endPointKey]) {
if (!FiatUnit[storedCurrency]) {
throw new Error('Invalid Fiat Unit');
}
preferredFiatCurrency = FiatUnit[parsedCurrency.endPointKey];
preferredFiatCurrency = FiatUnit[storedCurrency];
} catch (error) {
await AsyncStorage.removeItem(PREFERRED_CURRENCY_STORAGE_KEY);
await DefaultPreference.clear(PREFERRED_CURRENCY_STORAGE_KEY);
const deviceCurrencies = RNLocalize.getCurrencies();
if (deviceCurrencies[0] && FiatUnit[deviceCurrencies[0]]) {
preferredFiatCurrency = FiatUnit[deviceCurrencies[0]];

View File

@ -2,7 +2,7 @@ import { useAsyncStorage } from '@react-native-async-storage/async-storage';
import React, { createContext, useCallback, useEffect, useMemo, useState } from 'react';
import DefaultPreference from 'react-native-default-preference';
import BlueClipboard from '../../blue_modules/clipboard';
import { getPreferredCurrency, GROUP_IO_BLUEWALLET, initCurrencyDaemon } from '../../blue_modules/currency';
import { getPreferredCurrency, GROUP_IO_BLUEWALLET, initCurrencyDaemon, PREFERRED_CURRENCY_STORAGE_KEY } from '../../blue_modules/currency';
import { clearUseURv1, isURv1Enabled, setUseURv1 } from '../../blue_modules/ur';
import { BlueApp } from '../../class';
import { saveLanguage, STORAGE_KEY } from '../../loc';
@ -16,9 +16,14 @@ import { TotalWalletsBalanceKey, TotalWalletsBalancePreferredUnit } from '../Tot
import { BLOCK_EXPLORERS, getBlockExplorerUrl, saveBlockExplorer, BlockExplorer, normalizeUrl } from '../../models/blockExplorer';
const getDoNotTrackStorage = async (): Promise<boolean> => {
try {
await DefaultPreference.setName(GROUP_IO_BLUEWALLET);
const doNotTrack = await DefaultPreference.get(BlueApp.DO_NOT_TRACK);
return doNotTrack === '1';
} catch {
console.error('Error getting DoNotTrack');
return false;
}
};
export const setTotalBalanceViewEnabledStorage = async (value: boolean): Promise<void> => {
@ -39,7 +44,6 @@ export const getIsTotalBalanceViewEnabled = async (): Promise<boolean> => {
return isEnabledValue === 'true';
} catch (e) {
console.error('Error getting TotalBalanceViewEnabled:', e);
await setTotalBalanceViewEnabledStorage(true);
return true;
}
};
@ -214,9 +218,9 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = React.m
const setPreferredFiatCurrencyStorage = useCallback(async (currency: TFiatUnit): Promise<void> => {
try {
setPreferredFiatCurrency(currency);
await DefaultPreference.setName(GROUP_IO_BLUEWALLET);
await DefaultPreference.set('preferredFiatCurrency', currency as unknown as string);
await DefaultPreference.set(PREFERRED_CURRENCY_STORAGE_KEY, currency.endPointKey);
setPreferredFiatCurrency(currency);
} catch (e) {
console.error('Error setting preferredFiatCurrency:', e);
}

View File

@ -11,7 +11,7 @@ const HandOffComponent: React.FC<HandOffComponentProps> = props => {
const { isHandOffUseEnabled } = useSettings();
if (process.env.NODE_ENV === 'development') {
console.debug('HandOffComponent: props', props);
console.debug('HandOffComponent: render');
}
if (isHandOffUseEnabled) {
return <Handoff {...props} />;
@ -35,8 +35,8 @@ export const getIsHandOffUseEnabled = async (): Promise<boolean> => {
return isEnabledValue === 'true';
} catch (e) {
console.debug('getIsHandOffUseEnabled error', e);
}
return false;
}
};
export default MemoizedHandOffComponent;

View File

@ -2,7 +2,7 @@ import React from 'react';
import { HandOffComponentProps } from './types';
const HandOffComponent: React.FC<HandOffComponentProps> = props => {
console.debug('HandOffComponent: props', props);
console.debug('HandOffComponent render.');
return null;
};

View File

@ -29,26 +29,6 @@ import WalletsList from '../screen/wallets/WalletsList';
import { NavigationDefaultOptions, NavigationFormModalOptions, StatusBarLightOptions, DetailViewStack } from './index'; // Importing the navigator
import AddWalletStack from './AddWalletStack';
import AztecoRedeemStackRoot from './AztecoRedeemStack';
import {
AboutComponent,
BlockExplorerSettingsComponent,
CurrencyComponent,
DefaultViewComponent,
ElectrumSettingsComponent,
EncryptStorageComponent,
GeneralSettingsComponent,
LanguageComponent,
LicensingComponent,
LightningSettingsComponent,
NetworkSettingsComponent,
NotificationSettingsComponent,
PlausibleDeniabilityComponent,
ReleaseNotesComponent,
SelfTestComponent,
SettingsComponent,
SettingsPrivacyComponent,
ToolsComponent,
} from './LazyLoadSettingsStack';
import PaymentCodesListComponent from './LazyLoadPaymentCodeStack';
import LNDCreateInvoiceRoot from './LNDCreateInvoiceStack';
import ReceiveDetailsStackRoot from './ReceiveDetailsStack';
@ -67,6 +47,24 @@ import { useSettings } from '../hooks/context/useSettings';
import { useStorage } from '../hooks/context/useStorage';
import WalletTransactions from '../screen/wallets/WalletTransactions';
import AddWalletButton from '../components/AddWalletButton';
import Settings from '../screen/settings/Settings';
import Currency from '../screen/settings/Currency';
import GeneralSettings from '../screen/settings/GeneralSettings';
import PlausibleDeniability from '../screen/PlausibleDeniability';
import Licensing from '../screen/settings/Licensing';
import NetworkSettings from '../screen/settings/NetworkSettings';
import SettingsBlockExplorer from '../screen/settings/SettingsBlockExplorer';
import About from '../screen/settings/About';
import DefaultView from '../screen/settings/DefaultView';
import ElectrumSettings from '../screen/settings/ElectrumSettings';
import EncryptStorage from '../screen/settings/EncryptStorage';
import Language from '../screen/settings/Language';
import LightningSettings from '../screen/settings/LightningSettings';
import NotificationSettings from '../screen/settings/NotificationSettings';
import SelfTest from '../screen/settings/SelfTest';
import ReleaseNotes from '../screen/settings/ReleaseNotes';
import ToolsScreen from '../screen/settings/tools';
import SettingsPrivacy from '../screen/settings/SettingsPrivacy';
const DetailViewStackScreensStack = () => {
const theme = useTheme();
@ -268,7 +266,7 @@ const DetailViewStackScreensStack = () => {
/>
<DetailViewStack.Screen
name="Settings"
component={SettingsComponent}
component={Settings}
options={navigationStyle({
headerTransparent: true,
title: loc.settings.header,
@ -280,83 +278,67 @@ const DetailViewStackScreensStack = () => {
animationTypeForReplace: 'push',
})(theme)}
/>
<DetailViewStack.Screen
name="Currency"
component={CurrencyComponent}
options={navigationStyle({ title: loc.settings.currency })(theme)}
/>
<DetailViewStack.Screen name="Currency" component={Currency} options={navigationStyle({ title: loc.settings.currency })(theme)} />
<DetailViewStack.Screen
name="GeneralSettings"
component={GeneralSettingsComponent}
component={GeneralSettings}
options={navigationStyle({ title: loc.settings.general })(theme)}
/>
<DetailViewStack.Screen
name="PlausibleDeniability"
component={PlausibleDeniabilityComponent}
component={PlausibleDeniability}
options={navigationStyle({ title: loc.plausibledeniability.title })(theme)}
/>
<DetailViewStack.Screen
name="Licensing"
component={LicensingComponent}
options={navigationStyle({ title: loc.settings.license })(theme)}
/>
<DetailViewStack.Screen name="Licensing" component={Licensing} options={navigationStyle({ title: loc.settings.license })(theme)} />
<DetailViewStack.Screen
name="NetworkSettings"
component={NetworkSettingsComponent}
component={NetworkSettings}
options={navigationStyle({ title: loc.settings.network })(theme)}
/>
<DetailViewStack.Screen
name="SettingsBlockExplorer"
component={BlockExplorerSettingsComponent}
component={SettingsBlockExplorer}
options={navigationStyle({ title: loc.settings.block_explorer })(theme)}
/>
<DetailViewStack.Screen name="About" component={AboutComponent} options={navigationStyle({ title: loc.settings.about })(theme)} />
<DetailViewStack.Screen name="About" component={About} options={navigationStyle({ title: loc.settings.about })(theme)} />
<DetailViewStack.Screen
name="DefaultView"
component={DefaultViewComponent}
component={DefaultView}
options={navigationStyle({ title: loc.settings.default_title })(theme)}
/>
<DetailViewStack.Screen
name="ElectrumSettings"
component={ElectrumSettingsComponent}
component={ElectrumSettings}
options={navigationStyle({ title: loc.settings.electrum_settings_server })(theme)}
initialParams={{ server: undefined }}
/>
<DetailViewStack.Screen
name="EncryptStorage"
component={EncryptStorageComponent}
component={EncryptStorage}
options={navigationStyle({ title: loc.settings.encrypt_title })(theme)}
/>
<DetailViewStack.Screen
name="Language"
component={LanguageComponent}
options={navigationStyle({ title: loc.settings.language })(theme)}
/>
<DetailViewStack.Screen name="Language" component={Language} options={navigationStyle({ title: loc.settings.language })(theme)} />
<DetailViewStack.Screen
name="LightningSettings"
component={LightningSettingsComponent}
component={LightningSettings}
options={navigationStyle({ title: loc.settings.lightning_settings })(theme)}
/>
<DetailViewStack.Screen
name="NotificationSettings"
component={NotificationSettingsComponent}
component={NotificationSettings}
options={navigationStyle({ title: loc.settings.notifications })(theme)}
/>
<DetailViewStack.Screen
name="SelfTest"
component={SelfTestComponent}
options={navigationStyle({ title: loc.settings.selfTest })(theme)}
/>
<DetailViewStack.Screen name="SelfTest" component={SelfTest} options={navigationStyle({ title: loc.settings.selfTest })(theme)} />
<DetailViewStack.Screen
name="ReleaseNotes"
component={ReleaseNotesComponent}
component={ReleaseNotes}
options={navigationStyle({ title: loc.settings.about_release_notes })(theme)}
/>
<DetailViewStack.Screen name="Tools" component={ToolsComponent} options={navigationStyle({ title: loc.settings.tools })(theme)} />
<DetailViewStack.Screen name="ToolsScreen" component={ToolsScreen} options={navigationStyle({ title: loc.settings.tools })(theme)} />
<DetailViewStack.Screen
name="SettingsPrivacy"
component={SettingsPrivacyComponent}
component={SettingsPrivacy}
options={navigationStyle({ title: loc.settings.privacy })(theme)}
/>
<DetailViewStack.Screen

View File

@ -64,7 +64,7 @@ export type DetailViewStackParamList = {
NotificationSettings: undefined;
SelfTest: undefined;
ReleaseNotes: undefined;
Tools: undefined;
ToolsScreen: undefined;
SettingsPrivacy: undefined;
ViewEditMultisigCosignersRoot: { walletID: string; cosigners: string[] };
WalletXpubRoot: undefined;

View File

@ -1,48 +0,0 @@
import React, { lazy, Suspense } from 'react';
import { LazyLoadingIndicator } from './LazyLoadingIndicator';
const Currency = lazy(() => import('../screen/settings/Currency'));
const Language = lazy(() => import('../screen/settings/Language'));
const SettingsBlockExplorer = lazy(() => import('../screen/settings/SettingsBlockExplorer'));
const Settings = lazy(() => import('../screen/settings/Settings'));
const GeneralSettings = lazy(() => import('../screen/settings/GeneralSettings'));
const Licensing = lazy(() => import('../screen/settings/Licensing'));
const NetworkSettings = lazy(() => import('../screen/settings/NetworkSettings'));
const About = lazy(() => import('../screen/settings/About'));
const DefaultView = lazy(() => import('../screen/settings/DefaultView'));
const ElectrumSettings = lazy(() => import('../screen/settings/ElectrumSettings'));
const EncryptStorage = lazy(() => import('../screen/settings/EncryptStorage'));
const LightningSettings = lazy(() => import('../screen/settings/LightningSettings'));
const NotificationSettings = lazy(() => import('../screen/settings/NotificationSettings'));
const SelfTest = lazy(() => import('../screen/settings/SelfTest'));
const ReleaseNotes = lazy(() => import('../screen/settings/ReleaseNotes'));
const Tools = lazy(() => import('../screen/settings/tools'));
const SettingsPrivacy = lazy(() => import('../screen/settings/SettingsPrivacy'));
const PlausibleDeniability = lazy(() => import('../screen/PlausibleDeniability'));
const withSuspense =
<P extends object>(Component: React.ComponentType<P>) =>
(props: P) => (
<Suspense fallback={<LazyLoadingIndicator />}>
<Component {...props} />
</Suspense>
);
export const CurrencyComponent = withSuspense(Currency);
export const LanguageComponent = withSuspense(Language);
export const BlockExplorerSettingsComponent = withSuspense(SettingsBlockExplorer);
export const SettingsComponent = withSuspense(Settings);
export const GeneralSettingsComponent = withSuspense(GeneralSettings);
export const LicensingComponent = withSuspense(Licensing);
export const NetworkSettingsComponent = withSuspense(NetworkSettings);
export const AboutComponent = withSuspense(About);
export const DefaultViewComponent = withSuspense(DefaultView);
export const ElectrumSettingsComponent = withSuspense(ElectrumSettings);
export const EncryptStorageComponent = withSuspense(EncryptStorage);
export const LightningSettingsComponent = withSuspense(LightningSettings);
export const NotificationSettingsComponent = withSuspense(NotificationSettings);
export const SelfTestComponent = withSuspense(SelfTest);
export const ReleaseNotesComponent = withSuspense(ReleaseNotes);
export const ToolsComponent = withSuspense(Tools);
export const SettingsPrivacyComponent = withSuspense(SettingsPrivacy);
export const PlausibleDeniabilityComponent = withSuspense(PlausibleDeniability);

View File

@ -35,7 +35,7 @@ const Settings = () => {
<ListItem title={loc.settings.language} onPress={() => navigate('Language')} testID="Language" chevron />
<ListItem title={loc.settings.encrypt_title} onPress={() => navigate('EncryptStorage')} testID="SecurityButton" chevron />
<ListItem title={loc.settings.network} onPress={() => navigate('NetworkSettings')} testID="NetworkSettings" chevron />
<ListItem title={loc.settings.tools} onPress={() => navigate('Tools')} testID="Tools" chevron />
<ListItem title={loc.settings.tools} onPress={() => navigate('ToolsScreen')} testID="Tools" chevron />
<ListItem title={loc.settings.about} onPress={() => navigate('About')} testID="AboutButton" chevron />
</ScrollView>
);

View File

@ -5,7 +5,7 @@ import { ScrollView } from 'react-native';
import ListItem from '../../components/ListItem';
import loc from '../../loc';
const NetworkSettings = () => {
const ToolsScreen = () => {
const { navigate } = useNavigation();
const navigateToIsItMyAddress = () => {
@ -29,4 +29,4 @@ const NetworkSettings = () => {
);
};
export default NetworkSettings;
export default ToolsScreen;