replace React.Component by React.PureComponent

pull/165/head
Szymon Lesisz 6 years ago
parent 37ed349dff
commit c51b12906f

@ -1,4 +1,4 @@
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import styled, { css } from 'styled-components'; import styled, { css } from 'styled-components';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { FONT_SIZE, TRANSITION } from 'config/variables'; import { FONT_SIZE, TRANSITION } from 'config/variables';
@ -45,7 +45,7 @@ const StyledNavLink = styled(NavLink)`
`} `}
`; `;
class Link extends Component { class Link extends PureComponent {
render() { render() {
const shouldRenderRouterLink = this.props.to; const shouldRenderRouterLink = this.props.to;
let LinkComponent; let LinkComponent;

@ -1,4 +1,4 @@
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
@ -13,7 +13,7 @@ const Logo = styled.img`
display: block; display: block;
`; `;
class CoinLogo extends Component { class CoinLogo extends PureComponent {
constructor() { constructor() {
super(); super();
this.longIcons = ['etc', 'eth', 'trop']; this.longIcons = ['etc', 'eth', 'trop'];

@ -1,4 +1,4 @@
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import styled, { css } from 'styled-components'; import styled, { css } from 'styled-components';
import colors from 'config/colors'; import colors from 'config/colors';
@ -72,7 +72,7 @@ const BottomText = styled.span`
color: ${props => (props.color ? props.color : colors.TEXT_SECONDARY)}; color: ${props => (props.color ? props.color : colors.TEXT_SECONDARY)};
`; `;
class Input extends Component { class Input extends PureComponent {
getIcon(inputState) { getIcon(inputState) {
let icon = []; let icon = [];
if (inputState === 'success') { if (inputState === 'success') {

@ -1,5 +1,5 @@
/* @flow */ /* @flow */
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import { H2 } from 'components/Heading'; import { H2 } from 'components/Heading';
import P from 'components/Paragraph'; import P from 'components/Paragraph';
import styled from 'styled-components'; import styled from 'styled-components';
@ -36,7 +36,7 @@ const StyledButton = styled(Button)`
margin: 0 0 10px 0; margin: 0 0 10px 0;
`; `;
class ConfirmUnverifiedAddress extends Component<Props> { class ConfirmUnverifiedAddress extends PureComponent<Props> {
componentDidMount(): void { componentDidMount(): void {
this.keyboardHandler = this.keyboardHandler.bind(this); this.keyboardHandler = this.keyboardHandler.bind(this);
window.addEventListener('keydown', this.keyboardHandler, false); window.addEventListener('keydown', this.keyboardHandler, false);

@ -1,5 +1,5 @@
/* @flow */ /* @flow */
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { H3 } from 'components/Heading'; import { H3 } from 'components/Heading';
import P from 'components/Paragraph'; import P from 'components/Paragraph';
@ -62,7 +62,7 @@ const ErrorMessage = styled.div`
width: 100%; width: 100%;
`; `;
export default class DuplicateDevice extends Component<Props, State> { export default class DuplicateDevice extends PureComponent<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);

@ -1,6 +1,6 @@
/* @flow */ /* @flow */
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { H3 } from 'components/Heading'; import { H3 } from 'components/Heading';
import P from 'components/Paragraph'; import P from 'components/Paragraph';
@ -27,7 +27,7 @@ const Row = styled.div`
padding: 10px 0; padding: 10px 0;
`; `;
class ForgetDevice extends Component<Props> { class ForgetDevice extends PureComponent<Props> {
componentDidMount() { componentDidMount() {
this.keyboardHandler = this.keyboardHandler.bind(this); this.keyboardHandler = this.keyboardHandler.bind(this);
window.addEventListener('keydown', this.keyboardHandler, false); window.addEventListener('keydown', this.keyboardHandler, false);

@ -1,5 +1,5 @@
/* @flow */ /* @flow */
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { H3 } from 'components/Heading'; import { H3 } from 'components/Heading';
import P from 'components/Paragraph'; import P from 'components/Paragraph';
@ -47,7 +47,7 @@ const StyledLoader = styled(Loader)`
left: 200px; left: 200px;
`; `;
export default class RememberDevice extends Component<Props, State> { export default class RememberDevice extends PureComponent<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);

@ -1,6 +1,6 @@
/* @flow */ /* @flow */
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import styled, { css } from 'styled-components'; import styled, { css } from 'styled-components';
import { H3 } from 'components/Heading'; import { H3 } from 'components/Heading';
import P from 'components/Paragraph'; import P from 'components/Paragraph';
@ -64,7 +64,7 @@ const Content = styled.div`
`} `}
`; `;
class WalletType extends Component<Props> { class WalletType extends PureComponent<Props> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
this.keyboardHandler = this.keyboardHandler.bind(this); this.keyboardHandler = this.keyboardHandler.bind(this);

@ -85,7 +85,7 @@ const ModalWindow = styled.div`
text-align: center; text-align: center;
`; `;
class Modal extends React.Component<Props> { class Modal extends React.PureComponent<Props> {
render() { render() {
if (!this.props.modal.opened) return null; if (!this.props.modal.opened) return null;

@ -1,5 +1,5 @@
/* @flow */ /* @flow */
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import colors from 'config/colors'; import colors from 'config/colors';
import { FONT_SIZE, TRANSITION } from 'config/variables'; import { FONT_SIZE, TRANSITION } from 'config/variables';
@ -76,7 +76,7 @@ const LinkButton = styled(Button)`
} }
`; `;
class Passphrase extends Component<Props, State> { class Passphrase extends PureComponent<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);

@ -1,7 +1,7 @@
/* @flow */ /* @flow */
import P from 'components/Paragraph'; import P from 'components/Paragraph';
import { H2 } from 'components/Heading'; import { H2 } from 'components/Heading';
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import Link from 'components/Link'; import Link from 'components/Link';
import styled from 'styled-components'; import styled from 'styled-components';
@ -39,7 +39,7 @@ const Footer = styled.div`
flex-direction: column; flex-direction: column;
`; `;
class Pin extends Component<Props, State> { class Pin extends PureComponent<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);

@ -1,4 +1,4 @@
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import styled from 'styled-components'; import styled from 'styled-components';
import Icon from 'components/Icon'; import Icon from 'components/Icon';
@ -32,7 +32,7 @@ const Title = styled.div`
color: ${props => props.color}; color: ${props => props.color};
`; `;
class Group extends Component { class Group extends PureComponent {
constructor() { constructor() {
super(); super();
this.state = { this.state = {

@ -1,4 +1,4 @@
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
@ -6,7 +6,7 @@ import Group from './components/Group';
const Wrapper = styled.div``; const Wrapper = styled.div``;
class NotificationsGroup extends Component { class NotificationsGroup extends PureComponent {
groupNotifications = notifications => notifications groupNotifications = notifications => notifications
.reduce((acc, obj) => { .reduce((acc, obj) => {
const key = obj.type; const key = obj.type;

@ -1,8 +1,8 @@
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import RedBox from 'redbox-react'; import RedBox from 'redbox-react';
class ErrorBoundary extends Component { class ErrorBoundary extends PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { hasError: false, error: false }; this.state = { hasError: false, error: false };

@ -1,6 +1,6 @@
/* @flow */ /* @flow */
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import styled, { keyframes } from 'styled-components'; import styled, { keyframes } from 'styled-components';
import TrezorConnect from 'trezor-connect'; import TrezorConnect from 'trezor-connect';
import P from 'components/Paragraph'; import P from 'components/Paragraph';
@ -14,7 +14,7 @@ type Props = {
showWebUsb: boolean, showWebUsb: boolean,
showDisconnect: boolean, showDisconnect: boolean,
}; };
class ConnectDevice extends Component<Props> { class ConnectDevice extends PureComponent<Props> {
componentDidMount() { componentDidMount() {
if (this.props.showWebUsb) { if (this.props.showWebUsb) {
TrezorConnect.renderWebUSBButton(); TrezorConnect.renderWebUSBButton();

@ -1,6 +1,6 @@
/* @flow */ /* @flow */
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import colors from 'config/colors'; import colors from 'config/colors';
import { FONT_SIZE, FONT_WEIGHT } from 'config/variables'; import { FONT_SIZE, FONT_WEIGHT } from 'config/variables';
@ -118,7 +118,7 @@ const Li = styled.li`
text-align: justify; text-align: justify;
`; `;
class InstallBridge extends Component<Props, State> { class InstallBridge extends PureComponent<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);

@ -3,14 +3,14 @@ import coins from 'constants/coins';
import colors from 'config/colors'; import colors from 'config/colors';
import ICONS from 'config/icons'; import ICONS from 'config/icons';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import { NavLink } from 'react-router-dom'; import { NavLink } from 'react-router-dom';
import Divider from '../Divider'; import Divider from '../Divider';
import RowCoin from '../RowCoin'; import RowCoin from '../RowCoin';
const Wrapper = styled.div``; const Wrapper = styled.div``;
class CoinMenu extends Component { class CoinMenu extends PureComponent {
getBaseUrl() { getBaseUrl() {
const { selectedDevice } = this.props.wallet; const { selectedDevice } = this.props.wallet;
let baseUrl = ''; let baseUrl = '';

@ -1,6 +1,6 @@
/* @flow */ /* @flow */
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import Icon from 'components/Icon'; import Icon from 'components/Icon';
import DeviceHeader from 'components/DeviceHeader'; import DeviceHeader from 'components/DeviceHeader';
@ -22,7 +22,7 @@ type Props = {
forgetDevice: $ElementType<CommonProps, 'forgetDevice'>; forgetDevice: $ElementType<CommonProps, 'forgetDevice'>;
}; };
class DeviceList extends Component<Props> { class DeviceList extends PureComponent<Props> {
sortByInstance(a: TrezorDevice, b: TrezorDevice) { sortByInstance(a: TrezorDevice, b: TrezorDevice) {
if (!a.instance || !b.instance) return -1; if (!a.instance || !b.instance) return -1;
return a.instance > b.instance ? 1 : -1; return a.instance > b.instance ? 1 : -1;

@ -1,4 +1,4 @@
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Icon from 'components/Icon'; import Icon from 'components/Icon';
@ -27,7 +27,7 @@ const Label = styled.div`
padding-left: 15px; padding-left: 15px;
`; `;
class MenuItems extends Component { class MenuItems extends PureComponent {
onDeviceMenuClick(action, device) { onDeviceMenuClick(action, device) {
if (action === 'reload') { if (action === 'reload') {
this.props.acquireDevice(); this.props.acquireDevice();

@ -1,5 +1,5 @@
/* @flow */ /* @flow */
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import TrezorConnect from 'trezor-connect'; import TrezorConnect from 'trezor-connect';
import type { TrezorDevice } from 'flowtype'; import type { TrezorDevice } from 'flowtype';
@ -27,7 +27,7 @@ type DeviceMenuItem = {
label: string; label: string;
} }
class DeviceMenu extends Component<Props> { class DeviceMenu extends PureComponent<Props> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
this.mouseDownHandler = this.mouseDownHandler.bind(this); this.mouseDownHandler = this.mouseDownHandler.bind(this);

@ -2,7 +2,7 @@
import styled from 'styled-components'; import styled from 'styled-components';
import colors from 'config/colors'; import colors from 'config/colors';
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
type Props = { type Props = {
@ -25,7 +25,7 @@ const Wrapper = styled.div`
transition: all 0.3s ease-in-out; transition: all 0.3s ease-in-out;
`; `;
class Indicator extends Component<Props, State> { class Indicator extends PureComponent<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);

@ -1,5 +1,5 @@
/* @flow */ /* @flow */
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import colors from 'config/colors'; import colors from 'config/colors';
import ColorHash from 'color-hash'; import ColorHash from 'color-hash';
@ -67,7 +67,7 @@ const TransactionAmount = styled.div`
color: colors.TEXT_SECONDARY; color: colors.TEXT_SECONDARY;
`; `;
class PendingTransactions extends Component<Props> { class PendingTransactions extends PureComponent<Props> {
getPendingTransactions() { getPendingTransactions() {
return this.props.pending.filter(tx => !tx.rejected); return this.props.pending.filter(tx => !tx.rejected);
} }

@ -1,5 +1,5 @@
/* @flow */ /* @flow */
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import BigNumber from 'bignumber.js'; import BigNumber from 'bignumber.js';
import styled from 'styled-components'; import styled from 'styled-components';
import Icon from 'components/Icon'; import Icon from 'components/Icon';
@ -88,7 +88,7 @@ const Label = styled.div`
`; `;
class AccountBalance extends Component<Props, State> { class AccountBalance extends PureComponent<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
this.state = { this.state = {

@ -1,4 +1,4 @@
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import ColorHash from 'color-hash'; import ColorHash from 'color-hash';
import ScaleText from 'react-scale-text'; import ScaleText from 'react-scale-text';
@ -50,7 +50,7 @@ const RemoveTokenButton = styled(Button)`
padding: 0 0 0 10px; padding: 0 0 0 10px;
`; `;
class AddedToken extends Component<> { class AddedToken extends PureComponent {
getTokenBalance(token) { getTokenBalance(token) {
const pendingAmount = stateUtils.getPendingAmount(this.props.pending, token.symbol, true); const pendingAmount = stateUtils.getPendingAmount(this.props.pending, token.symbol, true);
const balance = new BigNumber(token.balance).minus(pendingAmount).toString(10); const balance = new BigNumber(token.balance).minus(pendingAmount).toString(10);

Loading…
Cancel
Save