mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 01:40:12 +01:00
wip
This commit is contained in:
parent
39073a3a29
commit
5a9e6452de
@ -418,10 +418,6 @@ function Notifications(props) {
|
||||
|
||||
Notifications.addNotification = async function (notification) {
|
||||
let notifications = [];
|
||||
try {
|
||||
const stringified = await AsyncStorage.getItem(NOTIFICATIONS_STORAGE);
|
||||
notifications = JSON.parse(stringified);
|
||||
if (!Array.isArray(notifications)) notifications = [];
|
||||
try {
|
||||
const stringified = await AsyncStorage.getItem(NOTIFICATIONS_STORAGE);
|
||||
notifications = JSON.parse(stringified);
|
||||
@ -498,9 +494,7 @@ function Notifications(props) {
|
||||
console.warn('Failed to load custom URI, falling back to default');
|
||||
baseURI = groundControlUri;
|
||||
// Attempt to reset in background
|
||||
AsyncStorage.setItem(GROUNDCONTROL_BASE_URI, groundControlUri).catch(err =>
|
||||
console.error('Failed to reset URI:', err)
|
||||
);
|
||||
AsyncStorage.setItem(GROUNDCONTROL_BASE_URI, groundControlUri).catch(err => console.error('Failed to reset URI:', err));
|
||||
}
|
||||
|
||||
// every launch should clear badges:
|
||||
|
@ -18,9 +18,17 @@ DefaultPreference.setName(GROUP_IO_BLUEWALLET);
|
||||
export const isBalanceDisplayAllowed = async (): Promise<boolean> => {
|
||||
try {
|
||||
const displayBalance = await DefaultPreference.get(WidgetCommunicationKeys.DisplayBalanceAllowed);
|
||||
return displayBalance === '1';
|
||||
} catch {
|
||||
await DefaultPreference.set(WidgetCommunicationKeys.DisplayBalanceAllowed, '1');
|
||||
if (displayBalance === '1') {
|
||||
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');
|
||||
return true;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to get DisplayBalanceAllowed:', error);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -30,7 +38,7 @@ export const setBalanceDisplayAllowed = async (allowed: boolean): Promise<void>
|
||||
if (allowed) {
|
||||
await DefaultPreference.set(WidgetCommunicationKeys.DisplayBalanceAllowed, '1');
|
||||
} else {
|
||||
await DefaultPreference.clear(WidgetCommunicationKeys.DisplayBalanceAllowed);
|
||||
await DefaultPreference.set(WidgetCommunicationKeys.DisplayBalanceAllowed, '0');
|
||||
}
|
||||
} catch (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 latestTransactionTime =
|
||||
confirmedTransactions.length > 0
|
||||
? Math.max(...confirmedTransactions.map(t => wallet.getLatestTransactionTimeEpoch()))
|
||||
? Math.max(...confirmedTransactions.map(t => t.received || t.time || 0))
|
||||
: WidgetCommunicationKeys.LatestTransactionIsUnconfirmed;
|
||||
|
||||
return { balance, latestTransactionTime };
|
||||
@ -104,14 +112,14 @@ const debouncedSyncWidgetBalanceWithWallets = debounce(
|
||||
wallets: TWallet[],
|
||||
walletsInitialized: boolean,
|
||||
cachedBalance: { current: number },
|
||||
cachedLatestTransactionTime: { current: number | string }
|
||||
cachedLatestTransactionTime: { current: number | string },
|
||||
) => {
|
||||
await syncWidgetBalanceWithWallets(wallets, walletsInitialized, cachedBalance, cachedLatestTransactionTime);
|
||||
},
|
||||
500
|
||||
500,
|
||||
);
|
||||
|
||||
export const useWidgetCommunication = (): void => {
|
||||
const useWidgetCommunication = (): void => {
|
||||
const { wallets, walletsInitialized } = useStorage();
|
||||
const { isWidgetBalanceDisplayAllowed } = useSettings();
|
||||
const cachedBalance = useRef<number>(0);
|
||||
@ -130,4 +138,4 @@ export const useWidgetCommunication = (): void => {
|
||||
}, []);
|
||||
};
|
||||
|
||||
export default useWidgetCommunication;
|
||||
export default useWidgetCommunication;
|
||||
|
@ -1,11 +1,9 @@
|
||||
export const useWidgetCommunication = (): void => {};
|
||||
const useWidgetCommunication = (): void => {};
|
||||
|
||||
export const isBalanceDisplayAllowed = async (): Promise<boolean> => {
|
||||
return true
|
||||
};
|
||||
|
||||
export const setBalanceDisplayAllowed = async (_allowed: boolean): Promise<void> => {
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export const setBalanceDisplayAllowed = async (_allowed: boolean): Promise<void> => {};
|
||||
|
||||
export default useWidgetCommunication;
|
||||
|
Loading…
Reference in New Issue
Block a user