From e6709f03aae54538384c6f054a86db6c091a7317 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 5 Feb 2020 17:55:25 +0100 Subject: [PATCH] Add trim history RPC command --- www/common/common-ui-elements.js | 5 +++-- www/common/outer/history.js | 17 ++++------------- www/common/pinpad.js | 11 +++++++++++ www/settings/inner.js | 7 +++---- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 68c33cdd0..4520e68fe 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -739,6 +739,7 @@ define([ if (data.rtChannel) { chan.push(data.rtChannel); } if (data.lastVersion) { chan.push(Hash.hrefToHexChannelId(data.lastVersion)); } var history = common.makeUniversal('history'); + var trimChannels = []; NThen(function (waitFor) { chan.forEach(function (c) { common.getFileSize(c, waitFor(function (e, _bytes) { @@ -758,6 +759,7 @@ define([ }, waitFor(function (obj) { if (obj && obj.error) { return; } historyBytes = obj.size; + trimChannels = obj.channels; })); }).nThen(function () { if (bytes === 0) { return void cb(void 0, $d); } @@ -806,7 +808,7 @@ define([ spinner.spin(); history.execCommand('TRIM_HISTORY', { pad: true, - channels: chan.filter(function (c) { return c.length === 32; }), + channels: trimChannels, teamId: typeof(owned) === "number" && owned }, function (obj) { if (obj && obj.error) { @@ -814,7 +816,6 @@ define([ // XXX what are the possible errors? return; } - // TODO: obj.warning? spinner.hide(); $(size).append(h('div.alert.alert-success', Messages.trimHistory_success || 'ok')); // XXX }); diff --git a/www/common/outer/history.js b/www/common/outer/history.js index 43860decb..1860e38c8 100644 --- a/www/common/outer/history.js +++ b/www/common/outer/history.js @@ -163,13 +163,14 @@ define([ size += obj.size; res.push({ channel: channel, - lastKnownHash: obj.hash + hash: obj.hash }); })); }); }).nThen(function () { cb({ warning: warning.length ? warning : undefined, + channels: res, size: size }); }); @@ -185,24 +186,14 @@ define([ var warning = []; - // If account trim history, get the correct channels here - if (data.account) { - channels = getAccountChannels(ctx); - } - nThen(function (waitFor) { - channels.forEach(function (chan) { - chan = chan; // XXX - waitFor = waitFor; // XXX - /* - rpc.trimHistory(chan, waitFor(function (err) { + channels.forEach(function (obj) { + rpc.trimHistory(obj, waitFor(function (err) { if (err) { - chanWarning = true; warning.push(err); return; } })); - */ // XXX TODO }); }).nThen(function () { // Only one channel and warning: error diff --git a/www/common/pinpad.js b/www/common/pinpad.js index e9ecbb7f3..2841656bc 100644 --- a/www/common/pinpad.js +++ b/www/common/pinpad.js @@ -125,6 +125,17 @@ var factory = function (Util, Rpc) { }); }; + exp.trimHistory = function (data, _cb) { + var cb = Util.once(Util.mkAsync(_cb)); + if (typeof(data) !== 'object' || !data.channel || !data.hash) { + return void cb('INVALID_ARGUMENTS'); + } + rpc.send('TRIM_HISTORY', data, function (e) { + if (e) { return cb(e); } + cb(); + }); + }; + exp.clearOwnedChannel = function (channel, cb) { if (typeof(channel) !== 'string' || channel.length !== 32) { return void cb('INVALID_ARGUMENTS'); diff --git a/www/settings/inner.js b/www/settings/inner.js index b19716fde..50a4c0205 100644 --- a/www/settings/inner.js +++ b/www/settings/inner.js @@ -1221,6 +1221,7 @@ define([ var $button = $(button); var size; + var channels = []; nThen(function (waitFor) { APP.history.execCommand('GET_HISTORY_SIZE', { account: true, @@ -1230,9 +1231,9 @@ define([ waitFor.abort(); var error = h('div.alert.alert-danger', Messages.trimHistory_error || 'error'); // XXX $(content).empty().append(error); - // TODO: obj.warning? return; } + channels = obj.channels; size = UIElements.prettySize(Number(obj.size)); })); }).nThen(function () { @@ -1247,14 +1248,12 @@ define([ $button.remove(); spinner.spin(); APP.history.execCommand('TRIM_HISTORY', { - account: true, - channels: [] + channels: channels }, function (obj) { if (obj && obj.error) { // XXX what are the possible errors? return; } - // TODO: obj.warning? spinner.hide(); $(content).append(h('div.alert.alert-success', Messages.trimHistory_success || 'ok')); // XXX });