@@ -68,35 +68,31 @@ class MintTokens extends Component<Props> {
6868 }
6969
7070 handleReset = ( withState = true ) => {
71- // TODO @bshevchenko : maybe there is a better way to reset FileUploader $FlowFixMe
7271 const node = this . fileUploader . nodes [ 0 ] ;
7372 if ( node ) {
74- const el = Array . from ( node . getElementsByClassName ( 'bx--file-close' ) ) [ 0 ] ;
75- const event = document . createEvent ( 'Events' ) ;
76- event . initEvent ( 'click' , true , false ) ;
77- el . dispatchEvent ( event ) ;
73+ this . fileUploader . clearFiles ( ) ;
7874 if ( withState ) {
7975 this . props . mintResetUploaded ( ) ;
8076 }
8177 }
8278 } ;
8379
84- handleClick = ( event : Object ) = > {
85- const el = event . target ;
86- if (
87- el . getAttribute ( 'class' ) === 'bx--file-close' ||
88- // TODO @bshevchenko : maybe there is a better way to handle cancel event
89- ( el . getAttribute ( 'd' ) &&
90- el . getAttribute ( 'd' ) . substring ( 0 , 6 ) === 'M8 0C3' )
91- ) {
92- this . props . mintResetUploaded ( ) ;
93- }
94- } ;
95-
96- handleUploaded = ( event : Object ) => {
80+ handleUploaded = async ( event : Object ) = > {
9781 const file = event . target . files [ 0 ] ;
9882 if ( file . type . match ( / c s v .* / ) || file . name . match ( / .* \. c s v $ / i) ) {
99- this . props . uploadCSV ( file ) ;
83+ await this . props . uploadCSV ( file ) ;
84+ //NOTE @sajclarke : This hack is necessary to add an eventlistener to the dynamic filename container from FileUploader
85+ const node = this . fileUploader . nodes [ 0 ] ;
86+ if ( node ) {
87+ const el = Array . from ( node . getElementsByClassName ( 'bx--file-close' ) ) [ 0 ] ;
88+ el . addEventListener (
89+ 'click' ,
90+ e => {
91+ this . props . mintResetUploaded ( ) ;
92+ } ,
93+ false
94+ ) ;
95+ }
10096 }
10197 } ;
10298
@@ -300,7 +296,6 @@ class MintTokens extends Component<Props> {
300296 iconDescription = "Cancel"
301297 buttonLabel = "Upload File"
302298 onChange = { this . handleUploaded }
303- onClick = { this . handleClick }
304299 className = { classNames ( 'file-uploader' , {
305300 disabled : stoInProgress || isTransfersPaused ,
306301 } ) }
0 commit comments