summaryrefslogtreecommitdiffhomepage
path: root/gui/src/shared/notifications
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/shared/notifications
parent63193938c1c5719e06eae51f8d213af55125a2de (diff)
downloadmullvadvpn-1f54942ca8da86efeb64b174dcceecdd9e48a85c.tar.xz
mullvadvpn-1f54942ca8da86efeb64b174dcceecdd9e48a85c.zip
Refactor AccountExpiry
Diffstat (limited to 'gui/src/shared/notifications')
-rw-r--r--gui/src/shared/notifications/accountExpiry.ts17
1 files changed, 10 insertions, 7 deletions
diff --git a/gui/src/shared/notifications/accountExpiry.ts b/gui/src/shared/notifications/accountExpiry.ts
index b749fb55c1..db536c7405 100644
--- a/gui/src/shared/notifications/accountExpiry.ts
+++ b/gui/src/shared/notifications/accountExpiry.ts
@@ -2,7 +2,7 @@ import moment from 'moment';
import { sprintf } from 'sprintf-js';
import { links } from '../../config.json';
import { messages } from '../../shared/gettext';
-import AccountExpiry from '../account-expiry';
+import { hasExpired, formatRemainingTime } from '../account-expiry';
import {
InAppNotification,
InAppNotificationProvider,
@@ -11,7 +11,8 @@ import {
} from './notification';
interface AccountExpiryContext {
- accountExpiry: AccountExpiry;
+ accountExpiry: string;
+ locale: string;
tooSoon?: boolean;
}
@@ -20,10 +21,12 @@ export class AccountExpiryNotificationProvider
public constructor(private context: AccountExpiryContext) {}
public mayDisplay() {
+ const willHaveExpiredInThreeDays = moment(this.context.accountExpiry).isSameOrBefore(
+ moment().add(3, 'days'),
+ );
+
return (
- !this.context.accountExpiry.hasExpired() &&
- this.context.accountExpiry.willHaveExpiredAt(moment().add(3, 'days').toDate()) &&
- !this.context.tooSoon
+ !hasExpired(this.context.accountExpiry) && willHaveExpiredInThreeDays && !this.context.tooSoon
);
}
@@ -34,7 +37,7 @@ export class AccountExpiryNotificationProvider
// TRANSLATORS: %(duration)s - remaining time, e.g. "2 days"
messages.pgettext('notifications', 'Account credit expires in %(duration)s'),
{
- duration: this.context.accountExpiry.remainingTime(),
+ duration: formatRemainingTime(this.context.accountExpiry, this.context.locale),
},
);
@@ -49,7 +52,7 @@ export class AccountExpiryNotificationProvider
return {
indicator: 'warning',
title: messages.pgettext('in-app-notifications', 'ACCOUNT CREDIT EXPIRES SOON'),
- subtitle: this.context.accountExpiry.remainingTime(true),
+ subtitle: formatRemainingTime(this.context.accountExpiry, this.context.locale, true),
action: { type: 'open-url', url: links.purchase, withAuth: true },
};
}