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: remove unnecessary configs in custom configs #1236

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#1236](https://github.com/alleslabs/celatone-frontend/pull/1236) Remove unnecessary configs for users in custom network configs
- [#1228](https://github.com/alleslabs/celatone-frontend/pull/1228) Refactor EVM verification form path and form type location
- [#1215](https://github.com/alleslabs/celatone-frontend/pull/1215) Bump react wallet widget package to support http endpoints
- [#1205](https://github.com/alleslabs/celatone-frontend/pull/1205) Improve EVM contract verify page via external verifier
Expand Down
7 changes: 4 additions & 3 deletions src/lib/layout/network-menu/network-card/NetworkCardCta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ export const NetworkCardCta = observer(
{isEditable && (
<Flex
{...pinIconStyles}
onClick={() =>
onClick={(e) => {
e.stopPropagation();
navigate({
pathname: "/custom-network/edit/[chainId]",
query: {
chainId,
},
})
}
});
}}
>
<CustomIcon name="settings" color="gray.600" boxSize={6} />
</Flex>
Expand Down
5 changes: 3 additions & 2 deletions src/lib/pages/custom-network/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const DEFAULT_POOL_CONFIG: ChainConfig["features"]["pool"] = {

export const DEFAULT_PUBLIC_PROJECT_CONFIG: ChainConfig["features"]["publicProject"] =
{
enabled: true,
enabled: false,
};

export const DEFAULT_GOV_CONFIG: ChainConfig["features"]["gov"] = {
Expand All @@ -42,10 +42,11 @@ export const DEFAULT_DENOM = "umin";

export const DEFAULT_CUSTOM_MINITIA_NETWORK: Pick<
ChainConfig,
"tier" | "chain" | "network_type" | "extra"
"tier" | "chain" | "wallets" | "network_type" | "extra"
> = {
tier: "sequencer",
chain: "initia",
wallets: [],
network_type: "local",
extra: {
isValidatorExternalLink: null,
Expand Down
26 changes: 18 additions & 8 deletions src/lib/pages/custom-network/edit/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Flex, Heading, Stack } from "@chakra-ui/react";
import { isUndefined, omit } from "lodash";
import { isUndefined, pick } from "lodash";
import { useRouter } from "next/router";
import { useCallback, useMemo } from "react";
import { z } from "zod";
Expand Down Expand Up @@ -57,13 +57,23 @@ interface NetworkConfigBodyProps {
const NetworkConfigBody = ({ chainId }: NetworkConfigBodyProps) => {
const { getLocalChainConfig } = useLocalChainConfigStore();
const chainConfig = getLocalChainConfig(chainId);
const json = useMemo(
() =>
JSON.stringify(
omit(chainConfig, ["tier", "wallets", "chain", "extra", "network_type"])
),
[chainConfig]
);
const json = useMemo(() => {
if (!chainConfig) return "";

// NOTE: hardcoding so the order is fixed
return JSON.stringify({
chainId: chainConfig.chainId,
registryChainName: chainConfig.registryChainName,
prettyName: chainConfig.prettyName,
logo_URIs: chainConfig.logo_URIs,
lcd: chainConfig.lcd,
rpc: chainConfig.rpc,
features: pick(chainConfig.features, ["wasm", "move", "evm"]),
gas: chainConfig.gas,
fees: chainConfig.fees,
registry: chainConfig.registry,
});
}, [chainConfig]);

const handleExportJson = useCallback(() => {
const blob = new Blob([json], {
Expand Down
31 changes: 20 additions & 11 deletions src/lib/pages/custom-network/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import {
zAsset,
zChainConfig,
zDenomUnit,
zEvmConfig,
zFeeToken,
zGasConfig,
zGasConfigCosts,
zHttpsUrl,
zMoveConfig,
zNumberInput,
zRegistry,
zWasmConfig,
} from "lib/types";

import {
Expand Down Expand Up @@ -367,7 +370,6 @@ export const zAddNetworkManualChainConfigJson = ({
assets,
}: AddNetworkManualForm) => ({
...DEFAULT_CUSTOM_MINITIA_NETWORK,
wallets: [],
chainId,
registryChainName,
prettyName,
Expand Down Expand Up @@ -414,9 +416,6 @@ export const zAddNetworkManualChainConfigJson = ({
registry: {
bech32_prefix,
slip44,
staking: {
staking_tokens: [],
},
assets: assets.map(({ name, base, symbol, denoms }) => ({
name,
base,
Expand Down Expand Up @@ -445,15 +444,29 @@ export const zAddNetworkJsonChainConfigJson = zChainConfig
logo_URIs: true,
lcd: true,
rpc: true,
wallets: true,
features: true,
gas: true,
fees: true,
registry: true,
})
.transform<ChainConfig>((val) => ({
.extend({
features: z.object({
wasm: zWasmConfig,
move: zMoveConfig,
evm: zEvmConfig,
}),
})
.transform<ChainConfig>(({ features, ...val }) => ({
...val,
...DEFAULT_CUSTOM_MINITIA_NETWORK,
features: {
...features,
pool: DEFAULT_POOL_CONFIG,
publicProject: DEFAULT_PUBLIC_PROJECT_CONFIG,
gov: DEFAULT_GOV_CONFIG,
nft: {
enabled: features.move.enabled,
},
},
}));

export type AddNetworkJsonChainConfigJson = z.infer<
Expand Down Expand Up @@ -489,7 +502,6 @@ export const zAddNetworkLinkChainConfigJson = z
chainId: val.chainId,
registryChainName: val.chainId,
prettyName: capitalize(val.chainId),
wallets: [],
lcd: val.lcd,
rpc: val.rpc,
features: {
Expand Down Expand Up @@ -523,9 +535,6 @@ export const zAddNetworkLinkChainConfigJson = z
registry: {
bech32_prefix: bech32Prefix,
slip44: DEFAULT_SLIP44,
staking: {
staking_tokens: [],
},
assets: [],
},
};
Expand Down
6 changes: 3 additions & 3 deletions src/lib/types/chainConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const zNumberInput = z.preprocess(
})
);

const zWasmConfig = z.union([
export const zWasmConfig = z.union([
z.object({
enabled: z.literal(true),
storeCodeMaxFileSize: z.number(),
Expand All @@ -26,7 +26,7 @@ const zWasmConfig = z.union([
}),
]);

const zMoveConfig = z.union([
export const zMoveConfig = z.union([
z.object({
enabled: z.literal(true),
moduleMaxFileSize: z.number(),
Expand All @@ -36,7 +36,7 @@ const zMoveConfig = z.union([
}),
]);

const zEvmConfig = z.union([
export const zEvmConfig = z.union([
z.object({
enabled: z.literal(true),
jsonRpc: zHttpsUrl,
Expand Down