Skip to content

Commit

Permalink
Rm set batch
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed May 27, 2024
1 parent da412ed commit 26ba204
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 33 deletions.
19 changes: 2 additions & 17 deletions src/hooks/useDraftBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useAppDispatch, useAppSelector } from '@/store'
import useChainId from './useChainId'
import useSafeAddress from './useSafeAddress'
import type { DraftBatchItem } from '@/store/batchSlice'
import { selectBatchBySafe, addTx, removeTx, setBatch } from '@/store/batchSlice'
import { selectBatchBySafe, addTx, removeTx } from '@/store/batchSlice'
import { type TransactionDetails } from '@safe-global/safe-gateway-typescript-sdk'
import { BATCH_EVENTS, trackEvent } from '@/services/analytics'
import { txDispatch, TxEvent } from '@/services/tx/txEvents'
Expand Down Expand Up @@ -43,22 +43,7 @@ export const useUpdateBatch = () => {
[dispatch, chainId, safeAddress],
)

const onSet = useCallback(
(items: DraftBatchItem[]) => {
dispatch(
setBatch({
chainId,
safeAddress,
items,
}),
)

trackEvent({ ...BATCH_EVENTS.BATCH_REORDER })
},
[dispatch, chainId, safeAddress],
)

return [onAdd, onDelete, onSet] as const
return [onAdd, onDelete] as const
}

export const useDraftBatch = (): DraftBatchItem[] => {
Expand Down
19 changes: 3 additions & 16 deletions src/store/batchSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ export const batchSlice = createSlice({
name: 'batch',
initialState,
reducers: {
// Set a batch (used for reordering)
setBatch: (
state,
action: PayloadAction<{
chainId: string
safeAddress: string
items: DraftBatchItem[]
}>,
) => {
const { chainId, safeAddress, items } = action.payload
state[chainId] = state[chainId] || {}
// @ts-expect-error
state[chainId][safeAddress] = items
},

// Add a tx to the batch
addTx: (
state,
Expand All @@ -47,9 +32,11 @@ export const batchSlice = createSlice({
const { chainId, safeAddress, txDetails } = action.payload
state[chainId] = state[chainId] || {}
state[chainId][safeAddress] = state[chainId][safeAddress] || []
// @ts-expect-error
state[chainId][safeAddress].push({
id: Math.random().toString(36).slice(2),
timestamp: Date.now(),
// @ts-expect-error
txDetails,
})
},
Expand All @@ -71,7 +58,7 @@ export const batchSlice = createSlice({
},
})

export const { setBatch, addTx, removeTx } = batchSlice.actions
export const { addTx, removeTx } = batchSlice.actions

const selectAllBatches = (state: RootState): BatchTxsState => {
return state[batchSlice.name] || initialState
Expand Down

0 comments on commit 26ba204

Please sign in to comment.