Created
April 12, 2016 18:24
-
-
Save delianides/729a35e455cad1f650180c10530fe4d3 to your computer and use it in GitHub Desktop.
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
// XXX How do I include GiveState here? | |
import { assign } from "lodash"; | |
const addTransaction = (state: any, action: any): any => { | |
let total = 0; | |
let mergedTransactions = assign(state.transactions, action.transactions); | |
for (let fund in mergedTransactions) { | |
if (typeof mergedTransactions[fund].value != "number") { | |
delete mergedTransactions[fund]; | |
} | |
total = total + mergedTransactions[fund].value; | |
} | |
return assign(state, { transactions: mergedTransactions, total: total }); | |
} | |
const clearTransaction = (state: any, action: any): any => { | |
let total = 0; | |
// console.log(action.transactionId, state.transactions) | |
if (!action.transactionId || !state.transactions[action.transactionId]) { | |
return state; | |
} | |
delete state.transactions[action.transactionId]; | |
for (let fund in state.transactions) { | |
if (typeof state.transactions[fund].value != "number") { | |
delete state.transactions[fund]; | |
} | |
total = total + state.transactions[fund].value; | |
} | |
return assign(state, { transactions: state.transactions, total: total }); | |
} | |
const clearTransactions = (state: any): any => { | |
return assign(state, { total: 0, transactions: {} }); | |
} | |
export default { | |
addTransaction: addTransaction, | |
clearTransaction: clearTransaction, | |
clearTransactions: clearTransactions | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment