Skip to content

Commit

Permalink
Merge branch 'master' into fabien/remove-intercom-widget
Browse files Browse the repository at this point in the history
  • Loading branch information
bonustrack authored Oct 25, 2024
2 parents cde4f08 + 7752a50 commit 9c77874
Show file tree
Hide file tree
Showing 24 changed files with 118 additions and 118 deletions.
4 changes: 1 addition & 3 deletions apps/mana/src/eth/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
clients,
evmArbitrum,
evmLineaGoerli,
evmMainnet,
EvmNetworkConfig,
evmOptimism,
Expand All @@ -18,8 +17,7 @@ export const NETWORKS = new Map<number, EvmNetworkConfig>([
[137, evmPolygon],
[42161, evmArbitrum],
[1, evmMainnet],
[11155111, evmSepolia],
[59140, evmLineaGoerli]
[11155111, evmSepolia]
]);

export const createNetworkHandler = (chainId: number) => {
Expand Down
10 changes: 0 additions & 10 deletions apps/subgraph-api/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,5 @@
"address": "0x0000000000021210000000000000000000000000",
"startBlock": 157825417
}
},
"linea-testnet": {
"ProxyFactory": {
"address": "0x12A1FfFFfd70677939D61d641eA043bc9060c718",
"startBlock": 858097
},
"L1AvatarExecutionStrategyFactory": {
"address": "0x0000000000021210000000000000000000000000",
"startBlock": 858097
}
}
}
3 changes: 1 addition & 2 deletions apps/subgraph-api/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "api-subgraph",
"private": true,
"version": "0.0.42",
"version": "0.0.43",
"scripts": {
"test": "graph test",
"codegen": "graph codegen",
Expand All @@ -11,7 +11,6 @@
"create-local": "graph create --node http://localhost:8020/ snapshot-labs/sx-subgraph",
"remove-local": "graph remove --node http://localhost:8020/ snapshot-labs/sx-subgraph",
"deploy-local": "yarn create-local && graph deploy --node http://localhost:8020/ --network sepolia -l `LC_ALL=C tr -dc a-z0-9 </dev/urandom | head -c 32` snapshot-labs/sx-subgraph",
"deploy-linea-testnet": "graph deploy --network linea-testnet --studio sx-linea-testnet",
"deploy-studio": "graph deploy --studio -l v${npm_package_version}",
"deploy-studio-mainnet": "yarn deploy-studio --network mainnet sx",
"deploy-studio-sepolia": "yarn deploy-studio --network sepolia sx-sepolia",
Expand Down
1 change: 0 additions & 1 deletion apps/subgraph-api/src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ CHAIN_IDS.set('sepolia', 11155111)
CHAIN_IDS.set('optimism', 10)
CHAIN_IDS.set('matic', 137)
CHAIN_IDS.set('arbitrum-one', 42161)
CHAIN_IDS.set('linea-testnet', 59140)

export function handleProxyDeployed(event: ProxyDeployed): void {
let network = dataSource.network()
Expand Down
56 changes: 49 additions & 7 deletions apps/ui/src/components/EditorChoices.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<script setup lang="ts">
import Draggable from 'vuedraggable';
import { BASIC_CHOICES } from '@/helpers/constants';
import { Draft } from '@/types';
const proposal = defineModel<Draft>({ required: true });
const props = defineProps<{
minimumBasicChoices: number;
error?: string;
definition: any;
}>();
Expand All @@ -18,6 +20,10 @@ function handleAddChoice() {
}
function handlePressEnter(index: number) {
if (proposal.value.type === 'basic' && proposal.value.choices.length === 3) {
return;
}
if (!choices.value[index + 1]) return handleAddChoice();
nextTick(() => choices.value[index + 1].focus());
Expand All @@ -27,12 +33,33 @@ function handlePressDelete(event: KeyboardEvent, index: number) {
if (proposal.value.choices[index] === '') {
event.preventDefault();
if (index !== 0) {
const canDelete =
proposal.value.type === 'basic'
? proposal.value.choices.length > props.minimumBasicChoices
: true;
if (canDelete && index !== 0) {
proposal.value.choices.splice(index, 1);
nextTick(() => choices.value[index - 1].focus());
}
}
}
function getPlaceholderText(index: number) {
if (proposal.value.type === 'basic' && index < 3) {
return BASIC_CHOICES[index];
}
return `Choice ${index + 1}`;
}
function shouldHaveDeleteButton(index: number) {
if (proposal.value.type === 'basic') {
return index > props.minimumBasicChoices - 1;
}
return proposal.value.choices.length > 1;
}
</script>

<template>
Expand Down Expand Up @@ -62,24 +89,39 @@ function handlePressDelete(event: KeyboardEvent, index: number) {
>
<IC-drag />
</div>
<div v-else class="mt-1.5">
<div
class="shrink-0 rounded-full choice-bg inline-block size-[18px]"
:class="`_${index + 1}`"
>
<IH-check
v-if="index === 0"
class="text-white size-[14px] mt-0.5 ml-0.5"
/>
<IH-x
v-else-if="index === 1"
class="text-white size-[14px] mt-0.5 ml-0.5"
/>
<IH-minus-sm
v-else-if="index === 2"
class="text-white size-[14px] mt-0.5 ml-0.5"
/>
</div>
</div>
<div class="grow">
<input
:ref="el => (choices[index] = el)"
v-model.trim="proposal.choices[index]"
type="text"
:maxLength="definition.items[0].maxLength"
class="w-full h-[40px] py-[10px] bg-transparent text-skin-heading"
:class="{
'!cursor-not-allowed ml-1': proposal.type === 'basic'
}"
:placeholder="`Choice ${index + 1}`"
:disabled="proposal.type === 'basic'"
:placeholder="getPlaceholderText(index)"
@keyup.enter="handlePressEnter(index)"
@keydown.delete="e => handlePressDelete(e, index)"
/>
</div>
<UiButton
v-if="proposal.choices.length > 1 && proposal.type !== 'basic'"
v-if="shouldHaveDeleteButton(index)"
class="!border-0 !rounded-l-none !rounded-r-lg !bg-transparent !size-[40px] !px-0 !text-skin-text shrink-0"
@click="proposal.choices.splice(index, 1)"
>
Expand Down
8 changes: 1 addition & 7 deletions apps/ui/src/components/ProposalResults.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ const props = withDefaults(
}
);
const LABELS = {
0: 'For',
1: 'Against',
2: 'Abstain'
};
const displayAllChoices = ref(false);
const totalProgress = computed(() => quorumProgress(props.proposal));
Expand Down Expand Up @@ -209,7 +203,7 @@ const otherResultsSummary = computed(() => {
<div
v-for="result in results"
:key="result.choice"
:title="LABELS[result.choice - 1]"
:title="props.proposal.choices[result.choice - 1]"
class="choice-bg float-left h-full"
:style="{
width: `${quorumChoiceProgress(props.proposal.quorum_type, result, totalProgress).toFixed(3)}%`
Expand Down
31 changes: 25 additions & 6 deletions apps/ui/src/components/ProposalVote.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,31 @@ const isEditable = computed(() => {
<IH-lock-closed class="size-[16px] shrink-0" />
<span class="truncate">Encrypted choice</span>
</div>
<div
v-else
class="grow truncate"
:class="{ 'text-skin-text': !isEditable }"
v-text="getChoiceText(proposal.choices, currentVote.choice)"
/>
<div v-else class="flex items-center gap-2">
<div
v-if="proposal.type === 'basic'"
class="shrink-0 rounded-full choice-bg inline-block size-[18px]"
:class="`_${currentVote.choice}`"
>
<IH-check
v-if="currentVote.choice === 1"
class="text-white size-[14px] mt-0.5 ml-0.5"
/>
<IH-x
v-else-if="currentVote.choice === 2"
class="text-white size-[14px] mt-0.5 ml-0.5"
/>
<IH-minus-sm
v-else-if="currentVote.choice === 3"
class="text-white size-[14px] mt-0.5 ml-0.5"
/>
</div>
<div
class="grow truncate"
:class="{ 'text-skin-text': !isEditable }"
v-text="getChoiceText(proposal.choices, currentVote.choice)"
/>
</div>
<IH-pencil v-if="isEditable" class="shrink-0" />
</UiButton>
</slot>
Expand Down
7 changes: 4 additions & 3 deletions apps/ui/src/components/ProposalVoteBasic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Choice } from '@/types';
withDefaults(
defineProps<{
size?: number;
choices: string[];
}>(),
{ size: 48 }
);
Expand All @@ -15,7 +16,7 @@ const emit = defineEmits<{

<template>
<div class="flex space-x-2">
<UiTooltip title="For">
<UiTooltip :title="choices[0]">
<UiButton
class="!text-skin-success !border-skin-success !px-0"
:class="{
Expand All @@ -27,7 +28,7 @@ const emit = defineEmits<{
<IH-check class="inline-block" />
</UiButton>
</UiTooltip>
<UiTooltip title="Against">
<UiTooltip :title="choices[1]">
<UiButton
class="!text-skin-danger !border-skin-danger !px-0"
:class="{
Expand All @@ -39,7 +40,7 @@ const emit = defineEmits<{
<IH-x class="inline-block" />
</UiButton>
</UiTooltip>
<UiTooltip title="Abstain">
<UiTooltip v-if="choices.length === 3" :title="choices[2]">
<UiButton
class="!text-gray-500 !border-gray-500 !px-0"
:class="{
Expand Down
1 change: 1 addition & 0 deletions apps/ui/src/components/ProposalsListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const handleVoteClick = (choice: Choice) => {
</template>
<ProposalVoteBasic
v-if="proposal.type === 'basic'"
:choices="proposal.choices"
:size="40"
class="py-2"
@vote="handleVoteClick"
Expand Down
6 changes: 3 additions & 3 deletions apps/ui/src/composables/useEditor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BASIC_CHOICES } from '@/helpers/constants';
import { lsGet, lsSet, omit } from '@/helpers/utils';
import { clone, lsGet, lsSet, omit } from '@/helpers/utils';
import { Draft, Drafts, VoteType } from '@/types';

const PREFERRED_VOTE_TYPE = 'single-choice';
const PREFERRED_VOTE_TYPE = 'basic';

const storedProposals = lsGet('proposals', {});
const processedProposals = Object.fromEntries(
Expand Down Expand Up @@ -117,7 +117,7 @@ export function useEditor() {
await setSpacesVoteType([spaceId]);

const type = payload?.type || spaceVoteType.get(spaceId)!;
const choices = type === 'basic' ? BASIC_CHOICES : Array(2).fill('');
const choices = type === 'basic' ? clone(BASIC_CHOICES) : Array(2).fill('');

const id = draftKey ?? generateId();
const key = `${spaceId}:${id}`;
Expand Down
1 change: 0 additions & 1 deletion apps/ui/src/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const CHAIN_IDS: Record<Exclude<NetworkID, 's' | 's-tn'>, ChainId> = {
oeth: 10,
matic: 137,
arb1: 42161,
'linea-testnet': 59140,
sep: 11155111,
// Starknet
sn: '0x534e5f4d41494e',
Expand Down
1 change: 0 additions & 1 deletion apps/ui/src/helpers/etherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export async function getABI(chainId: number, address: string) {
else if (chainId === 10) apiHost = 'https://api-optimistic.etherscan.io';
else if (chainId === 137) apiHost = 'https://api.polygonscan.com';
else if (chainId === 42161) apiHost = 'https://api.arbiscan.io';
else if (chainId === 59140) apiHost = 'https://api.lineascan.build';
else if (chainId === 11155111) apiHost = 'https://api-sepolia.etherscan.io';
else throw new Error('Unsupported chainId');

Expand Down
6 changes: 0 additions & 6 deletions apps/ui/src/helpers/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,5 @@
"chainId": 11155111,
"multicall": "0xcA11bde05977b3631167028862bE2a173976CA11",
"explorer": "https://sepolia.etherscan.io"
},
"59140": {
"key": "59140",
"chainId": 59140,
"multicall": "0x77dca2c955b15e9de4dbbcf1246b4b85b651e50e",
"explorer": "https://goerli.lineascan.build"
}
}
33 changes: 20 additions & 13 deletions apps/ui/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ import IHGlobeAlt from '~icons/heroicons-outline/globe-alt';
const IPFS_GATEWAY: string =
import.meta.env.VITE_IPFS_GATEWAY || 'https://cloudflare-ipfs.com';
const ADDABLE_NETWORKS = {
59140: {
chainName: 'Linea Goerli test network',
nativeCurrency: {
name: 'LineaETH',
symbol: 'ETH',
decimals: 18
},
rpcUrls: ['https://rpc.goerli.linea.build'],
blockExplorerUrls: ['https://goerli.lineascan.build']
}
// 12345: {
// chainName: 'My network name',
// nativeCurrency: {
// name: 'MyNetwork',
// symbol: 'NTW',
// decimals: 18
// },
// rpcUrls: ['https://...'],
// blockExplorerUrls: ['https://...']
// }
};

dayjs.extend(relativeTime);
Expand Down Expand Up @@ -371,7 +371,8 @@ export async function verifyNetwork(
params: [{ chainId: encodedChainId }]
});
} catch (err) {
if (err.code !== 4902 || !ADDABLE_NETWORKS) throw new Error(err.message);
if (err.code !== 4902 || !ADDABLE_NETWORKS[chainId])
throw new Error(err.message);

await web3Provider.provider.request({
method: 'wallet_addEthereumChain',
Expand Down Expand Up @@ -538,8 +539,14 @@ export function getChoiceWeight(

export function getChoiceText(availableChoices: string[], choice: Choice) {
if (typeof choice === 'string') {
return ['for', 'against', 'abstain'].includes(choice)
? choice.charAt(0).toUpperCase() + choice.slice(1)
const basicChoices = {
for: 0,
against: 1,
abstain: 2
};

return basicChoices[choice] !== undefined
? availableChoices[basicChoices[choice]]
: 'Invalid choice';
}

Expand Down
4 changes: 2 additions & 2 deletions apps/ui/src/networks/common/graphqlApi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
createHttpLink,
InMemoryCache
} from '@apollo/client/core';
import { BASIC_CHOICES, CHAIN_IDS } from '@/helpers/constants';
import { CHAIN_IDS } from '@/helpers/constants';
import { getNames } from '@/helpers/stamp';
import { clone, compareAddresses } from '@/helpers/utils';
import {
Expand Down Expand Up @@ -258,7 +258,7 @@ function formatProposal(
},
metadata_uri: proposal.metadata.id,
type: 'basic',
choices: BASIC_CHOICES,
choices: proposal.metadata.choices,
labels: proposal.metadata.labels,
scores: [proposal.scores_1, proposal.scores_2, proposal.scores_3],
title: proposal.metadata.title ?? '',
Expand Down
1 change: 1 addition & 0 deletions apps/ui/src/networks/common/graphqlApi/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const PROPOSAL_FRAGMENT = gql`
body
discussion
execution
choices
labels
}
start
Expand Down
Loading

0 comments on commit 9c77874

Please sign in to comment.