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

refactor: rewrite add to other list state, add default list to save #128

Merged
merged 5 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -98,6 +98,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#128](https://github.com/alleslabs/celatone-frontend/pull/128) Rewrite add to other list state and add default list to save to
- [#114](https://github.com/alleslabs/celatone-frontend/pull/114) Handle wallet connection cases in instantiate button
- [#115](https://github.com/alleslabs/celatone-frontend/pull/115) (Contract Details Page) Show no admin and correctly handle explorer link by address type
- [#68](https://github.com/alleslabs/celatone-frontend/pull/68) Refactor past txs link props and make sure navigation works
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/forms/ListSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ export const ListSelection = forwardRef<HTMLInputElement, ListSelectionProps>(
<Flex
alignItems="center"
color="text.main"
border="1px solid rgba(255,255,255,0.12)"
border="1px solid"
borderColor="divider.main"
background="none"
borderRadius="4px"
maxW="100%"
Expand Down
37 changes: 16 additions & 21 deletions src/lib/components/modal/contract/AddToOtherList.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Flex, Text, Box } from "@chakra-ui/react";
import { observer } from "mobx-react-lite";
import { useCallback, useEffect } from "react";
import { useForm } from "react-hook-form";
import { useEffect, useState } from "react";
import { MdBookmark } from "react-icons/md";

import { ExplorerLink } from "lib/components/ExplorerLink";
import { ListSelection } from "lib/components/forms/ListSelection";
import { ActionModal } from "lib/components/modal/ActionModal";
import type { OffchainDetail } from "lib/components/OffChainForm";
import { DEFAULT_LIST } from "lib/data";
import { useHandleContractSave } from "lib/hooks/useHandleSave";
import type { ContractLocalInfo } from "lib/stores/contract";
import type { LVPair } from "lib/types";
Expand All @@ -19,31 +18,27 @@ interface AddToOtherListProps {

export const AddToOtherList = observer(
({ contractLocalInfo, triggerElement }: AddToOtherListProps) => {
const { setValue, watch } = useForm<OffchainDetail>({
mode: "all",
});

const setContractListsValue = useCallback(
(selectedLists: LVPair[]) => {
setValue("lists", selectedLists);
},
[setValue]
);

useEffect(() => {
setContractListsValue(contractLocalInfo.lists ?? []);
}, [contractLocalInfo.lists, setContractListsValue]);

const offchainState = watch();
const [contractLists, setContractLists] = useState<LVPair[]>(DEFAULT_LIST);

const handleSave = useHandleContractSave({
title: "Action Complete!",
contractAddress: contractLocalInfo.contractAddress,
instantiator: contractLocalInfo.instantiator,
label: contractLocalInfo.label,
lists: offchainState.lists,
lists: contractLists,
});

const setContractListsValue = (selectedLists: LVPair[]) =>
setContractLists(selectedLists);

poomthiti marked this conversation as resolved.
Show resolved Hide resolved
useEffect(() => {
if (contractLocalInfo.lists?.length) {
setContractListsValue(contractLocalInfo.lists);
} else {
setContractListsValue(DEFAULT_LIST);
}
}, [contractLocalInfo.lists]);

return (
<ActionModal
title="Add or remove from other lists"
Expand Down Expand Up @@ -77,7 +72,7 @@ export const AddToOtherList = observer(
>
<Box my="16px">
<ListSelection
result={offchainState.lists}
result={contractLists}
placeholder="Add to contract lists"
helperText="Grouping your contracts by adding to your existing list or create
a new list"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ExplorerLink } from "lib/components/ExplorerLink";
import { ActionModal } from "lib/components/modal/ActionModal";
import type { OffchainDetail } from "lib/components/OffChainForm";
import { OffChainForm } from "lib/components/OffChainForm";
import { DEFAULT_LIST } from "lib/data";
import { useHandleContractSave } from "lib/hooks/useHandleSave";
import type { ContractLocalInfo } from "lib/stores/contract";
import type { LVPair } from "lib/types";
Expand All @@ -28,7 +29,7 @@ export const ContractDetailsTemplate = ({
name: contractLocalInfo.name ?? "",
description: getDescriptionDefault(contractLocalInfo.description),
tags: getTagsDefault(contractLocalInfo.tags),
lists: contractLocalInfo.lists ?? [],
lists: contractLocalInfo.lists ?? DEFAULT_LIST,
};
}, [
contractLocalInfo.description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const SelectContractAdmin = ({
onClose={resetOnClose}
closeOnOverlayClick={false}
size="4xl"
isCentered
>
<ModalOverlay />
<ModalContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export const SelectContractInstantiator = ({
onClose={resetOnClose}
closeOnOverlayClick={false}
size="4xl"
isCentered
>
<ModalOverlay />
{listSlug.length === 0 || !contractList ? (
Expand Down
9 changes: 9 additions & 0 deletions src/lib/data/constant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { MdBookmark, MdInbox, MdLibraryBooks } from "react-icons/md";

import type { LVPair } from "lib/types";
import { MsgType } from "lib/types";
import { formatSlugName } from "lib/utils/format";
poomthiti marked this conversation as resolved.
Show resolved Hide resolved

export const INSTANTIATED_LIST_NAME = "Instantiated by me";

Expand Down Expand Up @@ -52,6 +54,13 @@ export const getListIcon = (listName: string) => {
}
};

export const DEFAULT_LIST: LVPair[] = [
{
label: SAVED_LIST_NAME,
value: formatSlugName(SAVED_LIST_NAME),
},
];

export const DEFAULT_ADDRESS = "default-address";

export const MAX_FILE_SIZE = 800_000;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pages/contract-details/components/ContractTop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const ContractTop = ({ contractData }: ContractTopProps) => {
fontSize="22px"
variant="none"
aria-label="save"
color="none"
color="gray.600"
icon={<MdBookmarkBorder />}
/>
}
Expand Down