1
1
import { BsSendPlus } from 'react-icons/bs' ;
2
+ import { IoMdArrowDropdown , IoMdArrowDropup } from 'react-icons/io'
2
3
import Popup from 'reactjs-popup' ;
3
4
import styles from './style.module.css' ;
5
+ import Dropdown from 'react-dropdown' ;
4
6
5
7
import { smartdeploy , StateVariablesProps , UserWalletInfo , FetchDatas } from "@/pages" ;
6
8
import { isConnected } from '@stellar/freighter-api' ;
@@ -12,17 +14,30 @@ interface PublishedContract {
12
14
index : number ;
13
15
name : string ;
14
16
author : string ;
15
- version : Version ;
16
- version_string : string ;
17
- hash : string ;
17
+ versions : {
18
+ version : Version ,
19
+ hash : string
20
+ } [ ] ;
18
21
}
19
22
20
- type DeployIconComponentProps = {
23
+ type DeployProps = {
21
24
userWalletInfo : UserWalletInfo ;
22
25
refetchDeployedContract : FetchDatas ;
23
26
contract_name : string ;
24
- version : Option < Version > ;
25
- version_string : string ;
27
+ versions : { version : Version , version_string : string } [ ] ;
28
+ }
29
+
30
+ type DeployVersionProps = {
31
+ userWalletInfo : UserWalletInfo ;
32
+ refetchDeployedContract : FetchDatas ;
33
+ contract_name : string ;
34
+ selected_version : { version : Version , version_string : string } ;
35
+ }
36
+
37
+ type VersionDropdownProps = {
38
+ versions : { version : Version , version_string : string } [ ] ;
39
+ selected_version : { version : Version , version_string : string } ;
40
+ set_selected_version : Dispatch < SetStateAction < { version : Version , version_string : string } > > ;
26
41
}
27
42
28
43
type DeployArgsObj = {
@@ -48,20 +63,26 @@ async function listAllPublishedContracts() {
48
63
49
64
///@ts -ignore
50
65
contractArray . forEach ( ( [ name , publishedContract ] , i ) => {
51
- const version : Version = publishedContract . versions . keys ( ) . next ( ) . value ;
52
- const major = version . major ;
53
- const minor = version . minor ;
54
- const patch = version . patch ;
55
- const versionString = `v.${ major } .${ minor } .${ patch } ` ;
56
-
57
- const hash = publishedContract . versions . values ( ) . next ( ) . value . hash . join ( '' ) ;
66
+
67
+ let versions : { version : Version , hash : string } [ ] = [ ] ;
68
+
69
+ ///@ts -ignore
70
+ Array . from ( publishedContract . versions ) . forEach ( ( contractDatas : [ Version , any ] ) => {
71
+
72
+ // Version object
73
+ const version = contractDatas [ 0 ] ;
74
+
75
+ // hash
76
+ const hash = contractDatas [ 1 ] . hash . join ( '' ) ;
77
+
78
+ versions . push ( { version, hash} ) ;
79
+ } ) ;
80
+
58
81
const parsedPublishedContract : PublishedContract = {
59
82
index : i ,
60
83
name : name ,
61
84
author : publishedContract . author . toString ( ) ,
62
- version : version ,
63
- version_string : versionString ,
64
- hash : hash
85
+ versions : versions
65
86
} ;
66
87
67
88
publishedContracts . push ( parsedPublishedContract ) ;
@@ -141,7 +162,43 @@ async function deploy(
141
162
}
142
163
}
143
164
144
- function DeployIconComponent ( props : DeployIconComponentProps ) {
165
+ function VersionDropdownButton ( props : VersionDropdownProps ) {
166
+
167
+ const versions : string [ ] = [ ] ;
168
+
169
+ props . versions . forEach ( ( version ) => {
170
+ versions . push ( version . version_string ) ;
171
+ } ) ;
172
+
173
+ return (
174
+ < div >
175
+ < Dropdown
176
+ className = { styles . dropdownContainer }
177
+ controlClassName = { styles . dropdownControl }
178
+ menuClassName = { styles . dropdownMenu }
179
+ options = { versions }
180
+ placeholder = { versions [ 0 ] }
181
+ arrowClosed = { < IoMdArrowDropdown /> }
182
+ arrowOpen = { < IoMdArrowDropup /> }
183
+ onChange = { ( version ) => {
184
+
185
+ const newSelectedVersionString = version . value ;
186
+
187
+ const [ major , minor , patch ] = version . value . split ( '.' ) . slice ( 1 ) ;
188
+ const newSelectedVersion : Version = {
189
+ major : parseInt ( major ) ,
190
+ minor : parseInt ( minor ) ,
191
+ patch : parseInt ( patch ) ,
192
+ }
193
+
194
+ props . set_selected_version ( { version : newSelectedVersion , version_string : newSelectedVersionString } ) ;
195
+ } }
196
+ />
197
+ </ div >
198
+ )
199
+ }
200
+
201
+ function DeployIconComponent ( props : DeployVersionProps ) {
145
202
146
203
// Import the current Theme
147
204
const { activeTheme } = useThemeContext ( ) ;
@@ -173,7 +230,7 @@ function DeployIconComponent(props: DeployIconComponentProps) {
173
230
< button className = { styles . close } onClick = { ( ) => setWouldDeploy ( false ) } >
174
231
×
175
232
</ button >
176
- < div className = { styles . header } > Deploy < span className = { styles . nameColor } data-theme = { activeTheme } > { props . contract_name } ({ props . version_string } )</ span > </ div >
233
+ < div className = { styles . header } > Deploy < span className = { styles . nameColor } data-theme = { activeTheme } > { props . contract_name } ({ props . selected_version . version_string } )</ span > </ div >
177
234
< div className = { styles . content } >
178
235
< p className = { styles . mainMessage } > < b > You are about to create an instance of < span className = { styles . nameColor } data-theme = { activeTheme } > { props . contract_name } </ span > published contract where you will be the owner.</ b > < br /> </ p >
179
236
< div className = { styles . deployedNameDiv } >
@@ -200,7 +257,7 @@ function DeployIconComponent(props: DeployIconComponentProps) {
200
257
201
258
const argsObj : DeployArgsObj = {
202
259
contract_name : props . contract_name ,
203
- version : props . version ,
260
+ version : props . selected_version . version ,
204
261
deployed_name : deployedName ,
205
262
owner : props . userWalletInfo . address ,
206
263
salt : undefined
@@ -236,6 +293,35 @@ function DeployIconComponent(props: DeployIconComponentProps) {
236
293
) ;
237
294
}
238
295
296
+ function DeployVersionComponent ( props : DeployProps ) {
297
+
298
+ // The default selected version is the last one
299
+ const defaultSelectedVersion = {
300
+ version : props . versions [ 0 ] . version ,
301
+ version_string : props . versions [ 0 ] . version_string
302
+ } ;
303
+
304
+ const [ selectedVersion , setSelectedVersion ] = useState < { version : Version , version_string : string } > ( defaultSelectedVersion ) ;
305
+
306
+ return (
307
+ < >
308
+ < td >
309
+ < VersionDropdownButton
310
+ versions = { props . versions }
311
+ selected_version = { selectedVersion }
312
+ set_selected_version = { setSelectedVersion }
313
+ />
314
+ </ td >
315
+ < DeployIconComponent
316
+ userWalletInfo = { props . userWalletInfo }
317
+ refetchDeployedContract = { props . refetchDeployedContract }
318
+ contract_name = { props . contract_name }
319
+ selected_version = { selectedVersion }
320
+ />
321
+ </ >
322
+ )
323
+ }
324
+
239
325
240
326
export default function PublishedTab ( props : StateVariablesProps ) {
241
327
@@ -310,17 +396,33 @@ export default function PublishedTab(props: StateVariablesProps) {
310
396
const rows : JSX . Element [ ] = [ ] ;
311
397
312
398
publishedContracts . forEach ( ( publishedContract ) => {
399
+
400
+ const versions : { version : Version , version_string : string } [ ] = [ ] ;
401
+
402
+ publishedContract . versions . forEach ( ( obj ) => {
403
+
404
+ // Version obj
405
+ const version = obj . version ;
406
+
407
+ // Version string
408
+ const major = version . major ;
409
+ const minor = version . minor ;
410
+ const patch = version . patch ;
411
+ const version_string = `v.${ major } .${ minor } .${ patch } ` ;
412
+
413
+ versions . push ( { version, version_string} ) ;
414
+ } )
415
+ versions . reverse ( ) ;
416
+
313
417
rows . push (
314
418
< tr key = { publishedContract . index } data-theme = { activeTheme } >
315
419
< td className = { styles . contractCell } > { publishedContract . name } </ td >
316
420
< td > { publishedContract . author } </ td >
317
- < td > { publishedContract . version_string } </ td >
318
- < DeployIconComponent
421
+ < DeployVersionComponent
319
422
userWalletInfo = { props . walletInfo }
320
423
refetchDeployedContract = { props . fetchDeployed as FetchDatas }
321
424
contract_name = { publishedContract . name }
322
- version = { publishedContract . version }
323
- version_string = { publishedContract . version_string }
425
+ versions = { versions }
324
426
/>
325
427
</ tr >
326
428
) ;
@@ -340,7 +442,7 @@ export default function PublishedTab(props: StateVariablesProps) {
340
442
< tr >
341
443
< th > Contract</ th >
342
444
< th > Author</ th >
343
- < th > Version </ th >
445
+ < th > Versions </ th >
344
446
< th > Deploy</ th >
345
447
</ tr >
346
448
</ thead >
0 commit comments