Skip to content

Commit

Permalink
feat: add remove modal, view json
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpeach committed Aug 1, 2024
1 parent b5cdddd commit d7df339
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 109 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- [#1058](https://github.com/alleslabs/celatone-frontend/pull/1058) Show chain config JSON and remove modal
- [#1057](https://github.com/alleslabs/celatone-frontend/pull/1057) Add local minitias to network selector
- [#1043](https://github.com/alleslabs/celatone-frontend/pull/1043) Save custom minitias JSON form to localstorage
- [#1059](https://github.com/alleslabs/celatone-frontend/pull/1059) Disable add custom networks on non initia deployments
- [#1052](https://github.com/alleslabs/celatone-frontend/pull/1052) Add entry point to add custom minitias network in network selector
- [#1043](https://github.com/alleslabs/celatone-frontend/pull/1043) Save custom minitias JSON form to localstorage
- [#1038](https://github.com/alleslabs/celatone-frontend/pull/1038) Add custom networks options page to navigate between manual and upload json
- [#1054](https://github.com/alleslabs/celatone-frontend/pull/1054) Add chain config store, useChainConfig hook, and apply it all places

Expand Down
59 changes: 59 additions & 0 deletions src/lib/components/modal/RemoveChainConfigModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Text, useToast } from "@chakra-ui/react";
import type { ReactNode } from "react";

import { useInternalNavigate } from "lib/app-provider";
import { CustomIcon } from "lib/components/icon";
import { useChainConfigStore } from "lib/providers/store";

import { ActionModal } from "./ActionModal";

interface RemoveChainConfigModalProps {
chainId: string;
trigger: ReactNode;
}

export function RemoveChainConfigModal({
chainId,
trigger,
}: RemoveChainConfigModalProps) {
const { removeChainConfig, getChainConfig } = useChainConfigStore();
const navigate = useInternalNavigate();

const chainConfig = getChainConfig(chainId);

const toast = useToast();
const handleRemove = () => {
removeChainConfig(chainId);
navigate({ pathname: "/", replace: true });

setTimeout(() => {
toast({
title: `Removed '${chainConfig?.prettyName}'`,
status: "success",
duration: 5000,
isClosable: false,
position: "bottom-right",
icon: <CustomIcon name="check-circle-solid" color="success.main" />,
});
}, 1000);
};

return (
<ActionModal
title={`Removed '${chainConfig?.prettyName}'?`}
icon="delete-solid"
iconColor="error.light"
trigger={trigger}
mainBtnTitle="Yes, Remove it"
mainVariant="error"
mainAction={handleRemove}
otherBtnTitle="No, Keep It"
>
<Text>
All information about your Minitia will be lost and can&lsquo;t be
recovered. You can save this address again later, but you will need to
add its new address name.
</Text>
</ActionModal>
);
}
9 changes: 8 additions & 1 deletion src/lib/layout/network-menu/network-card/NetworkCardCta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ export const NetworkCardCta = observer(
{isEditable && (
<Flex
{...pinIconStyles}
onClick={() => navigate({ pathname: "/network-config" })}
onClick={() =>
navigate({
pathname: "/network-config",
query: {
chainId,
},
})
}
>
<CustomIcon name="settings" color="gray.600" boxSize={6} />
</Flex>
Expand Down
267 changes: 159 additions & 108 deletions src/lib/pages/network-config/index.tsx
Original file line number Diff line number Diff line change
@@ -1,120 +1,171 @@
import {
Button,
chakra,
Flex,
Grid,
TabList,
TabPanel,
TabPanels,
Tabs,
Tag,
} from "@chakra-ui/react";
import { Button, Grid, Heading, Stack } from "@chakra-ui/react";
import { isUndefined } from "lodash";
import { useRouter } from "next/router";
import { z } from "zod";

import { useAllowCustomNetworks } from "lib/app-provider";
import ActionPageContainer from "lib/components/ActionPageContainer";
import {
CustomNetworkFooterCta,
CustomNetworkPageHeader,
} from "lib/components/custom-network";
import { CustomTab } from "lib/components/CustomTab";
import { CustomNetworkPageHeader } from "lib/components/custom-network";
// import { CustomTab } from "lib/components/CustomTab";
import { CustomIcon } from "lib/components/icon";
import JsonReadOnly from "lib/components/json/JsonReadOnly";
import { RemoveChainConfigModal } from "lib/components/modal/RemoveChainConfigModal";
import { InvalidState } from "lib/components/state";
import { useChainConfigStore } from "lib/providers/store";
import { jsonPrettify } from "lib/utils";

import { ExportNetworkConfig } from "./components/ExportNetworkConfig";
import { UpdateGasFeeDetails } from "./components/UpdateGasFeeDetails";
import { UpdateNetworkDetails } from "./components/UpdateNetworkDetails";
import { UpdateSupportedFeatures } from "./components/UpdateSupportedFeatures";
import { UpdateWalletRegistry } from "./components/UpdateWalletRegistry";

const StyledCustomTab = chakra(CustomTab, {
baseStyle: {
border: "unset",
borderRadius: "4px",
_selected: { bgColor: "gray.800" },
_hover: { bgColor: "gray.700" },
},
});

const StyledTabPanel = chakra(TabPanel, {
baseStyle: {
p: 0,
width: "550px",
minWidth: "550px",
},
});

const TabMenu = [
{ name: "Network Details", key: "network-details" },
{ name: "Supported Features", key: "supported-features" },
{ name: "Gas & Fee Details", key: "gas-fee-details" },
{ name: "Wallet Registry", key: "wallet-registry" },
];
// import { ExportNetworkConfig } from "./components/ExportNetworkConfig";
// import { UpdateGasFeeDetails } from "./components/UpdateGasFeeDetails";
// import { UpdateNetworkDetails } from "./components/UpdateNetworkDetails";
// import { UpdateSupportedFeatures } from "./components/UpdateSupportedFeatures";
// import { UpdateWalletRegistry } from "./components/UpdateWalletRegistry";

export const NetworkConfig = () => {
useAllowCustomNetworks({ shouldRedirect: true });
// const StyledCustomTab = chakra(CustomTab, {
// baseStyle: {
// border: "unset",
// borderRadius: "4px",
// _selected: { bgColor: "gray.800" },
// _hover: { bgColor: "gray.700" },
// },
// });

// const StyledTabPanel = chakra(TabPanel, {
// baseStyle: {
// p: 0,
// width: "550px",
// minWidth: "550px",
// },
// });

// const TabMenu = [
// { name: "Network Details", key: "network-details" },
// { name: "Supported Features", key: "supported-features" },
// { name: "Gas & Fee Details", key: "gas-fee-details" },
// { name: "Wallet Registry", key: "wallet-registry" },
// ];

const InvalidChainId = () => <InvalidState title="Invalid Chain ID" />;

interface NetworkConfigBodyProps {
chainId: string;
}

const NetworkConfigBody = ({ chainId }: NetworkConfigBodyProps) => {
const { getChainConfig } = useChainConfigStore();
const chainConfig = getChainConfig(chainId);

// const leftButtonProps = {
// label: "Cancel",
// action: () => {},
// variant: "outline-secondary",
// };

// const rightButtonProps = {
// label: "Update",
// action: () => {},
// variant: "primary",
// };

const forms = [
<UpdateNetworkDetails />,
<UpdateSupportedFeatures />,
<UpdateGasFeeDetails />,
<UpdateWalletRegistry />,
];

const leftButtonProps = {
label: "Cancel",
action: () => {},
variant: "outline-secondary",
};

const rightButtonProps = {
label: "Update",
action: () => {},
variant: "primary",
};
if (isUndefined(chainConfig)) return <InvalidChainId />;

return (
<>
<ActionPageContainer width={900}>
<CustomNetworkPageHeader
title="CHAIN_NAME"
subtitle="Your Custom Minitia"
hasAlert={false}
/>
<Tabs variant="unstyled" orientation="vertical" mt={6}>
<Grid templateColumns="2fr 5fr" gap={6} w="full" my={8}>
<TabList w="full">
{TabMenu.map((item) => (
<StyledCustomTab key={item.key}>{item.name}</StyledCustomTab>
))}
<StyledCustomTab pointerEvents="none" isDisabled>
<Flex gap={2} align="center">
Export JSON <Tag size="xs">Soon</Tag>
</Flex>
</StyledCustomTab>
<Button
variant="outline-gray"
mt={10}
size="sm"
leftIcon={<CustomIcon name="delete" />}
>
Remove Network
</Button>
</TabList>
<TabPanels px={8} w="full">
{forms.map((item) => (
<StyledTabPanel>{item}</StyledTabPanel>
))}
<StyledTabPanel>
<ExportNetworkConfig />
</StyledTabPanel>
</TabPanels>
</Grid>
</Tabs>
</ActionPageContainer>
<CustomNetworkFooterCta
leftButtonProps={leftButtonProps}
rightButtonProps={rightButtonProps}
isCenterAlign={false}
<ActionPageContainer width={900}>
<CustomNetworkPageHeader
title={chainConfig.prettyName}
subtitle="Your Custom Minitia"
hasAlert={false}
/>
</>
<Grid templateColumns="2fr 5fr" gap={6} w="full" my={8}>
<RemoveChainConfigModal
chainId={chainId}
trigger={
<Button
variant="outline-gray"
mt={10}
size="md"
leftIcon={<CustomIcon name="delete" />}
>
Remove Network
</Button>
}
/>
<Stack>
<Heading as="h6" variant="h6">
Current Configuration in JSON
</Heading>
<JsonReadOnly
text={jsonPrettify(JSON.stringify(chainConfig))}
canCopy
fullWidth
/>
</Stack>
</Grid>
</ActionPageContainer>
);

// return (
// <>
// <ActionPageContainer width={900}>
// <CustomNetworkPageHeader
// title={chainConfig.prettyName}
// subtitle="Your Custom Minitia"
// hasAlert={false}
// />
// <Tabs variant="unstyled" orientation="vertical" mt={6}>
// <Grid templateColumns="2fr 5fr" gap={6} w="full" my={8}>
// <TabList w="full">
// {TabMenu.map((item) => (
// <StyledCustomTab key={item.key}>{item.name}</StyledCustomTab>
// ))}
// <StyledCustomTab pointerEvents="none" isDisabled>
// <Flex gap={2} align="center">
// Export JSON <Tag size="xs">Soon</Tag>
// </Flex>
// </StyledCustomTab>
// <Button
// variant="outline-gray"
// mt={10}
// size="sm"
// leftIcon={<CustomIcon name="delete" />}
// >
// Remove Network
// </Button>
// </TabList>
// <TabPanels px={8} w="full">
// <StyledTabPanel>
// <UpdateNetworkDetails />
// </StyledTabPanel>
// <StyledTabPanel>
// <UpdateSupportedFeatures />
// </StyledTabPanel>
// <StyledTabPanel>
// " <UpdateGasFeeDetails />
// </StyledTabPanel>
// <StyledTabPanel>
// <UpdateWalletRegistry />
// </StyledTabPanel>
// <StyledTabPanel>
// <ExportNetworkConfig />
// </StyledTabPanel>
// </TabPanels>
// </Grid>
// </Tabs>
// </ActionPageContainer>
// <CustomNetworkFooterCta
// leftButtonProps={leftButtonProps}
// rightButtonProps={rightButtonProps}
// isCenterAlign={false}
// />
// </>
// );
};

export const NetworkConfig = () => {
useAllowCustomNetworks({ shouldRedirect: true });
const router = useRouter();
const validated = z.string().safeParse(router.query.chainId);

if (!validated.success) return <InvalidChainId />;

return <NetworkConfigBody chainId={validated.data} />;
};
File renamed without changes.

0 comments on commit d7df339

Please sign in to comment.