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

chore: rename l1tol2messagedata #1920

Merged
merged 6 commits into from
Oct 7, 2024
Merged
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
49 changes: 30 additions & 19 deletions packages/arb-token-bridge-ui/src/hooks/useTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ type Action =
| { type: 'SET_RESOLVED_TIMESTAMP'; txID: string; timestamp?: string }
| { type: 'ADD_TRANSACTIONS'; transactions: Transaction[] }
| {
type: 'UPDATE_L1TOL2MSG_DATA'
type: 'UPDATE_PARENT_TO_CHILD_MSG_DATA'
txID: string
l1ToL2MsgData: ParentToChildMessageData
parentToChildMsgData: ParentToChildMessageData
}
| { type: 'SET_TRANSACTIONS'; transactions: Transaction[] }

Expand Down Expand Up @@ -177,10 +177,10 @@ function updateBlockNumber(
return newState
}

function updateTxnL1ToL2Msg(
function updateTxnParentToChildMsg(
state: Transaction[],
txID: string,
l1ToL2MsgData: ParentToChildMessageData
parentToChildMsgData: ParentToChildMessageData
) {
const newState = [...state]
const index = newState.findIndex(txn => txn.txID === txID)
Expand All @@ -193,17 +193,18 @@ function updateTxnL1ToL2Msg(

if (!(transaction.type === 'deposit' || transaction.type === 'deposit-l1')) {
throw new Error(
"Attempting to add a l1tol2msg to a tx that isn't a deposit:" + txID
"Attempting to add a parentToChildMsg to a tx that isn't a deposit:" +
txID
)
}

const previousL1ToL2MsgData = transaction.parentToChildMsgData
if (!previousL1ToL2MsgData) {
const previousParentToChildMsgData = transaction.parentToChildMsgData
if (!previousParentToChildMsgData) {
newState[index] = {
...transaction,
parentToChildMsgData: {
status: l1ToL2MsgData.status,
retryableCreationTxID: l1ToL2MsgData.retryableCreationTxID,
status: parentToChildMsgData.status,
retryableCreationTxID: parentToChildMsgData.retryableCreationTxID,
fetchingUpdate: false
}
}
Expand All @@ -212,7 +213,10 @@ function updateTxnL1ToL2Msg(

newState[index] = {
...transaction,
parentToChildMsgData: { ...previousL1ToL2MsgData, ...l1ToL2MsgData }
parentToChildMsgData: {
...previousParentToChildMsgData,
...parentToChildMsgData
}
}
return newState
}
Expand Down Expand Up @@ -283,8 +287,12 @@ function reducer(state: Transaction[], action: Action) {
case 'SET_RESOLVED_TIMESTAMP': {
return updateResolvedTimestamp(state, action.txID, action.timestamp)
}
case 'UPDATE_L1TOL2MSG_DATA': {
return updateTxnL1ToL2Msg(state, action.txID, action.l1ToL2MsgData)
case 'UPDATE_PARENT_TO_CHILD_MSG_DATA': {
return updateTxnParentToChildMsg(
state,
action.txID,
action.parentToChildMsgData
)
}
case 'SET_TRANSACTIONS': {
return action.transactions
Expand Down Expand Up @@ -339,14 +347,14 @@ const useTransactions = (): [Transaction[], TransactionActions] => {
})
}

const updateTxnL1ToL2MsgData = async (
const updateTxnParentToChildMsgData = async (
txID: string,
l1ToL2MsgData: ParentToChildMessageData
parentToChildMsgData: ParentToChildMessageData
) => {
dispatch({
type: 'UPDATE_L1TOL2MSG_DATA',
type: 'UPDATE_PARENT_TO_CHILD_MSG_DATA',
txID: txID,
l1ToL2MsgData
parentToChildMsgData
})
}

Expand Down Expand Up @@ -384,7 +392,7 @@ const useTransactions = (): [Transaction[], TransactionActions] => {
const updateTransaction = (
txReceipt: TransactionReceipt,
tx?: ethers.ContractTransaction,
l1ToL2MsgData?: ParentToChildMessageData
parentToChildMsgData?: ParentToChildMessageData
) => {
if (!txReceipt.transactionHash) {
return console.warn(
Expand All @@ -410,8 +418,11 @@ const useTransactions = (): [Transaction[], TransactionActions] => {
if (tx) {
setResolvedTimestamp(txReceipt.transactionHash, new Date().toISOString())
}
if (l1ToL2MsgData) {
updateTxnL1ToL2MsgData(txReceipt.transactionHash, l1ToL2MsgData)
if (parentToChildMsgData) {
updateTxnParentToChildMsgData(
txReceipt.transactionHash,
parentToChildMsgData
)
}
}

Expand Down