reducer.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. export const initialState = {
  2. active: 'remote',
  3. network: 'main',
  4. changingNetwork: false,
  5. remote: {
  6. client: 'infura',
  7. blockNumber: 100,
  8. timestamp: 0
  9. },
  10. local: {
  11. client: 'geth',
  12. blockNumber: 0,
  13. timestamp: 0,
  14. syncMode: 'fast',
  15. sync: {
  16. currentBlock: 0,
  17. highestBlock: 0,
  18. knownStates: 0,
  19. pulledStates: 0,
  20. startingBlock: 0
  21. }
  22. }
  23. };
  24. const nodes = (state = initialState, action) => {
  25. switch (action.type) {
  26. case '[MAIN]:LOCAL_NODE:SYNC_UPDATE':
  27. return Object.assign({}, state, {
  28. local: Object.assign({}, state.local, {
  29. sync: Object.assign({}, state.local.sync, {
  30. currentBlock: action.payload.currentBlock,
  31. highestBlock: action.payload.highestBlock,
  32. knownStates: action.payload.knownStates,
  33. pulledStates: action.payload.pulledStates,
  34. startingBlock: action.payload.startingBlock
  35. })
  36. })
  37. });
  38. case '[MAIN]:LOCAL_NODE:UPDATE_NEW_BLOCK':
  39. return Object.assign({}, state, {
  40. local: Object.assign({}, state.local, {
  41. blockNumber: action.payload.blockNumber,
  42. timestamp: action.payload.timestamp
  43. })
  44. });
  45. case '[MAIN]:LOCAL_NODE:RESET':
  46. return Object.assign({}, state, {
  47. local: Object.assign({}, state.local, {
  48. blockNumber: 0,
  49. timestamp: 0,
  50. sync: {
  51. currentBlock: 0,
  52. highestBlock: 0,
  53. knownStates: 0,
  54. pulledStates: 0,
  55. startingBlock: 0
  56. }
  57. })
  58. });
  59. case '[MAIN]:REMOTE_NODE:RESET':
  60. return Object.assign({}, state, {
  61. remote: Object.assign({}, state.remote, {
  62. blockNumber: 100,
  63. timestamp: 0
  64. })
  65. });
  66. case '[MAIN]:REMOTE_NODE:BLOCK_HEADER_RECEIVED':
  67. return Object.assign({}, state, {
  68. remote: Object.assign({}, state.remote, {
  69. blockNumber: action.payload.blockNumber,
  70. timestamp: action.payload.timestamp
  71. })
  72. });
  73. case '[MAIN]:NODES:CHANGE_ACTIVE':
  74. return Object.assign({}, state, {
  75. active: action.payload.active
  76. });
  77. case '[MAIN]:NODES:CHANGE_NETWORK_START':
  78. return Object.assign({}, state, {
  79. changingNetwork: true
  80. });
  81. case '[MAIN]:NODES:CHANGE_NETWORK_SUCCESS':
  82. return Object.assign({}, state, {
  83. changingNetwork: false,
  84. network: action.payload.network,
  85. remote: Object.assign({}, state.remote, {
  86. blockNumber: 100,
  87. timestamp: 0
  88. }),
  89. local: Object.assign({}, state.local, {
  90. blockNumber: 0,
  91. timestamp: 0,
  92. sync: {
  93. currentBlock: 0,
  94. highestBlock: 0,
  95. knownStates: 0,
  96. pulledStates: 0,
  97. startingBlock: 0
  98. }
  99. })
  100. });
  101. case '[MAIN]:NODES:CHANGE_SYNC_MODE':
  102. return Object.assign({}, state, {
  103. local: Object.assign({}, state.local, {
  104. syncMode: action.payload.syncMode
  105. })
  106. });
  107. default:
  108. return state;
  109. }
  110. };
  111. export default nodes;