2017-12-21 18:32:51 +01:00
|
|
|
import { createSelector } from 'reselect';
|
2021-11-09 00:02:41 +01:00
|
|
|
import { selectClaimsById, selectMyChannelClaims, makeSelectStakedLevelForChannelUri } from 'redux/selectors/claims';
|
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-10-23 04:41:43 +02:00
|
|
|
export const selectPlatform = (state) => selectState(state).platform;
|
2020-04-14 01:48:11 +02:00
|
|
|
|
2021-04-08 21:19:14 +02:00
|
|
|
export const selectUpdateUrl = createSelector(selectPlatform, (platform) => {
|
2020-04-14 01:48:11 +02:00
|
|
|
switch (platform) {
|
|
|
|
case 'darwin':
|
|
|
|
return 'https://lbry.com/get/lbry.dmg';
|
|
|
|
case 'linux':
|
|
|
|
return 'https://lbry.com/get/lbry.deb';
|
|
|
|
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-10-23 04:41:43 +02:00
|
|
|
export const selectHasClickedComment = (state) => selectState(state).hasClickedComment;
|
|
|
|
export const selectRemoteVersion = (state) => selectState(state).remoteVersion;
|
|
|
|
export const selectIsUpgradeAvailable = (state) => selectState(state).isUpgradeAvailable;
|
2021-10-27 17:07:06 +02:00
|
|
|
export const selectIsReloadRequired = (state) => selectState(state).isReloadRequired;
|
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-10-23 04:41:43 +02:00
|
|
|
export const selectDownloadProgress = (state) => selectState(state).downloadProgress;
|
|
|
|
export const selectDownloadComplete = (state) => selectState(state).upgradeDownloadCompleted;
|
|
|
|
export const selectIsUpgradeSkipped = (state) => selectState(state).isUpgradeSkipped;
|
|
|
|
export const selectUpgradeDownloadPath = (state) => selectState(state).downloadPath;
|
|
|
|
export const selectUpgradeDownloadItem = (state) => selectState(state).downloadItem;
|
|
|
|
export const selectAutoUpdateDownloaded = (state) => selectState(state).autoUpdateDownloaded;
|
|
|
|
export const selectAutoUpdateDeclined = (state) => selectState(state).autoUpdateDeclined;
|
|
|
|
export const selectDaemonVersionMatched = (state) => selectState(state).daemonVersionMatched;
|
|
|
|
export const selectVolume = (state) => selectState(state).volume;
|
|
|
|
export const selectMute = (state) => selectState(state).muted;
|
|
|
|
export const selectUpgradeTimer = (state) => selectState(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-10-23 04:41:43 +02:00
|
|
|
export const selectSearchOptionsExpanded = (state) => selectState(state).searchOptionsExpanded;
|
|
|
|
export const selectWelcomeVersion = (state) => selectState(state).welcomeVersion;
|
|
|
|
export const selectHasNavigated = (state) => selectState(state).hasNavigated;
|
|
|
|
export const selectAllowAnalytics = (state) => selectState(state).allowAnalytics;
|
|
|
|
export const selectScrollStartingPosition = (state) => selectState(state).currentScroll;
|
|
|
|
export const selectIsPasswordSaved = (state) => selectState(state).isPasswordSaved;
|
|
|
|
export const selectInterestedInYoutubeSync = (state) => selectState(state).interestedInYoutubeSync;
|
|
|
|
export const selectSplashAnimationEnabled = (state) => selectState(state).splashAnimationEnabled;
|
|
|
|
export const selectActiveChannelId = (state) => selectState(state).activeChannel;
|
2021-02-09 17:05:56 +01:00
|
|
|
|
|
|
|
export const selectActiveChannelClaim = createSelector(
|
2021-11-09 00:02:41 +01:00
|
|
|
selectActiveChannelId,
|
|
|
|
selectClaimsById,
|
2021-02-09 17:05:56 +01:00
|
|
|
selectMyChannelClaims,
|
2021-11-09 00:02:41 +01:00
|
|
|
(activeChannelClaimId, claimsById, myChannelClaims) => {
|
|
|
|
if (!activeChannelClaimId || !claimsById || !myChannelClaims || !myChannelClaims.length) {
|
2021-02-09 17:05:56 +01:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2021-11-09 00:02:41 +01:00
|
|
|
const activeChannelClaim = claimsById[activeChannelClaimId];
|
2021-02-09 17:05:56 +01:00
|
|
|
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;
|
|
|
|
const stakedLevel = makeSelectStakedLevelForChannelUri(uri)(state);
|
|
|
|
return stakedLevel;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-10-23 04:41:43 +02:00
|
|
|
export const selectIncognito = (state) => selectState(state).incognito;
|