-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstateUtil.js
67 lines (57 loc) · 1.1 KB
/
stateUtil.js
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
/*
* simple util functions related to state
*/
// simple namespace
var ns = {};
/**
* get sequence part of state
* @param {*} state
*/
ns.getSeq = function(state) {
return state.seq;
}
/**
* get sequence for a specific user
* @param {*} state
* @param {string} user - address
*/
ns.getSeqForUser = function(state, user) {
return ns.getSeq(state)[user];
}
/**
* set sequence for a specific user
* @param {*} state
* @param {*} user
* @param {*} sequence
*/
ns.setSeqForUser = function(state, user, sequence) {
ns.getSeq(state)[user] = sequence;
}
ns.getBalances = function(state) {
return state.balances;
}
/**
*
* @param {*} state
* @param {string} user - address
*/
ns.getBalancesForUser = function(state, user) {
return ns.getBalances(state)[user];
}
ns.getMarket = function(state) {
return state.market;
}
/**
*
* @param {*} state
* @param {string} marketId
*/
ns.getMarketForId = function(state, marketId) {
return ns.getMarket(state)[marketId];
}
// Export all in ns namespace
for(prop in ns) {
if(ns.hasOwnProperty(prop)) {
module.exports[prop] = ns[prop];
}
}