// Copyright 2015-2018 Parity Technologies (UK) Ltd. // This file is part of Parity. // // SPDX-License-Identifier: BSD-3-Clause import React, { Component } from 'react'; import { BrowserRouter, MemoryRouter, Redirect, Route, Switch } from 'react-router-dom'; import { inject, observer } from 'mobx-react'; import isElectron from 'is-electron'; import { Modal } from 'fether-ui'; import semver from 'semver'; import { version } from '../../package.json'; import Accounts from '../Accounts'; import BackupAccount from '../BackupAccount'; import Onboarding from '../Onboarding'; import RequireHealthOverlay from '../RequireHealthOverlay'; import Send from '../Send'; import Tokens from '../Tokens'; import Whitelist from '../Whitelist'; const currentVersion = version; // Use MemoryRouter for production viewing in file:// protocol // https://github.com/facebook/create-react-app/issues/3591 const Router = process.env.NODE_ENV === 'production' ? MemoryRouter : BrowserRouter; const electron = isElectron() ? window.require('electron') : null; @inject('onboardingStore', 'parityStore') @observer class App extends Component { state = { newRelease: false // false | {name, url, ignore} }; componentDidMount () { window.addEventListener('contextmenu', this.handleRightClick); window .fetch('https://api.github.com/repos/paritytech/fether/releases/latest') .then(j => j.json()) .then(({ name, html_url: url, tag_name: tag }) => { const latestVersion = tag.match(/v(\d+\.\d+(\.\d+)?)/)[1]; if (semver.gt(latestVersion, currentVersion)) { this.setState({ newRelease: { name, url, ignore: false } }); } }) .catch(e => { console.error('Error while checking for a new version of Fether:', e); }); } componentDidUnmount () { window.removeEventListener('contextmenu', this.handleRightClick); } renderModalLinks = () => { return ( ); }; hideNewReleaseModal = () => { this.setState({ newRelease: { ...this.state.newRelease, ignore: true } }); }; openNewReleaseUrl = () => { window.open(this.state.newRelease.url, '_blank', 'noopener noreferrer'); }; handleRightClick = () => { if (!electron) { return; } electron.ipcRenderer.send('asynchronous-message', 'app-right-click'); }; /** * Decide which screen to render. */ render () { const { onboardingStore: { isFirstRun }, parityStore: { api } } = this.props; const { newRelease } = this.state; if (isFirstRun) { return (
); } // The child components make use of light.js and light.js needs to be passed // an API first, otherwise it will throw an error. // We set parityStore.api right after we set the API for light.js, so we // verify here that parityStore.api is defined, and if not we don't render // the children, just a . if (!api) { return ( {/* Adding these components to have minimum height on window */}
); } return (
{/* The next line is the homepage */}
); } } export default App;