Welcome to CryptoDash, please select your favorite coins to begin.
121 | }
122 | }
123 | confirmFavorites=()=>{
124 | let currentFavorite = this.state.favorites[0]
125 | this.setState({
126 | firstVisit:false,
127 | page:'dashboard',
128 | prices:null,
129 | currentFavorite,
130 | historical:null
131 | },()=>{
132 | this.fetchPrice()
133 | this.fetchHistorical()
134 | })
135 | localStorage.setItem('cryptoDash', JSON.stringify({
136 | favorites:this.state.favorites,
137 | currentFavorite
138 | }));
139 | }
140 | settingsContent =()=>{
141 | return
142 | {this.firstVisitMessage()}
143 |
144 | Selected Favorites
145 | {CoinList.call(this, true)}
146 |
147 | {this.state.favorites && this.state.favorites.length >0 &&
148 | Confirm Favorites
149 | }
150 |
151 | {Search.call(this)}
152 | {this.state.notFound && No coin found}
153 | {CoinList.call(this)}
154 |
155 |
156 | }
157 | loadingContent=()=>{
158 | if(!this.state.coinList){
159 | return Loading coin...
160 | }
161 | if(!this.state.firstVisit && !this.state.prices){
162 | return Loading prices...
163 | }
164 | }
165 | addCointToFavorites =(key)=>{
166 | let favorites = [...this.state.favorites]
167 | if(favorites.length < MAX_FAVORITES){
168 | favorites.push(key)
169 | this.setState({favorites})
170 | }
171 | }
172 | removeCoinFromFavorites=(key)=>{
173 | if(!this.state.favorites){
174 | this.setState({firstVisit:true})
175 | } else {
176 | let favorites = [...this.state.favorites]
177 | this.setState({favorites:_.pull(favorites, key)})
178 | }
179 |
180 | }
181 | isInFavorites =(key)=> _.includes(this.state.favorites,key)
182 | handleFilter=_.debounce((inputValue)=>{
183 | let coinSymbols = Object.keys(this.state.coinList)
184 | let coinNames = coinSymbols.map(sym=>this.state.coinList[sym].CoinName)
185 | let allStringsToSearch = coinSymbols.concat(coinNames)
186 | let fuzzyResults = fuzzy.filter(inputValue, allStringsToSearch, {}).map(result =>result.string)
187 | let filteredCoins = _.pickBy(this.state.coinList, (result, symkey)=>{
188 | let coinName = result.CoinName
189 | return _.includes(fuzzyResults, symkey) || _.includes(fuzzyResults, coinName)
190 | })
191 | if(filteredCoins && Object.keys(filteredCoins).length === 0 ){
192 | this.setState({notFound:true})
193 | } else {
194 | this.setState({notFound:false})
195 | }
196 | this.setState({filteredCoins})
197 | }, 100)
198 | filterCoins=(e)=>{
199 | let inputValue=_.get(e, 'target.value')
200 | if(!inputValue){
201 | this.setState({
202 | filteredCoins:null
203 | })
204 | return;
205 | }
206 | this.handleFilter(inputValue)
207 | }
208 | render() {
209 | return (
210 |