diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 9143564..d81f802 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -103,6 +103,9 @@ const FETCH_CHANNEL_LIST_COMPLETED = 'FETCH_CHANNEL_LIST_COMPLETED'; const CREATE_CHANNEL_STARTED = 'CREATE_CHANNEL_STARTED'; const CREATE_CHANNEL_COMPLETED = 'CREATE_CHANNEL_COMPLETED'; const CREATE_CHANNEL_FAILED = 'CREATE_CHANNEL_FAILED'; +const UPDATE_CHANNEL_STARTED = 'UPDATE_CHANNEL_STARTED'; +const UPDATE_CHANNEL_COMPLETED = 'UPDATE_CHANNEL_COMPLETED'; +const UPDATE_CHANNEL_FAILED = 'UPDATE_CHANNEL_FAILED'; const PUBLISH_STARTED = 'PUBLISH_STARTED'; const PUBLISH_COMPLETED = 'PUBLISH_COMPLETED'; const PUBLISH_FAILED = 'PUBLISH_FAILED'; @@ -328,6 +331,9 @@ var action_types = /*#__PURE__*/Object.freeze({ CREATE_CHANNEL_STARTED: CREATE_CHANNEL_STARTED, CREATE_CHANNEL_COMPLETED: CREATE_CHANNEL_COMPLETED, CREATE_CHANNEL_FAILED: CREATE_CHANNEL_FAILED, + UPDATE_CHANNEL_STARTED: UPDATE_CHANNEL_STARTED, + UPDATE_CHANNEL_COMPLETED: UPDATE_CHANNEL_COMPLETED, + UPDATE_CHANNEL_FAILED: UPDATE_CHANNEL_FAILED, PUBLISH_STARTED: PUBLISH_STARTED, PUBLISH_COMPLETED: PUBLISH_COMPLETED, PUBLISH_FAILED: PUBLISH_FAILED, @@ -707,6 +713,7 @@ const Lbry = { claim_search: params => daemonCallWithResult('claim_search', params), claim_list: params => daemonCallWithResult('claim_list', params), channel_create: params => daemonCallWithResult('channel_create', params), + channel_update: params => daemonCallWithResult('channel_update', params), channel_list: params => daemonCallWithResult('channel_list', params), stream_abandon: params => daemonCallWithResult('stream_abandon', params), channel_abandon: params => daemonCallWithResult('channel_abandon', params), @@ -1334,6 +1341,10 @@ const makeSelectDateForUri = uri => reselect.createSelector(makeSelectClaimForUr return dateObj; }); +const makeSelectAmountForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => { + return claim && claim.amount; +}); + const makeSelectContentTypeForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => { const source = claim && claim.value && claim.value.source; return source ? source.media_type : undefined; @@ -2229,6 +2240,38 @@ function doCreateChannel(name, amount) { }; } +function doUpdateChannel(params) { + return dispatch => { + dispatch({ + type: UPDATE_CHANNEL_STARTED + }); + const updateParams = { + claim_id: params.claim_id, + bid: creditsToString(params.amount), + title: params.title, + cover_url: params.cover, + thumbnail_url: params.thumbnail, + description: params.description, + website_url: params.website, + email: params.email, + replace: true + }; + + return lbryProxy.channel_update(updateParams).then(result => { + const channelClaim = result.outputs[0]; + dispatch({ + type: UPDATE_CHANNEL_COMPLETED, + data: { channelClaim } + }); + }).catch(error => { + dispatch({ + type: UPDATE_CHANNEL_FAILED, + data: error + }); + }); + }; +} + function doFetchChannelListMine() { return dispatch => { dispatch({ @@ -3476,6 +3519,17 @@ reducers[CREATE_CHANNEL_COMPLETED] = (state, action) => { }); }; +reducers[UPDATE_CHANNEL_COMPLETED] = (state, action) => { + const channelClaim = action.data.channelClaim; + const byId = Object.assign({}, state.byId); + + byId[channelClaim.claim_id] = channelClaim; + + return Object.assign({}, state, { + byId + }); +}; + reducers[RESOLVE_URIS_STARTED] = (state, action) => { const { uris } = action.data; @@ -4619,6 +4673,7 @@ exports.doToggleTagFollow = doToggleTagFollow; exports.doTotalBalanceSubscribe = doTotalBalanceSubscribe; exports.doUpdateBalance = doUpdateBalance; exports.doUpdateBlockHeight = doUpdateBlockHeight; +exports.doUpdateChannel = doUpdateChannel; exports.doUpdatePublishForm = doUpdatePublishForm; exports.doUpdateSearchOptions = doUpdateSearchOptions; exports.doUpdateSearchQuery = doUpdateSearchQuery; @@ -4636,6 +4691,7 @@ exports.isClaimNsfw = isClaimNsfw; exports.isNameValid = isNameValid; exports.isURIClaimable = isURIClaimable; exports.isURIValid = isURIValid; +exports.makeSelectAmountForUri = makeSelectAmountForUri; exports.makeSelectChannelForClaimUri = makeSelectChannelForClaimUri; exports.makeSelectClaimForUri = makeSelectClaimForUri; exports.makeSelectClaimIsMine = makeSelectClaimIsMine; diff --git a/dist/flow-typed/Lbry.js b/dist/flow-typed/Lbry.js index 9931f68..6438792 100644 --- a/dist/flow-typed/Lbry.js +++ b/dist/flow-typed/Lbry.js @@ -176,6 +176,8 @@ declare type LbryTypes = { claim_search: (params: {}) => Promise, claim_list: (params?: {}) => Promise, channel_create: (params: {}) => Promise, + // TODO fix this type: + channel_update: (params: {}) => Promise, channel_list: () => Promise, stream_abandon: (params: {}) => Promise, channel_abandon: (params: {}) => Promise, diff --git a/flow-typed/Lbry.js b/flow-typed/Lbry.js index 9931f68..6438792 100644 --- a/flow-typed/Lbry.js +++ b/flow-typed/Lbry.js @@ -176,6 +176,8 @@ declare type LbryTypes = { claim_search: (params: {}) => Promise, claim_list: (params?: {}) => Promise, channel_create: (params: {}) => Promise, + // TODO fix this type: + channel_update: (params: {}) => Promise, channel_list: () => Promise, stream_abandon: (params: {}) => Promise, channel_abandon: (params: {}) => Promise, diff --git a/src/constants/action_types.js b/src/constants/action_types.js index 3fa9547..bdbad5d 100644 --- a/src/constants/action_types.js +++ b/src/constants/action_types.js @@ -80,6 +80,9 @@ export const FETCH_CHANNEL_LIST_COMPLETED = 'FETCH_CHANNEL_LIST_COMPLETED'; export const CREATE_CHANNEL_STARTED = 'CREATE_CHANNEL_STARTED'; export const CREATE_CHANNEL_COMPLETED = 'CREATE_CHANNEL_COMPLETED'; export const CREATE_CHANNEL_FAILED = 'CREATE_CHANNEL_FAILED'; +export const UPDATE_CHANNEL_STARTED = 'UPDATE_CHANNEL_STARTED'; +export const UPDATE_CHANNEL_COMPLETED = 'UPDATE_CHANNEL_COMPLETED'; +export const UPDATE_CHANNEL_FAILED = 'UPDATE_CHANNEL_FAILED'; export const PUBLISH_STARTED = 'PUBLISH_STARTED'; export const PUBLISH_COMPLETED = 'PUBLISH_COMPLETED'; export const PUBLISH_FAILED = 'PUBLISH_FAILED'; diff --git a/src/index.js b/src/index.js index 5b861a1..9754c25 100644 --- a/src/index.js +++ b/src/index.js @@ -49,6 +49,7 @@ export { doResolveUri, doFetchChannelListMine, doCreateChannel, + doUpdateChannel, doClaimSearch, } from 'redux/actions/claims'; @@ -149,6 +150,7 @@ export { makeSelectCoverForUri, makeSelectTitleForUri, makeSelectDateForUri, + makeSelectAmountForUri, makeSelectTagsForUri, makeSelectContentTypeForUri, makeSelectIsUriResolving, diff --git a/src/lbry.js b/src/lbry.js index 617b24b..07fe1f0 100644 --- a/src/lbry.js +++ b/src/lbry.js @@ -71,6 +71,7 @@ const Lbry: LbryTypes = { claim_search: params => daemonCallWithResult('claim_search', params), claim_list: params => daemonCallWithResult('claim_list', params), channel_create: params => daemonCallWithResult('channel_create', params), + channel_update: params => daemonCallWithResult('channel_update', params), channel_list: params => daemonCallWithResult('channel_list', params), stream_abandon: params => daemonCallWithResult('stream_abandon', params), channel_abandon: params => daemonCallWithResult('channel_abandon', params), diff --git a/src/redux/actions/claims.js b/src/redux/actions/claims.js index ea5e1a4..f973890 100644 --- a/src/redux/actions/claims.js +++ b/src/redux/actions/claims.js @@ -248,6 +248,40 @@ export function doCreateChannel(name: string, amount: number) { }; } +export function doUpdateChannel(params: any) { + return (dispatch: Dispatch) => { + dispatch({ + type: ACTIONS.UPDATE_CHANNEL_STARTED, + }); + const updateParams = { + claim_id: params.claim_id, + bid: creditsToString(params.amount), + title: params.title, + cover_url: params.cover, + thumbnail_url: params.thumbnail, + description: params.description, + website_url: params.website, + email: params.email, + replace: true, + }; + + return Lbry.channel_update(updateParams) + .then((result: ChannelCreateResponse) => { + const channelClaim = result.outputs[0]; + dispatch({ + type: ACTIONS.UPDATE_CHANNEL_COMPLETED, + data: { channelClaim }, + }); + }) + .catch(error => { + dispatch({ + type: ACTIONS.UPDATE_CHANNEL_FAILED, + data: error, + }); + }); + }; +} + export function doFetchChannelListMine() { return (dispatch: Dispatch) => { dispatch({ diff --git a/src/redux/reducers/claims.js b/src/redux/reducers/claims.js index 43ee173..99a8f7f 100644 --- a/src/redux/reducers/claims.js +++ b/src/redux/reducers/claims.js @@ -257,6 +257,17 @@ reducers[ACTIONS.CREATE_CHANNEL_COMPLETED] = (state: State, action: any): State }); }; +reducers[ACTIONS.UPDATE_CHANNEL_COMPLETED] = (state: State, action: any): State => { + const channelClaim: ChannelClaim = action.data.channelClaim; + const byId = Object.assign({}, state.byId); + + byId[channelClaim.claim_id] = channelClaim; + + return Object.assign({}, state, { + byId, + }); +}; + reducers[ACTIONS.RESOLVE_URIS_STARTED] = (state: State, action: any): State => { const { uris }: { uris: Array } = action.data; diff --git a/src/redux/selectors/claims.js b/src/redux/selectors/claims.js index 7caa2d2..69fddb5 100644 --- a/src/redux/selectors/claims.js +++ b/src/redux/selectors/claims.js @@ -204,6 +204,14 @@ export const makeSelectDateForUri = (uri: string) => } ); +export const makeSelectAmountForUri = (uri: string) => + createSelector( + makeSelectClaimForUri(uri), + claim => { + return claim && claim.amount; + } + ); + export const makeSelectContentTypeForUri = (uri: string) => createSelector( makeSelectClaimForUri(uri),