From e40b2d584de594fd728804b329b9f087ecaba736 Mon Sep 17 00:00:00 2001 From: Less Date: Mon, 30 Sep 2024 08:03:37 +0700 Subject: [PATCH 1/6] chore: keep default strategies sorting --- src/composables/useStrategies.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/composables/useStrategies.ts b/src/composables/useStrategies.ts index 718a42f4a5f6..cc5f9bbe17d2 100644 --- a/src/composables/useStrategies.ts +++ b/src/composables/useStrategies.ts @@ -23,8 +23,7 @@ export function useStrategies() { const filterStrategies = (q = '') => strategies.value - .filter(s => s.id.toLowerCase().includes(q.toLowerCase())) - .sort((a, b) => b.spacesCount - a.spacesCount); + .filter(s => s.id.toLowerCase().includes(q.toLowerCase())); const { apolloQuery } = useApolloQuery(); From cbebadbde9d1299a67e9318873790e8059308db7 Mon Sep 17 00:00:00 2001 From: Wan <495709+wa0x6e@users.noreply.github.com> Date: Mon, 30 Sep 2024 17:03:41 +0900 Subject: [PATCH 2/6] fix: fix search request not being resolved in order (#4896) --- src/views/SpaceDelegates.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/SpaceDelegates.vue b/src/views/SpaceDelegates.vue index 8cfb0b8c8d60..2b7b339820de 100644 --- a/src/views/SpaceDelegates.vue +++ b/src/views/SpaceDelegates.vue @@ -130,8 +130,8 @@ useInfiniteScroll( { distance: 500 } ); -watch(searchInputDebounced, () => { - loadDelegate(searchInput.value); +watch(searchInputDebounced, async () => { + await loadDelegate(searchInput.value); }); watch(matchFilter, () => { From 1f23609fe1ba6aa4f743cf564c09f03e2c034149 Mon Sep 17 00:00:00 2001 From: Wan <495709+wa0x6e@users.noreply.github.com> Date: Mon, 30 Sep 2024 17:03:53 +0900 Subject: [PATCH 3/6] feat: load delegate stats (#4895) --- src/components/SpaceDelegatesCard.vue | 12 ++++----- src/composables/useDelegates.ts | 37 +++++++++++++++++++-------- src/helpers/queries.ts | 12 +++++++++ src/views/SpaceDelegate.vue | 7 ++--- 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/components/SpaceDelegatesCard.vue b/src/components/SpaceDelegatesCard.vue index 11e3699867ee..b19beb005e5f 100644 --- a/src/components/SpaceDelegatesCard.vue +++ b/src/components/SpaceDelegatesCard.vue @@ -3,9 +3,7 @@ import { explorerUrl } from '@/helpers/utils'; import { DelegateWithPercent, Profile, - ExtendedSpace, - DelegatesVote, - DelegatesProposal + ExtendedSpace } from '@/helpers/interfaces'; const props = defineProps<{ @@ -13,8 +11,8 @@ const props = defineProps<{ profiles: Record; space: ExtendedSpace; stats?: { - votes: DelegatesVote[]; - proposals: DelegatesProposal[]; + votes: number; + proposals: number; }; about?: string; }>(); @@ -134,12 +132,12 @@ function handleDropdownAction(action: string) {
- {{ formatCompactNumber(stats?.votes.length || 0) }} + {{ formatCompactNumber(stats?.votes || 0) }} votes
ยท
- {{ formatCompactNumber(stats?.proposals.length || 0) }} + {{ formatCompactNumber(stats?.proposals || 0) }} proposals
diff --git a/src/composables/useDelegates.ts b/src/composables/useDelegates.ts index edbaba9fe2a7..72f5e2654f9e 100644 --- a/src/composables/useDelegates.ts +++ b/src/composables/useDelegates.ts @@ -1,25 +1,19 @@ +import { LEADERBOARD_QUERY } from '@/helpers/queries'; import { getInstance } from '@snapshot-labs/lock/plugins/vue3'; -import { - DelegateWithPercent, - DelegatesVote, - DelegatesProposal, - ExtendedSpace -} from '@/helpers/interfaces'; +import { DelegateWithPercent, ExtendedSpace } from '@/helpers/interfaces'; import { DelegationTypes, setupDelegation as getDelegationAdapter } from '@/helpers/delegationV2'; -type DelegatesStats = Record< - string, - { votes: DelegatesVote[]; proposals: DelegatesProposal[] } ->; +type DelegatesStats = Record; const DELEGATES_LIMIT = 18; export function useDelegates(space: ExtendedSpace) { const auth = getInstance(); const { resolveName } = useResolveName(); + const { apolloQuery } = useApolloQuery(); const { reader, writer } = getDelegationAdapter(space, auth); @@ -54,6 +48,7 @@ export function useDelegates(space: ExtendedSpace) { try { const response = await fetchDelegateBatch(orderBy); delegates.value = response; + loadStats(response.map(d => d.id)); hasMoreDelegates.value = response.length === DELEGATES_LIMIT; } catch (e) { console.error(e); @@ -73,6 +68,7 @@ export function useDelegates(space: ExtendedSpace) { orderBy, delegates.value.length ); + loadStats(response.map(d => d.id)); delegates.value = [...delegates.value, ...response]; hasMoreDelegates.value = response.length === DELEGATES_LIMIT; } catch (e) { @@ -93,6 +89,7 @@ export function useDelegates(space: ExtendedSpace) { const resolvedAddress = await resolveName(addressOrEns); if (!resolvedAddress) return; const response = await reader.getDelegate(resolvedAddress); + loadStats([response.id]); delegate.value = response; } catch (e) { console.error(e); @@ -140,6 +137,26 @@ export function useDelegates(space: ExtendedSpace) { } } + async function loadStats(addresses: string[]) { + const leaderboards = await apolloQuery( + { + query: LEADERBOARD_QUERY, + variables: { + space: space.id, + user_in: addresses + } + }, + 'leaderboards' + ); + + leaderboards.forEach(leaderboard => { + delegatesStats.value[leaderboard.user] = { + votes: leaderboard.votesCount, + proposals: leaderboard.proposalsCount + }; + }); + } + return { isLoadingDelegate, isLoadingDelegates, diff --git a/src/helpers/queries.ts b/src/helpers/queries.ts index 834d86a13c42..09773dfd7ee5 100644 --- a/src/helpers/queries.ts +++ b/src/helpers/queries.ts @@ -529,3 +529,15 @@ export const SPACE_QUERY = gql` } } `; + +export const LEADERBOARD_QUERY = gql` + query Leaderboard($space: String!, $user_in: [String]) { + leaderboards(where: { space: $space, user_in: $user_in }) { + space + user + proposalsCount + votesCount + lastVote + } + } +`; diff --git a/src/views/SpaceDelegate.vue b/src/views/SpaceDelegate.vue index b2d26450ca1c..c0b4185fc309 100644 --- a/src/views/SpaceDelegate.vue +++ b/src/views/SpaceDelegate.vue @@ -4,6 +4,7 @@ import { useConfirmDialog } from '@vueuse/core'; import { clone } from '@snapshot-labs/snapshot.js/src/utils'; import { DelegatingTo } from '../helpers/delegationV2/types'; import { DelegationTypes } from '@/helpers/delegationV2'; +import { getAddress } from '@ethersproject/address'; const INITIAL_STATEMENT = { about: '', @@ -67,7 +68,7 @@ const showUndelegate = computed(() => { }); const delegateStats = computed(() => { - return delegatesStats.value?.[address.value]; + return delegatesStats.value?.[getAddress(address.value)]; }); const delegatorItems = computed(() => { @@ -88,12 +89,12 @@ const delegatorItems = computed(() => { }, { label: 'Proposals', - value: formatCompactNumber(delegateStats.value?.proposals.length || 0), + value: formatCompactNumber(delegateStats.value?.proposals || 0), tooltip: null }, { label: 'Votes', - value: formatCompactNumber(delegateStats.value?.votes.length || 0), + value: formatCompactNumber(delegateStats.value?.votes || 0), tooltip: null } ]; From 4a52af59e482a4924d3d02d11380411821cb2093 Mon Sep 17 00:00:00 2001 From: Wan <495709+wa0x6e@users.noreply.github.com> Date: Mon, 30 Sep 2024 17:04:26 +0900 Subject: [PATCH 4/6] fix: fix stamp avatar case sensitiveness (#4893) --- src/components/AvatarUser.vue | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/AvatarUser.vue b/src/components/AvatarUser.vue index 07bc78c5c5d0..772a7d667e76 100644 --- a/src/components/AvatarUser.vue +++ b/src/components/AvatarUser.vue @@ -1,4 +1,6 @@