From a59bfda757ab94c923c4d8e9d6c3ad496314c3c6 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 1 Oct 2023 01:59:09 +0800 Subject: [PATCH 1/9] chore(deps): update dependency @types/echarts to v4.9.19 (#110) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 20 ++++---------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 2e7f37db7..0881a7210 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "devDependencies": { "@sentry/webpack-plugin": "2.7.1", "@testing-library/react": "12.1.5", - "@types/echarts": "4.9.18", + "@types/echarts": "4.9.19", "@types/eslint": "7.29.0", "@types/jest": "26.0.24", "@types/node": "16.18.50", diff --git a/yarn.lock b/yarn.lock index a77565d7f..279207d2a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2560,10 +2560,10 @@ resolved "https://registry.yarnpkg.com/@types/deep-freeze-strict/-/deep-freeze-strict-1.1.0.tgz#447a6a2576191344aa42310131dd3df5c41492c4" integrity sha512-fILflsS66kGQ4iIBzYoxuQCWK1wQdy/ooguTofUk0KSxA+G5ZzH8WdU8mf6IU+5cMBW+j9u+eh+7kv63R3O9Tw== -"@types/echarts@4.9.18": - version "4.9.18" - resolved "https://registry.yarnpkg.com/@types/echarts/-/echarts-4.9.18.tgz#6a789192ae7e958e5e11b1efdeab0794a54d0a31" - integrity sha512-Qav4M1i1qmPemMywMnDGIbvIBB/9pdrDKLI1dyMho4Yz/ldCB3ry2zGeH0UhAhgmaoPgwYrCDo8xd1UeByz+rw== +"@types/echarts@4.9.19": + version "4.9.19" + resolved "https://registry.yarnpkg.com/@types/echarts/-/echarts-4.9.19.tgz#6c50ccde9f4458edfc36a9c78f81511ec1853941" + integrity sha512-mtQzTmBFLQ1tyAmP667OTr7oOceyfqHRMa0tkIj9FBOKYY0ggG6OGE4AfUtDw2gOuPEEw4vzD+y0OJWKi1IZHQ== dependencies: "@types/zrender" "*" @@ -2910,23 +2910,11 @@ "@types/react" "*" csstype "^3.0.2" -"@types/three@0.149.0": - version "0.149.0" - resolved "https://registry.yarnpkg.com/@types/three/-/three-0.149.0.tgz#f48c03ffcf35b2d196f3532b51bc845e96f6090e" - integrity sha512-fgNBm9LWc65ER/W0cvoXdC0iMy7Ke9e2CONmEr6Jt8sDSY3sw4DgOubZfmdZ747dkPhbQrgRQAWwDEr2S/7IEg== - dependencies: - "@types/webxr" "*" - "@types/trusted-types@^2.0.2": version "2.0.2" resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-2.0.2.tgz#fc25ad9943bcac11cceb8168db4f275e0e72e756" integrity sha512-F5DIZ36YVLE+PN+Zwws4kJogq47hNgX3Nx6WyDJ3kcplxyke3XIzB8uK5n/Lpm1HBsbGzd6nmGehL8cPekP+Tg== -"@types/webxr@*": - version "0.5.1" - resolved "https://registry.yarnpkg.com/@types/webxr/-/webxr-0.5.1.tgz#4908349419104bd476a4252d04e4c3abb496748d" - integrity sha512-xlFXPfgJR5vIuDefhaHuUM9uUgvPaXB6GKdXy2gdEh8gBWQZ2ul24AJz3foUd8NNKlSTQuWYJpCb1/pL81m1KQ== - "@types/ws@^8.5.1": version "8.5.3" resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.3.tgz#7d25a1ffbecd3c4f2d35068d0b283c037003274d" From becc58f9dae99ea2bb7f7a5f9461f3f982b14bfd Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 10:04:16 +0700 Subject: [PATCH 2/9] chore(deps): update dependency @types/node to v16.18.58 (#111) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 0881a7210..cbabedf19 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "@types/echarts": "4.9.19", "@types/eslint": "7.29.0", "@types/jest": "26.0.24", - "@types/node": "16.18.50", + "@types/node": "16.18.58", "@types/react": "17.0.65", "@types/react-dom": "17.0.20", "@types/react-outside-click-handler": "^1.3.0", diff --git a/yarn.lock b/yarn.lock index 279207d2a..7d2ec28f7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2741,10 +2741,10 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-13.11.0.tgz#390ea202539c61c8fa6ba4428b57e05bc36dc47b" integrity sha512-uM4mnmsIIPK/yeO+42F2RQhGUIs39K2RFmugcJANppXe6J1nvH87PvzPZYpza7Xhhs8Yn9yIAVdLZ84z61+0xQ== -"@types/node@16.18.50": - version "16.18.50" - resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.50.tgz#93003cf0251a2ecd26dad6dc757168d648519805" - integrity sha512-OiDU5xRgYTJ203v4cprTs0RwOCd5c5Zjv+K5P8KSqfiCsB1W3LcamTUMcnQarpq5kOYbhHfSOgIEJvdPyb5xyw== +"@types/node@16.18.58": + version "16.18.58" + resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.58.tgz#bf66f63983104ed57c754f4e84ccaf16f8235adb" + integrity sha512-YGncyA25/MaVtQkjWW9r0EFBukZ+JulsLcVZBlGUfIb96OBMjkoRWwQo5IEWJ8Fj06Go3GHw+bjYDitv6BaGsA== "@types/normalize-package-data@^2.4.0": version "2.4.1" From 2e5634cbee06211e5c343640ef4ea300d04682c2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 12:58:28 +0700 Subject: [PATCH 3/9] chore(deps): update dependency @types/styled-components to v5.1.28 (#112) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index cbabedf19..b660af19a 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@types/react-outside-click-handler": "^1.3.0", "@types/react-router-dom": "5.3.3", "@types/react-test-renderer": "^18.0.0", - "@types/styled-components": "5.1.26", + "@types/styled-components": "5.1.28", "@typescript-eslint/eslint-plugin": "^4.29.0", "@typescript-eslint/parser": "5.62.0", "antd-dayjs-webpack-plugin": "^1.0.6", diff --git a/yarn.lock b/yarn.lock index 7d2ec28f7..6cb83ded4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2901,10 +2901,10 @@ resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.1.tgz#20f18294f797f2209b5f65c8e3b5c8e8261d127c" integrity sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw== -"@types/styled-components@5.1.26": - version "5.1.26" - resolved "https://registry.yarnpkg.com/@types/styled-components/-/styled-components-5.1.26.tgz#5627e6812ee96d755028a98dae61d28e57c233af" - integrity sha512-KuKJ9Z6xb93uJiIyxo/+ksS7yLjS1KzG6iv5i78dhVg/X3u5t1H7juRWqVmodIdz6wGVaIApo1u01kmFRdJHVw== +"@types/styled-components@5.1.28": + version "5.1.28" + resolved "https://registry.yarnpkg.com/@types/styled-components/-/styled-components-5.1.28.tgz#3b86c4d373924ff6976de788843cab445d9ab15b" + integrity sha512-nu0VKNybkjvUqJAXWtRqKd7j3iRUl8GbYSTvZNuIBJcw/HUp1Y4QUXNLlj7gcnRV/t784JnHAlvRnSnE3nPbJA== dependencies: "@types/hoist-non-react-statics" "*" "@types/react" "*" From b0d73bbe6982da0354b8940f133ee463d7ebd389 Mon Sep 17 00:00:00 2001 From: daryl Date: Sat, 7 Oct 2023 13:58:17 +0800 Subject: [PATCH 4/9] feat(typeId): show type id from the property "id" in response (#105) * feat(typeId): show type id from the property "id" in response * feat(typeId): use the same style as code hash --- src/pages/Script/index.tsx | 8 +++----- src/pages/Script/styles.module.scss | 5 +++++ src/pages/Script/types.ts | 3 +-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pages/Script/index.tsx b/src/pages/Script/index.tsx index 907d56bf1..f3a179da1 100644 --- a/src/pages/Script/index.tsx +++ b/src/pages/Script/index.tsx @@ -39,7 +39,7 @@ const scriptHashNameMap = new Map( ) const getScriptInfo = (scriptInfo: ScriptInfo) => { - const { scriptName, scriptType, typeId, codeHash, hashType, capacityOfDeployedCells, capacityOfReferringCells } = + const { scriptName, scriptType, id, codeHash, hashType, capacityOfDeployedCells, capacityOfReferringCells } = scriptInfo const items: OverviewItemData[] = [ { @@ -58,8 +58,7 @@ const getScriptInfo = (scriptInfo: ScriptInfo) => { }, { title: i18n.t('scripts.type_id'), - tooltip: i18n.t('glossary.type_id'), - content: typeId || '-', + content: id ? : '-', }, { title: i18n.t('scripts.code_hash'), @@ -123,10 +122,9 @@ export const ScriptPage = () => { status === 'success' && resp ? toCamelcase>(resp?.data)!.data : ({ - id: 0, + id: '-', scriptName: '', scriptType: '', - typeId: '', codeHash, hashType, capacityOfDeployedCells: '0', diff --git a/src/pages/Script/styles.module.scss b/src/pages/Script/styles.module.scss index a4198a024..3f6f7ea26 100644 --- a/src/pages/Script/styles.module.scss +++ b/src/pages/Script/styles.module.scss @@ -143,3 +143,8 @@ .hashType { text-transform: capitalize; } + +.typeId { + overflow: hidden; + text-overflow: ellipsis; +} diff --git a/src/pages/Script/types.ts b/src/pages/Script/types.ts index 4df243d3a..e3bcee0f4 100644 --- a/src/pages/Script/types.ts +++ b/src/pages/Script/types.ts @@ -1,8 +1,7 @@ export interface ScriptInfo { - id: number + id: string scriptName: string scriptType: string - typeId: string codeHash: string hashType: 'type' | 'data' capacityOfDeployedCells: string From 8d19adc9ee9f820f97ef8bab87d6118d36fe4180 Mon Sep 17 00:00:00 2001 From: WhiteMind Date: Sat, 7 Oct 2023 14:56:54 +0800 Subject: [PATCH 5/9] Refactor: Remove useAppState and the global state it contains, implement in other ways (#103) * refactor: remove statistics and app.tipBlockNumber from AppState * refactor: remove primaryColor, secondaryColor, and chartColor from State.App * refactor: remove language from State.App * refactor: remove toast from State.App * refactor: remove app from AppState * refactor: remove maintenanceAlertVisible from State.Components * refactor: remove headerSearchBarVisible from State.Components * refactor: remove the last global state mobileMenuVisible * feat: remove MaintenanceMsg in the Alert component * feat: stop using the reorgStartedAt property --- package.json | 1 + src/App.tsx | 13 +- src/components/Alert/index.tsx | 78 ---------- src/components/Alert/styled.tsx | 58 ------- src/components/Card/HashCard/index.tsx | 19 +-- src/components/Content/index.tsx | 8 +- src/components/Dropdown/Language/index.tsx | 9 -- .../Header/BlockchainComp/index.tsx | 8 +- src/components/Header/LanguageComp/index.tsx | 52 +------ src/components/Header/MobileMenu/index.tsx | 8 +- src/components/Header/MobileMenu/styled.tsx | 8 +- src/components/Header/SearchComp/index.tsx | 14 +- src/components/Header/index.module.scss | 12 ++ src/components/Header/index.tsx | 141 +++++++++++------- src/components/Header/styled.tsx | 6 - src/components/MaintainAlert/index.tsx | 13 ++ .../styles.module.scss | 0 src/components/Search/index.tsx | 20 +-- src/components/Sheet/index.tsx | 39 ++--- src/components/Sheet/styled.tsx | 31 +--- src/components/Text/CopyTooltipText/index.tsx | 12 +- src/components/Toast/index.tsx | 25 +++- .../TransactionItemCell/index.tsx | 6 +- src/constants/cache.ts | 1 - src/constants/common.ts | 1 - src/contexts/actions/index.ts | 23 --- src/contexts/providers/hook.ts | 43 +----- src/contexts/providers/index.tsx | 28 ---- src/contexts/reducer/app.ts | 73 --------- src/contexts/reducer/component.ts | 37 ----- src/contexts/reducer/index.ts | 30 ---- src/contexts/reducer/page.ts | 20 --- src/contexts/states/app.ts | 26 ---- src/contexts/states/components.ts | 7 - src/contexts/states/index.ts | 14 -- src/contexts/states/statistics.ts | 17 --- src/locales/en.json | 2 - src/locales/zh.json | 2 - src/pages/BlockDetail/BlockComp.tsx | 6 +- src/pages/Home/index.tsx | 44 ++---- src/pages/NervosDao/DaoOverview/index.tsx | 15 +- src/pages/Script/ScriptsComp.tsx | 12 +- src/pages/SimpleUDT/index.tsx | 9 +- .../activities/AddressBalanceRank.tsx | 2 +- .../activities/AddressCount.tsx | 2 +- .../activities/BalanceDistribution.tsx | 2 +- .../StatisticsChart/activities/CellCount.tsx | 2 +- .../activities/TransactionCount.tsx | 2 +- .../activities/TxFeeHistory.tsx | 2 +- .../block/AverageBlockTime.tsx | 2 +- .../block/BlockTimeDistribution.tsx | 2 +- .../block/EpochTimeDistribution.tsx | 2 +- src/pages/StatisticsChart/common/index.tsx | 9 +- .../StatisticsChart/mining/Difficulty.tsx | 2 +- .../mining/DifficultyHashRate.tsx | 2 +- .../mining/DifficultyUncleRateEpoch.tsx | 2 +- src/pages/StatisticsChart/mining/HashRate.tsx | 2 +- .../mining/MinerAddressDistribution.tsx | 2 +- .../mining/MinerVersionDistribution.tsx | 2 +- .../StatisticsChart/mining/UncleRate.tsx | 2 +- .../monetary/AnnualPercentageCompensation.tsx | 2 +- .../monetary/InflationRate.tsx | 2 +- .../StatisticsChart/monetary/Liquidity.tsx | 2 +- .../monetary/SecondaryIssuance.tsx | 2 +- .../StatisticsChart/monetary/TotalSupply.tsx | 2 +- .../nervosDao/CirculationRatio.tsx | 2 +- .../nervosDao/NewDaoDeposit.tsx | 2 +- .../nervosDao/TotalDaoDeposit.tsx | 2 +- .../TransactionCellScript/index.tsx | 28 ++-- src/pages/Transaction/TransactionComp.tsx | 6 +- src/pages/Transaction/index.tsx | 6 - src/routes/index.tsx | 46 +----- src/service/app/address.ts | 16 -- src/service/app/alert.ts | 24 --- src/service/app/blockchain.ts | 31 +--- src/service/app/statistics.ts | 18 --- src/service/http/fetcher.ts | 5 - src/service/http/interceptors.ts | 47 ++---- src/services/ExplorerService/hooks.ts | 10 ++ src/services/ExplorerService/index.ts | 67 +++++++++ src/types/index.d.ts | 57 +------ src/utils/state.ts | 44 ++++++ yarn.lock | 5 + 83 files changed, 426 insertions(+), 1032 deletions(-) delete mode 100644 src/components/Alert/index.tsx delete mode 100644 src/components/Alert/styled.tsx create mode 100644 src/components/MaintainAlert/index.tsx rename src/components/{Alert => MaintainAlert}/styles.module.scss (100%) delete mode 100644 src/contexts/actions/index.ts delete mode 100644 src/contexts/providers/index.tsx delete mode 100644 src/contexts/reducer/app.ts delete mode 100644 src/contexts/reducer/component.ts delete mode 100644 src/contexts/reducer/index.ts delete mode 100644 src/contexts/reducer/page.ts delete mode 100644 src/contexts/states/app.ts delete mode 100644 src/contexts/states/components.ts delete mode 100644 src/contexts/states/index.ts delete mode 100644 src/contexts/states/statistics.ts delete mode 100644 src/service/app/address.ts delete mode 100644 src/service/app/alert.ts delete mode 100644 src/service/app/statistics.ts create mode 100644 src/services/ExplorerService/hooks.ts create mode 100644 src/services/ExplorerService/index.ts create mode 100644 src/utils/state.ts diff --git a/package.json b/package.json index b660af19a..866ed5a75 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "jsbi": "3.2.5", "lint-staged": "^13.2.3", "moment": "2.29.4", + "observable-hooks": "^4.2.3", "react": "17.0.2", "react-dom": "17.0.2", "react-i18next": "11.18.6", diff --git a/src/App.tsx b/src/App.tsx index 15c2baa65..98e98e535 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,10 +4,10 @@ import { ThemeProvider } from 'styled-components' import 'antd/dist/antd.css' import Routers from './routes' import Toast from './components/Toast' -import withProviders, { useAppState } from './contexts/providers' import useInitApp from './contexts/providers/hook' import { isMainnet } from './utils/chain' import { DASQueryContextProvider } from './contexts/providers/dasQuery' +import { getPrimaryColor, getSecondaryColor } from './constants/common' const appStyle = { width: '100vw', @@ -17,15 +17,14 @@ const appStyle = { const queryClient = new QueryClient() -const App = withProviders(() => { +const App = () => { useInitApp() - const { app } = useAppState() const theme = useMemo( () => ({ - primary: app.primaryColor, - secondary: app.secondaryColor, + primary: getPrimaryColor(), + secondary: getSecondaryColor(), }), - [app.primaryColor, app.secondaryColor], + [], ) return ( @@ -40,6 +39,6 @@ const App = withProviders(() => { ) -}) +} export default App diff --git a/src/components/Alert/index.tsx b/src/components/Alert/index.tsx deleted file mode 100644 index 1632c9b75..000000000 --- a/src/components/Alert/index.tsx +++ /dev/null @@ -1,78 +0,0 @@ -import { useEffect } from 'react' -import { useAppState, useDispatch } from '../../contexts/providers' -import { AlertPanel } from './styled' -import i18n, { currentLanguage } from '../../utils/i18n' -import { dayjs, parseSimpleDateNoSecond } from '../../utils/date' -import SimpleButton from '../SimpleButton' -import { ComponentActions } from '../../contexts/actions' -import { AppCachedKeys } from '../../constants/cache' -import { IS_MAINTAINING } from '../../constants/common' -import styles from './styles.module.scss' - -const FIFTEEN_MINUTES = 15 * 60 * 1000 - -const Alert = () => { - const dispatch = useDispatch() - const { - app: { appErrors }, - components: { maintenanceAlertVisible }, - statistics: { reorgStartedAt }, - } = useAppState() - const [startTime, endTime] = appErrors[2].message - - const hideAlert = () => { - sessionStorage.setItem(AppCachedKeys.MaintenanceAlert, 'hide') - dispatch({ - type: ComponentActions.UpdateMaintenanceAlertVisible, - payload: { - maintenanceAlertVisible: false, - }, - }) - } - - useEffect(() => { - const hideMaintenance = sessionStorage.getItem(AppCachedKeys.MaintenanceAlert) === 'hide' - if (startTime && endTime && !hideMaintenance) { - dispatch({ - type: ComponentActions.UpdateMaintenanceAlertVisible, - payload: { - maintenanceAlertVisible: true, - }, - }) - } - }, [startTime, endTime, dispatch]) - - if (reorgStartedAt && new Date(reorgStartedAt).getTime() + FIFTEEN_MINUTES < new Date().getTime()) { - return ( -
- {i18n.t('toast.handling-reorg', { - time: dayjs(reorgStartedAt).format('YYYY-MM-DD HH:mm:ss'), - })} -
- ) - } - - if (IS_MAINTAINING) { - return
{i18n.t('error.maintain')}
- } - - return maintenanceAlertVisible ? ( - -
- - {i18n.t('toast.maintenance', { - start: parseSimpleDateNoSecond(startTime, '-', false), - end: parseSimpleDateNoSecond(endTime, '-', false), - })} - -
- hideAlert()}> - {i18n.t('toast.dismiss')} - -
-
-
- ) : null -} - -export default Alert diff --git a/src/components/Alert/styled.tsx b/src/components/Alert/styled.tsx deleted file mode 100644 index b840dac59..000000000 --- a/src/components/Alert/styled.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import styled from 'styled-components' - -export const AlertPanel = styled.div` - position: sticky; - top: 0; - z-index: 9000; - - > div { - width: 100%; - height: 48px; - background: #fa8f00; - display: flex; - flex-direction: row; - align-items: center; - justify-content: space-between; - padding: 0 120px; - color: white; - font-size: 14px; - font-weight: 450; - - @media (max-width: 1440px) { - padding: 0 100px; - } - - @media (max-width: 1200px) { - padding: 0 45px; - height: 64px; - } - - @media (max-width: 750px) { - padding: 8px 18px; - height: ${(props: { isEn: boolean }) => (props.isEn ? '120px' : '100px')}; - flex-direction: column; - align-items: flex-start; - } - } - - .alert__dismiss__panel { - @media (max-width: 750px) { - width: 100%; - display: flex; - justify-content: flex-end; - } - } - - .alert__dismiss { - width: 100px; - height: 30px; - line-height: 30px; - border-radius: 2px; - border: solid 1px #fff; - text-align: center; - - @media (max-width: 1200px) { - margin-left: 30px; - } - } -` diff --git a/src/components/Card/HashCard/index.tsx b/src/components/Card/HashCard/index.tsx index 4892931ee..7c3e50002 100644 --- a/src/components/Card/HashCard/index.tsx +++ b/src/components/Card/HashCard/index.tsx @@ -5,9 +5,7 @@ import CopyIcon from '../../../assets/copy.png' import i18n from '../../../utils/i18n' import { v2AxiosIns } from '../../../service/http/fetcher' import { copyElementValue } from '../../../utils/util' -import { AppActions } from '../../../contexts/actions' import SmallLoading from '../../Loading/SmallLoading' -import { useDispatch } from '../../../contexts/providers' import { useIsMobile, useNewAddr, useDeprecatedAddr } from '../../../utils/hook' import SimpleButton from '../../SimpleButton' import { ReactComponent as OpenInNew } from '../../../assets/open_in_new.svg' @@ -16,6 +14,7 @@ import { HashCardPanel, LoadingPanel } from './styled' import styles from './styles.module.scss' import AddressText from '../../AddressText' import { useDASAccount } from '../../../contexts/providers/dasQuery' +import { useSetToast } from '../../Toast' const DASInfo: FC<{ address: string }> = ({ address }) => { const alias = useDASAccount(address) @@ -50,7 +49,7 @@ export default ({ showDASInfoOnHeader?: boolean | string }) => { const isMobile = useIsMobile() - const dispatch = useDispatch() + const setToast = useSetToast() const isTx = i18n.t('transaction.transaction') === title const newAddr = useNewAddr(hash) @@ -59,12 +58,7 @@ export default ({ const handleExportTxClick = async () => { const res = await v2AxiosIns(`transactions/${hash}/raw`).catch(error => { - dispatch({ - type: AppActions.ShowToastMessage, - payload: { - message: error.message, - }, - }) + setToast({ message: error.message }) }) if (!res) return @@ -110,12 +104,7 @@ export default ({ className="hash__copy_icon" onClick={() => { copyElementValue(document.getElementById('hash__value')) - dispatch({ - type: AppActions.ShowToastMessage, - payload: { - message: i18n.t('common.copied'), - }, - }) + setToast({ message: i18n.t('common.copied') }) }} > {!loading && copy} diff --git a/src/components/Content/index.tsx b/src/components/Content/index.tsx index 2e53749b5..9846cd689 100644 --- a/src/components/Content/index.tsx +++ b/src/components/Content/index.tsx @@ -1,18 +1,12 @@ import { ReactNode } from 'react' import styled from 'styled-components' -import { useAppState } from '../../contexts/providers' -import MobileMenu from '../Header/MobileMenu' const ContentPanel = styled.div` width: 100%; overflow-x: hidden; flex: 1; - margin-top: var(--navbar-height); background: #ededed; ` export default ({ children, style }: { children: ReactNode; style?: any }) => { - const { - components: { mobileMenuVisible }, - } = useAppState() - return {mobileMenuVisible ? : children} + return {children} } diff --git a/src/components/Dropdown/Language/index.tsx b/src/components/Dropdown/Language/index.tsx index cf3df9ac0..4b1b4d7d3 100644 --- a/src/components/Dropdown/Language/index.tsx +++ b/src/components/Dropdown/Language/index.tsx @@ -1,6 +1,4 @@ import i18n, { currentLanguage, changeLanguage } from '../../../utils/i18n' -import { useDispatch } from '../../../contexts/providers' -import { AppActions } from '../../../contexts/actions' import { LanguagePanel } from './styled' import SimpleButton from '../../SimpleButton' @@ -12,19 +10,12 @@ export const languageText = (lan: 'en' | 'zh' | null, reverse?: boolean) => { } export default ({ setShow, left, top }: { setShow: Function; left: number; top: number }) => { - const dispatch = useDispatch() const hideDropdown = () => { setShow(false) } const handleLanguage = () => { hideDropdown() changeLanguage(currentLanguage() === 'en' ? 'zh' : 'en') - dispatch({ - type: AppActions.UpdateAppLanguage, - payload: { - language: currentLanguage() === 'en' ? 'zh' : 'en', - }, - }) } return ( diff --git a/src/components/Header/BlockchainComp/index.tsx b/src/components/Header/BlockchainComp/index.tsx index a0c554aff..66ead43ce 100644 --- a/src/components/Header/BlockchainComp/index.tsx +++ b/src/components/Header/BlockchainComp/index.tsx @@ -4,7 +4,6 @@ import { isMainnet } from '../../../utils/chain' import WhiteDropdownIcon from '../../../assets/white_dropdown.png' import BlueDropUpIcon from '../../../assets/blue_drop_up.png' import GreenDropUpIcon from '../../../assets/green_drop_up.png' -import { useAppState } from '../../../contexts/providers' import { HeaderBlockchainPanel, MobileSubMenuPanel } from './styled' import SimpleButton from '../../SimpleButton' import ChainDropdown from '../../Dropdown/ChainType' @@ -27,15 +26,12 @@ const handleVersion = (nodeVersion: string) => { } const BlockchainDropdown: FC<{ nodeVersion: string }> = ({ nodeVersion }) => { - const { - app: { language }, - } = useAppState() const [showChainType, setShowChainType] = useState(false) const [chainTypeLeft, setChainTypeLeft] = useState(0) const [chainTypeTop, setChainTypeTop] = useState(0) useLayoutEffect(() => { - if (showChainType && language) { + if (showChainType) { const chainDropdownComp = document.getElementById('header__blockchain__panel') if (chainDropdownComp) { const chainDropdownReact = chainDropdownComp.getBoundingClientRect() @@ -45,7 +41,7 @@ const BlockchainDropdown: FC<{ nodeVersion: string }> = ({ nodeVersion }) => { } } } - }, [showChainType, language]) + }, [showChainType]) return ( { if (!showDropdown) return WhiteDropdownIcon return isMainnet() ? GreenDropUpIcon : BlueDropUpIcon } -const languageAction = (dispatch: AppDispatch) => { - changeLanguage(currentLanguage() === 'en' ? 'zh' : 'en') - dispatch({ - type: AppActions.UpdateAppLanguage, - payload: { - language: currentLanguage() === 'en' ? 'zh' : 'en', - }, - }) - dispatch({ - type: ComponentActions.UpdateHeaderMobileMenuVisible, - payload: { - mobileMenuVisible: false, - }, - }) -} - -const hideMobileMenu = (dispatch: AppDispatch) => { - dispatch({ - type: ComponentActions.UpdateHeaderMobileMenuVisible, - payload: { - mobileMenuVisible: false, - }, - }) -} - -const LanguageDropdown = () => { - const { - app: { language }, - } = useAppState() - +export const LanguageDropdown = () => { const [showLanguage, setShowLanguage] = useState(false) const [languageLeft, setLanguageLeft] = useState(0) const [languageTop, setLanguageTop] = useState(0) useLayoutEffect(() => { - if (showLanguage && language) { + if (showLanguage) { const languageDropdownComp = document.getElementById('header__language__panel') if (languageDropdownComp) { const languageDropdownReact = languageDropdownComp.getBoundingClientRect() @@ -64,7 +30,7 @@ const LanguageDropdown = () => { } } } - }, [showLanguage, language]) + }, [showLanguage]) return ( { ) } -const LanguageMenu = () => { - const dispatch = useDispatch() +export const LanguageMenu: FC<{ hideMobileMenu: () => void }> = ({ hideMobileMenu }) => { const [showSubMenu, setShowSubMenu] = useState(false) return ( @@ -116,7 +81,7 @@ const LanguageMenu = () => { { - hideMobileMenu(dispatch) + hideMobileMenu() }} > {currentLanguage() === 'en' ? i18n.t('navbar.language_en') : i18n.t('navbar.language_zh')} @@ -124,7 +89,8 @@ const LanguageMenu = () => { { - languageAction(dispatch) + changeLanguage(currentLanguage() === 'en' ? 'zh' : 'en') + hideMobileMenu() }} > {currentLanguage() === 'en' ? i18n.t('navbar.language_zh') : i18n.t('navbar.language_en')} @@ -134,5 +100,3 @@ const LanguageMenu = () => { ) } - -export default memo(() => (useIsMobile() ? : )) diff --git a/src/components/Header/MobileMenu/index.tsx b/src/components/Header/MobileMenu/index.tsx index 88d0f771b..954c0efd9 100644 --- a/src/components/Header/MobileMenu/index.tsx +++ b/src/components/Header/MobileMenu/index.tsx @@ -1,14 +1,14 @@ import { MobileMenusPanel } from './styled' import MenuItems from '../MenusComp' import { SearchComp } from '../SearchComp' -import LanguageComp from '../LanguageComp' +import { LanguageMenu } from '../LanguageComp' import BlockchainComp from '../BlockchainComp' -export default () => ( +export default ({ hideMobileMenu }: { hideMobileMenu: () => void }) => ( - - {}} /> + + ) diff --git a/src/components/Header/MobileMenu/styled.tsx b/src/components/Header/MobileMenu/styled.tsx index 31ef9adc0..657b970ab 100644 --- a/src/components/Header/MobileMenu/styled.tsx +++ b/src/components/Header/MobileMenu/styled.tsx @@ -1,15 +1,13 @@ import styled from 'styled-components' export const MobileMenusPanel = styled.div` + flex: 1; width: 100%; background: #1c1c1c; display: flex; flex-direction: column; - position: fixed; - position: -webkit-fixed; z-index: 2; color: white; - top: var(--navbar-height); - bottom: 0; - overflow: hidden; + overflow: auto; + overscroll-behavior: contain; ` diff --git a/src/components/Header/SearchComp/index.tsx b/src/components/Header/SearchComp/index.tsx index 08b9074b1..5b0a4c623 100644 --- a/src/components/Header/SearchComp/index.tsx +++ b/src/components/Header/SearchComp/index.tsx @@ -4,10 +4,14 @@ import SearchLogo from '../../../assets/search_white.png' import { HeaderSearchPanel, HeaderSearchBarPanel } from './styled' export const SearchComp: FC<{ - expanded: boolean - setExpanded: (expanded: boolean) => void -}> = memo(({ expanded, setExpanded }) => { - const onEditEnd = useCallback(() => setExpanded(false), [setExpanded]) + expanded?: boolean + setExpanded?: (expanded: boolean) => void + hideMobileMenu?: () => void +}> = memo(({ expanded, setExpanded, hideMobileMenu }) => { + const onEditEnd = useCallback(() => { + setExpanded?.(false) + hideMobileMenu?.() + }, [hideMobileMenu, setExpanded]) if (!expanded) { return ( @@ -16,7 +20,7 @@ export const SearchComp: FC<{ tabIndex={-1} onKeyDown={() => {}} onClick={() => { - setExpanded(true) + setExpanded?.(true) }} > header search bar diff --git a/src/components/Header/index.module.scss b/src/components/Header/index.module.scss index 8cdac0f95..d2643b1a8 100644 --- a/src/components/Header/index.module.scss +++ b/src/components/Header/index.module.scss @@ -15,3 +15,15 @@ min-width: 0; } } + +.StickyContainer { + position: sticky; + top: 0; + z-index: 10; + display: flex; + flex-direction: column; + + &.expanded { + height: 100vh; + } +} diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx index 006190e57..51430c30e 100644 --- a/src/components/Header/index.tsx +++ b/src/components/Header/index.tsx @@ -1,16 +1,19 @@ import { FC, ReactNode, useEffect, useRef, useState } from 'react' import { useLocation } from 'react-router' +import classNames from 'classnames' +import { createBrowserHistory } from 'history' import LogoIcon from '../../assets/ckb_logo.png' import { HeaderPanel, HeaderEmptyPanel, HeaderMobileMenuPanel, HeaderLogoPanel } from './styled' -import { useAppState, useDispatch } from '../../contexts/providers/index' -import { ComponentActions } from '../../contexts/actions' import MenusComp from './MenusComp' import { SearchComp } from './SearchComp' -import LanguageComp from './LanguageComp' +import { LanguageDropdown } from './LanguageComp' import BlockchainComp from './BlockchainComp' -import { currentLanguage } from '../../utils/i18n' import { useElementSize, useIsMobile } from '../../utils/hook' import styles from './index.module.scss' +import MaintainAlert from '../MaintainAlert' +import Sheet from '../Sheet' +import { createGlobalState, useGlobalState } from '../../utils/state' +import MobileMenu from './MobileMenu' const LogoComp = () => ( @@ -18,22 +21,12 @@ const LogoComp = () => ( ) -const MobileMenuComp = () => { - const dispatch = useDispatch() - const { - components: { mobileMenuVisible }, - } = useAppState() +const MobileMenuComp: FC<{ mobileMenuVisible: boolean; setMobileMenuVisible: (value: boolean) => void }> = ({ + mobileMenuVisible, + setMobileMenuVisible, +}) => { return ( - { - dispatch({ - type: ComponentActions.UpdateHeaderMobileMenuVisible, - payload: { - mobileMenuVisible: !mobileMenuVisible, - }, - }) - }} - > + setMobileMenuVisible(!mobileMenuVisible)}>
@@ -65,45 +58,87 @@ const AutoExpand: FC<{ ) } +const globalShowHeaderSearchBarCounter = createGlobalState(0) + +export function useShowSearchBarInHeader(show: boolean) { + const [, setCounter] = useGlobalState(globalShowHeaderSearchBarCounter) + + useEffect(() => { + if (!show) return + + setCounter(counter => counter + 1) + return () => setCounter(counter => counter - 1) + }, [show, setCounter]) +} + +export function useIsShowSearchBarInHeader() { + const [counter] = useGlobalState(globalShowHeaderSearchBarCounter) + return counter > 0 +} + +const useRouterLocation = (callback: () => void) => { + const history = createBrowserHistory() + const savedCallback = useRef(() => {}) + useEffect(() => { + savedCallback.current = callback + }) + useEffect(() => { + const currentCallback = () => { + savedCallback.current() + } + const listen = history.listen(() => { + currentCallback() + }) + return () => { + listen() + } + }, [history]) +} + export default () => { const isMobile = useIsMobile() const { pathname } = useLocation() - const dispatch = useDispatch() - const { - components: { headerSearchBarVisible, maintenanceAlertVisible }, - } = useAppState() + // TODO: This hard-coded implementation is not ideal, but currently the header is loaded before the page component, + // so we can only handle it this way temporarily, otherwise there will be flickering during loading. + const defaultSearchBarVisible = pathname !== '/' && pathname !== '/search/fail' + const isShowSearchBar = useIsShowSearchBarInHeader() + const [mobileMenuVisible, setMobileMenuVisible] = useState(false) - useEffect(() => { - dispatch({ - type: ComponentActions.UpdateHeaderSearchBarVisible, - payload: { - headerSearchBarVisible: pathname !== '/' && pathname !== '/search/fail', - }, - }) - }, [dispatch, pathname]) + useRouterLocation(() => setMobileMenuVisible(false)) return ( - - - {!isMobile && ( - <> - } - expandableWidthRange={{ minimum: 320, maximum: 440 }} - renderExpandable={(expanded, setExpanded) => - headerSearchBarVisible && - } - /> - - - - )} - {isMobile && ( - <> - - - - )} - +
+ + + + {!isMobile && ( + <> + } + expandableWidthRange={{ minimum: 320, maximum: 440 }} + renderExpandable={(expanded, setExpanded) => + (defaultSearchBarVisible || isShowSearchBar) && ( + + ) + } + /> + + + + )} + {isMobile && ( + <> + + + + )} + + + {mobileMenuVisible && setMobileMenuVisible(false)} />} +
) } diff --git a/src/components/Header/styled.tsx b/src/components/Header/styled.tsx index 3da7b6ef4..256871ce9 100644 --- a/src/components/Header/styled.tsx +++ b/src/components/Header/styled.tsx @@ -7,11 +7,7 @@ export const HeaderPanel = styled.div` width: 100%; min-height: var(--navbar-height); background-color: #040607; - position: fixed; - position: -webkit-fixed; overflow: visible; - top: ${(props: { isNotTop?: boolean }) => (props.isNotTop ? '48px' : '0')}; - z-index: 10; display: flex; align-items: center; flex-wrap: wrap; @@ -23,12 +19,10 @@ export const HeaderPanel = styled.div` @media (max-width: 1200px) { padding: 0 45px; - top: ${(props: { isNotTop?: boolean }) => (props.isNotTop ? 'var(--navbar-height)' : '0')}; } @media (max-width: 780px) { padding: 0 18px; - top: ${(props: { isNotTop?: boolean; isEn: boolean }) => (props.isNotTop ? (props.isEn ? '120px' : '100px') : '0')}; } ` diff --git a/src/components/MaintainAlert/index.tsx b/src/components/MaintainAlert/index.tsx new file mode 100644 index 000000000..77e395e14 --- /dev/null +++ b/src/components/MaintainAlert/index.tsx @@ -0,0 +1,13 @@ +import i18n from '../../utils/i18n' +import { IS_MAINTAINING } from '../../constants/common' +import styles from './styles.module.scss' + +const MaintainAlert = () => { + if (IS_MAINTAINING) { + return
{i18n.t('error.maintain')}
+ } + + return null +} + +export default MaintainAlert diff --git a/src/components/Alert/styles.module.scss b/src/components/MaintainAlert/styles.module.scss similarity index 100% rename from src/components/Alert/styles.module.scss rename to src/components/MaintainAlert/styles.module.scss diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 97f3412ab..c847b99e6 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -9,9 +9,6 @@ import ClearLogo from '../../assets/clear.png' import { addPrefixForHash, containSpecialChar } from '../../utils/string' import i18n from '../../utils/i18n' import { HttpErrorCode, SearchFailType } from '../../constants/common' -import { AppDispatch } from '../../contexts/reducer' -import { ComponentActions } from '../../contexts/actions' -import { useDispatch } from '../../contexts/providers' import { useIsMobile } from '../../utils/hook' import { isChainTypeError } from '../../utils/chain' @@ -43,24 +40,12 @@ const setSearchContent = (inputElement: any, content: string) => { } } -const hideMobileMenu = (dispatch: AppDispatch) => { - dispatch({ - type: ComponentActions.UpdateHeaderMobileMenuVisible, - payload: { - mobileMenuVisible: false, - }, - }) -} - const handleSearchResult = ( searchValue: string, inputElement: any, - dispatch: AppDispatch, setSearchValue: Function, history: ReturnType, - isMobile: boolean, ) => { - if (isMobile) hideMobileMenu(dispatch) const query = searchValue.trim().replace(',', '') // remove front and end blank and ',' if (!query || containSpecialChar(query)) { history.push(`/search/fail?q=${query}`) @@ -117,7 +102,6 @@ const Search: FC<{ onEditEnd?: () => void }> = memo(({ content, hasButton, onEditEnd }) => { const isMobile = useIsMobile() - const dispatch = useDispatch() const history = useHistory() const [t] = useTranslation() const SearchPlaceholder = useMemo(() => t('navbar.search_placeholder'), [t]) @@ -153,7 +137,7 @@ const Search: FC<{ const searchKeyAction = (event: any) => { if (event.keyCode === 13) { - handleSearchResult(searchValue, inputElement, dispatch, setSearchValue, history, isMobile) + handleSearchResult(searchValue, inputElement, setSearchValue, history) onEditEnd?.() } } @@ -180,7 +164,7 @@ const Search: FC<{ {hasButton && ( { - handleSearchResult(searchValue, inputElement, dispatch, setSearchValue, history, isMobile) + handleSearchResult(searchValue, inputElement, setSearchValue, history) onEditEnd?.() }} > diff --git a/src/components/Sheet/index.tsx b/src/components/Sheet/index.tsx index 69ce549de..0cb700946 100644 --- a/src/components/Sheet/index.tsx +++ b/src/components/Sheet/index.tsx @@ -1,27 +1,28 @@ -import { useAppState } from '../../contexts/providers' import { SheetPanel, SheetPointPanel, SheetItem } from './styled' -import { currentLanguage } from '../../utils/i18n' +import { createGlobalState, createGlobalStateSetter, useGlobalState } from '../../utils/state' + +const globalNetworkErrMsgs = createGlobalState([]) +const globalChainAlerts = createGlobalState([]) + +export const setNetworkErrMsgs = createGlobalStateSetter(globalNetworkErrMsgs) +export const setChainAlerts = createGlobalStateSetter(globalChainAlerts) const Sheet = () => { - const { - app, - components: { maintenanceAlertVisible }, - } = useAppState() - const messages: string[] = app.appErrors[1].message.concat(app.appErrors[0].message) + const [networkErrMsgs] = useGlobalState(globalNetworkErrMsgs) + const [chainAlerts] = useGlobalState(globalChainAlerts) + const messages: string[] = chainAlerts.concat(networkErrMsgs) return messages.length > 0 ? ( - -
- {messages.map((context: string, index: number) => { - const key = index - return ( - - {messages.length > 1 && ·} - {context} - - ) - })} -
+ + {messages.map((context: string, index: number) => { + const key = index + return ( + + {messages.length > 1 && ·} + {context} + + ) + })} ) : null } diff --git a/src/components/Sheet/styled.tsx b/src/components/Sheet/styled.tsx index 8a77cb5ce..be826d8d1 100644 --- a/src/components/Sheet/styled.tsx +++ b/src/components/Sheet/styled.tsx @@ -2,31 +2,16 @@ import styled from 'styled-components' export const SheetPanel = styled.div` - position: sticky; - top: ${(props: { isNotTop?: boolean }) => (props.isNotTop ? '112px' : '64px')}; - z-index: 9000; - - @media (max-width: 1200px) { - top: ${(props: { isNotTop?: boolean }) => (props.isNotTop ? '128px' : '64px')}; - } + width: 100%; + background: #d03a3a; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + padding: 15px 0 20px; @media (max-width: 750px) { - top: ${(props: { isNotTop?: boolean; isEn: boolean }) => - props.isNotTop ? (props.isEn ? '184px' : '164px') : '64px'}; - } - - > div { - width: 100%; - background: #d03a3a; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - padding: 15px 0 20px; - - @media (max-width: 750px) { - padding: 6px 0 10px; - } + padding: 6px 0 10px; } ` diff --git a/src/components/Text/CopyTooltipText/index.tsx b/src/components/Text/CopyTooltipText/index.tsx index 73369ed2a..7582fc369 100644 --- a/src/components/Text/CopyTooltipText/index.tsx +++ b/src/components/Text/CopyTooltipText/index.tsx @@ -1,23 +1,17 @@ import i18n from '../../../utils/i18n' import { copyElementValue } from '../../../utils/util' -import { AppActions } from '../../../contexts/actions' -import { useDispatch } from '../../../contexts/providers' import SimpleButton from '../../SimpleButton' +import { useSetToast } from '../../Toast' export default ({ content }: { content: string }) => { - const dispatch = useDispatch() + const setToast = useSetToast() return ( { event.stopPropagation() copyElementValue(document.getElementById(`copy__content__${content}`)) - dispatch({ - type: AppActions.ShowToastMessage, - payload: { - message: i18n.t('common.copied'), - }, - }) + setToast({ message: i18n.t('common.copied') }) event.preventDefault() }} > diff --git a/src/components/Toast/index.tsx b/src/components/Toast/index.tsx index e581f842d..e48541539 100644 --- a/src/components/Toast/index.tsx +++ b/src/components/Toast/index.tsx @@ -1,7 +1,7 @@ -import { useState, useEffect, useReducer } from 'react' +import { useState, useEffect, useReducer, useCallback } from 'react' import { useTimeoutWithUnmount } from '../../utils/hook' -import { useAppState } from '../../contexts/providers' import { ToastItemPanel, ToastPanel } from './styled' +import { createGlobalState, useGlobalState } from '../../utils/state' const getColor = (type: 'success' | 'warning' | 'danger') => { switch (type) { @@ -81,10 +81,25 @@ const reducer = (state: any, action: any) => { } } +const globalToast = createGlobalState(null) + +export function useSetToast() { + const [, setToast] = useGlobalState(globalToast) + + return useCallback( + (data: Pick & Partial>) => + setToast({ + id: new Date().getTime(), + message: data.message, + type: data.type ?? 'success', + duration: data.duration, + }), + [setToast], + ) +} + export default () => { - const { - app: { toast }, - } = useAppState() + const [toast] = useGlobalState(globalToast) const [state, dispatch] = useReducer(reducer, initialState) useEffect(() => { diff --git a/src/components/TransactionItem/TransactionItemCell/index.tsx b/src/components/TransactionItem/TransactionItemCell/index.tsx index 478bd8e00..421d2939a 100644 --- a/src/components/TransactionItem/TransactionItemCell/index.tsx +++ b/src/components/TransactionItem/TransactionItemCell/index.tsx @@ -6,7 +6,7 @@ import NervosDAOCellIcon from '../../../assets/nervos_dao_cell.png' import NervosDAOWithdrawingIcon from '../../../assets/nervos_dao_withdrawing.png' import CurrentAddressIcon from '../../../assets/current_address.svg' import UDTTokenIcon from '../../../assets/udt_token.png' -import i18n from '../../../utils/i18n' +import i18n, { currentLanguage } from '../../../utils/i18n' import { localeNumberString, parseUDTAmount } from '../../../utils/number' import { shannonToCkb, shannonToCkbDecimal } from '../../../utils/util' import { @@ -20,7 +20,6 @@ import { import { CellType } from '../../../constants/common' import TransactionCellArrow from '../../Transaction/TransactionCellArrow' import DecimalCapacity from '../../DecimalCapacity' -import { useAppState } from '../../../contexts/providers' import { parseDiffDate } from '../../../utils/date' import Cellbase from '../../Transaction/Cellbase' import styles from './index.module.scss' @@ -93,9 +92,8 @@ const WithdrawPopoverItem = ({ const WithdrawPopoverInfo = ({ cell }: { cell: State.Cell }) => { const isMobile = useIsMobile() - const { app } = useAppState() let width = 'short' - if (app.language === 'en') { + if (currentLanguage() === 'en') { width = isDaoDepositCell(cell.cellType) ? 'long' : 'medium' } return ( diff --git a/src/constants/cache.ts b/src/constants/cache.ts index 4411ee276..aab0a6aa2 100644 --- a/src/constants/cache.ts +++ b/src/constants/cache.ts @@ -3,7 +3,6 @@ import CONFIG from '../config' export const AppCachedKeys = { AppLanguage: `${CONFIG.CHAIN_TYPE}-AppLanguage`, Version: `${CONFIG.CHAIN_TYPE}-Version`, - MaintenanceAlert: `${CONFIG.CHAIN_TYPE}-MaintenanceAlert`, NewAddrFormat: `is-address-format-new`, } diff --git a/src/constants/common.ts b/src/constants/common.ts index 4dbe8d46f..5e35126a2 100644 --- a/src/constants/common.ts +++ b/src/constants/common.ts @@ -8,7 +8,6 @@ export const FLUSH_CHART_CACHE_POLLING_TIME = 300000 // 5 minutes export const LOADING_WAITING_TIME = 500 export const DELAY_BLOCK_NUMBER = 11 export const PAGE_CELL_COUNT = 200 -export const MAINTENANCE_ALERT_POLLING_TIME = 3600000 // 1 hour export const NEXT_HARD_FORK_EPOCH = 5414 export const EPOCH_HOURS = 4 export const ONE_DAY_SECOND = 24 * 60 * 60 diff --git a/src/contexts/actions/index.ts b/src/contexts/actions/index.ts deleted file mode 100644 index 1c005368e..000000000 --- a/src/contexts/actions/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -export enum AppActions { - UpdateModal = 'updateModal', - ShowToastMessage = 'showToastMessage', - UpdateAppErrors = 'updateAppErrors', - UpdateTipBlockNumber = 'updateTipBlockNumber', - UpdateAppLanguage = 'updateAppLanguage', - UpdateHardForkStatus = 'updateHardForkStatus', -} - -export enum PageActions { - UpdateStatistics = 'updateStatistics', -} - -export enum ComponentActions { - UpdateHeaderMobileMenuVisible = 'updateHeaderMobileMenuVisible', - UpdateHeaderSearchBarVisible = 'updateHeaderSearchBarVisible', - UpdateMaintenanceAlertVisible = 'updateMaintenanceAlertVisible', -} - -export type StateActions = AppActions | PageActions | ComponentActions - -// eslint-disable-next-line no-undef -export default StateActions diff --git a/src/contexts/providers/hook.ts b/src/contexts/providers/hook.ts index 6a8f03360..3bf187b45 100644 --- a/src/contexts/providers/hook.ts +++ b/src/contexts/providers/hook.ts @@ -1,61 +1,32 @@ import { useState } from 'react' -import { useHistory } from 'react-router' import { initAxiosInterceptors } from '../../service/http/interceptors' -import { - MAINTENANCE_ALERT_POLLING_TIME, - FLUSH_CHART_CACHE_POLLING_TIME, - BLOCK_POLLING_TIME, -} from '../../constants/common' +import { FLUSH_CHART_CACHE_POLLING_TIME } from '../../constants/common' import { AppCachedKeys } from '../../constants/cache' -import { AppDispatch } from '../reducer' import { fetchCachedData } from '../../utils/cache' import { changeLanguage } from '../../utils/i18n' -import { useAppState, useDispatch } from '.' -import { AppActions } from '../actions' import { useInterval } from '../../utils/hook' -import { getMaintenanceInfo } from '../../service/app/alert' import flushCacheInfo from '../../service/app/charts/cache' -import getStatistics from '../../service/app/statistics' -const initAppLanguage = (app: State.App, dispatch: AppDispatch) => { - const language = fetchCachedData<'zh' | 'en'>(AppCachedKeys.AppLanguage) || app.language - // Warding: https://github.com/facebook/react/issues/18147 - setTimeout(() => { - dispatch({ - type: AppActions.UpdateAppLanguage, - payload: { - language, - }, - }) - }, 0) +const initAppLanguage = () => { + const language = + fetchCachedData<'zh' | 'en'>(AppCachedKeys.AppLanguage) || (navigator.language.includes('zh') ? 'zh' : 'en') changeLanguage(language) } export const useInitApp = () => { const [init, setInit] = useState(false) - const { app } = useAppState() - const dispatch = useDispatch() - const history = useHistory() if (!init) { setInit(true) - initAxiosInterceptors(dispatch, history) - initAppLanguage(app, dispatch) - getMaintenanceInfo(dispatch) + initAxiosInterceptors() + // TODO: This function may not belong here. + initAppLanguage() flushCacheInfo() - getStatistics(dispatch) } - useInterval(() => { - getMaintenanceInfo(dispatch) - }, MAINTENANCE_ALERT_POLLING_TIME) - useInterval(() => { flushCacheInfo() }, FLUSH_CHART_CACHE_POLLING_TIME) - useInterval(() => { - getStatistics(dispatch) - }, BLOCK_POLLING_TIME) } export default useInitApp diff --git a/src/contexts/providers/index.tsx b/src/contexts/providers/index.tsx deleted file mode 100644 index a2b1d73e0..000000000 --- a/src/contexts/providers/index.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import { createContext, useReducer, useContext } from 'react' -import initState from '../states/index' -import { AppDispatch, reducer } from '../reducer' - -export const AppContext = createContext<{ state: typeof initState; dispatch: AppDispatch }>({ - state: initState, - dispatch: () => {}, -}) - -const withProviders = (Comp: React.ComponentType) => (props: React.Props) => { - const [providers, dispatch] = useReducer(reducer, initState) - - return ( - - - - ) -} - -export const useAppState = () => useContext(AppContext).state -export const useDispatch = () => useContext(AppContext).dispatch - -export default withProviders diff --git a/src/contexts/reducer/app.ts b/src/contexts/reducer/app.ts deleted file mode 100644 index 73ebcb798..000000000 --- a/src/contexts/reducer/app.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { ChartColor, getPrimaryColor, getSecondaryColor } from '../../constants/common' -import { AppActions } from '../actions' - -export const appReducer = ( - state: State.AppState, - { type, payload }: { type: AppActions; payload: State.AppPayload }, -): State.AppState => { - switch (type) { - case AppActions.UpdateModal: - return { - ...state, - app: { - ...state.app, - }, - } - case AppActions.ShowToastMessage: - return { - ...state, - app: { - ...state.app, - toast: { - id: new Date().getTime(), - message: payload.message, - type: payload.type, - duration: payload.duration, - }, - }, - } - case AppActions.UpdateAppErrors: - return { - ...state, - app: { - ...state.app, - appErrors: state.app.appErrors.map((error: State.AppError) => { - if (payload.appError.type === error.type) { - return payload.appError - } - return error - }) as typeof state.app.appErrors, - }, - } - case AppActions.UpdateTipBlockNumber: - return { - ...state, - app: { - ...state.app, - tipBlockNumber: payload.tipBlockNumber, - }, - } - case AppActions.UpdateAppLanguage: - return { - ...state, - app: { - ...state.app, - language: payload.language, - }, - } - case AppActions.UpdateHardForkStatus: - return { - ...state, - app: { - ...state.app, - primaryColor: getPrimaryColor(), - secondaryColor: getSecondaryColor(), - chartColor: ChartColor, - }, - } - default: - return state - } -} - -export default appReducer diff --git a/src/contexts/reducer/component.ts b/src/contexts/reducer/component.ts deleted file mode 100644 index a4c1bf7ac..000000000 --- a/src/contexts/reducer/component.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { ComponentActions } from '../actions' - -export const componentReducer = ( - state: State.AppState, - { type, payload }: { type: ComponentActions; payload: State.Components }, -): State.AppState => { - switch (type) { - case ComponentActions.UpdateHeaderMobileMenuVisible: - return { - ...state, - components: { - ...state.components, - mobileMenuVisible: payload.mobileMenuVisible, - }, - } - case ComponentActions.UpdateHeaderSearchBarVisible: - return { - ...state, - components: { - ...state.components, - headerSearchBarVisible: payload.headerSearchBarVisible, - }, - } - case ComponentActions.UpdateMaintenanceAlertVisible: - return { - ...state, - components: { - ...state.components, - maintenanceAlertVisible: payload.maintenanceAlertVisible, - }, - } - default: - return state - } -} - -export default componentReducer diff --git a/src/contexts/reducer/index.ts b/src/contexts/reducer/index.ts deleted file mode 100644 index 041ba4770..000000000 --- a/src/contexts/reducer/index.ts +++ /dev/null @@ -1,30 +0,0 @@ -import React from 'react' -import StateActions, { AppActions, PageActions, ComponentActions } from '../actions' -import appReducer from './app' -import pageReducer from './page' -import componentReducer from './component' - -export type AppDispatch = React.Dispatch<{ type: StateActions; payload: any }> // TODO: add type of payload -export type StateWithDispatch = State.AppState & { dispatch: AppDispatch } - -export const reducer = ( - state: State.AppState, - { type, payload }: { type: StateActions; payload: any }, -): State.AppState => { - if (Object.values(AppActions).includes(type as AppActions)) { - return appReducer(state, { - type: type as AppActions, - payload, - }) - } - if (Object.values(PageActions).includes(type as PageActions)) { - return pageReducer(state, { - type: type as PageActions, - payload, - }) - } - return componentReducer(state, { - type: type as ComponentActions, - payload, - }) -} diff --git a/src/contexts/reducer/page.ts b/src/contexts/reducer/page.ts deleted file mode 100644 index 312165298..000000000 --- a/src/contexts/reducer/page.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { PageActions } from '../actions' - -export const pageReducer = ( - state: State.AppState, - { type, payload }: { type: PageActions; payload: State.PagePayload }, -): State.AppState => { - switch (type) { - // statistic chart page - case PageActions.UpdateStatistics: - return { - ...state, - statistics: payload.statistics, - } - - default: - return state - } -} - -export default pageReducer diff --git a/src/contexts/states/app.ts b/src/contexts/states/app.ts deleted file mode 100644 index db2c956a7..000000000 --- a/src/contexts/states/app.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { ChartColor, getPrimaryColor, getSecondaryColor } from '../../constants/common' - -export const initApp: State.App = { - toast: null, - appErrors: [ - { - type: 'Network', - message: [], - }, - { - type: 'ChainAlert', - message: [], - }, - { - type: 'Maintenance', - message: [], - }, - ], - tipBlockNumber: 0, - language: navigator.language.includes('zh') ? 'zh' : 'en', - primaryColor: getPrimaryColor(), - secondaryColor: getSecondaryColor(), - chartColor: ChartColor, -} - -export default initApp diff --git a/src/contexts/states/components.ts b/src/contexts/states/components.ts deleted file mode 100644 index b54d6c2d0..000000000 --- a/src/contexts/states/components.ts +++ /dev/null @@ -1,7 +0,0 @@ -export const initComponents: State.Components = { - mobileMenuVisible: false, - headerSearchBarVisible: false, - maintenanceAlertVisible: false, -} - -export default initComponents diff --git a/src/contexts/states/index.ts b/src/contexts/states/index.ts deleted file mode 100644 index 66c74d352..000000000 --- a/src/contexts/states/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -import initApp from './app' -import initStatistics from './statistics' -import initComponents from './components' - -export type FetchStatus = keyof State.FetchStatus - -const initState: State.AppState = { - app: initApp, - statistics: initStatistics, - - components: initComponents, -} - -export default initState diff --git a/src/contexts/states/statistics.ts b/src/contexts/states/statistics.ts deleted file mode 100644 index c47b5c329..000000000 --- a/src/contexts/states/statistics.ts +++ /dev/null @@ -1,17 +0,0 @@ -export const initStatistics: State.Statistics = { - tipBlockNumber: '0', - averageBlockTime: '0', - currentEpochDifficulty: '0', - hashRate: '0', - epochInfo: { - epochNumber: '0', - epochLength: '0', - index: '0', - }, - estimatedEpochTime: '0', - transactionsLast24Hrs: '0', - transactionsCountPerMinute: '0', - reorgStartedAt: null, -} - -export default initStatistics diff --git a/src/locales/en.json b/src/locales/en.json index 1eb30e271..70e1fc5c2 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -79,8 +79,6 @@ "too_many_request": "Too many requests, please try later", "data_too_large": "The data is too large, not available for download", "result_not_found": "Search result not found", - "maintenance": "Please note that CKB Explorer will be under maintenance from {{start}} to {{end}}. Data update during the period might be delayed.", - "dismiss": "Dismiss", "handling-reorg": "Reorg detected at {{time}} so CKB Explorer is checking data thoroughly. It may take half an hour, please visit later", "migration-notice": "Service of CKB explorer will have a migration on {{time}}, and the server might be unavailable temporarily" }, diff --git a/src/locales/zh.json b/src/locales/zh.json index 137aaf67b..b6c0c176e 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -79,8 +79,6 @@ "too_many_request": "请求次数过多, 请稍后再试", "data_too_large": "数据过大,不支持下载", "result_not_found": "没有找到搜索结果", - "maintenance": "请注意 CKB 浏览器将于 {{start}} 至 {{end}} 处于维护状态,期间数据更新可能会有延迟。", - "dismiss": "知道了", "handling-reorg": " 检测到 {{time}} 发生 Reorg, CKB 浏览器正在彻底检查数据。所需时间约为半小时, 请稍后访问", "migration-notice": "浏览器服务将于 {{time}} 进行迁移, 可能出现短时不可用状态" }, diff --git a/src/pages/BlockDetail/BlockComp.tsx b/src/pages/BlockDetail/BlockComp.tsx index 97456cab7..5f15e2ae0 100644 --- a/src/pages/BlockDetail/BlockComp.tsx +++ b/src/pages/BlockDetail/BlockComp.tsx @@ -10,7 +10,6 @@ import DropDownBlueIcon from '../../assets/content_blue_drop_down.png' import PackUpBlueIcon from '../../assets/content_blue_pack_up.png' import OverviewCard, { OverviewItemData } from '../../components/Card/OverviewCard' import TransactionItem from '../../components/TransactionItem/index' -import { useAppState } from '../../contexts/providers' import { parseSimpleDate } from '../../utils/date' import i18n from '../../utils/i18n' import { localeNumberString, handleDifficulty } from '../../utils/number' @@ -39,6 +38,7 @@ import AddressText from '../../components/AddressText' import ComparedToMaxTooltip from '../../components/Tooltip/ComparedToMaxTooltip' import Filter from '../../components/Search/Filter' import { HelpTip } from '../../components/HelpTip' +import { useLatestBlockNumber } from '../../services/ExplorerService' const CELL_BASE_ANCHOR = 'cellbase' @@ -104,9 +104,7 @@ const BlockMinerReward = ({ export const BlockOverview: FC<{ block: State.Block }> = ({ block }) => { const isMobile = useIsMobile() - const { - statistics: { tipBlockNumber }, - } = useAppState() + const tipBlockNumber = useLatestBlockNumber() const [showAllOverview, setShowAllOverview] = useState(false) const minerReward = const rootInfoItems = [ diff --git a/src/pages/Home/index.tsx b/src/pages/Home/index.tsx index b07e9f2f8..e1efa99ac 100644 --- a/src/pages/Home/index.tsx +++ b/src/pages/Home/index.tsx @@ -1,4 +1,4 @@ -import { FC, memo, useEffect, useMemo, useRef } from 'react' +import { FC, memo, useMemo, useRef } from 'react' import { useHistory } from 'react-router' import { useTranslation } from 'react-i18next' import { useQuery } from 'react-query' @@ -22,12 +22,10 @@ import { } from '../../constants/common' import { localeNumberString, handleHashRate, handleDifficulty } from '../../utils/number' import { handleBigNumber } from '../../utils/string' -import { useAppState, useDispatch } from '../../contexts/providers' import i18n from '../../utils/i18n' import LatestBlocksIcon from '../../assets/latest_blocks.png' import LatestTransactionsIcon from '../../assets/latest_transactions.png' import { BlockCardItem, TransactionCardItem } from './TableCard' -import { getTipBlockNumber } from '../../service/app/address' import Loading from '../../components/Loading/SmallLoading' import { useElementIntersecting, useInterval, useIsLGScreen, useIsMobile } from '../../utils/hook' import Banner from '../../components/Banner' @@ -35,10 +33,11 @@ import { handleBlockchainAlert } from '../../service/app/blockchain' import Search from '../../components/Search' import AverageBlockTimeChart from './AverageBlockTimeChart' import HashRateChart from './HashRateChart' -import { ComponentActions } from '../../contexts/actions' import styles from './index.module.scss' import { fetchLatestBlocks, fetchLatestTransactions } from '../../service/http/fetcher' import { RouteState } from '../../routes/state' +import { useLatestBlockNumber, useStatistics } from '../../services/ExplorerService' +import { useShowSearchBarInHeader } from '../../components/Header' interface BlockchainData { name: string @@ -116,7 +115,6 @@ const getBlockchainDataList = (statistics: State.Statistics, isMobile: boolean, ] const HomeHeaderTopPanel: FC = memo(() => { - const dispatch = useDispatch() const ref = useRef(null) const { height: resizedHeight } = useResizeDetector({ @@ -125,6 +123,8 @@ const HomeHeaderTopPanel: FC = memo(() => { }) const height = Math.round(resizedHeight ?? ref.current?.clientHeight ?? 0) const selfMarginTop = 20 + // TODO: This does not take into account the height of the Alert and Search when they appear, + // so a dynamic `--headerHeight` variable may be needed. const headerHeight = 64 const intersectingCheckOffset = height + selfMarginTop + headerHeight @@ -140,26 +140,7 @@ const HomeHeaderTopPanel: FC = memo(() => { true, ) - useEffect(() => { - if (ref.current == null) return - - dispatch({ - type: ComponentActions.UpdateHeaderSearchBarVisible, - payload: { - headerSearchBarVisible: !isFullDisplayInScreen, - }, - }) - - // eslint-disable-next-line consistent-return - return () => { - dispatch({ - type: ComponentActions.UpdateHeaderSearchBarVisible, - payload: { - headerSearchBarVisible: true, - }, - }) - } - }, [dispatch, isFullDisplayInScreen]) + useShowSearchBarInHeader(!isFullDisplayInScreen) return (
@@ -204,12 +185,9 @@ const TransactionList: FC<{ transactions: State.Transaction[]; tipBlockNumber: n export default () => { const isMobile = useIsMobile() const isLG = useIsLGScreen() - const dispatch = useDispatch() const history = useHistory() - const { - statistics, - app: { tipBlockNumber }, - } = useAppState() + const statistics = useStatistics() + const tipBlockNumber = useLatestBlockNumber() const [t] = useTranslation() const blocksQuery = useQuery( @@ -251,11 +229,7 @@ export default () => { ) useInterval(() => { - getTipBlockNumber(dispatch) - }, BLOCK_POLLING_TIME) - - useInterval(() => { - handleBlockchainAlert(dispatch) + handleBlockchainAlert() }, BLOCKCHAIN_ALERT_POLLING_TIME) const blockchainDataList = getBlockchainDataList(statistics, isMobile, isLG) diff --git a/src/pages/NervosDao/DaoOverview/index.tsx b/src/pages/NervosDao/DaoOverview/index.tsx index 335ddacfd..ae2dc4917 100644 --- a/src/pages/NervosDao/DaoOverview/index.tsx +++ b/src/pages/NervosDao/DaoOverview/index.tsx @@ -6,7 +6,6 @@ import 'echarts/lib/component/title' import 'echarts/lib/component/legend' import 'echarts/lib/component/legendScroll' import { Tooltip } from 'antd' -import { useAppState } from '../../../contexts/providers' import { DaoOverviewPanel, DaoOverviewLeftPanel, @@ -28,6 +27,7 @@ import DecimalCapacity from '../../../components/DecimalCapacity' import { useIsLGScreen, useIsMobile } from '../../../utils/hook' import { ReactChartCore } from '../../StatisticsChart/common' import { HelpTip } from '../../../components/HelpTip' +import { ChartColor } from '../../../constants/common' interface NervosDaoItemContent { title: string @@ -288,29 +288,26 @@ const NervosDaoPieItem = ({ item }: { item: NervosDaoPieItemContent }) => ( export default ({ nervosDao }: { nervosDao: State.NervosDao }) => { const isMobile = useIsMobile() const isExactLG = useIsLGScreen(true) - const { - app: { chartColor }, - } = useAppState() const nervosDaoPieItemContents = useCallback( (nervosDao: State.NervosDao): NervosDaoPieItemContent[] => [ { title: i18n.t('nervos_dao.mining_reward'), content: , - color: chartColor.daoColors[0], + color: ChartColor.daoColors[0], }, { title: i18n.t('nervos_dao.deposit_compensation'), content: , - color: chartColor.daoColors[1], + color: ChartColor.daoColors[1], }, { title: i18n.t('nervos_dao.burnt'), content: , - color: chartColor.daoColors[2], + color: ChartColor.daoColors[2], }, ], - [chartColor], + [], ) return ( @@ -324,7 +321,7 @@ export default ({ nervosDao }: { nervosDao: State.NervosDao }) => {
{ const history = useHistory() @@ -213,7 +212,7 @@ export const ScriptCells = ({ } export const CodeHashMessage = ({ codeHash }: { codeHash: string }) => { - const dispatch = useDispatch() + const setToast = useSetToast() return (
{codeHash} @@ -222,12 +221,7 @@ export const CodeHashMessage = ({ codeHash }: { codeHash: string }) => { onClick={() => { navigator.clipboard.writeText(codeHash).then( () => { - dispatch({ - type: AppActions.ShowToastMessage, - payload: { - message: i18n.t('common.copied'), - }, - }) + setToast({ message: i18n.t('common.copied') }) }, error => { console.error(error) diff --git a/src/pages/SimpleUDT/index.tsx b/src/pages/SimpleUDT/index.tsx index ed2c1e0ef..d9850744b 100644 --- a/src/pages/SimpleUDT/index.tsx +++ b/src/pages/SimpleUDT/index.tsx @@ -1,12 +1,10 @@ -import { useEffect, useState } from 'react' +import { useState } from 'react' import { Link, useHistory, useLocation, useParams } from 'react-router-dom' import { useTranslation } from 'react-i18next' import { useQuery } from 'react-query' import { Popover } from 'antd' import SimpleUDTHashCard from '../../components/Card/HashCard' import Content from '../../components/Content' -import { useDispatch } from '../../contexts/providers/index' -import { getTipBlockNumber } from '../../service/app/address' import i18n from '../../utils/i18n' import { SimpleUDTContentPanel, UDTTransactionTitlePanel, TypeScriptController } from './styled' import SimpleUDTComp, { SimpleUDTOverview } from './SimpleUDTComp' @@ -43,7 +41,6 @@ enum TransactionType { export const SimpleUDT = () => { const isMobile = useIsMobile() - const dispatch = useDispatch() const { push } = useHistory() const { search } = useLocation() const [t] = useTranslation() @@ -55,10 +52,6 @@ export const SimpleUDT = () => { const filter = query.get('filter') const type = query.get('type') - useEffect(() => { - getTipBlockNumber(dispatch) - }, [dispatch]) - const querySimpleUDT = useQuery(['simple-udt'], async () => { const wrapper = await fetchSimpleUDT(typeHash) const udt = wrapper.attributes diff --git a/src/pages/StatisticsChart/activities/AddressBalanceRank.tsx b/src/pages/StatisticsChart/activities/AddressBalanceRank.tsx index a4ca5707f..c2b415320 100644 --- a/src/pages/StatisticsChart/activities/AddressBalanceRank.tsx +++ b/src/pages/StatisticsChart/activities/AddressBalanceRank.tsx @@ -17,7 +17,7 @@ const getAddressWithRanking = (statisticAddressBalanceRanks: State.StatisticAddr const getOption = ( statisticAddressBalanceRanks: State.StatisticAddressBalanceRank[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, getAdaptAddressText: (address: string) => string, diff --git a/src/pages/StatisticsChart/activities/AddressCount.tsx b/src/pages/StatisticsChart/activities/AddressCount.tsx index 2247f04fa..9f012e921 100644 --- a/src/pages/StatisticsChart/activities/AddressCount.tsx +++ b/src/pages/StatisticsChart/activities/AddressCount.tsx @@ -9,7 +9,7 @@ import { ChartCachedKeys } from '../../../constants/cache' const getOption = ( statisticAddressCounts: State.StatisticAddressCount[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/activities/BalanceDistribution.tsx b/src/pages/StatisticsChart/activities/BalanceDistribution.tsx index 790af37fd..e2f5057c9 100644 --- a/src/pages/StatisticsChart/activities/BalanceDistribution.tsx +++ b/src/pages/StatisticsChart/activities/BalanceDistribution.tsx @@ -15,7 +15,7 @@ const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: string } const getOption = ( statisticBalanceDistributions: State.StatisticBalanceDistribution[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/activities/CellCount.tsx b/src/pages/StatisticsChart/activities/CellCount.tsx index 769247f61..00fbca839 100644 --- a/src/pages/StatisticsChart/activities/CellCount.tsx +++ b/src/pages/StatisticsChart/activities/CellCount.tsx @@ -24,7 +24,7 @@ const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: [string, const getOption = ( statisticCellCounts: State.StatisticCellCount[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/activities/TransactionCount.tsx b/src/pages/StatisticsChart/activities/TransactionCount.tsx index 6b8108238..b2bdba4f1 100644 --- a/src/pages/StatisticsChart/activities/TransactionCount.tsx +++ b/src/pages/StatisticsChart/activities/TransactionCount.tsx @@ -9,7 +9,7 @@ import { fetchStatisticTransactionCount } from '../../../service/http/fetcher' const getOption = ( statisticTransactionCounts: State.StatisticTransactionCount[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/activities/TxFeeHistory.tsx b/src/pages/StatisticsChart/activities/TxFeeHistory.tsx index 73bc1eae6..9cdd96b25 100644 --- a/src/pages/StatisticsChart/activities/TxFeeHistory.tsx +++ b/src/pages/StatisticsChart/activities/TxFeeHistory.tsx @@ -11,7 +11,7 @@ import { fetchStatisticTxFeeHistory } from '../../../service/http/fetcher' const getOption = ( statisticTxFeeHistories: State.StatisticTransactionFee[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/block/AverageBlockTime.tsx b/src/pages/StatisticsChart/block/AverageBlockTime.tsx index 23f5b463d..1c927bb41 100644 --- a/src/pages/StatisticsChart/block/AverageBlockTime.tsx +++ b/src/pages/StatisticsChart/block/AverageBlockTime.tsx @@ -9,7 +9,7 @@ import { ChartCachedKeys } from '../../../constants/cache' const getOption = ( statisticAverageBlockTimes: State.StatisticAverageBlockTime[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/block/BlockTimeDistribution.tsx b/src/pages/StatisticsChart/block/BlockTimeDistribution.tsx index 1451712ab..d0676b58a 100644 --- a/src/pages/StatisticsChart/block/BlockTimeDistribution.tsx +++ b/src/pages/StatisticsChart/block/BlockTimeDistribution.tsx @@ -7,7 +7,7 @@ import { fetchStatisticBlockTimeDistribution } from '../../../service/http/fetch const getOption = ( statisticBlockTimeDistributions: State.StatisticBlockTimeDistribution[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/block/EpochTimeDistribution.tsx b/src/pages/StatisticsChart/block/EpochTimeDistribution.tsx index 58958687b..8fd066415 100644 --- a/src/pages/StatisticsChart/block/EpochTimeDistribution.tsx +++ b/src/pages/StatisticsChart/block/EpochTimeDistribution.tsx @@ -9,7 +9,7 @@ import { ChartCachedKeys } from '../../../constants/cache' const getOption = ( statisticEpochTimeDistributions: State.StatisticEpochTimeDistribution[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/common/index.tsx b/src/pages/StatisticsChart/common/index.tsx index bf1a103e1..7b0423edb 100644 --- a/src/pages/StatisticsChart/common/index.tsx +++ b/src/pages/StatisticsChart/common/index.tsx @@ -21,9 +21,9 @@ import SmallLoading from '../../../components/Loading/SmallLoading' import i18n from '../../../utils/i18n' import Content from '../../../components/Content' import { useChartQueryWithCache, useIsMobile, usePrevious, useWindowResize } from '../../../utils/hook' -import { useAppState } from '../../../contexts/providers' import { isDeepEqual } from '../../../utils/util' import { HelpTip } from '../../../components/HelpTip' +import { ChartColor } from '../../../constants/common' const LoadingComp = ({ isThumbnail }: { isThumbnail?: boolean }) => (isThumbnail ? : ) @@ -160,7 +160,7 @@ export interface SmartChartPageProps { onFetched?: (dataList: T[]) => void getEChartOption: ( dataList: T[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail: boolean, ) => echarts.EChartOption @@ -183,7 +183,6 @@ export function SmartChartPage({ cacheMode = 'forever', }: SmartChartPageProps): ReactElement { const isMobile = useIsMobile() - const { app } = useAppState() const query = useChartQueryWithCache(fetchData, cacheKey, cacheMode) const dataList = useMemo(() => query.data ?? [], [query.data]) @@ -194,8 +193,8 @@ export function SmartChartPage({ }, [onFetched, query.data]) const option = useMemo( - () => getEChartOption(dataList, app.chartColor, isMobile, isThumbnail), - [app.chartColor, dataList, getEChartOption, isMobile, isThumbnail], + () => getEChartOption(dataList, ChartColor, isMobile, isThumbnail), + [dataList, getEChartOption, isMobile, isThumbnail], ) const content = query.isLoading ? ( diff --git a/src/pages/StatisticsChart/mining/Difficulty.tsx b/src/pages/StatisticsChart/mining/Difficulty.tsx index 3a47fbe10..e7ab8bfee 100644 --- a/src/pages/StatisticsChart/mining/Difficulty.tsx +++ b/src/pages/StatisticsChart/mining/Difficulty.tsx @@ -10,7 +10,7 @@ import { fetchStatisticDifficulty } from '../../../service/http/fetcher' const getOption = ( statisticDifficulties: State.StatisticDifficulty[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/mining/DifficultyHashRate.tsx b/src/pages/StatisticsChart/mining/DifficultyHashRate.tsx index c9904662c..ab5d54da4 100644 --- a/src/pages/StatisticsChart/mining/DifficultyHashRate.tsx +++ b/src/pages/StatisticsChart/mining/DifficultyHashRate.tsx @@ -9,7 +9,7 @@ import { ChartCachedKeys } from '../../../constants/cache' const getOption = ( statisticDifficultyHashRates: State.StatisticDifficultyHashRate[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/mining/DifficultyUncleRateEpoch.tsx b/src/pages/StatisticsChart/mining/DifficultyUncleRateEpoch.tsx index 5e52f24d0..0964d11f3 100644 --- a/src/pages/StatisticsChart/mining/DifficultyUncleRateEpoch.tsx +++ b/src/pages/StatisticsChart/mining/DifficultyUncleRateEpoch.tsx @@ -22,7 +22,7 @@ const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: string } const getOption = ( statisticChartData: State.StatisticDifficultyUncleRateEpoch[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/mining/HashRate.tsx b/src/pages/StatisticsChart/mining/HashRate.tsx index 328c67be7..436dce2e7 100644 --- a/src/pages/StatisticsChart/mining/HashRate.tsx +++ b/src/pages/StatisticsChart/mining/HashRate.tsx @@ -10,7 +10,7 @@ import { ChartCachedKeys } from '../../../constants/cache' const getOption = ( statisticHashRates: State.StatisticHashRate[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/mining/MinerAddressDistribution.tsx b/src/pages/StatisticsChart/mining/MinerAddressDistribution.tsx index 16f6e704c..aeb330096 100644 --- a/src/pages/StatisticsChart/mining/MinerAddressDistribution.tsx +++ b/src/pages/StatisticsChart/mining/MinerAddressDistribution.tsx @@ -22,7 +22,7 @@ const Colors = [ const getOption = ( statisticMinerAddresses: State.StatisticMinerAddress[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, getAdaptAddressText: (address: string) => string, diff --git a/src/pages/StatisticsChart/mining/MinerVersionDistribution.tsx b/src/pages/StatisticsChart/mining/MinerVersionDistribution.tsx index 3f8960501..fca6331d3 100644 --- a/src/pages/StatisticsChart/mining/MinerVersionDistribution.tsx +++ b/src/pages/StatisticsChart/mining/MinerVersionDistribution.tsx @@ -25,7 +25,7 @@ interface VersionRecord { const getOption = ( list: Array, - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/mining/UncleRate.tsx b/src/pages/StatisticsChart/mining/UncleRate.tsx index f238a3e94..dee92a51e 100644 --- a/src/pages/StatisticsChart/mining/UncleRate.tsx +++ b/src/pages/StatisticsChart/mining/UncleRate.tsx @@ -13,7 +13,7 @@ const max = (statisticUncleRates: State.StatisticUncleRate[]) => { const getOption = ( statisticUncleRates: State.StatisticUncleRate[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/monetary/AnnualPercentageCompensation.tsx b/src/pages/StatisticsChart/monetary/AnnualPercentageCompensation.tsx index d83a87f36..69fe5a806 100644 --- a/src/pages/StatisticsChart/monetary/AnnualPercentageCompensation.tsx +++ b/src/pages/StatisticsChart/monetary/AnnualPercentageCompensation.tsx @@ -7,7 +7,7 @@ import { fetchStatisticAnnualPercentageCompensation } from '../../../service/htt const getOption = ( statisticAnnualPercentageCompensations: State.StatisticAnnualPercentageCompensation[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/monetary/InflationRate.tsx b/src/pages/StatisticsChart/monetary/InflationRate.tsx index 1c1859104..33beee833 100644 --- a/src/pages/StatisticsChart/monetary/InflationRate.tsx +++ b/src/pages/StatisticsChart/monetary/InflationRate.tsx @@ -7,7 +7,7 @@ import { fetchStatisticInflationRate } from '../../../service/http/fetcher' const getOption = ( statisticInflationRates: State.StatisticInflationRate[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/monetary/Liquidity.tsx b/src/pages/StatisticsChart/monetary/Liquidity.tsx index fe03c4d7f..07b411827 100644 --- a/src/pages/StatisticsChart/monetary/Liquidity.tsx +++ b/src/pages/StatisticsChart/monetary/Liquidity.tsx @@ -9,7 +9,7 @@ import { fetchStatisticLiquidity } from '../../../service/http/fetcher' const getOption = ( statisticLiquidity: State.StatisticLiquidity[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/monetary/SecondaryIssuance.tsx b/src/pages/StatisticsChart/monetary/SecondaryIssuance.tsx index 02218f2aa..3d3bb8a1d 100644 --- a/src/pages/StatisticsChart/monetary/SecondaryIssuance.tsx +++ b/src/pages/StatisticsChart/monetary/SecondaryIssuance.tsx @@ -23,7 +23,7 @@ const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: [string, const getOption = ( statisticSecondaryIssuance: State.StatisticSecondaryIssuance[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/monetary/TotalSupply.tsx b/src/pages/StatisticsChart/monetary/TotalSupply.tsx index 5e3d3461d..1283bb809 100644 --- a/src/pages/StatisticsChart/monetary/TotalSupply.tsx +++ b/src/pages/StatisticsChart/monetary/TotalSupply.tsx @@ -28,7 +28,7 @@ const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: [string, const getOption = ( statisticTotalSupplies: State.StatisticTotalSupply[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/nervosDao/CirculationRatio.tsx b/src/pages/StatisticsChart/nervosDao/CirculationRatio.tsx index c4083051b..f48acc0ea 100644 --- a/src/pages/StatisticsChart/nervosDao/CirculationRatio.tsx +++ b/src/pages/StatisticsChart/nervosDao/CirculationRatio.tsx @@ -8,7 +8,7 @@ import { fetchStatisticCirculationRatio } from '../../../service/http/fetcher' const getOption = ( statisticCirculationRatios: State.StatisticCirculationRatio[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/nervosDao/NewDaoDeposit.tsx b/src/pages/StatisticsChart/nervosDao/NewDaoDeposit.tsx index cea097a73..94615c2f9 100644 --- a/src/pages/StatisticsChart/nervosDao/NewDaoDeposit.tsx +++ b/src/pages/StatisticsChart/nervosDao/NewDaoDeposit.tsx @@ -30,7 +30,7 @@ const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: [string, const getOption = ( statisticNewDaoDeposits: State.StatisticNewDaoDeposit[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/StatisticsChart/nervosDao/TotalDaoDeposit.tsx b/src/pages/StatisticsChart/nervosDao/TotalDaoDeposit.tsx index ee08cf6db..5f06290e7 100644 --- a/src/pages/StatisticsChart/nervosDao/TotalDaoDeposit.tsx +++ b/src/pages/StatisticsChart/nervosDao/TotalDaoDeposit.tsx @@ -30,7 +30,7 @@ const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: [string, const getOption = ( statisticTotalDaoDeposits: State.StatisticTotalDaoDeposit[], - chartColor: State.App['chartColor'], + chartColor: State.ChartColor, isMobile: boolean, isThumbnail = false, ): echarts.EChartOption => { diff --git a/src/pages/Transaction/TransactionCellScript/index.tsx b/src/pages/Transaction/TransactionCellScript/index.tsx index 117a57ea0..50c8a782d 100644 --- a/src/pages/Transaction/TransactionCellScript/index.tsx +++ b/src/pages/Transaction/TransactionCellScript/index.tsx @@ -17,10 +17,7 @@ import { TransactionDetailScriptButton, } from './styled' import i18n from '../../../utils/i18n' -import { AppDispatch } from '../../../contexts/reducer' -import { AppActions } from '../../../contexts/actions' import SmallLoading from '../../../components/Loading/SmallLoading' -import { useDispatch } from '../../../contexts/providers' import CloseIcon from '../../../assets/modal_close.png' import { getContractHashTag } from '../../../utils/util' import { localeNumberString } from '../../../utils/number' @@ -28,6 +25,7 @@ import HashTag from '../../../components/HashTag' import { ReactComponent as CopyIcon } from '../../../assets/copy_icon.svg' import { ReactComponent as OuterLinkIcon } from '../../../assets/outer_link_icon.svg' import { HelpTip } from '../../../components/HelpTip' +import { useSetToast } from '../../../components/Toast' const initScriptContent = { lock: 'null', @@ -60,7 +58,7 @@ const handleFetchCellInfo = async ( state: CellState, setScriptFetchStatus: (val: boolean) => void, setContent: Function, - dispatch: AppDispatch, + setToast: ReturnType, ) => { setScriptFetchStatus(false) @@ -94,12 +92,9 @@ const handleFetchCellInfo = async ( if (error.response && error.response.data && error.response.data[0]) { const err = error.response.data[0] if (err.status === 400 && err.code === 1022) { - dispatch({ - type: AppActions.ShowToastMessage, - payload: { - message: i18n.t('toast.data_too_large'), - type: 'warning', - }, + setToast({ + message: i18n.t('toast.data_too_large'), + type: 'warning', }) return null } @@ -244,7 +239,7 @@ const ScriptContentJson = ({ ) export default ({ cell, onClose }: { cell: State.Cell; onClose: Function }) => { - const dispatch = useDispatch() + const setToast = useSetToast() const [scriptFetched, setScriptFetched] = useState(false) const [content, setContent] = useState(null as State.Script | State.Data | CapacityUsage | null) const [state, setState] = useState(CellState.LOCK as CellState) @@ -255,18 +250,13 @@ export default ({ cell, onClose }: { cell: State.Cell; onClose: Function }) => { } useEffect(() => { - handleFetchCellInfo(cell, state, setScriptFetched, setContent, dispatch) - }, [cell, state, dispatch]) + handleFetchCellInfo(cell, state, setScriptFetched, setContent, setToast) + }, [cell, state, setToast]) const onClickCopy = () => { navigator.clipboard.writeText(updateJsonFormat(content)).then( () => { - dispatch({ - type: AppActions.ShowToastMessage, - payload: { - message: i18n.t('common.copied'), - }, - }) + setToast({ message: i18n.t('common.copied') }) }, error => { console.error(error) diff --git a/src/pages/Transaction/TransactionComp.tsx b/src/pages/Transaction/TransactionComp.tsx index 5d850dea9..91bbf97c0 100644 --- a/src/pages/Transaction/TransactionComp.tsx +++ b/src/pages/Transaction/TransactionComp.tsx @@ -4,7 +4,6 @@ import { Link } from 'react-router-dom' import BigNumber from 'bignumber.js' import { Trans } from 'react-i18next' import OverviewCard, { OverviewItemData } from '../../components/Card/OverviewCard' -import { useAppState } from '../../contexts/providers/index' import { parseSimpleDate } from '../../utils/date' import i18n from '../../utils/i18n' import { localeNumberString } from '../../utils/number' @@ -28,6 +27,7 @@ import HashTag from '../../components/HashTag' import { useAddrFormatToggle } from '../../utils/hook' import ComparedToMaxTooltip from '../../components/Tooltip/ComparedToMaxTooltip' import { HelpTip } from '../../components/HelpTip' +import { useLatestBlockNumber } from '../../services/ExplorerService' const showTxStatus = (txStatus: string) => txStatus?.replace(/^\S/, s => s.toUpperCase()) ?? '-' @@ -109,9 +109,7 @@ const TransactionInfoItemWrapper = ({ export const TransactionOverview: FC<{ transaction: State.Transaction }> = ({ transaction }) => { const [showParams, setShowParams] = useState(false) - const { - app: { tipBlockNumber }, - } = useAppState() + const tipBlockNumber = useLatestBlockNumber() const { blockNumber, cellDeps, diff --git a/src/pages/Transaction/index.tsx b/src/pages/Transaction/index.tsx index d32b4dff7..389362112 100644 --- a/src/pages/Transaction/index.tsx +++ b/src/pages/Transaction/index.tsx @@ -1,19 +1,15 @@ -import { useEffect } from 'react' import { useParams } from 'react-router-dom' import { useQuery } from 'react-query' import TransactionHashCard from '../../components/Card/HashCard' import Content from '../../components/Content' -import { getTipBlockNumber } from '../../service/app/address' import i18n from '../../utils/i18n' import { TransactionDiv as TransactionPanel } from './styled' import TransactionComp, { TransactionOverview } from './TransactionComp' -import { useDispatch } from '../../contexts/providers' import { fetchTransactionByHash } from '../../service/http/fetcher' import { QueryResult } from '../../components/QueryResult' import { defaultTransactionInfo } from './state' export default () => { - const dispatch = useDispatch() const { hash: txHash } = useParams<{ hash: string }>() const query = useQuery(['transaction', txHash], async () => { @@ -27,8 +23,6 @@ export default () => { const transaction = query.data ?? defaultTransactionInfo const { blockTimestamp, txStatus } = transaction - useEffect(() => getTipBlockNumber(dispatch), [dispatch]) - return ( diff --git a/src/routes/index.tsx b/src/routes/index.tsx index e81b25a9b..1e08bbb1a 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -1,15 +1,10 @@ -import { useEffect, useRef, Suspense, lazy, Component } from 'react' +import { useEffect, Suspense, lazy, Component } from 'react' import { BrowserRouter as Router, Route, Redirect, Switch, useLocation } from 'react-router-dom' import { createBrowserHistory } from 'history' import Page from '../components/Page' import Header from '../components/Header' import Footer from '../components/Footer' -import Sheet from '../components/Sheet' -import { useDispatch, useAppState } from '../contexts/providers' -import { ComponentActions } from '../contexts/actions' -import { useIsMobile } from '../utils/hook' import { isChainTypeError } from '../utils/chain' -import Alert from '../components/Alert' const Home = lazy(() => import('../pages/Home')) const Block = lazy(() => import('../pages/BlockDetail')) @@ -341,25 +336,6 @@ const useRouter = (callback: Function) => { }, [callback, history]) } -const useRouterLocation = (callback: () => void) => { - const history = createBrowserHistory() - const savedCallback = useRef(() => {}) - useEffect(() => { - savedCallback.current = callback - }) - useEffect(() => { - const currentCallback = () => { - savedCallback.current() - } - const listen = history.listen(() => { - currentCallback() - }) - return () => { - listen() - } - }, [history]) -} - const RouterComp = ({ container, routeProps }: { container: CustomRouter.Route; routeProps: any }) => { const { pathname = '' } = useLocation() if (container.name === 'Address' && isChainTypeError(pathname.substring(pathname.lastIndexOf('/') + 1))) { @@ -417,34 +393,16 @@ class PageErrorBoundary extends Component { - const isMobile = useIsMobile() - const dispatch = useDispatch() - const { components } = useAppState() - const { mobileMenuVisible } = components - useRouter(() => { window.scrollTo(0, 0) }) - useRouterLocation(() => { - if (mobileMenuVisible) { - dispatch({ - type: ComponentActions.UpdateHeaderMobileMenuVisible, - payload: { - mobileMenuVisible: false, - }, - }) - } - }) - return ( ( -
- }> @@ -458,7 +416,7 @@ export default () => { - {!(isMobile && mobileMenuVisible) &&