Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nonces: reset nonces #5170

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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