Skip to content

Commit aca3cdb

Browse files
nonces: reset nonces (#5170)
* resetNonces helper * name * reset nonces
1 parent a3719b7 commit aca3cdb

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/entities/nonce.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ interface NetworkNonceInfo {
55
nonce: number;
66
}
77

8-
type AccountNonceInfo = Record<Network, NetworkNonceInfo>;
8+
type AccountNonceInfo = Partial<Record<Network, NetworkNonceInfo>>;
99

1010
export interface NonceManager {
1111
[key: EthereumAddress]: AccountNonceInfo;

src/redux/nonceManager.ts

+18
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,25 @@ export const updateNonce = (
8888
saveNonceManager(updatedNonceManager);
8989
}
9090
};
91+
export const resetNonces = (accountAddress: EthereumAddress) => async (
92+
dispatch: AppDispatch,
93+
getState: AppGetState
94+
) => {
95+
const { nonceManager: currentNonceData } = getState();
96+
97+
const currentAccountAddress = accountAddress.toLowerCase();
9198

99+
const updatedNonceManager: NonceManager = {
100+
...currentNonceData,
101+
[currentAccountAddress]: {},
102+
};
103+
104+
dispatch({
105+
payload: updatedNonceManager,
106+
type: NONCE_MANAGER_UPDATE_NONCE,
107+
});
108+
saveNonceManager(updatedNonceManager);
109+
};
92110
// -- Reducer ----------------------------------------- //
93111
const INITIAL_STATE: NonceManager = {};
94112

src/screens/SettingsSheet/components/DevSection.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { isAuthenticated } from '@/utils/authentication';
5757
import { DATA_UPDATE_PENDING_TRANSACTIONS_SUCCESS } from '@/redux/data';
5858
import { saveLocalPendingTransactions } from '@/handlers/localstorage/accountLocal';
5959
import { getFCMToken } from '@/notifications/tokens';
60+
import { resetNonces } from '@/redux/nonceManager';
6061

6162
const DevSection = () => {
6263
const { navigate } = useNavigation();
@@ -213,12 +214,14 @@ const DevSection = () => {
213214
const clearPendingTransactions = async () => {
214215
// clear local storage
215216
saveLocalPendingTransactions([], accountAddress, Network.mainnet);
216-
217217
// clear redux
218218
dispatch({
219219
payload: [],
220220
type: DATA_UPDATE_PENDING_TRANSACTIONS_SUCCESS,
221221
});
222+
223+
// reset nonces
224+
resetNonces(accountAddress);
222225
};
223226

224227
const clearLocalStorage = async () => {

0 commit comments

Comments
 (0)