src/components/migration/Migrate2.js
//use this after safex keys were generated
use this after safex keys were generated
use this after safex keys were generated
saveSafexKeys() {
        try {
            var json = JSON.parse(localStorage.getItem('wallet'));
        } catch (e) {
            this.setOpenMigrationAlert('Error parsing the wallet data.');
        }
        if (json.hasOwnProperty('safex_keys')) {
            json['safex_keys'].push(this.state.safex_key);
        } else {
            json['safex_keys'] = [];
            json['safex_keys'].push(this.state.safex_key);
        }
        var index = -1;
        for (var key in json.keys) {
            if (json.keys[key].public_key === this.props.data.address) {
                index = key;
                json.keys[key]['migration_data'] = {};
                json.keys[key]['migration_data'].safex_keys = this.state.safex_key;
                json.keys[key].migration_progress = 2;
            }
        }
        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) {
                console.log('Problem communicating to the wallet file.');
                this.setOpenMigrationAlert('Problem communicating to the wallet file.');
            } else {
                try {
                    localStorage.setItem('wallet', JSON.stringify(json));
                    var json2 = JSON.parse(localStorage.getItem('wallet'));
                    console.log(json2.keys[index].migration_data);
                    this.exportNewWalletAddress();
                    this.props.setMigrationProgress(2);
                } catch (e) {
                    console.log(e);
                    this.setOpenMigrationAlert('An error adding a key to the wallet. Please contact team@safex.io');
                }
            }
        });
    }
saveSafexKeys ( ) { try { var json = JSON . parse ( localStorage . getItem ( 'wallet' ) ) ; } catch ( e ) { this . setOpenMigrationAlert ( 'Error parsing the wallet data.' ) ; } if ( json . hasOwnProperty ( 'safex_keys' ) ) { json [ 'safex_keys' ] . push ( this . state . safex_key ) ; } else { json [ 'safex_keys' ] = [ ] ; json [ 'safex_keys' ] . push ( this . state . safex_key ) ; } var index = - 1 ; for ( var key in json . keys ) { if ( json . keys [ key ] . public_key === this . props . data . address ) { index = key ; json . keys [ key ] [ 'migration_data' ] = { } ; json . keys [ key ] [ 'migration_data' ] . safex_keys = this . state . safex_key ; json . keys [ key ] . migration_progress = 2 ; } } 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 ) { console . log ( 'Problem communicating to the wallet file.' ) ; this . setOpenMigrationAlert ( 'Problem communicating to the wallet file.' ) ; } else { try { localStorage . setItem ( 'wallet' , JSON . stringify ( json ) ) ; var json2 = JSON . parse ( localStorage . getItem ( 'wallet' ) ) ; console . log ( json2 . keys [ index ] . migration_data ) ; this . exportNewWalletAddress ( ) ; this . props . setMigrationProgress ( 2 ) ; } catch ( e ) { console . log ( e ) ; this . setOpenMigrationAlert ( 'An error adding a key to the wallet. Please contact team@safex.io' ) ; } } } ) ; }
use this after safex keys were generated
use this after safex keys were generated
//in here do the logic for modifying the wallet file data info