-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathstore.js
41 lines (36 loc) · 1 KB
/
store.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
import {BigNumber} from '@uniswap/sdk';
import {applyMiddleware, createStore} from 'redux';
import thunk from 'redux-thunk';
import {saveStateMiddleware} from './lib/middleware/app';
import {getState} from './lib/stores/app';
import rootReducer from './reducers';
let STORE = null;
const BIG_NUMBER_FIELDS = ['gasPrice', 'gasLimit'];
function convertBigNumbers(value, key) {
if (typeof value === 'object') {
for (const key in value) {
value[key] = convertBigNumbers(value[key], key);
}
return value;
} else if (typeof value === 'array') {
return value.map(v => convertBigNumbers(v, key));
} else {
if (~BIG_NUMBER_FIELDS.indexOf(key)) {
return new BigNumber(value);
} else {
return value;
}
}
}
export async function initialize(next) {
const initialState = await getState(convertBigNumbers);
STORE = createStore(
rootReducer,
initialState,
applyMiddleware(thunk, saveStateMiddleware),
);
next(STORE);
}
export function get() {
return STORE;
}