diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2020-02-28 16:15:07 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2020-04-06 10:37:05 +0200 |
| commit | 43294fbf8bead7f2bb28a84e8ff6fddc7100ec23 (patch) | |
| tree | 7d5ca2e2f3d0cfcd30b2f11bb0eaa4ef7dda9cd3 /gui | |
| parent | 808d2f753c64da3a3e5f49bb0fdf52767faa2e30 (diff) | |
| download | mullvadvpn-43294fbf8bead7f2bb28a84e8ff6fddc7100ec23.tar.xz mullvadvpn-43294fbf8bead7f2bb28a84e8ff6fddc7100ec23.zip | |
Make welcome screen disappear after adding time to account
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/src/main/account-data-cache.ts | 15 | ||||
| -rw-r--r-- | gui/src/main/index.ts | 4 | ||||
| -rw-r--r-- | gui/src/renderer/components/Connect.tsx | 9 | ||||
| -rw-r--r-- | gui/src/renderer/components/NewAccountView.tsx | 9 | ||||
| -rw-r--r-- | gui/src/renderer/containers/NewAccountViewContainer.tsx | 26 |
5 files changed, 54 insertions, 9 deletions
diff --git a/gui/src/main/account-data-cache.ts b/gui/src/main/account-data-cache.ts index 97a94eb7c3..7db2c05ca8 100644 --- a/gui/src/main/account-data-cache.ts +++ b/gui/src/main/account-data-cache.ts @@ -1,7 +1,10 @@ import log from 'electron-log'; +import moment from 'moment'; import { AccountToken, IAccountData } from '../shared/daemon-rpc-types'; import consumePromise from '../shared/promise'; +const EXPIRED_ACCOUNT_REFRESH_PERIOD = 60_000; + export enum AccountFetchRetryAction { stop, retry, @@ -77,6 +80,7 @@ export default class AccountDataCache { if (this.currentAccount === accountToken) { this.setValue(accountData); + this.scheduleRefetchIfExpired(accountToken, accountData); } } catch (error) { if (this.currentAccount === accountToken) { @@ -85,6 +89,13 @@ export default class AccountDataCache { } } + private scheduleRefetchIfExpired(accountToken: AccountToken, accountData: IAccountData) { + const hasExpired = moment(accountData.expiry).isSameOrBefore(new Date()); + if (hasExpired) { + this.scheduleFetch(accountToken, EXPIRED_ACCOUNT_REFRESH_PERIOD); + } + } + private handleFetchError(accountToken: AccountToken, error: Error) { let shouldRetry = true; @@ -107,6 +118,10 @@ export default class AccountDataCache { log.warn(`Failed to fetch account data. Retrying in ${delay} ms`); + this.scheduleFetch(accountToken, delay); + } + + private scheduleFetch(accountToken: AccountToken, delay: number) { this.fetchRetryTimeout = global.setTimeout(() => { this.fetchRetryTimeout = undefined; consumePromise(this.performFetch(accountToken)); diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 01aec17d62..28956d8c88 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -901,7 +901,7 @@ class ApplicationMain { // cancel notifications when window appears this.notificationController.cancelPendingNotifications(); - this.updateAccountExpiryIfNeeded(); + this.updateAccountData(); }); windowController.window.on('hide', () => { @@ -1159,7 +1159,7 @@ class ApplicationMain { } } - private updateAccountExpiryIfNeeded() { + private updateAccountData() { if (this.connectedToDaemon && this.settings.accountToken) { this.accountDataCache.fetch(this.settings.accountToken); } diff --git a/gui/src/renderer/components/Connect.tsx b/gui/src/renderer/components/Connect.tsx index 7a6ba17739..c994f4f42f 100644 --- a/gui/src/renderer/components/Connect.tsx +++ b/gui/src/renderer/components/Connect.tsx @@ -3,6 +3,7 @@ import { Component, Styles, View } from 'reactxp'; import { links } from '../../config.json'; import AccountExpiry from '../../shared/account-expiry'; import { AccountToken } from '../../shared/daemon-rpc-types'; +import NewAccountViewContainer from '../containers/NewAccountViewContainer'; import NotificationAreaContainer from '../containers/NotificationAreaContainer'; import { AuthFailureKind, parseAuthFailure } from '../lib/auth-failure'; import { LoginState } from '../redux/account/reducers'; @@ -15,7 +16,6 @@ import { Container, Header, Layout } from './Layout'; import Map, { MarkerStyle, ZoomLevel } from './Map'; import { ModalContainer } from './Modal'; import TunnelControl from './TunnelControl'; -import NewAccountView from './NewAccountView'; interface IProps { connection: IConnectionReduxState; @@ -143,12 +143,7 @@ export default class Connect extends Component<IProps, IState> { private renderContent() { if (this.props.loginState.type === 'ok' && this.props.loginState.method === 'new_account') { - return ( - <NewAccountView - accountToken={this.props.accountToken} - onExternalLinkWithAuth={this.props.onExternalLinkWithAuth} - /> - ); + return <NewAccountViewContainer />; } else if (this.state.isAccountExpired) { return ( <ExpiredAccountErrorView diff --git a/gui/src/renderer/components/NewAccountView.tsx b/gui/src/renderer/components/NewAccountView.tsx index e6319a3d0e..a4a51191fb 100644 --- a/gui/src/renderer/components/NewAccountView.tsx +++ b/gui/src/renderer/components/NewAccountView.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import { Component, Text, View } from 'reactxp'; import { links } from '../../config.json'; +import AccountExpiry from '../../shared/account-expiry'; import { AccountToken } from '../../shared/daemon-rpc-types'; import { messages } from '../../shared/gettext'; import styles from './NewAccountViewStyles'; @@ -9,10 +10,18 @@ import * as AppButton from './AppButton'; interface INewAccountViewProps { accountToken?: AccountToken; + accountExpiry?: AccountExpiry; + hideWelcomeView: () => void; onExternalLinkWithAuth: (url: string) => Promise<void>; } export default class NewAccountView extends Component<INewAccountViewProps> { + public componentDidUpdate() { + if (this.props.accountExpiry && !this.props.accountExpiry.hasExpired()) { + this.props.hideWelcomeView(); + } + } + public render() { return ( <View style={styles.container}> diff --git a/gui/src/renderer/containers/NewAccountViewContainer.tsx b/gui/src/renderer/containers/NewAccountViewContainer.tsx new file mode 100644 index 0000000000..a174874d48 --- /dev/null +++ b/gui/src/renderer/containers/NewAccountViewContainer.tsx @@ -0,0 +1,26 @@ +import { connect } from 'react-redux'; +import { bindActionCreators } from 'redux'; +import AccountExpiry from '../../shared/account-expiry'; +import NewAccountView from '../components/NewAccountView'; +import accountActions from '../redux/account/actions'; + +import withAppContext, { IAppContext } from '../context'; +import { IReduxState, ReduxDispatch } from '../redux/store'; + +const mapStateToProps = (state: IReduxState) => ({ + accountToken: state.account.accountToken, + accountExpiry: state.account.expiry + ? new AccountExpiry(state.account.expiry, state.userInterface.locale) + : undefined, + isOffline: state.connection.isBlocked, +}); +const mapDispatchToProps = (dispatch: ReduxDispatch, props: IAppContext) => { + const account = bindActionCreators(accountActions, dispatch); + return { + // Changes login method from "new_account" to "existing_account" + hideWelcomeView: () => account.loggedIn(), + onExternalLinkWithAuth: (url: string) => props.app.openLinkWithAuth(url), + }; +}; + +export default withAppContext(connect(mapStateToProps, mapDispatchToProps)(NewAccountView)); |
