11import { CheckIcon , ChevronDownIcon } from "@chakra-ui/icons" ;
22import {
3+ Badge ,
34 Box ,
45 Button ,
56 Flex ,
@@ -19,16 +20,16 @@ import { ShareUrlImport } from "./import/ShareUrlImport";
1920import { TransactionIdImport } from "./import/TransactionIdImport" ;
2021import { Preview } from "./preview/Preview" ;
2122
22- const IMPORT_TYPES : Record < PreviewSource , string > = {
23- tx : "Transaction ID" ,
24- shareUrl : "Share URL" ,
25- shareJson : "Share JSON" ,
26- anchorProgramId : "Anchor Program ID" ,
27- anchorJson : "Anchor IDL JSON" ,
28- } ;
23+ const SOURCES : { source : PreviewSource ; label : string ; type : string } [ ] = [
24+ { source : "tx" , label : "Transaction ID" , type : "tx" } ,
25+ { source : "anchorProgramId" , label : "Anchor Program ID" , type : "anchor" } ,
26+ { source : "shareUrl" , label : " Share URL" , type : "share" } ,
27+ { source : "shareJson" , label : "Share JSON" , type : "share" } ,
28+ { source : " anchorJson" , label : "Anchor IDL JSON" , type : "anchor" } ,
29+ ] ;
2930
3031export const ImportTransaction : React . FC = ( ) => {
31- const [ importType , setImportType ] = useState < PreviewSource > ( "tx" ) ;
32+ const [ source , setSource ] = useState < PreviewSource > ( "tx" ) ;
3233 const [ preview , setPreview ] = useState < IPreview > ( ) ;
3334 const [ error , setError ] = useState ( "" ) ;
3435
@@ -37,38 +38,54 @@ export const ImportTransaction: React.FC = () => {
3738 < Flex mb = "1" >
3839 < Menu matchWidth = { true } >
3940 < MenuButton flex = "1" as = { Button } size = "sm" >
40- { IMPORT_TYPES [ importType ] } < ChevronDownIcon />
41+ { SOURCES . find ( ( x ) => x . source === source ) ?. label } { " " }
42+ < ChevronDownIcon />
4143 </ MenuButton >
4244 < MenuList fontSize = "sm" zIndex = "modal" >
43- { Object . entries ( IMPORT_TYPES ) . map ( ( [ type , label ] ) => (
45+ { SOURCES . map ( ( { source : s , label, type } ) => (
4446 < MenuItem
45- key = { type }
46- icon = { type === importType ? < CheckIcon /> : undefined }
47+ key = { s }
48+ icon = { source === s ? < CheckIcon /> : undefined }
4749 onClick = { ( ) => {
4850 setPreview ( undefined ) ; // clear
49- setImportType ( type as PreviewSource ) ;
51+ setSource ( s ) ;
5052 } }
5153 >
54+ < Badge
55+ maxH = "4"
56+ mr = "1"
57+ colorScheme = {
58+ type === "tx"
59+ ? "green"
60+ : type === "share"
61+ ? "purple"
62+ : type === "anchor"
63+ ? "blue"
64+ : undefined
65+ }
66+ >
67+ { type }
68+ </ Badge >
5269 { label }
5370 </ MenuItem >
5471 ) ) }
5572 </ MenuList >
5673 </ Menu >
5774 </ Flex >
5875
59- { importType === "tx" && (
76+ { source === "tx" && (
6077 < TransactionIdImport setPreview = { setPreview } setError = { setError } />
6178 ) }
62- { importType === "shareUrl" && (
79+ { source === "shareUrl" && (
6380 < ShareUrlImport setPreview = { setPreview } setError = { setError } />
6481 ) }
65- { importType === "shareJson" && (
82+ { source === "shareJson" && (
6683 < ShareJsonImport setPreview = { setPreview } setError = { setError } />
6784 ) }
68- { importType === "anchorProgramId" && (
85+ { source === "anchorProgramId" && (
6986 < AnchorProgramIdImport setPreview = { setPreview } setError = { setError } />
7087 ) }
71- { importType === "anchorJson" && (
88+ { source === "anchorJson" && (
7289 < AnchorJsonImport setPreview = { setPreview } setError = { setError } />
7390 ) }
7491
0 commit comments