summaryrefslogtreecommitdiffhomepage
path: root/gui/src/renderer
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2020-06-15 20:11:24 +0200
committerOskar Nyberg <oskar@mullvad.net>2020-06-24 11:23:07 +0200
commit1f54942ca8da86efeb64b174dcceecdd9e48a85c (patch)
treef1187dd93e4e6cb1f6ee1c91e87e101a7031694b /gui/src/renderer
parent63193938c1c5719e06eae51f8d213af55125a2de (diff)
downloadmullvadvpn-1f54942ca8da86efeb64b174dcceecdd9e48a85c.tar.xz
mullvadvpn-1f54942ca8da86efeb64b174dcceecdd9e48a85c.zip
Refactor AccountExpiry
Diffstat (limited to 'gui/src/renderer')
-rw-r--r--gui/src/renderer/components/Account.tsx8
-rw-r--r--gui/src/renderer/components/Connect.tsx6
-rw-r--r--gui/src/renderer/components/ExpiredAccountErrorView.tsx6
-rw-r--r--gui/src/renderer/components/NotificationArea.tsx10
-rw-r--r--gui/src/renderer/components/Settings.tsx11
-rw-r--r--gui/src/renderer/containers/ConnectPage.tsx5
-rw-r--r--gui/src/renderer/containers/ExpiredAccountErrorViewContainer.tsx5
7 files changed, 19 insertions, 32 deletions
diff --git a/gui/src/renderer/components/Account.tsx b/gui/src/renderer/components/Account.tsx
index 352ed1dad3..3d344887bd 100644
--- a/gui/src/renderer/components/Account.tsx
+++ b/gui/src/renderer/components/Account.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import AccountExpiry from '../../shared/account-expiry';
+import { formatDate, hasExpired } from '../../shared/account-expiry';
import { messages } from '../../shared/gettext';
import {
AccountContainer,
@@ -97,14 +97,12 @@ export default class Account extends React.Component<IProps> {
function FormattedAccountExpiry(props: { expiry?: string; locale: string }) {
if (props.expiry) {
- const expiry = new AccountExpiry(props.expiry, props.locale);
-
- if (expiry.hasExpired()) {
+ if (hasExpired(props.expiry)) {
return (
<AccountOutOfTime>{messages.pgettext('account-view', 'OUT OF TIME')}</AccountOutOfTime>
);
} else {
- return <AccountRowValue>{expiry.formattedDate()}</AccountRowValue>;
+ return <AccountRowValue>{formatDate(props.expiry, props.locale)}</AccountRowValue>;
}
} else {
return (
diff --git a/gui/src/renderer/components/Connect.tsx b/gui/src/renderer/components/Connect.tsx
index b57c63a273..636f445bc1 100644
--- a/gui/src/renderer/components/Connect.tsx
+++ b/gui/src/renderer/components/Connect.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
import { Component, Styles, View } from 'reactxp';
import styled from 'styled-components';
-import AccountExpiry from '../../shared/account-expiry';
+import { hasExpired } from '../../shared/account-expiry';
import ExpiredAccountErrorViewContainer from '../containers/ExpiredAccountErrorViewContainer';
import NotificationArea from '../components/NotificationArea';
import { AuthFailureKind, parseAuthFailure } from '../../shared/auth-failure';
@@ -17,7 +17,7 @@ import TunnelControl from './TunnelControl';
interface IProps {
connection: IConnectionReduxState;
loginState: LoginState;
- accountExpiry?: AccountExpiry;
+ accountExpiry?: string;
blockWhenDisconnected: boolean;
selectedRelayName: string;
onSettings: () => void;
@@ -135,7 +135,7 @@ export default class Connect extends Component<IProps, IState> {
// Use the account expiry to deduce the account state
if (this.props.accountExpiry) {
- return this.props.accountExpiry.hasExpired();
+ return hasExpired(this.props.accountExpiry);
}
// Do not assume that the account hasn't expired if the expiry is not available at the moment
diff --git a/gui/src/renderer/components/ExpiredAccountErrorView.tsx b/gui/src/renderer/components/ExpiredAccountErrorView.tsx
index 61140016ea..0854f0ace2 100644
--- a/gui/src/renderer/components/ExpiredAccountErrorView.tsx
+++ b/gui/src/renderer/components/ExpiredAccountErrorView.tsx
@@ -2,7 +2,7 @@ import * as React from 'react';
import { Component, Text, View } from 'reactxp';
import { sprintf } from 'sprintf-js';
import { links } from '../../config.json';
-import AccountExpiry from '../../shared/account-expiry';
+import { hasExpired } from '../../shared/account-expiry';
import { AccountToken } from '../../shared/daemon-rpc-types';
import { messages } from '../../shared/gettext';
import { LoginState } from '../redux/account/reducers';
@@ -29,7 +29,7 @@ interface IExpiredAccountErrorViewProps {
isBlocked: boolean;
blockWhenDisconnected: boolean;
accountToken?: AccountToken;
- accountExpiry?: AccountExpiry;
+ accountExpiry?: string;
loginState: LoginState;
hideWelcomeView: () => void;
onExternalLinkWithAuth: (url: string) => Promise<void>;
@@ -52,7 +52,7 @@ export default class ExpiredAccountErrorView extends Component<
};
public componentDidUpdate() {
- if (this.props.accountExpiry && !this.props.accountExpiry.hasExpired()) {
+ if (this.props.accountExpiry && !hasExpired(this.props.accountExpiry)) {
this.props.hideWelcomeView();
}
}
diff --git a/gui/src/renderer/components/NotificationArea.tsx b/gui/src/renderer/components/NotificationArea.tsx
index bc76ba0885..89d742df0a 100644
--- a/gui/src/renderer/components/NotificationArea.tsx
+++ b/gui/src/renderer/components/NotificationArea.tsx
@@ -3,7 +3,6 @@ import log from 'electron-log';
import React, { useCallback } from 'react';
import { useSelector } from 'react-redux';
import { Types } from 'reactxp';
-import AccountExpiry from '../../shared/account-expiry';
import {
AccountExpiryNotificationProvider,
BlockWhenDisconnectedNotificationProvider,
@@ -33,11 +32,8 @@ interface IProps {
}
export default function NotificationArea(props: IProps) {
- const accountExpiry = useSelector((state: IReduxState) =>
- state.account.expiry
- ? new AccountExpiry(state.account.expiry, state.userInterface.locale)
- : undefined,
- );
+ const accountExpiry = useSelector((state: IReduxState) => state.account.expiry);
+ const locale = useSelector((state: IReduxState) => state.userInterface.locale);
const tunnelState = useSelector((state: IReduxState) => state.connection.status);
const version = useSelector((state: IReduxState) => state.version);
const blockWhenDisconnected = useSelector(
@@ -55,7 +51,7 @@ export default function NotificationArea(props: IProps) {
];
if (accountExpiry) {
- notificationProviders.push(new AccountExpiryNotificationProvider({ accountExpiry }));
+ notificationProviders.push(new AccountExpiryNotificationProvider({ accountExpiry, locale }));
}
const notificationProvider = notificationProviders.find((notification) =>
diff --git a/gui/src/renderer/components/Settings.tsx b/gui/src/renderer/components/Settings.tsx
index 4a7684f405..f01bfd7036 100644
--- a/gui/src/renderer/components/Settings.tsx
+++ b/gui/src/renderer/components/Settings.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
import { Component, Text, View } from 'reactxp';
import { colors, links } from '../../config.json';
-import AccountExpiry from '../../shared/account-expiry';
+import { hasExpired, formatRemainingTime } from '../../shared/account-expiry';
import { messages } from '../../shared/gettext';
import * as AppButton from './AppButton';
import * as Cell from './Cell';
@@ -102,11 +102,10 @@ export default class Settings extends Component<IProps> {
return null;
}
- const expiry = this.props.accountExpiry
- ? new AccountExpiry(this.props.accountExpiry, this.props.expiryLocale)
- : null;
- const isOutOfTime = expiry ? expiry.hasExpired() : false;
- const formattedExpiry = expiry ? expiry.remainingTime().toUpperCase() : '';
+ const isOutOfTime = this.props.accountExpiry ? hasExpired(this.props.accountExpiry) : false;
+ const formattedExpiry = this.props.accountExpiry
+ ? formatRemainingTime(this.props.accountExpiry, this.props.expiryLocale).toUpperCase()
+ : '';
const outOfTimeMessage = messages.pgettext('settings-view', 'OUT OF TIME');
diff --git a/gui/src/renderer/containers/ConnectPage.tsx b/gui/src/renderer/containers/ConnectPage.tsx
index 4ba47f7511..57f550d988 100644
--- a/gui/src/renderer/containers/ConnectPage.tsx
+++ b/gui/src/renderer/containers/ConnectPage.tsx
@@ -3,7 +3,6 @@ import log from 'electron-log';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { sprintf } from 'sprintf-js';
-import AccountExpiry from '../../shared/account-expiry';
import { messages } from '../../shared/gettext';
import Connect from '../components/Connect';
import withAppContext, { IAppContext } from '../context';
@@ -65,9 +64,7 @@ function getRelayName(
const mapStateToProps = (state: IReduxState) => {
return {
- accountExpiry: state.account.expiry
- ? new AccountExpiry(state.account.expiry, state.userInterface.locale)
- : undefined,
+ accountExpiry: state.account.expiry,
loginState: state.account.status,
blockWhenDisconnected: state.settings.blockWhenDisconnected,
selectedRelayName: getRelayName(state.settings.relaySettings, state.settings.relayLocations),
diff --git a/gui/src/renderer/containers/ExpiredAccountErrorViewContainer.tsx b/gui/src/renderer/containers/ExpiredAccountErrorViewContainer.tsx
index 2c4ca2e6dd..dcdc862355 100644
--- a/gui/src/renderer/containers/ExpiredAccountErrorViewContainer.tsx
+++ b/gui/src/renderer/containers/ExpiredAccountErrorViewContainer.tsx
@@ -1,7 +1,6 @@
import log from 'electron-log';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
-import AccountExpiry from '../../shared/account-expiry';
import ExpiredAccountErrorView from '../components/ExpiredAccountErrorView';
import accountActions from '../redux/account/actions';
@@ -10,9 +9,7 @@ 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,
+ accountExpiry: state.account.expiry,
loginState: state.account.status,
isBlocked: state.connection.isBlocked,
blockWhenDisconnected: state.settings.blockWhenDisconnected,