Skip to content

Commit 01a9299

Browse files
author
raxy
committedMar 4, 2018
jsonify msg if needed
1 parent 1459989 commit 01a9299

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed
 

‎js/send.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* I am IotaMessageSender/js/send.js from https://github.com/alero3/IotaMessageSender.git
2-
modded by raxy on 03fev18
2+
modded by raxy
33
wallet server parametrable, changed labels, add #transfers : updated by getAccountInfo()
4+
04mar ensure $("#message").val() is a json or fix it
45
*/
56
var seed;
67
var balance = 0;
@@ -157,10 +158,18 @@ $(document).ready(function() {
157158
var value = parseInt($("#value").val());
158159
var address = $("#address").val();
159160
var message = $("#message").val();
161+
var iotaMsg;
160162
console.log ("Value =", value);
161163
if( value == null || value == NaN || value < 0 || !message)
162164
return
163-
var iotaMsg = JSON.stringify( { "name":"", "message": message}); // mandatory object!
165+
try {
166+
var tmp = JSON.parse(message);
167+
iotaMsg = message;
168+
}
169+
catch (e) {
170+
// message probably not json, make it stringified json!
171+
iotaMsg = JSON.stringify({ "message": message});
172+
}
164173
console.log("value, message OK");
165174
if (value > balance) {
166175
var html = '<div class="alert alert-warning alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Value too high!</strong> You have specified a too high value.</div>'
@@ -172,8 +181,8 @@ $(document).ready(function() {
172181
// Convert the user iotaMsg into trytes
173182
// In case the user supplied non-ASCII characters we throw an error
174183
try {
175-
console.log("Sending Message: ", message);
176-
var messageTrytes = iota.utils.toTrytes( message);
184+
console.log("Sending Message: ", iotaMsg);
185+
var messageTrytes = iota.utils.toTrytes( iotaMsg);
177186
console.log("Message converted into trytes: ", messageTrytes);
178187
// We display the loading screen
179188
$("#send__waiting").css("display", "block");

0 commit comments

Comments
 (0)
Please sign in to comment.