src/components/migration/Migrate2.js
//use this for selected key from dropdown menu
use this for selected key from dropdown menu
use this for selected key from dropdown menu
selectKey(e) {
        e.preventDefault();
        if (e.target.address_selection.value.length > 0) {
            try {
                var json = JSON.parse(localStorage.getItem('wallet'));
            } catch (e) {
                console.log('Error parsing the wallet data.');
                this.setOpenMigrationAlert('Error parsing the wallet data.');
            }
            var key_index = -1;
            var x_index = -1;
            for (var key in json.keys) {
                if (json.keys[key].public_key === this.props.data.address) {
                    key_index = key;
                    for (var x_key in json.safex_keys) {
                        if (json.safex_keys[x_key].public_addr === e.target.address_selection.value) {
                            x_index = x_key;
                            json.keys[key_index]['migration_data'] = {};
                            json.keys[key_index]['migration_data'].safex_keys = json.safex_keys[x_index];
                            json.keys[key_index].migration_progress = 2;
                        }
                    }
                }
            }
            if (x_index != -1 && key_index != -1) {
                var algorithm = 'aes-256-ctr';
                var password = localStorage.getItem('password');
                var cipher_text = encrypt(JSON.stringify(json), algorithm, password);
                fs.writeFile(localStorage.getItem('wallet_path'), cipher_text, (err) => {
                    if (err) {
                        this.setOpenMigrationAlert('Problem communicating to the wallet file.');
                    } else {
                        try {
                            localStorage.setItem('wallet', JSON.stringify(json));
                            var json2 = JSON.parse(localStorage.getItem('wallet'));
                            this.setState({
                                safex_key: json2.safex_keys[x_index],
                                safex_address: json2.safex_keys[x_index].public_addr,
                                safex_spend_pub: json2.safex_keys[x_index].spend.pub,
                                safex_spend_sec: json2.safex_keys[x_index].spend.sec,
                                safex_view_pub: json2.safex_keys[x_index].view.pub,
                                safex_view_sec: json2.safex_keys[x_index].view.sec,
                                loading: false,
                            });
                            this.props.setMigrationProgress(2);
                        } catch (e) {
                            console.log(e);
                            this.setOpenMigrationAlert('An error adding a key to the wallet. Please contact team@safex.io');
                        }
                    }
                });
            } else {
                console.log('Key does not exist');
                this.setOpenMigrationAlert('Key does not exist');
            }
        } else {
            console.log('No key from your list has been selected');
            this.setOpenMigrationAlert('No key from your list has been selected');
        }
    }
selectKey ( e ) { e . preventDefault ( ) ; if ( e . target . address_selection . value . length > 0 ) { try { var json = JSON . parse ( localStorage . getItem ( 'wallet' ) ) ; } catch ( e ) { console . log ( 'Error parsing the wallet data.' ) ; this . setOpenMigrationAlert ( 'Error parsing the wallet data.' ) ; } var key_index = - 1 ; var x_index = - 1 ; for ( var key in json . keys ) { if ( json . keys [ key ] . public_key === this . props . data . address ) { key_index = key ; for ( var x_key in json . safex_keys ) { if ( json . safex_keys [ x_key ] . public_addr === e . target . address_selection . value ) { x_index = x_key ; json . keys [ key_index ] [ 'migration_data' ] = { } ; json . keys [ key_index ] [ 'migration_data' ] . safex_keys = json . safex_keys [ x_index ] ; json . keys [ key_index ] . migration_progress = 2 ; } } } } if ( x_index != - 1 && key_index != - 1 ) { var algorithm = 'aes-256-ctr' ; var password = localStorage . getItem ( 'password' ) ; var cipher_text = encrypt ( JSON . stringify ( json ) , algorithm , password ) ; fs . writeFile ( localStorage . getItem ( 'wallet_path' ) , cipher_text , ( err ) => { if ( err ) { this . setOpenMigrationAlert ( 'Problem communicating to the wallet file.' ) ; } else { try { localStorage . setItem ( 'wallet' , JSON . stringify ( json ) ) ; var json2 = JSON . parse ( localStorage . getItem ( 'wallet' ) ) ; this . setState ( { safex_key : json2 . safex_keys [ x_index ] , safex_address : json2 . safex_keys [ x_index ] . public_addr , safex_spend_pub : json2 . safex_keys [ x_index ] . spend . pub , safex_spend_sec : json2 . safex_keys [ x_index ] . spend . sec , safex_view_pub : json2 . safex_keys [ x_index ] . view . pub , safex_view_sec : json2 . safex_keys [ x_index ] . view . sec , loading : false , } ) ; this . props . setMigrationProgress ( 2 ) ; } catch ( e ) { console . log ( e ) ; this . setOpenMigrationAlert ( 'An error adding a key to the wallet. Please contact team@safex.io' ) ; } } } ) ; } else { console . log ( 'Key does not exist' ) ; this . setOpenMigrationAlert ( 'Key does not exist' ) ; } } else { console . log ( 'No key from your list has been selected' ) ; this . setOpenMigrationAlert ( 'No key from your list has been selected' ) ; } }
use this for selected key from dropdown menu
use this for selected key from dropdown menu