Skip to content

Commit

Permalink
fix(unlock-app): fixing the password setting flow (#13424)
Browse files Browse the repository at this point in the history
* fix(unlock-app): fixing the password setting flow

* typescript fix
  • Loading branch information
julien51 committed Mar 7, 2024
1 parent eaca05d commit f9fa6e4
Showing 1 changed file with 4 additions and 19 deletions.
@@ -1,5 +1,4 @@
import { Button, Input, Placeholder } from '@unlock-protocol/ui'
import { useState } from 'react'
import { DEFAULT_USER_ACCOUNT_ADDRESS } from '~/constants'
import { CustomComponentProps } from '../UpdateHooksForm'
import { useAuth } from '~/contexts/AuthenticationContext'
Expand All @@ -9,7 +8,6 @@ import { useWeb3Service } from '~/utils/withWeb3Service'
import { getEthersWalletFromPassword } from '~/utils/strings'
import { useFormContext } from 'react-hook-form'

const FAKE_PWD = 'fakepwd'
export const PasswordContractHook = ({
disabled,
lockAddress,
Expand All @@ -19,11 +17,10 @@ export const PasswordContractHook = ({
}: CustomComponentProps) => {
const { getWalletService } = useAuth()
const web3Service = useWeb3Service()
const [hookValue, setHookValue] = useState('')

const onSavePassword = async () => {
const onSavePassword = async (password: string) => {
const { address: signerAddress } =
getEthersWalletFromPassword(hookValue) ?? {}
getEthersWalletFromPassword(password) ?? {}
const walletService = await getWalletService(network)
const tx = await walletService.setPasswordHookSigner(
{
Expand All @@ -45,29 +42,17 @@ export const PasswordContractHook = ({
contractAddress: hookAddress,
network,
})
},
{
onSuccess: (signers: string) => {
if (signers && signers !== DEFAULT_USER_ACCOUNT_ADDRESS) {
setHookValue(FAKE_PWD)
}
},
}
)

const hasSigner =
signers?.toLowerCase() !== DEFAULT_USER_ACCOUNT_ADDRESS?.toLowerCase()

const savePasswordMutation = useMutation(onSavePassword, {
onSuccess: () => {
setHookValue(FAKE_PWD)
},
})
const savePasswordMutation = useMutation(onSavePassword)

const onSubmit = async ({ hook, ...rest }: any) => {
await setEventsHooksMutation.mutateAsync(rest)

const promise = savePasswordMutation.mutateAsync()
const promise = savePasswordMutation.mutateAsync(hook.password)
await ToastHelper.promise(promise, {
loading: 'Updating password...',
success: 'Password is set for the lock.',
Expand Down

0 comments on commit f9fa6e4

Please sign in to comment.