From 26cabfe3866dfbb36da18f54fb4b8497fe1f609e Mon Sep 17 00:00:00 2001 From: Bartek Date: Thu, 12 Dec 2024 14:51:31 +0100 Subject: [PATCH 1/3] add executed withdrawals to cache --- .../src/util/withdrawals/helpers.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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..1cf448edfa 100644 --- a/packages/arb-token-bridge-ui/src/util/withdrawals/helpers.ts +++ b/packages/arb-token-bridge-ui/src/util/withdrawals/helpers.ts @@ -107,13 +107,15 @@ export async function getOutgoingMessageState( l2Provider: Provider, l2ChainID: number ) { + const executedMessagesCacheKey = 'arbitrum:bridge:executed-messages' + const cacheKey = getExecutedMessagesCacheKey({ event, l2ChainId: l2ChainID }) const executedMessagesCache = JSON.parse( - localStorage.getItem('arbitrum:bridge:executed-messages') || '{}' + localStorage.getItem(executedMessagesCacheKey) || '{}' ) if (executedMessagesCache[cacheKey]) { return OutgoingMessageState.EXECUTED @@ -122,7 +124,19 @@ 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) { + localStorage.setItem( + executedMessagesCacheKey, + JSON.stringify({ + ...executedMessagesCache, + [cacheKey]: true + }) + ) + } + + return status } catch (error) { return OutgoingMessageState.UNCONFIRMED } From e4bd3fc958eb20d902f56b5e934b172ea5d4b655 Mon Sep 17 00:00:00 2001 From: Bartek Date: Thu, 12 Dec 2024 15:44:19 +0100 Subject: [PATCH 2/3] rename --- .../arb-token-bridge-ui/src/util/withdrawals/helpers.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 1cf448edfa..6e1021b258 100644 --- a/packages/arb-token-bridge-ui/src/util/withdrawals/helpers.ts +++ b/packages/arb-token-bridge-ui/src/util/withdrawals/helpers.ts @@ -107,7 +107,7 @@ export async function getOutgoingMessageState( l2Provider: Provider, l2ChainID: number ) { - const executedMessagesCacheKey = 'arbitrum:bridge:executed-messages' + const localStorageKey = 'arbitrum:bridge:executed-messages' const cacheKey = getExecutedMessagesCacheKey({ event, @@ -115,7 +115,7 @@ export async function getOutgoingMessageState( }) const executedMessagesCache = JSON.parse( - localStorage.getItem(executedMessagesCacheKey) || '{}' + localStorage.getItem(localStorageKey) || '{}' ) if (executedMessagesCache[cacheKey]) { return OutgoingMessageState.EXECUTED @@ -128,7 +128,7 @@ export async function getOutgoingMessageState( if (status === OutgoingMessageState.EXECUTED) { localStorage.setItem( - executedMessagesCacheKey, + localStorageKey, JSON.stringify({ ...executedMessagesCache, [cacheKey]: true From 334194708e7445239d16ab36dd5042c27fbb0864 Mon Sep 17 00:00:00 2001 From: Bartek Date: Thu, 12 Dec 2024 17:34:57 +0100 Subject: [PATCH 3/3] fix --- .../src/util/withdrawals/helpers.ts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) 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 6e1021b258..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,6 +101,8 @@ export async function mapETHWithdrawalToL2ToL1EventResult({ } } +let localStoragePromise = Promise.resolve() + export async function getOutgoingMessageState( event: L2ToL1EventResult, l1Provider: Provider, @@ -127,13 +129,20 @@ export async function getOutgoingMessageState( const status = await messageReader.status(l2Provider) if (status === OutgoingMessageState.EXECUTED) { - localStorage.setItem( - localStorageKey, - JSON.stringify({ - ...executedMessagesCache, - [cacheKey]: true - }) - ) + // 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