Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. import {
  2. GET_DATA,
  3. CONVERSION_ERROR,
  4. CONVERSION_RESULT,
  5. PICK_FUNDING_SOURCE,
  6. SAVE_ACCOUNT_ID,
  7. SAVE_CREDIT_CARD_ID,
  8. SAVE_MCCFILTER_ID,
  9. SAVE_LOCK_ID,
  10. } from "../actions/build"
  11.  
  12. const initialState = {
  13. count: "1",
  14. }
  15. const recursiveLookup = (state, count) => {
  16. let root = state
  17. let step = count
  18.  
  19. if (root.auth_with) {
  20. for (var k in root.auth_with) {
  21. if (root.auth_with[k].step == step) {
  22. return root.auth_with[k]
  23. } else if (root.auth_with.length) {
  24. return recursiveLookup(root.auth_with[k], step)
  25. }
  26. }
  27. } else {
  28. return root
  29. }
  30. }
  31.  
  32. const updateBuild = (state, action) => {
  33. let step = state.count
  34. let newState = recursiveLookup(state, state.count)
  35.  
  36. if (newState.auth_with === undefined) {
  37. newState.auth_with = []
  38. }
  39. newState.auth_with.push({
  40. _type: action.fundingSource,
  41. id: action.id,
  42. step: step,
  43. })
  44.  
  45. state.count = state.count += "1"
  46. return { ...state }
  47. }
  48.  
  49. const reducer = (state = initialState, action) => {
  50. switch (action.type) {
  51. case GET_DATA:
  52. return {
  53. ...state,
  54. ...action.result,
  55. }
  56. case CONVERSION_ERROR:
  57. return { ...state, error: action.error }
  58. case CONVERSION_RESULT:
  59. return { ...state, ...action.result }
  60. case PICK_FUNDING_SOURCE:
  61. return { ...state }
  62. case SAVE_ACCOUNT_ID:
  63. return updateBuild(state, action)
  64. case SAVE_CREDIT_CARD_ID:
  65. return updateBuild(state, action)
  66. case SAVE_MCCFILTER_ID:
  67. return updateBuild(state, action)
  68. case SAVE_LOCK_ID:
  69. return updateBuild(state, action)
  70. default:
  71. return state
  72. }
  73. }
  74.  
  75. export default reducer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement