1- import React , { useCallback , useEffect , useMemo } from 'react'
1+ import React , { useState , useCallback , useEffect , useMemo } from 'react'
22import { useTranslation } from 'react-i18next'
33import {
44 Stack ,
@@ -224,9 +224,13 @@ const Submission = ({
224224} : WizardElementProps < { type : string } > ) => {
225225 const { name, password, confirmPassword, imported } = state
226226 const [ t ] = useTranslation ( )
227+ const [ loading , setLoading ] = useState ( false )
227228 const message = 'wizard.set-wallet-name-and-password'
228229
229230 useEffect ( ( ) => {
231+ if ( loading ) {
232+ return
233+ }
230234 dispatch ( {
231235 type : 'name' ,
232236 payload : generateWalletName ( wallets , wallets . length + 1 , t ) ,
@@ -239,7 +243,7 @@ const Submission = ({
239243 type : 'confirmPassword' ,
240244 payload : '' ,
241245 } )
242- } , [ dispatch , wallets , t ] )
246+ } , [ loading , dispatch , wallets , t ] )
243247
244248 const onChange = useCallback (
245249 ( e : any , value ?: string ) => {
@@ -258,22 +262,28 @@ const Submission = ({
258262 )
259263
260264 const onNext = useCallback ( ( ) => {
265+ if ( loading ) {
266+ return
267+ }
261268 const p = {
262269 name,
263270 password,
264271 mnemonic : imported ,
265272 }
266- if ( type === MnemonicAction . Create ) {
267- createWalletWithMnemonic ( p ) ( dispatch , history )
268- } else {
269- importWalletWithMnemonic ( p ) ( dispatch , history )
270- }
271- } , [ type , name , password , imported , history , dispatch ] )
273+ setLoading ( true )
274+ setTimeout ( ( ) => {
275+ if ( type === MnemonicAction . Create ) {
276+ createWalletWithMnemonic ( p ) ( dispatch , history ) . finally ( ( ) => setLoading ( false ) )
277+ } else {
278+ importWalletWithMnemonic ( p ) ( dispatch , history ) . finally ( ( ) => setLoading ( false ) )
279+ }
280+ } , 0 )
281+ } , [ type , name , password , imported , history , dispatch , loading ] )
272282
273283 const isNameUnused = useMemo ( ( ) => name && ! wallets . find ( w => w . name === name ) , [ name , wallets ] )
274284 const isPwdComplex = useMemo ( ( ) => verifyPasswordComplexity ( password ) === true , [ password ] )
275285 const isPwdSame = useMemo ( ( ) => password && password === confirmPassword , [ password , confirmPassword ] )
276- const disableNext = ! ( isNameUnused && isPwdComplex && isPwdSame )
286+ const disableNext = loading || ! ( isNameUnused && isPwdComplex && isPwdSame )
277287
278288 return (
279289 < Stack verticalFill verticalAlign = "center" horizontalAlign = "stretch" tokens = { { childrenGap : 15 } } >
0 commit comments