This commit is contained in:
Sean Yesmunt 2019-11-01 15:08:42 -04:00
parent 2157834ff6
commit 861880a029
9 changed files with 151 additions and 105 deletions

99
dist/bundle.es.js vendored
View file

@ -772,6 +772,7 @@ const Lbry = {
channel_import: params => daemonCallWithResult('channel_import', params),
channel_list: params => daemonCallWithResult('channel_list', params),
stream_abandon: params => daemonCallWithResult('stream_abandon', params),
stream_list: params => daemonCallWithResult('stream_list', params),
channel_abandon: params => daemonCallWithResult('channel_abandon', params),
support_create: params => daemonCallWithResult('support_create', params),
@ -831,16 +832,16 @@ const Lbry = {
// Flow thinks this could be empty, but it will always reuturn a promise
// $FlowFixMe
return Lbry.connectPromise;
}
};
},
Lbry.publish = (params = {}) => new Promise((resolve, reject) => {
if (Lbry.overrides.publish) {
Lbry.overrides.publish(params).then(resolve, reject);
} else {
apiCall('publish', params, resolve, reject);
}
});
publish: (params = {}) => new Promise((resolve, reject) => {
if (Lbry.overrides.publish) {
Lbry.overrides.publish(params).then(resolve, reject);
} else {
apiCall('publish', params, resolve, reject);
}
})
};
function checkAndParse(response) {
if (response.status >= 200 && response.status < 300) {
@ -1703,7 +1704,7 @@ const makeSelectFilteredTransactionsForPage = (page = 1) => reselect.createSelec
});
const makeSelectLatestTransactions = reselect.createSelector(selectTransactionItems, transactions => {
return transactions && transactions.length ? transactions.slice(transactions.length < LATEST_PAGE_SIZE ? transactions.length : LATEST_PAGE_SIZE) : [];
return transactions && transactions.length ? transactions.slice(0, LATEST_PAGE_SIZE) : [];
});
const selectFilteredTransactionCount = reselect.createSelector(selectFilteredTransactions, filteredTransactions => filteredTransactions.length);
@ -2172,30 +2173,38 @@ function creditsToString(amount) {
return creditString;
}
let walletBalancePromise = null;
function doUpdateBalance() {
return (dispatch, getState) => {
const {
wallet: { totalBalance: totalInStore }
} = 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) {
dispatch({
type: UPDATE_BALANCE,
data: {
totalBalance: totalFloat,
balance: parseFloat(available),
reservedBalance: parseFloat(reserved),
claimsBalance: parseFloat(claims),
supportsBalance: parseFloat(supports),
tipsBalance: parseFloat(tips)
}
});
}
});
if (walletBalancePromise === null) {
walletBalancePromise = lbryProxy.wallet_balance({ reserved_subtotals: true }).then(response => {
walletBalancePromise = null;
const { available, reserved, reserved_subtotals, total } = response;
const { claims, supports, tips } = reserved_subtotals;
const totalFloat = parseFloat(total);
if (totalInStore !== totalFloat) {
dispatch({
type: UPDATE_BALANCE,
data: {
totalBalance: totalFloat,
balance: parseFloat(available),
reservedBalance: parseFloat(reserved),
claimsBalance: parseFloat(claims),
supportsBalance: parseFloat(supports),
tipsBalance: parseFloat(tips)
}
});
}
});
}
return walletBalancePromise;
};
}
@ -2206,18 +2215,18 @@ function doBalanceSubscribe() {
};
}
function doFetchTransactions(page, pageSize) {
function doFetchTransactions(page = 1, pageSize = 99999) {
return dispatch => {
dispatch(doFetchSupports());
dispatch({
type: FETCH_TRANSACTIONS_STARTED
});
debugger;
lbryProxy.utxo_release().then(() => lbryProxy.transaction_list({ page: page, page_size: pageSize })).then(results => {
lbryProxy.utxo_release().then(() => lbryProxy.transaction_list({ page, page_size: pageSize })).then(result => {
dispatch({
type: FETCH_TRANSACTIONS_COMPLETED,
data: {
transactions: results
transactions: result.items
}
});
});
@ -2593,13 +2602,15 @@ function doResolveUri(uri) {
return doResolveUris([uri]);
}
function doFetchClaimListMine() {
function doFetchClaimListMine(page = 1, pageSize = 9999) {
return dispatch => {
dispatch({
type: FETCH_CLAIM_LIST_MINE_STARTED
});
lbryProxy.claim_list().then(claims => {
lbryProxy.claim_list({ page, page_size: pageSize }).then(result => {
const claims = result.items;
dispatch({
type: FETCH_CLAIM_LIST_MINE_COMPLETED,
data: {
@ -2664,10 +2675,12 @@ function doAbandonClaim(txid, nout) {
message: abandonMessage
}));
// After abandoning, call claim_list to show the claim as abandoned
// Also fetch transactions to show the new abandon transaction
if (isClaim) dispatch(doFetchClaimListMine());
dispatch(doFetchTransactions(1, 2));
// After abandoning, fetch transactions to show the new abandon transaction
// Only fetch the latest few transactions since we don't care about old ones
// Not very robust, but better than calling the entire list for large wallets
const page = 1;
const pageSize = 10;
dispatch(doFetchTransactions(page, pageSize));
};
const abandonParams = {
@ -2867,7 +2880,9 @@ function doFetchChannelListMine() {
}
function doClaimSearch(options = {
page_size: 10
no_totals: true,
page_size: 10,
page: 1
}) {
const query = createNormalizedClaimSearchKey(options);
return dispatch => {
@ -3431,6 +3446,7 @@ const doUploadThumbnail = (filePath, thumbnailBlob, fsAdapter, fs, path) => disp
const name = makeid();
const file = thumbnailBlob || thumbnail && new File([thumbnail], fileName, { type: fileType });
data.append('name', name);
// $FlowFixMe
data.append('file', file);
return fetch(SPEECH_PUBLISH, {
@ -3618,8 +3634,9 @@ const doCheckPendingPublishes = onConfirmed => (dispatch, getState) => {
let publishCheckInterval;
const checkFileList = () => {
lbryProxy.stream_list({ page: 1, page_size: 5 }).then(claims => {
// $FlowFixMe
lbryProxy.stream_list({ page: 1, page_size: 10 }).then(result => {
const claims = result.items;
claims.forEach(claim => {
// If it's confirmed, check if it was pending previously
if (claim.confirmations > 0 && pendingById[claim.claim_id]) {

View file

@ -107,7 +107,7 @@ declare type ClaimSearchResponse = {
};
declare type ClaimListResponse = {
claims: Array<ChannelClaim | Claim>,
items: Array<ChannelClaim | Claim>,
};
declare type ChannelCreateResponse = GenericTxResponse & {
@ -125,7 +125,7 @@ declare type ChannelListResponse = Array<ChannelClaim>;
declare type FileListResponse = Array<FileListItem>;
declare type TxListResponse = Array<Transaction>;
declare type TxListResponse = { items: Array<Transaction> };
declare type BlobListResponse = Array<string>;
@ -146,6 +146,8 @@ declare type SyncApplyResponse = {
declare type SupportAbandonResponse = GenericTxResponse;
declare type StreamListResponse = { items: Array<StreamClaim> };
//
// Types used in the generic Lbry object that is exported
//
@ -168,7 +170,7 @@ declare type LbryTypes = {
version: () => Promise<VersionResponse>,
resolve: (params: {}) => Promise<ResolveResponse>,
get: (params: {}) => Promise<GetResponse>,
publish?: (params: {}) => Promise<PublishResponse>,
publish: (params: {}) => Promise<PublishResponse>,
claim_search: (params: {}) => Promise<ClaimSearchResponse>,
claim_list: (params?: {}) => Promise<ClaimListResponse>,
@ -177,6 +179,7 @@ declare type LbryTypes = {
channel_import: (params: {}) => Promise<string>,
channel_list: () => Promise<ChannelListResponse>,
stream_abandon: (params: {}) => Promise<GenericTxResponse>,
stream_list: (params: {}) => Promise<StreamListResponse>,
channel_abandon: (params: {}) => Promise<GenericTxResponse>,
support_create: (params: {}) => Promise<GenericTxResponse>,

9
flow-typed/Lbry.js vendored
View file

@ -107,7 +107,7 @@ declare type ClaimSearchResponse = {
};
declare type ClaimListResponse = {
claims: Array<ChannelClaim | Claim>,
items: Array<ChannelClaim | Claim>,
};
declare type ChannelCreateResponse = GenericTxResponse & {
@ -125,7 +125,7 @@ declare type ChannelListResponse = Array<ChannelClaim>;
declare type FileListResponse = Array<FileListItem>;
declare type TxListResponse = Array<Transaction>;
declare type TxListResponse = { items: Array<Transaction> };
declare type BlobListResponse = Array<string>;
@ -146,6 +146,8 @@ declare type SyncApplyResponse = {
declare type SupportAbandonResponse = GenericTxResponse;
declare type StreamListResponse = { items: Array<StreamClaim> };
//
// Types used in the generic Lbry object that is exported
//
@ -168,7 +170,7 @@ declare type LbryTypes = {
version: () => Promise<VersionResponse>,
resolve: (params: {}) => Promise<ResolveResponse>,
get: (params: {}) => Promise<GetResponse>,
publish?: (params: {}) => Promise<PublishResponse>,
publish: (params: {}) => Promise<PublishResponse>,
claim_search: (params: {}) => Promise<ClaimSearchResponse>,
claim_list: (params?: {}) => Promise<ClaimListResponse>,
@ -177,6 +179,7 @@ declare type LbryTypes = {
channel_import: (params: {}) => Promise<string>,
channel_list: () => Promise<ChannelListResponse>,
stream_abandon: (params: {}) => Promise<GenericTxResponse>,
stream_list: (params: {}) => Promise<StreamListResponse>,
channel_abandon: (params: {}) => Promise<GenericTxResponse>,
support_create: (params: {}) => Promise<GenericTxResponse>,

View file

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

View file

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

View file

@ -145,8 +145,10 @@ export const doUploadThumbnail = (
const data = new FormData();
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);
// $FlowFixMe
data.append('file', file);
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
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 publishPayload: {
@ -336,7 +340,7 @@ export const doPublish = (success: Function, fail: Function) => (
}
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)) {
@ -366,8 +370,9 @@ export const doCheckPendingPublishes = (onConfirmed: Function) => (
let publishCheckInterval;
const checkFileList = () => {
Lbry.stream_list( { page: 1, page_size: 5}).then(claims => {
// $FlowFixMe
Lbry.stream_list({ page: 1, page_size: 10 }).then(result => {
const claims = result.items;
claims.forEach(claim => {
// If it's confirmed, check if it was pending previously
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 { selectMyClaimsRaw } from 'redux/selectors/claims';
let walletBalancePromise = null;
export function doUpdateBalance() {
return (dispatch, getState) => {
const {
wallet: { totalBalance: totalInStore },
} = 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) {
dispatch({
type: ACTIONS.UPDATE_BALANCE,
data: {
totalBalance: totalFloat,
balance: parseFloat(available),
reservedBalance: parseFloat(reserved),
claimsBalance: parseFloat(claims),
supportsBalance: parseFloat(supports),
tipsBalance: parseFloat(tips),
},
});
}
});
if (walletBalancePromise === null) {
walletBalancePromise = Lbry.wallet_balance({ reserved_subtotals: true }).then(response => {
walletBalancePromise = null;
const { available, reserved, reserved_subtotals, total } = response;
const { claims, supports, tips } = reserved_subtotals;
const totalFloat = parseFloat(total);
if (totalInStore !== totalFloat) {
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,20 +47,20 @@ export function doBalanceSubscribe() {
};
}
export function doFetchTransactions(page, pageSize) {
export function doFetchTransactions(page = 1, pageSize = 99999) {
return dispatch => {
dispatch(doFetchSupports());
dispatch({
type: ACTIONS.FETCH_TRANSACTIONS_STARTED,
});
debugger;
Lbry.utxo_release()
.then(() => Lbry.transaction_list({ page: page, page_size: pageSize}))
.then(results => {
.then(() => Lbry.transaction_list({ page, page_size: pageSize }))
.then(result => {
dispatch({
type: ACTIONS.FETCH_TRANSACTIONS_COMPLETED,
data: {
transactions: results,
transactions: result.items,
},
});
});

View file

@ -285,7 +285,7 @@ export const selectFilteredTransactions = createSelector(
}
);
export const makeSelectFilteredTransactionsForPage = (page: number = 1): Array<any> =>
export const makeSelectFilteredTransactionsForPage = (page = 1) =>
createSelector(
selectFilteredTransactions,
filteredTransactions => {
@ -297,14 +297,12 @@ export const makeSelectFilteredTransactionsForPage = (page: number = 1): Array<a
}
);
export const makeSelectLatestTransactions = createSelector(
selectTransactionItems,
(transactions) => {
return transactions && transactions.length
? transactions.slice( transactions.length < LATEST_PAGE_SIZE ? transactions.length : LATEST_PAGE_SIZE )
: [];
}
);
export const makeSelectLatestTransactions = createSelector(
selectTransactionItems,
transactions => {
return transactions && transactions.length ? transactions.slice(0, LATEST_PAGE_SIZE) : [];
}
);
export const selectFilteredTransactionCount = createSelector(
selectFilteredTransactions,

View file

@ -23,7 +23,7 @@ export const isClaimNsfw = (claim: Claim): boolean => {
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 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;
@ -31,20 +31,23 @@ export function createNormalizedClaimSearchKey(options: { page?: number, release
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 (!concatClaimList) {
return [];
}
return concatClaimList.slice();
}
const claims = claimList.slice();
concatClaimList.forEach(claim => {
if (!claims.some(item => item.claim_id === claim.claim_id)) {
claims.push(claim);
}
});
return claims;
}