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

[Multichain] fix: Disable submit button while replaying safe [SW-173] #4211

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,33 @@ const ReplaySafeDialog = ({
const customRpc = useAppSelector(selectRpc)
const dispatch = useAppDispatch()
const [creationError, setCreationError] = useState<Error>()
const [isSubmitDisabled, setIsSubmitDisabled] = useState<boolean>(false)
Copy link
Member

Choose a reason for hiding this comment

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

This is very similar to the submitDisabled variable.
Should we rename this to isSubmitting and inverse it?


// Load some data
const [safeCreationData, safeCreationDataError, safeCreationDataLoading] = safeCreationResult

const onFormSubmit = handleSubmit(async (data) => {
setIsSubmitDisabled(true)

const selectedChain = chain ?? replayableChains?.find((config) => config.chainId === data.chainId)
if (!safeCreationData || !selectedChain) {
setIsSubmitDisabled(false)
return
}

// We need to create a readOnly provider of the deployed chain
const customRpcUrl = selectedChain ? customRpc?.[selectedChain.chainId] : undefined
const provider = createWeb3ReadOnly(selectedChain, customRpcUrl)
if (!provider) {
setIsSubmitDisabled(false)
return
}

// 1. Double check that the creation Data will lead to the correct address
const predictedAddress = await predictAddressBasedOnReplayData(safeCreationData, provider)
if (!sameAddress(safeAddress, predictedAddress)) {
setCreationError(new Error('The replayed Safe leads to an unexpected address'))
setIsSubmitDisabled(false)
return
Copy link
Member

Choose a reason for hiding this comment

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

Should we just use a try-catch-finally where we setIsSubmitDisabled(false) in the finally block?

}

Expand All @@ -102,12 +108,18 @@ const ReplaySafeDialog = ({
},
})

setIsSubmitDisabled(false)

// Close modal
onClose()
})

const submitDisabled =
isUnsupportedSafeCreationVersion || !!safeCreationDataError || safeCreationDataLoading || !formState.isValid
isUnsupportedSafeCreationVersion ||
!!safeCreationDataError ||
safeCreationDataLoading ||
!formState.isValid ||
isSubmitDisabled

const noChainsAvailable =
!chain && safeCreationData && replayableChains && replayableChains.filter((chain) => chain.available).length === 0
Expand Down
Loading