1
- import React , { useEffect , useState } from 'react'
1
+ import React , { useCallback , useEffect , useMemo , useState } from 'react'
2
2
import { ethers } from 'ethers'
3
3
import classNames from 'classnames'
4
4
import { List , ModalNavigation } from 'decentraland-ui'
@@ -23,12 +23,7 @@ import './PublishWizardCollectionModal.css'
23
23
export const PublishWizardCollectionModal : React . FC < Props > = props => {
24
24
const { collection, items, wallet, rarities, onClose, onFetchRarities, onPublish, onAuthorizedAction, onCloseAuthorization } = props
25
25
const [ currentStep , setCurrentStep ] = useState < number > ( PublishWizardCollectionSteps . CONFIRM_COLLECTION_NAME )
26
- const [ collectionName , setCollectionName ] = useState < string > ( '' )
27
26
const [ emailAddress , setEmailAddress ] = useState < string > ( '' )
28
- const [ contentPolicyFirstConditionChecked , setContentPolicyFirstConditionChecked ] = useState < boolean > ( false )
29
- const [ acceptTermsOfUseChecked , setAcceptTermsOfUseChecked ] = useState < boolean > ( false )
30
- const [ acknowledgeImmutability , setAcknowledgeImmutability ] = useState < boolean > ( false )
31
- const [ acknowledgeDaoTermsChecked , setAcknowledgeDaoTermsChecked ] = useState < boolean > ( false )
32
27
const [ subscribeToNewsletter , setSubscribeToNewsletter ] = useState < boolean > ( false )
33
28
34
29
useEffect ( ( ) => {
@@ -40,97 +35,71 @@ export const PublishWizardCollectionModal: React.FC<Props> = props => {
40
35
setCurrentStep ( PublishWizardCollectionSteps . COLLECTION_PUBLISHED )
41
36
onCloseAuthorization ( )
42
37
}
43
- } , [ collection . forumLink , onCloseAuthorization ] )
38
+ } , [ collection . forumLink , onCloseAuthorization , setCurrentStep ] )
44
39
45
- const handleOnNextStep = ( ) => {
40
+ const handleOnNextStep = useCallback ( ( ) => {
46
41
setCurrentStep ( step => step + 1 )
47
- }
42
+ } , [ setCurrentStep ] )
48
43
49
- const handleOnPrevStep = ( ) => {
44
+ const handleOnPrevStep = useCallback ( ( ) => {
50
45
setCurrentStep ( step => step - 1 )
51
- }
52
-
53
- const handleOnConfirmCollectionName = ( confirmedCollectionName : string ) => {
54
- setCollectionName ( confirmedCollectionName )
55
- }
56
-
57
- const handleOnChangeEmailAddress = ( email : string ) => {
58
- setEmailAddress ( email )
59
- }
60
-
61
- const handleOnContentPolicyFirstConditionChange = ( value : boolean ) => {
62
- setContentPolicyFirstConditionChecked ( value )
63
- }
46
+ } , [ setCurrentStep ] )
64
47
65
- const handleOnAcceptTermsOfUseChange = ( value : boolean ) => {
66
- setAcceptTermsOfUseChecked ( value )
67
- }
68
-
69
- const handleOnAcknowledgeImmutability = ( value : boolean ) => {
70
- setAcknowledgeImmutability ( value )
71
- }
72
-
73
- const handleOnAcknowledgeDaoTermsChange = ( value : boolean ) => {
74
- setAcknowledgeDaoTermsChecked ( value )
75
- }
76
-
77
- const handleOnSubscribeToNewsletter = ( value : boolean ) => {
78
- setSubscribeToNewsletter ( value )
79
- }
48
+ const handleOnChangeEmailAddress = useCallback (
49
+ ( email : string ) => {
50
+ setEmailAddress ( email )
51
+ } ,
52
+ [ setEmailAddress ]
53
+ )
80
54
81
- const handleOnPublish = ( paymentMethod : PaymentMethod ) => {
82
- if ( paymentMethod === PaymentMethod . FIAT ) {
83
- onPublish ( collection , items , emailAddress , subscribeToNewsletter , paymentMethod )
84
- return
85
- }
55
+ const handleOnSubscribeToNewsletter = useCallback (
56
+ ( value : boolean ) => {
57
+ setSubscribeToNewsletter ( value )
58
+ } ,
59
+ [ setSubscribeToNewsletter ]
60
+ )
86
61
87
- const authorization = buildManaAuthorization ( wallet . address , wallet . networks . MATIC . chainId , ContractName . CollectionManager )
88
-
89
- onAuthorizedAction ( {
90
- authorizedAddress : authorization . authorizedAddress ,
91
- authorizedContractLabel : ContractName . CollectionManager ,
92
- targetContract : {
93
- name : authorization . contractName ,
94
- address : authorization . contractAddress ,
95
- chainId : authorization . chainId ,
96
- network : Network . MATIC ,
97
- category : NFTCategory . ENS
98
- } ,
99
- targetContractName : ContractName . MANAToken ,
100
- requiredAllowanceInWei : ethers . BigNumber . from ( rarities [ 0 ] . prices ! . MANA ) . mul ( items . length ) . toString ( ) ,
101
- authorizationType : AuthorizationType . ALLOWANCE ,
102
- onAuthorized : ( ) => onPublish ( collection , items , emailAddress , subscribeToNewsletter , paymentMethod )
103
- } )
104
- }
62
+ const handleOnPublish = useCallback (
63
+ ( paymentMethod : PaymentMethod ) => {
64
+ if ( paymentMethod === PaymentMethod . FIAT ) {
65
+ onPublish ( collection , items , emailAddress , subscribeToNewsletter , paymentMethod )
66
+ return
67
+ }
68
+
69
+ const authorization = buildManaAuthorization ( wallet . address , wallet . networks . MATIC . chainId , ContractName . CollectionManager )
70
+
71
+ onAuthorizedAction ( {
72
+ authorizedAddress : authorization . authorizedAddress ,
73
+ authorizedContractLabel : ContractName . CollectionManager ,
74
+ targetContract : {
75
+ name : authorization . contractName ,
76
+ address : authorization . contractAddress ,
77
+ chainId : authorization . chainId ,
78
+ network : Network . MATIC ,
79
+ category : NFTCategory . ENS
80
+ } ,
81
+ targetContractName : ContractName . MANAToken ,
82
+ requiredAllowanceInWei : ethers . BigNumber . from ( rarities [ 0 ] . prices ! . MANA ) . mul ( items . length ) . toString ( ) ,
83
+ authorizationType : AuthorizationType . ALLOWANCE ,
84
+ onAuthorized : ( ) => onPublish ( collection , items , emailAddress , subscribeToNewsletter , paymentMethod )
85
+ } )
86
+ } ,
87
+ [ onPublish , collection , items , emailAddress , subscribeToNewsletter , wallet , rarities , onAuthorizedAction ]
88
+ )
105
89
106
90
const renderStepView = ( ) => {
107
91
switch ( currentStep ) {
108
92
case PublishWizardCollectionSteps . CONFIRM_COLLECTION_NAME :
109
- return (
110
- < ConfirmCollectionNameStep
111
- collection = { collection }
112
- confirmedCollectionName = { collectionName }
113
- onChangeCollectionName = { handleOnConfirmCollectionName }
114
- onNextStep = { handleOnNextStep }
115
- />
116
- )
93
+ return < ConfirmCollectionNameStep collection = { collection } onNextStep = { handleOnNextStep } />
117
94
case PublishWizardCollectionSteps . CONFIRM_COLLECTION_ITEMS :
118
95
return < ConfirmCollectionItemsStep items = { items } onNextStep = { handleOnNextStep } onPrevStep = { handleOnPrevStep } />
119
96
case PublishWizardCollectionSteps . REVIEW_CONTENT_POLICY :
120
97
return (
121
98
< ReviewContentPolicyStep
122
99
collection = { collection }
123
100
confirmedEmailAddress = { emailAddress }
124
- contentPolicyFirstConditionChecked = { contentPolicyFirstConditionChecked }
125
- acceptTermsOfUseChecked = { acceptTermsOfUseChecked }
126
- acknowledgeImmutability = { acknowledgeImmutability }
127
- acknowledgeDaoTermsChecked = { acknowledgeDaoTermsChecked }
128
101
subscribeToNewsletter = { subscribeToNewsletter }
129
102
onChangeEmailAddress = { handleOnChangeEmailAddress }
130
- onContentPolicyFirstConditionChange = { handleOnContentPolicyFirstConditionChange }
131
- onAcceptTermsOfUseChange = { handleOnAcceptTermsOfUseChange }
132
- onAcknowledgeImmutability = { handleOnAcknowledgeImmutability }
133
- onAcknowledgeDaoTermsChange = { handleOnAcknowledgeDaoTermsChange }
134
103
onSubscribeToNewsletter = { handleOnSubscribeToNewsletter }
135
104
onNextStep = { handleOnNextStep }
136
105
onPrevStep = { handleOnPrevStep }
@@ -145,7 +114,7 @@ export const PublishWizardCollectionModal: React.FC<Props> = props => {
145
114
}
146
115
}
147
116
148
- const renderStepTitle = ( ) => {
117
+ const stepTitle = useMemo ( ( ) => {
149
118
switch ( currentStep ) {
150
119
case PublishWizardCollectionSteps . CONFIRM_COLLECTION_NAME :
151
120
case PublishWizardCollectionSteps . CONFIRM_COLLECTION_ITEMS :
@@ -159,28 +128,33 @@ export const PublishWizardCollectionModal: React.FC<Props> = props => {
159
128
default :
160
129
return null
161
130
}
162
- }
131
+ } , [ t , currentStep ] )
163
132
164
- const renderStepsInicator = ( ) => {
133
+ const stepIndicator = useMemo ( ( ) => {
165
134
if ( currentStep === PublishWizardCollectionSteps . COLLECTION_PUBLISHED ) {
166
135
return null
167
136
}
137
+ const steps = Object . values ( PublishWizardCollectionSteps ) . filter (
138
+ step => ! isNaN ( Number ( step ) ) && step !== PublishWizardCollectionSteps . COLLECTION_PUBLISHED
139
+ )
140
+ const activeStepPosition = steps . findIndex ( step => step === currentStep )
168
141
169
142
return (
170
143
< List horizontal className = "steps-indicator content" >
171
- { Object . values ( PublishWizardCollectionSteps )
172
- . filter ( step => ! isNaN ( Number ( step ) ) && step !== PublishWizardCollectionSteps . COLLECTION_PUBLISHED )
173
- . map ( step => (
174
- < List . Item key = { step } className = { classNames ( 'step' , { active : currentStep === step } ) } />
175
- ) ) }
144
+ { steps . map ( ( step , index ) => (
145
+ < List . Item
146
+ key = { step }
147
+ className = { classNames ( 'step' , { active : currentStep === step , beforeActiveStep : index < activeStepPosition } ) }
148
+ />
149
+ ) ) }
176
150
</ List >
177
151
)
178
- }
152
+ } , [ currentStep ] )
179
153
180
154
return (
181
155
< Modal className = "PublishWizardCollectionModal" size = "small" onClose = { onClose } closeOnDimmerClick = { false } >
182
- < ModalNavigation title = { renderStepTitle ( ) } onClose = { onClose } />
183
- { renderStepsInicator ( ) }
156
+ < ModalNavigation title = { stepTitle } onClose = { onClose } />
157
+ { stepIndicator }
184
158
{ renderStepView ( ) }
185
159
</ Modal >
186
160
)
0 commit comments