mirror of https://github.com/BTCPrivate/copay.git
bitcoin: working. paypro todo
This commit is contained in:
parent
2fe6ec4c6a
commit
80e22c59a0
|
@ -5,7 +5,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
// Global go. This should be in a better place TODO
|
||||
// We dont do a 'go' directive, to use the benefits of ng-touch with ng-click
|
||||
$rootScope.go = function (path) {
|
||||
go.go(path);
|
||||
go.path(path);
|
||||
};
|
||||
|
||||
var _credentials, _firstpin;
|
||||
|
|
|
@ -30,12 +30,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
$scope.isMobile = isMobile.any();
|
||||
|
||||
if ($rootScope.pendingPayment) {
|
||||
var value;
|
||||
var pp = $rootScope.pendingPayment;
|
||||
var amount = (pp.data && pp.data.amount) ?
|
||||
pp.data.amount * 100000000 * satToUnit : 0;
|
||||
$scope.setForm(pp.address, amount, pp.data.message)
|
||||
_onAddressChange(pp);
|
||||
$scope.setFromUri($rootScope.pendingPayment)
|
||||
}
|
||||
|
||||
$scope.setInputs();
|
||||
|
@ -95,8 +90,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
return this._address;
|
||||
},
|
||||
set: function(newValue) {
|
||||
this._address = newValue;
|
||||
_onAddressChange();
|
||||
this._address = $scope.onAddressChange(newValue);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
|
@ -104,10 +98,10 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
};
|
||||
|
||||
$scope.setScanner = function() {
|
||||
navigator.getUserMedia = navigator.getUserMedia ||
|
||||
navigator.webkitGetUserMedia || navigator.mozGetUserMedia ||
|
||||
navigator.getUserMedia = navigator.getUserMedia ||
|
||||
navigator.webkitGetUserMedia || navigator.mozGetUserMedia ||
|
||||
navigator.msGetUserMedia;
|
||||
window.URL = window.URL || window.webkitURL ||
|
||||
window.URL = window.URL || window.webkitURL ||
|
||||
window.mozURL || window.msURL;
|
||||
|
||||
if (!window.cordova && !navigator.getUserMedia)
|
||||
|
@ -343,16 +337,21 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
$scope.setForm = function(to, amount, comment) {
|
||||
var form = $scope.sendForm;
|
||||
form.address.$setViewValue(merchantData.domain);
|
||||
form.address.$setViewValue(to);
|
||||
form.address.$render();
|
||||
form.address.$isValid = true;
|
||||
$scope.lockAddress = true;
|
||||
|
||||
form.amount.$setViewValue(merchantData.unitTotal);
|
||||
form.amount.$render();
|
||||
form.amount.$isValid = true;
|
||||
if (amount) {
|
||||
form.amount.$setViewValue(amount);
|
||||
form.amount.$render();
|
||||
form.amount.$isValid = true;
|
||||
$scope.lockAmount = true;
|
||||
}
|
||||
|
||||
if (comment)
|
||||
$scope.commentText = comment;
|
||||
if (comment) {
|
||||
form.commentText.$setViewValue(comment);
|
||||
}
|
||||
};
|
||||
|
||||
$scope.cancelSend = function(error) {
|
||||
|
@ -388,50 +387,18 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
};
|
||||
|
||||
|
||||
$scope.setFromPayPro = function(uri) {
|
||||
console.log('[send.js.391:uri:]', uri); //TODO
|
||||
|
||||
var _onAddressChange = function(pp) {
|
||||
var value;
|
||||
value = value || $scope.address || '';
|
||||
var uri;
|
||||
|
||||
$scope.error = $scope.success = null;
|
||||
|
||||
if (value.indexOf('bitcoin:') === 0) {
|
||||
uri = new bitcore.BIP21(value);
|
||||
} else if (/^https?:\/\//.test(value)) {
|
||||
uri = {
|
||||
data: {
|
||||
merchant: value
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!uri || !uri.data.merchant) {
|
||||
if (uri && uri.address) {
|
||||
var amount = (uri.data && uri.data.amount) ? uri.data.amount * 100000000 * satToUnit : 0;
|
||||
var address = uri.address.data;
|
||||
if (amount && address) {
|
||||
$scope.isPayUri = {fixedAmount: true} ;
|
||||
}
|
||||
$timeout(function() {
|
||||
$scope.amount = amount;
|
||||
}, 1000);
|
||||
$scope.commentText = uri.data.message;
|
||||
$scope.address = address;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.fetchingURL = uri.data.merchant;
|
||||
$scope.fetchingURL = uri;
|
||||
$scope.loading = true;
|
||||
|
||||
|
||||
var balance = w.balanceInfo.availableBalance;
|
||||
var available = +(balance * unitToSat).toFixed(0);
|
||||
|
||||
// Payment Protocol URI (BIP-72)
|
||||
$scope.wallet.fetchPaymentRequest({
|
||||
url: uri.data.merchant
|
||||
w.fetchPaymentRequest({
|
||||
url: uri
|
||||
}, function(err, merchantData) {
|
||||
$scope.loading = false;
|
||||
$scope.fetchingURL = null;
|
||||
|
@ -442,18 +409,53 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
} else {
|
||||
$scope.cancelSend(err.toString());
|
||||
}
|
||||
|
||||
} else if (merchantData && available < +merchantData.total) {
|
||||
$scope.cancelSend(err.toString('Insufficient funds'));
|
||||
$scope.cancelSend('Insufficient funds');
|
||||
} else {
|
||||
$scope.setForm(merchantData.domain, merchantData.unitTotal)
|
||||
}
|
||||
$timeout(function() {
|
||||
$scope.$digest();
|
||||
}, 1);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.setFromUri = function(uri) {
|
||||
var form = $scope.sendForm;
|
||||
|
||||
var parsed = new bitcore.BIP21(uri);
|
||||
if (!parsed.isValid() || !parsed.address.isValid()) {
|
||||
$scope.error = 'Invalid bitcoin URL';
|
||||
form.address.$isValid = false;
|
||||
return uri;
|
||||
};
|
||||
|
||||
var addr = parsed.address.toString();
|
||||
|
||||
console.log('[send.js.430:parsed:]',addr,parsed.data); //TODO
|
||||
|
||||
if (parsed.data.merchant)
|
||||
return $scope.setFromPayPro(parsed.data.merchant);
|
||||
|
||||
var amount = (parsed.data && parsed.data.amount) ?
|
||||
parsed.data.amount * 100000000 * satToUnit : 0;
|
||||
|
||||
$scope.setForm(addr, amount, parsed.data.message, true);
|
||||
return addr;
|
||||
};
|
||||
|
||||
$scope.onAddressChange = function(value) {
|
||||
var addr;
|
||||
console.log('[send.js.391:value:]', value); //TODO
|
||||
|
||||
$scope.error = $scope.success = null;
|
||||
if (!value) return '';
|
||||
|
||||
if (value.indexOf('bitcoin:') === 0) {
|
||||
return $scope.setFromUri(value);
|
||||
} else if (/^https?:\/\//.test(value)) {
|
||||
return $scope.setFromPayPro(value);
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
$scope.openAddressBook = function() {
|
||||
var modalInstance = $modal.open({
|
||||
templateUrl: 'views/modals/address-book.html',
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
</div>
|
||||
|
||||
<div class="input">
|
||||
<input type="text" id="address" name="address" ng-disabled="loading || isPayUri"
|
||||
<input type="text" id="address" name="address" ng-disabled="loading || lockAddress"
|
||||
placeholder="{{'Bitcoin address'|translate}}" ng-model="address" valid-address required>
|
||||
<i class="fi-address-book"></i>
|
||||
<div ng-hide="showScanner || disableScanner">
|
||||
|
@ -87,7 +87,7 @@
|
|||
<div class="small-9 columns">
|
||||
<div class="input">
|
||||
<input type="number" id="amount"
|
||||
ng-disabled="loading || isPayUri.fixedAmount"
|
||||
ng-disabled="loading || lockAmount"
|
||||
name="amount" placeholder="{{'Amount'|translate}}" ng-model="amount"
|
||||
ng-minlength="0.00000001" ng-maxlength="10000000000" valid-amount required
|
||||
autocomplete="off">
|
||||
|
@ -112,7 +112,7 @@
|
|||
<div class="small-9 columns">
|
||||
<div class="input">
|
||||
<input type="number" id="alternative"
|
||||
ng-disabled="loading || !isRateAvailable ||isPayUri"
|
||||
ng-disabled="loading || !isRateAvailable || lockAmount"
|
||||
name="alternative" placeholder="{{'Amount'|translate}}" ng-model="alternative" requiredautocomplete="off">
|
||||
<i class="icon-usd"></i>
|
||||
</div>
|
||||
|
@ -173,10 +173,10 @@
|
|||
|
||||
<div class="row">
|
||||
<div class="large-6 medium-6 small-6 columns text-left">
|
||||
<a class="button tiny secondary m0" title="Address book" ng-hide="!!$root.merchant || isPayUri" ng-click="openAddressBook()">
|
||||
<a class="button tiny secondary m0" title="Address book" ng-hide="!!$root.merchant || lockAddress" ng-click="openAddressBook()">
|
||||
<i class="fi-address-book"></i> Address book
|
||||
</a>
|
||||
<a ng-click="cancelSend(sendForm)" class="button warning m0" ng-show="!!$root.merchant || isPayUri">
|
||||
<a ng-click="cancelSend(sendForm)" class="button warning m0" ng-show="!!$root.merchant || lockAddress">
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue