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

Convert ChainNetwork type to string. #8843

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion libs/schemas/src/entities/community.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const Community = z.object({
name: z.string(),
chain_node_id: PG_INT,
default_symbol: z.string().default(''),
network: z.nativeEnum(ChainNetwork).default(ChainNetwork.Ethereum),
network: z.string().default(ChainNetwork.Ethereum),
base: z.nativeEnum(ChainBase),
icon_url: z.string().nullish(),
active: z.boolean(),
Expand Down
45 changes: 10 additions & 35 deletions libs/shared/src/types/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,51 +127,26 @@ export enum CommunityCategoryType {
DAO = 'DAO',
}

// TODO: remove many of these chain networks, esp substrate (make them all "Substrate"),
// and just use id to identify specific chains for conditionals
// This enum represents known values for the "network" field on Community, which can be used for
// switched functionality against specific groups of communities (so we could e.g. group together all
// communities on a specific testnet, or all ERC20s). In practice this field is deprecated, and should be
// removed, but these following values remain as either defaults or for custom integration support.
export enum ChainNetwork {
Ethereum = 'ethereum',
ERC20 = 'erc20',
ERC721 = 'erc721',
ERC1155 = 'erc1155',
Edgeware = 'edgeware',
EdgewareTestnet = 'edgeware-testnet',
Kusama = 'kusama',
Kulupu = 'kulupu',
Polkadot = 'polkadot',
Plasm = 'plasm',
Stafi = 'stafi',
Darwinia = 'darwinia',
Phala = 'phala',
Centrifuge = 'centrifuge',
Straightedge = 'straightedge',
Osmosis = 'osmosis',
Injective = 'injective',
InjectiveTestnet = 'injective-testnet',
Solana = 'solana',
Terra = 'terra',
Ethereum = 'ethereum',
NEAR = 'near',
NEARTestnet = 'near-testnet',
Stargaze = 'stargaze',
Compound = 'compound',
Aave = 'aave',
AaveLocal = 'aave-local',
dYdX = 'dydx',
Metacartel = 'metacartel',
ALEX = 'alex',
ERC20 = 'erc20',
ERC721 = 'erc721',
ERC1155 = 'erc1155',
CW20 = 'cw20',
CW721 = 'cw721',
Clover = 'clover',
HydraDX = 'hydradx',
Crust = 'crust',
Sputnik = 'sputnik',
SolanaDevnet = 'solana-devnet',
SolanaTestnet = 'solana-testnet',
Solana = 'solana',
SPL = 'spl', // solana token
Evmos = 'evmos',
Kava = 'kava',
Kyve = 'kyve',
Stargaze = 'stargaze',
Cosmos = 'cosmos',
}

/**
Expand Down
8 changes: 2 additions & 6 deletions packages/commonwealth/client/scripts/models/ChainInfo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { ExtendedCommunity } from '@hicommonwealth/schemas';
import type {
AddressRole,
ChainNetwork,
DefaultPage,
} from '@hicommonwealth/shared';
import type { AddressRole, DefaultPage } from '@hicommonwealth/shared';
import { ChainBase } from '@hicommonwealth/shared';
import type { RegisteredTypes } from '@polkadot/types/types';
import { z } from 'zod';
Expand All @@ -23,7 +19,7 @@ class ChainInfo {
public readonly profileCount: number;
public readonly default_symbol: string;
public name: string;
public readonly network: ChainNetwork;
public readonly network: string;
public readonly base: ChainBase;
public iconUrl: string;
public description: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const CommunitiesPage = () => {
return list.filter((data) => {
const communityNetwork =
Object.keys(ChainNetwork)[
Object.values(ChainNetwork).indexOf(data.network)
Object.values(ChainNetwork).indexOf(data.network as ChainNetwork)
]; // Converts chain.base into a ChainBase key to match our filterMap keys

if (communityNetworks.includes(communityNetwork)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { CreateCommunity } from '@hicommonwealth/schemas';
import {
BalanceType,
ChainBase,
ChainNetwork,
ChainType,
DefaultPage,
NotificationCategories,
Expand Down Expand Up @@ -370,7 +369,7 @@ export async function __createCommunity(
default_symbol,
icon_url,
description,
network: network as ChainNetwork,
network,
type,
// @ts-expect-error StrictNullChecks
social_links: uniqueLinksArray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
CommunityInstance,
ModelInstance,
} from '@hicommonwealth/model';
import { ChainNetwork } from '@hicommonwealth/shared';
import { type ModelStatic } from 'sequelize';
import { z } from 'zod';
import { ServerCommunitiesController } from '../server_communities_controller';
Expand Down Expand Up @@ -61,9 +60,10 @@ export async function __updateCommunityId(
id: new_community_id,
...communityData,
redirect: community_id,
network: (communityData.network === id
? new_community_id
: communityData.network) as ChainNetwork,
network:
communityData.network === id
? new_community_id
: communityData.network,
},
{ transaction },
);
Expand Down
Loading