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

Space settings: use alias for vote and proposal #3265

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a957140
check voting with hardcoded setting for alias
Oct 24, 2022
e72a344
add inputs for enabling alias
Oct 24, 2022
4becf9b
remove empty line
Oct 24, 2022
e89dc39
Merge branch 'develop' into use-alias-for-vote-and-proposal
Oct 24, 2022
b3789ee
remove package-lock.json
Oct 24, 2022
94de30c
refactor check for alias
Oct 24, 2022
1b95acc
remove toggle and param for aliased proposal settings
Oct 24, 2022
0a5fff8
update locale for the vote only
Oct 24, 2022
e4ac5bc
remove console.log
Oct 24, 2022
93eb8f5
remove hardcoded aliased and use space.voting
Oct 24, 2022
b2498bb
Merge branch 'develop' into use-alias-for-vote-and-proposal
zzuziak Oct 25, 2022
b12dd41
add delete-proposal to aliased actions and update locale
Oct 25, 2022
57dbcd4
Merge branch 'develop' into use-alias-for-vote-and-proposal
ChaituVR Oct 25, 2022
fccf201
escape is voting is undefined
Oct 25, 2022
c30815e
add aliased to query
Oct 25, 2022
92ea422
Merge branch 'develop' into use-alias-for-vote-and-proposal
zzuziak Oct 26, 2022
9f9308c
add from original address in payload
Oct 26, 2022
ead6e31
add tooltip for aliased voting
Oct 27, 2022
b8f1053
Merge branch 'develop' into use-alias-for-vote-and-proposal
zzuziak Oct 27, 2022
90a905a
fix empty class
Oct 27, 2022
fd64496
Merge branch 'use-alias-for-vote-and-proposal' of github.com:snapshot…
Oct 27, 2022
1e84da3
Merge branch 'develop' into use-alias-for-vote-and-proposal
samuveth Oct 28, 2022
dffb9df
update alias voting toggle text
zzuziak Oct 28, 2022
d1b0de6
Update src/locales/default.json
samuveth Oct 28, 2022
7e661d2
Merge branch 'develop' into use-alias-for-vote-and-proposal
bonustrack Nov 11, 2022
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
5 changes: 5 additions & 0 deletions src/components/SettingsVotingBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ const votingPeriod = computed({
v-model="form.voting.hideAbstain"
:text-right="$t('settings.hideAbstain')"
/>
<InputSwitch
v-if="form.validation.name === 'basic'"
v-model="form.voting.aliased"
:text-right="$t('settings.enableAliased')"
/>
</div>
</BaseBlock>
</template>
95 changes: 58 additions & 37 deletions src/composables/useClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import clientGnosisSafe from '@/helpers/clientGnosisSafe';
import clientEIP712 from '@/helpers/clientEIP712';
import { useWeb3 } from '@/composables/useWeb3';
import { useFlashNotification } from '@/composables/useFlashNotification';
import { useAliasAction } from '@/composables/useAliasAction';
import { getInstance } from '@snapshot-labs/lock/plugins/vue3';

export function useClient() {
const { t } = useI18n();
const { web3 } = useWeb3();
const auth = getInstance();
const { notify } = useFlashNotification();
const { setAlias, aliasWallet, isValidAlias, checkAlias } = useAliasAction();

const isSending = ref(false);

Expand Down Expand Up @@ -55,43 +57,62 @@ export function useClient() {
}

async function sendEIP712(space, type, payload) {
samuveth marked this conversation as resolved.
Show resolved Hide resolved
if (type === 'proposal') {
let plugins = {};
if (Object.keys(payload.metadata?.plugins).length !== 0)
plugins = payload.metadata.plugins;
return clientEIP712.proposal(auth.web3, web3.value.account, {
space: space.id,
type: payload.type,
title: payload.name,
body: payload.body,
discussion: payload.discussion,
choices: payload.choices,
start: payload.start,
end: payload.end,
snapshot: payload.snapshot,
plugins: JSON.stringify(plugins),
app: 'snapshot'
});
} else if (type === 'vote') {
return clientEIP712.vote(auth.web3, web3.value.account, {
space: space.id,
proposal: payload.proposal.id,
type: payload.proposal.type,
choice: payload.choice,
privacy: payload.privacy,
app: 'snapshot',
reason: payload.reason
});
} else if (type === 'delete-proposal') {
return clientEIP712.cancelProposal(auth.web3, web3.value.account, {
space: space.id,
proposal: payload.proposal.id
});
} else if (type === 'settings') {
return clientEIP712.space(auth.web3, web3.value.account, {
space: space.id,
settings: JSON.stringify(payload)
});
const aliased = space.voting.aliased;
try {
if (aliased) {
samuveth marked this conversation as resolved.
Show resolved Hide resolved
await checkAlias();
if (!aliasWallet.value || !isValidAlias.value) await setAlias();
}

const [provider, address] = aliased
? [aliasWallet.value, aliasWallet.value.address]
: [auth.web3, web3.value.account];

samuveth marked this conversation as resolved.
Show resolved Hide resolved
if (type === 'proposal') {
let plugins = {};
if (Object.keys(payload.metadata?.plugins).length !== 0)
plugins = payload.metadata.plugins;
return clientEIP712.proposal(provider, address, {
space: space.id,
type: payload.type,
title: payload.name,
body: payload.body,
discussion: payload.discussion,
choices: payload.choices,
start: payload.start,
end: payload.end,
snapshot: payload.snapshot,
plugins: JSON.stringify(plugins),
app: 'snapshot'
});
} else if (type === 'vote') {
return clientEIP712.vote(provider, address, {
samuveth marked this conversation as resolved.
Show resolved Hide resolved
space: space.id,
proposal: payload.proposal.id,
type: payload.proposal.type,
choice: payload.choice,
privacy: payload.privacy,
app: 'snapshot',
reason: payload.reason
});
} else if (type === 'delete-proposal') {
return clientEIP712.cancelProposal(provider, address, {
space: space.id,
proposal: payload.proposal.id
});
} else if (type === 'settings') {
return clientEIP712.space(auth.web3, web3.value.account, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And here for settings, without alias 👌

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@samuveth here for settings I don't use provider and address but force the auth via web3, so even if aliased === true settings update will require a signature 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh okay, that's pretty easy to miss, I was expecting a condition where you set the provider and address at the top

Copy link
Contributor Author

@zzuziak zzuziak Oct 28, 2022

Choose a reason for hiding this comment

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

Feel free to suggest a more readable solution! 🙏 The conditional is defined above, but I just don't use it for the settings action.

space: space.id,
settings: JSON.stringify(payload)
});
}
} catch (e: any) {
const errorMessage =
e?.error_description && typeof e.error_description === 'string'
? `Oops, ${e.error_description}`
: t('notify.somethingWentWrong');
notify(['red', errorMessage]);
return e;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/composables/useSpaceForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const EMPTY_SPACE_FORM = {
period: 0,
quorum: 0,
type: '',
privacy: ''
privacy: '',
aliased: false
},
validation: BASIC_VALIDATION,
name: '',
Expand Down
1 change: 1 addition & 0 deletions src/helpers/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export interface ExtendedSpace {
quorum: number | null;
type: string | null;
privacy: string | null;
aliased: boolean;
};
}

Expand Down
1 change: 1 addition & 0 deletions src/locales/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@
"information": "The minimum amount of voting power required to create a proposal"
},
"allowOnlyAuthors": "Allow only authors to submit a proposal",
"enableAliased": "Allow voting with session keys",
samuveth marked this conversation as resolved.
Show resolved Hide resolved
zzuziak marked this conversation as resolved.
Show resolved Hide resolved
"editValidation": "Edit validation",
"selectValidation": "Select validation",
"validationParameters": "Validation parameters",
Expand Down