Update CompanionDelegates.tsx

This commit is contained in:
Marcos Rodriguez Velez 2024-11-11 21:20:53 -04:00
parent a8674aed0e
commit ae15a4a77f

View File

@ -53,6 +53,7 @@ const CompanionDelegates = () => {
const notifications2process = await getStoredNotifications();
await clearStoredNotifications();
await setApplicationIconBadgeNumber(0);
const deliveredNotifications = await getDeliveredNotifications();
setTimeout(async () => {
try {
@ -61,12 +62,8 @@ const CompanionDelegates = () => {
console.error('Failed to remove delivered notifications:', error);
}
}, 5000);
return notifications2process;
} catch (error) {
console.error('Failed to process notifications:', error);
return [];
}
// Process notifications
for (const payload of notifications2process) {
const wasTapped = payload.foreground === false || (payload.foreground === true && payload.userInteraction);
@ -115,9 +112,60 @@ const CompanionDelegates = () => {
}
if (deliveredNotifications.length > 0) {
refreshAllWalletTransactions();
for (const payload of deliveredNotifications) {
const wasTapped = payload.foreground === false || (payload.foreground === true && payload.userInteraction);
console.log('processing push notification:', payload);
let wallet;
switch (+payload.type) {
case 2:
case 3:
wallet = wallets.find(w => w.weOwnAddress(payload.address));
break;
case 1:
case 4:
wallet = wallets.find(w => w.weOwnTransaction(payload.txid || payload.hash));
break;
}
if (wallet) {
const walletID = wallet.getID();
fetchAndSaveWalletTransactions(walletID);
if (wasTapped) {
if (payload.type !== 3 || wallet.chain === Chain.OFFCHAIN) {
navigationRef.dispatch(
CommonActions.navigate({
name: 'WalletTransactions',
params: {
walletID,
walletType: wallet.type,
},
}),
);
} else {
navigationRef.navigate('ReceiveDetailsRoot', {
screen: 'ReceiveDetails',
params: {
walletID,
address: payload.address,
},
});
}
return true;
}
} else {
console.log('could not find wallet while processing push notification, NOP');
}
}
}
if (deliveredNotifications.length > 0) {
refreshAllWalletTransactions();
}
} catch (error) {
console.error('Failed to process push notifications:', error);
}
return false;
}, [fetchAndSaveWalletTransactions, refreshAllWalletTransactions, wallets]);