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

feat: store withdrawals executed status in cache #2136

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 25 additions & 2 deletions packages/arb-token-bridge-ui/src/util/withdrawals/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
Loading