Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent read-only address submission when validating input #3705

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions ui/components/Shared/SharedAddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Props = {
value: { address: HexString; name?: string } | undefined,
) => void
onFocus?: () => void
onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>
id?: string
placeholder?: string
isEmpty?: boolean
Expand All @@ -23,6 +24,7 @@ export default function SharedAddressInput({
label,
onAddressChange,
onFocus,
onKeyDown,
id,
placeholder,
isEmpty,
Expand All @@ -48,6 +50,7 @@ export default function SharedAddressInput({
label={label}
onChange={setInputValue}
onFocus={onFocus}
onKeyDown={onKeyDown}
errorMessage={errorMessage}
id={id}
placeholder={placeholder}
Expand Down
3 changes: 3 additions & 0 deletions ui/components/Shared/SharedInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface Props<T> {
value?: string | undefined
onChange?: (value: T | undefined) => void
onFocus?: () => void
onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>
errorMessage?: string
warningMessage?: string
autoFocus?: boolean
Expand All @@ -37,6 +38,7 @@ export function SharedTypedInput<T = string>(props: Props<T>): ReactElement {
name,
onChange,
onFocus,
onKeyDown,
value: currentValue,
errorMessage,
warningMessage,
Expand Down Expand Up @@ -92,6 +94,7 @@ export function SharedTypedInput<T = string>(props: Props<T>): ReactElement {
handleInputChange(event.target.value)
}
onFocus={onFocus}
onKeyDown={onKeyDown}
data-empty={inputValue.trim().length < 1}
className={classNames({
error: !isEmpty && (errorMessage ?? parserError !== undefined),
Expand Down
35 changes: 23 additions & 12 deletions ui/pages/Onboarding/Tabbed/ViewOnlyWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export default function ViewOnlyWallet(): ReactElement {
)

const handleSubmitViewOnlyAddress = useCallback(async () => {
if (addressOnNetwork === undefined) {
return
}
if (addressOnNetwork === undefined) return

await dispatch(addAddressNetwork(addressOnNetwork))

Expand All @@ -63,6 +61,22 @@ export default function ViewOnlyWallet(): ReactElement {
setRedirect(true)
}, [dispatch, addressOnNetwork])

const handleFormSubmitOnEnter = (
event: React.KeyboardEvent<HTMLInputElement>,
) => {
if (event.key === "Enter") {
event.preventDefault()
handleSubmitViewOnlyAddress()
}
}

const handleFormSubmitOnClick = (
event: React.MouseEvent<HTMLButtonElement, MouseEvent>,
) => {
event.preventDefault()
handleSubmitViewOnlyAddress()
}

// Redirect to the final onboarding tab once an account is set
if (redirect) {
return <Redirect to={OnboardingRoutes.ONBOARDING_COMPLETE} />
Expand All @@ -84,23 +98,20 @@ export default function ViewOnlyWallet(): ReactElement {
</div>
</header>
<div className="content">
<form
onSubmit={(event) => {
event.preventDefault()
handleSubmitViewOnlyAddress()
}}
>
<form>
<div className="input_wrap">
<SharedAddressInput onAddressChange={handleNewAddress} />
<SharedAddressInput
onAddressChange={handleNewAddress}
onKeyDown={handleFormSubmitOnEnter}
/>
</div>
<SharedButton
type="primary"
size="large"
onClick={handleSubmitViewOnlyAddress}
onClick={handleFormSubmitOnClick}
isDisabled={addressOnNetwork === undefined}
showLoadingOnClick
center
isFormSubmit
>
{t("submit")}
</SharedButton>
Expand Down