@@ -7,15 +7,14 @@ import { Checkbox, Form, Input, PasswordInput, SubmitButton } from '@/components
77import CancelButton from '@/components/cancel-button'
88import Text from '@/components/text'
99import Info from '@/components/info'
10- import { useFormState , useMaxSteps , useNext , useStepIndex } from '@/components/multi-step-form'
11- import { isTemplate , isWallet , protocolDisplayName , protocolFormId , protocolLogName , walletLud16Domain } from '@/wallets/lib/util'
10+ import { useIsFirstStep , useIsLastStep , useNext } from '@/components/multi-step-form'
11+ import { isTemplate , protocolDisplayName , protocolFormId , protocolLogName , walletLud16Domain } from '@/wallets/lib/util'
1212import { WalletGuide , WalletLayout , WalletLayoutHeader , WalletLayoutImageOrName , WalletLogs } from '@/wallets/client/components'
1313import { TemplateLogsProvider , useTestSendPayment , useWalletLogger , useTestCreateInvoice , useWalletSupport } from '@/wallets/client/hooks'
1414import ArrowRight from '@/svgs/arrow-right-s-fill.svg'
1515import { useFormikContext } from 'formik'
1616
17- import { WalletMultiStepFormContextProvider , Step , useWallet , useWalletProtocols , useProtocol , useProtocolForm } from './hooks'
18- import { Settings } from './settings'
17+ import { WalletMultiStepFormContextProvider , Step , useWallet , useWalletProtocols , useProtocol , useProtocolForm , useSaveWallet } from './hooks'
1918import { BackButton , SkipButton } from './button'
2019
2120export function WalletMultiStepForm ( { wallet } ) {
@@ -33,8 +32,7 @@ export function WalletMultiStepForm ({ wallet }) {
3332 const steps = useMemo ( ( ) =>
3433 [
3534 support . send && Step . SEND ,
36- support . receive && Step . RECEIVE ,
37- Step . SETTINGS
35+ support . receive && Step . RECEIVE
3836 ] . filter ( Boolean ) ,
3937 [ support ] )
4038
@@ -51,7 +49,7 @@ export function WalletMultiStepForm ({ wallet }) {
5149 // and can thus render a different form for send vs. receive
5250 if ( step === Step . SEND ) return < WalletForm key = { step } />
5351 if ( step === Step . RECEIVE ) return < WalletForm key = { step } />
54- return < Settings key = { step } />
52+ return null
5553 } ) }
5654 </ WalletMultiStepFormContextProvider >
5755 </ div >
@@ -92,12 +90,21 @@ function WalletProtocolSelector () {
9290function WalletProtocolForm ( ) {
9391 const wallet = useWallet ( )
9492 const [ protocol ] = useProtocol ( )
95- const next = useNext ( )
93+
94+ // on the last step, we save the wallet, otherwise we just go to the next step
95+ const isLastStep = useIsLastStep ( )
96+ const formNext = useNext ( )
97+ const formSave = useSaveWallet ( )
98+
9699 const testSendPayment = useTestSendPayment ( protocol )
97100 const testCreateInvoice = useTestCreateInvoice ( protocol )
98101 const logger = useWalletLogger ( protocol )
99102 const [ { fields, initial, schema } , setFormState ] = useProtocolForm ( protocol )
100103
104+ const next = useCallback ( ( ) => {
105+ isLastStep ? formSave ( ) : formNext ( )
106+ } , [ isLastStep , formSave , formNext ] )
107+
101108 // create a copy of values to avoid mutating the original
102109 const onSubmit = useCallback ( async ( { ...values } ) => {
103110 const lud16Domain = walletLud16Domain ( wallet . name )
@@ -152,25 +159,31 @@ function WalletProtocolForm () {
152159}
153160
154161function WalletProtocolFormNavigator ( ) {
155- const wallet = useWallet ( )
156- const stepIndex = useStepIndex ( )
157- const maxSteps = useMaxSteps ( )
158- const [ formState ] = useFormState ( )
159-
160- // was something already configured or was something configured just now?
161- const configExists = ( isWallet ( wallet ) && wallet . protocols . length > 0 ) || Object . keys ( formState ) . length > 0
162-
163- // don't allow going to settings as last step with nothing configured
164- const hideSkip = stepIndex === maxSteps - 2 && ! configExists
162+ // show 'cancel' in the first step
163+ const showCancel = useIsFirstStep ( )
164+ // show 'save' instead of 'next' in the last step
165+ const isLastStep = useIsLastStep ( )
166+ // show 'skip' if there's a next step
167+ const showSkip = ! isLastStep
165168
166169 return (
167170 < div className = 'd-flex justify-content-end align-items-center' >
168- { stepIndex === 0 ? < CancelButton > cancel</ CancelButton > : < BackButton /> }
169- { ! hideSkip ? < SkipButton /> : < div className = 'ms-auto' /> }
170- < SubmitButton variant = 'primary' className = 'ps-3 pe-2 d-flex align-items-center' >
171- next
172- < ArrowRight width = { 24 } height = { 24 } />
173- </ SubmitButton >
171+ { showCancel ? < CancelButton > cancel</ CancelButton > : < BackButton /> }
172+ { showSkip ? < SkipButton /> : < div className = 'ms-auto' /> }
173+ {
174+ isLastStep
175+ ? (
176+ < SubmitButton variant = 'primary' className = 'd-flex align-items-center' >
177+ save
178+ </ SubmitButton >
179+ )
180+ : (
181+ < SubmitButton variant = 'primary' className = 'ps-3 pe-2 d-flex align-items-center' >
182+ next
183+ < ArrowRight width = { 24 } height = { 24 } />
184+ </ SubmitButton >
185+ )
186+ }
174187 </ div >
175188 )
176189}
0 commit comments