From ab83c4a93114e6e42018cfe181d562ce27ae443f Mon Sep 17 00:00:00 2001 From: Rigidity Date: Tue, 24 Dec 2024 09:25:21 -0500 Subject: [PATCH] Always allow manual entry of NFTs and tokens --- src/components/selectors/DropdownSelector.tsx | 19 ++++----- src/components/selectors/NftSelector.tsx | 30 ++++++++++++- src/components/selectors/TokenSelector.tsx | 42 ++++++++----------- src/pages/MakeOffer.tsx | 1 - 4 files changed, 54 insertions(+), 38 deletions(-) diff --git a/src/components/selectors/DropdownSelector.tsx b/src/components/selectors/DropdownSelector.tsx index 8c1fb879..38f7b83a 100644 --- a/src/components/selectors/DropdownSelector.tsx +++ b/src/components/selectors/DropdownSelector.tsx @@ -55,14 +55,8 @@ export function DropdownSelector({ - {manualInput && ( - <> -
{manualInput}
- - - )} - {setPage && ( - <> + <> + {!!setPage && (
@@ -94,10 +88,11 @@ export function DropdownSelector({
- - - )} -
+ )} + {manualInput &&
{manualInput}
} + {!!setPage || (manualInput && )} + +
{loadedItems.length === 0 ? (
No items available diff --git a/src/components/selectors/NftSelector.tsx b/src/components/selectors/NftSelector.tsx index 2578a55c..b25e896a 100644 --- a/src/components/selectors/NftSelector.tsx +++ b/src/components/selectors/NftSelector.tsx @@ -1,8 +1,10 @@ import { commands, NftRecord } from '@/bindings'; import { useErrors } from '@/hooks/useErrors'; import { nftUri } from '@/lib/nftUri'; +import { addressInfo } from '@/lib/utils'; import { useWalletState } from '@/state'; import { useEffect, useState } from 'react'; +import { Input } from '../ui/input'; import { DropdownSelector } from './DropdownSelector'; export interface NftSelectorProps { @@ -45,6 +47,14 @@ export function NftSelector({ useEffect(() => { if (value && selectedNft?.launcher_id !== value) { + try { + if (addressInfo(value).puzzleHash.length !== 64) { + return setSelectedNft(null); + } + } catch { + return setSelectedNft(null); + } + commands .getNft({ nft_id: value }) .then((data) => setSelectedNft(data.nft)) @@ -57,7 +67,13 @@ export function NftSelector({ useEffect(() => { const nftsToFetch = [...nfts.map((nft) => nft.launcher_id)]; if (value && !nfts.find((nft) => nft.launcher_id === value)) { - nftsToFetch.push(value); + try { + if (addressInfo(value).puzzleHash.length === 64) { + nftsToFetch.push(value); + } + } catch { + // The checksum failed + } } Promise.all( @@ -90,6 +106,18 @@ export function NftSelector({ setSelectedNft(nft); }} className={className} + manualInput={ + { + onChange(e.target.value); + setSelectedNft( + nfts.find((nft) => nft.launcher_id === e.target.value) ?? null, + ); + }} + /> + } renderItem={(nft) => (
void; disabled?: string[]; className?: string; - allowManualInput?: boolean; } export function TokenSelector({ @@ -18,9 +16,7 @@ export function TokenSelector({ onChange, disabled = [], className, - allowManualInput = false, }: TokenSelectorProps) { - const walletState = useWalletState(); const { addError } = useErrors(); const [tokens, setTokens] = useState([]); @@ -55,26 +51,24 @@ export function TokenSelector({ }} className={className} manualInput={ - allowManualInput && ( - { - onChange(e.target.value); - setSelectedToken( - tokens.find((token) => token.asset_id === e.target.value) ?? { - name: 'Unknown', - asset_id: e.target.value, - icon_url: null, - balance: 0, - ticker: null, - description: null, - visible: true, - }, - ); - }} - /> - ) + { + onChange(e.target.value); + setSelectedToken( + tokens.find((token) => token.asset_id === e.target.value) ?? { + name: 'Unknown', + asset_id: e.target.value, + icon_url: null, + balance: 0, + ticker: null, + description: null, + visible: true, + }, + ); + }} + /> } renderItem={(token) => (
diff --git a/src/pages/MakeOffer.tsx b/src/pages/MakeOffer.tsx index eff8bba8..be240df6 100644 --- a/src/pages/MakeOffer.tsx +++ b/src/pages/MakeOffer.tsx @@ -540,7 +540,6 @@ function AssetSelector({ .filter((amount) => amount.asset_id !== cat.asset_id) .map((amount) => amount.asset_id)} className='rounded-r-none' - allowManualInput={!offering} />