Merge branch 'wallet/sprint/18' into wallet/task/399
This commit is contained in:
commit
1d9efcca06
36 changed files with 808 additions and 157 deletions
24
src/js/services/clipboardService.js
Normal file
24
src/js/services/clipboardService.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('clipboardService', function ($http, $log, platformInfo, nodeWebkitService, gettextCatalog, ionicToast, clipboard) {
|
||||
var root = {};
|
||||
|
||||
root.copyToClipboard = function (data) {
|
||||
if (!data) return;
|
||||
|
||||
$log.debug("Copy '"+data+"' to clipboard");
|
||||
if (platformInfo.isCordova) {
|
||||
cordova.plugins.clipboard.copy(data);
|
||||
} else if (platformInfo.isNW) {
|
||||
nodeWebkitService.writeToClipboard(data);
|
||||
} else if (clipboard.supported) {
|
||||
clipboard.copyText(data);
|
||||
} else {
|
||||
// No supported
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
@ -107,7 +107,7 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
|||
enabled: false,
|
||||
},
|
||||
|
||||
soundsEnabled: false,
|
||||
soundsEnabled: true,
|
||||
|
||||
log: {
|
||||
filter: 'debug',
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
_completeInitialization(status, callback);
|
||||
});
|
||||
} else {
|
||||
isAvailable = true; // XX SP: Availability can change after permissions are granted after being denied.
|
||||
_completeInitialization(status, callback);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.services')
|
||||
.factory('storageService', function(appConfigService, logHeader, fileStorageService, localStorageService, sjcl, $log, lodash, platformInfo, secureStorageService, $timeout) {
|
||||
.factory('storageService', function(appConfigService, logHeader, fileStorageService, localStorageService, sjcl, $log, lodash, platformInfo, $timeout) {
|
||||
|
||||
var root = {};
|
||||
var storage;
|
||||
|
|
@ -121,11 +121,7 @@ angular.module('copayApp.services')
|
|||
|
||||
root.storeProfile = function(profile, cb) {
|
||||
var profileString = profile.toObj();
|
||||
if (platformInfo.isNW) {
|
||||
storage.set('profile', profileString, cb);
|
||||
} else {
|
||||
secureStorageService.set('profile', profileString, cb);
|
||||
}
|
||||
storage.set('profile', profileString, cb);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -205,48 +201,19 @@ angular.module('copayApp.services')
|
|||
* @param {getProfileCallback} cb
|
||||
*/
|
||||
root.getProfile = function(cb) {
|
||||
if (platformInfo.isNW) {
|
||||
storage.get('profile', function(getErr, getStr) {
|
||||
_onOldProfileRetrieved(getErr, getStr, cb);
|
||||
});
|
||||
return
|
||||
}
|
||||
|
||||
secureStorageService.get('profile', function(secureErr, secureStr) {
|
||||
var secureProfile;
|
||||
var oldProfile;
|
||||
|
||||
if (secureErr) {
|
||||
return cb(secureErr, null);
|
||||
storage.get('profile', function(getErr, getStr) {
|
||||
if (getErr) {
|
||||
cb(getErr, null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (secureStr) {
|
||||
try {
|
||||
secureProfile = Profile.fromString(secureStr);
|
||||
$log.debug('profile: ' + JSON.stringify(secureProfile));
|
||||
} catch (e) {
|
||||
$log.error(e);
|
||||
return cb(e, null);
|
||||
}
|
||||
if (!getStr) {
|
||||
cb(null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
storage.get('profile', function(getErr, getStr) {
|
||||
_onOldProfileRetrieved(getErr, getStr, function(oldErr, oldProfile){
|
||||
if (oldErr) {
|
||||
return cb(oldErr, null);
|
||||
}
|
||||
|
||||
if (!oldProfile) {
|
||||
if (secureProfile) {
|
||||
return cb(null, secureProfile);
|
||||
} else {
|
||||
// No profiles found. No errors either.
|
||||
return cb(null, null);
|
||||
}
|
||||
}
|
||||
_migrateProfiles(oldProfile, secureProfile, cb);
|
||||
});
|
||||
});
|
||||
|
||||
var profile = Profile.fromString(getStr);
|
||||
cb(null, profile);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -72,11 +72,19 @@ angular.module('copayApp.services').factory('txFormatService', function($filter,
|
|||
var config = configService.getSync().wallet.settings;
|
||||
|
||||
var val = function() {
|
||||
var v1 = parseFloat((rateService.toFiat(satoshis, config.alternativeIsoCode, coin)).toFixed(2));
|
||||
v1 = $filter('formatFiatAmount')(v1);
|
||||
var fiatAmount = rateService.toFiat(satoshis, config.alternativeIsoCode, coin);
|
||||
var roundedStr = fiatAmount.toFixed(2);
|
||||
var roundedNum = parseFloat(roundedStr);
|
||||
var subcent = roundedNum === 0 && fiatAmount > 0;
|
||||
var lessThanPrefix = '';
|
||||
if (subcent) {
|
||||
roundedNum = 0.01;
|
||||
lessThanPrefix = '< ';
|
||||
}
|
||||
var v1 = $filter('formatFiatAmount')(roundedNum);
|
||||
if (!v1) return null;
|
||||
|
||||
return v1 + ' ' + config.alternativeIsoCode;
|
||||
return lessThanPrefix + v1 + ' ' + config.alternativeIsoCode;
|
||||
};
|
||||
|
||||
// Async version
|
||||
|
|
|
|||
68
src/js/services/txFormatService.spec.js
Normal file
68
src/js/services/txFormatService.spec.js
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
describe('txFormatService', function(){
|
||||
var configServiceMock,
|
||||
rateServiceMock,
|
||||
txFormatService;
|
||||
|
||||
beforeEach(function(){
|
||||
module('ngLodash');
|
||||
module('bwcModule');
|
||||
module('copayApp.filters');
|
||||
module('copayApp.services');
|
||||
|
||||
configServiceMock = {
|
||||
getSync: jasmine.createSpy()
|
||||
};
|
||||
|
||||
rateServiceMock = {
|
||||
isAvailable: jasmine.createSpy(),
|
||||
toFiat: jasmine.createSpy()
|
||||
};
|
||||
|
||||
module(function($provide) {
|
||||
$provide.value('configService', configServiceMock);
|
||||
$provide.value('rateService', rateServiceMock);
|
||||
});
|
||||
|
||||
inject(function($injector){
|
||||
txFormatService = $injector.get('txFormatService');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('formatAlternativeStr 0.49 cents.', function() {
|
||||
|
||||
configServiceMock.getSync.and.returnValue({
|
||||
wallet: {
|
||||
settings: {
|
||||
alternativeIsoCode: 'USD'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
rateServiceMock.isAvailable.and.returnValue(true);
|
||||
rateServiceMock.toFiat.and.returnValue(0.00499);
|
||||
|
||||
var formatted = txFormatService.formatAlternativeStr('bch', 123);
|
||||
|
||||
expect(formatted).toBe('< 0.01 USD');
|
||||
});
|
||||
|
||||
it('formatAlternativeStr 0.5 cents.', function() {
|
||||
|
||||
configServiceMock.getSync.and.returnValue({
|
||||
wallet: {
|
||||
settings: {
|
||||
alternativeIsoCode: 'USD'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
rateServiceMock.isAvailable.and.returnValue(true);
|
||||
rateServiceMock.toFiat.and.returnValue(0.005);
|
||||
|
||||
var formatted = txFormatService.formatAlternativeStr('bch', 123);
|
||||
|
||||
expect(formatted).toBe('0.01 USD');
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue