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

feat: allow proposal creation only on premium networks #1120

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
feat: pull list of premium networs from hub
  • Loading branch information
wa0x6e committed Jan 27, 2025
commit 2182fd28cf1b2df99b335ac852fdd6f03bade58d
8 changes: 1 addition & 7 deletions apps/ui/src/components/Ui/SelectorNetwork.vue
Original file line number Diff line number Diff line change
@@ -15,9 +15,7 @@ const props = defineProps<{
};
}>();

const { networks, getUsage } = useOffchainNetworksList(
props.definition.networkId
);
const { networks } = useOffchainNetworksList(props.definition.networkId);

const options = computed(() => {
const networksListKind = props.definition.networksListKind;
@@ -87,10 +85,6 @@ const options = computed(() => {
})
.filter(network => !network.readOnly);
});

onMounted(() => {
getUsage();
});
</script>

<template>
44 changes: 34 additions & 10 deletions apps/ui/src/composables/useOffchainNetworksList.ts
Original file line number Diff line number Diff line change
@@ -3,25 +3,24 @@ import { getNetwork } from '@/networks';
import { ChainId, NetworkID } from '@/types';

const usage = ref<Record<ChainId, number | undefined> | null>(null);
const premiumChainIds = ref<Set<ChainId>>(new Set());
const loaded = ref(false);

export function useOffchainNetworksList(
networkId: NetworkID,
hideUnused = false
) {
async function getUsage() {
if (loaded.value) return;

const network = getNetwork(networkId);

usage.value = await network.api.getNetworksUsage();
}

const networks = computed(() => {
const rawNetworks = Object.values(snapshotJsNetworks).filter(
({ chainId }) => typeof chainId === 'number'
);

rawNetworks.forEach(network => {
if (premiumChainIds.value.has(network.chainId)) {
network.premium = true;
}
});

const usageValue = usage.value;
if (!usageValue) return rawNetworks;

@@ -37,8 +36,33 @@ export function useOffchainNetworksList(
});
});

async function load() {
const network = getNetwork(networkId);
const networks = await network.api.getNetworks();

usage.value = Object.keys(networks).reduce(
(acc, chainId) => {
acc[chainId] = networks[chainId].spaces_count;
return acc;
},
{} as Record<ChainId, number>
);

Object.keys(networks).forEach(chainId => {
if (networks[chainId].premium) {
premiumChainIds.value.add(Number(chainId));
}
});

loaded.value = true;
}

onMounted(() => {
load();
});

return {
getUsage,
networks
networks,
premiumChainIds
};
}
6 changes: 0 additions & 6 deletions apps/ui/src/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -159,9 +159,3 @@ export const VALIDATION_TYPES_INFO: Record<
description: 'Use EAS attest.sh to determine if user can create a proposal.'
}
};

export const PROPOSALS_NETWORK_WHITELIST: ChainId[] = [
1, //Ethereum
42161, // Arbitrum
137 // Polygon
];
2 changes: 1 addition & 1 deletion apps/ui/src/networks/common/graphqlApi/index.ts
Original file line number Diff line number Diff line change
@@ -711,7 +711,7 @@ export function createApi(
loadStrategy: async () => {
return null;
},
getNetworksUsage: async () => {
getNetworks: async () => {
return {};
},
loadSettings: async () => {
11 changes: 7 additions & 4 deletions apps/ui/src/networks/offchain/api/index.ts
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ import {
import {
ALIASES_QUERY,
LEADERBOARD_QUERY,
NETWORKS_USAGE_QUERY,
NETWORKS_QUERY,
PROPOSAL_QUERY,
PROPOSALS_QUERY,
RANKING_QUERY,
@@ -816,15 +816,18 @@ export function createApi(

return formatStrategy(data.strategy as ApiStrategy);
},
getNetworksUsage: async () => {
getNetworks: async () => {
const { data } = await apollo.query({
query: NETWORKS_USAGE_QUERY
query: NETWORKS_QUERY
});

return Object.fromEntries(
data.networks.map((network: any) => [
Number(network.id),
network.spacesCount
{
spaces_count: network.spacesCount,
premium: true
}
])
);
},
2 changes: 1 addition & 1 deletion apps/ui/src/networks/offchain/api/queries.ts
Original file line number Diff line number Diff line change
@@ -367,7 +367,7 @@ export const STRATEGY_QUERY = gql`
${STRATEGY_FRAGMENT}
`;

export const NETWORKS_USAGE_QUERY = gql`
export const NETWORKS_QUERY = gql`
query Networks {
networks {
id
4 changes: 3 additions & 1 deletion apps/ui/src/networks/types.ts
Original file line number Diff line number Diff line change
@@ -327,7 +327,9 @@ export type NetworkApi = {
): Promise<Statement[]>;
loadStrategies(): Promise<StrategyTemplate[]>;
loadStrategy(address: string): Promise<StrategyTemplate | null>;
getNetworksUsage(): Promise<Record<ChainId, number | undefined>>;
getNetworks(): Promise<
Record<ChainId, { spaces_count: number; premium: boolean }>
>;
loadSettings(): Promise<Setting[]>;
};

6 changes: 1 addition & 5 deletions apps/ui/src/views/My/Explore.vue
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ const protocol = ref<ExplorePageProtocol>(DEFAULT_PROTOCOL);
const network = ref<string>(DEFAULT_NETWORK);
const category = ref<SpaceCategory>(DEFAULT_CATEGORY);

const { networks: offchainNetworks, getUsage } = useOffchainNetworksList(
const { networks: offchainNetworks } = useOffchainNetworksList(
metadataNetwork,
true
);
@@ -138,10 +138,6 @@ watch(
);

watchEffect(() => setTitle('Explore'));

onMounted(() => {
getUsage();
});
</script>

<template>
7 changes: 5 additions & 2 deletions apps/ui/src/views/Space/Editor.vue
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
import { sanitizeUrl } from '@braintree/sanitize-url';
import { LocationQueryValue } from 'vue-router';
import { StrategyWithTreasury } from '@/composables/useTreasuries';
import { PROPOSALS_NETWORK_WHITELIST } from '@/helpers/constants';
import {
MAX_1D_PROPOSALS,
MAX_30D_PROPOSALS,
@@ -235,8 +234,12 @@ const unsupportedProposalNetworks = computed(() => {
)
]);

const premiumsChainIds = networks.value
.filter(network => network.premium)
.map(network => network.chainId);

return Array.from(ids)
.filter(n => !PROPOSALS_NETWORK_WHITELIST.includes(n))
.filter(n => !premiumsChainIds.includes(n))
.map(chainId => networks.value.find(n => n.chainId === chainId));
});