Wallet/src/js/controllers/paymentUri.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'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)));
};
2015-03-06 12:00:10 -03:00
// Build bitcoinURI with querystring
this.init = function() {
var query = [];
this.bitcoinURI = $stateParams.url;
2015-03-06 12:00:10 -03:00
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);
2015-03-06 12:00:10 -03:00
if (uri && uri.address) {
var config = configService.getSync().wallet.settings;
var unitToSatoshi = config.unitToSatoshi;
var satToUnit = 1 / unitToSatoshi;
var unitName = config.unitName;
2015-03-06 12:00:10 -03:00
2015-05-15 20:10:12 -03:00
if (uri.amount) {
uri.amount = strip(uri.amount * satToUnit) + ' ' + unitName;
}
uri.network = uri.address.network.name;
2015-05-15 20:10:12 -03:00
this.uri = uri;
}
};
2015-03-06 12:00:10 -03:00
this.getWallets = function(network) {
return profileService.getWallets(network);
};
2015-03-06 12:00:10 -03:00
this.selectWallet = function(wid) {
var self = this;
2016-01-21 16:42:44 -03:00
profileService.setAndStoreFocus(wid, function() {});
2016-03-08 16:48:04 -03:00
go.walletHome();
$timeout(function() {
$rootScope.$emit('paymentUri', self.bitcoinURI);
2015-12-09 16:55:56 -03:00
}, 1000);
};
});