diff --git a/common/actions/common.js b/common/actions/common.js index febde1eb..550cab47 100644 --- a/common/actions/common.js +++ b/common/actions/common.js @@ -1,4 +1,4 @@ -export const LOCATION_CHANGE = '@@router/LOCATION_CHANGE' +export const LOCATION_CHANGE = '@@router/LOCATION_CHANGE'; // I'm not sure, but I guess that if you use redux-devtools extension your APP_INIT should be look like: // export const APP_INIT = '@@INIT' -export const APP_INIT = '@@redux/INIT' +export const APP_INIT = '@@redux/INIT'; diff --git a/common/actions/notifications.js b/common/actions/notifications.js index 9c852ab3..be8fd623 100644 --- a/common/actions/notifications.js +++ b/common/actions/notifications.js @@ -3,41 +3,45 @@ export type NOTIFICATION_LEVEL = 'danger' | 'warning' | 'success' | 'info'; export type Notification = { - level: NOTIFICATION_LEVEL, - msg: string, - duration?: number + level: NOTIFICATION_LEVEL, + msg: string, + duration?: number }; export type ShowNotificationAction = { - type: 'SHOW_NOTIFICATION', - payload: Notification + type: 'SHOW_NOTIFICATION', + payload: Notification }; export type CloseNotificationAction = { - type: 'CLOSE_NOTIFICATION', - payload: Notification + type: 'CLOSE_NOTIFICATION', + payload: Notification }; -export type NotificationsAction = ShowNotificationAction | CloseNotificationAction; +export type NotificationsAction = + | ShowNotificationAction + | CloseNotificationAction; export function showNotification( - level: NOTIFICATION_LEVEL = 'info', - msg: string, - duration?: number + level: NOTIFICATION_LEVEL = 'info', + msg: string, + duration?: number ): ShowNotificationAction { - return { - type: 'SHOW_NOTIFICATION', - payload: { - level, - msg, - duration - } - }; + return { + type: 'SHOW_NOTIFICATION', + payload: { + level, + msg, + duration + } + }; } -export function closeNotification(notification: Notification): CloseNotificationAction { - return { - type: 'CLOSE_NOTIFICATION', - payload: notification - }; +export function closeNotification( + notification: Notification +): CloseNotificationAction { + return { + type: 'CLOSE_NOTIFICATION', + payload: notification + }; } diff --git a/common/api/utils.js b/common/api/utils.js index 276d09ca..f97d1908 100644 --- a/common/api/utils.js +++ b/common/api/utils.js @@ -2,55 +2,55 @@ // feel free to replace with your code // (get, post are used in ApiServices) +import { getLocalToken } from 'api/AuthSvc'; +import config from 'config'; -import {getLocalToken} from 'api/AuthSvc'; -import config from 'config' - -window.BASE_API = config.BASE_API +window.BASE_API = config.BASE_API; function requestWrapper(method) { - return async function (url, data = null, params = {}) { - if (method === 'GET') { - // is it a GET? - // GET doesn't have data - params = data; - data = null; - } else if (data === Object(data)) { - // (data === Object(data)) === _.isObject(data) - data = JSON.stringify(data) - } else { - throw new Error(`XHR invalid, check ${method} on ${url}`) - } - - // default params for fetch = method + (Content-Type) - let defaults = { - method: method, - headers: { - 'Content-Type': 'application/json; charset=UTF-8' - } - } - - // check that req url is relative and request was sent to our domain - if (url.match(/^https?:\/\//gi) > -1) { - let token = getLocalToken(); - if (token) { - defaults.headers['Authorization'] = `JWT ${token}`; - } - url = window.BASE_API + url; - } - - if (data) { - defaults.body = data; - } - - let paramsObj = {...defaults, headers: {...params, ...defaults.headers}} - - return await fetch(url, paramsObj) - .then(parseJSON) - .catch((err) => { - console.error(err) - }); + return async function(url, data = null, params = {}) { + if (method === 'GET') { + // is it a GET? + // GET doesn't have data + params = data; + data = null; + } else if (data === Object(data)) { + // (data === Object(data)) === _.isObject(data) + data = JSON.stringify(data); + } else { + throw new Error(`XHR invalid, check ${method} on ${url}`); } + + // default params for fetch = method + (Content-Type) + let defaults = { + method: method, + headers: { + 'Content-Type': 'application/json; charset=UTF-8' + } + }; + + // check that req url is relative and request was sent to our domain + if (url.match(/^https?:\/\//gi) > -1) { + let token = getLocalToken(); + if (token) { + defaults.headers['Authorization'] = `JWT ${token}`; + } + url = window.BASE_API + url; + } + + if (data) { + defaults.body = data; + } + + let paramsObj = { + ...defaults, + headers: { ...params, ...defaults.headers } + }; + + return await fetch(url, paramsObj).then(parseJSON).catch(err => { + console.error(err); + }); + }; } // middlewares @@ -64,28 +64,27 @@ function requestWrapper(method) { * @return {Object} response result with "ok" property */ async function parseJSON(res) { - let json; - try { - json = await res.json() - } catch (e) { - return {data: {}, ok: false} - } + let json; + try { + json = await res.json(); + } catch (e) { + return { data: {}, ok: false }; + } - // simplest validation ever, ahah :) - if (!res.ok) { - return {data: json, ok: false} - } - // resultOK - is a function with side effects - // It removes ok property from result object - return {data: json, ok: true} + // simplest validation ever, ahah :) + if (!res.ok) { + return { data: json, ok: false }; + } + // resultOK - is a function with side effects + // It removes ok property from result object + return { data: json, ok: true }; } - -export const get = requestWrapper('GET') -export const post = requestWrapper('POST') -export const put = requestWrapper('PUT') -export const patch = requestWrapper('PATCH') -export const del = requestWrapper('DELETE') +export const get = requestWrapper('GET'); +export const post = requestWrapper('POST'); +export const put = requestWrapper('PUT'); +export const patch = requestWrapper('PATCH'); +export const del = requestWrapper('DELETE'); // USAGE: // get('https://www.google.com', { @@ -108,11 +107,11 @@ export const del = requestWrapper('DELETE') * @return {bool} - indicates was request successful or not */ export function resultOK(result) { - if (result) { - let ok = result.ok - delete result.ok - return ok //look at parseJSON - } else { - return false - } + if (result) { + let ok = result.ok; + delete result.ok; + return ok; //look at parseJSON + } else { + return false; + } } diff --git a/common/components/Root/index.jsx b/common/components/Root/index.jsx index 73e0b4f8..a8a24b11 100644 --- a/common/components/Root/index.jsx +++ b/common/components/Root/index.jsx @@ -1,24 +1,24 @@ -import React, {Component} from 'react' -import {Provider} from 'react-redux' -import {Router} from 'react-router' +import React, { Component } from 'react'; +import { Provider } from 'react-redux'; +import { Router } from 'react-router'; import PropTypes from 'prop-types'; export default class Root extends Component { - static propTypes = { - store: PropTypes.object, - history: PropTypes.object, - routes: PropTypes.func - }; + static propTypes = { + store: PropTypes.object, + history: PropTypes.object, + routes: PropTypes.func + }; - render() { - const {store, history, routes} = this.props; - // key={Math.random()} = hack for HMR from https://github.com/webpack/webpack-dev-server/issues/395 - return ( - - - {routes()} - - - ); - } + render() { + const { store, history, routes } = this.props; + // key={Math.random()} = hack for HMR from https://github.com/webpack/webpack-dev-server/issues/395 + return ( + + + {routes()} + + + ); + } } diff --git a/common/containers/App/Notifications.jsx b/common/containers/App/Notifications.jsx index 40697e7f..105616bd 100644 --- a/common/containers/App/Notifications.jsx +++ b/common/containers/App/Notifications.jsx @@ -5,74 +5,74 @@ import { closeNotification } from 'actions/notifications'; import type { Notification } from 'actions/notifications'; class NotificationRow extends React.Component { - props: { - notification: Notification, - onClose: (n: Notification) => void - }; - render() { - const { msg, level } = this.props.notification; - let className = ''; + props: { + notification: Notification, + onClose: (n: Notification) => void + }; + render() { + const { msg, level } = this.props.notification; + let className = ''; - switch (level) { - case 'danger': - className = 'alert-danger'; - break; - case 'success': - className = 'alert-success'; - break; - case 'warning': - className = 'alert-warning'; - break; - } - - return ( -
- {level} -
- -
- ); + switch (level) { + case 'danger': + className = 'alert-danger'; + break; + case 'success': + className = 'alert-success'; + break; + case 'warning': + className = 'alert-warning'; + break; } - onClose = () => { - this.props.onClose(this.props.notification); - }; + return ( +
+ {level} +
+ +
+ ); + } + + onClose = () => { + this.props.onClose(this.props.notification); + }; } export class Notifications extends React.Component { - props: { - notifications: Notification[], - closeNotification: (n: Notification) => void - }; - render() { - if (!this.props.notifications.length) { - return null; - } - return ( -
- {this.props.notifications.map((n, i) => - - )} -
- ); + props: { + notifications: Notification[], + closeNotification: (n: Notification) => void + }; + render() { + if (!this.props.notifications.length) { + return null; } + return ( +
+ {this.props.notifications.map((n, i) => + + )} +
+ ); + } } const mapStateToProps = state => ({ - notifications: state.notifications + notifications: state.notifications }); export default connect(mapStateToProps, { closeNotification })(Notifications); diff --git a/common/containers/Tabs/Help/index.js b/common/containers/Tabs/Help/index.js index 29bb7e5d..7a8999f6 100644 --- a/common/containers/Tabs/Help/index.js +++ b/common/containers/Tabs/Help/index.js @@ -1,27 +1,47 @@ import React from 'react'; -const Help = () => ( -
- -
-); +const Help = () => +
+ +
; -export default Help +export default Help; diff --git a/common/containers/Tabs/SendTransaction/components/GasField.jsx b/common/containers/Tabs/SendTransaction/components/GasField.jsx index ca541807..0d539868 100644 --- a/common/containers/Tabs/SendTransaction/components/GasField.jsx +++ b/common/containers/Tabs/SendTransaction/components/GasField.jsx @@ -15,7 +15,8 @@ export default class GasField extends React.Component { return (
-