This repository was archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 816
Expand file tree
/
Copy pathreducers.js
More file actions
85 lines (74 loc) · 2.18 KB
/
Copy pathreducers.js
File metadata and controls
85 lines (74 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const Core = require("./actions");
const initialState = {
flavor: "ethereum",
isMining: true,
mnemonic: "",
hdPath: "",
privateKeys: {},
latestBlock: 0, // Block the current chain is on
lastRequestedBlock: -1, // Last block whose data was requested
gasPrice: "0",
gasLimit: "0",
hardfork: "merge",
snapshots: [],
blocks: [],
transactions: [],
};
export default function (state = initialState, action) {
let accountBalances;
let accountNonces;
switch (action.type) {
case Core.SET_KEY_DATA:
return Object.assign({}, state, {
mnemonic: action.mnemonic,
hdPath: action.hdPath,
privateKeys: action.privateKeys,
});
case Core.SET_LAST_REQUESTED_BLOCK_NUMBER:
return Object.assign({}, state, {
lastRequestedBlock: action.number,
});
case Core.GET_ACCOUNTS:
var accounts = action.accounts;
accountBalances = Object.assign({}, state.accountBalances);
accountNonces = Object.assign({}, state.accountNonces);
// Set default balance to zero if this is a new account
accounts.forEach(account => {
if (!accountBalances[account]) accountBalances[account] = "0";
if (!accountNonces[account]) accountNonces[account] = 0;
});
return Object.assign({}, state, {
accounts,
accountBalances,
accountNonces,
});
case Core.GET_ACCOUNT_BALANCE:
accountBalances = Object.assign({}, state.accountBalances, {
[action.account]: action.balance,
});
return Object.assign({}, state, {
accountBalances,
});
case Core.GET_ACCOUNT_NONCE:
accountNonces = Object.assign({}, state.accountNonces, {
[action.account]: action.nonce,
});
return Object.assign({}, state, {
accountNonces,
});
case Core.SET_GAS_PRICE:
return Object.assign({}, state, {
gasPrice: action.gasPrice,
});
case Core.SET_GAS_LIMIT:
return Object.assign({}, state, {
gasLimit: action.gasLimit,
});
case Core.SET_BLOCK_NUMBER:
return Object.assign({}, state, {
latestBlock: Number(action.number),
});
default:
return state;
}
}