From cad3e2c16a7c0a4ae7131b7659a86158ec38db6c Mon Sep 17 00:00:00 2001 From: poomthiti Date: Thu, 26 Jan 2023 17:26:14 +0700 Subject: [PATCH 1/5] refactor: rewrite add to other list state and add default case --- src/lib/components/forms/ListSelection.tsx | 3 +- .../modal/contract/AddToOtherList.tsx | 37 ++++++++----------- .../contract/ContractDetailsTemplate.tsx | 3 +- .../select-contract/SelectContractAdmin.tsx | 1 + .../SelectContractInstantiator.tsx | 1 + src/lib/data/constant.ts | 9 +++++ .../components/ContractTop.tsx | 2 +- 7 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/lib/components/forms/ListSelection.tsx b/src/lib/components/forms/ListSelection.tsx index ef794ddc4..0cc78c850 100644 --- a/src/lib/components/forms/ListSelection.tsx +++ b/src/lib/components/forms/ListSelection.tsx @@ -127,7 +127,8 @@ export const ListSelection = forwardRef( { - const { setValue, watch } = useForm({ - 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(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); + + useEffect(() => { + if (contractLocalInfo.lists?.length) { + setContractListsValue(contractLocalInfo.lists); + } else { + setContractListsValue(DEFAULT_LIST); + } + }, [contractLocalInfo.lists]); + return ( diff --git a/src/lib/components/modal/select-contract/SelectContractInstantiator.tsx b/src/lib/components/modal/select-contract/SelectContractInstantiator.tsx index 413af814c..a69629110 100644 --- a/src/lib/components/modal/select-contract/SelectContractInstantiator.tsx +++ b/src/lib/components/modal/select-contract/SelectContractInstantiator.tsx @@ -112,6 +112,7 @@ export const SelectContractInstantiator = ({ onClose={resetOnClose} closeOnOverlayClick={false} size="4xl" + isCentered > {listSlug.length === 0 || !contractList ? ( diff --git a/src/lib/data/constant.ts b/src/lib/data/constant.ts index bbdc666c3..bb6842fb0 100644 --- a/src/lib/data/constant.ts +++ b/src/lib/data/constant.ts @@ -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"; export const INSTANTIATED_LIST_NAME = "Instantiated by me"; @@ -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; diff --git a/src/lib/pages/contract-details/components/ContractTop.tsx b/src/lib/pages/contract-details/components/ContractTop.tsx index dab7a4dc7..8ae0011e5 100644 --- a/src/lib/pages/contract-details/components/ContractTop.tsx +++ b/src/lib/pages/contract-details/components/ContractTop.tsx @@ -79,7 +79,7 @@ export const ContractTop = ({ contractData }: ContractTopProps) => { fontSize="22px" variant="none" aria-label="save" - color="none" + color="gray.600" icon={} /> } From acc0eedbd8adc007705abc5e71d7d321a0ffc380 Mon Sep 17 00:00:00 2001 From: poomthiti Date: Thu, 26 Jan 2023 17:31:46 +0700 Subject: [PATCH 2/5] chore: changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ab983154..57aff465c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 9445b60c343be26e45cd2e6606eba90d7f133957 Mon Sep 17 00:00:00 2001 From: poomthiti Date: Fri, 27 Jan 2023 11:05:38 +0700 Subject: [PATCH 3/5] style: scroll contract modal body --- .../select-contract/SelectContractAdmin.tsx | 4 +- .../SelectContractInstantiator.tsx | 160 +++++++++--------- 2 files changed, 83 insertions(+), 81 deletions(-) diff --git a/src/lib/components/modal/select-contract/SelectContractAdmin.tsx b/src/lib/components/modal/select-contract/SelectContractAdmin.tsx index eede89156..0368bb8f7 100644 --- a/src/lib/components/modal/select-contract/SelectContractAdmin.tsx +++ b/src/lib/components/modal/select-contract/SelectContractAdmin.tsx @@ -78,7 +78,7 @@ export const SelectContractAdmin = ({ isCentered > - + @@ -86,7 +86,7 @@ export const SelectContractAdmin = ({ - + - {listSlug.length === 0 || !contractList ? ( - - - - - Select Contract - - - + + {listSlug.length === 0 || !contractList ? ( + <> + + + + Select Contract + + + - - - Fill contract address manually - - - { - const inputValue = e.target.value; - setSearchContract(inputValue as ContractAddr); - }} - placeholder={`ex. ${exampleContractAddress}`} - size="md" - /> - - - - {invalid} - + + + Fill contract address manually + + + { + const inputValue = e.target.value; + setSearchContract(inputValue as ContractAddr); + }} + placeholder={`ex. ${exampleContractAddress}`} + size="md" + /> + + + + {invalid} + - - - OR - - + + + OR + + - - Select from your Contract List - - - - - ) : ( - - - setListSlug("")} - cursor="pointer" - /> - - {contractList.name} - - - - - - - - )} + + Select from your Contract List + + + + + ) : ( + <> + + setListSlug("")} + cursor="pointer" + /> + + {contractList.name} + + + + + + + + )} + ); From ab18df84971f386b1d81f95ea5b2860fde903dfc Mon Sep 17 00:00:00 2001 From: poomthiti Date: Fri, 27 Jan 2023 11:09:26 +0700 Subject: [PATCH 4/5] fix: commented --- src/lib/components/modal/contract/AddToOtherList.tsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib/components/modal/contract/AddToOtherList.tsx b/src/lib/components/modal/contract/AddToOtherList.tsx index ec4e9f4fe..c76733311 100644 --- a/src/lib/components/modal/contract/AddToOtherList.tsx +++ b/src/lib/components/modal/contract/AddToOtherList.tsx @@ -28,14 +28,11 @@ export const AddToOtherList = observer( lists: contractLists, }); - const setContractListsValue = (selectedLists: LVPair[]) => - setContractLists(selectedLists); - useEffect(() => { if (contractLocalInfo.lists?.length) { - setContractListsValue(contractLocalInfo.lists); + setContractLists(contractLocalInfo.lists); } else { - setContractListsValue(DEFAULT_LIST); + setContractLists(DEFAULT_LIST); } }, [contractLocalInfo.lists]); @@ -76,7 +73,7 @@ export const AddToOtherList = observer( placeholder="Add to contract lists" helperText="Grouping your contracts by adding to your existing list or create a new list" - setResult={setContractListsValue} + setResult={(selectedList) => setContractLists(selectedList)} labelBgColor="gray.800" /> From b460f83056eb04a5cb7f42aa02bf8791dc6336e0 Mon Sep 17 00:00:00 2001 From: poomthiti Date: Fri, 27 Jan 2023 11:35:21 +0700 Subject: [PATCH 5/5] fix: as commented --- src/lib/components/modal/contract/AddToOtherList.tsx | 10 ++++------ src/lib/data/constant.ts | 3 +++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/lib/components/modal/contract/AddToOtherList.tsx b/src/lib/components/modal/contract/AddToOtherList.tsx index c76733311..99a3ccac8 100644 --- a/src/lib/components/modal/contract/AddToOtherList.tsx +++ b/src/lib/components/modal/contract/AddToOtherList.tsx @@ -29,11 +29,9 @@ export const AddToOtherList = observer( }); useEffect(() => { - if (contractLocalInfo.lists?.length) { - setContractLists(contractLocalInfo.lists); - } else { - setContractLists(DEFAULT_LIST); - } + setContractLists( + contractLocalInfo.lists?.length ? contractLocalInfo.lists : DEFAULT_LIST + ); }, [contractLocalInfo.lists]); return ( @@ -73,7 +71,7 @@ export const AddToOtherList = observer( placeholder="Add to contract lists" helperText="Grouping your contracts by adding to your existing list or create a new list" - setResult={(selectedList) => setContractLists(selectedList)} + setResult={setContractLists} labelBgColor="gray.800" /> diff --git a/src/lib/data/constant.ts b/src/lib/data/constant.ts index bb6842fb0..68656f2af 100644 --- a/src/lib/data/constant.ts +++ b/src/lib/data/constant.ts @@ -2,6 +2,9 @@ import { MdBookmark, MdInbox, MdLibraryBooks } from "react-icons/md"; import type { LVPair } from "lib/types"; import { MsgType } from "lib/types"; +/** + * @todos Revisit utils import later + */ import { formatSlugName } from "lib/utils/format"; export const INSTANTIATED_LIST_NAME = "Instantiated by me";