move to new notificaion logic - UNTESTED

This commit is contained in:
Sean Yesmunt 2018-11-20 12:07:12 -05:00
parent dffff47a9f
commit eb4995da86
23 changed files with 52 additions and 68 deletions

View file

@ -33,7 +33,7 @@ import {
ToastAndroid
} from 'react-native';
import { doDeleteCompleteBlobs } from '../redux/actions/file';
import { SETTINGS, doHideNotification, doNotify, selectNotification } from 'lbry-redux';
import { SETTINGS, doHideNotification, doToast, selectToast } from 'lbry-redux';
import {
doUserEmailVerify,
doUserEmailVerifyFailure,
@ -240,15 +240,15 @@ class AppWithNavigationState extends React.Component {
componentWillUpdate(nextProps) {
const { dispatch } = this.props;
const {
notification,
toast,
emailToVerify,
emailVerifyPending,
emailVerifyErrorMessage,
user
} = nextProps;
if (notification) {
const { displayType, message } = notification;
if (toast) {
const { message } = toast;
let currentDisplayType;
if (displayType && displayType.length) {
for (let i = 0; i < displayType.length; i++) {
@ -287,7 +287,7 @@ class AppWithNavigationState extends React.Component {
AsyncStorage.removeItem(Constants.KEY_FIRST_RUN_EMAIL);
}
AsyncStorage.removeItem(Constants.KEY_SHOULD_VERIFY_EMAIL);
dispatch(doNotify({ message, displayType: ['toast'] }));
dispatch(doToast({ message }));
}
});
}
@ -340,12 +340,11 @@ class AppWithNavigationState extends React.Component {
} catch (error) {
const message = 'Invalid Verification Token';
dispatch(doUserEmailVerifyFailure(message));
dispatch(doNotify({ message, displayType: ['toast'] }));
dispatch(doToast({ message }));
}
} else {
dispatch(doNotify({
dispatch(doToast({
message: 'Invalid Verification URI',
displayType: ['toast'],
}));
}
} else {
@ -363,7 +362,7 @@ const mapStateToProps = state => ({
backgroundPlayEnabled: makeSelectClientSetting(SETTINGS.BACKGROUND_PLAY_ENABLED)(state),
keepDaemonRunning: makeSelectClientSetting(SETTINGS.KEEP_DAEMON_RUNNING)(state),
nav: state.nav,
notification: selectNotification(state),
toast: selectToast(state),
emailToVerify: selectEmailToVerify(state),
emailVerifyPending: selectEmailVerifyIsPending(state),
emailVerifyErrorMessage: selectEmailVerifyErrorMessage(state),

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import Address from './view';
export default connect(null, {
doNotify,
doToast,
})(Address);

View file

@ -6,21 +6,20 @@ import walletStyle from '../../styles/wallet';
type Props = {
address: string,
doNotify: ({ message: string, displayType: Array<string> }) => void,
doToast: ({ message: string }) => void,
};
export default class Address extends React.PureComponent<Props> {
render() {
const { address, doNotify, style } = this.props;
const { address, doToast, style } = this.props;
return (
<View style={[walletStyle.row, style]}>
<Text selectable={true} numberOfLines={1} style={walletStyle.address}>{address || ''}</Text>
<Button icon={'clipboard'} style={walletStyle.button} onPress={() => {
Clipboard.setString(address);
doNotify({
doToast({
message: 'Address copied',
displayType: ['toast'],
});
}} />
</View>

View file

@ -5,7 +5,7 @@ import {
selectEmailNewIsPending,
selectEmailToVerify
} from 'lbryinc';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import EmailRewardSubcard from './view';
const select = state => ({
@ -16,7 +16,7 @@ const select = state => ({
const perform = dispatch => ({
addUserEmail: email => dispatch(doUserEmailNew(email)),
notify: data => dispatch(doNotify(data))
notify: data => dispatch(doToast(data))
});
export default connect(select, perform)(EmailRewardSubcard);

View file

@ -38,12 +38,11 @@ class EmailRewardSubcard extends React.PureComponent {
if (this.state.verifyStarted && !emailNewPending) {
if (emailNewErrorMessage) {
notify({ message: String(emailNewErrorMessage), displayType: ['toast']});
notify({ message: String(emailNewErrorMessage), isError: true });
this.setState({ verifyStarted: false });
} else {
notify({
message: 'Please follow the instructions in the email sent to your address to continue.',
displayType: ['toast']
});
}
}
@ -65,7 +64,6 @@ class EmailRewardSubcard extends React.PureComponent {
if (!email || email.trim().length === 0 || email.indexOf('@') === -1) {
return notify({
message: 'Please provide a valid email address to continue.',
displayType: ['toast'],
});
}

View file

@ -1,9 +1,9 @@
import { connect } from 'react-redux';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import Link from './view';
const perform = dispatch => ({
notify: (data) => dispatch(doNotify(data))
notify: (data) => dispatch(doToast(data))
});
export default connect(null, perform)(Link);

View file

@ -21,7 +21,7 @@ export default class Link extends React.PureComponent {
Linking.openURL(href)
.then(() => setTimeout(() => { this.setState({ tappedStyle: false }); }, 2000))
.catch(err => {
notify({ message: error, displayType: ['toast']})
notify({ message: error, isError: true })
this.setState({tappedStyle: false})
}
);

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import {
doUserPhoneNew,
doUserPhoneVerify,
@ -22,7 +22,7 @@ const select = state => ({
const perform = dispatch => ({
addUserPhone: (phone, country_code) => dispatch(doUserPhoneNew(phone, country_code)),
verifyPhone: (verificationCode) => dispatch(doUserPhoneVerify(verificationCode)),
notify: data => dispatch(doNotify(data)),
notify: data => dispatch(doToast(data)),
});
export default connect(select, perform)(PhoneNumberRewardSubcard);

View file

@ -70,17 +70,17 @@ class PhoneNumberRewardSubcard extends React.PureComponent {
if (!phoneNewIsPending && (phoneNewIsPending !== prevProps.phoneNewIsPending)) {
if (phoneNewErrorMessage) {
notify({ message: String(phoneNewErrorMessage), displayType: ['toast'] });
notify({ message: String(phoneNewErrorMessage) });
} else {
this.setState({ newPhoneAdded: true });
}
}
if (!phoneVerifyIsPending && (phoneVerifyIsPending !== prevProps.phoneVerifyIsPending)) {
if (phoneVerifyErrorMessage) {
notify({ message: String(phoneVerifyErrorMessage), displayType: ['toast'] });
notify({ message: String(phoneVerifyErrorMessage) });
this.setState({ codeVerifyStarted: false });
} else {
notify({ message: 'Your phone number was successfully verified.', displayType: ['toast'] });
notify({ message: 'Your phone number was successfully verified.' });
this.setState({ codeVerifySuccessful: true });
if (onPhoneVerifySuccessful) {
onPhoneVerifySuccessful();
@ -107,7 +107,6 @@ class PhoneNumberRewardSubcard extends React.PureComponent {
if (!NativeModules.UtilityModule) {
return notify({
message: 'The required permission could not be obtained due to a missing module.',
displayType: ['toast']
});
}
@ -120,7 +119,6 @@ class PhoneNumberRewardSubcard extends React.PureComponent {
if (!this.phoneInput.isValidNumber()) {
return notify({
message: 'Please provide a valid telephone number.',
displayType: ['toast']
});
}

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import {
doClaimRewardType,
doClaimRewardClearError,
@ -23,7 +23,7 @@ const makeSelect = () => {
const perform = dispatch => ({
claimReward: reward => dispatch(doClaimRewardType(reward.reward_type, true)),
clearError: reward => dispatch(doClaimRewardClearError(reward)),
notify: data => dispatch(doNotify(data))
notify: data => dispatch(doToast(data))
});
export default connect(makeSelect, perform)(RewardCard);

View file

@ -30,10 +30,10 @@ class RewardCard extends React.PureComponent<Props> {
const { clearError, notify, reward } = this.props;
if (this.state.claimStarted && !isPending) {
if (errorMessage && errorMessage.trim().length > 0) {
notify({ message: errorMessage, displayType: ['toast'] });
notify({ message: errorMessage });
clearError(reward);
} else {
notify({ message: 'Reward successfully claimed!', displayType: ['toast'] });
notify({ message: 'Reward successfully claimed!' });
}
this.setState({ claimStarted: false });
}
@ -48,7 +48,7 @@ class RewardCard extends React.PureComponent<Props> {
} = this.props;
if (!canClaim) {
notify({ message: 'Unfortunately, you are not eligible to claim this reward at this time.', displayType: ['toast'] });
notify({ message: 'Unfortunately, you are not eligible to claim this reward at this time.' });
return;
}

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import { doRewardList, selectUnclaimedRewardValue, selectFetchingRewards, selectUser } from 'lbryinc';
import RewardSummary from './view';
@ -11,7 +11,7 @@ const select = state => ({
const perform = dispatch => ({
fetchRewards: () => dispatch(doRewardList()),
notify: data => dispatch(doNotify(data))
notify: data => dispatch(doToast(data))
});
export default connect(select, perform)(RewardSummary);

View file

@ -38,7 +38,6 @@ class RewardSummary extends React.Component {
this.setState({ dismissed: true });
this.props.notify({
message: 'You can always claim your rewards from the Rewards page.',
displayType: ['toast']
});
}

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import {
doNotify,
doToast,
doSendDraftTransaction,
selectDraftTransaction,
selectDraftTransactionError,
@ -10,7 +10,7 @@ import WalletSend from './view';
const perform = dispatch => ({
sendToAddress: (address, amount) => dispatch(doSendDraftTransaction(address, amount)),
notify: (data) => dispatch(doNotify(data))
notify: (data) => dispatch(doToast(data))
});
const select = state => ({

View file

@ -38,7 +38,6 @@ class WalletSend extends React.PureComponent<Props> {
if (address && !regexAddress.test(address)) {
notify({
message: 'The recipient address is not a valid LBRY address.',
displayType: ['toast']
});
return;
}
@ -46,7 +45,6 @@ class WalletSend extends React.PureComponent<Props> {
if (amount > balance) {
notify({
message: 'Insufficient credits',
displayType: ['toast']
});
return;
}
@ -62,7 +60,6 @@ class WalletSend extends React.PureComponent<Props> {
const { notify } = this.props;
notify({
message: 'The recipient address is not a valid LBRY address.',
displayType: ['toast']
});
}
}

View file

@ -3,7 +3,7 @@ import {
doFetchFileInfo,
doFetchCostInfoForUri,
doResolveUri,
doNotify,
doToast,
makeSelectIsUriResolving,
makeSelectCostInfoForUri,
makeSelectFileInfoForUri,
@ -38,7 +38,7 @@ const perform = dispatch => ({
},
fetchFileInfo: uri => dispatch(doFetchFileInfo(uri)),
fetchCostInfo: uri => dispatch(doFetchCostInfoForUri(uri)),
notify: data => dispatch(doNotify(data)),
notify: data => dispatch(doToast(data)),
resolveUri: uri => dispatch(doResolveUri(uri)),
stopDownload: (uri, fileInfo) => dispatch(doStopDownloadingFile(uri, fileInfo)),
});

View file

@ -189,7 +189,6 @@ class FilePage extends React.PureComponent {
// after the file_set_status and file_delete operations, so let the user know
notify({
message: 'The download will stop momentarily. You do not need to wait to discover something else.',
displayType: ['toast']
});
}}
],

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import {
doGenerateAuthToken,
doUserEmailNew,
@ -22,7 +22,7 @@ const select = (state) => ({
const perform = dispatch => ({
addUserEmail: email => dispatch(doUserEmailNew(email)),
generateAuthToken: installationId => dispatch(doGenerateAuthToken(installationId)),
notify: data => dispatch(doNotify(data))
notify: data => dispatch(doToast(data))
});
export default connect(select, perform)(FirstRun);

View file

@ -61,7 +61,7 @@ class FirstRunScreen extends React.PureComponent {
if (this.state.emailSubmitted && !emailNewPending) {
this.setState({ emailSubmitted: false });
if (emailNewErrorMessage) {
notify ({ message: String(emailNewErrorMessage), displayType: ['toast']});
notify ({ message: String(emailNewErrorMessage), isError: true });
} else {
// Request successful. Navigate to discover.
this.closeFinalPage();
@ -115,7 +115,6 @@ class FirstRunScreen extends React.PureComponent {
if (email.indexOf('@') === -1) {
return notify({
message: 'Please provide a valid email address to continue.',
displayType: ['toast'],
});
}

View file

@ -8,7 +8,7 @@ import {
selectClaimedRewards,
selectUser,
} from 'lbryinc';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import RewardsPage from './view';
const select = state => ({
@ -22,7 +22,7 @@ const select = state => ({
const perform = dispatch => ({
fetchRewards: () => dispatch(doRewardList()),
notify: data => dispatch(doNotify(data)),
notify: data => dispatch(doToast(data)),
});
export default connect(select, perform)(RewardsPage);

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { doBalanceSubscribe, doBlackListedOutpointsSubscribe, doNotify } from 'lbry-redux';
import { doBalanceSubscribe, doBlackListedOutpointsSubscribe, doToast } from 'lbry-redux';
import {
doAuthenticate,
doFetchRewardedContent,
@ -23,7 +23,7 @@ const perform = dispatch => ({
blacklistedOutpointsSubscribe: () => dispatch(doBlackListedOutpointsSubscribe()),
deleteCompleteBlobs: () => dispatch(doDeleteCompleteBlobs()),
fetchRewardedContent: () => dispatch(doFetchRewardedContent()),
notify: data => dispatch(doNotify(data)),
notify: data => dispatch(doToast(data)),
setEmailToVerify: email => dispatch(doUserEmailToVerify(email)),
verifyUserEmail: (token, recaptcha) => dispatch(doUserEmailVerify(token, recaptcha)),
verifyUserEmailFailure: error => dispatch(doUserEmailVerifyFailure(error)),

View file

@ -102,12 +102,11 @@ class SplashScreen extends React.PureComponent {
} catch (error) {
const message = 'Invalid Verification Token';
verifyUserEmailFailure(message);
notify({ message, displayType: ['toast'] });
notify({ message });
}
} else {
notify({
message: 'Invalid Verification URI',
displayType: ['toast'],
});
}
} else {

View file

@ -1,7 +1,7 @@
import {
ACTIONS,
Lbry,
doNotify,
doToast,
formatCredits,
selectBalance,
makeSelectCostInfoForUri,
@ -188,9 +188,8 @@ export function doLoadVideo(uri, failureCallback) {
data: { uri },
});
dispatch(doNotify({
dispatch(doToast({
message: `File timeout for uri ${uri}`,
displayType: ['toast']
}));
if (failureCallback) {
@ -207,9 +206,8 @@ export function doLoadVideo(uri, failureCallback) {
data: { uri },
});
dispatch(doNotify({
dispatch(doToast({
message: `Failed to download ${uri}, please try again. If this problem persists, visit https://lbry.io/faq/support for support.`,
displayType: ['toast']
}));
if (failureCallback) {
@ -268,9 +266,8 @@ export function doPurchaseUri(uri, specificCostInfo, failureCallback) {
if (cost > balance) {
dispatch(doSetPlayingUri(null));
dispatch(doNotify({
dispatch(doToast({
message: 'Insufficient credits',
displayType: ['toast']
}));
if (failureCallback) {
failureCallback();