add optionalParams to doCreateChannel. Update myClaims after fetching channels #195

Merged
akinwale merged 6 commits from channel-creator into master 2019-09-15 13:00:14 +02:00
5 changed files with 126 additions and 16 deletions

67
dist/bundle.es.js vendored
View file

@ -1790,6 +1790,10 @@ const makeSelectSupportsForUri = uri => reselect.createSelector(selectSupportsBy
return total;
});
const selectUpdatingChannel = reselect.createSelector(selectState$2, state => state.updatingChannel);
const selectUpdateChannelError = reselect.createSelector(selectState$2, state => state.updateChannelError);
function formatCredits(amount, precision, shortFormat = false) {
let actualAmount = parseFloat(amount),
suffix = '';
@ -2393,16 +2397,42 @@ function doFetchClaimsByChannel(uri, page = 1) {
};
neb-b commented 2019-09-03 19:33:40 +02:00 (Migrated from github.com)
Review

Should this be called coverUrl to match the sdk value?

Should this be called `coverUrl` to match the sdk value?
akinwale commented 2019-09-09 11:04:57 +02:00 (Migrated from github.com)
Review

I suppose it should. I'll also have to update this in doUpdateChannel.

I suppose it should. I'll also have to update this in `doUpdateChannel`.
}
function doCreateChannel(name, amount) {
function doCreateChannel(name, amount, optionalParams) {
return dispatch => {
dispatch({
type: CREATE_CHANNEL_STARTED
});
return lbryProxy.channel_create({
const createParams = {
name,
bid: creditsToString(amount)
})
};
if (optionalParams) {
if (optionalParams.title) {
createParams.title = optionalParams.title;
}
if (optionalParams.coverUrl) {
createParams.cover_url = optionalParams.coverUrl;
}
if (optionalParams.thumbnailUrl) {
createParams.thumbnail_url = optionalParams.thumbnailUrl;
}
if (optionalParams.description) {
createParams.description = optionalParams.description;
}
if (optionalParams.website) {
createParams.website_url = optionalParams.website;
}
if (optionalParams.email) {
createParams.email = optionalParams.email;
}
if (optionalParams.tags) {
createParams.tags = optionalParams.tags.map(tag => tag.name);
}
}
return lbryProxy.channel_create(createParams)
// outputs[0] is the certificate
// outputs[1] is the change from the tx, not in the app currently
.then(result => {
@ -2429,8 +2459,8 @@ function doUpdateChannel(params) {
claim_id: params.claim_id,
bid: creditsToString(params.amount),
title: params.title,
cover_url: params.cover,
thumbnail_url: params.thumbnail,
cover_url: params.coverUrl,
thumbnail_url: params.thumbnailUrl,
description: params.description,
website_url: params.website,
email: params.email,
@ -3532,7 +3562,9 @@ const defaultState = {
claimSearchError: false,
claimSearchByQuery: {},
claimSearchByQueryLastPageReached: {},
fetchingClaimSearchByQuery: {}
fetchingClaimSearchByQuery: {},
updateChannelError: '',
updatingChannel: false
};
function handleClaimAction(state, action) {
@ -3665,7 +3697,8 @@ reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => {
return Object.assign({}, state, {
byId,
fetchingMyChannels: false,
myChannelClaims
myChannelClaims,
myClaims: claims
});
};
@ -3763,6 +3796,13 @@ reducers[CREATE_CHANNEL_COMPLETED] = (state, action) => {
});
};
reducers[UPDATE_CHANNEL_STARTED] = (state, action) => {
return Object.assign({}, state, {
updateChannelError: '',
updatingChannel: true
});
};
reducers[UPDATE_CHANNEL_COMPLETED] = (state, action) => {
const channelClaim = action.data.channelClaim;
const byId = Object.assign({}, state.byId);
@ -3770,7 +3810,16 @@ reducers[UPDATE_CHANNEL_COMPLETED] = (state, action) => {
byId[channelClaim.claim_id] = channelClaim;
return Object.assign({}, state, {
byId
byId,
updateChannelError: '',
updatingChannel: false
});
};
reducers[UPDATE_CHANNEL_FAILED] = (state, action) => {
return Object.assign({}, state, {
updateChannelError: action.data.message,
updatingChannel: false
});
};
@ -5014,6 +5063,8 @@ exports.selectTransactionItems = selectTransactionItems;
exports.selectTransactionListFilter = selectTransactionListFilter;
exports.selectTransactionsById = selectTransactionsById;
exports.selectUnfollowedTags = selectUnfollowedTags;
exports.selectUpdateChannelError = selectUpdateChannelError;
exports.selectUpdatingChannel = selectUpdatingChannel;
exports.selectUrisLoading = selectUrisLoading;
exports.selectWalletDecryptPending = selectWalletDecryptPending;
exports.selectWalletDecryptResult = selectWalletDecryptResult;

View file

@ -200,6 +200,8 @@ export {
selectFetchingClaimSearchByQuery,
selectClaimSearchByQuery,
selectClaimSearchByQueryLastPageReached,
selectUpdatingChannel,
selectUpdateChannelError,
} from 'redux/selectors/claims';
export { makeSelectCommentsForUri } from 'redux/selectors/comments';

View file

@ -226,17 +226,43 @@ export function doFetchClaimsByChannel(uri: string, page: number = 1) {
};
}
export function doCreateChannel(name: string, amount: number) {
export function doCreateChannel(name: string, amount: number, optionalParams: any) {
return (dispatch: Dispatch) => {
dispatch({
type: ACTIONS.CREATE_CHANNEL_STARTED,
});
return (
Lbry.channel_create({
const createParams = {
name,
bid: creditsToString(amount),
})
};
if (optionalParams) {
if (optionalParams.title) {
createParams.title = optionalParams.title;
}
if (optionalParams.coverUrl) {
createParams.cover_url = optionalParams.coverUrl;
}
if (optionalParams.thumbnailUrl) {
createParams.thumbnail_url = optionalParams.thumbnailUrl;
}
if (optionalParams.description) {
createParams.description = optionalParams.description;
}
if (optionalParams.website) {
createParams.website_url = optionalParams.website;
}
if (optionalParams.email) {
createParams.email = optionalParams.email;
}
if (optionalParams.tags) {
createParams.tags = optionalParams.tags.map(tag => tag.name);
}
}
return (
Lbry.channel_create(createParams)
// outputs[0] is the certificate
// outputs[1] is the change from the tx, not in the app currently
.then((result: ChannelCreateResponse) => {
@ -265,8 +291,8 @@ export function doUpdateChannel(params: any) {
claim_id: params.claim_id,
bid: creditsToString(params.amount),
title: params.title,
cover_url: params.cover,
thumbnail_url: params.thumbnail,
cover_url: params.coverUrl,
thumbnail_url: params.thumbnailUrl,
description: params.description,
website_url: params.website,
email: params.email,

View file

@ -30,6 +30,8 @@ type State = {
[number]: Array<string>,
},
},
updateChannelError: string,
updatingChannel: boolean,
};
const reducers = {};
@ -50,6 +52,8 @@ const defaultState = {
claimSearchByQuery: {},
claimSearchByQueryLastPageReached: {},
fetchingClaimSearchByQuery: {},
updateChannelError: '',
updatingChannel: false,
};
function handleClaimAction(state: State, action: any): State {
@ -194,6 +198,7 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St
byId,
fetchingMyChannels: false,
myChannelClaims,
myClaims: claims,
});
};
@ -291,6 +296,13 @@ reducers[ACTIONS.CREATE_CHANNEL_COMPLETED] = (state: State, action: any): State
});
};
reducers[ACTIONS.UPDATE_CHANNEL_STARTED] = (state: State, action: any): State => {
return Object.assign({}, state, {
updateChannelError: '',
updatingChannel: true,
});
};
reducers[ACTIONS.UPDATE_CHANNEL_COMPLETED] = (state: State, action: any): State => {
const channelClaim: ChannelClaim = action.data.channelClaim;
const byId = Object.assign({}, state.byId);
@ -299,6 +311,15 @@ reducers[ACTIONS.UPDATE_CHANNEL_COMPLETED] = (state: State, action: any): State
return Object.assign({}, state, {
byId,
updateChannelError: '',
updatingChannel: false,
});
};
reducers[ACTIONS.UPDATE_CHANNEL_FAILED] = (state: State, action: any): State => {
return Object.assign({}, state, {
updateChannelError: action.data.message,
updatingChannel: false,
});
};

View file

@ -563,3 +563,13 @@ export const makeSelectSupportsForUri = (uri: string) =>
return total;
}
);
export const selectUpdatingChannel = createSelector(
selectState,
state => state.updatingChannel
);
export const selectUpdateChannelError = createSelector(
selectState,
state => state.updateChannelError
);