async saveToDisk() {
    let walletsToSave = [];
    for (let key of this.wallets) {
      if (typeof key === 'boolean') continue;
      walletsToSave.push(JSON.stringify({ ...key, type: key.type }));
    }

    let data = {
      wallets: walletsToSave,
      tx_metadata: this.tx_metadata,
    };

    if (this.cachedPassword) {
      // should find the correct bucket, encrypt and then save
      let buckets = await AsyncStorage.getItem('data');
      buckets = JSON.parse(buckets);
      let newData = [];
      for (let bucket of buckets) {
        let decrypted = encryption.decrypt(bucket, this.cachedPassword);
        if (!decrypted) {
          // no luck decrypting, its not our bucket
          newData.push(bucket);
        } else {
          // decrypted ok, this is our bucket
          // we serialize our object's data, encrypt it, and add it to buckets
          newData.push(encryption.encrypt(JSON.stringify(data), this.cachedPassword));
          await AsyncStorage.setItem(AppStorage.FLAG_ENCRYPTED, '1');
        }
      }
      data = newData;
    } else {
      await AsyncStorage.setItem(AppStorage.FLAG_ENCRYPTED, ''); // drop the flag
    }

    return AsyncStorage.setItem('data', JSON.stringify(data));
  }
/**
   * Serializes and saves to storage object data.
   * If cached password is saved - finds the correct bucket
   * to save to, encrypts and then saves.
   *
   * @returns {Promise} Result of AsyncStorage save
   */
Serializes and saves to storage object data.
If cached password is saved - finds the correct bucket
to save to, encrypts and then saves.

@returns {Promise} Result of AsyncStorage save
Serializes and saves to storage object data . If cached password is saved - finds the correct bucket to save to encrypts and then saves . @returns { Promise } Result of AsyncStorage save
async saveToDisk() {
    let walletsToSave = [];
    for (let key of this.wallets) {
      if (typeof key === 'boolean') continue;
      walletsToSave.push(JSON.stringify({ ...key, type: key.type }));
    }
    let data = {
      wallets: walletsToSave,
      tx_metadata: this.tx_metadata,
    };
    if (this.cachedPassword) {
      let buckets = await AsyncStorage.getItem('data');
      buckets = JSON.parse(buckets);
      let newData = [];
      for (let bucket of buckets) {
        let decrypted = encryption.decrypt(bucket, this.cachedPassword);
        if (!decrypted) {
          newData.push(bucket);
        } else {
          newData.push(encryption.encrypt(JSON.stringify(data), this.cachedPassword));
          await AsyncStorage.setItem(AppStorage.FLAG_ENCRYPTED, '1');
        }
      }
      data = newData;
    } else {
      await AsyncStorage.setItem(AppStorage.FLAG_ENCRYPTED, ''); 
    }
    return AsyncStorage.setItem('data', JSON.stringify(data));
  }
async saveToDisk ( ) { let walletsToSave = [ ] ; for ( let key of this . wallets ) { if ( typeof key === 'boolean' ) continue ; walletsToSave . push ( JSON . stringify ( { ... key , type : key . type } ) ) ; } let data = { wallets : walletsToSave , tx_metadata : this . tx_metadata , } ; if ( this . cachedPassword ) { let buckets = await AsyncStorage . getItem ( 'data' ) ; buckets = JSON . parse ( buckets ) ; let newData = [ ] ; for ( let bucket of buckets ) { let decrypted = encryption . decrypt ( bucket , this . cachedPassword ) ; if ( ! decrypted ) { newData . push ( bucket ) ; } else { newData . push ( encryption . encrypt ( JSON . stringify ( data ) , this . cachedPassword ) ) ; await AsyncStorage . setItem ( AppStorage . FLAG_ENCRYPTED , '1' ) ; } } data = newData ; } else { await AsyncStorage . setItem ( AppStorage . FLAG_ENCRYPTED , '' ) ; } return AsyncStorage . setItem ( 'data' , JSON . stringify ( data ) ) ; }
Serializes and saves to storage object data.
Serializes and saves to storage object data .
// should find the correct bucket, encrypt and then save // no luck decrypting, its not our bucket // decrypted ok, this is our bucket // we serialize our object's data, encrypt it, and add it to buckets // drop the flag