From 63fd8677571dadb7da1f9363aa3bb032ff80697c Mon Sep 17 00:00:00 2001 From: infinite-persistence <64950861+infinite-persistence@users.noreply.github.com> Date: Tue, 21 Sep 2021 22:40:44 +0800 Subject: [PATCH] Fix moderator data misalignment. (#7139) ## Issue Closes 7121 Missing mod block option (large number of moderated channels?) ## Notes It was bad to assume `channelSignatures` would be the same length as the promise result -- any failure in signing would cause a misalignment. For my case, an accidentally-merged channel couldn't be signed due to a missing private key. I think it's the same for Drew. --- ui/redux/actions/comments.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/ui/redux/actions/comments.js b/ui/redux/actions/comments.js index 0e5425ea0..488bf8e94 100644 --- a/ui/redux/actions/comments.js +++ b/ui/redux/actions/comments.js @@ -21,6 +21,7 @@ import { doAlertWaitingForSync } from 'redux/actions/app'; const isDev = process.env.NODE_ENV !== 'production'; const FETCH_API_FAILED_TO_FETCH = 'Failed to fetch'; +const PROMISE_FULFILLED = 'fulfilled'; declare type CommentronErrorMap = { [string]: { @@ -1377,9 +1378,7 @@ export function doFetchCommentModAmIList(channelClaim: ChannelClaim) { const state = getState(); const myChannels = selectMyChannelClaims(state); - dispatch({ - type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_STARTED, - }); + dispatch({ type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_STARTED }); let channelSignatures = []; @@ -1399,13 +1398,13 @@ export function doFetchCommentModAmIList(channelClaim: ChannelClaim) { }) ) ) - .then((res) => { + .then((results) => { const delegatorsById = {}; - channelSignatures.forEach((chanSig, index) => { - if (chanSig && res[index]) { - const value = res[index].value; - delegatorsById[chanSig.claim_id] = { + results.forEach((result, index) => { + if (result.status === PROMISE_FULFILLED) { + const value = result.value; + delegatorsById[value.channel_id] = { global: value ? value.type === 'Global' : false, delegators: value && value.authorized_channels ? value.authorized_channels : {}, }; @@ -1418,15 +1417,12 @@ export function doFetchCommentModAmIList(channelClaim: ChannelClaim) { }); }) .catch((err) => { - dispatch({ - type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_FAILED, - }); + devToast(dispatch, `AmI: ${err}`); + dispatch({ type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_FAILED }); }); }) .catch(() => { - dispatch({ - type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_FAILED, - }); + dispatch({ type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_FAILED }); }); }; }