Skip to content

Commit

Permalink
Merge f262dfc into 609f5e8
Browse files Browse the repository at this point in the history
  • Loading branch information
chloezxyy authored Oct 9, 2023
2 parents 609f5e8 + f262dfc commit c967168
Showing 1 changed file with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LabeledAddress, LocalAddress } from "@store/userPreferences";
import { useThemeContext } from "@waveshq/walletkit-ui";
import { WalletTextInputV2 } from "@components/WalletTextInputV2";
import { SubmitButtonGroup } from "@components/SubmitButtonGroup";
import { WalletAddressI, useWalletAddress } from "@hooks/useWalletAddress";
import { useWalletAddress, WalletAddressI } from "@hooks/useWalletAddress";
import { useSelector } from "react-redux";
import { RootState } from "@store";
import { DomainType, useDomainContext } from "@contexts/DomainContext";
Expand Down Expand Up @@ -63,11 +63,38 @@ export const CreateOrEditAddressLabelForm = memo(
}, [labelInput]);

const validateLabelInput = (input: string): boolean => {
if (input !== undefined) {
const trimmedInput = input.trim();
if (trimmedInput !== undefined) {
if (input.trim().length > 40) {
setLabelInputErrorMessage("Invalid label. Maximum of 40 characters.");
return false;
}

if (trimmedInput === "") {
setLabelInputErrorMessage("Label cannot be empty.");
return false;
}

// check if label exists in address book
if (
walletAddress.some(
(item) =>
item.generatedLabel === trimmedInput && item.dvm !== address,
)
) {
setLabelInputErrorMessage("Use a unique wallet label.");
return false;
}

// Check walletAddressFromStore object
if (
Object.values(walletAddressFromStore).some(
(item) => item.label === trimmedInput && item.address !== address,
)
) {
setLabelInputErrorMessage("Use a unique wallet label");
return false;
}
}

setLabelInputErrorMessage("");
Expand Down Expand Up @@ -104,16 +131,12 @@ export const CreateOrEditAddressLabelForm = memo(
};

const isSaveDisabled = (): boolean => {
if (
return (
labelInput === undefined ||
labelInput === "" || // disable if label is empty or no change in label
labelInput === "" ||
labelInput === addressLabel?.label ||
labelInputErrorMessage !== ""
) {
return true;
}

return false;
);
};

return (
Expand Down

0 comments on commit c967168

Please sign in to comment.