Verified Commit 72fa7fd0 authored by reprograma's avatar reprograma
Browse files

update: apply & enforce eslint, move hardcoded values to .env

parent 8df4bfa5
......@@ -15,6 +15,7 @@
"axios": "^0.19.0",
"chart.js": "^2.7.3",
"chartist": "^0.11.0",
"classnames": "^2.2.6",
"eslint": "^6.6.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^6.6.0",
......@@ -63,4 +64,4 @@
"git add"
]
}
}
\ No newline at end of file
}
......@@ -27,4 +27,11 @@ REACT_APP_LAST_TRANSACTIONS_PATH="<< last transactions api path here >>"
REACT_APP_EARNINGS_PATH="<< earnings api path here >>"
# src/components/widgets/CurrenciesValue/actions.js
REACT_APP_CURRENCIES_VALUE_PATH="<< currencies value api path here >>"
\ No newline at end of file
REACT_APP_CURRENCIES_VALUE_PATH="<< currencies value api path here >>"
# src/components/widgets/WalletActions/actions.js
REACT_APP_WALLET_ACTIONS_PATH="<< wallet actions api path here >>"
# src/layouts/actions.js
REACT_APP_USER_WALLET_PATH="<< user wallet api path here >>"
REACT_APP_USER_ACCOUNT_PATH="<< user account api path here >>"
\ No newline at end of file
import { CURRENCIES_VALUE } from './constants';
export default function currencies_value(
state = { status: 'initial' },
action
) {
export function currencies_value(state = { status: 'initial' }, action) {
switch (action.type) {
case CURRENCIES_VALUE: {
const {
......
import { EARNINGS } from './constants';
export default function earnings(
state = { status: 'initial', earnings: {} },
action
) {
export function earnings(state = { status: 'initial', earnings: {} }, action) {
switch (action.type) {
case EARNINGS: {
const {
......
import { LAST_TRANSACTIONS } from './constants';
export default function last_transactions(
state = { status: 'initial' },
action
) {
export function last_transactions(state = { status: 'initial' }, action) {
switch (action.type) {
case LAST_TRANSACTIONS: {
const {
......
import { MONTH_EARNINGS } from './constants';
export default function month_earnings(state = { status: 'initial' }, action) {
export function month_earnings(state = { status: 'initial' }, action) {
switch (action.type) {
case MONTH_EARNINGS: {
const {
......
export const TRANSACTIONS = 'CURRECIES_VALUE';
export const TRANSACTIONS = 'TRANSACTIONS';
import { TRANSACTIONS } from './constants';
export default function _transactions(state = { status: 'initial' }, action) {
export function transactions(state = { status: 'initial' }, action) {
switch (action.type) {
case TRANSACTIONS: {
const {
......
import { createAction } from 'redux-actions';
import { fetchApi } from 'utils';
import WALLET_ACTIONS from './constants';
import { WALLET_ACTIONS } from './constants';
const WALLET_ACTIONS_URL = 'user/v1/methods';
const WALLET_ACTIONS_PATH = process.env.REACT_APP_WALLET_ACTIONS_PATH;
const reset = createAction(WALLET_ACTIONS, () => ({
status: 'initial'
......@@ -25,7 +25,7 @@ const success = createAction(WALLET_ACTIONS, methods => ({
const getActions = () => dispatch => {
dispatch(begin);
fetchApi({
path: WALLET_ACTIONS_URL
path: WALLET_ACTIONS_PATH
})
.then(response => {
const methods = response;
......
const WALLET_ACTIONS = 'WALLET_ACTIONS';
export default WALLET_ACTIONS;
export const WALLET_ACTIONS = 'WALLET_ACTIONS';
import WALLET_ACTIONS from './constants';
import { WALLET_ACTIONS } from './constants';
import {
CASH_IN_TOKENS,
CASH_IN_TOKEN_CREATE,
......@@ -6,7 +6,7 @@ import {
} from './CashIn/methods/constants';
// TODO: handle errors
export default function wallet_actions(
export function wallet_actions(
state = { status: 'initial', cash_in: [], cash_out: [] },
action
) {
......
import React from "react";
import cx from "classnames";
import { connect } from "react-redux"
import actions from './actions';
import { isLoggedIn } from 'utils'
import React from 'react';
import cx from 'classnames';
import { connect } from 'react-redux';
import { isLoggedIn } from 'utils';
import PropTypes from "prop-types";
import { Switch, Route, Redirect } from "react-router-dom";
import { Switch, Route, Redirect } from 'react-router-dom';
// @material-ui/core components
import withStyles from "@material-ui/core/styles/withStyles";
import withStyles from '@material-ui/core/styles/withStyles';
// core components
import Header from "components/atoms/Header/Header.jsx";
import Sidebar from "components/atoms/Sidebar/Sidebar.jsx";
import Header from 'components/atoms/Header/Header';
import Sidebar from 'components/atoms/Sidebar/Sidebar';
import dashboardRoutes from "routes/dashboard.jsx";
import dashboardRoutes from 'routes/dashboard';
import appStyle from "assets/jss/material-dashboard-pro-react/layouts/dashboardStyle.jsx";
import appStyle from 'assets/jss/material-dashboard-pro-react/layouts/dashboardStyle';
import image from "assets/img/sidebar-2.jpg";
import logo from "logo.jpg";
import image from 'assets/img/sidebar-2.jpg';
import logo from 'logo.jpg';
import actions from './actions';
const switchRoutes = (
<Switch>
{dashboardRoutes.map((prop, key) => {
{dashboardRoutes.map(prop => {
if (prop.redirect)
return <Redirect from={prop.path} to={prop.pathTo} key={key} />;
return <Redirect from={prop.path} to={prop.pathTo} key={prop.id} />;
if (prop.collapse)
return prop.views.map((prop, key) => {
return prop.views.map(prop => {
return (
<Route path={prop.path} component={prop.component} key={key} />
<Route path={prop.path} component={prop.component} key={prop.id} />
);
});
return <Route path={prop.path} component={prop.component} key={key} />;
return (
<Route path={prop.path} component={prop.component} key={prop.id} />
);
})}
</Switch>
);
......@@ -40,61 +41,72 @@ const switchRoutes = (
class Dashboard extends React.Component {
constructor(props) {
super(props);
this.state = {
mobileOpen: false,
miniActive: false,
loading: true
};
this.mainPanelRef = React.createRef();
this.getRoute = this.getRoute.bind(this);
this.handleDrawerToggle = this.handleDrawerToggle.bind(this);
this.sidebarMinimize = this.sidebarMinimize.bind(this);
this.resizeFunction = this.resizeFunction.bind(this);
}
componentWillMount() {
// TODO: fix me
UNSAFE_componentWillMount() {
if (!isLoggedIn()) {
this.props.history.push('/login');
}
this.props.getMe();
}
componentWillReceiveProps(nextProps) {
if(nextProps.status === "success"){
this.setState({loading: false});
}else if (nextProps.status === "error"){
this.props.history.push('/login')
// TODO: fix me
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.status === 'success') {
this.setState({ loading: false });
} else if (nextProps.status === 'error') {
this.props.history.push('/login');
}
}
getRoute = () => {
return this.props.location.pathname !== '/maps/full-screen-maps';
};
handleDrawerToggle = () => {
this.setState({ mobileOpen: !this.state.mobileOpen });
this.setState(prevState => ({ mobileOpen: !prevState.mobileOpen }));
};
getRoute() {
return this.props.location.pathname !== "/maps/full-screen-maps";
}
sidebarMinimize() {
this.setState({ miniActive: !this.state.miniActive });
}
resizeFunction() {
sidebarMinimize = () => {
this.setState(prevState => ({ miniActive: !prevState.miniActive }));
};
resizeFunction = () => {
if (window.innerWidth >= 960) {
this.setState({ mobileOpen: false });
}
}
};
render() {
const { classes, user, ...rest } = this.props;
const { loading } = this.state;
if(loading){
return("Loading");
if (loading) {
return 'Loading';
}
const mainPanel =
classes.mainPanel +
" " +
cx({
[classes.mainPanelSidebarMini]: this.state.miniActive,
[classes.mainPanelWithPerfectScrollbar]:
navigator.platform.indexOf("Win") > -1
});
const mainPanel = `${classes.mainPanel} ${cx({
[classes.mainPanelSidebarMini]: this.state.miniActive,
[classes.mainPanelWithPerfectScrollbar]:
navigator.platform.indexOf('Win') > -1
})}`;
return (
<div className={classes.wrapper}>
<Sidebar
routes={dashboardRoutes}
logoText={"BotC Wallet"}
logoText="BotC Wallet"
logo={logo}
image={image}
handleDrawerToggle={this.handleDrawerToggle}
......@@ -105,31 +117,30 @@ class Dashboard extends React.Component {
user={user}
{...rest}
/>
<div className={mainPanel} ref="mainPanel">
<div className={mainPanel} ref={this.mainPanelRef}>
<Header
sidebarMinimize={this.sidebarMinimize.bind(this)}
sidebarMinimize={this.sidebarMinimize}
miniActive={this.state.miniActive}
routes={dashboardRoutes}
handleDrawerToggle={this.handleDrawerToggle}
{...rest}
/>
<div className={classes.content}>
<div className={classes.container}>{switchRoutes}</div>
</div>
<div className={classes.content}>
<div className={classes.container}>{switchRoutes}</div>
</div>
</div>
</div>
);
}
}
Dashboard.propTypes = {
classes: PropTypes.object.isRequired
};
const mapStateToProps = (state) => ({
const mapStateToProps = state => ({
user: state.user.data,
status: state.user.status,
wallet_status: state.wallet.status
})
});
export default connect(mapStateToProps, actions)(withStyles(appStyle)(Dashboard));
export default connect(
mapStateToProps,
actions
)(withStyles(appStyle)(Dashboard));
......@@ -2,6 +2,9 @@ import { createAction } from 'redux-actions';
import { fetchApi, logOut } from 'utils';
import { USER, WALLET } from './constants';
const USER_WALLET_PATH = process.env.REACT_APP_USER_WALLET_PATH;
const USER_ACCOUNT_PATH = process.env.REACT_APP_USER_ACCOUNT_PATH;
const reset = createAction(USER, () => ({
status: 'initial'
}));
......@@ -42,8 +45,8 @@ const getMe = () => dispatch => {
dispatch(begin());
dispatch(beginWallet());
Promise.all([
fetchApi({ path: 'user/v1/account' }),
fetchApi({ path: 'user/v1/wallet' })
fetchApi({ path: USER_ACCOUNT_PATH }),
fetchApi({ path: USER_WALLET_PATH })
])
.then(responses => {
const user = responses[0];
......
import { USER, WALLET } from './constants';
export default function user(state = { status: 'initial' }, action) {
export function user(state = { status: 'initial' }, action) {
switch (action.type) {
case USER: {
const {
......
import React from "react";
import PropTypes from "prop-types";
import React from 'react';
// @material-ui/core components
import withStyles from "@material-ui/core/styles/withStyles";
import dashboardStyle from "assets/jss/material-dashboard-pro-react/views/dashboardStyle";
import CurrenciesValue from "components/widgets/CurrenciesValue";
import Earnings from "components/widgets/Earnings"
import MonthEarnings from "components/widgets/MonthEarnings"
import LastTransactions from "components/widgets/LastTransactions";
import GridContainer from "components/atoms/Grid/GridContainer.jsx";
import GridItem from "components/atoms/Grid/GridItem.jsx";
class Dashboard extends React.Component {
render() {
return (
<div>
<CurrenciesValue />
<MonthEarnings />
<GridContainer
direction="row"
justify="space-between"
alignItems="flex-start"
container
>
<GridItem xs={7}>
<LastTransactions />
</GridItem>
<GridItem xs={5}>
<Earnings />
</GridItem>
</GridContainer>
</div>
);
}
}
Dashboard.propTypes = {
classes: PropTypes.object.isRequired
};
export default withStyles(dashboardStyle)(Dashboard);
\ No newline at end of file
import withStyles from '@material-ui/core/styles/withStyles';
import dashboardStyle from 'assets/jss/material-dashboard-pro-react/views/dashboardStyle';
import CurrenciesValue from 'components/widgets/CurrenciesValue';
import Earnings from 'components/widgets/Earnings';
import MonthEarnings from 'components/widgets/MonthEarnings';
import LastTransactions from 'components/widgets/LastTransactions';
import GridContainer from 'components/atoms/Grid/GridContainer';
import GridItem from 'components/atoms/Grid/GridItem';
const Dashboard = () => (
<div>
<CurrenciesValue />
<MonthEarnings />
<GridContainer
direction="row"
justify="space-between"
alignItems="flex-start"
container
>
<GridItem xs={7}>
<LastTransactions />
</GridItem>
<GridItem xs={5}>
<Earnings />
</GridItem>
</GridContainer>
</div>
);
export default withStyles(dashboardStyle)(Dashboard);
......@@ -28,8 +28,8 @@ const fail = createAction(LOGIN, error => ({
const login = (username, password, code) => dispatch => {
dispatch(begin());
const body = {
CLIENT_ID,
CLIENT_SECRET,
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
pin: code,
grant_type: 'password',
scope: 'panel',
......
import { LOGIN } from './constants';
export default function login(state = { status: 'initial' }, action) {
export function login(state = { status: 'initial' }, action) {
switch (action.type) {
case LOGIN: {
const {
......
import { combineReducers } from 'redux';
import currencies_value from 'components/widgets/CurrenciesValue/reducers';
import last_transactions from 'components/widgets/LastTransactions/reducers';
import earnings from 'components/widgets/Earnings/reducers';
import month_earnings from 'components/widgets/MonthEarnings/reducers';
import transactions from 'components/widgets/Transactions/reducers';
import wallet_actions from 'components/widgets/WalletActions/reducers';
import user, { wallet } from 'layouts/reducers';
import login from 'pages/login/reducers';
import { currencies_value } from 'components/widgets/CurrenciesValue/reducers';
import { last_transactions } from 'components/widgets/LastTransactions/reducers';
import { earnings } from 'components/widgets/Earnings/reducers';
import { month_earnings } from 'components/widgets/MonthEarnings/reducers';
import { transactions } from 'components/widgets/Transactions/reducers';
import { wallet_actions } from 'components/widgets/WalletActions/reducers';
import { user, wallet } from 'layouts/reducers';
import { login } from 'pages/login/reducers';
const reducers = {
currencies_value,
......
import Dashboard from "pages/dashboard";
import Wallet from "pages/wallet";
import Dashboard from 'pages/dashboard';
import Wallet from 'pages/wallet';
// @material-ui/icons
import DashboardIcon from "@material-ui/icons/Dashboard";
import WalletIcon from "@material-ui/icons/AccountBalanceWallet";
import DashboardIcon from '@material-ui/icons/Dashboard';
import WalletIcon from '@material-ui/icons/AccountBalanceWallet';
var dashRoutes = [
const dashboardRoutes = [
{
path: "/dashboard",
name: "Dashboard",
id: 0,
path: '/dashboard',
name: 'Dashboard',
icon: DashboardIcon,
component: Dashboard
},
{
path: "/wallet",
name: "Wallet",
id: 1,
path: '/wallet',
name: 'Wallet',
icon: WalletIcon,
component: Wallet
},
{ redirect: true, path: "/", pathTo: "/dashboard", name: "Dashboard" }
{
id: 2,
redirect: true,
path: '/',
pathTo: '/dashboard',
name: 'Dashboard'
}
];
export default dashRoutes;
export default dashboardRoutes;
......@@ -2877,7 +2877,7 @@ class-utils@^0.3.5:
isobject "^3.0.0"
static-extend "^0.1.1"
classnames@^2.2.5:
classnames@^2.2.5, classnames@^2.2.6:
version "2.2.6"
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.6.tgz#43935bffdd291f326dad0a205309b38d00f650ce"
integrity sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q==
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment