2017-12-21 18:32:51 +01:00
|
|
|
import { createSelector } from 'reselect';
|
2021-12-31 18:52:26 +01:00
|
|
|
import { selectClaimsById, selectMyChannelClaims, selectTotalStakedAmountForChannelUri } from 'redux/selectors/claims';
|
2022-03-01 12:36:33 +01:00
|
|
|
import * as MODALS from 'constants/modal_types';
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectState = (state) => state.app || {};
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectPlatform = createSelector(selectState, (state) => state.platform);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2022-07-07 22:48:42 +02:00
|
|
|
export const selectRemoteVersion = createSelector(selectState, (state) => state.remoteVersion);
|
|
|
|
|
|
|
|
export const selectUpdateUrl = createSelector(selectPlatform, selectRemoteVersion, (platform, releaseVersion) => {
|
2020-04-14 01:48:11 +02:00
|
|
|
switch (platform) {
|
|
|
|
case 'darwin':
|
|
|
|
return 'https://lbry.com/get/lbry.dmg';
|
|
|
|
case 'linux':
|
2022-07-07 22:48:42 +02:00
|
|
|
// releaseVersion can be used as the tag name
|
|
|
|
// Example: v0.53.5-alpha.test7495b
|
|
|
|
// When downloading, we need to remove the initial
|
|
|
|
// v, ending up with a file name like
|
|
|
|
// LBRY_0.53.5-alpha.test7495b.deb
|
|
|
|
const fileName = 'LBRY_' + (releaseVersion || '').replace('v', '') + '.deb';
|
|
|
|
return `https://github.com/lbryio/lbry-desktop/releases/download/${releaseVersion}/${fileName}`;
|
2020-04-14 01:48:11 +02:00
|
|
|
case 'win32':
|
|
|
|
return 'https://lbry.com/get/lbry.exe';
|
|
|
|
default:
|
|
|
|
throw Error('Unknown platform');
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
2020-04-14 01:48:11 +02:00
|
|
|
});
|
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectHasClickedComment = createSelector(selectState, (state) => state.hasClickedComment);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectIsUpgradeAvailable = createSelector(selectState, (state) => state.isUpgradeAvailable);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2022-07-07 22:48:42 +02:00
|
|
|
export const selectUpgradeInitialized = createSelector(selectState, (state) => state.upgradeInitialized);
|
|
|
|
|
|
|
|
export const selectUpgradeFailedInstallation = createSelector(selectState, (state) => state.upgradeFailedInstallation);
|
|
|
|
|
2020-04-14 01:48:11 +02:00
|
|
|
export const selectUpgradeFilename = createSelector(selectPlatform, selectRemoteVersion, (platform, version) => {
|
|
|
|
switch (platform) {
|
|
|
|
case 'darwin':
|
|
|
|
return `LBRY_${version}.dmg`;
|
|
|
|
case 'linux':
|
|
|
|
return `LBRY_${version}.deb`;
|
|
|
|
case 'win32':
|
|
|
|
return `LBRY_${version}.exe`;
|
|
|
|
default:
|
|
|
|
throw Error('Unknown platform');
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
2020-04-14 01:48:11 +02:00
|
|
|
});
|
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectDownloadProgress = createSelector(selectState, (state) => state.downloadProgress);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectDownloadComplete = createSelector(selectState, (state) => state.upgradeDownloadCompleted);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectIsUpgradeSkipped = createSelector(selectState, (state) => state.isUpgradeSkipped);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectUpgradeDownloadPath = createSelector(selectState, (state) => state.downloadPath);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectAutoUpdateDownloaded = createSelector(selectState, (state) => state.autoUpdateDownloaded);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectAutoUpdateDeclined = createSelector(selectState, (state) => state.autoUpdateDeclined);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2022-07-07 22:48:42 +02:00
|
|
|
export const selectAutoUpdateFailed = createSelector(selectState, (state) => state.autoUpdateFailed);
|
|
|
|
|
|
|
|
export const selectAutoUpdateDownloading = createSelector(selectState, (state) => state.autoUpdateDownloading);
|
|
|
|
|
2022-02-21 14:08:17 +01:00
|
|
|
export const selectIsUpdateModalDisplayed = createSelector(selectState, (state) => {
|
2022-03-01 12:36:33 +01:00
|
|
|
return [MODALS.AUTO_UPDATE_DOWNLOADED, MODALS.UPGRADE, MODALS.DOWNLOADING].includes(state.modal);
|
2022-02-18 19:44:00 +01:00
|
|
|
});
|
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectDaemonVersionMatched = createSelector(selectState, (state) => state.daemonVersionMatched);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectVolume = createSelector(selectState, (state) => state.volume);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectMute = createSelector(selectState, (state) => state.muted);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectUpgradeTimer = createSelector(selectState, (state) => state.checkUpgradeTimer);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectModal = createSelector(selectState, (state) => {
|
2020-04-14 01:48:11 +02:00
|
|
|
if (!state.modal) {
|
|
|
|
return null;
|
2019-03-05 05:46:57 +01:00
|
|
|
}
|
2020-04-14 01:48:11 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
id: state.modal,
|
|
|
|
modalProps: state.modalProps,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectSearchOptionsExpanded = createSelector(selectState, (state) => state.searchOptionsExpanded);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectWelcomeVersion = createSelector(selectState, (state) => state.welcomeVersion);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectHasNavigated = createSelector(selectState, (state) => state.hasNavigated);
|
2020-07-10 23:04:36 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectAllowAnalytics = createSelector(selectState, (state) => state.allowAnalytics);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectScrollStartingPosition = createSelector(selectState, (state) => state.currentScroll);
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectIsPasswordSaved = createSelector(selectState, (state) => state.isPasswordSaved);
|
2020-09-04 17:02:30 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectInterestedInYoutubeSync = createSelector(selectState, (state) => state.interestedInYoutubeSync);
|
2020-11-09 18:22:38 +01:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectSplashAnimationEnabled = createSelector(selectState, (state) => state.splashAnimationEnabled);
|
2021-02-09 17:05:56 +01:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectActiveChannelId = createSelector(selectState, (state) => state.activeChannel);
|
2021-02-09 17:05:56 +01:00
|
|
|
|
|
|
|
export const selectActiveChannelClaim = createSelector(
|
|
|
|
selectActiveChannelId,
|
|
|
|
selectClaimsById,
|
|
|
|
selectMyChannelClaims,
|
|
|
|
(activeChannelClaimId, claimsById, myChannelClaims) => {
|
|
|
|
if (!activeChannelClaimId || !claimsById || !myChannelClaims || !myChannelClaims.length) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const activeChannelClaim = claimsById[activeChannelClaimId];
|
|
|
|
if (activeChannelClaim) {
|
|
|
|
return activeChannelClaim;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return myChannelClaimsByEffectiveAmount[0];
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectActiveChannelStakedLevel = createSelector(
|
|
|
|
(state) => state,
|
|
|
|
selectActiveChannelClaim,
|
|
|
|
(state, activeChannelClaim) => {
|
|
|
|
if (!activeChannelClaim) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uri = activeChannelClaim.permanent_url;
|
2022-01-04 16:13:15 +01:00
|
|
|
const stakedLevel = selectTotalStakedAmountForChannelUri(state, uri);
|
2021-04-08 21:19:14 +02:00
|
|
|
|
|
|
|
return stakedLevel;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
export const selectIncognito = createSelector(selectState, (state) => state.incognito);
|
2022-02-25 21:01:14 +01:00
|
|
|
|
|
|
|
export const selectDiskSpace = createSelector(selectState, (state) => state.diskSpace);
|