Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create date start and end #2631

Closed
wants to merge 6 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions src/views/SpaceCreate.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, computed, onMounted, inject, watch } from 'vue';
import { ref, computed, onMounted, inject, watch, onBeforeUnmount } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { useI18n } from '@/composables/useI18n';
import { clone } from '@snapshot-labs/snapshot.js/src/utils';
Expand All @@ -17,10 +17,13 @@ import { usePlugins } from '@/composables/usePlugins';
import { ExtendedSpace } from '@/helpers/interfaces';
import { useSpaceCreateForm } from '@/composables/useSpaceCreateForm';

const BODY_LIMIT_CHARACTERS = 14400;

const props = defineProps<{
space: ExtendedSpace;
}>();

const notify: any = inject('notify');
const router = useRouter();
const route = useRoute();
const { t, setPageTitle } = useI18n();
Expand All @@ -29,43 +32,53 @@ const { domain } = useApp();
const { web3, web3Account } = useWeb3();
const { send, clientLoading } = useClient();
const { pluginIndex } = usePlugins();
const { modalAccountOpen } = useModal();
const { modalTermsOpen, termsAccepted, acceptTerms } = useTerms(props.space.id);
const {
form,
userSelectedDateEnd,
userSelectedDateStart,
sourceProposalLoaded,
sourceProposal,
resetForm
} = useSpaceCreateForm();
const { modalAccountOpen } = useModal();
const { modalTermsOpen, termsAccepted, acceptTerms } = useTerms(props.space.id);

const notify: any = inject('notify');

const passValidation = ref([false, '']);
const validationLoading = ref(false);
const timeSeconds = ref(Number((Date.now() / 1e3).toFixed()));

const BODY_LIMIT_CHARACTERS = 14400;

const proposal = computed(() =>
Object.assign(form.value, { choices: form.value.choices })
);
// Timestamp updated every second
const currentTimeSeconds = ref(Number((Date.now() / 1e3).toFixed()));
function updateCurrentTime() {
currentTimeSeconds.value = Number((Date.now() / 1e3).toFixed());
}
const updateTimeInterval = setInterval(updateCurrentTime, 1000);
onBeforeUnmount(() => {
clearInterval(updateTimeInterval);
});

const dateStart = computed(() => {
return props.space?.voting?.delay
? timeSeconds.value + props.space.voting.delay
: form.value.start;
? currentTimeSeconds.value + props.space.voting.delay
: (userSelectedDateStart.value || sourceProposalLoaded.value) &&
form.value.start >= currentTimeSeconds.value
? form.value.start
: currentTimeSeconds.value;
});

const dateEnd = computed(() => {
const threeDays = 259200;
return props.space?.voting?.period
? dateStart.value + props.space.voting.period
: userSelectedDateEnd.value || sourceProposalLoaded.value
: (userSelectedDateEnd.value || sourceProposalLoaded.value) &&
form.value.end > dateStart.value
? form.value.end
: dateStart.value + threeDays;
});

const proposal = computed(() =>
Object.assign(form.value, { choices: form.value.choices })
);

const isValid = computed(() => {
const isSafeSnapPluginValid = form.value.metadata.plugins?.safeSnap
? form.value.metadata.plugins.safeSnap.valid
Expand All @@ -76,6 +89,7 @@ const isValid = computed(() => {
form.value.body.length <= BODY_LIMIT_CHARACTERS &&
dateEnd.value &&
dateEnd.value > dateStart.value &&
dateStart.value >= currentTimeSeconds.value &&
form.value.snapshot &&
form.value.choices.length >= 1 &&
!form.value.choices.some((a, i) => a.text === '' && i === 0) &&
Expand Down Expand Up @@ -119,7 +133,6 @@ function getFormattedForm() {
clonedForm.choices = form.value.choices
.map(choice => choice.text)
.filter(choiceText => choiceText.length > 0);
updateTime();
clonedForm.start = dateStart.value;
clonedForm.end = dateEnd.value;
return clonedForm;
Expand Down Expand Up @@ -196,10 +209,6 @@ function previosStep() {
});
}

function updateTime() {
timeSeconds.value = Number((Date.now() / 1e3).toFixed());
}

// Check if account passes space validation
// (catch errors to show confiuration error message)
const executingValidationFailed = ref(false);
Expand Down