Skip to content

Commit

Permalink
Merge branch 'master' into validation-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gsteenkamp89 committed May 28, 2024
2 parents 0654a34 + 0bc4eba commit 12a1d24
Show file tree
Hide file tree
Showing 22 changed files with 127 additions and 66 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@shutter-network/shutter-crypto": "1.0.1",
"@snapshot-labs/lock": "^0.2.4",
"@snapshot-labs/pineapple": "^1.1.0",
"@snapshot-labs/snapshot.js": "^0.11.17",
"@snapshot-labs/snapshot.js": "^0.11.24",
"@vue/apollo-composable": "4.0.0-beta.11",
"@vueuse/core": "^10.6.1",
"@vueuse/head": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion snapshot-spaces
2 changes: 2 additions & 0 deletions src/components/ModalAccount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const injected = computed(() => getInjected());
const filteredConnectors = computed(() => {
const baseConnectors = ['injected', 'walletconnect', 'walletlink'];
// If injected is Coinbase, hide WalletLink
if (injected.value?.name === 'Coinbase') connectors.walletlink.hidden = true;
if (isShowingAllConnectors.value) return Object.keys(connectors);
return Object.keys(connectors).filter(cId => baseConnectors.includes(cId));
});
Expand Down
4 changes: 3 additions & 1 deletion src/components/SettingsTreasuriesBlockItemButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { TreasuryWallet } from '@/helpers/interfaces';
import { Network } from '@/plugins/oSnap/types';
import { ConfigError, getIsOsnapEnabled } from '@/plugins/oSnap/utils/getters';
import { ConfigError, getIsOsnapEnabled } from '@/plugins/oSnap/utils/getters';
const props = defineProps<{
treasury: TreasuryWallet;
Expand All @@ -18,6 +19,7 @@ const emit = defineEmits<{
const isOsnapEnabled = ref(false);
const isChainSupported = ref(true);
const isChainSupported = ref(true);
async function updateIsOsnapEnabled() {
if (!props.hasOsnapPlugin) return;
Expand Down Expand Up @@ -53,7 +55,7 @@ onUnmounted(() => {
<div class="flex items-center gap-2 truncate pr-[20px] text-left">
<h4 class="truncate">{{ treasury.name }}</h4>
</div>
<div class="ml-auto mr-3">
<div v-if="hasOsnapPlugin" class="ml-auto mr-3">
<SettingsTreasuryActivateOsnapButton
v-if="hasOsnapPlugin && isChainSupported"
:is-osnap-enabled="isOsnapEnabled"
Expand Down
14 changes: 3 additions & 11 deletions src/components/SpaceCreateVoting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ExtendedSpace } from '@/helpers/interfaces';
import draggable from 'vuedraggable';
import SpaceCreateLegacyOsnap from './SpaceCreateLegacyOsnap.vue';
import SpaceCreateOsnap from './SpaceCreateOsnap.vue';
import { BOOST_ENABLED_VOTING_TYPES } from '@/helpers/constants';
const props = defineProps<{
space: ExtendedSpace;
Expand Down Expand Up @@ -122,20 +123,11 @@ defineEmits<{
/>
<template v-if="isWhitelisted(space.id)">
<BaseMessage
v-if="form.type !== 'single-choice' && form.type !== 'basic'"
v-if="!BOOST_ENABLED_VOTING_TYPES.includes(form.type)"
level="info"
class="mt-2 border bg-[--border-color-subtle] p-3 rounded-xl"
>
Note that Boost is not available for this voting type. Please use
Basic or Single Choice if you want to use Boost.
</BaseMessage>
<BaseMessage
v-else-if="space.voting.privacy === 'shutter'"
level="info"
class="mt-2 border bg-[--border-color-subtle] p-3 rounded-xl"
>
Note that Boost is not available with Shutter encrypted voting. Please
disable it in the space settings if you want to use Boost.
Note that Boost is not available for this voting type.
</BaseMessage>
</template>
Expand Down
16 changes: 13 additions & 3 deletions src/components/SpaceProposalBoost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,24 @@ const newBoostLink = computed(() => ({
const isActive = computed(() => props.proposal.state === 'active');
const isFinal = computed(() => props.proposal.scores_state === 'final');
const winningChoice = computed(() => {
const maxScore = Math.max(...props.proposal.scores);
const maxScoreCount = props.proposal.scores.filter(
score => score === maxScore
).length;
return maxScoreCount > 1 ? 0 : props.proposal.scores.indexOf(maxScore) + 1;
});
function isEligible(boost: BoostSubgraph) {
const type = boost.strategy.eligibility.type;
const choice = boost.strategy.eligibility.choice;
if (!web3Account.value) return false;
if (props.proposal.privacy === 'shutter' && !isFinal.value) return false;
if (!isFinal.value) return false;
if (!userVote.value) return false;
if (choice === null) return true;
if (type === 'prediction')
return userVote.value.choice.toString() === winningChoice.value.toString();
if (type === 'incentive' && choice === null) return true;
return userVote.value.choice.toString() === choice;
}
Expand Down
13 changes: 8 additions & 5 deletions src/components/SpaceProposalBoostClaimModalItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ const reward = computed(() => {
props.boost.token.decimals
);
return formatNumber(
Number(amountDecimal),
getNumberFormatter({ maximumFractionDigits: 8 }).value
);
return amountDecimal;
});
const claim = computed(() => {
Expand Down Expand Up @@ -84,7 +81,13 @@ async function handleClaimAndReload() {
{{ hasClaimed ? 'Claimed' : 'Reward' }}
</span>
<TuneTag class="text-skin-heading text-base">
{{ reward }} {{ props.boost.token.symbol }}
{{
formatNumber(
Number(reward),
getNumberFormatter({ maximumFractionDigits: 8 }).value
)
}}
{{ props.boost.token.symbol }}
</TuneTag>
<div class="mt-1 flex items-center flex-wrap">
<span
Expand Down
5 changes: 4 additions & 1 deletion src/components/SpaceProposalBoostItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ const { pause } = useIntervalFn(() => {
<div class="w-full">
<div class="text-skin-heading flex flex-wrap -mt-1 pr-5">
<div class="whitespace-nowrap mt-1 mr-1 flex items-center">
<template v-if="boost.strategy.eligibility.choice !== null">
<template v-if="boost.strategy.eligibility.type === 'prediction'">
Anyone who votes for the winning choice
</template>
<template v-else-if="boost.strategy.eligibility.choice !== null">
Who votes
<div>
<TuneTag
Expand Down
5 changes: 2 additions & 3 deletions src/components/SpaceProposalPage.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import voting from '@snapshot-labs/snapshot.js/src/voting';
import { ExtendedSpace, Proposal, Results } from '@/helpers/interfaces';
import { BOOST_ENABLED_VOTING_TYPES } from '@/helpers/constants';
const props = defineProps<{ space: ExtendedSpace; proposal: Proposal }>();
const emit = defineEmits(['reload-proposal']);
Expand Down Expand Up @@ -56,9 +57,7 @@ const strategies = computed(
const boostEnabled = computed(() => {
return (
(props.proposal.type === 'basic' ||
props.proposal.type === 'single-choice') &&
props.proposal.privacy !== 'shutter' &&
BOOST_ENABLED_VOTING_TYPES.includes(props.proposal.type) &&
isWhitelisted(props.space.id) &&
props.space.boost.enabled
);
Expand Down
13 changes: 6 additions & 7 deletions src/composables/useAliasAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export function useAliasAction() {
query: ALIASES_QUERY,
variables: {
address: web3.value.account,
alias: aliasWallet.value.address
alias: aliasWallet.value.address,
created_gt: Math.floor(Date.now() / 1000) - 30 * 60 * 60 * 24
}
},
'aliases'
Expand All @@ -53,12 +54,10 @@ export function useAliasAction() {

async function setAlias() {
const rndWallet = Wallet.createRandom();
aliases.value = Object.assign(
{
[web3.value.account]: rndWallet.privateKey
},
aliases.value
);
aliases.value = {
...aliases.value,
[web3.value.account]: rndWallet.privateKey
};
lsSet('aliases', aliases.value);

if (aliasWallet.value?.address) {
Expand Down
3 changes: 1 addition & 2 deletions src/composables/useChangeNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import networks from '@snapshot-labs/snapshot.js/src/networks.json';
import { sleep } from '@snapshot-labs/snapshot.js/src/utils';
import { hexlify } from '@ethersproject/bytes';

export function useChangeNetwork() {
const changingNetwork = ref(false);
Expand All @@ -11,7 +10,7 @@ export function useChangeNetwork() {
method: 'wallet_switchEthereumChain',
params: [
{
chainId: hexlify(Number(networks[network].chainId))
chainId: `0x${Number(networks[network].chainId).toString(16)}`
}
]
});
Expand Down
9 changes: 7 additions & 2 deletions src/composables/useFollowSpace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,30 @@ export function useFollowSpace(spaceId: any = {}) {

async function follow(space) {
loadingFollow.value = spaceId;

try {
await checkAlias();
if (!aliasWallet.value || !isValidAlias.value) {
await setAlias();
follow(space);
} else {
const network = process.env.VITE_ENV === 'production' ? 's' : 's-tn';

if (isFollowing.value) {
// Also unsubscribe to the notifications if the user leaves the space.
if (isSubscribed.value) {
await toggleSubscription();
}
await client.unfollow(aliasWallet.value, aliasWallet.value.address, {
from: web3Account.value,
space
space,
network
});
} else {
await client.follow(aliasWallet.value, aliasWallet.value.address, {
from: web3Account.value,
space
space,
network
});
}
await loadFollows();
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useTreasury.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import snapshot from '@snapshot-labs/snapshot.js';
import { getTokenBalances, ETHER_CONTRACT } from '@/helpers/covalent';
import { TreasuryAsset } from '@/helpers/interfaces';

const TOKEN_LIST_URL = 'https://gateway.ipfs.io/ipns/tokens.uniswap.org';
const TOKEN_LIST_URL = 'https://ipfs.io/ipns/tokens.uniswap.org';

const tokenListContractAddresses = ref<null | string[]>(null);
const treasuryAssets = ref<{ [key: string]: TreasuryAsset[] }>({});
Expand Down
1 change: 1 addition & 0 deletions src/composables/useWeb3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function useWeb3() {

function logout() {
auth = getInstance();
if (auth.provider?.value?.isCoinbaseWallet) auth.provider.value.close();
auth.logout();
state.account = '';
}
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/boost/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const BOOST_WHITELIST_SETTINGS = {
'vote.vitadao.eth',
'shutterdao0x36.eth',
'testeteste123.eth',
'alkimiexchange.eth',
// Internal testers
'testsnap.eth',
'fabien.eth',
Expand Down Expand Up @@ -122,7 +123,7 @@ export async function withdrawAndBurn(
): Promise<any> {
const signer = web3.getSigner();
const contract = new Contract(BOOST_CONTRACTS[networkId], ABI, signer);
return await contract.burn(boostId, to);
return await contract.withdrawAndBurn(boostId, to);
}

export async function getFees(web3: Web3Provider, networkId: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/boost/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export type BoostSubgraph = {
name: string;
proposal: string;
eligibility: {
type: 'incentive' | 'bribe';
type: 'incentive' | 'prediction' | 'bribe';
choice: string | null;
};
distribution: {
Expand Down
5 changes: 3 additions & 2 deletions src/helpers/connectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const connectors = {
projectId: 'e6454bd61aba40b786e866a69bd4c5c6',
chains: [1],
optionalChains: [
4, 5, 10, 42, 56, 100, 137, 246, 1088, 42161, 73799, 1115511
4, 5, 10, 42, 56, 100, 137, 246, 1088, 42161, 73799, 11155111
],
methods: ['eth_sendTransaction', 'personal_sign', 'eth_signTypedData_v4'],
optionalMethods: ['eth_accounts'],
Expand Down Expand Up @@ -43,7 +43,8 @@ const connectors = {
chainId: 1,
ethJsonrpcUrl: `${import.meta.env.VITE_BROVIDER_URL}/1`
},
icon: 'ipfs://QmbJKEaeMz6qR3DmJSTxtYtrZeQPptVfnnYK72QBsvAw5q'
icon: 'ipfs://QmbJKEaeMz6qR3DmJSTxtYtrZeQPptVfnnYK72QBsvAw5q',
hidden: false
},
portis: {
id: 'portis',
Expand Down
9 changes: 8 additions & 1 deletion src/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const KNOWN_HOSTS = [
'pilot.gnosisguild.org',
'metissafe.tech',
'multisig.mantle.xyz',
'wallet.ambire.com'
'wallet.ambire.com',
'multisig.moonbeam.network'
];

export const SPACE_CATEGORIES = [
Expand Down Expand Up @@ -95,3 +96,9 @@ export const TWO_WEEKS = 1209600;
export const ONE_DAY = 86400;

export const SNAPSHOT_HELP_LINK = 'https://help.snapshot.org/en';

export const BOOST_ENABLED_VOTING_TYPES = [
'basic',
'single-choice',
'ranked-choice'
];
6 changes: 4 additions & 2 deletions src/helpers/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ export const SUBSCRIPTIONS_QUERY = gql`
`;

export const ALIASES_QUERY = gql`
query Aliases($address: String!, $alias: String!) {
aliases(where: { address: $address, alias: $alias }) {
query Aliases($address: String!, $alias: String!, $created_gt: Int) {
aliases(
where: { address: $address, alias: $alias, created_gt: $created_gt }
) {
address
alias
}
Expand Down
2 changes: 1 addition & 1 deletion src/locales/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@
"label": "Privacy",
"title": "Select voting privacy",
"information": "The type of privacy used on proposals. (Enforced on all future proposals)",
"any": "Any",
"any": "No privacy",
"none": "None",
"shutter": {
"label": "Shutter",
Expand Down
Loading

0 comments on commit 12a1d24

Please sign in to comment.