Commentron: *Delegates was failing silently

Added toasts to indicate errors instead of failing silently.
This commit is contained in:
infinite-persistence 2022-01-18 10:46:18 +08:00
parent c1cb9345ad
commit bdb83b5295
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
3 changed files with 31 additions and 9 deletions

View file

@ -1395,6 +1395,7 @@
"Unable to edit this comment, please try again later.": "Unable to edit this comment, please try again later.",
"No active channel selected.": "No active channel selected.",
"Unable to verify your channel. Please try again.": "Unable to verify your channel. Please try again.",
"Unable to verify signature for %channel%.": "Unable to verify signature for %channel%.",
"Channel cannot be anonymous, please select a channel and try again.": "Channel cannot be anonymous, please select a channel and try again.",
"Change to list layout": "Change to list layout",
"Change to tile layout": "Change to tile layout",

View file

@ -5,7 +5,7 @@ import * as PAGES from 'constants/pages';
import { SORT_BY, BLOCK_LEVEL } from 'constants/comment';
import Lbry from 'lbry';
import { parseURI, buildURI, isURIEqual } from 'util/lbryURI';
import { resolveCommentronError } from 'util/commentron-error';
import { devToast, doFailedSignatureToast, resolveCommentronError } from 'util/commentron-error';
import { selectClaimForUri, selectClaimsByUri, selectMyChannelClaims } from 'redux/selectors/claims';
import { doResolveUri, doClaimSearch } from 'redux/actions/claims';
import { doToast, doSeeNotifications } from 'redux/actions/notifications';
@ -23,19 +23,11 @@ import Comments from 'comments';
import { selectPrefsReady } from 'redux/selectors/sync';
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';
const MENTION_REGEX = /(?:^| |\n)@[^\s=&#$@%?:;/"<>%{}|^~[]*(?::[\w]+)?/gm;
function devToast(dispatch, msg) {
if (isDev) {
console.error(msg); // eslint-disable-line
dispatch(doToast({ isError: true, message: `DEV: ${msg}` }));
}
}
export function doCommentList(
uri: string,
parentId: string,
@ -1321,6 +1313,7 @@ export function doCommentModAddDelegate(
return async (dispatch: Dispatch, getState: GetState) => {
const signature = await channelSignData(creatorChannelClaim.claim_id, creatorChannelClaim.name);
if (!signature) {
doFailedSignatureToast(dispatch, creatorChannelClaim.name);
return;
}
@ -1359,6 +1352,7 @@ export function doCommentModRemoveDelegate(
return async (dispatch: Dispatch, getState: GetState) => {
const signature = await channelSignData(creatorChannelClaim.claim_id, creatorChannelClaim.name);
if (!signature) {
doFailedSignatureToast(dispatch, creatorChannelClaim.name);
return;
}
@ -1380,6 +1374,7 @@ export function doCommentModListDelegates(channelClaim: ChannelClaim) {
const signature = await channelSignData(channelClaim.claim_id, channelClaim.name);
if (!signature) {
doFailedSignatureToast(dispatch, channelClaim.name);
dispatch({ type: ACTIONS.COMMENT_FETCH_MODERATION_DELEGATES_FAILED });
return;
}
@ -1399,6 +1394,7 @@ export function doCommentModListDelegates(channelClaim: ChannelClaim) {
});
})
.catch((err) => {
dispatch(doToast({ message: err.message, isError: true }));
dispatch({ type: ACTIONS.COMMENT_FETCH_MODERATION_DELEGATES_FAILED });
});
};

View file

@ -1,4 +1,29 @@
// @flow
import { doToast } from 'redux/actions/notifications';
// ****************************************************************************
// Helpers
// ****************************************************************************
export function doFailedSignatureToast(dispatch: Dispatch, channelName: string) {
dispatch(
doToast({
message: __('Unable to verify signature for %channel%.', { channel: channelName }),
isError: true,
})
);
}
export function devToast(dispatch: Dispatch, msg: string) {
// @if process.env.NODE_ENV!='production'
console.error(msg); // eslint-disable-line
dispatch(doToast({ isError: true, message: `DEV: ${msg}` }));
// @endif
}
// ****************************************************************************
// Error mapping
// ****************************************************************************
declare type CommentronErrorMap = {
[string]: {