lbry-desktop/ui/redux/actions/app.js

709 lines
19 KiB
JavaScript
Raw Normal View History

import { execSync } from 'child_process';
import isDev from 'electron-is-dev';
import { ipcRenderer } from 'electron';
import * as remote from '@electron/remote';
2018-11-07 23:44:38 +01:00
import * as ACTIONS from 'constants/action_types';
import * as MODALS from 'constants/modal_types';
import * as SETTINGS from 'constants/settings';
import * as DAEMON_SETTINGS from 'constants/daemon_settings';
import * as SHARED_PREFERENCES from 'constants/shared_preferences';
import { DOMAIN } from 'config';
import Lbry from 'lbry';
import { doFetchChannelListMine, doFetchCollectionListMine, doCheckPendingClaims } from 'redux/actions/claims';
import { selectClaimForUri, selectClaimIsMineForUri, selectMyChannelClaims } from 'redux/selectors/claims';
import { doFetchFileInfos } from 'redux/actions/file_info';
import { doClearSupport, doBalanceSubscribe } from 'redux/actions/wallet';
import { doClearPublish } from 'redux/actions/publish';
import { Lbryio } from 'lbryinc';
import { selectFollowedTagsList } from 'redux/selectors/tags';
2020-07-23 16:22:57 +02:00
import { doToast, doError, doNotificationList } from 'redux/actions/notifications';
import {
doFetchDaemonSettings,
doSetAutoLaunch,
doSetDaemonSetting,
doFindFFmpeg,
doGetDaemonStatus,
} from 'redux/actions/settings';
2017-04-07 07:15:22 +02:00
import {
selectIsUpgradeSkipped,
2017-04-07 07:15:22 +02:00
selectUpdateUrl,
selectUpgradeDownloadItem,
selectUpgradeDownloadPath,
selectAutoUpdateDeclined,
selectRemoteVersion,
selectUpgradeTimer,
selectModal,
selectAllowAnalytics,
} from 'redux/selectors/app';
import { selectDaemonSettings, makeSelectClientSetting, selectDisableAutoUpdates } from 'redux/selectors/settings';
2022-01-07 20:02:33 +01:00
import { selectUser } from 'redux/selectors/user';
import { doSyncLoop, doSetPrefsReady, doPreferenceGet, doPopulateSharedUserState } from 'redux/actions/sync';
import { doAuthenticate } from 'redux/actions/user';
2018-09-24 05:44:42 +02:00
import { lbrySettings as config, version as appVersion } from 'package.json';
import analytics, { SHARE_INTERNAL } from 'analytics';
import { doSignOutCleanup } from 'util/saved-passwords';
import { doNotificationSocketConnect } from 'redux/actions/websocket';
import { stringifyServerParam, shouldSetSetting } from 'util/sync-settings';
2017-11-16 22:39:10 +01:00
const CHECK_UPGRADE_INTERVAL = 10 * 60 * 1000;
2017-04-07 07:15:22 +02:00
export function doOpenModal(id, modalProps = {}) {
return {
type: ACTIONS.SHOW_MODAL,
data: {
id,
modalProps,
},
};
}
export function doHideModal() {
return {
type: ACTIONS.HIDE_MODAL,
};
}
2017-04-07 07:15:22 +02:00
export function doUpdateDownloadProgress(percent) {
return {
type: ACTIONS.UPGRADE_DOWNLOAD_PROGRESSED,
2017-04-07 07:15:22 +02:00
data: {
2017-12-13 22:36:30 +01:00
percent,
2017-06-06 23:19:12 +02:00
},
};
2017-04-07 07:15:22 +02:00
}
export function doSkipUpgrade() {
return {
type: ACTIONS.SKIP_UPGRADE,
2017-06-06 23:19:12 +02:00
};
2017-04-07 07:15:22 +02:00
}
export function doStartUpgrade() {
return (dispatch, getState) => {
2017-06-06 23:19:12 +02:00
const state = getState();
const upgradeDownloadPath = selectUpgradeDownloadPath(state);
2017-04-07 07:15:22 +02:00
ipcRenderer.send('upgrade', upgradeDownloadPath);
2017-06-06 23:19:12 +02:00
};
2017-04-07 07:15:22 +02:00
}
export function doDownloadUpgrade() {
return (dispatch, getState) => {
2017-06-06 23:19:12 +02:00
const state = getState();
const url = selectUpdateUrl(state);
ipcRenderer.send('download-upgrade', { url, options: {} });
2017-04-07 07:15:22 +02:00
dispatch({
type: ACTIONS.UPGRADE_DOWNLOAD_STARTED,
2017-06-06 23:19:12 +02:00
});
dispatch(doHideModal());
dispatch(doOpenModal(MODALS.DOWNLOADING));
2017-06-06 23:19:12 +02:00
};
2017-04-07 07:15:22 +02:00
}
export function doDownloadUpgradeRequested() {
// This means the user requested an upgrade by clicking the "upgrade" button in the navbar.
// If on Mac and Windows, we do some new behavior for the auto-update system.
// This will probably be reorganized once we get auto-update going on Linux and remove
// the old logic.
return (dispatch) => {
if (['win32', 'darwin'].includes(process.platform) || !!process.env.APPIMAGE) {
// electron-updater behavior
dispatch(doOpenModal(MODALS.AUTO_UPDATE_DOWNLOADED));
} else {
// Old behavior for Linux
dispatch(doDownloadUpgrade());
}
};
}
export function doClearUpgradeTimer() {
return (dispatch, getState) => {
const state = getState();
if (selectUpgradeTimer(state)) {
clearInterval(selectUpgradeTimer(state));
dispatch({
type: ACTIONS.CLEAR_UPGRADE_TIMER,
});
}
};
}
export function doAutoUpdate() {
return (dispatch) => {
dispatch({
type: ACTIONS.AUTO_UPDATE_DOWNLOADED,
});
dispatch(doOpenModal(MODALS.AUTO_UPDATE_DOWNLOADED));
dispatch(doClearUpgradeTimer());
};
}
export function doAutoUpdateDeclined() {
return (dispatch) => {
dispatch(doClearUpgradeTimer());
dispatch({
type: ACTIONS.AUTO_UPDATE_DECLINED,
});
2018-02-24 01:24:00 +01:00
};
}
2017-04-07 07:15:22 +02:00
export function doCancelUpgrade() {
return (dispatch, getState) => {
2017-06-06 23:19:12 +02:00
const state = getState();
const upgradeDownloadItem = selectUpgradeDownloadItem(state);
2017-04-07 07:15:22 +02:00
if (upgradeDownloadItem) {
/*
* Right now the remote reference to the download item gets garbage collected as soon as the
* the download is over (maybe even earlier), so trying to cancel a finished download may
* throw an error.
*/
try {
upgradeDownloadItem.cancel();
} catch (err) {
2019-07-23 10:05:51 +02:00
console.error(err); // eslint-disable-line no-console
2017-04-07 07:15:22 +02:00
}
}
dispatch({ type: ACTIONS.UPGRADE_CANCELLED });
2017-06-06 23:19:12 +02:00
};
2017-04-07 07:15:22 +02:00
}
export function doCheckUpgradeAvailable() {
return (dispatch, getState) => {
2017-06-06 23:19:12 +02:00
const state = getState();
dispatch({
type: ACTIONS.CHECK_UPGRADE_START,
});
2017-04-07 07:15:22 +02:00
const autoUpdateSupported = ['win32', 'darwin'].includes(process.platform) || !!process.env.APPIMAGE;
const autoUpdateDeclined = selectAutoUpdateDeclined(state);
// If auto update isn't supported (Linux using .deb packages)
// don't perform any download, just get the upgrade info
// (release notes and version)
const disableAutoUpdate = !autoUpdateSupported || selectDisableAutoUpdates(state);
if (autoUpdateDeclined || isDev) {
return;
}
ipcRenderer.send('check-for-updates', !disableAutoUpdate);
};
}
export function doNotifyUpdateAvailable(e) {
return (dispatch, getState) => {
const remoteVersion = e.releaseName || e.version;
const state = getState();
const noModalBeingDisplayed = !selectModal(state);
const isUpgradeSkipped = selectIsUpgradeSkipped(state);
2022-03-04 16:32:06 +01:00
const isRemoteVersionDiff = remoteVersion !== selectRemoteVersion(state);
dispatch({
type: ACTIONS.CHECK_UPGRADE_SUCCESS,
data: {
upgradeAvailable: true,
remoteVersion,
releaseNotes: e.releaseNotes,
},
});
const autoUpdateSupported = ['win32', 'darwin'].includes(process.platform) || !!process.env.APPIMAGE;
if (autoUpdateSupported) {
return;
}
2022-03-04 16:32:06 +01:00
if (noModalBeingDisplayed && !isUpgradeSkipped && isRemoteVersionDiff) {
dispatch(doOpenModal(MODALS.UPGRADE));
}
};
}
/*
Initiate a timer that will check for an app upgrade every 10 minutes.
*/
2017-11-16 22:39:10 +01:00
export function doCheckUpgradeSubscribe() {
return (dispatch) => {
2019-05-07 23:38:29 +02:00
const checkUpgradeTimer = setInterval(() => dispatch(doCheckUpgradeAvailable()), CHECK_UPGRADE_INTERVAL);
dispatch({
type: ACTIONS.CHECK_UPGRADE_SUBSCRIBE,
data: { checkUpgradeTimer },
2017-04-07 07:15:22 +02:00
});
2017-06-06 23:19:12 +02:00
};
2017-04-07 07:15:22 +02:00
}
export function doCheckDaemonVersion() {
return (dispatch) => {
2019-02-22 06:01:59 +01:00
// @if TARGET='app'
Lbry.version().then(({ lbrynet_version: lbrynetVersion }) => {
// Avoid the incompatible daemon modal if running in dev mode
// Lets you run a different daemon than the one specified in package.json
2020-02-05 19:01:07 +01:00
if (config.lbrynetDaemonVersion === lbrynetVersion || process.env.NODE_ENV !== 'production') {
return dispatch({
2018-05-11 01:06:41 +02:00
type: ACTIONS.DAEMON_VERSION_MATCH,
});
}
dispatch({
2018-05-11 01:06:41 +02:00
type: ACTIONS.DAEMON_VERSION_MISMATCH,
});
2020-02-05 19:01:07 +01:00
if (process.env.NODE_ENV === 'production') {
return dispatch(doOpenModal(MODALS.INCOMPATIBLE_DAEMON));
}
});
2019-02-22 06:01:59 +01:00
// @endif
// @if TARGET='web'
dispatch({
type: ACTIONS.DAEMON_VERSION_MATCH,
});
// @endif
};
}
2018-07-18 21:48:30 +02:00
export function doNotifyEncryptWallet() {
return (dispatch) => {
dispatch(doOpenModal(MODALS.WALLET_ENCRYPT));
2018-07-18 21:48:30 +02:00
};
}
export function doNotifyDecryptWallet() {
return (dispatch) => {
dispatch(doOpenModal(MODALS.WALLET_DECRYPT));
2018-07-18 21:48:30 +02:00
};
}
export function doNotifyUnlockWallet() {
return (dispatch) => {
dispatch(doOpenModal(MODALS.WALLET_UNLOCK));
2018-07-18 21:48:30 +02:00
};
}
export function doNotifyForgetPassword(props) {
return (dispatch) => {
dispatch(doOpenModal(MODALS.WALLET_PASSWORD_UNSAVE, props));
2019-08-20 14:29:59 +02:00
};
}
2017-04-07 07:15:22 +02:00
export function doAlertError(errorList) {
return (dispatch) => {
dispatch(doError(errorList));
2017-06-06 23:19:12 +02:00
};
2017-04-07 07:15:22 +02:00
}
export function doAlertWaitingForSync() {
2022-01-07 20:02:33 +01:00
return (dispatch) => {
dispatch(
doToast({
2022-01-07 20:02:33 +01:00
message: __('Please wait a bit, we are still getting your account ready.'),
isError: false,
})
);
2020-11-10 06:21:04 +01:00
};
}
2017-04-22 15:17:01 +02:00
export function doDaemonReady() {
return (dispatch, getState) => {
2017-11-16 22:39:10 +01:00
const state = getState();
// TODO: call doFetchDaemonSettings, then get usage data, and call doAuthenticate once they are loaded into the store
2022-01-07 20:02:33 +01:00
const shareUsageData = window.localStorage.getItem(SHARE_INTERNAL) === 'true';
2020-03-12 17:36:45 +01:00
dispatch(
2020-06-04 19:43:36 +02:00
doAuthenticate(
appVersion,
undefined,
undefined,
shareUsageData,
(status) => {
2020-06-04 19:43:36 +02:00
const trendingAlgorithm =
status &&
status.wallet &&
status.wallet.connected_features &&
status.wallet.connected_features.trending_algorithm;
if (trendingAlgorithm) {
analytics.trendingAlgorithmEvent(trendingAlgorithm);
}
},
undefined,
DOMAIN
2020-06-04 19:43:36 +02:00
)
2020-03-12 17:36:45 +01:00
);
dispatch({ type: ACTIONS.DAEMON_READY });
2019-03-29 15:23:32 +01:00
2019-02-22 06:01:59 +01:00
// @if TARGET='app'
dispatch(doBalanceSubscribe());
2019-11-18 19:30:15 +01:00
dispatch(doSetAutoLaunch());
dispatch(doFindFFmpeg());
dispatch(doGetDaemonStatus());
2019-09-26 18:07:11 +02:00
dispatch(doFetchDaemonSettings());
dispatch(doFetchFileInfos());
2017-11-16 22:39:10 +01:00
if (!selectIsUpgradeSkipped(state)) {
dispatch(doCheckUpgradeAvailable());
}
dispatch(doCheckUpgradeSubscribe());
2019-02-22 06:01:59 +01:00
// @endif
2017-06-08 02:56:52 +02:00
};
2017-04-22 15:17:01 +02:00
}
2017-05-23 09:21:21 +02:00
export function doClearCache() {
return (dispatch) => {
2019-07-23 10:05:51 +02:00
// Need to update this to work with new version of redux-persist
// Leaving for now
// const reducersToClear = whiteListedReducers.filter(reducerKey => reducerKey !== 'tags');
// window.cacheStore.purge(reducersToClear);
2020-03-27 17:49:41 +01:00
window.sessionStorage.clear();
dispatch(doClearSupport());
2020-03-27 17:49:41 +01:00
window.location.reload();
2019-10-04 19:29:57 +02:00
return dispatch(doClearPublish());
};
}
export function doQuit() {
return () => {
2019-02-22 06:01:59 +01:00
// @if TARGET='app'
remote.app.quit();
2019-02-22 06:01:59 +01:00
// @endif
};
}
export function doQuitAnyDaemon() {
return (dispatch) => {
2019-02-22 06:01:59 +01:00
// @if TARGET='app'
2019-02-18 18:33:02 +01:00
Lbry.stop()
.catch(() => {
try {
if (process.platform === 'win32') {
execSync('taskkill /im lbrynet.exe /t /f');
} else {
execSync('pkill lbrynet');
}
} catch (error) {
dispatch(doAlertError(`Quitting daemon failed due to: ${error.message}`));
}
2019-02-22 06:01:59 +01:00
})
.finally(() => {
dispatch(doQuit());
2019-02-18 18:33:02 +01:00
});
2019-02-22 06:01:59 +01:00
// @endif
};
}
export function doChangeVolume(volume) {
return (dispatch) => {
dispatch({
type: ACTIONS.VOLUME_CHANGED,
data: {
volume,
},
});
};
}
2017-12-23 03:09:06 +01:00
export function doChangeMute(muted) {
return (dispatch) => {
dispatch({
type: ACTIONS.VOLUME_MUTED,
data: {
muted,
},
});
};
}
2018-11-07 23:44:38 +01:00
export function doClickCommentButton() {
return {
type: ACTIONS.ADD_COMMENT,
};
}
export function doToggleSearchExpanded() {
return {
type: ACTIONS.TOGGLE_SEARCH_EXPANDED,
};
}
2019-08-14 05:04:08 +02:00
export function doAnalyticsView(uri, timeToStart) {
return (dispatch, getState) => {
const state = getState();
const claim = selectClaimForUri(state, uri);
const { txid, nout, claim_id: claimId } = claim;
const claimIsMine = selectClaimIsMineForUri(state, claim);
2019-08-14 05:04:08 +02:00
const outpoint = `${txid}:${nout}`;
if (claimIsMine) {
2019-09-21 18:45:52 +02:00
return Promise.resolve();
2019-08-14 05:04:08 +02:00
}
return analytics.apiLogView(uri, outpoint, claimId, timeToStart);
2019-08-14 05:04:08 +02:00
};
}
2019-09-26 18:07:11 +02:00
2020-08-07 22:59:20 +02:00
export function doAnalyticsBuffer(uri, bufferData) {
return (dispatch, getState) => {
const state = getState();
const claim = selectClaimForUri(state, uri);
2020-08-07 22:59:20 +02:00
const user = selectUser(state);
const {
value: { video, audio, source },
} = claim;
const timeAtBuffer = parseInt(bufferData.currentTime ? bufferData.currentTime * 1000 : 0);
const bufferDuration = parseInt(bufferData.secondsToLoad ? bufferData.secondsToLoad * 1000 : 0);
2020-08-07 22:59:20 +02:00
const fileDurationInSeconds = (video && video.duration) || (audio && audio.duration);
const fileSize = source.size; // size in bytes
const fileSizeInBits = fileSize * 8;
const bitRate = parseInt(fileSizeInBits / fileDurationInSeconds);
2021-06-18 00:52:21 +02:00
const userId = user && user.id.toString();
// if there's a logged in user, send buffer event data to watchman
2021-06-18 00:52:21 +02:00
if (userId) {
analytics.videoBufferEvent(claim, {
timeAtBuffer,
bufferDuration,
bitRate,
userId,
duration: fileDurationInSeconds,
playerPoweredBy: bufferData.playerPoweredBy,
readyState: bufferData.readyState,
});
}
2020-08-07 22:59:20 +02:00
};
}
export function doAnalyticsTagSync() {
return (dispatch, getState) => {
const state = getState();
const tags = selectFollowedTagsList(state);
const stringOfTags = tags.join(',');
if (stringOfTags) {
analytics.apiSyncTags({ content_tags: stringOfTags });
}
};
}
2020-05-21 17:38:28 +02:00
export function doAnaltyicsPurchaseEvent(fileInfo) {
2021-10-19 01:37:58 +02:00
return () => {
2020-05-21 17:38:28 +02:00
let purchasePrice = fileInfo.purchase_receipt && fileInfo.purchase_receipt.amount;
if (purchasePrice) {
const purchaseInt = Number(Number(purchasePrice).toFixed(0));
analytics.purchaseEvent(purchaseInt);
}
};
}
2019-09-26 18:07:11 +02:00
export function doSignIn() {
return (dispatch, getState) => {
const state = getState();
const user = selectUser(state);
const notificationsEnabled = user.experimental_ui;
dispatch(doNotificationSocketConnect(notificationsEnabled));
2020-07-23 16:22:57 +02:00
if (notificationsEnabled) {
dispatch(doNotificationList());
}
2021-06-25 00:06:08 +02:00
dispatch(doCheckPendingClaims());
2020-07-23 16:22:57 +02:00
2019-09-26 18:07:11 +02:00
// @if TARGET='web'
dispatch(doBalanceSubscribe());
dispatch(doFetchChannelListMine());
wip wip wip - everything but publish, autoplay, and styling collection publishing add channel to collection publish cleanup wip bump clear mass add after success move collection item management controls redirect replace to published collection id bump playlist selector on create bump use new collection add ui element bump wip gitignore add content json wip bump context add to playlist basic collections page style pass wip wip: edits, buttons, styles... change fileAuthor to claimAuthor update, pending bugfixes, delete modal progress, collection header, other bugfixes bump cleaning show page bugfix builtin collection headers no playlists, no grid title wip style tweaks use normal looking claim previews for collection tiles add collection changes style library previews collection menulist for delete/view on library delete modal works for unpublished rearrange collection publish tabs clean up collection publishing and items show on odysee begin collectoin edit header and css renaming better thumbnails bump fix collection publish redirect view collection in menu does something copy and thumbs list previews, pending, context menus, list page enter to add collection, lists page empty state playable lists only, delete feature, bump put fileListDownloaded back better collection titles improve collection claim details fix horiz more icon fix up channel page style, copy, bump refactor preview overlay properties, fix reposts showing as floppydisk add watch later toast, small overlay properties on wunderbar results, fix collection actions buttons bump cleanup cleaning, refactoring bump preview thumb styling, cleanup support discover page lists search sync, bump bump, fix sync more enforce builtin order for now new lists page empty state try to indicate unpublished edits in lists bump fix autoplay and linting consts, fix autoplay bugs fixes cleanup fix, bump lists experimental ui, fixes refactor listIndex out hack in collection fallback thumb bump
2021-02-06 08:03:51 +01:00
dispatch(doFetchCollectionListMine());
2019-10-01 06:53:33 +02:00
// @endif
2019-09-26 18:07:11 +02:00
};
}
export function doSignOut() {
return () => {
Lbryio.call('user', 'signout')
.then(doSignOutCleanup)
2019-09-26 18:07:11 +02:00
.then(() => {
2019-10-03 23:40:54 +02:00
// @if TARGET='web'
window.persistor.purge();
// @endif
})
.then(() => {
setTimeout(() => {
location.reload();
});
2019-09-26 18:07:11 +02:00
})
.catch(() => location.reload());
};
}
2019-10-15 23:23:51 +02:00
export function doSetWelcomeVersion(version) {
return {
type: ACTIONS.SET_WELCOME_VERSION,
data: version,
};
}
export function doSetHasNavigated() {
return {
type: ACTIONS.SET_HAS_NAVIGATED,
data: true,
};
}
export function doToggle3PAnalytics(allowParam, doNotDispatch) {
return (dispatch, getState) => {
const state = getState();
const allowState = selectAllowAnalytics(state);
const allow = allowParam !== undefined && allowParam !== null ? allowParam : allowState;
analytics.toggleThirdParty(allow);
if (!doNotDispatch) {
return dispatch({
type: ACTIONS.SET_ALLOW_ANALYTICS,
data: allow,
});
}
};
}
export function doGetAndPopulatePreferences() {
const { SDK_SYNC_KEYS } = SHARED_PREFERENCES;
return (dispatch, getState) => {
const state = getState();
const syncEnabled = makeSelectClientSetting(SETTINGS.ENABLE_SYNC)(state);
const hasVerifiedEmail = state.user && state.user.user && state.user.user.has_verified_email;
2020-08-07 22:59:20 +02:00
let preferenceKey;
preferenceKey = syncEnabled && hasVerifiedEmail ? 'shared' : 'local';
function successCb(savedPreferences) {
const successState = getState();
const daemonSettings = selectDaemonSettings(successState);
if (savedPreferences !== null) {
dispatch(doPopulateSharedUserState(savedPreferences));
const { settings } = savedPreferences.value;
2020-08-28 17:25:47 +02:00
if (settings) {
Object.entries(settings).forEach(([key, val]) => {
if (SDK_SYNC_KEYS.includes(key)) {
if (shouldSetSetting(key, val, daemonSettings[key])) {
if (key === DAEMON_SETTINGS.LBRYUM_SERVERS) {
const servers = stringifyServerParam(val);
dispatch(doSetDaemonSetting(key, servers, true));
} else {
dispatch(doSetDaemonSetting(key, val, true));
}
}
}
// probably set commentServer here instead of in doPopulateSharedUserState()
2020-08-28 17:25:47 +02:00
});
}
} else {
dispatch(doSetPrefsReady());
2019-10-15 23:23:51 +02:00
}
2020-09-04 17:02:30 +02:00
return true;
}
2019-10-15 23:23:51 +02:00
2021-07-15 20:07:06 +02:00
function failCb(er) {
dispatch(
doToast({
isError: true,
message: __('Unable to load your saved preferences.'),
})
);
dispatch({
type: ACTIONS.SYNC_FATAL_ERROR,
2021-07-15 20:07:06 +02:00
error: er,
});
2020-09-04 17:02:30 +02:00
return false;
}
2020-01-02 17:30:27 +01:00
return dispatch(doPreferenceGet(preferenceKey, successCb, failCb));
};
}
2019-10-15 23:23:51 +02:00
export function doHandleSyncComplete(error, hasNewData) {
return (dispatch) => {
if (!error) {
if (hasNewData) {
2021-11-30 04:26:12 +01:00
dispatch(doGetAndPopulatePreferences());
// we just got sync data, better update our channels
dispatch(doFetchChannelListMine());
}
2021-07-15 20:07:06 +02:00
} else {
2021-07-15 22:55:57 +02:00
console.error('Error in doHandleSyncComplete', error);
2019-10-15 23:23:51 +02:00
}
};
}
2019-10-15 23:23:51 +02:00
export function doSyncWithPreferences() {
return (dispatch) => dispatch(doSyncLoop());
2019-10-15 23:23:51 +02:00
}
export function doToggleInterestedInYoutubeSync() {
return {
type: ACTIONS.TOGGLE_YOUTUBE_SYNC_INTEREST,
};
}
2020-11-09 18:22:38 +01:00
export function doToggleSplashAnimation() {
return {
type: ACTIONS.TOGGLE_SPLASH_ANIMATION,
};
}
export function doSetActiveChannel(claimId) {
return (dispatch, getState) => {
if (claimId) {
return dispatch({
type: ACTIONS.SET_ACTIVE_CHANNEL,
data: {
claimId,
},
});
}
// If no claimId is passed, set the active channel to the one with the highest effective_amount
const state = getState();
const myChannelClaims = selectMyChannelClaims(state);
if (!myChannelClaims || !myChannelClaims.length) {
return;
}
const myChannelClaimsByEffectiveAmount = myChannelClaims.slice().sort((a, b) => {
const effectiveAmountA = (a.meta && Number(a.meta.effective_amount)) || 0;
const effectiveAmountB = (b.meta && Number(b.meta.effective_amount)) || 0;
if (effectiveAmountA === effectiveAmountB) {
return 0;
} else if (effectiveAmountA > effectiveAmountB) {
return -1;
} else {
return 1;
}
});
const newActiveChannelClaim = myChannelClaimsByEffectiveAmount[0];
dispatch({
type: ACTIONS.SET_ACTIVE_CHANNEL,
data: {
claimId: newActiveChannelClaim.claim_id,
},
});
};
}
export function doSetIncognito(incognitoEnabled) {
return {
type: ACTIONS.SET_INCOGNITO,
data: {
enabled: incognitoEnabled,
},
};
}