Skip to content

Commit

Permalink
nonces: reset nonces (#5170)
Browse files Browse the repository at this point in the history
* resetNonces helper

* name

* reset nonces
  • Loading branch information
skylarbarrera committed Nov 8, 2023
1 parent a3719b7 commit aca3cdb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/entities/nonce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface NetworkNonceInfo {
nonce: number;
}

type AccountNonceInfo = Record<Network, NetworkNonceInfo>;
type AccountNonceInfo = Partial<Record<Network, NetworkNonceInfo>>;

export interface NonceManager {
[key: EthereumAddress]: AccountNonceInfo;
Expand Down
18 changes: 18 additions & 0 deletions src/redux/nonceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,25 @@ export const updateNonce = (
saveNonceManager(updatedNonceManager);
}
};
export const resetNonces = (accountAddress: EthereumAddress) => async (
dispatch: AppDispatch,
getState: AppGetState
) => {
const { nonceManager: currentNonceData } = getState();

const currentAccountAddress = accountAddress.toLowerCase();

const updatedNonceManager: NonceManager = {
...currentNonceData,
[currentAccountAddress]: {},
};

dispatch({
payload: updatedNonceManager,
type: NONCE_MANAGER_UPDATE_NONCE,
});
saveNonceManager(updatedNonceManager);
};
// -- Reducer ----------------------------------------- //
const INITIAL_STATE: NonceManager = {};

Expand Down
5 changes: 4 additions & 1 deletion src/screens/SettingsSheet/components/DevSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { isAuthenticated } from '@/utils/authentication';
import { DATA_UPDATE_PENDING_TRANSACTIONS_SUCCESS } from '@/redux/data';
import { saveLocalPendingTransactions } from '@/handlers/localstorage/accountLocal';
import { getFCMToken } from '@/notifications/tokens';
import { resetNonces } from '@/redux/nonceManager';

const DevSection = () => {
const { navigate } = useNavigation();
Expand Down Expand Up @@ -213,12 +214,14 @@ const DevSection = () => {
const clearPendingTransactions = async () => {
// clear local storage
saveLocalPendingTransactions([], accountAddress, Network.mainnet);

// clear redux
dispatch({
payload: [],
type: DATA_UPDATE_PENDING_TRANSACTIONS_SUCCESS,
});

// reset nonces
resetNonces(accountAddress);
};

const clearLocalStorage = async () => {
Expand Down

0 comments on commit aca3cdb

Please sign in to comment.