Skip to content

Commit

Permalink
feat: add support for hibernated spaces (#4350)
Browse files Browse the repository at this point in the history
* feat: disable proposal creation on hibernate spaces

* fix: add button to reactivate space

* fix: add link to hibernation doc

* fix: add translations

* chore: fix formatting

* refactor: extract hibernation warning message to its own component

* feat: reactivate space via sequencer

* chore: formatting fix

* fix: show success message on space reactivation

* fix: add link to doc

* chore: fix formatting

* fix: use settings basic update to reactivate space

* chore: fix formatting

* fix: redirect reactivate space CTA to settings page

* fix: update hibernated warning message

* feat: add space reactivation message in space settings

* Update src/components/MessageWarningHibernated.vue

Co-authored-by: Sam <51686767+samuveth@users.noreply.github.com>

* fix: increase warning level to red

* fix: remove title and change layout

* fix: "learn more" should only visible to admin/controller

* refactor: extract message into its own components

* Update src/locales/default.json

* Fixes

* Update src/locales/default.json

---------

Co-authored-by: Sam <51686767+samuveth@users.noreply.github.com>
Co-authored-by: Sam <samuv.eth@gmail.com>
Co-authored-by: Chaitanya <yourchaitu@gmail.com>
  • Loading branch information
4 people authored Nov 17, 2023
1 parent 495fe60 commit 89c2314
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 11 deletions.
43 changes: 43 additions & 0 deletions src/components/MessageWarningHibernated.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<script setup lang="ts">
import { ExtendedSpace } from '@/helpers/interfaces';
const props = defineProps<{
space: ExtendedSpace;
}>();
const { web3Account } = useWeb3();
const { loadSpaceController, isSpaceController } = useSpaceController();
const isAuthorized = computed(() => {
const admins = (props.space.admins || []).map(admin => admin.toLowerCase());
return (
admins.includes(web3Account.value?.toLowerCase()) || isSpaceController.value
);
});
onMounted(async () => {
await loadSpaceController();
});
</script>

<template>
<BaseMessageBlock v-if="space.hibernated" level="warning-red" is-responsive>
{{
isAuthorized
? $t('create.errorSpaceHibernatedAdmin')
: $t('create.errorSpaceHibernatedUsers')
}}
<BaseLink
v-if="isAuthorized"
link="https://docs.snapshot.org/user-guides/spaces/space-hibernation"
>
{{ $t('learnMore') }}
</BaseLink>

<p v-if="isAuthorized" class="mt-3">
<router-link :to="{ name: 'spaceSettings' }">
<BaseButton> Go to Settings </BaseButton>
</router-link>
</p>
</BaseMessageBlock>
</template>
4 changes: 3 additions & 1 deletion src/components/SpaceCreateWarnings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ const strategySymbolsString = computed(() => {

<template>
<div class="mb-4 space-y-2">
<MessageWarningHibernated v-if="space.hibernated" :space="space" />

<MessageWarningGnosisNetwork
v-if="isGnosisAndNotSpaceNetwork"
v-else-if="isGnosisAndNotSpaceNetwork"
:space="space"
action="create"
is-responsive
Expand Down
37 changes: 37 additions & 0 deletions src/components/SpaceSettingsMessageHibernated.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script setup lang="ts">
import { ExtendedSpace } from '@/helpers/interfaces';
defineProps<{
space: ExtendedSpace;
isSending: boolean;
isValid: boolean;
}>();
const emit = defineEmits(['showErrors', 'reactivateSpace']);
onMounted(() => {
emit('showErrors');
});
</script>

<template>
<BaseMessageBlock level="warning-red" is-responsive>
<div v-if="isValid">
{{ $t('settings.reactivatingHibernatedSpace.information') }}
</div>

<div v-else>
{{ $t('settings.reactivatingHibernatedSpace.disabledInformation') }}
</div>

<BaseButton
primary
:loading="isSending"
:disabled="!isValid"
class="mt-3 whitespace-nowrap"
@click="emit('reactivateSpace')"
>
{{ $t('reactivateSpace') }}
</BaseButton>
</BaseMessageBlock>
</template>
14 changes: 14 additions & 0 deletions src/composables/useClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ export function useClient() {
proposalId: payload.proposal.id
});

return receipt;
} else if (type === 'reactivate-space') {
const receipt = await client.reactivateSpace(
auth.web3,
web3.value.account,
{
space: space.id
}
);

mixpanel.track('Reactivate space', {
space: space.id
});

return receipt;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/composables/useFormSpaceSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export function useFormSpaceSettings(context: 'setup' | 'settings') {
delete formData.followersCount;
delete formData.verified;
delete formData.flagged;
delete formData.hibernated;

if (formData.filters.invalids) delete formData.filters.invalids;
}
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export interface Space {
activeProposals: number;
followersCount: number;
flagged: boolean;
hibernated: boolean;
terms: string;
}

Expand Down Expand Up @@ -165,6 +166,7 @@ export interface ExtendedSpace {
guidelines: string;
verified: boolean;
flagged: boolean;
hibernated: boolean;
voting: {
delay: number | null;
hideAbstain: boolean;
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ export const SPACES_QUERY = gql`
followersCount
terms
flagged
hibernated
}
}
`;
Expand Down Expand Up @@ -452,6 +453,7 @@ export const SPACE_QUERY = gql`
guidelines
verified
flagged
hibernated
parent {
id
name
Expand Down
12 changes: 10 additions & 2 deletions src/locales/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
"createASpace": "Create a space",
"getStarted": "Get started",
"skip": "Skip",
"reactivateSpace": "Reactivate space",
"newSpaceNotice": {
"header": "Your space is live!",
"mainText": "You can change how voting power is calculated via strategies in your {settings}. Changes to your settings will only affect new proposals, existing proposals can not be changed.",
Expand Down Expand Up @@ -235,7 +236,9 @@
"uploading": "Uploading image",
"markdown": "Styling with Markdown is supported",
"errorGettingSnapshot": "We encountered an error while fetching the snapshot block number which is needed to calculate your voting power. Please try again later.",
"errorTimeInPast": "Entered time is in the past. Please select a future time."
"errorTimeInPast": "Entered time is in the past. Please select a future time.",
"errorSpaceHibernatedAdmin": "Admins your attention is required. This space has been hibernated due to a lack of activity, and as a result, proposal creation is currently disabled. To re-enable your space, please go to the settings page and click \"Reactivate\".",
"errorSpaceHibernatedUsers": "This space has been hibernated due to a lack of activity. As a result, the creation of proposals has been temporarily disabled. To resume your ability to create proposals, the space needs to be reactivated by an admin. Please check back later or contact your space admin for further information."
},
"delegates": {
"header": "Delegates",
Expand Down Expand Up @@ -534,6 +537,10 @@
"delegationPortal": {
"title": "Delegation portal",
"information": "Please ensure your token adheres to a compatible delegation standard to enable delegate discovery and activity within your Snapshot space."
},
"reactivatingHibernatedSpace": {
"information": "Your space is currently in hibernation due to six months of inactivity. To re-enable proposal creation, please click the button below to reactivate your space. There are no penalties for hibernation, but the space will remain inactive for proposal creation until reactivation by an admin.",
"disabledInformation": "Your space contains invalid settings since your last update. Fix the errors below and your space will be reactivated automatically upon save."
}
},
"setup": {
Expand Down Expand Up @@ -652,7 +659,8 @@
"ensSet": "ENS text record was successfully set",
"transactionSent": "Transaction sent",
"emailPreferencesUpdated": "Email preferences updated",
"delegationAdded": "Well done. Delegate was successfully added"
"delegationAdded": "Well done. Delegate was successfully added",
"spaceReactivated": "The space has been reactivated"
},
"explore": {
"createStrategy": "Create strategy",
Expand Down
3 changes: 2 additions & 1 deletion src/views/SpaceCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ onBeforeRouteLeave(async () => {
web3.authLoading ||
hasAuthorValidationFailed ||
validationLoading ||
isGnosisAndNotSpaceNetwork
isGnosisAndNotSpaceNetwork ||
space.hibernated
"
primary
:data-testid="
Expand Down
23 changes: 16 additions & 7 deletions src/views/SpaceSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,6 @@ async function handleSubmit() {
}
}
onMounted(async () => {
populateForm(props.space);
await loadEnsOwner();
await loadSpaceController();
loaded.value = true;
});
const {
isRevealed: isConfirmLeaveOpen,
reveal: openConfirmLeave,
Expand All @@ -172,6 +165,13 @@ const isViewOnly = computed(() => {
return !(isSpaceController.value || isSpaceAdmin.value);
});
onMounted(async () => {
populateForm(props.space);
await loadEnsOwner();
await loadSpaceController();
loaded.value = true;
});
onBeforeRouteLeave(async () => {
if (hasFormChanged.value && !isViewOnly.value) {
const { data } = await openConfirmLeave();
Expand All @@ -190,6 +190,15 @@ onBeforeRouteLeave(async () => {

<template v-else>
<div class="mt-3 space-y-3 sm:mt-0">
<SpaceSettingsMessageHibernated
v-if="space.hibernated && !isViewOnly"
:space="space"
:is-sending="isSending"
:is-valid="isValid"
@show-errors="showFormErrors = true"
@reactivate-space="handleSubmit"
/>

<BaseMessageBlock
v-if="showFormErrors && Object.keys(validationErrors).length"
level="warning-red"
Expand Down

1 comment on commit 89c2314

@vercel
Copy link

@vercel vercel bot commented on 89c2314 Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.