From 437358f780d973e38c1f4d893143e35637eddf4b Mon Sep 17 00:00:00 2001 From: Michal Zielenkiewicz Date: Tue, 29 Aug 2023 12:02:01 +0200 Subject: [PATCH 1/5] Create NewExtensionWarning component --- src/assets/images/warning.svg | 10 +++++++ src/i18n/en.json | 6 ++++- src/i18n/zh_CN.json | 5 +++- .../component/NewExtensionWarning/index.js | 21 +++++++++++++++ .../component/NewExtensionWarning/index.scss | 26 +++++++++++++++++++ 5 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 src/assets/images/warning.svg create mode 100644 src/popup/component/NewExtensionWarning/index.js create mode 100644 src/popup/component/NewExtensionWarning/index.scss diff --git a/src/assets/images/warning.svg b/src/assets/images/warning.svg new file mode 100644 index 00000000..10bf1626 --- /dev/null +++ b/src/assets/images/warning.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/i18n/en.json b/src/i18n/en.json index bc98ddff..371a9f3f 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -287,5 +287,9 @@ "withdrawTitle":"Withdraw", "withdrawToAddress":"Withdraw Address", - "withdrawInfo":"Withdraw Info" + "withdrawInfo":"Withdraw Info", + + "warning": "Warning", + "newExtensionNotice": "Your mnemonic will no longer be stored in the new version of the wallet extension. You'll be able to backup your mnemonic again before we stop storing it.", + "remindMe": "Remind me later" } diff --git a/src/i18n/zh_CN.json b/src/i18n/zh_CN.json index 0aeaa85e..e0397a8d 100644 --- a/src/i18n/zh_CN.json +++ b/src/i18n/zh_CN.json @@ -279,6 +279,9 @@ "withdrawTitle":"提现", "withdrawToAddress":"提现地址", - "withdrawInfo":"提现信息" + "withdrawInfo":"提现信息", + "warning": "警告", + "newExtensionNotice": "您的助记词将不再存储在新版本的钱包扩展中。在我们停止存储助记词之前,您可以再次备份助记词。", + "remindMe": "稍后提醒我" } diff --git a/src/popup/component/NewExtensionWarning/index.js b/src/popup/component/NewExtensionWarning/index.js new file mode 100644 index 00000000..9f67b13d --- /dev/null +++ b/src/popup/component/NewExtensionWarning/index.js @@ -0,0 +1,21 @@ +import warningIconSrc from '../../../assets/images/warning.svg'; +import { getLanguage } from '../../../i18n'; +import './index.scss'; + +export const NewExtensionWarning = () => { + return ( +
+
+ {getLanguage('warning')} +
+
+ {getLanguage('newExtensionNotice')} +
+ +
+
+
+ ); +}; diff --git a/src/popup/component/NewExtensionWarning/index.scss b/src/popup/component/NewExtensionWarning/index.scss new file mode 100644 index 00000000..e3b32880 --- /dev/null +++ b/src/popup/component/NewExtensionWarning/index.scss @@ -0,0 +1,26 @@ +.indicator { + display: flex; + padding: 10px 5px; + justify-content: center; + align-items: flex-start; + gap: 10px; + background: #fcf1d0; + + &-content { + color: #06152b; + font-size: 14px; + font-style: normal; + font-weight: 500; + line-height: 125%; + } + + &-reminder { + background-color: transparent; + border: 0; + padding: 0; + margin: 0; + cursor: pointer; + font: inherit; + color: #0092f6; + } +} From b6377be2aa95cc1076457e9356393f90d091efec Mon Sep 17 00:00:00 2001 From: Michal Zielenkiewicz Date: Tue, 29 Aug 2023 11:39:13 +0200 Subject: [PATCH 2/5] Show new extension warning --- src/popup/pages/Lock/index.js | 4 ++++ src/popup/pages/Wallet/index.js | 4 ++++ src/popup/pages/Welcome/index.js | 2 ++ src/popup/pages/Welcome/index.scss | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/popup/pages/Lock/index.js b/src/popup/pages/Lock/index.js index eedf21a7..58394353 100644 --- a/src/popup/pages/Lock/index.js +++ b/src/popup/pages/Lock/index.js @@ -20,6 +20,7 @@ import CustomView from "../../component/CustomView"; import TestModal from "../../component/TestModal"; import TextInput from "../../component/TextInput"; import Toast from "../../component/Toast"; +import { NewExtensionWarning } from "../../component/NewExtensionWarning" import "./index.scss"; class LockPage extends React.Component { constructor(props) { @@ -230,6 +231,9 @@ class LockPage extends React.Component { isReceive={true} history={this.props.history}>
+
+ +
diff --git a/src/popup/pages/Wallet/index.js b/src/popup/pages/Wallet/index.js index 49d28d61..d5b445e9 100644 --- a/src/popup/pages/Wallet/index.js +++ b/src/popup/pages/Wallet/index.js @@ -24,6 +24,7 @@ import Clock from "../../component/Clock"; import TestModal from "../../component/TestModal"; import Toast from "../../component/Toast"; import WalletBar from "../../component/WalletBar"; +import { NewExtensionWarning } from "../../component/NewExtensionWarning" import "./index.scss"; import oasisIcon from "../../../assets/images/oasisIcon.svg"; import evmIcon from "../../../assets/images/evmIcon.svg"; @@ -650,6 +651,9 @@ class Wallet extends React.Component {
+
+ +
{infoAndHistory} {this.renderChangeModal()} { this.fetchData(this.props.currentAccount.address) }} /> diff --git a/src/popup/pages/Welcome/index.js b/src/popup/pages/Welcome/index.js index 5390ccc9..a5af155b 100644 --- a/src/popup/pages/Welcome/index.js +++ b/src/popup/pages/Welcome/index.js @@ -15,6 +15,7 @@ import { setWelcomeNextRoute } from "../../../reducers/cache"; import { openCurrentRouteInPersistentPopup } from '../../../utils/popup'; import Button from "../../component/Button"; import Select from "../../component/Select"; +import { NewExtensionWarning } from "../../component/NewExtensionWarning" import "./index.scss"; class Welcome extends React.Component { constructor(props) { @@ -82,6 +83,7 @@ class Welcome extends React.Component { render() { return (
+

{"Oasis Wallet"}

diff --git a/src/popup/pages/Welcome/index.scss b/src/popup/pages/Welcome/index.scss index e0fb9027..db0dd4b3 100644 --- a/src/popup/pages/Welcome/index.scss +++ b/src/popup/pages/Welcome/index.scss @@ -8,7 +8,7 @@ } .welcome-button-container { - margin-top: 200px; + margin-top: 150px; width: 100%; text-align: center; } From 01fdaf74bb7f4b75030e2737a38e1dc939c244b6 Mon Sep 17 00:00:00 2001 From: Michal Zielenkiewicz Date: Tue, 29 Aug 2023 12:57:01 +0200 Subject: [PATCH 3/5] Dismiss warning on user action --- src/constant/storageKey.js | 6 ++++++ src/popup/component/NewExtensionWarning/index.js | 11 +++++++++-- src/popup/pages/Lock/index.js | 14 ++++++++++---- src/popup/pages/Wallet/index.js | 13 ++++++++++--- src/popup/pages/Welcome/index.js | 8 ++++++-- src/reducers/appReducer.js | 16 ++++++++++++++++ 6 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/constant/storageKey.js b/src/constant/storageKey.js index 03aa04a9..4a61c8dc 100644 --- a/src/constant/storageKey.js +++ b/src/constant/storageKey.js @@ -18,3 +18,9 @@ export const LANGUAGE_CONFIG = "LANGUAGE_CONFIG" */ export const ADDRESS_BOOK_CONFIG = "ADDRESS_BOOK_CONFIG" + + +/** + * store user decision whether to display the new extension warning + */ +export const NEW_EXTENSION_WARNING_DISMISSED = "NEW_EXTENSION_WARNING_DISMISSED" diff --git a/src/popup/component/NewExtensionWarning/index.js b/src/popup/component/NewExtensionWarning/index.js index 9f67b13d..5b50e6d5 100644 --- a/src/popup/component/NewExtensionWarning/index.js +++ b/src/popup/component/NewExtensionWarning/index.js @@ -1,8 +1,15 @@ import warningIconSrc from '../../../assets/images/warning.svg'; import { getLanguage } from '../../../i18n'; +import { NEW_EXTENSION_WARNING_DISMISSED } from "../../../constant/storageKey"; +import { saveLocal } from "../../../background/storage/localStorage"; import './index.scss'; -export const NewExtensionWarning = () => { +export const NewExtensionWarning = (props) => { + const handleClick = () => { + saveLocal(NEW_EXTENSION_WARNING_DISMISSED, true) + props.handleClick() + } + return (
@@ -11,7 +18,7 @@ export const NewExtensionWarning = () => {
{getLanguage('newExtensionNotice')}
-
diff --git a/src/popup/pages/Lock/index.js b/src/popup/pages/Lock/index.js index 58394353..bcbd39a8 100644 --- a/src/popup/pages/Lock/index.js +++ b/src/popup/pages/Lock/index.js @@ -9,6 +9,7 @@ import { NETWORK_CONFIG } from "../../../constant/storageKey"; import { RESET_WALLET, WALLET_APP_SUBMIT_PWD } from "../../../constant/types"; import { getLanguage } from "../../../i18n"; import { resetWallet } from "../../../reducers"; +import { hideNewExtensionWarning } from "../../../reducers/appReducer"; import { updateCurrentAccount } from "../../../reducers/accountReducer"; import { updateNetConfigList } from "../../../reducers/network"; import { sendMsg } from "../../../utils/commonMsg"; @@ -231,9 +232,11 @@ class LockPage extends React.Component { isReceive={true} history={this.props.history}>
-
- -
+ {this.props.showNewExtensionWarning && ( +
+ +
+ )}
@@ -250,6 +253,7 @@ class LockPage extends React.Component { } const mapStateToProps = (state) => ({ + showNewExtensionWarning: state.appReducer.showNewExtensionWarning, }); function mapDispatchToProps(dispatch) { @@ -263,7 +267,9 @@ function mapDispatchToProps(dispatch) { updateNetConfigList: (config) => { dispatch(updateNetConfigList(config)) }, - + hideNewExtensionWarning: () => { + dispatch(hideNewExtensionWarning()); + }, }; } diff --git a/src/popup/pages/Wallet/index.js b/src/popup/pages/Wallet/index.js index d5b445e9..202887b3 100644 --- a/src/popup/pages/Wallet/index.js +++ b/src/popup/pages/Wallet/index.js @@ -14,6 +14,7 @@ import { getBalance, getRpcNonce, getTransactionList } from "../../../background import { DAPP_ACCOUNT_CONNECT_SITE, DAPP_CHANGE_CONNECTING_ADDRESS, DAPP_DISCONNECT_SITE, DAPP_GET_ALL_APPROVE_ACCOUNT, SEND_PAGE_TYPE_SEND, WALLET_CHANGE_CURRENT_ACCOUNT, WALLET_SEND_RUNTIME_EVM_WITHDRAW } from "../../../constant/types"; import { ACCOUNT_TYPE, TRANSACTION_TYPE } from '../../../constant/walletType'; import { getLanguage } from "../../../i18n"; +import { hideNewExtensionWarning } from "../../../reducers/appReducer"; import { updateAccountTx, updateCurrentAccount, updateNetAccount, updateRpcNonce } from "../../../reducers/accountReducer"; import { setAccountInfo, updateDappConnectList, updateNetConfigRequest, updateSendPageType } from "../../../reducers/cache"; import { updateNetConfigList } from "../../../reducers/network"; @@ -651,9 +652,11 @@ class Wallet extends React.Component {
-
- -
+ {this.props.showNewExtensionWarning && ( +
+ +
+ )} {infoAndHistory} {this.renderChangeModal()} { this.fetchData(this.props.currentAccount.address) }} /> @@ -674,6 +677,7 @@ const mapStateToProps = (state) => ({ dappConnectAccountList: state.cache.dappConnectAccountList, dappConnectAddressList: state.cache.dappConnectAddressList, currentActiveTabUrl: state.cache.currentActiveTabUrl, + showNewExtensionWarning: state.appReducer.showNewExtensionWarning, }); function mapDispatchToProps(dispatch) { @@ -708,6 +712,9 @@ function mapDispatchToProps(dispatch) { updateHomeIndex: (index) => { dispatch(updateHomeIndex(index)); }, + hideNewExtensionWarning: () => { + dispatch(hideNewExtensionWarning()); + }, }; } diff --git a/src/popup/pages/Welcome/index.js b/src/popup/pages/Welcome/index.js index a5af155b..8b253f02 100644 --- a/src/popup/pages/Welcome/index.js +++ b/src/popup/pages/Welcome/index.js @@ -10,7 +10,7 @@ import { getLanguage, languageOption } from "../../../i18n"; -import { setLanguage } from "../../../reducers/appReducer"; +import { setLanguage, hideNewExtensionWarning } from "../../../reducers/appReducer"; import { setWelcomeNextRoute } from "../../../reducers/cache"; import { openCurrentRouteInPersistentPopup } from '../../../utils/popup'; import Button from "../../component/Button"; @@ -83,7 +83,7 @@ class Welcome extends React.Component { render() { return (
- + {this.props.showNewExtensionWarning && }

{"Oasis Wallet"}

@@ -110,6 +110,7 @@ class Welcome extends React.Component { const mapStateToProps = (state) => ({ language: state.appReducer.language, + showNewExtensionWarning: state.appReducer.showNewExtensionWarning, }); function mapDispatchToProps(dispatch) { @@ -120,6 +121,9 @@ function mapDispatchToProps(dispatch) { setWelcomeNextRoute: (nextRoute) => { dispatch(setWelcomeNextRoute(nextRoute)) }, + hideNewExtensionWarning: () => { + dispatch(hideNewExtensionWarning()); + }, }; } diff --git a/src/reducers/appReducer.js b/src/reducers/appReducer.js index 257b8426..435aacd7 100644 --- a/src/reducers/appReducer.js +++ b/src/reducers/appReducer.js @@ -1,6 +1,9 @@ import { DEFAULT_LANGUAGE } from "../../config"; +import { NEW_EXTENSION_WARNING_DISMISSED } from "../constant/storageKey"; +import { getLocal } from "../background/storage/localStorage"; const SET_LANGUAGE = "SET_LANGUAGE" +const HIDE_NEW_EXTENSION_WARNING = "HIDE_NEW_EXTENSION_WARNING" export function setLanguage(language) { @@ -10,8 +13,15 @@ export function setLanguage(language) { }; } +export function hideNewExtensionWarning() { + return { + type: HIDE_NEW_EXTENSION_WARNING + }; +} + const initState = { language: DEFAULT_LANGUAGE, + showNewExtensionWarning: !getLocal(NEW_EXTENSION_WARNING_DISMISSED) }; const appReducer = (state = initState, action) => { @@ -19,8 +29,14 @@ const appReducer = (state = initState, action) => { case SET_LANGUAGE: let language = action.language return { + ...state, language, }; + case HIDE_NEW_EXTENSION_WARNING: + return { + ...state, + showNewExtensionWarning: false, + }; default: return state; } From 586c2822885c7e11dff5dd08d1db99eb421ced74 Mon Sep 17 00:00:00 2001 From: Michal Zielenkiewicz Date: Tue, 29 Aug 2023 13:13:40 +0200 Subject: [PATCH 4/5] Hide dismissing option when release date is close --- config.js | 5 +++++ package.json | 1 + .../component/NewExtensionWarning/index.js | 16 +++++++++++----- src/reducers/appReducer.js | 2 +- yarn.lock | 19 +++++++++++++++++++ 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/config.js b/config.js index c71f63bf..8118b906 100644 --- a/config.js +++ b/config.js @@ -99,3 +99,8 @@ export const network_config = [ }, ] +/** + * Update when release date of new extension is known. + * format: YYYY-MM-DD + */ +export const NEW_EXTENSION_RELEASE_DATE = undefined diff --git a/package.json b/package.json index f10a9e6a..0a8af661 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "bignumber.js": "9.0.1", "bip39": "3.0.2", "classnames": "2.2.6", + "date-fns": "^2.30.0", "ethereumjs-util": "7.1.3", "extensionizer": "1.0.1", "i18next": "19.8.4", diff --git a/src/popup/component/NewExtensionWarning/index.js b/src/popup/component/NewExtensionWarning/index.js index 5b50e6d5..d61c3ee4 100644 --- a/src/popup/component/NewExtensionWarning/index.js +++ b/src/popup/component/NewExtensionWarning/index.js @@ -1,9 +1,13 @@ +import differenceInDays from 'date-fns/differenceInDays' +import { NEW_EXTENSION_RELEASE_DATE } from '../../../../config' import warningIconSrc from '../../../assets/images/warning.svg'; import { getLanguage } from '../../../i18n'; import { NEW_EXTENSION_WARNING_DISMISSED } from "../../../constant/storageKey"; import { saveLocal } from "../../../background/storage/localStorage"; import './index.scss'; +const isDismissingEnabled = NEW_EXTENSION_RELEASE_DATE ? differenceInDays(new Date(NEW_EXTENSION_RELEASE_DATE), new Date()) > 3 : true; + export const NewExtensionWarning = (props) => { const handleClick = () => { saveLocal(NEW_EXTENSION_WARNING_DISMISSED, true) @@ -17,11 +21,13 @@ export const NewExtensionWarning = (props) => {
{getLanguage('newExtensionNotice')} -
- -
+ {isDismissingEnabled && +
+ +
+ }
); diff --git a/src/reducers/appReducer.js b/src/reducers/appReducer.js index 435aacd7..ed96fa9d 100644 --- a/src/reducers/appReducer.js +++ b/src/reducers/appReducer.js @@ -1,4 +1,4 @@ -import { DEFAULT_LANGUAGE } from "../../config"; +import { DEFAULT_LANGUAGE, } from "../../config"; import { NEW_EXTENSION_WARNING_DISMISSED } from "../constant/storageKey"; import { getLocal } from "../background/storage/localStorage"; diff --git a/yarn.lock b/yarn.lock index 9abfe2c1..9c0e7cac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2286,6 +2286,13 @@ dependencies: regenerator-runtime "^0.13.4" +"@babel/runtime@^7.21.0": + version "7.22.11" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.22.11.tgz#7a9ba3bbe406ad6f9e8dd4da2ece453eb23a77a4" + integrity sha512-ee7jVNlWN09+KftVOu9n7S8gQzD/Z6hN/I8VBRXW4P1+Xe7kJGXMwu8vds4aGIMHZnNbdpSWCfZZtinytpcAvA== + dependencies: + regenerator-runtime "^0.14.0" + "@babel/template@^7.10.4", "@babel/template@^7.12.13", "@babel/template@^7.3.3": version "7.12.13" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.12.13.tgz#530265be8a2589dbb37523844c5bcb55947fb327" @@ -6515,6 +6522,13 @@ data-urls@^3.0.2: whatwg-mimetype "^3.0.0" whatwg-url "^11.0.0" +date-fns@^2.30.0: + version "2.30.0" + resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.30.0.tgz#f367e644839ff57894ec6ac480de40cae4b0f4d0" + integrity sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw== + dependencies: + "@babel/runtime" "^7.21.0" + debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.9: version "2.6.9" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" @@ -13200,6 +13214,11 @@ regenerator-runtime@^0.13.4, regenerator-runtime@^0.13.7: resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz#cac2dacc8a1ea675feaabaeb8ae833898ae46f55" integrity sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew== +regenerator-runtime@^0.14.0: + version "0.14.0" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.14.0.tgz#5e19d68eb12d486f797e15a3c6a918f7cec5eb45" + integrity sha512-srw17NI0TUWHuGa5CFGGmhfNIeja30WMBfbslPNhf6JrqQlLN5gcrvig1oqPxiVaXb0oW0XRKtH6Nngs5lKCIA== + regenerator-transform@^0.14.2: version "0.14.5" resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.14.5.tgz#c98da154683671c9c4dcb16ece736517e1b7feb4" From 15730999156549d1015e121130a2fa60671ccfd2 Mon Sep 17 00:00:00 2001 From: Michal Zielenkiewicz Date: Tue, 29 Aug 2023 17:59:05 +0200 Subject: [PATCH 5/5] Control visibility of warning indicator --- src/constant/storageKey.js | 4 +-- .../component/NewExtensionWarning/index.js | 22 +++++++------ src/reducers/appReducer.js | 32 ++++++++++++++++--- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/constant/storageKey.js b/src/constant/storageKey.js index 4a61c8dc..b1f24633 100644 --- a/src/constant/storageKey.js +++ b/src/constant/storageKey.js @@ -21,6 +21,6 @@ export const ADDRESS_BOOK_CONFIG = "ADDRESS_BOOK_CONFIG" /** - * store user decision whether to display the new extension warning + * Date when the user decides to dismiss the new extension warning. */ -export const NEW_EXTENSION_WARNING_DISMISSED = "NEW_EXTENSION_WARNING_DISMISSED" +export const DISMISSED_NEW_EXTENSION_WARNING = "DISMISSED_NEW_EXTENSION_WARNING" diff --git a/src/popup/component/NewExtensionWarning/index.js b/src/popup/component/NewExtensionWarning/index.js index d61c3ee4..76597186 100644 --- a/src/popup/component/NewExtensionWarning/index.js +++ b/src/popup/component/NewExtensionWarning/index.js @@ -1,18 +1,20 @@ -import differenceInDays from 'date-fns/differenceInDays' -import { NEW_EXTENSION_RELEASE_DATE } from '../../../../config' +import differenceInDays from 'date-fns/differenceInDays'; +import { NEW_EXTENSION_RELEASE_DATE } from '../../../../config'; import warningIconSrc from '../../../assets/images/warning.svg'; import { getLanguage } from '../../../i18n'; -import { NEW_EXTENSION_WARNING_DISMISSED } from "../../../constant/storageKey"; -import { saveLocal } from "../../../background/storage/localStorage"; +import { DISMISSED_NEW_EXTENSION_WARNING } from '../../../constant/storageKey'; +import { saveLocal } from '../../../background/storage/localStorage'; import './index.scss'; -const isDismissingEnabled = NEW_EXTENSION_RELEASE_DATE ? differenceInDays(new Date(NEW_EXTENSION_RELEASE_DATE), new Date()) > 3 : true; +const canDismiss = NEW_EXTENSION_RELEASE_DATE + ? differenceInDays(new Date(NEW_EXTENSION_RELEASE_DATE), new Date()) > 3 + : true; export const NewExtensionWarning = (props) => { const handleClick = () => { - saveLocal(NEW_EXTENSION_WARNING_DISMISSED, true) - props.handleClick() - } + saveLocal(DISMISSED_NEW_EXTENSION_WARNING, new Date().toISOString()); + props.handleClick(); + }; return (
@@ -21,13 +23,13 @@ export const NewExtensionWarning = (props) => {
{getLanguage('newExtensionNotice')} - {isDismissingEnabled && + {canDismiss && (
- } + )}
); diff --git a/src/reducers/appReducer.js b/src/reducers/appReducer.js index ed96fa9d..ea21aaf9 100644 --- a/src/reducers/appReducer.js +++ b/src/reducers/appReducer.js @@ -1,6 +1,7 @@ -import { DEFAULT_LANGUAGE, } from "../../config"; -import { NEW_EXTENSION_WARNING_DISMISSED } from "../constant/storageKey"; -import { getLocal } from "../background/storage/localStorage"; +import differenceInDays from 'date-fns/differenceInDays' +import { DEFAULT_LANGUAGE, NEW_EXTENSION_RELEASE_DATE } from "../../config"; +import { DISMISSED_NEW_EXTENSION_WARNING } from "../constant/storageKey"; +import { getLocal, removeLocal } from "../background/storage/localStorage"; const SET_LANGUAGE = "SET_LANGUAGE" const HIDE_NEW_EXTENSION_WARNING = "HIDE_NEW_EXTENSION_WARNING" @@ -19,9 +20,32 @@ export function hideNewExtensionWarning() { }; } +function shouldShowNewExtensionWarning() { + const dismissed = getLocal(DISMISSED_NEW_EXTENSION_WARNING); + if (!dismissed || !NEW_EXTENSION_RELEASE_DATE) { + return !dismissed; + } + + const dismissedDate = new Date(dismissed); + const releaseDate = new Date(NEW_EXTENSION_RELEASE_DATE); + // Always show the warning if the release date is less than or equal to 3 days away + if (differenceInDays(releaseDate, new Date()) <= 3) { + return true; + } + // Show the warning and reset the dismissed date + // if it was set more than two weeks before the release date + if (differenceInDays(releaseDate, dismissedDate) > 14) { + removeLocal(DISMISSED_NEW_EXTENSION_WARNING); + return true; + } + + return false; +} + + const initState = { language: DEFAULT_LANGUAGE, - showNewExtensionWarning: !getLocal(NEW_EXTENSION_WARNING_DISMISSED) + showNewExtensionWarning: shouldShowNewExtensionWarning() }; const appReducer = (state = initState, action) => {