2015-03-06 12:00:10 -03:00
|
|
|
'use strict';
|
2015-04-23 16:17:18 -03:00
|
|
|
angular.module('copayApp.controllers').controller('paymentUriController',
|
2016-09-02 16:05:25 -03:00
|
|
|
function($rootScope, $scope, $stateParams, $location, $timeout, $ionicHistory, profileService, configService, lodash, bitcore, $state) {
|
2015-04-23 16:17:18 -03:00
|
|
|
function strip(number) {
|
|
|
|
|
return (parseFloat(number.toPrecision(12)));
|
|
|
|
|
};
|
2015-03-06 12:00:10 -03:00
|
|
|
|
2015-04-23 16:17:18 -03:00
|
|
|
// Build bitcoinURI with querystring
|
2016-06-11 13:52:44 -03:00
|
|
|
this.init = function() {
|
2015-04-23 16:17:18 -03:00
|
|
|
var query = [];
|
2016-06-11 13:52:44 -03:00
|
|
|
this.bitcoinURI = $stateParams.url;
|
2015-03-06 12:00:10 -03:00
|
|
|
|
2015-04-23 16:17:18 -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
|
|
|
|
2015-04-23 16:17:18 -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;
|
|
|
|
|
}
|
2015-04-23 16:17:18 -03:00
|
|
|
uri.network = uri.address.network.name;
|
2015-05-15 20:10:12 -03:00
|
|
|
this.uri = uri;
|
2015-04-23 16:17:18 -03:00
|
|
|
}
|
|
|
|
|
};
|
2015-03-06 12:00:10 -03:00
|
|
|
|
2015-04-23 16:17:18 -03:00
|
|
|
this.getWallets = function(network) {
|
2016-07-22 12:21:07 -03:00
|
|
|
|
|
|
|
|
$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-04-23 16:17:18 -03:00
|
|
|
};
|
2015-03-06 12:00:10 -03:00
|
|
|
|
2015-04-23 16:17:18 -03:00
|
|
|
this.selectWallet = function(wid) {
|
|
|
|
|
var self = this;
|
2016-01-21 16:42:44 -03:00
|
|
|
profileService.setAndStoreFocus(wid, function() {});
|
2016-09-23 12:42:33 -03:00
|
|
|
$ionicHistory.removeBackView();
|
2016-08-19 13:07:18 -03:00
|
|
|
$state.go('tabs.home');
|
2015-04-23 16:17:18 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
$rootScope.$emit('paymentUri', self.bitcoinURI);
|
2015-12-09 16:55:56 -03:00
|
|
|
}, 1000);
|
2015-04-23 16:17:18 -03:00
|
|
|
};
|
|
|
|
|
});
|