Skip to content

Commit

Permalink
post data with payment
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyofbyteball committed Jun 18, 2019
1 parent 7f9c51b commit 4c709ce
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
36 changes: 30 additions & 6 deletions public/views/walletHome.html
Original file line number Diff line number Diff line change
Expand Up @@ -432,20 +432,20 @@ <h4 class="title m0">
<i class="icon-wallet size-18" style="margin-right: -3px;vertical-align: baseline;"></i>
</a>
</div>
<div ng-if="home.deviceAddressIsKnown()" style="font-size: 11px; font-weight: bold; margin-top: -1.5rem; margin-bottom: 1.5rem;">
<div ng-if="home.deviceAddressIsKnown()" style="font-size: 11px; font-weight: bold; margin-top: -1.5rem; margin-bottom: 1rem;">
<a ng-click="home.openBindModal()">
<span ng-if="!home.binding" translate>Bind the payment to a condition</span>
<span ng-if="home.binding" translate>This payment is bound to a condition</span>
<span ng-if="!home.binding" translate>Bind the payment to a condition...</span>
<span ng-if="home.binding" translate>This payment is bound to a condition...</span>
</a>
</div>
<div ng-if="!index.arrBalances[index.assetIndex].is_private && !home.blockUx && !home.lockAddress && home.canSendExternalPayment()" style="font-size: 11px; font-weight: bold; margin-top: -1.5rem; margin-bottom: 1.5rem; float: right;">
<div ng-if="!index.arrBalances[index.assetIndex].is_private && !home.blockUx && !home.lockAddress && home.canSendExternalPayment()" style="font-size: 11px; font-weight: bold; margin-top: -1.5rem; margin-bottom: 1rem; float: right;">
<a ng-click="home.lockAmount = home.send_multiple = !home.send_multiple" class="text-gray" style="border-bottom: 1px dashed grey;">
<span ng-if="home.send_multiple" translate>switch to single address</span>
<span ng-if="!home.send_multiple" translate ng-click="home.resetForm(sendPaymentForm)">switch to multi-address</span>
</a>
</div>
<div id="binding-drop" class="f-dropdown" data-dropdown-content style="padding: 10px;" translate>To bind the payment to a condition, please click the peer's address in chat</div>
<div ng-if="!home.deviceAddressIsKnown()" style="font-size: 11px; font-weight: bold; margin-top: -1.5rem; margin-bottom: 1.5rem">
<div ng-if="!home.deviceAddressIsKnown()" style="font-size: 11px; font-weight: bold; margin-top: -1.5rem; margin-bottom: 1rem">
<a dropdown-toggle="#binding-drop" data-options="align:top">
<span translate class="text-gray">Bind the payment to a condition</span>
</a>
Expand Down Expand Up @@ -477,6 +477,30 @@ <h4 class="title m0">
</div>
</div>

<div class="row" ng-if="home.feedvaluespairs.length === 0">
<div class="large-12 columns m30b">
<a style="font-size: 11px; font-weight: bold; margin-top: -1.5rem; margin-bottom: 1rem;" ng-click="home.feedvaluespairs.push({})" translate>Also send data...</a>
</div>
</div>

<div class="row" ng-if="home.feedvaluespairs.length > 0">
<div class="large-12 columns m30b m10t">
<label translate>Data to be posted with the payment:</label>
<div>
<span ng-repeat="pair in home.feedvaluespairs">
<input type="text" ng-model="pair.name" placeholder="{{'Field'|translate}}" class="datafeed_input" ng-required="true" ng-maxlength="64" maxlength="64" >
<input type="text" ng-model="pair.value" placeholder="{{'Value'|translate}}" class="datafeed_input" ng-required="true" ng-maxlength="64" maxlength="64">
<a ng-show="$last" ng-click="home.feedvaluespairs.splice(home.feedvaluespairs.length-1)"><i class="fi-minus size-18 m10r" style="vertical-align: middle;"></i></a>
</span>
<div class="clear"></div>
<a ng-click="home.feedvaluespairs.push({})" style="padding:10px 0;" ng-show="home.feedvaluespairs.length < 20">
<i class="fi-plus size-18 m10r" style="vertical-align: middle;"></i>
<span class="text-close size-12" translate>Add fields</span>
</a>
</div>
</div>
</div>

<div class="" ng-show="index.m < index.n && index.m > 1">
<div class="large-12 medium-12">
<label>
Expand Down Expand Up @@ -518,7 +542,7 @@ <h4 class="title m0">
</div>
<div ng-show="home.shownForm=='data' && index.isSingleAddress">
<div class="large-12 large-centered columns">
<form name="sendDataForm" ng-submit="home.submitData()" ng-disabled="home.blockUx || home.onGoingProcess" novalidate ng-init="home.feedvaluespairs=[{}]">
<form name="sendDataForm" ng-submit="home.submitData()" ng-disabled="home.blockUx || home.onGoingProcess" novalidate dont-ng-init="home.feedvaluespairs=[{}]">
<div class="box-notification" ng-show="home.error" ng-click="home.resetError()">
<span class="text-warning">
{{home.error|translate}}
Expand Down
31 changes: 31 additions & 0 deletions src/js/controllers/walletHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,30 @@ angular.module('copayApp.controllers')
return;
}

var data_payload = {};
var errored = false;
$scope.home.feedvaluespairs.forEach(function(pair) {
if (data_payload[pair.name]) {
self.setSendError("All keys must be unique");
errored = true;
return;
}
data_payload[pair.name] = pair.value;
});
if (errored)
return;
var objDataMessage;
if (Object.keys(data_payload).length > 0) {
var objectHash = require('ocore/object_hash.js');
var storage = require('ocore/storage.js');
objDataMessage = {
app: 'data',
payload_location: "inline",
payload_hash: objectHash.getBase64Hash(data_payload, storage.getMinRetrievableMci() >= constants.timestampUpgradeMci),
payload: data_payload
};
}

if (fc.isPrivKeyEncrypted()) {
profileService.unlockFC(null, function(err) {
if (err)
Expand Down Expand Up @@ -1162,6 +1186,8 @@ angular.module('copayApp.controllers')
});
};
}
if (objDataMessage)
opts.messages = [objDataMessage];
fc.sendMultiPayment(opts, function(err, unit, mnemonics) {
// if multisig, it might take very long before the callback is called
indexScope.setOngoingProcess(gettext('sending'), false);
Expand Down Expand Up @@ -1249,10 +1275,14 @@ angular.module('copayApp.controllers')
this.lockAmount = this.send_multiple = false;
if ($scope.assetIndexSelectorValue < 0) {
this.shownForm = 'data';
if (!this.feedvaluespairs || this.feedvaluespairs.length === 0)
this.feedvaluespairs = [{}];
}
else {
$scope.index.assetIndex = $scope.assetIndexSelectorValue;
this.shownForm = 'payment';
if (!this.feedvaluespairs || this.feedvaluespairs.length > 0 && (!this.feedvaluespairs[0].name || !this.feedvaluespairs[0].value))
this.feedvaluespairs = [];
}
$scope.mtab = $scope.index.arrBalances[$scope.index.assetIndex] && $scope.index.arrBalances[$scope.index.assetIndex].is_private && !this.lockAddress ? 2 : 1;
}
Expand Down Expand Up @@ -1633,6 +1663,7 @@ angular.module('copayApp.controllers')

this._amount = this._address = null;
this.bSendAll = false;
this.feedvaluespairs = [];

var form = $scope.sendPaymentForm;
var self = this;
Expand Down

0 comments on commit 4c709ce

Please sign in to comment.