Wallet/src/js/controllers/paymentUri.js

55 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'use strict';
angular.module('copayApp.controllers').controller('paymentUriController',
2016-08-19 13:07:18 -03:00
function($rootScope, $scope, $stateParams, $location, $timeout, profileService, configService, lodash, bitcore, $state) {
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) {
$scope.wallets = [];
lodash.forEach(profileService.getWallets(network), function(w) {
var client = profileService.getClient(w.id);
profileService.isReady(client, function(err) {
if (err) return;
$scope.wallets.push(w);
})
});
};
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-08-19 13:07:18 -03:00
$state.go('tabs.home');
$timeout(function() {
$rootScope.$emit('paymentUri', self.bitcoinURI);
2015-12-09 16:55:56 -03:00
}, 1000);
};
});