<commit_before>import { Injectable } from '@angular/core';
import { InjectionToken, Inject } from '@angular/core';
import { Logger } from '@nsalaun/ng-logger';
import * as _ from 'lodash';

import { IStorage, ISTORAGE } from './storage/istorage';
import { PlatformProvider } from '../platform/platform';
import { LocalStorage } from './storage/local-storage';
import { ChromeStorage } from './storage/chrome-storage';
import { FileStorage } from './storage/file-storage';
import { RamStorage } from './storage/ram-storage';

const Keys = {
  ADDRESS_BOOK: network => 'addressbook-' + network,
  AGREE_DISCLAIMER: 'agreeDisclaimer',
  AMAZON_GIFT_CARDS: network => 'amazonGiftCards-' + network,
  APP_IDENTITY: network => 'appIdentity-' + network,
  BACKUP: walletId => 'backup-' + walletId,
  BALANCE_CACHE: cardId => 'balanceCache-' + cardId,
  BITPAY_ACCOUNTS_V2: network => 'bitpayAccounts-v2-' + network,
  CLEAN_AND_SCAN_ADDRESSES: 'CleanAndScanAddresses',
  COINBASE_REFRESH_TOKEN: network => 'coinbaseRefreshToken-' + network,
  COINBASE_TOKEN: network => 'coinbaseToken-' + network,
  COINBASE_TXS: network => 'coinbaseTxs-' + network,
  CONFIG: 'config',
  FEEDBACK: 'feedback',
  FOCUSED_WALLET_ID: 'focusedWalletId',
  GLIDERA_PERMISSIONS: network => 'glideraPermissions-' + network,
  GLIDERA_STATUS: network => 'glideraStatus-' + network,
  GLIDERA_TOKEN: network => 'glideraToken-' + network,
  GLIDERA_TXS: network => 'glideraTxs-' + network,
  HIDE_BALANCE: walletId => 'hideBalance-' + walletId,
  HOME_TIP: 'homeTip',
  LAST_ADDRESS: walletId => 'lastAddress-' + walletId,
  LAST_CURRENCY_USED: 'lastCurrencyUsed',
  PROFILE: 'profile',
  REMOTE_PREF_STORED: 'remotePrefStored',
  TX_CONFIRM_NOTIF: txid => 'txConfirmNotif-' + txid,
  TX_HISTORY: walletId => 'txsHistory-' + walletId,
};

export let persistenceProviderFactory = (platform: PlatformProvider, log: Logger) => {
  // TODO: select appropriate storage service based on platform
  let storage;
  /*
  if (this.platform.isChromeApp) {
    storage = new ChromeStorage(log);
  } else if (this.platform.isCordova) {
    storage = new FileStorage(log);
  } else {
    storage = new LocalStorage(log);
  }
   */
  // Testing in RAM
  storage = new RamStorage(log);
  return new PersistenceProvider(storage, log);
};

@Injectable()
export class PersistenceProvider {
  constructor( @Inject(ISTORAGE) public storage: IStorage, private log: Logger) {
  };

  storeNewProfile(profile): Promise<void> {
    return this.storage.create(Keys.PROFILE, profile);
  };

  storeProfile(profile): Promise<void> {
    return this.storage.set(Keys.PROFILE, profile);
  };

  getProfile(): Promise<any> {
    return this.storage.get(Keys.PROFILE);
  };

  deleteProfile(): Promise<void> {<commit_msg>Fix get profile<commit_after>import { Injectable } from '@angular/core';
import { InjectionToken, Inject } from '@angular/core';
import { Logger } from '@nsalaun/ng-logger';
import * as _ from 'lodash';

import { IStorage, ISTORAGE } from './storage/istorage';
import { PlatformProvider } from '../platform/platform';
import { LocalStorage } from './storage/local-storage';
import { ChromeStorage } from './storage/chrome-storage';
import { FileStorage } from './storage/file-storage';
import { RamStorage } from './storage/ram-storage';

const Keys = {
  ADDRESS_BOOK: network => 'addressbook-' + network,
  AGREE_DISCLAIMER: 'agreeDisclaimer',
  AMAZON_GIFT_CARDS: network => 'amazonGiftCards-' + network,
  APP_IDENTITY: network => 'appIdentity-' + network,
  BACKUP: walletId => 'backup-' + walletId,
  BALANCE_CACHE: cardId => 'balanceCache-' + cardId,
  BITPAY_ACCOUNTS_V2: network => 'bitpayAccounts-v2-' + network,
  CLEAN_AND_SCAN_ADDRESSES: 'CleanAndScanAddresses',
  COINBASE_REFRESH_TOKEN: network => 'coinbaseRefreshToken-' + network,
  COINBASE_TOKEN: network => 'coinbaseToken-' + network,
  COINBASE_TXS: network => 'coinbaseTxs-' + network,
  CONFIG: 'config',
  FEEDBACK: 'feedback',
  FOCUSED_WALLET_ID: 'focusedWalletId',
  GLIDERA_PERMISSIONS: network => 'glideraPermissions-' + network,
  GLIDERA_STATUS: network => 'glideraStatus-' + network,
  GLIDERA_TOKEN: network => 'glideraToken-' + network,
  GLIDERA_TXS: network => 'glideraTxs-' + network,
  HIDE_BALANCE: walletId => 'hideBalance-' + walletId,
  HOME_TIP: 'homeTip',
  LAST_ADDRESS: walletId => 'lastAddress-' + walletId,
  LAST_CURRENCY_USED: 'lastCurrencyUsed',
  PROFILE: 'profile',
  REMOTE_PREF_STORED: 'remotePrefStored',
  TX_CONFIRM_NOTIF: txid => 'txConfirmNotif-' + txid,
  TX_HISTORY: walletId => 'txsHistory-' + walletId,
};

export let persistenceProviderFactory = (platform: PlatformProvider, log: Logger) => {
  // TODO: select appropriate storage service based on platform
  let storage;
  /*
  if (this.platform.isChromeApp) {
    storage = new ChromeStorage(log);
  } else if (this.platform.isCordova) {
    storage = new FileStorage(log);
  } else {
    storage = new LocalStorage(log);
  }
   */
  // Testing in RAM
  storage = new RamStorage(log);
  return new PersistenceProvider(storage, log);
};

@Injectable()
export class PersistenceProvider {
  constructor( @Inject(ISTORAGE) public storage: IStorage, private log: Logger) {
  };

  storeNewProfile(profile): Promise<void> {
    return this.storage.create(Keys.PROFILE, profile);
  };

  storeProfile(profile): Promise<void> {
    return this.storage.set(Keys.PROFILE, profile);
  };

  getProfile(): Promise<any> {
    return new Promise((resolve, reject) => {
      this.storage.get(Keys.PROFILE).then((profile) => {
        resolve(profile);
      });
    });
  };

  deleteProfile(): Promise<void> {
{'fraction_non_alphanumeric': 0.13950177935943062, 'fraction_numerical': 0.0007117437722419929, 'mean_word_length': 4.712398373983739, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5924061', 'n_tokens_mistral': 1914, 'n_tokens_neox': 1841, 'n_words': 406}