Wallet/src/js/controllers/paymentUri.js
Matias Alejo Garcia a8cf875def
rm go
2016-08-19 13:07:18 -03:00

55 lines
1.6 KiB
JavaScript

'use strict';
angular.module('copayApp.controllers').controller('paymentUriController',
function($rootScope, $scope, $stateParams, $location, $timeout, profileService, configService, lodash, bitcore, $state) {
function strip(number) {
return (parseFloat(number.toPrecision(12)));
};
// Build bitcoinURI with querystring
this.init = function() {
var query = [];
this.bitcoinURI = $stateParams.url;
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;
if (uri.amount) {
uri.amount = strip(uri.amount * satToUnit) + ' ' + unitName;
}
uri.network = uri.address.network.name;
this.uri = uri;
}
};
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);
})
});
};
this.selectWallet = function(wid) {
var self = this;
profileService.setAndStoreFocus(wid, function() {});
$state.go('tabs.home');
$timeout(function() {
$rootScope.$emit('paymentUri', self.bitcoinURI);
}, 1000);
};
});