Skip to content

Commit

Permalink
Merge branch 'master' into show-pending-results-message
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Dec 17, 2024
2 parents 816e89e + b63c672 commit 5ab0d42
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 56 deletions.
12 changes: 7 additions & 5 deletions apps/ui/src/components/Breadcrumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ const space = computed(() => {
class="flex item-center space-x-2.5 truncate text-[24px]"
v-bind="$attrs"
>
<SpaceAvatar
:space="{ ...space, network: networkId as NetworkID }"
:size="36"
class="!rounded-[4px] shrink-0"
/>
<div class="shrink-0">
<SpaceAvatar
:space="{ ...space, network: networkId as NetworkID }"
:size="36"
class="!rounded-[4px]"
/>
</div>
<span class="truncate" v-text="space.name" />
</AppLink>
</template>
19 changes: 11 additions & 8 deletions apps/ui/src/components/Modal/DateTime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,28 @@ watch(
<template #header>
<h3 v-text="current.title" />
</template>
<div :class="['!m-4 text-center', { 's-error': formError }]">
<div :class="['s-box !m-4 text-center', { 's-error': formError }]">
<UiCalendar
v-if="isCurrent('date')"
:min="min"
:selected="date"
@pick="handleDateUpdate"
/>
<template v-else-if="isCurrent('time')">
<input
v-model="time"
type="time"
class="s-input mx-auto max-w-[140px] text-center text-lg"
/>
<div v-else-if="isCurrent('time')" class="s-base">
<div class="relative mx-auto max-w-[140px]">
<label class="s-label w-full">Time</label>
<input
v-model="time"
type="time"
class="s-input text-center text-lg"
/>
</div>
<span
v-if="formError"
class="s-input-error-message"
v-text="formError"
/>
</template>
</div>
</div>
<template #footer>
<div class="flex space-x-3">
Expand Down
4 changes: 2 additions & 2 deletions apps/ui/src/components/Modal/VotingPower.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const loading = computed(
<div class="text-skin-link shrink-0">
{{
_n(
Number(strategy.value) / 10 ** votingPower.decimals,
Number(strategy.value) / 10 ** strategy.cumulativeDecimals,
'compact',
{
maximumFractionDigits: 2,
Expand Down Expand Up @@ -109,7 +109,7 @@ const loading = computed(
</div>
<div v-else />
<div>
{{ _n(Number(strategy.value) / 10 ** strategy.decimals) }}
{{ _n(Number(strategy.value) / 10 ** strategy.displayDecimals) }}
{{ strategy.symbol || 'units' }}
</div>
</div>
Expand Down
9 changes: 7 additions & 2 deletions apps/ui/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,13 @@ export function getSocialNetworksLink(data: any) {
export function getFormattedVotingPower(votingPower?: VotingPowerItem) {
if (!votingPower) return;

const { totalVotingPower, decimals, symbol } = votingPower;
const value = _vp(Number(totalVotingPower) / 10 ** decimals);
const { votingPowers, symbol } = votingPower;
const value = _vp(
votingPowers.reduce(
(acc, b) => acc + Number(b.value) / 10 ** b.cumulativeDecimals,
0
)
);

return symbol ? `${value} ${symbol}` : value;
}
Expand Down
16 changes: 14 additions & 2 deletions apps/ui/src/networks/evm/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,11 +660,22 @@ export function createActions(
if (snapshotInfo.at === null)
throw new Error('EVM requires block number to be defined');

const cumulativeDecimals = Math.max(
...strategiesMetadata.map(metadata => metadata.decimals ?? 0)
);

return Promise.all(
strategiesAddresses.map(async (address, i) => {
const strategy = getEvmStrategy(address, networkConfig);
if (!strategy)
return { address, value: 0n, decimals: 0, token: null, symbol: '' };
return {
address,
value: 0n,
displayDecimals: 0,
cumulativeDecimals: 0,
token: null,
symbol: ''
};

const strategyMetadata = await parseStrategyMetadata(
strategiesMetadata[i].payload
Expand All @@ -685,7 +696,8 @@ export function createActions(
return {
address,
value,
decimals: strategiesMetadata[i]?.decimals ?? 0,
cumulativeDecimals,
displayDecimals: strategiesMetadata[i]?.decimals ?? 0,
symbol: strategiesMetadata[i]?.symbol ?? '',
token,
swapLink: getSwapLink(strategy.type, address, chainId)
Expand Down
13 changes: 7 additions & 6 deletions apps/ui/src/networks/evm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const METADATA: Record<string, Metadata> = {
ticker: 'MATIC',
chainId: 137,
apiUrl:
'https://api.studio.thegraph.com/query/23545/sx-polygon/version/latest',
'https://subgrapher.snapshot.org/subgraph/arbitrum/5DzKWssJUVKA1imXGyExrycUjdz7t5t7gzTsE9GQhBUn',
avatar:
'ipfs://bafkreihcx4zkpfjfcs6fazjp6lcyes4pdhqx3uvnjuo5uj2dlsjopxv5am',
blockTime: 2.15812
Expand All @@ -37,7 +37,7 @@ export const METADATA: Record<string, Metadata> = {
chainId: 42161,
currentChainId: 1,
apiUrl:
'https://api.studio.thegraph.com/query/23545/sx-arbitrum/version/latest',
'https://subgrapher.snapshot.org/subgraph/arbitrum/4QovVxoK3TBLwZKPD1YPHHko5Zz87HvdjpEDBvitCWcH',
avatar:
'ipfs://bafkreic2p3zzafvz34y4tnx2kaoj6osqo66fpdo3xnagocil452y766gdq',
blockTime: ETH_MAINNET_BLOCK_TIME
Expand All @@ -46,22 +46,23 @@ export const METADATA: Record<string, Metadata> = {
name: 'Optimism',
chainId: 10,
apiUrl:
'https://api.studio.thegraph.com/query/23545/sx-optimism/version/latest',
'https://subgrapher.snapshot.org/subgraph/arbitrum/4zXNNp5B34DUNACzonVsHivNJRUHnFBqhvBPYJVaNyks',
avatar: 'ipfs://QmfF4kwhGL8QosUXvgq2KWCmavhKBvwD6kbhs7L4p5ZAWb',
blockTime: 2
},
base: {
name: 'Base',
chainId: 8453,
apiUrl:
'https://api.studio.thegraph.com/query/23545/sx-base/version/latest',
'https://subgrapher.snapshot.org/subgraph/arbitrum/BmcnmDYyCcN7NmQuWXyx3p1xLEiq3sYmvFct8uvBQfum',
avatar: 'ipfs://QmaxRoHpxZd8PqccAynherrMznMufG6sdmHZLihkECXmZv',
blockTime: 2
},
eth: {
name: 'Ethereum',
chainId: 1,
apiUrl: 'https://api.studio.thegraph.com/query/23545/sx/version/latest',
apiUrl:
'https://subgrapher.snapshot.org/subgraph/arbitrum/GerdwbJnTbEz45K7S3D2MLET6VFiY8VqwrqWZg52x2vx',
avatar:
'ipfs://bafkreid7ndxh6y2ljw2jhbisodiyrhcy2udvnwqgon5wgells3kh4si5z4',
blockTime: ETH_MAINNET_BLOCK_TIME
Expand All @@ -71,7 +72,7 @@ export const METADATA: Record<string, Metadata> = {
chainId: 11155111,
apiUrl:
import.meta.env.VITE_EVM_SEPOLIA_API ??
'https://api.studio.thegraph.com/query/23545/sx-sepolia/version/latest',
'https://subgrapher.snapshot.org/subgraph/arbitrum/3682UpSJVQ89v6BMSzxDSiQWZKa3Hbn6RKucpT8jZ5nT',
avatar:
'ipfs://bafkreid7ndxh6y2ljw2jhbisodiyrhcy2udvnwqgon5wgells3kh4si5z4',
blockTime: 13.2816
Expand Down
15 changes: 12 additions & 3 deletions apps/ui/src/networks/offchain/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,14 @@ export function createActions(

if (!strategy || !isAddress(voterAddress)) {
return [
{ address: name, value: 0n, decimals: 0, token: null, symbol: '' }
{
address: name,
value: 0n,
cumulativeDecimals: 0,
displayDecimals: 0,
token: null,
symbol: ''
}
];
}

Expand All @@ -257,7 +264,8 @@ export function createActions(
return [
{
address: strategiesNames[0],
decimals: 0,
cumulativeDecimals: 0,
displayDecimals: 0,
symbol: '',
token: '',
chainId: snapshotInfo.chainId,
Expand All @@ -273,7 +281,8 @@ export function createActions(
return {
address: strategy.name,
value,
decimals,
cumulativeDecimals: decimals,
displayDecimals: decimals,
symbol: strategy.params.symbol,
token: strategy.params.address,
chainId: strategy.network ? parseInt(strategy.network) : undefined,
Expand Down
21 changes: 14 additions & 7 deletions apps/ui/src/networks/offchain/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ describe('offchain network', () => {
).resolves.toEqual([
{
address: 'ticket',
decimals: 0,
cumulativeDecimals: 0,
displayDecimals: 0,
symbol: '',
token: null,
value: 0n
Expand Down Expand Up @@ -88,7 +89,8 @@ describe('offchain network', () => {
).resolves.toEqual([
{
address: 'ticket',
decimals: 9,
cumulativeDecimals: 9,
displayDecimals: 9,
symbol: 'SYM',
token: 'TOKEN',
value: result[0],
Expand All @@ -97,7 +99,8 @@ describe('offchain network', () => {
},
{
address: 'math',
decimals: 18,
cumulativeDecimals: 18,
displayDecimals: 18,
symbol: undefined,
token: undefined,
value: result[1],
Expand All @@ -106,7 +109,8 @@ describe('offchain network', () => {
},
{
address: 'api',
decimals: 18,
cumulativeDecimals: 18,
displayDecimals: 18,
symbol: undefined,
token: undefined,
value: result[2],
Expand Down Expand Up @@ -141,7 +145,8 @@ describe('offchain network', () => {
).resolves.toEqual([
{
address: 'basic',
decimals: 0,
cumulativeDecimals: 0,
displayDecimals: 0,
symbol: '',
token: null,
value: 0n
Expand All @@ -167,7 +172,8 @@ describe('offchain network', () => {
{
address: 'only-members',
value: 1n,
decimals: 0,
cumulativeDecimals: 0,
displayDecimals: 0,
symbol: '',
token: '',
chainId: undefined
Expand All @@ -191,7 +197,8 @@ describe('offchain network', () => {
{
address: 'only-members',
value: 0n,
decimals: 0,
cumulativeDecimals: 0,
displayDecimals: 0,
symbol: '',
token: '',
chainId: undefined
Expand Down
16 changes: 14 additions & 2 deletions apps/ui/src/networks/starknet/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,22 @@ export function createActions(
voterAddress: string,
snapshotInfo: SnapshotInfo
): Promise<VotingPower[]> => {
const cumulativeDecimals = Math.max(
...strategiesMetadata.map(metadata => metadata.decimals ?? 0)
);

return Promise.all(
strategiesAddresses.map(async (address, i) => {
const strategy = getStarknetStrategy(address, networkConfig);
if (!strategy)
return { address, value: 0n, decimals: 0, token: null, symbol: '' };
return {
address,
value: 0n,
cumulativeDecimals: 0,
displayDecimals: 0,
token: null,
symbol: ''
};

const strategyMetadata = await parseStrategyMetadata(
strategiesMetadata[i].payload
Expand All @@ -704,7 +715,8 @@ export function createActions(
return {
address,
value,
decimals: strategiesMetadata[i]?.decimals ?? 0,
cumulativeDecimals,
displayDecimals: strategiesMetadata[i]?.decimals ?? 0,
symbol: strategiesMetadata[i]?.symbol ?? '',
token: strategiesMetadata[i]?.token ?? null
};
Expand Down
9 changes: 8 additions & 1 deletion apps/ui/src/networks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@ export type SnapshotInfo = {
export type VotingPower = {
address: string;
value: bigint;
decimals: number;
/**
* Decimals used to interpret value in context of final (total) VP.
*/
cumulativeDecimals: number;
/**
* Decimals used to display this strategy value.
*/
displayDecimals: number;
token: string | null;
symbol: string;
chainId?: number;
Expand Down
15 changes: 6 additions & 9 deletions apps/ui/src/stores/votingPowers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ const LATEST_BLOCK_NAME = 'latest';
type SpaceDetails = Proposal['space'];
export type VotingPowerItem = {
votingPowers: VotingPower[];
totalVotingPower: bigint;
status: VotingPowerStatus;
symbol: string;
decimals: number;
error: utils.errors.VotingPowerDetailsError | null;
canPropose: boolean;
canVote: boolean;
Expand Down Expand Up @@ -63,8 +61,6 @@ export const useVotingPowersStore = defineStore('votingPowers', () => {
let vpItem: VotingPowerItem = {
status: 'loading',
votingPowers: [],
totalVotingPower: 0n,
decimals: 18,
symbol: space.voting_power_symbol,
error: null,
canPropose: false,
Expand Down Expand Up @@ -106,19 +102,20 @@ export const useVotingPowersStore = defineStore('votingPowers', () => {
vpItem = {
...vpItem,
votingPowers: vp,
totalVotingPower: vp.reduce((acc, b) => acc + b.value, 0n),
status: 'success',
decimals: Math.max(...vp.map(votingPower => votingPower.decimals), 0)
status: 'success'
};

if (isSpace(item) && proposeVp) {
const totalProposeVp = proposeVp.reduce((acc, b) => acc + b.value, 0n);
const totalProposeVp = proposeVp.reduce(
(acc, b) => acc + Number(b.value) / 10 ** b.cumulativeDecimals,
0
);

vpItem.canPropose =
totalProposeVp >= BigInt(item.proposal_threshold) ||
isSpaceMember(space as Space, account);
} else {
vpItem.canVote = vpItem.totalVotingPower > 0n;
vpItem.canVote = vp.some(vp => vp.value > 0n);
}
} catch (e: unknown) {
if (e instanceof utils.errors.VotingPowerDetailsError) {
Expand Down
4 changes: 4 additions & 0 deletions apps/ui/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ input[type='number'] {
appearance: textfield;
}

input[type="time"]::-webkit-calendar-picker-indicator {
display: none;
}

input:placeholder-shown {
@apply text-ellipsis;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/views/Proposal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ watchEffect(() => {
<a
v-if="
votingPower?.status === 'success' &&
votingPower.totalVotingPower === BigInt(0)
votingPower.votingPowers.every(v => v.value === 0n)
"
:href="`${HELPDESK_URL}/en/articles/9566904-why-do-i-have-0-voting-power`"
target="_blank"
Expand Down
Loading

0 comments on commit 5ab0d42

Please sign in to comment.