Skip to content

Commit

Permalink
fix: improve pasting p/x address in contact form (#22)
Browse files Browse the repository at this point in the history
Signed-off-by: ryanml <ryanlanese@gmail.com>
Co-authored-by: vvava <94397450+vvava@users.noreply.github.com>
  • Loading branch information
ryanml and vvava authored Aug 12, 2024
1 parent 7bbdbc6 commit 452d190
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/components/settings/components/ContactForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ export const ContactForm = ({
setAddressXpError('');
};

const sanitizeXPAddress = (address: string) => {
if (address.startsWith('P-') || address.startsWith('X-')) {
return address.substring(2, address.length);
} else {
return address;
}
};

const handleUpdate = (name: keyof Contact, value: string) => {
resetErrors();

Expand Down Expand Up @@ -212,6 +220,11 @@ export const ContactForm = ({
e.stopPropagation();
handleUpdate('addressXP', e.target.value);
}}
onPaste={(e) => {
e.preventDefault();
const pastedAddress = e.clipboardData.getData('Text');
handleUpdate('addressXP', sanitizeXPAddress(pastedAddress));
}}
value={contact.addressXP}
label={t('Avalanche (X/P-Chain) Address')}
error={!!addressXpError}
Expand Down

0 comments on commit 452d190

Please sign in to comment.