mirror of https://github.com/BTCPrivate/copay.git
add merchant data in tx proposals
This commit is contained in:
parent
d4a0f5c008
commit
088a616736
|
@ -13,6 +13,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
$rootScope.title = 'Send';
|
||||
$scope.loading = false;
|
||||
$scope.error = $scope.success = null;
|
||||
var satToUnit = 1 / w.settings.unitToSatoshi;
|
||||
$scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit;
|
||||
$scope.unitToBtc = w.settings.unitToSatoshi / bitcore.util.COIN;
|
||||
|
@ -145,15 +146,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
if (w.requiresMultipleSignatures()) {
|
||||
$scope.loading = false;
|
||||
var message = 'The transaction proposal has been created';
|
||||
if (merchantData) {
|
||||
if (merchantData.pr.ca) {
|
||||
message += ' This payment protocol transaction' + ' has been verified through ' + merchantData.pr.ca + '.';
|
||||
}
|
||||
message += merchantData.pr.pd.memo;
|
||||
message += ' Merchant: ' + merchantData.pr.pd.payment_url;
|
||||
}
|
||||
$scope.success = message;
|
||||
notification.success('Success', 'The transaction proposal created');
|
||||
$scope.loadTxs();
|
||||
} else {
|
||||
w.sendTx(ntxid, function(txid, merchantData) {
|
||||
|
@ -362,7 +355,6 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
$scope.submitAddressBook = function(form) {
|
||||
if (form.$invalid) {
|
||||
scope.error = 'Please complete required fields';
|
||||
return;
|
||||
}
|
||||
var entry = {
|
||||
|
@ -409,14 +401,15 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
|
||||
$scope.send = function(ntxid, cb) {
|
||||
$scope.error = $scope.success = null;
|
||||
$scope.loading = true;
|
||||
$rootScope.txAlertCount = 0;
|
||||
w.sendTx(ntxid, function(txid, merchantData) {
|
||||
if (!txid) {
|
||||
$scope.error = 'There was an error sending the transaction';
|
||||
notification.error('Error', 'There was an error sending the transaction');
|
||||
} else {
|
||||
if (!merchantData) {
|
||||
$scope.success = 'Transaction broadcasted!';
|
||||
notification.success('Success', 'Transaction broadcasted!');
|
||||
} else {
|
||||
var message = 'Transaction ID: ' + txid;
|
||||
if (merchantData.pr.ca) {
|
||||
|
@ -424,7 +417,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
}
|
||||
message += ' Message from server: ' + merchantData.ack.memo;
|
||||
message += ' For merchant: ' + merchantData.pr.pd.payment_url;
|
||||
$scope.success = 'Transaction sent' + message;
|
||||
notification.success('Success', 'Transaction sent' + message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -435,15 +428,15 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
$scope.sign = function(ntxid) {
|
||||
$scope.loading = true;
|
||||
$scope.error = $scope.success = null;
|
||||
|
||||
try {
|
||||
w.sign(ntxid);
|
||||
} catch (e) {
|
||||
$scope.error = 'There was an error signing the transaction';
|
||||
notification.error('Error','There was an error signing the transaction');
|
||||
$scope.loadTxs();
|
||||
return;
|
||||
}
|
||||
$scope.error = undefined;
|
||||
|
||||
var p = w.txProposals.getTxProposal(ntxid);
|
||||
if (p.builder.isFullySigned()) {
|
||||
|
@ -465,16 +458,15 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
};
|
||||
|
||||
$scope.clearMerchant = function(callback) {
|
||||
var scope = $scope;
|
||||
// TODO: Find a better way of detecting
|
||||
// whether we're in the Send scope or not.
|
||||
if (!scope.sendForm || !scope.sendForm.address) {
|
||||
if (!$scope.sendForm || !$scope.sendForm.address) {
|
||||
delete $rootScope.merchant;
|
||||
$rootScope.merchantError = false;
|
||||
if (callback) callback();
|
||||
return;
|
||||
}
|
||||
var val = scope.sendForm.address.$viewValue || '';
|
||||
var val = $scope.sendForm.address.$viewValue || '';
|
||||
var uri;
|
||||
// If we're setting the domain, ignore the change.
|
||||
if ($rootScope.merchant && $rootScope.merchant.domain && val === $rootScope.merchant.domain) {
|
||||
|
@ -491,8 +483,8 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
}
|
||||
if (!uri || !uri.merchant) {
|
||||
delete $rootScope.merchant;
|
||||
scope.sendForm.amount.$setViewValue('');
|
||||
scope.sendForm.amount.$render();
|
||||
$scope.sendForm.amount.$setViewValue('');
|
||||
$scope.sendForm.amount.$render();
|
||||
if (callback) callback();
|
||||
if ($rootScope.$$phase !== '$apply' && $rootScope.$$phase !== '$digest') {
|
||||
$rootScope.$apply();
|
||||
|
@ -501,10 +493,10 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
};
|
||||
|
||||
$scope.onChanged = function() {
|
||||
var scope = $scope;
|
||||
var value = scope.address || '';
|
||||
var value = $scope.address || '';
|
||||
var uri;
|
||||
|
||||
$scope.error = $scope.success = null;
|
||||
// If we're setting the domain, ignore the change.
|
||||
if ($rootScope.merchant && $rootScope.merchant.domain && value === $rootScope.merchant.domain) {
|
||||
return;
|
||||
|
@ -528,28 +520,28 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
}
|
||||
};
|
||||
|
||||
scope.fetchingURL = uri.merchant;
|
||||
scope.loading = true;
|
||||
$scope.fetchingURL = uri.merchant;
|
||||
$scope.loading = true;
|
||||
apply();
|
||||
|
||||
var timeout = setTimeout(function() {
|
||||
timeout = null;
|
||||
scope.fetchingURL = null;
|
||||
scope.loading = false;
|
||||
scope.sendForm.address.$setViewValue('');
|
||||
scope.sendForm.address.$render();
|
||||
scope.sendForm.address.$isValid = false;
|
||||
scope.error = 'Payment server timed out';
|
||||
$scope.fetchingURL = null;
|
||||
$scope.loading = false;
|
||||
$scope.sendForm.address.$setViewValue('');
|
||||
$scope.sendForm.address.$render();
|
||||
$scope.sendForm.address.$isValid = false;
|
||||
$scope.error = 'Payment server timed out';
|
||||
apply();
|
||||
}, 10 * 1000);
|
||||
|
||||
// Payment Protocol URI (BIP-72)
|
||||
scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) {
|
||||
$scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) {
|
||||
if (!timeout) return;
|
||||
clearTimeout(timeout);
|
||||
|
||||
scope.loading = false;
|
||||
scope.fetchingURL = null;
|
||||
$scope.loading = false;
|
||||
$scope.fetchingURL = null;
|
||||
apply();
|
||||
|
||||
var balance = $rootScope.availableBalance;
|
||||
|
@ -561,28 +553,29 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
if (err) {
|
||||
if (err.amount) {
|
||||
scope.sendForm.amount.$setViewValue(+err.amount / w.settings.unitToSatoshi);
|
||||
scope.sendForm.amount.$render();
|
||||
scope.sendForm.amount.$isValid = false;
|
||||
scope.notEnoughAmount = true;
|
||||
$scope.sendForm.amount.$setViewValue(+err.amount / w.settings.unitToSatoshi);
|
||||
$scope.sendForm.amount.$render();
|
||||
$scope.sendForm.amount.$isValid = false;
|
||||
$scope.notEnoughAmount = true;
|
||||
$rootScope.merchantError = true;
|
||||
var lastAddr = scope.sendForm.address.$viewValue;
|
||||
var unregister = scope.$watch('address', function() {
|
||||
if (scope.sendForm.address.$viewValue !== lastAddr) {
|
||||
var lastAddr = $scope.sendForm.address.$viewValue;
|
||||
var unregister = $scope.$watch('address', function() {
|
||||
if ($scope.sendForm.address.$viewValue !== lastAddr) {
|
||||
delete $rootScope.merchantError;
|
||||
scope.sendForm.amount.$setViewValue('');
|
||||
scope.sendForm.amount.$render();
|
||||
$scope.sendForm.amount.$setViewValue('');
|
||||
$scope.sendForm.amount.$render();
|
||||
unregister();
|
||||
apply();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
scope.sendForm.address.$setViewValue('');
|
||||
scope.sendForm.address.$render();
|
||||
$scope.sendForm.address.$setViewValue('');
|
||||
$scope.sendForm.address.$render();
|
||||
}
|
||||
scope.sendForm.address.$isValid = false;
|
||||
$scope.sendForm.address.$isValid = false;
|
||||
copay.logger.error(err);
|
||||
|
||||
scope.error = err.message || 'Bad payment server';
|
||||
$scope.error = 'Could not fetch payment request';
|
||||
|
||||
apply();
|
||||
return;
|
||||
|
@ -593,18 +586,18 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
merchantData.unitTotal = (+merchantData.total / w.settings.unitToSatoshi) + '';
|
||||
merchantData.expiration = new Date(
|
||||
merchantData.pr.pd.expires * 1000).toISOString();
|
||||
merchantData.pr.pd.expires * 1000);
|
||||
merchantData.domain = domain;
|
||||
|
||||
$rootScope.merchant = merchantData;
|
||||
|
||||
scope.sendForm.address.$setViewValue(domain);
|
||||
scope.sendForm.address.$render();
|
||||
scope.sendForm.address.$isValid = true;
|
||||
$scope.sendForm.address.$setViewValue(domain);
|
||||
$scope.sendForm.address.$render();
|
||||
$scope.sendForm.address.$isValid = true;
|
||||
|
||||
scope.sendForm.amount.$setViewValue(merchantData.unitTotal);
|
||||
scope.sendForm.amount.$render();
|
||||
scope.sendForm.amount.$isValid = true;
|
||||
$scope.sendForm.amount.$setViewValue(merchantData.unitTotal);
|
||||
$scope.sendForm.amount.$render();
|
||||
$scope.sendForm.amount.$isValid = true;
|
||||
|
||||
// If the address changes to a non-payment-protocol one,
|
||||
// delete the `merchant` property from the scope.
|
||||
|
@ -613,9 +606,6 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
});
|
||||
|
||||
apply();
|
||||
|
||||
scope.success = 'Payment Request:' + merchantData.unitTotal +
|
||||
' ' + w.settings.unitName + '. ' + (merchantData.pr.pd.memo || '');
|
||||
});
|
||||
};
|
||||
});
|
||||
|
|
|
@ -186,7 +186,7 @@ angular.module('copayApp.directives')
|
|||
}
|
||||
|
||||
element.bind('click', function() {
|
||||
selectText(elm[0]);
|
||||
selectText(element[0]);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -362,6 +362,11 @@ angular.module('copayApp.services')
|
|||
var res = w.getPendingTxProposals();
|
||||
_.each(res.txs, function(tx) {
|
||||
root.computeAlternativeAmount(w, tx);
|
||||
if (tx.merchant) {
|
||||
var url = tx.merchant.request_url;
|
||||
var domain = /^(?:https?)?:\/\/([^\/:]+).*$/.exec(url)[1];
|
||||
tx.merchant.domain = domain;
|
||||
}
|
||||
});
|
||||
$rootScope.txps = res.txs;
|
||||
if ($rootScope.pendingTxCount < res.pendingForUs) {
|
||||
|
|
|
@ -49,9 +49,6 @@
|
|||
|
||||
|
||||
<div class="box-setup">
|
||||
<h4 class="size-12" tooltip="HOLA">http://HOLA 1234 </h4>
|
||||
|
||||
<h4 class="size-12" clip-copy="HOLA">http://HOLA 1234 </h4>
|
||||
<h1><span translate>Sign in to</span> <b>Copay</b></h1>
|
||||
<form name="loginForm" ng-submit="openProfile(loginForm)" novalidate>
|
||||
<p class="text-warning size-12"
|
||||
|
|
|
@ -20,7 +20,20 @@
|
|||
<contact address="{{out.address}}" tooltip-popup-delay="500" tooltip tooltip-placement="right" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="line-t" ng-show="!!tx.merchant">
|
||||
<div class="send-note">
|
||||
<p>
|
||||
<b>{{tx.merchant.pr.pd.memo}}</b>
|
||||
<p>
|
||||
Expires {{tx.merchant.pr.pd.expires * 1000 | amTimeAgo }}
|
||||
<span ng-show="tx.merchant.domain">[{{tx.merchant.domain}}]</span>
|
||||
<span ng-show="!!tx.merchant.pr.ca"><i class="fi-lock"></i> {{tx.merchant.pr.ca}}</span>
|
||||
<span ng-show="!tx.merchant.pr.ca" style="color:red;weight:bold;"><i class="fi-unlock"></i> Untrusted</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table class="last-transactions-content">
|
||||
<tbody>
|
||||
<tr ng-repeat="c in tx.actionList">
|
||||
|
|
|
@ -129,7 +129,7 @@
|
|||
<div class="row">
|
||||
<div class="large-12 columns" ng-show="fetchingURL">
|
||||
<h3>
|
||||
<i class="glyphicon glyphicon-refresh icon-rotate"></i>
|
||||
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
|
||||
Fetching payment
|
||||
</h3>
|
||||
<p> From {{fetchingURL}}
|
||||
|
@ -139,34 +139,24 @@
|
|||
<h3>This is a payment protocol transaction</h3>
|
||||
<div class="send-note">
|
||||
<p>
|
||||
<b translate>Send to</b>:
|
||||
{{$root.merchant.domain}}
|
||||
<b>{{$root.merchant.pr.pd.memo}}</b>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b translate>Total amount for this transaction</b>:
|
||||
<i>{{amount + defaultFee |noFractionNumber}} {{$root.wallet.settings.unitName}}</i>
|
||||
<small ng-if="isRateAvailable">
|
||||
<span class="text-gray" ng-if="isRateAvailable">
|
||||
{{ rateService.toFiat((amount + defaultFee) * unitToSatoshi, alternativeIsoCode) | noFractionNumber: 2 }} {{ alternativeIsoCode }}
|
||||
</small>
|
||||
<small>
|
||||
</span>
|
||||
<span class="text-gray" >
|
||||
(<span translate>Including fee of</span>
|
||||
{{defaultFee|noFractionNumber}}
|
||||
{{$root.wallet.settings.unitName}})
|
||||
</small>
|
||||
</p>
|
||||
</span>
|
||||
<p>
|
||||
<b translate>Server Says</b>:
|
||||
{{$root.merchant.pr.pd.memo}}
|
||||
</p>
|
||||
<p>
|
||||
<b translate>Certificate</b>:
|
||||
<span ng-show="!!$root.merchant.pr.ca">{{$root.merchant.pr.ca}}</span>
|
||||
<span ng-show="!$root.merchant.pr.ca" style="color:red;weight:bold;">Untrusted</span>
|
||||
</p>
|
||||
<p>
|
||||
<b translate>Payment Expiration</b>:
|
||||
{{$root.merchant.expiration}}
|
||||
</p>
|
||||
Expires {{$root.merchant.expiration | amTimeAgo }}
|
||||
[{{$root.merchant.domain}}]
|
||||
<span ng-show="!!$root.merchant.pr.ca"><i class="fi-lock"></i> {{$root.merchant.pr.ca}}</span>
|
||||
<span ng-show="!$root.merchant.pr.ca" style="color:red;weight:bold;"><i class="fi-unlock"></i> Untrusted</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue