This commit is contained in:
Marcos Rodriguez Velez 2024-11-08 21:59:39 -04:00
parent 39073a3a29
commit 5a9e6452de
3 changed files with 22 additions and 22 deletions

View File

@ -418,10 +418,6 @@ function Notifications(props) {
Notifications.addNotification = async function (notification) { Notifications.addNotification = async function (notification) {
let notifications = []; let notifications = [];
try {
const stringified = await AsyncStorage.getItem(NOTIFICATIONS_STORAGE);
notifications = JSON.parse(stringified);
if (!Array.isArray(notifications)) notifications = [];
try { try {
const stringified = await AsyncStorage.getItem(NOTIFICATIONS_STORAGE); const stringified = await AsyncStorage.getItem(NOTIFICATIONS_STORAGE);
notifications = JSON.parse(stringified); notifications = JSON.parse(stringified);
@ -498,9 +494,7 @@ function Notifications(props) {
console.warn('Failed to load custom URI, falling back to default'); console.warn('Failed to load custom URI, falling back to default');
baseURI = groundControlUri; baseURI = groundControlUri;
// Attempt to reset in background // Attempt to reset in background
AsyncStorage.setItem(GROUNDCONTROL_BASE_URI, groundControlUri).catch(err => AsyncStorage.setItem(GROUNDCONTROL_BASE_URI, groundControlUri).catch(err => console.error('Failed to reset URI:', err));
console.error('Failed to reset URI:', err)
);
} }
// every launch should clear badges: // every launch should clear badges:

View File

@ -18,11 +18,19 @@ DefaultPreference.setName(GROUP_IO_BLUEWALLET);
export const isBalanceDisplayAllowed = async (): Promise<boolean> => { export const isBalanceDisplayAllowed = async (): Promise<boolean> => {
try { try {
const displayBalance = await DefaultPreference.get(WidgetCommunicationKeys.DisplayBalanceAllowed); const displayBalance = await DefaultPreference.get(WidgetCommunicationKeys.DisplayBalanceAllowed);
return displayBalance === '1'; if (displayBalance === '1') {
} catch { return true;
} else if (displayBalance === '0') {
return false;
} else {
// Preference not set, initialize it to '1' (allowed) and return true
await DefaultPreference.set(WidgetCommunicationKeys.DisplayBalanceAllowed, '1'); await DefaultPreference.set(WidgetCommunicationKeys.DisplayBalanceAllowed, '1');
return true; return true;
} }
} catch (error) {
console.error('Failed to get DisplayBalanceAllowed:', error);
return true;
}
}; };
export const setBalanceDisplayAllowed = async (allowed: boolean): Promise<void> => { export const setBalanceDisplayAllowed = async (allowed: boolean): Promise<void> => {
@ -30,7 +38,7 @@ export const setBalanceDisplayAllowed = async (allowed: boolean): Promise<void>
if (allowed) { if (allowed) {
await DefaultPreference.set(WidgetCommunicationKeys.DisplayBalanceAllowed, '1'); await DefaultPreference.set(WidgetCommunicationKeys.DisplayBalanceAllowed, '1');
} else { } else {
await DefaultPreference.clear(WidgetCommunicationKeys.DisplayBalanceAllowed); await DefaultPreference.set(WidgetCommunicationKeys.DisplayBalanceAllowed, '0');
} }
} catch (error) { } catch (error) {
console.error('Failed to set DisplayBalanceAllowed:', error); console.error('Failed to set DisplayBalanceAllowed:', error);
@ -57,7 +65,7 @@ export const calculateBalanceAndTransactionTime = async (
const confirmedTransactions = transactions.filter(t => t.confirmations > 0); const confirmedTransactions = transactions.filter(t => t.confirmations > 0);
const latestTransactionTime = const latestTransactionTime =
confirmedTransactions.length > 0 confirmedTransactions.length > 0
? Math.max(...confirmedTransactions.map(t => wallet.getLatestTransactionTimeEpoch())) ? Math.max(...confirmedTransactions.map(t => t.received || t.time || 0))
: WidgetCommunicationKeys.LatestTransactionIsUnconfirmed; : WidgetCommunicationKeys.LatestTransactionIsUnconfirmed;
return { balance, latestTransactionTime }; return { balance, latestTransactionTime };
@ -104,14 +112,14 @@ const debouncedSyncWidgetBalanceWithWallets = debounce(
wallets: TWallet[], wallets: TWallet[],
walletsInitialized: boolean, walletsInitialized: boolean,
cachedBalance: { current: number }, cachedBalance: { current: number },
cachedLatestTransactionTime: { current: number | string } cachedLatestTransactionTime: { current: number | string },
) => { ) => {
await syncWidgetBalanceWithWallets(wallets, walletsInitialized, cachedBalance, cachedLatestTransactionTime); await syncWidgetBalanceWithWallets(wallets, walletsInitialized, cachedBalance, cachedLatestTransactionTime);
}, },
500 500,
); );
export const useWidgetCommunication = (): void => { const useWidgetCommunication = (): void => {
const { wallets, walletsInitialized } = useStorage(); const { wallets, walletsInitialized } = useStorage();
const { isWidgetBalanceDisplayAllowed } = useSettings(); const { isWidgetBalanceDisplayAllowed } = useSettings();
const cachedBalance = useRef<number>(0); const cachedBalance = useRef<number>(0);

View File

@ -1,11 +1,9 @@
export const useWidgetCommunication = (): void => {}; const useWidgetCommunication = (): void => {};
export const isBalanceDisplayAllowed = async (): Promise<boolean> => { export const isBalanceDisplayAllowed = async (): Promise<boolean> => {
return true return true;
};
export const setBalanceDisplayAllowed = async (_allowed: boolean): Promise<void> => {
}; };
export const setBalanceDisplayAllowed = async (_allowed: boolean): Promise<void> => {};
export default useWidgetCommunication;