-
-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store a list of all processed transactions (#247)
* Store a list of all processed transactions * Test fixes * Further test fixes * Typos are not our friends * Fixing the other instance of the same typo ...
- Loading branch information
Showing
8 changed files
with
58 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,29 @@ | ||
import { SET_TRANSACTION, UPDATE_TRANSACTION } from '../actions/transaction' | ||
|
||
const initialState = null | ||
const initialState = { | ||
latest: null, | ||
all: {}, | ||
lastUpdated: 0, | ||
} | ||
|
||
const transactionReducer = (state = initialState, action) => { | ||
const transactionReducer = (transactions = initialState, action) => { | ||
let newTransactions = Object.assign({}, transactions) | ||
|
||
if (action.type === SET_TRANSACTION) { | ||
if (action.transaction) { | ||
return { | ||
...action.transaction, | ||
} | ||
newTransactions.latest = Object.assign({}, action.transaction) | ||
if (action.transaction.hash) newTransactions.all[action.transaction.hash] = Object.assign({}, action.transaction) | ||
} else { | ||
newTransactions.latest = null // Unset the latest transaction if SET_TRANSACTION was called with no transaction | ||
} | ||
return null | ||
} | ||
|
||
if (action.type === UPDATE_TRANSACTION) { | ||
// Only change the transaction if it is the same as before | ||
if (action.transaction.createdAt === state.createdAt ) { | ||
return { | ||
...action.transaction, | ||
} | ||
if (action.transaction) { | ||
if (action.type === UPDATE_TRANSACTION && action.transaction.createdAt === transactions.latest.createdAt) { | ||
newTransactions.latest = Object.assign({}, action.transaction) | ||
if (action.transaction.hash) newTransactions.all[action.transaction.hash] = Object.assign({}, action.transaction) | ||
} | ||
} | ||
|
||
return state | ||
return newTransactions | ||
} | ||
|
||
export default transactionReducer |