From b0c0c58b0f21780fb30289ac293f4b2bf27421c9 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Fri, 6 Dec 2024 17:53:27 -0500 Subject: [PATCH 01/10] Added basic erc20 token list, WIP for nfts and uploading custom tokenlists --- src/components/helpers/FilledCheckBox.tsx | 5 +- .../helpers/FilledRoundCheckBox.tsx | 2 +- src/components/helpers/index.tsx | 6 + src/components/network/NetworkItem.tsx | 2 +- src/components/recovery/WalletList.tsx | 4 +- .../wallet/collectibles/ImportCollectible.tsx | 171 ++++++++++++------ .../wallet/collectibles/SendCollectible.tsx | 2 +- src/components/wallet/tokens/ImportToken.tsx | 107 ++++++++--- src/components/wallet/tokens/SendToken.tsx | 2 +- .../wallet/tokens/TokenBalanceItem.tsx | 2 - src/components/wallet/tokens/TokenList.tsx | 4 +- src/constants/network.ts | 74 ++++---- src/constants/storage.ts | 5 +- src/routes/Recovery.tsx | 2 +- src/stores/CollectibleStore.ts | 46 ++++- src/stores/NetworkStore.ts | 2 +- src/stores/TokenStore.ts | 33 ++++ src/utils/indexeddb.ts | 59 ++++-- 18 files changed, 381 insertions(+), 147 deletions(-) create mode 100644 src/components/helpers/index.tsx diff --git a/src/components/helpers/FilledCheckBox.tsx b/src/components/helpers/FilledCheckBox.tsx index 8152a0d..9c8d8e0 100644 --- a/src/components/helpers/FilledCheckBox.tsx +++ b/src/components/helpers/FilledCheckBox.tsx @@ -1,9 +1,9 @@ -import { Box } from '@0xsequence/design-system' +import { Box, BoxProps } from '@0xsequence/design-system' import Checkmark from '~/assets/icons/checkmark.svg' import EmptyCheckBox from '~/assets/icons/square-checkbox.svg' -export default function FilledCheckBox({ checked, size = 'lg' }: { checked: boolean; size?: 'lg' | 'md' }) { +export function FilledCheckBox({ checked, size = 'lg', ...rest }: { checked: boolean; size?: 'lg' | 'md' } & BoxProps) { return ( {checked ? ( void }) const [isAddingCollectible, setIsAddingCollectible] = useState(false) const [tokenDirectory, setTokenDirectory] = useState() + const [isAddingCollectibleManually, setIsAddingCollectibleManually] = useState(false) + + const [collectibleList, setCollectibleList] = useState(undefined) + useEffect(() => { - if (selectedNetwork) { - setTokenDirectory(networks.find(n => n.chainId === selectedNetwork.chainId)?.blockExplorer?.rootUrl) + const fetchCollectibleList = async () => { + if (selectedNetwork) { + setTokenDirectory(networks.find(n => n.chainId === selectedNetwork.chainId)?.blockExplorer?.rootUrl) + if (contractType === CollectibleContractTypeValues.ERC721) { + setCollectibleList(await collectibleStore.getDefaultERC721List(selectedNetwork.chainId)) + } else if (contractType === CollectibleContractTypeValues.ERC1155) { + setCollectibleList(await collectibleStore.getDefaultERC1155List(selectedNetwork.chainId)) + } + } } + fetchCollectibleList() + if (selectedNetwork && collectibleAddress && collectibleTokenId && contractType) { collectibleStore .getCollectibleInfo({ @@ -117,7 +130,7 @@ export default function ImportCollectible({ onClose }: { onClose: () => void }) - Import ERC721 or ERC1155 Collectible + Import ERC721 or ERC1155 Collectibles @@ -133,40 +146,6 @@ export default function ImportCollectible({ onClose }: { onClose: () => void }) /> - - - Collectible Address - - - - - See addresses on network's - - - { - if (tokenDirectory) { - window.open(tokenDirectory) - } - }} - > - directory - - - - ) => { - setCollectibleAddress(ev.target.value) - }} - /> - - Collectible Type @@ -184,27 +163,96 @@ export default function ImportCollectible({ onClose }: { onClose: () => void }) - Collectible Token ID + Token - void }) => { - if (!/[0-9]/.test(event.key)) { - event.preventDefault() - } - }} - onChange={(ev: ChangeEvent) => { - if (ev.target.value === '') { - setCollectibleTokenId(undefined) - return - } - - setCollectibleTokenId(ev.target.value as unknown as number) - }} + {}} + width="fit" + cursor="pointer" + paddingBottom="0.5" + opacity={{ base: '100', hover: '80' }} + > + + Import external token list + + + + { + return { + label: token.symbol, + value: token.address + } + }) ?? [] + } + onValueChange={value => setTokenAddress(value)} /> + + {isAddingTokenManually && ( + + + Token Address + + + + + See addresses on network's + + { + if (tokenDirectory) { + window.open(tokenDirectory) + } + }} + > + directory + + + + ) => { + setTokenAddress(ev.target.value) + }} + /> + + )} {isFetchingTokenInfo && ( @@ -171,8 +213,19 @@ export default function ImportToken({ onClose }: { onClose: () => void }) { - -