Newer
Older
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
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: MIT
import { action, observable } from 'mobx';
import store from 'store';
import ethereumIcon from '../assets/img/tokens/ethereum.png';
const LS_PREFIX = '__paritylight::';
const LS_KEY = `${LS_PREFIX}tokens`;
class TokensStore {
@observable tokens = new Map();
constructor() {
const value = store.get(LS_KEY);
if (!value) {
this.addToken('ETH', {
image: ethereumIcon,
name: 'Ethereum',
symbol: 'ETH'
});
// TODO Remove this testing values
this.addToken('ABC', {
image: 'https://s2.coinmarketcap.com/static/img/coins/64x64/1.png',
name: 'Abc Token',
symbol: 'ABC'
});
this.addToken('DEF', {
image: 'https://s2.coinmarketcap.com/static/img/coins/64x64/1.png',
name: 'Def Token',
symbol: 'DEF'
});
} else {
this.tokens.replace(value);
}
}
@action
addToken = (key, token) => {
this.tokens.set(key, token);
this.updateLS();
};
@action
removeToken = key => {
this.tokens.delete(key);
this.updateLS();
};
updateLS = () => store.set(LS_KEY, this.tokens);
}
export default new TokensStore();