Skip to content

Commit

Permalink
Show meaningful error when votes download is failing on the demo webs…
Browse files Browse the repository at this point in the history
…ite (snapshot-labs#4070)

* fix: show meaningful error when votes download is failing on the demo website

* fix: fix wrong import

* fix: fix wording to reflect unavailability on env and not network

* Trigger deploy

---------

Co-authored-by: Sam <[email protected]>
  • Loading branch information
wa0x6e and samuveth authored Jul 14, 2023
1 parent 0e1ebd9 commit dd8c51e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ node_modules
components.d.ts
auto-imports.d.ts

# local env files
# local env file
.env.local
.env.*.local

Expand Down
13 changes: 8 additions & 5 deletions src/components/SpaceProposalVotesList.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { ExtendedSpace, Proposal } from '@/helpers/interfaces';
import camelCase from 'lodash/camelCase';
const props = defineProps<{
space: ExtendedSpace;
Expand Down Expand Up @@ -31,11 +32,13 @@ async function downloadReport(proposalId: string) {
}
const errorMessagekeyPrefix = computed(() => {
return `proposal.downloadCsvVotes.postDownloadModal.message.${
errorCode?.value?.message === 'PENDING_GENERATION'
? 'pendingGeneration'
: 'unknownError'
}`;
const knownErrors = ['PENDING_GENERATION', 'UNSUPPORTED_ENV'];
return `proposal.downloadCsvVotes.postDownloadModal.message.${camelCase(
knownErrors.includes(errorCode?.value?.message as string)
? errorCode?.value?.message
: 'UNKNOWN_ERROR'
)}`;
});
onMounted(async () => {
Expand Down
6 changes: 6 additions & 0 deletions src/composables/useReportDownload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pkg from '@/../package.json';

export function useReportDownload() {
const { env } = useApp();
const isDownloadingVotes = ref(false);
const errorCode: globalThis.Ref<null | Error> = ref(null);

Expand All @@ -18,6 +19,11 @@ export function useReportDownload() {
}

async function downloadVotes(proposalId: string) {
if (env === 'demo') {
errorCode.value = new Error('UNSUPPORTED_ENV');
return false;
}

isDownloadingVotes.value = true;
errorCode.value = null;

Expand Down
4 changes: 4 additions & 0 deletions src/locales/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@
"title": "Your report is currently being generated",
"description": "It may take a few minutes. Please check back shortly."
},
"unsupportedEnv": {
"title": "Unsupported environment",
"description": "Votes report are not available on demo."
},
"unknownError": {
"title": "We're having trouble connecting to the server responsible for downloads",
"description": "Please try again in a few moments. If the problem persists, consider contacting our support team."
Expand Down

0 comments on commit dd8c51e

Please sign in to comment.