Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Add claim finalized middleware (#2126)
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolin authored Jan 14, 2022
1 parent 8ef567f commit f560da0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/custom/state/claim/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Middleware, isAnyOf } from '@reduxjs/toolkit'
import { AppState } from 'state'
import { finalizeTransaction } from '../enhancedTransactions/actions'

const isFinalizeTransaction = isAnyOf(finalizeTransaction)

// On each Pending, Expired, Fulfilled order action a corresponding sound is dispatched
export const claimMinedMiddleware: Middleware<Record<string, unknown>, AppState> = (store) => (next) => (action) => {
const result = next(action)

if (isFinalizeTransaction(action)) {
const { chainId, hash, receipt, safeTransaction } = action.payload
const transaction = store.getState().transactions[chainId][hash]

console.log('[stat:claim:middleware] Transaction finalized', transaction, receipt, safeTransaction)
if (transaction.claim) {
// TODO: Update state
console.log('[stat:claim:middleware] It is a CLAIM transaction')
}
}

return result
}
2 changes: 2 additions & 0 deletions src/custom/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import enhancedTransactions from 'state/enhancedTransactions/reducer'
import claim from 'state/claim/reducer'

import { popupMiddleware, soundMiddleware } from './orders/middleware'
import { claimMinedMiddleware } from './claim/middleware'
import { DEFAULT_NETWORK_FOR_LISTS } from 'constants/lists'

const UNISWAP_REDUCERS = {
Expand Down Expand Up @@ -65,6 +66,7 @@ const store = configureStore({
.concat(routingApi.middleware)
.concat(save({ states: PERSISTED_KEYS, debounce: 1000 }))
.concat(popupMiddleware)
.concat(claimMinedMiddleware)
.concat(soundMiddleware),
preloadedState: load({ states: PERSISTED_KEYS, disableWarnings: process.env.NODE_ENV === 'test' }),
})
Expand Down

0 comments on commit f560da0

Please sign in to comment.