1
1
import { useState , useEffect } from "react" ;
2
- import { Button , Card , Col , Dropdown , Form , Input , Row , Result , Space , Spin , Switch } from "antd" ;
2
+ import {
3
+ Button ,
4
+ Card ,
5
+ Col ,
6
+ Select ,
7
+ Dropdown ,
8
+ Form ,
9
+ Input ,
10
+ Row ,
11
+ Result ,
12
+ Space ,
13
+ Spin ,
14
+ Switch ,
15
+ } from "antd" ;
3
16
import { DownOutlined } from "@ant-design/icons" ;
4
17
import axios from "axios" ;
5
18
6
19
export const Transfer = ( ) => {
7
20
const [ transferFeeRecord , setTransferFeeRecord ] = useState ( null ) ;
8
21
const [ amountRecord , setAmountRecord ] = useState ( null ) ;
9
- const [ transferUrl , setTransferUrl ] = useState ( "https://api.explorer.aleo.org/v1" ) ;
22
+ const [ transferUrl , setTransferUrl ] = useState (
23
+ "https://api.explorer.aleo.org/v1" ,
24
+ ) ;
10
25
const [ transferAmount , setTransferAmount ] = useState ( "1.0" ) ;
11
26
const [ transferFee , setTransferFee ] = useState ( "1.0" ) ;
12
27
const [ privateFee , setPrivateFee ] = useState ( true ) ;
@@ -16,7 +31,7 @@ export const Transfer = () => {
16
31
const [ transferError , setTransferError ] = useState ( null ) ;
17
32
const [ status , setStatus ] = useState ( "" ) ;
18
33
const [ transactionID , setTransactionID ] = useState ( null ) ;
19
- const [ visibility , setVisibility ] = useState ( "private " ) ;
34
+ const [ visibility , setVisibility ] = useState ( "public " ) ;
20
35
const [ worker , setWorker ] = useState ( null ) ;
21
36
22
37
function spawnWorker ( ) {
@@ -77,7 +92,10 @@ export const Transfer = () => {
77
92
}
78
93
79
94
let amountRecord = amountRecordString ( ) ;
80
- if ( visibilityString ( ) === "public" || visibilityString ( ) === "publicToPrivate" ) {
95
+ if (
96
+ visibilityString ( ) === "public" ||
97
+ visibilityString ( ) === "publicToPrivate"
98
+ ) {
81
99
amountRecord = undefined ;
82
100
}
83
101
@@ -171,36 +189,36 @@ export const Transfer = () => {
171
189
return privateKey ;
172
190
} ;
173
191
174
- const onClick = ( { key } ) => {
192
+ const onClick = ( { value } ) => {
175
193
setTransactionID ( null ) ;
176
194
setTransferError ( null ) ;
177
- console . log ( "Visibility changed to: " , key ) ;
178
- setVisibility ( key ) ;
179
- if ( key === "public" || key === "publicToPrivate" ) {
195
+ setVisibility ( value ) ;
196
+ console . log ( "Visibility changed to: " , value ) ;
197
+ if ( value === "public" || value === "publicToPrivate" ) {
180
198
setAmountRecord ( null ) ;
181
199
}
182
200
} ;
183
201
184
202
const items = [
185
203
{
186
- label : ' private' ,
187
- key : ' private' ,
204
+ label : " private" ,
205
+ value : " private" ,
188
206
} ,
189
207
{
190
- label : ' privateToPublic' ,
191
- key : ' privateToPublic' ,
208
+ label : " privateToPublic" ,
209
+ value : " privateToPublic" ,
192
210
} ,
193
211
{
194
- label : ' public' ,
195
- key : ' public' ,
212
+ label : " public" ,
213
+ value : " public" ,
196
214
} ,
197
215
{
198
- label : ' publicToPrivate' ,
199
- key : ' publicToPrivate' ,
216
+ label : " publicToPrivate" ,
217
+ value : " publicToPrivate" ,
200
218
} ,
201
219
] ;
202
220
203
- const layout = { labelCol : { span : 5 } , wrapperCol : { span : 21 } } ;
221
+ const layout = { labelCol : { span : 5 } , wrapperCol : { span : 21 } } ;
204
222
const feeString = ( ) => ( transferFee !== null ? transferFee : "" ) ;
205
223
const amountString = ( ) => ( transferAmount !== null ? transferAmount : "" ) ;
206
224
const recipientString = ( ) => ( recipient !== null ? recipient : "" ) ;
@@ -214,20 +232,28 @@ export const Transfer = () => {
214
232
const transferErrorString = ( ) =>
215
233
transferError !== null ? transferError : "" ;
216
234
const peerUrl = ( ) => ( transferUrl !== null ? transferUrl : "" ) ;
217
- const visibilityString = ( ) => ( visibility !== null ? visibility : "private" ) ;
235
+ const visibilityString = ( ) =>
236
+ visibility !== null ? visibility : "private" ;
218
237
219
238
return (
220
- < Card
221
- title = "Transfer"
222
- style = { { width : "100%" } }
223
- extra = {
224
- < Dropdown menu = { { items, onClick } } >
225
- < a onClick = { ( e ) => e . preventDefault ( ) } >
226
- < Button > { visibilityString ( ) } </ Button >
227
- </ a >
228
- </ Dropdown > }
229
- >
239
+ < Card title = "Transfer" style = { { width : "100%" } } extra = { < > </ > } >
230
240
< Form { ...layout } >
241
+ < div
242
+ style = { {
243
+ display : "flex" ,
244
+ gap : "13px" ,
245
+ alignItems : "center" ,
246
+ marginBottom : "10px" ,
247
+ } }
248
+ >
249
+ < p > Transaction Visibility </ p >
250
+ < Select
251
+ style = { { width : "9rem" } }
252
+ placeholder = { visibilityString ( ) }
253
+ options = { items }
254
+ onChange = { ( item ) => { setVisibility ( item ) } }
255
+ > </ Select >
256
+ </ div >
231
257
< Form . Item
232
258
label = "Recipient Address"
233
259
colon = { false }
@@ -252,8 +278,8 @@ export const Transfer = () => {
252
278
value = { amountString ( ) }
253
279
/>
254
280
</ Form . Item >
255
- {
256
- ( visibilityString ( ) === "privateToPublic" || visibilityString ( ) === " private") &&
281
+ { ( visibilityString ( ) === "privateToPublic" ||
282
+ visibilityString ( ) === "private" ) && (
257
283
< Form . Item
258
284
label = "Amount Record"
259
285
colon = { false }
@@ -268,7 +294,7 @@ export const Transfer = () => {
268
294
value = { amountRecordString ( ) }
269
295
/>
270
296
</ Form . Item >
271
- }
297
+ ) }
272
298
< Form . Item label = "Fee" colon = { false } validateStatus = { status } >
273
299
< Input . TextArea
274
300
name = "Fee"
@@ -332,12 +358,7 @@ export const Transfer = () => {
332
358
</ Form . Item >
333
359
< Row justify = "center" >
334
360
< Col justify = "center" >
335
- < Button
336
- type = "primary"
337
-
338
- size = "middle"
339
- onClick = { transfer }
340
- >
361
+ < Button type = "primary" size = "middle" onClick = { transfer } >
341
362
Transfer
342
363
</ Button >
343
364
</ Col >
0 commit comments