Skip to content

Commit 2717c6c

Browse files
committed
fix(wallet): #1733 avoid duplicate notification for received onchain tx
1 parent ada9b65 commit 2717c6c

File tree

13 files changed

+47
-83
lines changed

13 files changed

+47
-83
lines changed

src/screens/Settings/AddressTypePreference/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const AddressTypeSettings = ({
5151
onPress: async (): Promise<void> => {
5252
navigation.goBack();
5353
await updateSelectedAddressType({ addressType: addressType.type });
54-
await refreshWallet({ lightning: false, onchain: true });
54+
await refreshWallet({ lightning: false });
5555
},
5656
testID: addressType.type,
5757
})),

src/screens/Settings/DevSettings/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ const DevSettings = ({
279279
const fakeTx = getFakeTransaction(id);
280280
fakeTx[id].height = 0;
281281
injectFakeTransaction(fakeTx);
282-
refreshWallet({ selectedWallet, selectedNetwork }).then();
282+
refreshWallet().then();
283283
},
284284
},
285285
{

src/screens/Settings/ElectrumConfig/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ const ElectrumConfig = ({
308308
autoComplete="off"
309309
keyboardType="default"
310310
autoCorrect={false}
311-
onChangeText={setHost}
312311
returnKeyType="done"
313312
testID="HostInput"
313+
onChangeText={setHost}
314314
/>
315315

316316
<Caption13Up style={styles.label} color="secondary">
@@ -326,8 +326,9 @@ const ElectrumConfig = ({
326326
autoComplete="off"
327327
keyboardType="number-pad"
328328
autoCorrect={false}
329-
onChangeText={setPort}
329+
returnKeyType="done"
330330
testID="PortInput"
331+
onChangeText={setPort}
331332
/>
332333

333334
<View

src/screens/Settings/GapLimit/index.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ const GapLimit = (): ReactElement => {
7676
});
7777
if (res.isOk()) {
7878
dispatch(updateWallet({ gapLimitOptions: res.value }));
79-
await refreshWallet({
80-
lightning: false,
81-
onchain: true,
82-
scanAllAddresses: true,
83-
});
79+
await refreshWallet({ lightning: false, scanAllAddresses: true });
8480
showToast({
8581
type: 'success',
8682
title: t('gap.gap_limit_update_title'),

src/screens/Wallets/BoostPrompt.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ import { useAppDispatch, useAppSelector } from '../../hooks/redux';
2020
import { rootNavigation } from '../../navigation/root/RootNavigator';
2121
import { resetSendTransaction } from '../../store/actions/wallet';
2222
import { viewControllerSelector } from '../../store/reselect/ui';
23-
import {
24-
selectedNetworkSelector,
25-
selectedWalletSelector,
26-
transactionSelector,
27-
} from '../../store/reselect/wallet';
23+
import { transactionSelector } from '../../store/reselect/wallet';
2824
import { closeSheet } from '../../store/slices/ui';
2925
import { TOnchainActivityItem } from '../../store/types/activity';
3026
import { EUnit } from '../../store/types/wallet';
@@ -48,8 +44,6 @@ const BoostForm = ({
4844
const { t } = useTranslation('wallet');
4945
const dispatch = useAppDispatch();
5046
const transaction = useAppSelector(transactionSelector);
51-
const selectedNetwork = useAppSelector(selectedNetworkSelector);
52-
const selectedWallet = useAppSelector(selectedWalletSelector);
5347

5448
const [preparing, setPreparing] = useState(true);
5549
const [loading, setLoading] = useState(false);
@@ -69,8 +63,6 @@ const BoostForm = ({
6963
useEffect(() => {
7064
(async (): Promise<void> => {
7165
const res = await setupBoost({
72-
selectedWallet,
73-
selectedNetwork,
7466
txid: activityItem.txId,
7567
});
7668
setPreparing(false);
@@ -84,7 +76,7 @@ const BoostForm = ({
8476
return (): void => {
8577
resetSendTransaction();
8678
};
87-
}, [activityItem.txId, selectedNetwork, selectedWallet, dispatch]);
79+
}, [activityItem.txId, dispatch]);
8880

8981
const onSwitchView = (): void => {
9082
if (showCustom) {

src/store/mmkv-storage.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,36 @@ export const reduxStorage: Storage = {
1919
},
2020
};
2121

22+
// Used to prevent duplicate notifications for the same txId that seems to occur when:
23+
// - when Bitkit is brought from background to foreground
24+
// - connection to electrum server is lost and then re-established
25+
export const receivedTxIds = {
26+
STORAGE_KEY: 'receivedTxIds',
27+
28+
// Get stored txIds
29+
get: (): string[] => {
30+
return JSON.parse(storage.getString(receivedTxIds.STORAGE_KEY) || '[]');
31+
},
32+
33+
// Save txIds to storage
34+
save: (txIds: string[]): void => {
35+
storage.set(receivedTxIds.STORAGE_KEY, JSON.stringify(txIds));
36+
},
37+
38+
// Add a new txId
39+
add: (txId: string): void => {
40+
const txIds = receivedTxIds.get();
41+
txIds.push(txId);
42+
receivedTxIds.save(txIds);
43+
},
44+
45+
// Check if txId exists
46+
has: (txId: string): boolean => {
47+
const txIds = receivedTxIds.get();
48+
return txIds.includes(txId);
49+
},
50+
};
51+
2252
export class WebRelayCache {
2353
location: string;
2454

src/store/utils/blocktank.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,10 @@ export const startChannelPurchase = async ({
244244
/**
245245
* Creates, broadcasts and confirms a given Blocktank channel purchase by orderId.
246246
* @param {string} orderId
247-
* @param {EAvailableNetwork} [selectedNetwork]
248-
* @param {TWalletName} [selectedWallet]
249247
* @returns {Promise<Result<string>>}
250248
*/
251249
export const confirmChannelPurchase = async ({
252250
order,
253-
selectedWallet = getSelectedWallet(),
254-
selectedNetwork = getSelectedNetwork(),
255251
}: {
256252
order: IBtOrder;
257253
selectedNetwork?: EAvailableNetwork;
@@ -293,12 +289,8 @@ export const confirmChannelPurchase = async ({
293289

294290
watchOrder(order.id).then();
295291
dispatch(setLightningSetupStep(0));
296-
refreshWallet({
297-
onchain: true,
298-
lightning: false, // No need to refresh lightning wallet at this time.
299-
selectedWallet,
300-
selectedNetwork,
301-
}).then();
292+
// No need to refresh lightning wallet at this time.
293+
refreshWallet({ lightning: false }).then();
302294

303295
if (!__E2E__) {
304296
await scheduleNotifications();

src/store/utils/ui.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,9 @@ export const showNewOnchainTxPrompt = ({
4848
value,
4949
},
5050
});
51-
5251
dispatch(closeSheet('receiveNavigation'));
5352
};
5453

55-
export const showNewTxPrompt = (txId: string): void => {
56-
const activityItem = getActivityStore().items.find(({ id }) => id === txId);
57-
58-
if (activityItem) {
59-
vibrate({ type: 'default' });
60-
showBottomSheet('newTxPrompt', { activityItem });
61-
dispatch(closeSheet('receiveNavigation'));
62-
}
63-
};
64-
6554
export const checkForAppUpdate = async (): Promise<void> => {
6655
const currentBuild = Number(getBuildNumber());
6756
const response = await fetch(releaseUrl);

src/utils/startup/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ export const startWalletServices = async ({
165165
onchain: restore,
166166
lightning,
167167
scanAllAddresses: restore,
168-
showNotification: !restore,
169168
});
170169
await runChecks({ selectedWallet, selectedNetwork });
171170
}

src/utils/wallet/checks.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,7 @@ export const runStorageCheck = async ({
145145
);
146146

147147
await clearUtxos();
148-
149-
await refreshWallet({
150-
onchain: true,
151-
lightning: true,
152-
scanAllAddresses: true,
153-
showNotification: false,
154-
});
148+
await refreshWallet({ scanAllAddresses: true });
155149

156150
return ok('Replaced Impacted Addresses');
157151
};

0 commit comments

Comments
 (0)