From d7eed4262e0a024b7915d1c559bbcf012bfd3e5e Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Fri, 27 May 2022 19:28:20 +1000 Subject: [PATCH] fix: governance 404 page --- components/governance/Metrics.vue | 4 +- components/governance/Proposal.vue | 10 ++- .../icons/{Error404Icon.vue => ErrorIcon.vue} | 61 +++++++++++-------- components/icons/index.js | 2 +- langs/en.json | 9 ++- layouts/error.vue | 61 +++++++++++++++---- pages/governance.vue | 10 +-- pages/governance/_id.vue | 4 +- 8 files changed, 114 insertions(+), 47 deletions(-) rename components/icons/{Error404Icon.vue => ErrorIcon.vue} (78%) diff --git a/components/governance/Metrics.vue b/components/governance/Metrics.vue index 9dc8e52..1761fd6 100644 --- a/components/governance/Metrics.vue +++ b/components/governance/Metrics.vue @@ -60,7 +60,7 @@ export default { balance: (state) => fromWei(state.balance) }), ...mapState('governance/gov', ['lockedBalance', 'delegatedBalance']), - ...mapGetters('governance/gov', ['isFetchingBalances']), + ...mapGetters('governance/gov', ['isFetchingBalances', 'isEnabledGovernance']), ...mapGetters('governance/staking', ['reward', 'isCheckingReward']), ...mapGetters('token', ['toDecimals']), ...mapState('metamask', ['isInitialized']), @@ -74,7 +74,7 @@ export default { watch: { isInitialized: { handler(isInitialized) { - if (isInitialized) { + if (isInitialized && this.isEnabledGovernance) { this.checkReward() this.fetchTokenBalance() this.fetchTokenAllowance() diff --git a/components/governance/Proposal.vue b/components/governance/Proposal.vue index f843e04..eb75c09 100644 --- a/components/governance/Proposal.vue +++ b/components/governance/Proposal.vue @@ -188,7 +188,13 @@ export default { ...mapState('metamask', ['ethAccount', 'isInitialized']), ...mapGetters('txHashKeeper', ['addressExplorerUrl']), ...mapGetters('metamask', ['networkConfig']), - ...mapGetters('governance/gov', ['votingPower', 'constants', 'votingPeriod', 'isFetchingBalances']), + ...mapGetters('governance/gov', [ + 'votingPower', + 'constants', + 'votingPeriod', + 'isFetchingBalances', + 'isEnabledGovernance' + ]), readyForAction() { return ( this.data.status !== 'active' || @@ -219,7 +225,7 @@ export default { watch: { isInitialized: { handler(isInitialized) { - if (isInitialized) { + if (isInitialized && this.isEnabledGovernance) { this.fetchReceipt({ id: this.data.id }) } }, diff --git a/components/icons/Error404Icon.vue b/components/icons/ErrorIcon.vue similarity index 78% rename from components/icons/Error404Icon.vue rename to components/icons/ErrorIcon.vue index 74c8e03..45c48ca 100644 --- a/components/icons/Error404Icon.vue +++ b/components/icons/ErrorIcon.vue @@ -1,28 +1,30 @@ - diff --git a/pages/governance.vue b/pages/governance.vue index 31e4df2..7f87400 100644 --- a/pages/governance.vue +++ b/pages/governance.vue @@ -12,7 +12,7 @@ import Metrics from '@/components/governance/Metrics' export default { middleware({ store, error }) { if (!store.getters['governance/gov/isEnabledGovernance']) { - return error({ statusCode: 404 }) + return error({ statusCode: 204, pageName: 'governance' }) } }, components: { @@ -25,14 +25,16 @@ export default { watch: { isInitialized: { handler() { - this.fetchProposals({}) - this.fetchConstants() + if (this.isEnabledGovernance) { + this.fetchProposals({}) + this.fetchConstants() + } }, immediate: true }, isEnabledGovernance(isEnabled) { if (!isEnabled) { - this.$router.push('/') + this.$nuxt.error({ statusCode: 204, pageName: 'governance' }) } } }, diff --git a/pages/governance/_id.vue b/pages/governance/_id.vue index 44d5cc3..ae5c40c 100644 --- a/pages/governance/_id.vue +++ b/pages/governance/_id.vue @@ -21,7 +21,7 @@ export default { }, computed: { ...mapState('governance/gov', ['proposals']), - ...mapGetters('governance/gov', ['isFetchingProposals']), + ...mapGetters('governance/gov', ['isFetchingProposals', 'isEnabledGovernance']), ...mapState('metamask', ['isInitialized']), proposal() { return this.proposals[this.$route.params.id - 1] @@ -30,7 +30,7 @@ export default { watch: { isInitialized: { handler(isInitialized) { - if (isInitialized) { + if (isInitialized && this.isEnabledGovernance) { this.fetchBalances() this.fetchedLockedTimestamp() this.fetchDelegatee()