Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Conversation

@DaniSomoza
Copy link
Contributor

Added some Accessibility improvements in the AddressInput Component.

  • We are using a tag for the input label
  • If an error is present o the value is empty we only visually remove the label see this for more info
  • Restored some MUI animations
  • Added Network prefix support
  • Added ENS Resolution if a function is provided

Captura de pantalla 2021-11-15 a las 17 00 34

@github-actions
Copy link

github-actions bot commented Nov 15, 2021

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action


export default AddressInput;

const TextField = styled(TextFieldMui)`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would define this on top or into a separate file. It's a long component and wasn't expecting to find it here

Copy link
Collaborator

@dasanra dasanra Nov 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, was there some issue why we didn't use the existing TextField in src/inputs/TextField/index

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new TextFieldInput and deprecated the old TextField component because is coupled to Final Form

@DaniSomoza DaniSomoza requested a review from dasanra November 22, 2021 12:22
Comment on lines 106 to 132
// const StyledTextField = styled(TextFieldInput)`
// && {
// .MuiFilledInput-root {
// background-color: lightgreen;
// width: 200px;
// transition: width 1s ease-out;
// }

// .MuiFilledInput-root.Mui-focused {
// width: 400px;
// }

// .MuiFormLabel-root.Mui-focused {
// color: ${({ error, theme }) =>
// error ? theme.colors.error : 'darkgreen'};
// }

// .MuiInputLabel-filled {
// color: ${({ theme, error }) => (error ? theme.colors.error : 'purple')};
// }

// .MuiFilledInput-underline:after {
// border-bottom: 2px solid
// ${({ theme, error }) => (error ? theme.colors.error : 'orange')};
// }
// }
// `;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added that comment to be able to see the styles in the storybook:

Captura de pantalla 2021-11-22 a las 16 36 41

But now I think that its better add the code inside a <pre> tag:
Captura de pantalla 2021-11-22 a las 16 42 00


// Based on https://docs.ens.domains/dapp-developer-guide/resolving-names
// [...] a correct integration of ENS treats any dot-separated name as a potential ENS name [...]
const isValidEnsName = (name: string): boolean => name.includes('.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only checks that there's a dot but not any other symbols? . is not a valid ens name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!! I will update it to match with something.somethig

What is your opinion about this regex?

const isENSRegex = new RegExp(/[^\[\]]+\.[^\[\]]/)

Captura de pantalla 2021-11-22 a las 16 23 48

Comment on lines 48 to 82
useEffect(() => {
if (isValidAddress(address) && !isChecksumAddress(address)) {
onChangeAddress(checksumAddress(address));
}
}, [address, onChangeAddress]);

// ENS resolution
useEffect(() => {
const resolveDomainName = async (ENSName: string) => {
try {
setIsLoadingENSResolution(true);
const address = (await getAddressFromDomain?.(ENSName)) as string;
onChangeAddress(address);
setPrefix(showNetworkPrefix ? networkPrefix : '');
} catch (e) {
onChangeAddress(ENSName);
setPrefix('');
} finally {
setIsLoadingENSResolution(false);
}
};

const isEnsName = isValidEnsName(address);

if (isEnsName && getAddressFromDomain) {
throttle(() => resolveDomainName(address));
}
}, [
address,
getAddressFromDomain,
networkPrefix,
showNetworkPrefix,
onChangeAddress,
throttle,
]);
Copy link
Contributor

@mmv08 mmv08 Nov 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be merged into a single effect? I'm not sure if it's a good idea to run multiple effects that, in the end, call the same onChangeAddress function, could be subject to potential race conditions and bugs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done! now we only have one useEffect!

each time we use onChangeAddress we checksumValidAddress first:

 onChangeAddress(checksumValidAddress(address));

@github-actions
Copy link

📚 Storybook review

@DaniSomoza DaniSomoza requested a review from mmv08 November 22, 2021 16:05
Copy link
Contributor

@mmv08 mmv08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪

@DaniSomoza DaniSomoza merged commit 90531e3 into main Nov 23, 2021
@DaniSomoza DaniSomoza deleted the address-input-with-prefix branch November 23, 2021 16:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants