mirror of https://github.com/BTCPrivate/copay.git
migrated more methods from storageService
This commit is contained in:
parent
b3acf29899
commit
13586f60f8
|
@ -2,6 +2,7 @@ import { TestBed, inject } from '@angular/core/testing';
|
||||||
import { PersistenceProvider } from './persistence';
|
import { PersistenceProvider } from './persistence';
|
||||||
import { IStorage, ISTORAGE, KeyAlreadyExistsError } from './storage/istorage';
|
import { IStorage, ISTORAGE, KeyAlreadyExistsError } from './storage/istorage';
|
||||||
import { RamStorage } from './storage/ram-storage';
|
import { RamStorage } from './storage/ram-storage';
|
||||||
|
import { Logger } from '@nsalaun/ng-logger';
|
||||||
|
|
||||||
describe('Storage Service', () => {
|
describe('Storage Service', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -9,6 +10,7 @@ describe('Storage Service', () => {
|
||||||
providers: [
|
providers: [
|
||||||
PersistenceProvider,
|
PersistenceProvider,
|
||||||
{ provide: ISTORAGE, useClass: RamStorage },
|
{ provide: ISTORAGE, useClass: RamStorage },
|
||||||
|
{ provide: Logger },
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -19,7 +21,7 @@ describe('Storage Service', () => {
|
||||||
service = pp;
|
service = pp;
|
||||||
}));
|
}));
|
||||||
it('should correctly perform a profile roundtrip', () => {
|
it('should correctly perform a profile roundtrip', () => {
|
||||||
var p = { name: 'My profile' };
|
let p = { name: 'My profile' };
|
||||||
service.storeNewProfile(p).then(() => {
|
service.storeNewProfile(p).then(() => {
|
||||||
service.getProfile().then((profile) => {
|
service.getProfile().then((profile) => {
|
||||||
expect(typeof profile).toEqual('object');
|
expect(typeof profile).toEqual('object');
|
||||||
|
@ -28,7 +30,7 @@ describe('Storage Service', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should fail to create a profile when one already exists', () => {
|
it('should fail to create a profile when one already exists', () => {
|
||||||
var p = { name: 'My profile' };
|
let p = { name: 'My profile' };
|
||||||
service.storeNewProfile(p).then(() => {
|
service.storeNewProfile(p).then(() => {
|
||||||
service.storeNewProfile(p).catch((err) => {
|
service.storeNewProfile(p).catch((err) => {
|
||||||
expect(err.message).toEqual('Key already exists');
|
expect(err.message).toEqual('Key already exists');
|
||||||
|
|
|
@ -1,34 +1,441 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { InjectionToken, Inject } from '@angular/core';
|
import { InjectionToken, Inject } from '@angular/core';
|
||||||
import { IStorage, ISTORAGE } from './storage/istorage';
|
import { IStorage, ISTORAGE } from './storage/istorage';
|
||||||
|
import { Logger } from '@nsalaun/ng-logger';
|
||||||
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PersistenceProvider {
|
export class PersistenceProvider {
|
||||||
constructor( @Inject(ISTORAGE) public storage: IStorage) {
|
constructor( @Inject(ISTORAGE) public storage: IStorage, private log: Logger) {
|
||||||
}
|
}
|
||||||
|
|
||||||
storeNewProfile(profile): Promise<void> {
|
storeNewProfile(profile): Promise<void> {
|
||||||
return this.storage.create('profile', profile);
|
return this.storage.create(Keys.PROFILE, profile);
|
||||||
};
|
};
|
||||||
|
|
||||||
storeProfile(profile): Promise<void> {
|
storeProfile(profile): Promise<void> {
|
||||||
return this.storage.set('profile', profile);
|
return this.storage.set(Keys.PROFILE, profile);
|
||||||
};
|
};
|
||||||
|
|
||||||
getProfile(): Promise<any> {
|
getProfile(): Promise<any> {
|
||||||
return this.storage.get('profile').then((profile) => {
|
return this.storage.get(Keys.PROFILE);
|
||||||
return profile;
|
};
|
||||||
|
|
||||||
|
deleteProfile(): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.PROFILE);
|
||||||
|
};
|
||||||
|
|
||||||
|
setFeedbackInfo(feedbackValues: any): Promise<void> {
|
||||||
|
return this.storage.set(Keys.FEEDBACK, feedbackValues);
|
||||||
|
};
|
||||||
|
|
||||||
|
getFeedbackInfo(): Promise<void> {
|
||||||
|
return this.storage.get(Keys.FEEDBACK);
|
||||||
|
};
|
||||||
|
|
||||||
|
storeFocusedWalletId(walletId: string): Promise<void> {
|
||||||
|
return this.storage.set(Keys.FOCUSED_WALLET_ID, walletId || '');
|
||||||
|
};
|
||||||
|
|
||||||
|
getFocusedWalletId(): Promise<string> {
|
||||||
|
return this.storage.get(Keys.FOCUSED_WALLET_ID);
|
||||||
|
};
|
||||||
|
|
||||||
|
getLastAddress(walletId: string): Promise<any> {
|
||||||
|
return this.storage.get(Keys.LAST_ADDRESS(walletId));
|
||||||
|
};
|
||||||
|
|
||||||
|
storeLastAddress(walletId: string, address: any): Promise<void> {
|
||||||
|
return this.storage.set(Keys.LAST_ADDRESS(walletId), address);
|
||||||
|
};
|
||||||
|
|
||||||
|
clearLastAddress(walletId: string): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.LAST_ADDRESS(walletId));
|
||||||
|
};
|
||||||
|
|
||||||
|
setBackupFlag(walletId: string): Promise<void> {
|
||||||
|
return this.storage.set(Keys.BACKUP(walletId), Date.now());
|
||||||
|
};
|
||||||
|
|
||||||
|
getBackupFlag(walletId: string): Promise<any> {
|
||||||
|
return this.storage.get(Keys.BACKUP(walletId));
|
||||||
|
};
|
||||||
|
|
||||||
|
clearBackupFlag(walletId: string): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.BACKUP(walletId));
|
||||||
|
};
|
||||||
|
|
||||||
|
setCleanAndScanAddresses(walletId: string): Promise<void> {
|
||||||
|
return this.storage.set(Keys.CLEAN_AND_SCAN_ADDRESSES, walletId);
|
||||||
|
};
|
||||||
|
|
||||||
|
getCleanAndScanAddresses(): Promise<any> {
|
||||||
|
return this.storage.get(Keys.CLEAN_AND_SCAN_ADDRESSES);
|
||||||
|
};
|
||||||
|
|
||||||
|
removeCleanAndScanAddresses(): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.CLEAN_AND_SCAN_ADDRESSES);
|
||||||
|
};
|
||||||
|
|
||||||
|
getConfig(): Promise<void> {
|
||||||
|
return this.storage.get(Keys.CONFIG);
|
||||||
|
};
|
||||||
|
|
||||||
|
storeConfig(config: any): Promise<void> {
|
||||||
|
return this.storage.set(Keys.CONFIG, config);
|
||||||
|
};
|
||||||
|
|
||||||
|
clearConfig(): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.CONFIG);
|
||||||
|
};
|
||||||
|
|
||||||
|
getHomeTipAccepted(): Promise<any> {
|
||||||
|
return this.storage.get(Keys.HOME_TIP);
|
||||||
|
};
|
||||||
|
|
||||||
|
setHomeTipAccepted(homeTip: any): Promise<void> {
|
||||||
|
return this.storage.set(Keys.HOME_TIP, homeTip);
|
||||||
|
};
|
||||||
|
|
||||||
|
setHideBalanceFlag(walletId: string, val: any): Promise<void> {
|
||||||
|
return this.storage.set(Keys.HIDE_BALANCE(walletId), val);
|
||||||
|
};
|
||||||
|
|
||||||
|
getHideBalanceFlag(walletId: string): Promise<any> {
|
||||||
|
return this.storage.get(Keys.HIDE_BALANCE(walletId));
|
||||||
|
};
|
||||||
|
|
||||||
|
//for compatibility
|
||||||
|
getCopayDisclaimerFlag(): Promise<any> {
|
||||||
|
return this.storage.get(Keys.AGREE_DISCLAIMER);
|
||||||
|
};
|
||||||
|
|
||||||
|
setRemotePrefsStoredFlag(): Promise<void> {
|
||||||
|
return this.storage.set(Keys.REMOTE_PREF_STORED, true);
|
||||||
|
};
|
||||||
|
|
||||||
|
getRemotePrefsStoredFlag(): Promise<any> {
|
||||||
|
return this.storage.get(Keys.REMOTE_PREF_STORED);
|
||||||
|
};
|
||||||
|
|
||||||
|
setGlideraToken(network: string, token: string): Promise<void> {
|
||||||
|
return this.storage.set(Keys.GLIDERA_TOKEN(network), token);
|
||||||
|
};
|
||||||
|
|
||||||
|
getGlideraToken(network: string): Promise<string> {
|
||||||
|
return this.storage.get(Keys.GLIDERA_TOKEN(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
removeGlideraToken(network: string): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.GLIDERA_TOKEN(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
setGlideraPermissions(network: string, permissions: any): Promise<void> {
|
||||||
|
return this.storage.set(Keys.GLIDERA_PERMISSIONS(network), permissions);
|
||||||
|
};
|
||||||
|
|
||||||
|
getGlideraPermissions(network: string): Promise<any> {
|
||||||
|
return this.storage.get(Keys.GLIDERA_PERMISSIONS(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
removeGlideraPermissions(network: string): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.GLIDERA_PERMISSIONS(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
setGlideraStatus(network: string, status: any): Promise<void> {
|
||||||
|
return this.storage.set(Keys.GLIDERA_STATUS(network), status);
|
||||||
|
};
|
||||||
|
|
||||||
|
getGlideraStatus(network: string): Promise<any> {
|
||||||
|
return this.storage.get(Keys.GLIDERA_STATUS(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
removeGlideraStatus(network: string): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.GLIDERA_STATUS(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
setGlideraTxs(network: string, txs: any): Promise<void> {
|
||||||
|
return this.storage.set(Keys.GLIDERA_TXS(network), txs);
|
||||||
|
};
|
||||||
|
|
||||||
|
getGlideraTxs(network: string): Promise<any> {
|
||||||
|
return this.storage.get(Keys.GLIDERA_TXS(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
removeGlideraTxs(network: string): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.GLIDERA_TXS(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
setCoinbaseToken(network: string, token: string): Promise<void> {
|
||||||
|
return this.storage.set(Keys.COINBASE_TOKEN(network), token);
|
||||||
|
};
|
||||||
|
|
||||||
|
getCoinbaseToken(network: string): Promise<string> {
|
||||||
|
return this.storage.get(Keys.COINBASE_TOKEN(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
removeCoinbaseToken(network: string): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.COINBASE_TOKEN(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
setCoinbaseRefreshToken(network: string, token: string): Promise<void> {
|
||||||
|
return this.storage.set(Keys.COINBASE_REFRESH_TOKEN(network), token);
|
||||||
|
};
|
||||||
|
|
||||||
|
getCoinbaseRefreshToken(network: string): Promise<string> {
|
||||||
|
return this.storage.get(Keys.COINBASE_REFRESH_TOKEN(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
removeCoinbaseRefreshToken(network: string): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.COINBASE_REFRESH_TOKEN(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
setCoinbaseTxs(network: string, ctx: any): Promise<void> {
|
||||||
|
return this.storage.set(Keys.COINBASE_TXS(network), ctx);
|
||||||
|
};
|
||||||
|
|
||||||
|
getCoinbaseTxs(network: string): Promise<any> {
|
||||||
|
return this.storage.get(Keys.COINBASE_TXS(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
removeCoinbaseTxs(network: string): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.COINBASE_TXS(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
setAddressbook(network: string, addressbook: any): Promise<void> {
|
||||||
|
return this.storage.set(Keys.ADDRESS_BOOK(network), addressbook);
|
||||||
|
};
|
||||||
|
|
||||||
|
getAddressbook(network: string): Promise<any> {
|
||||||
|
return this.storage.get(Keys.ADDRESS_BOOK(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
removeAddressbook(network: string): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.ADDRESS_BOOK(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
setLastCurrencyUsed(lastCurrencyUsed: any): Promise<void> {
|
||||||
|
return this.storage.set(Keys.LAST_CURRENCY_USED, lastCurrencyUsed);
|
||||||
|
};
|
||||||
|
|
||||||
|
getLastCurrencyUsed(): Promise<any> {
|
||||||
|
return this.storage.get(Keys.LAST_CURRENCY_USED);
|
||||||
|
};
|
||||||
|
|
||||||
|
checkQuota(): void {
|
||||||
|
let block = '';
|
||||||
|
// 50MB
|
||||||
|
for (let i = 0; i < 1024 * 1024; ++i) {
|
||||||
|
block += '12345678901234567890123456789012345678901234567890';
|
||||||
|
}
|
||||||
|
this.storage.set('test', block).catch(err => {
|
||||||
|
this.log.error('CheckQuota Return:' + err);
|
||||||
});
|
});
|
||||||
// decryptOnMobile(str, function (err, str) {
|
};
|
||||||
// if (err) return cb(err);
|
|
||||||
// var p, err;
|
setTxHistory(walletId: string, txs: any): Promise<void> {
|
||||||
// try {
|
return this.storage.set(Keys.TX_HISTORY(walletId), txs).catch(err => {
|
||||||
// p = Profile.fromString(str);
|
this.log.error('Error saving tx History. Size:' + txs.length);
|
||||||
// } catch (e) {
|
this.log.error(err);
|
||||||
// $log.debug('Could not read profile:', e);
|
});
|
||||||
// err = new Error('Could not read profile:' + p);
|
}
|
||||||
|
|
||||||
|
getTxHistory(walletId: string): Promise<any> {
|
||||||
|
return this.storage.get(Keys.TX_HISTORY(walletId));
|
||||||
|
}
|
||||||
|
|
||||||
|
removeTxHistory(walletId: string): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.TX_HISTORY(walletId));
|
||||||
|
}
|
||||||
|
|
||||||
|
setBalanceCache(cardId: string, data: any): Promise<void> {
|
||||||
|
return this.storage.set(Keys.BALANCE_CACHE(cardId), data);
|
||||||
|
};
|
||||||
|
|
||||||
|
getBalanceCache(cardId: string): Promise<any> {
|
||||||
|
return this.storage.get(Keys.BALANCE_CACHE(cardId));
|
||||||
|
};
|
||||||
|
|
||||||
|
removeBalanceCache(cardId: string): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.BALANCE_CACHE(cardId));
|
||||||
|
};
|
||||||
|
|
||||||
|
setAppIdentity(network: string, data: any): Promise<void> {
|
||||||
|
return this.storage.set(Keys.APP_IDENTITY(network), data);
|
||||||
|
};
|
||||||
|
|
||||||
|
getAppIdentity(network: string): Promise<any> {
|
||||||
|
return this.storage.get(Keys.APP_IDENTITY(network)).then(data => {
|
||||||
|
return JSON.parse(data || '{}');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
removeAppIdentity(network: string): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.APP_IDENTITY(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
removeAllWalletData(walletId: string): Promise<void> {
|
||||||
|
return this.clearLastAddress(walletId)
|
||||||
|
.then(() => {
|
||||||
|
return this.removeTxHistory(walletId);
|
||||||
|
}).then(() => {
|
||||||
|
return this.clearBackupFlag(walletId);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
setAmazonGiftCards(network: string, gcs: any): Promise<void> {
|
||||||
|
return this.storage.set(Keys.AMAZON_GIFT_CARDS(network), gcs);
|
||||||
|
};
|
||||||
|
|
||||||
|
getAmazonGiftCards(network: string): Promise<any> {
|
||||||
|
return this.storage.get(Keys.AMAZON_GIFT_CARDS(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
removeAmazonGiftCards(network: string): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.AMAZON_GIFT_CARDS(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
setTxConfirmNotification(txid: string, val: any): Promise<void> {
|
||||||
|
return this.storage.set(Keys.TX_CONFIRM_NOTIF(txid), val);
|
||||||
|
};
|
||||||
|
|
||||||
|
getTxConfirmNotification(txid: string): Promise<any> {
|
||||||
|
return this.storage.get(Keys.TX_CONFIRM_NOTIF(txid));
|
||||||
|
};
|
||||||
|
|
||||||
|
removeTxConfirmNotification(txid: string): Promise<void> {
|
||||||
|
return this.storage.remove(Keys.TX_CONFIRM_NOTIF(txid));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// cb(err, accounts)
|
||||||
|
// accounts: {
|
||||||
|
// email_1: {
|
||||||
|
// token: account token
|
||||||
|
// cards: {
|
||||||
|
// <card-data>
|
||||||
// }
|
// }
|
||||||
// return cb(err, p);
|
// }
|
||||||
// });
|
// ...
|
||||||
|
// email_n: {
|
||||||
|
// token: account token
|
||||||
|
// cards: {
|
||||||
|
// <card-data>
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
getBitpayAccounts(network: string): Promise<any> {
|
||||||
|
return this.storage.get(Keys.BITPAY_ACCOUNTS_V2(network));
|
||||||
|
};
|
||||||
|
|
||||||
|
setBitpayAccount(network: string, data: {
|
||||||
|
email: string,
|
||||||
|
token: string,
|
||||||
|
familyName?: string, // last name
|
||||||
|
givenName?: string, // firstName
|
||||||
|
}): Promise<any> {
|
||||||
|
return this.getBitpayAccounts(network)
|
||||||
|
.then(allAccounts => {
|
||||||
|
allAccounts = allAccounts || {};
|
||||||
|
let account = allAccounts[data.email] || {};
|
||||||
|
account.token = data.token;
|
||||||
|
account.familyName = data.familyName;
|
||||||
|
account.givenName = data.givenName;
|
||||||
|
allAccounts[data.email] = account;
|
||||||
|
|
||||||
|
this.log.info('Storing BitPay accounts with new account:' + data.email);
|
||||||
|
return this.storage.set(Keys.BITPAY_ACCOUNTS_V2(network), allAccounts);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
removeBitpayAccount(network: string, email: string): Promise<void> {
|
||||||
|
return this.getBitpayAccounts(network)
|
||||||
|
.then(allAccounts => {
|
||||||
|
allAccounts = allAccounts || {};
|
||||||
|
delete allAccounts[email];
|
||||||
|
return this.storage.set(Keys.BITPAY_ACCOUNTS_V2(network), allAccounts);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// cards: [
|
||||||
|
// eid: card id
|
||||||
|
// id: card id
|
||||||
|
// lastFourDigits: card number
|
||||||
|
// token: card token
|
||||||
|
// ]
|
||||||
|
setBitpayDebitCards(network: string, email: string, cards: any): Promise<void> {
|
||||||
|
return this.getBitpayAccounts(network).then(allAccounts => {
|
||||||
|
allAccounts = allAccounts || {};
|
||||||
|
if (!allAccounts[email]) throw new Error('Cannot set cards for unknown account ' + email);
|
||||||
|
allAccounts[email].cards = cards;
|
||||||
|
return this.storage.set(Keys.BITPAY_ACCOUNTS_V2(network), allAccounts);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// cards: [
|
||||||
|
// eid: card id
|
||||||
|
// id: card id
|
||||||
|
// lastFourDigits: card number
|
||||||
|
// token: card token
|
||||||
|
// email: account email
|
||||||
|
// ]
|
||||||
|
getBitpayDebitCards(network: string): Promise<any[]> {
|
||||||
|
return this.getBitpayAccounts(network).then(allAccounts => {
|
||||||
|
let allCards = [];
|
||||||
|
_.each(allAccounts, (account, email) => {
|
||||||
|
if (account.cards) {
|
||||||
|
// Add account's email to each card
|
||||||
|
var cards = _.clone(account.cards);
|
||||||
|
_.each(cards, function (x) {
|
||||||
|
x.email = email;
|
||||||
|
});
|
||||||
|
|
||||||
|
allCards = allCards.concat(cards);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return allCards;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
removeBitpayDebitCard(network: string, cardEid: string): Promise<void> {
|
||||||
|
return this.getBitpayAccounts(network).then(allAccounts => {
|
||||||
|
_.each(allAccounts, function (account) {
|
||||||
|
account.cards = _.reject(account.cards, {
|
||||||
|
eid: cardEid
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.storage.set(Keys.BITPAY_ACCOUNTS_V2(network), allAccounts);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ export class LocalStorage implements IStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
set(k: string, v: any): Promise<void> {
|
set(k: string, v: any): Promise<void> {
|
||||||
return new Promise<void>(() => {
|
return new Promise((resolve) => {
|
||||||
if (_.isObject(v)) {
|
if (_.isObject(v)) {
|
||||||
v = JSON.stringify(v);
|
v = JSON.stringify(v);
|
||||||
}
|
}
|
||||||
|
@ -37,11 +37,12 @@ export class LocalStorage implements IStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ls.setItem(k, v);
|
this.ls.setItem(k, v);
|
||||||
|
resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(k: string): Promise<void> {
|
remove(k: string): Promise<void> {
|
||||||
return new Promise<void>(() => {
|
return Promise.resolve().then(() => {
|
||||||
this.ls.removeItem(k);
|
this.ls.removeItem(k);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,21 +4,13 @@ export class RamStorage implements IStorage {
|
||||||
hash = {};
|
hash = {};
|
||||||
|
|
||||||
get(k: string): Promise<any> {
|
get(k: string): Promise<any> {
|
||||||
return new Promise((resolve) => {
|
return Promise.resolve(this.hash[k]);
|
||||||
resolve(this.hash[k]);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
set(k: string, v: any): Promise<void> {
|
set(k: string, v: any): Promise<void> {
|
||||||
return new Promise<void>((resolve) => {
|
return Promise.resolve().then(() => this.hash[k] = v);
|
||||||
this.hash[k] = v;
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
remove(k: string): Promise<void> {
|
remove(k: string): Promise<void> {
|
||||||
return new Promise<void>((resolve) => {
|
return Promise.resolve().then(() => { delete this.hash[k]; });
|
||||||
delete this.hash[k];
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
create(k: string, v: any): Promise<void> {
|
create(k: string, v: any): Promise<void> {
|
||||||
return this.get(k).then((data) => {
|
return this.get(k).then((data) => {
|
||||||
|
|
Loading…
Reference in New Issue