Skip to content

Commit

Permalink
chore: rename l1tol2messagedata (#1920)
Browse files Browse the repository at this point in the history
Co-authored-by: Fionna Chan <[email protected]>
  • Loading branch information
douglance and fionnachan authored Oct 7, 2024
1 parent 90443e4 commit 16572f6
Showing 1 changed file with 30 additions and 19 deletions.
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

0 comments on commit 16572f6

Please sign in to comment.