From 6be97e533ce5bdd9ea0826a69a899f99f227e0e6 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Wed, 1 Mar 2017 17:35:32 +0800 Subject: [PATCH] pad payment_id with zeros if too short to 64 characters --- html/js/controllers/send_coins.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/html/js/controllers/send_coins.js b/html/js/controllers/send_coins.js index e9a1890..81baa9d 100644 --- a/html/js/controllers/send_coins.js +++ b/html/js/controllers/send_coins.js @@ -188,6 +188,14 @@ thinwalletCtrls.controller('SendCoinsCtrl', function($scope, $http, $q, AccountS })(deferred, target); } + var strpad = function(padString, length) + { // from http://stackoverflow.com/a/10073737/248823 + var str = this; + while (str.length < length) + str = padString + str; + return str; + }; + // Transaction will need at least 1KB fee (13KB for RingCT) var feePerKB = new JSBigInt(config.feePerKB); @@ -209,10 +217,23 @@ thinwalletCtrls.controller('SendCoinsCtrl', function($scope, $http, $q, AccountS $scope.error = "You need to enter a valid destination"; return; } - if (payment_id && (payment_id.length !== 64 || !(/^[0-9a-fA-F]{64}$/.test(payment_id)))) { - $scope.submitting = false; - $scope.error = "The payment ID you've entered is not valid"; - return; + if (payment_id) + { + if (payment_id.length <= 64 && /^[0-9a-fA-F]+$/.test(payment_id)) + { + // if payment id is shorter, but has correct number, just + // pad it to required length with zeros + payment_id = strpad("0", 64); + } + + // now double check if ok, when we padded it + if (payment_id.length !== 64 || !(/^[0-9a-fA-F]{64}$/.test(payment_id))) + { + $scope.submitting = false; + $scope.error = "The payment ID you've entered is not valid"; + return; + } + } if (realDsts.length === 1) {//multiple destinations aren't supported by MyMonero, but don't include integrated ID anyway (possibly should error in the future) var decode_result = cnUtil.decode_address(realDsts[0].address);