Newer
Older
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
Axel Chalon
committed
import React, { Component } from 'react';
import {
BrowserRouter,
MemoryRouter,
Redirect,
Route,
Switch
Axel Chalon
committed
} from 'react-router-dom';
import { inject, observer } from 'mobx-react';
import { Modal } from 'fether-ui';
import semver from 'semver';
import { version } from '../../package.json';
Axel Chalon
committed
import Accounts from '../Accounts';
import BackupAccount from '../BackupAccount';
Axel Chalon
committed
import Onboarding from '../Onboarding';
import RequireHealthOverlay from '../RequireHealthOverlay';
Axel Chalon
committed
import Tokens from '../Tokens';
const currentVersion = version;
// Use MemoryRouter for production viewing in file:// protocol
// https://github.com/facebook/create-react-app/issues/3591
const Router =
Axel Chalon
committed
process.env.NODE_ENV === 'production' ? MemoryRouter : BrowserRouter;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
state = {
newRelease: false // false | {name, url, ignore}
};
componentDidMount () {
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);
});
}
renderModalLinks = () => {
return (
<nav className='form-nav -binary'>
<button className='button -back' onClick={this.hideNewReleaseModal}>
Remind me later
</button>
<button className='button' onClick={this.openNewReleaseUrl}>
Download
</button>
</nav>
);
};
hideNewReleaseModal = () => {
this.setState({
newRelease: { ...this.state.newRelease, ignore: true }
});
};
openNewReleaseUrl = () => {
window.open(this.state.newRelease.url, '_blank', 'noopener noreferrer');
onboardingStore: { isFirstRun },
parityStore: { api }
Axel Chalon
committed
<div className='window'>
<Onboarding />
</div>
);
// 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 <RequireHealthOverlay />.
<RequireHealthOverlay fullscreen require='node'>
{/* Adding these components to have minimum height on window */}
<div className='content'>
<div className='window' />
</div>
</RequireHealthOverlay>
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<div className='content'>
<div className='window'>
<Modal
title='New version available'
description={newRelease ? `${newRelease.name} was released!` : ''}
visible={newRelease && !newRelease.ignore}
buttons={this.renderModalLinks()}
>
<Router>
<Switch>
{/* The next line is the homepage */}
<Redirect exact from='/' to='/accounts' />
<Route path='/accounts' component={Accounts} />
<Route path='/onboarding' component={Onboarding} />
<Route path='/tokens/:accountAddress' component={Tokens} />
<Route
path='/whitelist/:accountAddress'
component={Whitelist}
/>
<Route
path='/backup/:accountAddress'
component={BackupAccount}
/>
<Route
path='/send/:tokenAddress/from/:accountAddress'
component={Send}
/>
<Redirect from='*' to='/' />
</Switch>
</Router>
</Modal>