Skip to content
Merged
Changes from all 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
31 changes: 15 additions & 16 deletions components/ui/MagicTextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ interface Props {

const MagicTextArea: FC<Props> = (props: Props) => {
const { isERC721, displayModal, setRecipients, holderAddresses } = props;

const [friendtechValue, setFriendtechValue] = useState<string>("");

const formatFriendtechAirdrop = (addresses: string[] | undefined, friendtechValue: string) => {
return addresses?.map((address) => `${address},${friendtechValue}`).join("\n") || "";
};
Expand All @@ -35,9 +35,17 @@ const MagicTextArea: FC<Props> = (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) {
Expand Down Expand Up @@ -91,14 +99,13 @@ const MagicTextArea: FC<Props> = (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][] = [];

console.log('hello world');

// Loop through validLines
for (let i = 0; i < validLines.length; i++) {
const regex = /(?=[=,\s]\s*\d)/;
Expand All @@ -121,14 +128,7 @@ const MagicTextArea: FC<Props> = (props: Props) => {

const handleTextareaChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
const value = e.target.value;

if (isERC721) {
handleERC721(value);
setTextareaValue(value);
} else {
handleERC20(value);
setTextareaValue(value);
}
setTextareaValue(value);
};

const handleClick = (e: MouseEvent<HTMLButtonElement>) => {
Expand All @@ -150,7 +150,6 @@ const MagicTextArea: FC<Props> = (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
Expand Down