From 9b021b1a46e3bdfee3da2331ff3d09e935de3919 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 15 Sep 2023 10:59:02 -0400 Subject: [PATCH 1/2] quick fix --- components/ui/MagicTextArea.tsx | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/components/ui/MagicTextArea.tsx b/components/ui/MagicTextArea.tsx index f9c4204..deb93c5 100644 --- a/components/ui/MagicTextArea.tsx +++ b/components/ui/MagicTextArea.tsx @@ -19,9 +19,9 @@ interface Props { const MagicTextArea: FC = (props: Props) => { const { isERC721, displayModal, setRecipients, holderAddresses } = props; - + const [friendtechValue, setFriendtechValue] = useState(""); - + const formatFriendtechAirdrop = (addresses: string[] | undefined, friendtechValue: string) => { return addresses?.map((address) => `${address},${friendtechValue}`).join("\n") || ""; }; @@ -35,9 +35,17 @@ const MagicTextArea: FC = (props: Props) => { ); useEffect(() => { - setTextareaValue(formatFriendtechAirdrop(holderAddresses, friendtechValue)); - }, [friendtechValue, holderAddresses]); + const formattedTextValue = formatFriendtechAirdrop(holderAddresses, friendtechValue); + + if (isERC721) { + handleERC721(formattedTextValue); + } else { + handleERC20(formattedTextValue); + } + + setTextareaValue(formattedTextValue); + }, [friendtechValue, holderAddresses]); const placeholder = () => { if (isERC721) { @@ -93,12 +101,11 @@ const MagicTextArea: FC = (props: Props) => { const handleERC20 = (value: string) => { const regex = /^0x[a-fA-F0-9]{40}(?= ?[^ ])([=,]?) *(\d+(\.\d+)?)$/; const lines = value.split('\n'); + const validLines = lines.filter((line) => regex.test(line)); const addressValueCombos: [string, string][] = []; - console.log('hello world'); - // Loop through validLines for (let i = 0; i < validLines.length; i++) { const regex = /(?=[=,\s]\s*\d)/; @@ -113,7 +120,7 @@ const MagicTextArea: FC = (props: Props) => { addressValueCombos.push([address, val]); } - + if (validLines.length === addressValueCombos.length) { setLocalRecipients(addressValueCombos); } @@ -121,14 +128,7 @@ const MagicTextArea: FC = (props: Props) => { const handleTextareaChange = (e: ChangeEvent) => { const value = e.target.value; - - if (isERC721) { - handleERC721(value); - setTextareaValue(value); - } else { - handleERC20(value); - setTextareaValue(value); - } + setTextareaValue(value); }; const handleClick = (e: MouseEvent) => { @@ -150,7 +150,6 @@ const MagicTextArea: FC = (props: Props) => { value={friendtechValue} onChange={(e) => { setFriendtechValue(e.target.value); - handleTextareaChange; }} placeholder="Ex: 0.1" className="border-2 border-neutral-700 bg-transparent text-base-100 p-4 text-xl rounded-md mb-2" // added mb-2 here From ee56539364e56756818dfb585d3bfd728cf11baf Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 15 Sep 2023 11:04:22 -0400 Subject: [PATCH 2/2] Handle .1 --- components/ui/MagicTextArea.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/ui/MagicTextArea.tsx b/components/ui/MagicTextArea.tsx index deb93c5..bde1508 100644 --- a/components/ui/MagicTextArea.tsx +++ b/components/ui/MagicTextArea.tsx @@ -99,9 +99,9 @@ const MagicTextArea: FC = (props: Props) => { }; const handleERC20 = (value: string) => { - const regex = /^0x[a-fA-F0-9]{40}(?= ?[^ ])([=,]?) *(\d+(\.\d+)?)$/; + const regex = /^0x[a-fA-F0-9]{40}(?= ?[^ ])([=,]?) *(\d*(\.\d+)?)$/; const lines = value.split('\n'); - + const validLines = lines.filter((line) => regex.test(line)); const addressValueCombos: [string, string][] = []; @@ -120,7 +120,7 @@ const MagicTextArea: FC = (props: Props) => { addressValueCombos.push([address, val]); } - + if (validLines.length === addressValueCombos.length) { setLocalRecipients(addressValueCombos); }