Skip to content

Commit

Permalink
feat: Add settings for boost (snapshot-labs#4616)
Browse files Browse the repository at this point in the history
* Add boost settings

* Change to enabled

* Fix whitelist conditions and add query

* Fix bribe disabled

* Fixes

* Update src/composables/useFormSpaceSettings.ts

Co-authored-by: Chaitanya <[email protected]>

* Fix disable button is not enabled or closed

---------

Co-authored-by: Chaitanya <[email protected]>
  • Loading branch information
samuveth and ChaituVR authored Mar 15, 2024
1 parent 8061939 commit 9b55e9d
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/assets/css/tune.scss
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
}

.tune-sublabel {
@apply font-sans text-sm text-skin-text opacity-60;
@apply font-sans text-skin-text opacity-60;
}

.tune-icon-hint {
Expand Down
28 changes: 7 additions & 21 deletions src/components/SettingsBoostBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,22 @@ const props = defineProps<{
}>();
const { form } = useFormSpaceSettings(props.context);
watch(
() => form.value.boost.enabled,
value => {
if (value === false) {
form.value.boost.restriction = '';
}
}
);
</script>

<template>
<BaseBlock title="Boost">
<div class="space-y-2">
<TuneSwitch
v-model="form.boost.enabled"
label="Enable boost"
label="Enable Boost"
sublabel="Allow users to set up rewards for voters."
:disabled="props.isViewOnly"
/>
<TuneListbox
v-model="form.boost.restriction"
:disabled="form.boost.enabled === false || props.isViewOnly"
label="Restrict usage"
:items="[
{
value: 'no-bribe',
name: 'Disable bribe'
}
]"
title="Boost"
<TuneSwitch
v-model="form.boost.bribeEnabled"
label="Enable strategic incentivization"
sublabel="Allow users to set up rewards for voting on a specific choice."
:disabled="props.isViewOnly"
/>
</div>
</BaseBlock>
Expand Down
5 changes: 3 additions & 2 deletions src/components/SpaceProposalBoost.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { getClaims, getBoosts } from '@/helpers/boost/subgraph';
import { Proposal } from '@/helpers/interfaces';
import { Proposal, ExtendedSpace } from '@/helpers/interfaces';
import { useStorage } from '@vueuse/core';
import { getRewards } from '@/helpers/boost/api';
import { toChecksumAddress } from '@/helpers/utils';
Expand All @@ -16,6 +16,7 @@ const INITIAL_VISIBLE_BOOSTS = 3;
const props = defineProps<{
proposal: Proposal;
space: ExtendedSpace;
}>();
const createModalOpen = ref(false);
Expand Down Expand Up @@ -118,7 +119,7 @@ async function loadBoosts() {
const sanitizedBoosts = sanitizeBoosts(
response,
[props.proposal],
props.proposal.space.id
props.space
);
boosts.value = sanitizedBoosts;
} catch (e) {
Expand Down
9 changes: 7 additions & 2 deletions src/components/SpaceProposalPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ const boostEnabled = computed(() => {
return (
(props.proposal.type === 'basic' ||
props.proposal.type === 'single-choice') &&
props.proposal.privacy !== 'shutter' &&
isWhitelisted(props.space.id) &&
props.proposal.privacy !== 'shutter'
props.space.boost.enabled
);
});
Expand Down Expand Up @@ -172,7 +173,11 @@ onMounted(() => setMessageVisibility(props.proposal.flagged));
@click-vote="clickVote"
/>

<SpaceProposalBoost v-if="boostEnabled" :proposal="proposal" />
<SpaceProposalBoost
v-if="boostEnabled"
:proposal="proposal"
:space="space"
/>

<SpaceProposalVotes :space="space" :proposal="proposal" />

Expand Down
13 changes: 4 additions & 9 deletions src/composables/useBoost.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BOOST_WHITELIST_SETTINGS, claimTokens } from '@/helpers/boost';
import { BoostSubgraph } from '@/helpers/boost/types';
import { Proposal } from '@/helpers/interfaces';
import { Proposal, ExtendedSpace } from '@/helpers/interfaces';
import { TWO_WEEKS } from '@/helpers/constants';
import { getVouchers } from '@/helpers/boost/api';
import { toChecksumAddress } from '@/helpers/utils';
Expand All @@ -15,21 +15,17 @@ export function useBoost() {
const loadingClaim = ref(false);

function isWhitelisted(spaceId: string) {
return !!BOOST_WHITELIST_SETTINGS[env][spaceId];
}

function bribeDisabled(spaceId: string) {
return BOOST_WHITELIST_SETTINGS[env][spaceId]?.bribeDisabled;
return BOOST_WHITELIST_SETTINGS[env].includes(spaceId);
}

function sanitizeBoosts(
boosts: BoostSubgraph[],
proposals: Proposal[],
spaceId: string
space: ExtendedSpace
) {
return boosts.filter(boost => {
if (
bribeDisabled(spaceId) &&
!space.boost.bribeEnabled &&
boost.strategy.eligibility.type === 'bribe'
) {
return false;
Expand Down Expand Up @@ -91,7 +87,6 @@ export function useBoost() {

return {
isWhitelisted,
bribeDisabled,
sanitizeBoosts,
loadVouchers,
handleClaim,
Expand Down
5 changes: 5 additions & 0 deletions src/composables/useFormSpaceSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const EMPTY_SPACE_FORM = {
type: '',
privacy: ''
},
boost: {
enabled: true,
bribeEnabled: false
},
validation: clone(DEFAULT_PROPOSAL_VALIDATION),
voteValidation: clone(DEFAULT_VOTE_VALIDATION),
name: '',
Expand Down Expand Up @@ -155,6 +159,7 @@ export function useFormSpaceSettings(
? formData.children.map((child: any) => child.id)
: [];
formData.parent = formData.parent?.id || '';
formData.boost = formData.boost || { enabled: true, bribeEnabled: false };
}

function shouldUseAnyValidation(formData: any) {
Expand Down
22 changes: 11 additions & 11 deletions src/helpers/boost/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ export const SNAPSHOT_GUARD_ADDRESS =

export const BOOST_WHITELIST_SETTINGS = {
demo: [],
production: {
production: [
// External testers
'community.daosquare.eth': {},
'community.daosquare.eth',
// Internal testers
'testsnap.eth': {},
'fabien.eth': {},
'pscott.eth': {},
'gillvill.eth': {},
'0cf5e.eth': {},
'thanku.eth': {},
'test.wa0x6e.eth': {},
'aurelianob.eth': {}
}
'testsnap.eth',
'fabien.eth',
'pscott.eth',
'gillvill.eth',
'0cf5e.eth',
'thanku.eth',
'test.wa0x6e.eth',
'aurelianob.eth'
]
};

export async function createBoost(
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ export interface ExtendedSpace {
flagged: boolean;
hibernated: boolean;
turbo: boolean;
boost: {
enabled: boolean;
bribeEnabled: boolean;
};
voting: {
delay: number | null;
hideAbstain: boolean;
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ export const SPACE_QUERY = gql`
address
network
}
boost {
enabled
bribeEnabled
}
}
}
`;
Expand Down
22 changes: 17 additions & 5 deletions src/views/SpaceBoost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ const { modalAccountOpen } = useModal();
const { getRelativeProposalPeriod } = useIntl();
const { env } = useApp();
const { formatNumber, getNumberFormatter } = useIntl();
const { bribeDisabled } = useBoost();
const { loadBalances, tokens, loading: loadingBalances } = useBalances();
const { isWhitelisted } = useBoost();
const proposal = ref();
const createStatus = ref('');
Expand Down Expand Up @@ -103,7 +103,7 @@ const eligibilityOptions = computed(() => {
return {
value: index + 1,
label: `Who votes '${choice}'`,
extras: { disabled: bribeDisabled(props.space.id) }
extras: { disabled: !props.space.boost.bribeEnabled }
};
}
);
Expand Down Expand Up @@ -655,13 +655,14 @@ watch(
:items="eligibilityOptions"
label="Eligible to"
/>
<TuneBlockFooter v-if="bribeDisabled(space.id)">
<TuneBlockFooter v-if="!space.boost.bribeEnabled">
<BaseMessage level="info">
Selecting a specific choice is disabled for the
<span class="font-semibold">
{{ space.name }}
</span>
space
space. Please enable strategic incentivization in the space
settings to enable this feature.
</BaseMessage>
</TuneBlockFooter>
</TuneBlock>
Expand All @@ -684,6 +685,11 @@ watch(
</div>
<TuneButton
:loading="isLoading"
:disabled="
!isWhitelisted(space.id) ||
!space.boost.enabled ||
proposal.state === 'closed'
"
primary
class="w-full mt-3"
@click="handleCreate"
Expand All @@ -694,10 +700,16 @@ watch(
v-if="isEndingSoon || proposal.state === 'closed'"
class="text-boost flex items-center gap-1 justify-center mt-[6px]"
>
<template v-if="proposal.state === 'closed'">
<template v-if="proposal.state !== 'closed'">
<i-ho-exclamation-circle />
This proposal is closed
</template>
<template
v-else-if="!isWhitelisted(space.id) || !space.boost.enabled"
>
<i-ho-exclamation-circle />
Boost is not enabled in this space
</template>
<template v-else-if="isEndingSoon">
<i-ho-clock />
Proposal
Expand Down
4 changes: 2 additions & 2 deletions src/views/SpaceProposals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async function getProposals(skip = 0) {
}
async function loadBoosts(proposals: Proposal[]) {
if (!isWhitelisted(props.space.id)) return;
if (!isWhitelisted(props.space.id) || !props.space.boost.enabled) return;
const alreadyLoadedProposals = boosts.value.map(
boost => boost.strategy.proposal
Expand All @@ -99,7 +99,7 @@ async function loadBoosts(proposals: Proposal[]) {
const response = await getBoosts(
proposalsToLoad.map(proposal => proposal.id)
);
const sanitizedBoosts = sanitizeBoosts(response, proposals, props.space.id);
const sanitizedBoosts = sanitizeBoosts(response, proposals, props.space);
boosts.value = boosts.value.concat(sanitizedBoosts);
} catch (e) {
console.error('Load boosts error:', e);
Expand Down
11 changes: 7 additions & 4 deletions src/views/SpaceSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const { web3Account } = useWeb3();
const { send, isSending } = useClient();
const { reloadSpace, deleteSpace } = useExtendedSpaces();
const { loadFollows } = useFollowSpace();
const { isWhitelisted } = useBoost();
const {
validationErrors,
isValid,
Expand Down Expand Up @@ -252,10 +253,6 @@ onBeforeRouteLeave(async () => {
</template>

<template v-if="currentPage === Page.PROPOSAL">
<!-- <SettingsBoostBlock
context="settings"
:is-view-only="isViewOnly"
/> -->
<SettingsValidationBlock
context="settings"
:is-view-only="isViewOnly"
Expand All @@ -268,6 +265,12 @@ onBeforeRouteLeave(async () => {
</template>

<template v-if="currentPage === Page.VOTING">
<SettingsBoostBlock
v-if="isWhitelisted(space.id)"
context="settings"
:is-view-only="isViewOnly"
/>

<SettingsVotingBlock
context="settings"
:is-view-only="isViewOnly"
Expand Down

0 comments on commit 9b55e9d

Please sign in to comment.