support for 0.45 sdk #240

Merged
neb-b merged 6 commits from api-improvements into master 2019-11-06 18:14:00 +01:00
19 changed files with 344 additions and 161 deletions

156
dist/bundle.es.js vendored
View file

@ -657,9 +657,11 @@ var transaction_types = /*#__PURE__*/Object.freeze({
// PAGE SIZE // PAGE SIZE
const PAGE_SIZE$1 = 50; const PAGE_SIZE$1 = 50;
const LATEST_PAGE_SIZE = 20;
var transaction_list = /*#__PURE__*/Object.freeze({ var transaction_list = /*#__PURE__*/Object.freeze({
PAGE_SIZE: PAGE_SIZE$1 PAGE_SIZE: PAGE_SIZE$1,
LATEST_PAGE_SIZE: LATEST_PAGE_SIZE
}); });
const SPEECH_STATUS = 'https://spee.ch/api/config/site/publishing'; const SPEECH_STATUS = 'https://spee.ch/api/config/site/publishing';
@ -770,8 +772,10 @@ const Lbry = {
channel_import: params => daemonCallWithResult('channel_import', params), channel_import: params => daemonCallWithResult('channel_import', params),
channel_list: params => daemonCallWithResult('channel_list', params), channel_list: params => daemonCallWithResult('channel_list', params),
stream_abandon: params => daemonCallWithResult('stream_abandon', params), stream_abandon: params => daemonCallWithResult('stream_abandon', params),
stream_list: params => daemonCallWithResult('stream_list', params),
channel_abandon: params => daemonCallWithResult('channel_abandon', params), channel_abandon: params => daemonCallWithResult('channel_abandon', params),
support_create: params => daemonCallWithResult('support_create', params), support_create: params => daemonCallWithResult('support_create', params),
support_list: params => daemonCallWithResult('support_list', params),
// File fetching and manipulation // File fetching and manipulation
file_list: (params = {}) => daemonCallWithResult('file_list', params), file_list: (params = {}) => daemonCallWithResult('file_list', params),
@ -829,16 +833,16 @@ const Lbry = {
// Flow thinks this could be empty, but it will always reuturn a promise // Flow thinks this could be empty, but it will always reuturn a promise
// $FlowFixMe // $FlowFixMe
return Lbry.connectPromise; return Lbry.connectPromise;
} },
};
Lbry.publish = (params = {}) => new Promise((resolve, reject) => { publish: (params = {}) => new Promise((resolve, reject) => {
if (Lbry.overrides.publish) { if (Lbry.overrides.publish) {
Lbry.overrides.publish(params).then(resolve, reject); Lbry.overrides.publish(params).then(resolve, reject);
} else { } else {
apiCall('publish', params, resolve, reject); apiCall('publish', params, resolve, reject);
} }
}); })
};
function checkAndParse(response) { function checkAndParse(response) {
if (response.status >= 200 && response.status < 300) { if (response.status >= 200 && response.status < 300) {
@ -1712,6 +1716,10 @@ const makeSelectFilteredTransactionsForPage = (page = 1) => reselect.createSelec
return filteredTransactions && filteredTransactions.length ? filteredTransactions.slice(start, end) : []; return filteredTransactions && filteredTransactions.length ? filteredTransactions.slice(start, end) : [];
}); });
const makeSelectLatestTransactions = reselect.createSelector(selectTransactionItems, transactions => {
return transactions && transactions.length ? transactions.slice(0, LATEST_PAGE_SIZE) : [];
});
const selectFilteredTransactionCount = reselect.createSelector(selectFilteredTransactions, filteredTransactions => filteredTransactions.length); const selectFilteredTransactionCount = reselect.createSelector(selectFilteredTransactions, filteredTransactions => filteredTransactions.length);
var _extends$3 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _extends$3 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
@ -2178,30 +2186,38 @@ function creditsToString(amount) {
return creditString; return creditString;
} }
let walletBalancePromise = null;
function doUpdateBalance() { function doUpdateBalance() {
return (dispatch, getState) => { return (dispatch, getState) => {
const { const {
wallet: { totalBalance: totalInStore } wallet: { totalBalance: totalInStore }
} = getState(); } = getState();
return lbryProxy.wallet_balance({ reserved_subtotals: true }).then(response => {
const { available, reserved, reserved_subtotals, total } = response;
const { claims, supports, tips } = reserved_subtotals;
const totalFloat = parseFloat(total);
if (totalInStore !== totalFloat) { if (walletBalancePromise === null) {
dispatch({ walletBalancePromise = lbryProxy.wallet_balance().then(response => {
type: UPDATE_BALANCE, walletBalancePromise = null;
data: {
totalBalance: totalFloat, const { available, reserved, reserved_subtotals, total } = response;
balance: parseFloat(available), const { claims, supports, tips } = reserved_subtotals;
reservedBalance: parseFloat(reserved), const totalFloat = parseFloat(total);
claimsBalance: parseFloat(claims),
supportsBalance: parseFloat(supports), if (totalInStore !== totalFloat) {
tipsBalance: parseFloat(tips) dispatch({
} type: UPDATE_BALANCE,
}); data: {
} totalBalance: totalFloat,
}); balance: parseFloat(available),
reservedBalance: parseFloat(reserved),
claimsBalance: parseFloat(claims),
supportsBalance: parseFloat(supports),
tipsBalance: parseFloat(tips)
}
});
}
});
}
return walletBalancePromise;
}; };
} }
@ -2212,35 +2228,35 @@ function doBalanceSubscribe() {
}; };
} }
function doFetchTransactions() { function doFetchTransactions(page = 1, pageSize = 99999) {
return dispatch => { return dispatch => {
dispatch(doFetchSupports()); dispatch(doFetchSupports());
dispatch({ dispatch({
type: FETCH_TRANSACTIONS_STARTED type: FETCH_TRANSACTIONS_STARTED
}); });
lbryProxy.utxo_release().then(() => lbryProxy.transaction_list()).then(results => { lbryProxy.utxo_release().then(() => lbryProxy.transaction_list({ page, page_size: pageSize })).then(result => {
dispatch({ dispatch({
type: FETCH_TRANSACTIONS_COMPLETED, type: FETCH_TRANSACTIONS_COMPLETED,
data: { data: {
transactions: results transactions: result.items
} }
}); });
}); });
}; };
} }
function doFetchSupports() { function doFetchSupports(page = 1, pageSize = 99999) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: FETCH_SUPPORTS_STARTED type: FETCH_SUPPORTS_STARTED
}); });
lbryProxy.support_list().then(results => { lbryProxy.support_list({ page, page_size: pageSize }).then(result => {
dispatch({ dispatch({
type: FETCH_SUPPORTS_COMPLETED, type: FETCH_SUPPORTS_COMPLETED,
data: { data: {
supports: results supports: result.items
} }
}); });
}); });
@ -2599,13 +2615,15 @@ function doResolveUri(uri) {
return doResolveUris([uri]); return doResolveUris([uri]);
} }
function doFetchClaimListMine() { function doFetchClaimListMine(page = 1, pageSize = 99999) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: FETCH_CLAIM_LIST_MINE_STARTED type: FETCH_CLAIM_LIST_MINE_STARTED
}); });
lbryProxy.claim_list().then(claims => { lbryProxy.stream_list({ page, page_size: pageSize }).then(result => {
const claims = result.items;
dispatch({ dispatch({
type: FETCH_CLAIM_LIST_MINE_COMPLETED, type: FETCH_CLAIM_LIST_MINE_COMPLETED,
data: { data: {
@ -2670,10 +2688,12 @@ function doAbandonClaim(txid, nout) {
message: abandonMessage message: abandonMessage
})); }));
// After abandoning, call claim_list to show the claim as abandoned // After abandoning, fetch transactions to show the new abandon transaction
// Also fetch transactions to show the new abandon transaction // Only fetch the latest few transactions since we don't care about old ones
if (isClaim) dispatch(doFetchClaimListMine()); // Not very robust, but better than calling the entire list for large wallets
dispatch(doFetchTransactions()); const page = 1;
const pageSize = 10;
dispatch(doFetchTransactions(page, pageSize));
}; };
const abandonParams = { const abandonParams = {
@ -2855,25 +2875,27 @@ function doImportChannel(certificate) {
}; };
} }
function doFetchChannelListMine() { function doFetchChannelListMine(page = 1, pageSize = 99999) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: FETCH_CHANNEL_LIST_STARTED type: FETCH_CHANNEL_LIST_STARTED
}); });
const callback = channels => { const callback = response => {
dispatch({ dispatch({
type: FETCH_CHANNEL_LIST_COMPLETED, type: FETCH_CHANNEL_LIST_COMPLETED,
data: { claims: channels } data: { claims: response.items }
}); });
}; };
lbryProxy.channel_list().then(callback); lbryProxy.channel_list({ page, page_size: pageSize }).then(callback);
}; };
} }
function doClaimSearch(options = { function doClaimSearch(options = {
page_size: 10 no_totals: true,
page_size: 10,
page: 1
}) { }) {
const query = createNormalizedClaimSearchKey(options); const query = createNormalizedClaimSearchKey(options);
return dispatch => { return dispatch => {
@ -2995,7 +3017,7 @@ const selectFileListDownloadedSort = reselect.createSelector(selectState$3, stat
const selectDownloadedUris = reselect.createSelector(selectFileInfosDownloaded, const selectDownloadedUris = reselect.createSelector(selectFileInfosDownloaded,
// We should use permament_url but it doesn't exist in file_list // We should use permament_url but it doesn't exist in file_list
info => info.slice().reverse().map(claim => `lbry://${claim.claim_name}#${claim.claim_id}`)); info => info.slice().map(claim => `lbry://${claim.claim_name}#${claim.claim_id}`));
const makeSelectMediaTypeForUri = uri => reselect.createSelector(makeSelectFileInfoForUri(uri), makeSelectContentTypeForUri(uri), (fileInfo, contentType) => { const makeSelectMediaTypeForUri = uri => reselect.createSelector(makeSelectFileInfoForUri(uri), makeSelectContentTypeForUri(uri), (fileInfo, contentType) => {
if (!fileInfo && !contentType) { if (!fileInfo && !contentType) {
@ -3046,7 +3068,11 @@ const makeSelectSearchDownloadUrlsForPage = (query, page = 1) => reselect.create
const start = (Number(page) - 1) * Number(PAGE_SIZE); const start = (Number(page) - 1) * Number(PAGE_SIZE);
const end = Number(page) * Number(PAGE_SIZE); const end = Number(page) * Number(PAGE_SIZE);
return matchingFileInfos && matchingFileInfos.length ? matchingFileInfos.slice(start, end).map(fileInfo => buildURI({ streamName: fileInfo.claim_name, channelName: fileInfo.channel_name, channelClaimId: fileInfo.channel_claim_id })) : []; return matchingFileInfos && matchingFileInfos.length ? matchingFileInfos.slice(start, end).map(fileInfo => buildURI({
streamName: fileInfo.claim_name,
channelName: fileInfo.channel_name,
channelClaimId: fileInfo.channel_claim_id
})) : [];
}); });
const makeSelectSearchDownloadUrlsCount = query => reselect.createSelector(selectFileInfosDownloaded, fileInfos => { const makeSelectSearchDownloadUrlsCount = query => reselect.createSelector(selectFileInfosDownloaded, fileInfos => {
@ -3189,12 +3215,15 @@ function doFetchFileInfo(uri) {
} }
}); });
lbryProxy.file_list({ outpoint, full_status: true }).then(fileInfos => { lbryProxy.file_list({ outpoint, full_status: true, page: 1, page_size: 1 }).then(result => {
const { items: fileInfos } = result;
const fileInfo = fileInfos[0];
dispatch({ dispatch({
type: FETCH_FILE_INFO_COMPLETED, type: FETCH_FILE_INFO_COMPLETED,
data: { data: {
outpoint, outpoint,
fileInfo: fileInfos && fileInfos.length ? fileInfos[0] : null fileInfo: fileInfo || null
} }
}); });
}); });
@ -3202,7 +3231,7 @@ function doFetchFileInfo(uri) {
}; };
} }
function doFileList() { function doFileList(page = 1, pageSize = 99999) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
const isFetching = selectIsFetchingFileList(state); const isFetching = selectIsFetchingFileList(state);
@ -3212,11 +3241,12 @@ function doFileList() {
type: FILE_LIST_STARTED type: FILE_LIST_STARTED
}); });
lbryProxy.file_list().then(fileInfos => { lbryProxy.file_list({ page, page_size: pageSize }).then(result => {
const { items: fileInfos } = result;
dispatch({ dispatch({
type: FILE_LIST_SUCCEEDED, type: FILE_LIST_SUCCEEDED,
data: { data: {
fileInfos fileInfos: fileInfos.reverse()
} }
}); });
}); });
@ -3437,6 +3467,7 @@ const doUploadThumbnail = (filePath, thumbnailBlob, fsAdapter, fs, path) => disp
const name = makeid(); const name = makeid();
const file = thumbnailBlob || thumbnail && new File([thumbnail], fileName, { type: fileType }); const file = thumbnailBlob || thumbnail && new File([thumbnail], fileName, { type: fileType });
data.append('name', name); data.append('name', name);
// $FlowFixMe
data.append('file', file); data.append('file', file);
return fetch(SPEECH_PUBLISH, { return fetch(SPEECH_PUBLISH, {
@ -3624,8 +3655,9 @@ const doCheckPendingPublishes = onConfirmed => (dispatch, getState) => {
let publishCheckInterval; let publishCheckInterval;
const checkFileList = () => { const checkFileList = () => {
lbryProxy.claim_list().then(claims => { lbryProxy.stream_list({ page: 1, page_size: 10 }).then(result => {
// $FlowFixMe const claims = result.items;
claims.forEach(claim => { claims.forEach(claim => {
// If it's confirmed, check if it was pending previously // If it's confirmed, check if it was pending previously
if (claim.confirmations > 0 && pendingById[claim.claim_id]) { if (claim.confirmations > 0 && pendingById[claim.claim_id]) {
@ -3866,7 +3898,7 @@ const doDeleteTag = name => ({
// //
function doCommentList(uri) { function doCommentList(uri, page = 1, pageSize = 99999) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
const claim = selectClaimsByUri(state)[uri]; const claim = selectClaimsByUri(state)[uri];
@ -3876,12 +3908,15 @@ function doCommentList(uri) {
type: COMMENT_LIST_STARTED type: COMMENT_LIST_STARTED
}); });
lbryProxy.comment_list({ lbryProxy.comment_list({
claim_id: claimId claim_id: claimId,
}).then(results => { page,
page_size: pageSize
}).then(result => {
const { items: comments } = result;
dispatch({ dispatch({
type: COMMENT_LIST_COMPLETED, type: COMMENT_LIST_COMPLETED,
data: { data: {
comments: results, comments,
claimId: claimId, claimId: claimId,
uri: uri uri: uri
} }
@ -4364,8 +4399,8 @@ const commentReducer = handleActions({
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const commentsByUri = Object.assign({}, state.commentsByUri); const commentsByUri = Object.assign({}, state.commentsByUri);
if (comments['items']) { if (comments) {
byId[claimId] = comments['items']; byId[claimId] = comments;
commentsByUri[uri] = claimId; commentsByUri[uri] = claimId;
} }
return _extends$7({}, state, { return _extends$7({}, state, {
@ -5425,6 +5460,7 @@ exports.makeSelectFilteredTransactionsForPage = makeSelectFilteredTransactionsFo
exports.makeSelectFirstRecommendedFileForUri = makeSelectFirstRecommendedFileForUri; exports.makeSelectFirstRecommendedFileForUri = makeSelectFirstRecommendedFileForUri;
exports.makeSelectIsFollowingTag = makeSelectIsFollowingTag; exports.makeSelectIsFollowingTag = makeSelectIsFollowingTag;
exports.makeSelectIsUriResolving = makeSelectIsUriResolving; exports.makeSelectIsUriResolving = makeSelectIsUriResolving;
exports.makeSelectLatestTransactions = makeSelectLatestTransactions;
exports.makeSelectLoadingForUri = makeSelectLoadingForUri; exports.makeSelectLoadingForUri = makeSelectLoadingForUri;
exports.makeSelectMediaTypeForUri = makeSelectMediaTypeForUri; exports.makeSelectMediaTypeForUri = makeSelectMediaTypeForUri;
exports.makeSelectMetadataForUri = makeSelectMetadataForUri; exports.makeSelectMetadataForUri = makeSelectMetadataForUri;

View file

@ -2,6 +2,7 @@
declare type FileListItem = { declare type FileListItem = {
metadata: StreamMetadata, metadata: StreamMetadata,
added_on: number,
blobs_completed: number, blobs_completed: number,
blobs_in_stream: number, blobs_in_stream: number,
blobs_remaining: number, blobs_remaining: number,

View file

@ -107,7 +107,11 @@ declare type ClaimSearchResponse = {
}; };
declare type ClaimListResponse = { declare type ClaimListResponse = {
claims: Array<ChannelClaim | Claim>, items: Array<ChannelClaim | Claim>,
page: number,
page_size: number,
total_items: number,
total_pages: number,
}; };
declare type ChannelCreateResponse = GenericTxResponse & { declare type ChannelCreateResponse = GenericTxResponse & {
@ -119,15 +123,47 @@ declare type ChannelUpdateResponse = GenericTxResponse & {
}; };
declare type CommentCreateResponse = Comment; declare type CommentCreateResponse = Comment;
declare type CommentListResponse = Array<Comment>; declare type CommentListResponse = {
items: Array<Comment>,
page: number,
page_size: number,
total_items: number,
total_pages: number,
};
declare type ChannelListResponse = Array<ChannelClaim>; declare type ChannelListResponse = {
items: Array<ChannelClaim>,
page: number,
page_size: number,
total_items: number,
total_pages: number,
};
declare type FileListResponse = Array<FileListItem>; declare type FileListResponse = {
items: Array<FileListItem>,
page: number,
page_size: number,
total_items: number,
total_pages: number,
};
declare type TxListResponse = Array<Transaction>; declare type TxListResponse = {
items: Array<Transaction>,
page: number,
page_size: number,
total_items: number,
total_pages: number,
};
declare type BlobListResponse = Array<string>; declare type SupportListResponse = {
items: Array<Support>,
page: number,
page_size: number,
total_items: number,
total_pages: number,
};
declare type BlobListResponse = { items: Array<string> };
declare type WalletListResponse = Array<{ declare type WalletListResponse = Array<{
id: string, id: string,
@ -146,6 +182,14 @@ declare type SyncApplyResponse = {
declare type SupportAbandonResponse = GenericTxResponse; declare type SupportAbandonResponse = GenericTxResponse;
declare type StreamListResponse = {
items: Array<StreamClaim>,
page: number,
page_size: number,
total_items: number,
total_pages: number,
};
// //
// Types used in the generic Lbry object that is exported // Types used in the generic Lbry object that is exported
// //
@ -168,17 +212,20 @@ declare type LbryTypes = {
version: () => Promise<VersionResponse>, version: () => Promise<VersionResponse>,
resolve: (params: {}) => Promise<ResolveResponse>, resolve: (params: {}) => Promise<ResolveResponse>,
get: (params: {}) => Promise<GetResponse>, get: (params: {}) => Promise<GetResponse>,
publish?: (params: {}) => Promise<PublishResponse>, publish: (params: {}) => Promise<PublishResponse>,
claim_search: (params: {}) => Promise<ClaimSearchResponse>, claim_search: (params: {}) => Promise<ClaimSearchResponse>,
claim_list: (params?: {}) => Promise<ClaimListResponse>, claim_list: (params: {}) => Promise<ClaimListResponse>,
channel_create: (params: {}) => Promise<ChannelCreateResponse>, channel_create: (params: {}) => Promise<ChannelCreateResponse>,
channel_update: (params: {}) => Promise<ChannelUpdateResponse>, channel_update: (params: {}) => Promise<ChannelUpdateResponse>,
channel_import: (params: {}) => Promise<string>, channel_import: (params: {}) => Promise<string>,
channel_list: () => Promise<ChannelListResponse>, channel_list: (params: {}) => Promise<ChannelListResponse>,
stream_abandon: (params: {}) => Promise<GenericTxResponse>, stream_abandon: (params: {}) => Promise<GenericTxResponse>,
stream_list: (params: {}) => Promise<StreamListResponse>,
channel_abandon: (params: {}) => Promise<GenericTxResponse>, channel_abandon: (params: {}) => Promise<GenericTxResponse>,
support_create: (params: {}) => Promise<GenericTxResponse>, support_create: (params: {}) => Promise<GenericTxResponse>,
support_list: (params: {}) => Promise<SupportListResponse>,
support_abandon: (params: {}) => Promise<SupportAbandonResponse>,
// File fetching and manipulation // File fetching and manipulation
file_list: (params: {}) => Promise<FileListResponse>, file_list: (params: {}) => Promise<FileListResponse>,
@ -205,7 +252,6 @@ declare type LbryTypes = {
address_unused: (params: {}) => Promise<string>, // New address address_unused: (params: {}) => Promise<string>, // New address
address_list: (params: {}) => Promise<string>, address_list: (params: {}) => Promise<string>,
transaction_list: (params: {}) => Promise<TxListResponse>, transaction_list: (params: {}) => Promise<TxListResponse>,
support_abandon: (params: {}) => Promise<SupportAbandonResponse>,
// Sync // Sync
sync_hash: (params: {}) => Promise<string>, sync_hash: (params: {}) => Promise<string>,

View file

@ -19,6 +19,7 @@ declare type Support = {
is_change: string, is_change: string,
is_mine: string, is_mine: string,
name: string, name: string,
normalized_name: string,
nout: string, nout: string,
permanent_url: string, permanent_url: string,
timestamp: number, timestamp: number,

1
flow-typed/File.js vendored
View file

@ -2,6 +2,7 @@
declare type FileListItem = { declare type FileListItem = {
metadata: StreamMetadata, metadata: StreamMetadata,
added_on: number,
blobs_completed: number, blobs_completed: number,
blobs_in_stream: number, blobs_in_stream: number,
blobs_remaining: number, blobs_remaining: number,

66
flow-typed/Lbry.js vendored
View file

@ -107,7 +107,11 @@ declare type ClaimSearchResponse = {
}; };
declare type ClaimListResponse = { declare type ClaimListResponse = {
claims: Array<ChannelClaim | Claim>, items: Array<ChannelClaim | Claim>,
page: number,
page_size: number,
total_items: number,
total_pages: number,
}; };
declare type ChannelCreateResponse = GenericTxResponse & { declare type ChannelCreateResponse = GenericTxResponse & {
@ -119,15 +123,47 @@ declare type ChannelUpdateResponse = GenericTxResponse & {
}; };
declare type CommentCreateResponse = Comment; declare type CommentCreateResponse = Comment;
declare type CommentListResponse = Array<Comment>; declare type CommentListResponse = {
items: Array<Comment>,
page: number,
page_size: number,
total_items: number,
total_pages: number,
};
declare type ChannelListResponse = Array<ChannelClaim>; declare type ChannelListResponse = {
items: Array<ChannelClaim>,
page: number,
page_size: number,
total_items: number,
total_pages: number,
};
declare type FileListResponse = Array<FileListItem>; declare type FileListResponse = {
items: Array<FileListItem>,
page: number,
page_size: number,
total_items: number,
total_pages: number,
};
declare type TxListResponse = Array<Transaction>; declare type TxListResponse = {
items: Array<Transaction>,
page: number,
page_size: number,
total_items: number,
total_pages: number,
};
declare type BlobListResponse = Array<string>; declare type SupportListResponse = {
items: Array<Support>,
page: number,
page_size: number,
total_items: number,
total_pages: number,
};
declare type BlobListResponse = { items: Array<string> };
declare type WalletListResponse = Array<{ declare type WalletListResponse = Array<{
id: string, id: string,
@ -146,6 +182,14 @@ declare type SyncApplyResponse = {
declare type SupportAbandonResponse = GenericTxResponse; declare type SupportAbandonResponse = GenericTxResponse;
declare type StreamListResponse = {
items: Array<StreamClaim>,
page: number,
page_size: number,
total_items: number,
total_pages: number,
};
// //
// Types used in the generic Lbry object that is exported // Types used in the generic Lbry object that is exported
// //
@ -168,17 +212,20 @@ declare type LbryTypes = {
version: () => Promise<VersionResponse>, version: () => Promise<VersionResponse>,
resolve: (params: {}) => Promise<ResolveResponse>, resolve: (params: {}) => Promise<ResolveResponse>,
get: (params: {}) => Promise<GetResponse>, get: (params: {}) => Promise<GetResponse>,
publish?: (params: {}) => Promise<PublishResponse>, publish: (params: {}) => Promise<PublishResponse>,
claim_search: (params: {}) => Promise<ClaimSearchResponse>, claim_search: (params: {}) => Promise<ClaimSearchResponse>,
claim_list: (params?: {}) => Promise<ClaimListResponse>, claim_list: (params: {}) => Promise<ClaimListResponse>,
channel_create: (params: {}) => Promise<ChannelCreateResponse>, channel_create: (params: {}) => Promise<ChannelCreateResponse>,
channel_update: (params: {}) => Promise<ChannelUpdateResponse>, channel_update: (params: {}) => Promise<ChannelUpdateResponse>,
channel_import: (params: {}) => Promise<string>, channel_import: (params: {}) => Promise<string>,
channel_list: () => Promise<ChannelListResponse>, channel_list: (params: {}) => Promise<ChannelListResponse>,
stream_abandon: (params: {}) => Promise<GenericTxResponse>, stream_abandon: (params: {}) => Promise<GenericTxResponse>,
stream_list: (params: {}) => Promise<StreamListResponse>,
channel_abandon: (params: {}) => Promise<GenericTxResponse>, channel_abandon: (params: {}) => Promise<GenericTxResponse>,
support_create: (params: {}) => Promise<GenericTxResponse>, support_create: (params: {}) => Promise<GenericTxResponse>,
support_list: (params: {}) => Promise<SupportListResponse>,
support_abandon: (params: {}) => Promise<SupportAbandonResponse>,
// File fetching and manipulation // File fetching and manipulation
file_list: (params: {}) => Promise<FileListResponse>, file_list: (params: {}) => Promise<FileListResponse>,
@ -205,7 +252,6 @@ declare type LbryTypes = {
address_unused: (params: {}) => Promise<string>, // New address address_unused: (params: {}) => Promise<string>, // New address
address_list: (params: {}) => Promise<string>, address_list: (params: {}) => Promise<string>,
transaction_list: (params: {}) => Promise<TxListResponse>, transaction_list: (params: {}) => Promise<TxListResponse>,
support_abandon: (params: {}) => Promise<SupportAbandonResponse>,
// Sync // Sync
sync_hash: (params: {}) => Promise<string>, sync_hash: (params: {}) => Promise<string>,

View file

@ -19,6 +19,7 @@ declare type Support = {
is_change: string, is_change: string,
is_mine: string, is_mine: string,
name: string, name: string,
normalized_name: string,
nout: string, nout: string,
permanent_url: string, permanent_url: string,
timestamp: number, timestamp: number,

View file

@ -1,2 +1,3 @@
// PAGE SIZE // PAGE SIZE
export const PAGE_SIZE = 50; export const PAGE_SIZE = 50;
export const LATEST_PAGE_SIZE = 20;

View file

@ -301,6 +301,7 @@ export {
selectWalletUnlockResult, selectWalletUnlockResult,
selectTransactionListFilter, selectTransactionListFilter,
selectFilteredTransactions, selectFilteredTransactions,
makeSelectLatestTransactions,
makeSelectFilteredTransactionsForPage, makeSelectFilteredTransactionsForPage,
selectFilteredTransactionCount, selectFilteredTransactionCount,
} from 'redux/selectors/wallet'; } from 'redux/selectors/wallet';

View file

@ -82,8 +82,10 @@ const Lbry: LbryTypes = {
channel_import: params => daemonCallWithResult('channel_import', params), channel_import: params => daemonCallWithResult('channel_import', params),
channel_list: params => daemonCallWithResult('channel_list', params), channel_list: params => daemonCallWithResult('channel_list', params),
stream_abandon: params => daemonCallWithResult('stream_abandon', params), stream_abandon: params => daemonCallWithResult('stream_abandon', params),
stream_list: params => daemonCallWithResult('stream_list', params),
channel_abandon: params => daemonCallWithResult('channel_abandon', params), channel_abandon: params => daemonCallWithResult('channel_abandon', params),
support_create: params => daemonCallWithResult('support_create', params), support_create: params => daemonCallWithResult('support_create', params),
support_list: params => daemonCallWithResult('support_list', params),
// File fetching and manipulation // File fetching and manipulation
file_list: (params = {}) => daemonCallWithResult('file_list', params), file_list: (params = {}) => daemonCallWithResult('file_list', params),
@ -144,16 +146,16 @@ const Lbry: LbryTypes = {
// $FlowFixMe // $FlowFixMe
return Lbry.connectPromise; return Lbry.connectPromise;
}, },
};
Lbry.publish = (params = {}) => publish: (params = {}) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
if (Lbry.overrides.publish) { if (Lbry.overrides.publish) {
Lbry.overrides.publish(params).then(resolve, reject); Lbry.overrides.publish(params).then(resolve, reject);
} else { } else {
apiCall('publish', params, resolve, reject); apiCall('publish', params, resolve, reject);
} }
}); }),
};
function checkAndParse(response) { function checkAndParse(response) {
if (response.status >= 200 && response.status < 300) { if (response.status >= 200 && response.status < 300) {

View file

@ -94,13 +94,15 @@ export function doResolveUri(uri: string) {
return doResolveUris([uri]); return doResolveUris([uri]);
} }
export function doFetchClaimListMine() { export function doFetchClaimListMine(page: number = 1, pageSize: number = 99999) {
return (dispatch: Dispatch) => { return (dispatch: Dispatch) => {
dispatch({ dispatch({
type: ACTIONS.FETCH_CLAIM_LIST_MINE_STARTED, type: ACTIONS.FETCH_CLAIM_LIST_MINE_STARTED,
}); });
Lbry.claim_list().then((claims: ClaimListResponse) => { Lbry.stream_list({ page, page_size: pageSize }).then((result: StreamListResponse) => {
const claims = result.items;
dispatch({ dispatch({
type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED, type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED,
data: { data: {
@ -175,10 +177,12 @@ export function doAbandonClaim(txid: string, nout: number) {
}) })
); );
// After abandoning, call claim_list to show the claim as abandoned // After abandoning, fetch transactions to show the new abandon transaction
// Also fetch transactions to show the new abandon transaction // Only fetch the latest few transactions since we don't care about old ones
if (isClaim) dispatch(doFetchClaimListMine()); // Not very robust, but better than calling the entire list for large wallets
dispatch(doFetchTransactions()); const page = 1;
const pageSize = 10;
dispatch(doFetchTransactions(page, pageSize));
}; };
const abandonParams = { const abandonParams = {
@ -378,26 +382,38 @@ export function doImportChannel(certificate: string) {
}; };
} }
export function doFetchChannelListMine() { export function doFetchChannelListMine(page: number = 1, pageSize: number = 99999) {
return (dispatch: Dispatch) => { return (dispatch: Dispatch) => {
dispatch({ dispatch({
type: ACTIONS.FETCH_CHANNEL_LIST_STARTED, type: ACTIONS.FETCH_CHANNEL_LIST_STARTED,
}); });
const callback = (channels: Array<ChannelClaim>) => { const callback = (response: ChannelListResponse) => {
dispatch({ dispatch({
type: ACTIONS.FETCH_CHANNEL_LIST_COMPLETED, type: ACTIONS.FETCH_CHANNEL_LIST_COMPLETED,
data: { claims: channels }, data: { claims: response.items },
}); });
}; };
Lbry.channel_list().then(callback); Lbry.channel_list({ page, page_size: pageSize }).then(callback);
}; };
} }
export function doClaimSearch( export function doClaimSearch(
options: { tags?: Array<string>, page?: number, page_size?: number, release_time?: string } = { options: {
page_size: number,
page: number,
no_totals: boolean,
any_tags?: Array<string>,
channel_ids?: Array<string>,
not_channel_ids?: Array<string>,
not_tags?: Array<string>,
order_by?: Array<string>,
release_time?: string,
} = {
no_totals: true,
page_size: 10, page_size: 10,
page: 1,
} }
) { ) {
const query = createNormalizedClaimSearchKey(options); const query = createNormalizedClaimSearchKey(options);

View file

@ -4,7 +4,7 @@ import Lbry from 'lbry';
import { selectClaimsByUri, selectMyChannelClaims } from 'redux/selectors/claims'; import { selectClaimsByUri, selectMyChannelClaims } from 'redux/selectors/claims';
import { doToast } from 'redux/actions/notifications'; import { doToast } from 'redux/actions/notifications';
export function doCommentList(uri: string) { export function doCommentList(uri: string, page: number = 1, pageSize: number = 99999) {
return (dispatch: Dispatch, getState: GetState) => { return (dispatch: Dispatch, getState: GetState) => {
const state = getState(); const state = getState();
const claim = selectClaimsByUri(state)[uri]; const claim = selectClaimsByUri(state)[uri];
@ -15,12 +15,15 @@ export function doCommentList(uri: string) {
}); });
Lbry.comment_list({ Lbry.comment_list({
claim_id: claimId, claim_id: claimId,
page,
page_size: pageSize,
}) })
.then((results: CommentListResponse) => { .then((result: CommentListResponse) => {
const { items: comments } = result;
dispatch({ dispatch({
type: ACTIONS.COMMENT_LIST_COMPLETED, type: ACTIONS.COMMENT_LIST_COMPLETED,
data: { data: {
comments: results, comments,
claimId: claimId, claimId: claimId,
uri: uri, uri: uri,
}, },

View file

@ -19,12 +19,15 @@ export function doFetchFileInfo(uri) {
}, },
}); });
Lbry.file_list({ outpoint, full_status: true }).then(fileInfos => { Lbry.file_list({ outpoint, full_status: true, page: 1, page_size: 1 }).then(result => {
const { items: fileInfos } = result;
const fileInfo = fileInfos[0];
dispatch({ dispatch({
type: ACTIONS.FETCH_FILE_INFO_COMPLETED, type: ACTIONS.FETCH_FILE_INFO_COMPLETED,
data: { data: {
outpoint, outpoint,
fileInfo: fileInfos && fileInfos.length ? fileInfos[0] : null, fileInfo: fileInfo || null,
}, },
}); });
}); });
@ -32,7 +35,7 @@ export function doFetchFileInfo(uri) {
}; };
} }
export function doFileList() { export function doFileList(page: number = 1, pageSize: number = 99999) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
const isFetching = selectIsFetchingFileList(state); const isFetching = selectIsFetchingFileList(state);
@ -42,11 +45,12 @@ export function doFileList() {
type: ACTIONS.FILE_LIST_STARTED, type: ACTIONS.FILE_LIST_STARTED,
}); });
Lbry.file_list().then(fileInfos => { Lbry.file_list({ page, page_size: pageSize }).then(result => {
const { items: fileInfos } = result;
dispatch({ dispatch({
type: ACTIONS.FILE_LIST_SUCCEEDED, type: ACTIONS.FILE_LIST_SUCCEEDED,
data: { data: {
fileInfos, fileInfos: fileInfos.reverse(),
}, },
}); });
}); });

View file

@ -145,8 +145,10 @@ export const doUploadThumbnail = (
const data = new FormData(); const data = new FormData();
const name = makeid(); const name = makeid();
const file = thumbnailBlob || (thumbnail && new File([thumbnail], fileName, { type: fileType })); const file =
thumbnailBlob || (thumbnail && new File([thumbnail], fileName, { type: fileType }));
data.append('name', name); data.append('name', name);
// $FlowFixMe
data.append('file', file); data.append('file', file);
return fetch(SPEECH_PUBLISH, { return fetch(SPEECH_PUBLISH, {
@ -275,7 +277,9 @@ export const doPublish = (success: Function, fail: Function) => (
} }
// get the claim id from the channel name, we will use that instead // get the claim id from the channel name, we will use that instead
const namedChannelClaim = myChannels ? myChannels.find(myChannel => myChannel.name === channel) : null; const namedChannelClaim = myChannels
? myChannels.find(myChannel => myChannel.name === channel)
: null;
const channelId = namedChannelClaim ? namedChannelClaim.claim_id : ''; const channelId = namedChannelClaim ? namedChannelClaim.claim_id : '';
const publishPayload: { const publishPayload: {
@ -336,7 +340,7 @@ export const doPublish = (success: Function, fail: Function) => (
} }
if (myClaimForUri && myClaimForUri.value && myClaimForUri.value.locations) { if (myClaimForUri && myClaimForUri.value && myClaimForUri.value.locations) {
publishPayload.locations = myClaimForUri.value.locations; publishPayload.locations = myClaimForUri.value.locations;
} }
if (!contentIsFree && fee && (fee.currency && Number(fee.amount) > 0)) { if (!contentIsFree && fee && (fee.currency && Number(fee.amount) > 0)) {
@ -366,8 +370,9 @@ export const doCheckPendingPublishes = (onConfirmed: Function) => (
let publishCheckInterval; let publishCheckInterval;
const checkFileList = () => { const checkFileList = () => {
Lbry.claim_list().then(claims => { Lbry.stream_list({ page: 1, page_size: 10 }).then(result => {
// $FlowFixMe const claims = result.items;
claims.forEach(claim => { claims.forEach(claim => {
// If it's confirmed, check if it was pending previously // If it's confirmed, check if it was pending previously
if (claim.confirmations > 0 && pendingById[claim.claim_id]) { if (claim.confirmations > 0 && pendingById[claim.claim_id]) {

View file

@ -5,30 +5,38 @@ import { selectBalance } from 'redux/selectors/wallet';
import { creditsToString } from 'util/format-credits'; import { creditsToString } from 'util/format-credits';
import { selectMyClaimsRaw } from 'redux/selectors/claims'; import { selectMyClaimsRaw } from 'redux/selectors/claims';
let walletBalancePromise = null;
export function doUpdateBalance() { export function doUpdateBalance() {
return (dispatch, getState) => { return (dispatch, getState) => {
const { const {
wallet: { totalBalance: totalInStore }, wallet: { totalBalance: totalInStore },
} = getState(); } = getState();
return Lbry.wallet_balance({ reserved_subtotals: true }).then(response => {
const { available, reserved, reserved_subtotals, total } = response;
const { claims, supports, tips } = reserved_subtotals;
const totalFloat = parseFloat(total);
if (totalInStore !== totalFloat) { if (walletBalancePromise === null) {
dispatch({ walletBalancePromise = Lbry.wallet_balance().then(response => {
type: ACTIONS.UPDATE_BALANCE, walletBalancePromise = null;
data: {
totalBalance: totalFloat, const { available, reserved, reserved_subtotals, total } = response;
balance: parseFloat(available), const { claims, supports, tips } = reserved_subtotals;
reservedBalance: parseFloat(reserved), const totalFloat = parseFloat(total);
claimsBalance: parseFloat(claims),
supportsBalance: parseFloat(supports), if (totalInStore !== totalFloat) {
tipsBalance: parseFloat(tips), dispatch({
}, type: ACTIONS.UPDATE_BALANCE,
}); data: {
} totalBalance: totalFloat,
}); balance: parseFloat(available),
reservedBalance: parseFloat(reserved),
claimsBalance: parseFloat(claims),
supportsBalance: parseFloat(supports),
tipsBalance: parseFloat(tips),
},
});
}
});
}
return walletBalancePromise;
}; };
} }
@ -39,7 +47,7 @@ export function doBalanceSubscribe() {
}; };
} }
export function doFetchTransactions() { export function doFetchTransactions(page = 1, pageSize = 99999) {
return dispatch => { return dispatch => {
dispatch(doFetchSupports()); dispatch(doFetchSupports());
dispatch({ dispatch({
@ -47,29 +55,29 @@ export function doFetchTransactions() {
}); });
Lbry.utxo_release() Lbry.utxo_release()
.then(() => Lbry.transaction_list()) .then(() => Lbry.transaction_list({ page, page_size: pageSize }))
.then(results => { .then(result => {
dispatch({ dispatch({
type: ACTIONS.FETCH_TRANSACTIONS_COMPLETED, type: ACTIONS.FETCH_TRANSACTIONS_COMPLETED,
data: { data: {
transactions: results, transactions: result.items,
}, },
}); });
}); });
}; };
} }
export function doFetchSupports() { export function doFetchSupports(page = 1, pageSize = 99999) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: ACTIONS.FETCH_SUPPORTS_STARTED, type: ACTIONS.FETCH_SUPPORTS_STARTED,
}); });
Lbry.support_list().then(results => { Lbry.support_list({ page, page_size: pageSize }).then(result => {
dispatch({ dispatch({
type: ACTIONS.FETCH_SUPPORTS_COMPLETED, type: ACTIONS.FETCH_SUPPORTS_COMPLETED,
data: { data: {
supports: results, supports: result.items,
}, },
}); });
}); });

View file

@ -42,8 +42,8 @@ export const commentReducer = handleActions(
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const commentsByUri = Object.assign({}, state.commentsByUri); const commentsByUri = Object.assign({}, state.commentsByUri);
if (comments['items']) { if (comments) {
byId[claimId] = comments['items']; byId[claimId] = comments;
commentsByUri[uri] = claimId; commentsByUri[uri] = claimId;
} }
return { return {

View file

@ -146,11 +146,7 @@ export const selectFileListDownloadedSort = createSelector(
export const selectDownloadedUris = createSelector( export const selectDownloadedUris = createSelector(
selectFileInfosDownloaded, selectFileInfosDownloaded,
// We should use permament_url but it doesn't exist in file_list // We should use permament_url but it doesn't exist in file_list
info => info => info.slice().map(claim => `lbry://${claim.claim_name}#${claim.claim_id}`)
info
.slice()
.reverse()
.map(claim => `lbry://${claim.claim_name}#${claim.claim_id}`)
); );
export const makeSelectMediaTypeForUri = uri => export const makeSelectMediaTypeForUri = uri =>
@ -214,9 +210,11 @@ function filterFileInfos(fileInfos, query) {
const queryMatchRegExp = new RegExp(query, 'i'); const queryMatchRegExp = new RegExp(query, 'i');
return fileInfos.filter(fileInfo => { return fileInfos.filter(fileInfo => {
const { metadata } = fileInfo; const { metadata } = fileInfo;
return (metadata.title && metadata.title.match(queryMatchRegExp)) || return (
(metadata.title && metadata.title.match(queryMatchRegExp)) ||
(fileInfo.channel_name && fileInfo.channel_name.match(queryMatchRegExp)) || (fileInfo.channel_name && fileInfo.channel_name.match(queryMatchRegExp)) ||
(fileInfo.claim_name && fileInfo.claim_name.match(queryMatchRegExp)); (fileInfo.claim_name && fileInfo.claim_name.match(queryMatchRegExp))
);
}); });
} }
@ -228,22 +226,25 @@ export const makeSelectSearchDownloadUrlsForPage = (query, page = 1) =>
selectFileInfosDownloaded, selectFileInfosDownloaded,
fileInfos => { fileInfos => {
const matchingFileInfos = filterFileInfos(fileInfos, query); const matchingFileInfos = filterFileInfos(fileInfos, query);
const start = ((Number(page) - 1) * Number(PAGE_SIZE)); const start = (Number(page) - 1) * Number(PAGE_SIZE);
const end = (Number(page) * Number(PAGE_SIZE)); const end = Number(page) * Number(PAGE_SIZE);
return (matchingFileInfos && matchingFileInfos.length) return matchingFileInfos && matchingFileInfos.length
? matchingFileInfos.slice(start, end).map(fileInfo => ? matchingFileInfos.slice(start, end).map(fileInfo =>
buildURI({ streamName: fileInfo.claim_name, channelName: fileInfo.channel_name, channelClaimId: fileInfo.channel_claim_id })) buildURI({
streamName: fileInfo.claim_name,
channelName: fileInfo.channel_name,
channelClaimId: fileInfo.channel_claim_id,
})
)
: []; : [];
} }
); );
export const makeSelectSearchDownloadUrlsCount = (query) => export const makeSelectSearchDownloadUrlsCount = query =>
createSelector( createSelector(
selectFileInfosDownloaded, selectFileInfosDownloaded,
fileInfos => { fileInfos => {
return fileInfos && fileInfos.length return fileInfos && fileInfos.length ? filterFileInfos(fileInfos, query).length : 0;
? filterFileInfos(fileInfos, query).length
: 0;
} }
); );

View file

@ -1,6 +1,6 @@
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import * as TRANSACTIONS from 'constants/transaction_types'; import * as TRANSACTIONS from 'constants/transaction_types';
import { PAGE_SIZE } from 'constants/transaction_list'; import { PAGE_SIZE, LATEST_PAGE_SIZE } from 'constants/transaction_list';
export const selectState = state => state.wallet || {}; export const selectState = state => state.wallet || {};
@ -300,7 +300,7 @@ export const selectFilteredTransactions = createSelector(
} }
); );
export const makeSelectFilteredTransactionsForPage = (page: number = 1): Array<any> => export const makeSelectFilteredTransactionsForPage = (page = 1) =>
createSelector( createSelector(
selectFilteredTransactions, selectFilteredTransactions,
filteredTransactions => { filteredTransactions => {
@ -312,6 +312,13 @@ export const makeSelectFilteredTransactionsForPage = (page: number = 1): Array<a
} }
); );
export const makeSelectLatestTransactions = createSelector(
selectTransactionItems,
transactions => {
return transactions && transactions.length ? transactions.slice(0, LATEST_PAGE_SIZE) : [];
}
);
export const selectFilteredTransactionCount = createSelector( export const selectFilteredTransactionCount = createSelector(
selectFilteredTransactions, selectFilteredTransactions,
filteredTransactions => filteredTransactions.length filteredTransactions => filteredTransactions.length

View file

@ -23,7 +23,7 @@ export const isClaimNsfw = (claim: Claim): boolean => {
return false; return false;
}; };
export function createNormalizedClaimSearchKey(options: { page?: number, release_time?: string }) { export function createNormalizedClaimSearchKey(options: { page: number, release_time?: string }) {
// Ignore page because we don't care what the last page searched was, we want everything // Ignore page because we don't care what the last page searched was, we want everything
// Ignore release_time because that will change depending on when you call claim_search ex: release_time: ">12344567" // Ignore release_time because that will change depending on when you call claim_search ex: release_time: ">12344567"
const { page: optionToIgnoreForQuery, release_time: anotherToIgnore, ...rest } = options; const { page: optionToIgnoreForQuery, release_time: anotherToIgnore, ...rest } = options;
@ -31,20 +31,23 @@ export function createNormalizedClaimSearchKey(options: { page?: number, release
return query; return query;
} }
export function concatClaims(claimList: Array<Claim> = [], concatClaimList: Array<any> = []): Array<Claim> { export function concatClaims(
claimList: Array<Claim> = [],
concatClaimList: Array<any> = []
): Array<Claim> {
if (!claimList || claimList.length === 0) { if (!claimList || claimList.length === 0) {
if (!concatClaimList) { if (!concatClaimList) {
return []; return [];
} }
return concatClaimList.slice(); return concatClaimList.slice();
} }
const claims = claimList.slice(); const claims = claimList.slice();
concatClaimList.forEach(claim => { concatClaimList.forEach(claim => {
if (!claims.some(item => item.claim_id === claim.claim_id)) { if (!claims.some(item => item.claim_id === claim.claim_id)) {
claims.push(claim); claims.push(claim);
} }
}); });
return claims; return claims;
} }