diff --git a/packages/arb-token-bridge-ui/src/util/withdrawals/helpers.ts b/packages/arb-token-bridge-ui/src/util/withdrawals/helpers.ts index 89ab0369be..a3c91b77ae 100644 --- a/packages/arb-token-bridge-ui/src/util/withdrawals/helpers.ts +++ b/packages/arb-token-bridge-ui/src/util/withdrawals/helpers.ts @@ -101,19 +101,23 @@ export async function mapETHWithdrawalToL2ToL1EventResult({ } } +let localStoragePromise = Promise.resolve() + export async function getOutgoingMessageState( event: L2ToL1EventResult, l1Provider: Provider, l2Provider: Provider, l2ChainID: number ) { + const localStorageKey = 'arbitrum:bridge:executed-messages' + const cacheKey = getExecutedMessagesCacheKey({ event, l2ChainId: l2ChainID }) const executedMessagesCache = JSON.parse( - localStorage.getItem('arbitrum:bridge:executed-messages') || '{}' + localStorage.getItem(localStorageKey) || '{}' ) if (executedMessagesCache[cacheKey]) { return OutgoingMessageState.EXECUTED @@ -122,7 +126,26 @@ export async function getOutgoingMessageState( const messageReader = new ChildToParentMessageReader(l1Provider, event) try { - return await messageReader.status(l2Provider) + const status = await messageReader.status(l2Provider) + + if (status === OutgoingMessageState.EXECUTED) { + // Ensures all parallel methods save to local storage sequentially + localStoragePromise = localStoragePromise.then(() => { + const latestExecutedMessagesCache = JSON.parse( + localStorage.getItem(localStorageKey) || '{}' + ) + + localStorage.setItem( + localStorageKey, + JSON.stringify({ + ...latestExecutedMessagesCache, + [cacheKey]: true + }) + ) + }) + } + + return status } catch (error) { return OutgoingMessageState.UNCONFIRMED }