@@ -59,17 +59,18 @@ function FinanceQuickTransferModal({
59
59
const { sendNotification } = useNotifications ( ) ;
60
60
const [ message , setMessage ] = useState ( '' ) ;
61
61
62
- // For transfer button is clicked in some profile
62
+ // For the transfer button when using user input
63
63
const MAX_AMOUNT = useSelector ( ( state : any ) => state . auth . balance ) ;
64
64
const [ value , setValue ] = useState ( 0 ) ;
65
65
const [ canContinue , setCanContinue ] = useState ( true ) ;
66
66
67
- // Check if we have a valid profile or not
67
+ // Check if we have a valid profile
68
68
const hasProfile = ! ! contactInfo ;
69
69
70
70
// Check if the passed address matches the profile's address
71
71
const isSame =
72
- hasProfile && contactInfo ?. ownedBy ?. address ?. toLowerCase ( ) === address ?. toLowerCase ( ) ;
72
+ hasProfile &&
73
+ contactInfo ?. ownedBy ?. address ?. toLowerCase ( ) === address ?. toLowerCase ( ) ;
73
74
74
75
// If no valid profile, show "Destination wallet", else use profile’s displayName
75
76
const displayName = hasProfile
@@ -107,9 +108,14 @@ function FinanceQuickTransferModal({
107
108
}
108
109
}
109
110
111
+ // Define the transfer amount: if a positive 'amount' is passed, use it; otherwise, use the entered value
112
+ const transferAmount = amount > 0 ? amount : value ;
113
+ // Validation: if 'amount' is passed, assume it's valid; otherwise, ensure that the value is greater than 0 and input validation (canContinue) passes.
114
+ const isTransferValid = transferAmount > 0 && ( amount > 0 || canContinue ) ;
115
+
110
116
const handleConfirmTransfer = async ( ) => {
111
117
try {
112
- await transfer ( { amount : amount > 0 ? amount : value , recipient : address ?? '' } ) ;
118
+ await transfer ( { amount : transferAmount , recipient : address ?? '' } ) ;
113
119
114
120
onFinish ( ) ;
115
121
@@ -120,57 +126,65 @@ function FinanceQuickTransferModal({
120
126
'TRANSFER' ,
121
127
{
122
128
id : isSame ? ( contactInfo ?. id ?? '' ) : ( address ?? '' ) ,
123
- displayName : isSame ? ( contactInfo ?. metadata ?. displayName ?? 'No name' ) : 'External wallet' ,
129
+ displayName : isSame
130
+ ? ( contactInfo ?. metadata ?. displayName ?? 'No name' )
131
+ : 'External wallet' ,
124
132
avatar : ( contactInfo ?. metadata ?. picture as any ) ?. optimized ?. uri ?? '' ,
125
133
} ,
126
134
{
127
- rawDescription : `${ sessionData ?. profile ?. metadata ?. displayName ?? address } sent you ${ amount } MMC` ,
135
+ rawDescription : `${ sessionData ?. profile ?. metadata ?. displayName ?? address } sent you ${ transferAmount } MMC` ,
128
136
message,
129
137
}
130
138
) ;
131
139
132
- // Store transaction in supabase
140
+ // Store transaction in Supabase
133
141
await storeTransactionInSupabase ( contactInfo ?. id ?? address , senderId , {
134
142
address : contactInfo ?. ownedBy ?. address ?? address ,
135
- amount : amount > 0 ? amount : value ,
143
+ amount : transferAmount ,
136
144
message,
137
145
...notificationPayload ,
138
146
} ) ;
139
147
140
- // Send notification to lens profile or address
148
+ // Send notification to the Lens profile or address
141
149
await sendNotification (
142
150
contactInfo ?. id ?? address ?? '' ,
143
151
sessionData ?. profile ?. id ,
144
152
notificationPayload
145
153
) ;
146
154
147
155
notifySuccess ( SUCCESS . TRANSFER_CREATED_SUCCESSFULLY , {
148
- destination : isSame ? contactInfo ?. metadata ?. displayName : truncateAddress ( address ?? '' ) ,
156
+ destination : isSame
157
+ ? contactInfo ?. metadata ?. displayName ?? contactInfo ?. handle ?. localName
158
+ : truncateAddress ( address ?? '' ) ,
149
159
} ) ;
150
160
} catch ( err : any ) {
151
161
notifyError ( ERRORS . TRANSFER_FAILED_ERROR ) ;
152
162
}
153
163
} ;
154
164
155
- const handleChangeInput = useCallback ( ( event : React . ChangeEvent < HTMLInputElement > ) => {
156
- const value = Number ( event . target . value ) ;
157
- handleAmountConstraints ( { value, MAX_AMOUNT , MAX_POOL , setAmount : setValue , setCanContinue} ) ;
158
- } , [ MAX_AMOUNT ] ) ;
159
-
165
+ const handleChangeInput = useCallback (
166
+ ( event : React . ChangeEvent < HTMLInputElement > ) => {
167
+ const value = Number ( event . target . value ) ;
168
+ handleAmountConstraints ( { value, MAX_AMOUNT , MAX_POOL , setAmount : setValue , setCanContinue } ) ;
169
+ } ,
170
+ [ MAX_AMOUNT ]
171
+ ) ;
160
172
161
173
const handleBlur = useCallback ( ( ) => {
162
- handleAmountConstraints ( { value, MAX_AMOUNT , MAX_POOL , setAmount : setValue , setCanContinue} ) ;
174
+ handleAmountConstraints ( { value, MAX_AMOUNT , MAX_POOL , setAmount : setValue , setCanContinue } ) ;
163
175
} , [ value , MAX_AMOUNT ] ) ;
164
176
165
177
const RainbowEffect = transferLoading ? NeonPaper : Box ;
166
178
167
179
return (
168
180
< Dialog open = { open } fullWidth maxWidth = "xs" onClose = { onClose } >
169
- < DialogTitle sx = { {
170
- borderBottom : `dashed 1px ${ theme . palette . divider } ` ,
171
- padding : '16px 24px' ,
172
- marginBottom : '8px'
173
- } } >
181
+ < DialogTitle
182
+ sx = { {
183
+ borderBottom : `dashed 1px ${ theme . palette . divider } ` ,
184
+ padding : '16px 24px' ,
185
+ marginBottom : '8px' ,
186
+ } }
187
+ >
174
188
Send to
175
189
</ DialogTitle >
176
190
< Stack direction = "column" spacing = { 3 } sx = { { px : 3 } } >
@@ -190,19 +204,20 @@ function FinanceQuickTransferModal({
190
204
</ Stack >
191
205
192
206
< Stack direction = "column" spacing = { 0 } sx = { { py : 2 , flexGrow : 1 } } >
193
- { amount > 0 ? (
194
-
207
+ { amount > 0 ? (
195
208
< ListItemText
196
209
primary = "Amount:"
197
210
secondary = { `${ amount } MMC` }
198
211
secondaryTypographyProps = { { component : 'span' , mt : 0.5 } }
199
212
/>
200
- ) : < InputAmount
201
- max = { MAX_POOL }
202
- amount = { value }
203
- onBlur = { handleBlur }
204
- onChange = { handleChangeInput }
205
- /> }
213
+ ) : (
214
+ < InputAmount
215
+ max = { MAX_POOL }
216
+ amount = { value }
217
+ onBlur = { handleBlur }
218
+ onChange = { handleChangeInput }
219
+ />
220
+ ) }
206
221
</ Stack >
207
222
</ Stack >
208
223
@@ -219,7 +234,7 @@ function FinanceQuickTransferModal({
219
234
sx = { {
220
235
borderTop : `dashed 1px ${ theme . palette . divider } ` ,
221
236
padding : '16px 24px' ,
222
- marginTop : '24px'
237
+ marginTop : '24px' ,
223
238
} }
224
239
>
225
240
< Button onClick = { onClose } > Cancel</ Button >
@@ -236,7 +251,7 @@ function FinanceQuickTransferModal({
236
251
variant = "contained"
237
252
sx = { { backgroundColor : '#fff' } }
238
253
onClick = { handleConfirmTransfer }
239
- disabled = { transferLoading || ! canContinue || value <= 0 }
254
+ disabled = { transferLoading || ! isTransferValid }
240
255
loading = { transferLoading }
241
256
>
242
257
Confirm
0 commit comments