Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(props) {
super(props);
this.showFileUploader = this.showFileUploader.bind(this);
// check localStorage for existing user data
Lockr.prefix = 'userData';
const currencyPrefs = Lockr.get('baseCurrency');
let baseCurrency = props.baseCurrency;
if(currencyPrefs) {
const {currency, symbol} = JSON.parse(currencyPrefs);
props.dispatch({type: 'globalData/baseCurrencyChanged', newBaseCurrency: currency, newBaseCurrencySymbol: symbol});
baseCurrency = currency;
}
const deposits = Lockr.get('deposits');
if(deposits) {
props.dispatch({type: 'userData/depositHistoryUploaded', deposits: JSON.parse(deposits)});
props.dispatch({type: 'userData/withdrawlHistoryUploaded', withdrawls: JSON.parse(Lockr.get('withdrawls'))});
props.dispatch({type: 'userData/tradeHistoryUploaded', trades: JSON.parse(Lockr.get('trades'))});
props.dispatch({type: 'globalData/setDemo', isDemo: JSON.parse(Lockr.get('demo'))});
props.dispatch({type: 'userData/allDataUploaded'});
componentWillReceiveProps(nextProps) {
const {deposits, withdrawls, trades, dispatch} = nextProps;
if(deposits && withdrawls && trades) {
// store the uploaded data in localStorage so it's persistant
Lockr.prefix = 'userData';
Lockr.set('deposits', JSON.stringify(nextProps.deposits));
Lockr.set('withdrawls', JSON.stringify(nextProps.withdrawls));
Lockr.set('trades', JSON.stringify(nextProps.trades));
Lockr.set('demo', JSON.stringify(true));
// redirect to the overview page
dispatch({type: 'userData/allDataUploaded'});
dispatch({type: 'globalData/setDemoFlag', isDemo: true});
dispatch(push('/index'));
// and then hard-refresh the page to force any components to reload from scratch
window.location.reload();
}
}
setTimeout(() => {
this.setState({
confirmLoading: false,
});
// store the uploaded data in localStorage so it's persistant
Lockr.prefix = 'userData';
Lockr.set('deposits', JSON.stringify(this.props.deposits));
Lockr.set('withdrawls', JSON.stringify(this.props.withdrawls));
Lockr.set('trades', JSON.stringify(this.props.trades));
Lockr.set('demo', JSON.stringify(false));
// signal that all data has been successfully uploaded and that it's time to show some juicy visualizations
this.props.dispatch({type: 'userData/allDataUploaded'});
this.hideFileUploader();
// since this is real user data, set the `isDemo` flag to false
this.props.dispatch({type: 'globalData/setDemoFlag', isDemo: false});
// hard-refresh the page since components are wired to not watch for changes to static user data
window.location.reload();
}, 1234);
this.setState({