From 4c709ce06688f711a70697fb408ceecf7bbafb7a Mon Sep 17 00:00:00 2001 From: tony Date: Tue, 18 Jun 2019 23:55:20 +0300 Subject: [PATCH] post data with payment --- public/views/walletHome.html | 36 ++++++++++++++++++++++++++------ src/js/controllers/walletHome.js | 31 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/public/views/walletHome.html b/public/views/walletHome.html index 7d00ab7f7..ed1fedbbb 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -432,20 +432,20 @@

-
+
- Bind the payment to a condition - This payment is bound to a condition + Bind the payment to a condition... + This payment is bound to a condition...
-
+
switch to single address switch to multi-address
To bind the payment to a condition, please click the peer's address in chat
-
+
+ + +
+
+ +
+ + + + + +
+ + + Add fields + +
+
+
+
-
+
{{home.error|translate}} diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index 8e6f52ff2..797d48a2b 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -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) @@ -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); @@ -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; } @@ -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;