bwc
This commit is contained in:
parent
04fb7ba032
commit
320de62f13
348 changed files with 7745 additions and 30874 deletions
60
src/js/controllers/paymentUri.js
Normal file
60
src/js/controllers/paymentUri.js
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.controllers').controller('paymentUriController',
|
||||
function($rootScope, $stateParams, $location, $timeout, profileService, configService, lodash, bitcore, go) {
|
||||
|
||||
function strip(number) {
|
||||
return (parseFloat(number.toPrecision(12)));
|
||||
};
|
||||
|
||||
// Build bitcoinURI with querystring
|
||||
this.checkBitcoinUri = function() {
|
||||
var query = [];
|
||||
angular.forEach($location.search(), function(value, key) {
|
||||
query.push(key + "=" + value);
|
||||
});
|
||||
var queryString = query ? query.join("&") : null;
|
||||
this.bitcoinURI = $stateParams.data + ( queryString ? '?' + queryString : '');
|
||||
|
||||
var URI = bitcore.URI;
|
||||
var isUriValid = URI.isValid(this.bitcoinURI);
|
||||
if (!URI.isValid(this.bitcoinURI)) {
|
||||
this.error = true;
|
||||
return;
|
||||
}
|
||||
var uri = new URI(this.bitcoinURI);
|
||||
|
||||
if (uri && uri.address) {
|
||||
var config = configService.getSync().wallet.settings;
|
||||
var unitToSatoshi = config.unitToSatoshi;
|
||||
var satToUnit = 1 / unitToSatoshi;
|
||||
var unitName = config.unitName;
|
||||
|
||||
uri.amount = strip(uri.amount * satToUnit) + ' ' + unitName;
|
||||
return uri;
|
||||
}
|
||||
};
|
||||
|
||||
this.getWallets = function() {
|
||||
if (!profileService.profile) return;
|
||||
var ret = lodash.map(profileService.profile.credentials, function(c) {
|
||||
return {
|
||||
m: c.m,
|
||||
n: c.n,
|
||||
name: c.walletName,
|
||||
id: c.walletId,
|
||||
};
|
||||
});
|
||||
return lodash.sortBy(ret, 'walletName');
|
||||
};
|
||||
|
||||
this.selectWallet = function(wid) {
|
||||
var self = this;
|
||||
if (wid != profileService.focusedClient.credentials.walletId) {
|
||||
profileService.setAndStoreFocus(wid, function() {});
|
||||
}
|
||||
go.send();
|
||||
$timeout(function() {
|
||||
$rootScope.$emit('paymentUri', self.bitcoinURI);
|
||||
}, 100);
|
||||
};
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue