diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-06-05 17:06:47 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-06-12 15:58:20 +0200 |
| commit | 70cf899e378875970050b4fd84ffe7e4973d8dc3 (patch) | |
| tree | d050755f406dc1d537095c71e7b507780e492548 /app/components | |
| parent | ab6dc0a7af2bde75bf361c185f48ba38c05cc564 (diff) | |
| download | mullvadvpn-70cf899e378875970050b4fd84ffe7e4973d8dc3.tar.xz mullvadvpn-70cf899e378875970050b4fd84ffe7e4973d8dc3.zip | |
Update account expiry when showing the account details
Diffstat (limited to 'app/components')
| -rw-r--r-- | app/components/Account.js | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/app/components/Account.js b/app/components/Account.js index b4eef86712..74c7d99629 100644 --- a/app/components/Account.js +++ b/app/components/Account.js @@ -1,6 +1,6 @@ // @flow import moment from 'moment'; -import React from 'react'; +import * as React from 'react'; import { Component, Text, View } from 'reactxp'; import { Button, RedButton, GreenButton, Label } from './styled'; import { Layout, Container } from './Layout'; @@ -8,21 +8,40 @@ import styles from './AccountStyles'; import Img from './Img'; import { formatAccount } from '../lib/formatters'; -import type { AccountReduxState } from '../redux/account/reducers'; +import type { AccountToken } from '../lib/ipc-facade'; export type AccountProps = { - account: AccountReduxState, + accountToken: AccountToken, + accountExpiry: string, + updateAccountExpiry: () => Promise<void>, onLogout: () => void, onClose: () => void, onBuyMore: () => void, }; -export default class Account extends Component { - props: AccountProps; +export type AccountState = { + isRefreshingExpiry: boolean, +}; + +export default class Account extends Component<AccountProps, AccountState> { + state = { + isRefreshingExpiry: false, + }; + + _isMounted = false; + + componentDidMount() { + this._isMounted = true; + this._refreshAccountExpiry(); + } + + componentWillUnmount() { + this._isMounted = false; + } render() { - const expiry = moment(this.props.account.expiry); - const formattedAccountToken = formatAccount(this.props.account.accountToken || ''); + const expiry = moment(this.props.accountExpiry); + const formattedAccountToken = formatAccount(this.props.accountToken || ''); const formattedExpiry = expiry.format('hA, D MMMM YYYY').toUpperCase(); const isOutOfTime = expiry.isSameOrBefore(moment()); @@ -81,4 +100,18 @@ export default class Account extends Component { </Layout> ); } + + async _refreshAccountExpiry() { + this.setState({ isRefreshingExpiry: true }); + + try { + await this.props.updateAccountExpiry(); + } catch (e) { + // TODO: Report the error to user + } + + if (this._isMounted) { + this.setState({ isRefreshingExpiry: false }); + } + } } |
