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: refresh scores once proposal is closed #1077

Merged
merged 9 commits into from
Jan 6, 2025
Merged

Conversation

ChaituVR
Copy link
Member

@ChaituVR ChaituVR commented Jan 3, 2025

Summary

Closes: https://github.com/snapshot-labs/workflow/issues/347

How to test

  1. Create a proposal with shutter
  2. Before the fix, you will see finalizing results message forever
  3. Now, we send a request to our API to refresh scores and once it is successful we will refresh the page
  4. You should see the results

@ChaituVR ChaituVR requested a review from bonustrack January 3, 2025 18:44
@ChaituVR ChaituVR requested review from wa0x6e and Sekhmet January 6, 2025 05:45
Copy link
Member

@Sekhmet Sekhmet left a comment

Choose a reason for hiding this comment

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

Other than that it looks good to me.

apps/ui/src/components/ProposalResults.vue Outdated Show resolved Hide resolved
apps/ui/src/components/ProposalResults.vue Outdated Show resolved Hide resolved
@ChaituVR ChaituVR requested a review from Sekhmet January 6, 2025 10:20
Copy link
Member

@Sekhmet Sekhmet left a comment

Choose a reason for hiding this comment

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

Can we move this function to where it usually is (after computed, above lifecycle methods)?

Also what do you think about refetching proposal instead of triggering hard page reload?

diff --git a/apps/ui/src/components/ProposalResults.vue b/apps/ui/src/components/ProposalResults.vue
index 702f0cd2..34bf3f17 100644
--- a/apps/ui/src/components/ProposalResults.vue
+++ b/apps/ui/src/components/ProposalResults.vue
@@ -13,21 +13,6 @@ const DEFAULT_MAX_CHOICES = 6;
 
 const SHUTTER_URL = 'https://www.shutter.network/shielded-voting';
 
-async function refreshScores() {
-  try {
-    const network = getNetwork(props.proposal.network);
-    const hubUrl = network.api.apiUrl.replace('/graphql', '');
-    const response = await fetch(`${hubUrl}/api/scores/${props.proposal.id}`);
-    const result = await response.json();
-
-    if (result.result === true) {
-      window.location.reload();
-    }
-  } catch (e) {
-    console.warn('Failed to refresh scores', e);
-  }
-}
-
 const props = withDefaults(
   defineProps<{
     proposal: ProposalType;
@@ -42,6 +27,8 @@ const props = withDefaults(
   }
 );
 
+const proposalsStore = useProposalsStore();
+
 const displayAllChoices = ref(false);
 
 const totalProgress = computed(() => quorumProgress(props.proposal));
@@ -111,6 +98,26 @@ const isFinalizing = computed(() => {
   );
 });
 
+async function refreshScores() {
+  try {
+    const network = getNetwork(props.proposal.network);
+    const hubUrl = network.api.apiUrl.replace('/graphql', '');
+    const response = await fetch(`${hubUrl}/api/scores/${props.proposal.id}`);
+    const result = await response.json();
+
+    if (result.result === true) {
+      proposalsStore.reset(props.proposal.space.id, props.proposal.network);
+      await proposalsStore.fetchProposal(
+        props.proposal.space.id,
+        props.proposal.id,
+        props.proposal.network
+      );
+    }
+  } catch (e) {
+    console.warn('Failed to refresh scores', e);
+  }
+}
+
 onMounted(() => {
   if (offchainNetworks.includes(props.proposal.network) && isFinalizing.value) {
     refreshScores();

@ChaituVR
Copy link
Member Author

ChaituVR commented Jan 6, 2025

Also what do you think about refetching proposal instead of triggering hard page reload?

Nice idea

@ChaituVR ChaituVR requested a review from Sekhmet January 6, 2025 12:06
Copy link
Member

@Sekhmet Sekhmet left a comment

Choose a reason for hiding this comment

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

partial tACK (haven't tested on actual isFinalizing proposal).

@ChaituVR ChaituVR merged commit e79b4ef into master Jan 6, 2025
2 checks passed
@ChaituVR ChaituVR deleted the fix-refresh-scores branch January 6, 2025 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants