Skip to content

Commit

Permalink
Prevent read-only address submission when validating input
Browse files Browse the repository at this point in the history
  • Loading branch information
xpaczka committed Dec 15, 2023
1 parent e416e29 commit 8316b24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
16 changes: 15 additions & 1 deletion ui/components/Shared/SharedAddressInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { HexString } from "@tallyho/tally-background/types"
import React, { ReactElement, useEffect, useState } from "react"
import React, {
Dispatch,
ReactElement,
SetStateAction,
useEffect,
useState,
} from "react"
import { useDelayContentChange } from "../../hooks"
import { useAddressOrNameValidation } from "../../hooks/validation-hooks"

Expand All @@ -16,6 +22,7 @@ type Props = {
id?: string
placeholder?: string
isEmpty?: boolean
setIsValidating?: Dispatch<SetStateAction<boolean>>
}

export default function SharedAddressInput({
Expand All @@ -26,6 +33,7 @@ export default function SharedAddressInput({
id,
placeholder,
isEmpty,
setIsValidating,
}: Props): ReactElement {
const [inputValue, setInputValue] = useState(value ?? "")
const debouncedValue = useDelayContentChange(
Expand All @@ -41,6 +49,12 @@ export default function SharedAddressInput({
handleInputChange(debouncedValue)
}, [debouncedValue, handleInputChange])

useEffect(() => {
if (setIsValidating !== undefined) {
setIsValidating(isValidating)
}
}, [setIsValidating, isValidating])

return (
<>
<SharedInput
Expand Down
11 changes: 8 additions & 3 deletions ui/pages/Onboarding/Tabbed/ViewOnlyWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default function ViewOnlyWallet(): ReactElement {
AddressOnNetwork | undefined
>(undefined)

const [isValidating, setIsValidating] = useState(false)

const { t } = useTranslation("translation", {
keyPrefix: "onboarding.tabbed.addWallet.viewOnly",
})
Expand All @@ -42,7 +44,7 @@ export default function ViewOnlyWallet(): ReactElement {
)

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

Expand All @@ -61,7 +63,7 @@ export default function ViewOnlyWallet(): ReactElement {

dispatch(setNewSelectedAccount(addressOnNetwork))
setRedirect(true)
}, [dispatch, addressOnNetwork])
}, [dispatch, addressOnNetwork, isValidating])

// Redirect to the final onboarding tab once an account is set
if (redirect) {
Expand Down Expand Up @@ -91,7 +93,10 @@ export default function ViewOnlyWallet(): ReactElement {
}}
>
<div className="input_wrap">
<SharedAddressInput onAddressChange={handleNewAddress} />
<SharedAddressInput
onAddressChange={handleNewAddress}
setIsValidating={setIsValidating}
/>
</div>
<SharedButton
type="primary"
Expand Down

0 comments on commit 8316b24

Please sign in to comment.