From 85797982eddc51150ae2f8371f27a13b449dabc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyauheni-kryzhyk-deriv=E2=80=9D?= <“yauheni@deriv.me”> Date: Mon, 27 Mar 2023 17:01:09 +0300 Subject: [PATCH 1/4] refactor: accountclosed ts migration --- ...{account-closed.jsx => account-closed.tsx} | 27 +++++++++++-------- .../Sections/Security/AccountClosed/index.js | 3 --- .../Sections/Security/AccountClosed/index.ts | 3 +++ 3 files changed, 19 insertions(+), 14 deletions(-) rename packages/account/src/Sections/Security/AccountClosed/{account-closed.jsx => account-closed.tsx} (84%) delete mode 100644 packages/account/src/Sections/Security/AccountClosed/index.js create mode 100644 packages/account/src/Sections/Security/AccountClosed/index.ts diff --git a/packages/account/src/Sections/Security/AccountClosed/account-closed.jsx b/packages/account/src/Sections/Security/AccountClosed/account-closed.tsx similarity index 84% rename from packages/account/src/Sections/Security/AccountClosed/account-closed.jsx rename to packages/account/src/Sections/Security/AccountClosed/account-closed.tsx index d3e553109ee5..711136165d42 100644 --- a/packages/account/src/Sections/Security/AccountClosed/account-closed.jsx +++ b/packages/account/src/Sections/Security/AccountClosed/account-closed.tsx @@ -3,21 +3,17 @@ import { Modal, Text } from '@deriv/components'; import { Localize } from '@deriv/translations'; import { getStaticUrl, PlatformContext } from '@deriv/shared'; import { connect } from 'Stores/connect'; +import RootStore from 'Stores/index'; -const AccountClosed = ({ logout }) => { +type TAccountClosed = { + logout: () => void; +}; + +const AccountClosed = ({ logout }: TAccountClosed) => { const [is_modal_open, setModalState] = React.useState(true); const [timer, setTimer] = React.useState(10); const { is_appstore } = React.useContext(PlatformContext); - React.useEffect(() => { - window.history.pushState(null, null, '/'); - logout(); - const handleInterval = setInterval(() => counter(), 1000); - return () => { - if (handleInterval) clearInterval(handleInterval); - }; - }, [timer, is_modal_open, logout, counter]); - const counter = React.useCallback(() => { if (timer > 0) { setTimer(timer - 1); @@ -26,6 +22,15 @@ const AccountClosed = ({ logout }) => { } }, [is_appstore, timer]); + React.useEffect(() => { + window.history.pushState(null, '', '/'); + logout(); + const handleInterval = setInterval(() => counter(), 1000); + return () => { + if (handleInterval) clearInterval(handleInterval); + }; + }, [timer, is_modal_open, logout, counter]); + return ( { ); }; -export default connect(({ client }) => ({ +export default connect(({ client }: RootStore) => ({ logout: client.logout, }))(AccountClosed); diff --git a/packages/account/src/Sections/Security/AccountClosed/index.js b/packages/account/src/Sections/Security/AccountClosed/index.js deleted file mode 100644 index 2bd0b89a2d3b..000000000000 --- a/packages/account/src/Sections/Security/AccountClosed/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import AccountClosed from './account-closed.jsx'; - -export default AccountClosed; diff --git a/packages/account/src/Sections/Security/AccountClosed/index.ts b/packages/account/src/Sections/Security/AccountClosed/index.ts new file mode 100644 index 000000000000..4b50331936e9 --- /dev/null +++ b/packages/account/src/Sections/Security/AccountClosed/index.ts @@ -0,0 +1,3 @@ +import AccountClosed from './account-closed'; + +export default AccountClosed; From 6001c86d78d8b775ff949e76c4e76357d98cbe1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyauheni-kryzhyk-deriv=E2=80=9D?= <“yauheni@deriv.me”> Date: Tue, 28 Mar 2023 11:51:48 +0300 Subject: [PATCH 2/4] refactor: types replaced --- packages/account/package.json | 1 + .../src/Sections/Security/AccountClosed/account-closed.tsx | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/account/package.json b/packages/account/package.json index 3ab4a4eadc71..4d8eafb94353 100644 --- a/packages/account/package.json +++ b/packages/account/package.json @@ -31,6 +31,7 @@ "@deriv/api-types": "^1.0.11", "@deriv/components": "^1.0.0", "@deriv/shared": "^1.0.0", + "@deriv/stores": "^1.0.0", "@deriv/translations": "^1.0.0", "bowser": "^2.9.0", "classnames": "^2.2.6", diff --git a/packages/account/src/Sections/Security/AccountClosed/account-closed.tsx b/packages/account/src/Sections/Security/AccountClosed/account-closed.tsx index 711136165d42..1027c9854030 100644 --- a/packages/account/src/Sections/Security/AccountClosed/account-closed.tsx +++ b/packages/account/src/Sections/Security/AccountClosed/account-closed.tsx @@ -3,7 +3,7 @@ import { Modal, Text } from '@deriv/components'; import { Localize } from '@deriv/translations'; import { getStaticUrl, PlatformContext } from '@deriv/shared'; import { connect } from 'Stores/connect'; -import RootStore from 'Stores/index'; +import type { TRootStore } from '@deriv/stores/types'; type TAccountClosed = { logout: () => void; @@ -45,6 +45,6 @@ const AccountClosed = ({ logout }: TAccountClosed) => { ); }; -export default connect(({ client }: RootStore) => ({ +export default connect(({ client }: TRootStore) => ({ logout: client.logout, }))(AccountClosed); From 75ac491f8efb45c381c1b58cdd961cd6590d5d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyauheni-kryzhyk-deriv=E2=80=9D?= <“yauheni@deriv.me”> Date: Tue, 28 Mar 2023 12:37:11 +0300 Subject: [PATCH 3/4] refactor: pushState replaced with history.push --- .../src/Sections/Security/AccountClosed/account-closed.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/account/src/Sections/Security/AccountClosed/account-closed.tsx b/packages/account/src/Sections/Security/AccountClosed/account-closed.tsx index 1027c9854030..3f7c52d2ec1a 100644 --- a/packages/account/src/Sections/Security/AccountClosed/account-closed.tsx +++ b/packages/account/src/Sections/Security/AccountClosed/account-closed.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import { useHistory } from 'react-router-dom'; import { Modal, Text } from '@deriv/components'; import { Localize } from '@deriv/translations'; import { getStaticUrl, PlatformContext } from '@deriv/shared'; @@ -13,6 +14,7 @@ const AccountClosed = ({ logout }: TAccountClosed) => { const [is_modal_open, setModalState] = React.useState(true); const [timer, setTimer] = React.useState(10); const { is_appstore } = React.useContext(PlatformContext); + const history = useHistory(); const counter = React.useCallback(() => { if (timer > 0) { @@ -23,7 +25,7 @@ const AccountClosed = ({ logout }: TAccountClosed) => { }, [is_appstore, timer]); React.useEffect(() => { - window.history.pushState(null, '', '/'); + history.push('/'); logout(); const handleInterval = setInterval(() => counter(), 1000); return () => { From 7559c046e5279f65e26ba92a0f23169210596845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyauheni-kryzhyk-deriv=E2=80=9D?= <“yauheni@deriv.me”> Date: Tue, 28 Mar 2023 13:44:56 +0300 Subject: [PATCH 4/4] refactor: routes root usage added --- .../src/Sections/Security/AccountClosed/account-closed.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/account/src/Sections/Security/AccountClosed/account-closed.tsx b/packages/account/src/Sections/Security/AccountClosed/account-closed.tsx index 3f7c52d2ec1a..068fdbe42e59 100644 --- a/packages/account/src/Sections/Security/AccountClosed/account-closed.tsx +++ b/packages/account/src/Sections/Security/AccountClosed/account-closed.tsx @@ -1,8 +1,8 @@ import React from 'react'; import { useHistory } from 'react-router-dom'; import { Modal, Text } from '@deriv/components'; +import { routes, getStaticUrl, PlatformContext } from '@deriv/shared'; import { Localize } from '@deriv/translations'; -import { getStaticUrl, PlatformContext } from '@deriv/shared'; import { connect } from 'Stores/connect'; import type { TRootStore } from '@deriv/stores/types'; @@ -25,7 +25,7 @@ const AccountClosed = ({ logout }: TAccountClosed) => { }, [is_appstore, timer]); React.useEffect(() => { - history.push('/'); + history.push(routes.root); logout(); const handleInterval = setInterval(() => counter(), 1000); return () => {