Merge pull request #101 from lbryio/time

estimate claim date with block height
This commit is contained in:
Sean Yesmunt 2018-11-08 15:52:04 -05:00 committed by GitHub
commit 5edee274b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 811 additions and 730 deletions

1399
dist/bundle.js vendored

File diff suppressed because it is too large Load diff

View file

@ -58,6 +58,7 @@ export const WALLET_LOCK_FAILED = 'WALLET_LOCK_FAILED';
export const WALLET_STATUS_START = 'WALLET_STATUS_START'; export const WALLET_STATUS_START = 'WALLET_STATUS_START';
export const WALLET_STATUS_COMPLETED = 'WALLET_STATUS_COMPLETED'; export const WALLET_STATUS_COMPLETED = 'WALLET_STATUS_COMPLETED';
export const SET_TRANSACTION_LIST_FILTER = 'SET_TRANSACTION_LIST_FILTER'; export const SET_TRANSACTION_LIST_FILTER = 'SET_TRANSACTION_LIST_FILTER';
export const UPDATE_CURRENT_HEIGHT = 'UPDATE_CURRENT_HEIGHT';
// Claims // Claims
export const FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED'; export const FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED';

View file

@ -88,6 +88,7 @@ export {
doWalletUnlock, doWalletUnlock,
doWalletStatus, doWalletStatus,
doSetTransactionListFilter, doSetTransactionListFilter,
doUpdateBlockHeight,
} from 'redux/actions/wallet'; } from 'redux/actions/wallet';
// utils // utils

View file

@ -1,10 +1,11 @@
import * as ACTIONS from 'constants/action_types'; import * as ACTIONS from 'constants/action_types';
import Lbry from 'lbry'; import Lbry from 'lbry';
import Lbryapi from 'lbryapi'; import Lbryapi from 'lbryapi';
import { buildURI, normalizeURI } from 'lbryURI'; import { normalizeURI } from 'lbryURI';
import { doNotify } from 'redux/actions/notifications'; import { doNotify } from 'redux/actions/notifications';
import { selectMyClaimsRaw, selectResolvingUris } from 'redux/selectors/claims'; import { selectMyClaimsRaw, selectResolvingUris } from 'redux/selectors/claims';
import { batchActions } from 'util/batchActions'; import { batchActions } from 'util/batchActions';
import { doFetchTransactions } from 'redux/actions/wallet';
export function doResolveUris(uris) { export function doResolveUris(uris) {
return (dispatch, getState) => { return (dispatch, getState) => {
@ -72,7 +73,7 @@ export function doAbandonClaim(txid, nout) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
const myClaims = selectMyClaimsRaw(state); const myClaims = selectMyClaimsRaw(state);
const { claim_id: claimId, name } = myClaims.find( const { claim_id: claimId } = myClaims.find(
(claim) => claim.txid === txid && claim.nout === nout (claim) => claim.txid === txid && claim.nout === nout
); );
@ -109,8 +110,11 @@ export function doAbandonClaim(txid, nout) {
displayType: ['snackbar', 'toast'], displayType: ['snackbar', 'toast'],
}) })
); );
dispatch(doResolveUri(buildURI({ name, claimId })));
// After abandoning, call claim_list_mine to show the claim as abandoned
// Also fetch transactions to show the new abandon transaction
dispatch(doFetchClaimListMine()); dispatch(doFetchClaimListMine());
dispatch(doFetchTransactions());
} else { } else {
dispatch( dispatch(
doNotify({ doNotify({

View file

@ -9,7 +9,7 @@ export function doUpdateBalance() {
const { const {
wallet: { balance: balanceInStore }, wallet: { balance: balanceInStore },
} = getState(); } = getState();
Lbry.account_balance().then(balance => { Lbry.account_balance().then((balance) => {
if (balanceInStore !== balance) { if (balanceInStore !== balance) {
dispatch({ dispatch({
type: ACTIONS.UPDATE_BALANCE, type: ACTIONS.UPDATE_BALANCE,
@ -23,19 +23,19 @@ export function doUpdateBalance() {
} }
export function doBalanceSubscribe() { export function doBalanceSubscribe() {
return dispatch => { return (dispatch) => {
dispatch(doUpdateBalance()); dispatch(doUpdateBalance());
setInterval(() => dispatch(doUpdateBalance()), 5000); setInterval(() => dispatch(doUpdateBalance()), 5000);
}; };
} }
export function doFetchTransactions() { export function doFetchTransactions() {
return dispatch => { return (dispatch) => {
dispatch({ dispatch({
type: ACTIONS.FETCH_TRANSACTIONS_STARTED, type: ACTIONS.FETCH_TRANSACTIONS_STARTED,
}); });
Lbry.transaction_list().then(results => { Lbry.transaction_list().then((results) => {
dispatch({ dispatch({
type: ACTIONS.FETCH_TRANSACTIONS_COMPLETED, type: ACTIONS.FETCH_TRANSACTIONS_COMPLETED,
data: { data: {
@ -47,8 +47,8 @@ export function doFetchTransactions() {
} }
export function doFetchBlock(height) { export function doFetchBlock(height) {
return dispatch => { return (dispatch) => {
Lbry.block_show({ height }).then(block => { Lbry.block_show({ height }).then((block) => {
dispatch({ dispatch({
type: ACTIONS.FETCH_BLOCK_SUCCESS, type: ACTIONS.FETCH_BLOCK_SUCCESS,
data: { block }, data: { block },
@ -58,13 +58,13 @@ export function doFetchBlock(height) {
} }
export function doGetNewAddress() { export function doGetNewAddress() {
return dispatch => { return (dispatch) => {
dispatch({ dispatch({
type: ACTIONS.GET_NEW_ADDRESS_STARTED, type: ACTIONS.GET_NEW_ADDRESS_STARTED,
}); });
// Removed localStorage use, since address is expected to be stored in redux store // Removed localStorage use, since address is expected to be stored in redux store
Lbry.address_unused().then(address => { Lbry.address_unused().then((address) => {
dispatch({ dispatch({
type: ACTIONS.GET_NEW_ADDRESS_COMPLETED, type: ACTIONS.GET_NEW_ADDRESS_COMPLETED,
data: { address }, data: { address },
@ -74,12 +74,12 @@ export function doGetNewAddress() {
} }
export function doCheckAddressIsMine(address) { export function doCheckAddressIsMine(address) {
return dispatch => { return (dispatch) => {
dispatch({ dispatch({
type: ACTIONS.CHECK_ADDRESS_IS_MINE_STARTED, type: ACTIONS.CHECK_ADDRESS_IS_MINE_STARTED,
}); });
Lbry.address_is_mine({ address }).then(isMine => { Lbry.address_is_mine({ address }).then((isMine) => {
if (!isMine) dispatch(doGetNewAddress()); if (!isMine) dispatch(doGetNewAddress());
dispatch({ dispatch({
@ -110,7 +110,7 @@ export function doSendDraftTransaction(address, amount) {
type: ACTIONS.SEND_TRANSACTION_STARTED, type: ACTIONS.SEND_TRANSACTION_STARTED,
}); });
const successCallback = response => { const successCallback = (response) => {
if (response.txid) { if (response.txid) {
dispatch({ dispatch({
type: ACTIONS.SEND_TRANSACTION_COMPLETED, type: ACTIONS.SEND_TRANSACTION_COMPLETED,
@ -141,7 +141,7 @@ export function doSendDraftTransaction(address, amount) {
} }
}; };
const errorCallback = error => { const errorCallback = (error) => {
dispatch({ dispatch({
type: ACTIONS.SEND_TRANSACTION_FAILED, type: ACTIONS.SEND_TRANSACTION_FAILED,
data: { error: error.message }, data: { error: error.message },
@ -213,7 +213,7 @@ export function doSendTip(amount, claimId, uri, successCallback, errorCallback)
} }
}; };
const error = err => { const error = (err) => {
dispatch( dispatch(
doNotify({ doNotify({
message: __(`There was an error sending support funds.`), message: __(`There was an error sending support funds.`),
@ -245,12 +245,12 @@ export function doSendTip(amount, claimId, uri, successCallback, errorCallback)
} }
export function doWalletEncrypt(newPassword) { export function doWalletEncrypt(newPassword) {
return dispatch => { return (dispatch) => {
dispatch({ dispatch({
type: ACTIONS.WALLET_ENCRYPT_START, type: ACTIONS.WALLET_ENCRYPT_START,
}); });
Lbry.account_encrypt({ new_password: newPassword }).then(result => { Lbry.account_encrypt({ new_password: newPassword }).then((result) => {
if (result === true) { if (result === true) {
dispatch({ dispatch({
type: ACTIONS.WALLET_ENCRYPT_COMPLETED, type: ACTIONS.WALLET_ENCRYPT_COMPLETED,
@ -267,12 +267,12 @@ export function doWalletEncrypt(newPassword) {
} }
export function doWalletUnlock(password) { export function doWalletUnlock(password) {
return dispatch => { return (dispatch) => {
dispatch({ dispatch({
type: ACTIONS.WALLET_UNLOCK_START, type: ACTIONS.WALLET_UNLOCK_START,
}); });
Lbry.account_unlock({ password }).then(result => { Lbry.account_unlock({ password }).then((result) => {
if (result === true) { if (result === true) {
dispatch({ dispatch({
type: ACTIONS.WALLET_UNLOCK_COMPLETED, type: ACTIONS.WALLET_UNLOCK_COMPLETED,
@ -289,12 +289,12 @@ export function doWalletUnlock(password) {
} }
export function doWalletLock() { export function doWalletLock() {
return dispatch => { return (dispatch) => {
dispatch({ dispatch({
type: ACTIONS.WALLET_LOCK_START, type: ACTIONS.WALLET_LOCK_START,
}); });
Lbry.wallet_lock().then(result => { Lbry.wallet_lock().then((result) => {
if (result === true) { if (result === true) {
dispatch({ dispatch({
type: ACTIONS.WALLET_LOCK_COMPLETED, type: ACTIONS.WALLET_LOCK_COMPLETED,
@ -311,12 +311,12 @@ export function doWalletLock() {
} }
export function doWalletDecrypt() { export function doWalletDecrypt() {
return dispatch => { return (dispatch) => {
dispatch({ dispatch({
type: ACTIONS.WALLET_DECRYPT_START, type: ACTIONS.WALLET_DECRYPT_START,
}); });
Lbry.account_decrypt().then(result => { Lbry.account_decrypt().then((result) => {
if (result === true) { if (result === true) {
dispatch({ dispatch({
type: ACTIONS.WALLET_DECRYPT_COMPLETED, type: ACTIONS.WALLET_DECRYPT_COMPLETED,
@ -333,12 +333,12 @@ export function doWalletDecrypt() {
} }
export function doWalletStatus() { export function doWalletStatus() {
return dispatch => { return (dispatch) => {
dispatch({ dispatch({
type: ACTIONS.WALLET_STATUS_START, type: ACTIONS.WALLET_STATUS_START,
}); });
Lbry.status().then(status => { Lbry.status().then((status) => {
if (status && status.wallet) { if (status && status.wallet) {
dispatch({ dispatch({
type: ACTIONS.WALLET_STATUS_COMPLETED, type: ACTIONS.WALLET_STATUS_COMPLETED,
@ -355,3 +355,15 @@ export function doSetTransactionListFilter(filterOption) {
data: filterOption, data: filterOption,
}; };
} }
export function doUpdateBlockHeight() {
return (dispatch) =>
Lbry.status().then((status) => {
if (status.wallet) {
dispatch({
type: ACTIONS.UPDATE_CURRENT_HEIGHT,
data: status.wallet.blocks,
});
}
});
}

View file

@ -17,6 +17,7 @@ type ActionResult = {
type WalletState = { type WalletState = {
balance: any, balance: any,
blocks: any, blocks: any,
latestBlock: number,
transactions: any, transactions: any,
fetchingTransactions: boolean, fetchingTransactions: boolean,
gettingNewAddress: boolean, gettingNewAddress: boolean,
@ -40,6 +41,7 @@ type WalletState = {
const defaultState = { const defaultState = {
balance: undefined, balance: undefined,
blocks: {}, blocks: {},
latestBlock: undefined,
transactions: {}, transactions: {},
fetchingTransactions: false, fetchingTransactions: false,
gettingNewAddress: false, gettingNewAddress: false,
@ -281,6 +283,11 @@ reducers[ACTIONS.SET_TRANSACTION_LIST_FILTER] = (state: WalletState, action: {})
transactionListFilter: action.data, transactionListFilter: action.data,
}); });
reducers[ACTIONS.UPDATE_CURRENT_HEIGHT] = (state: WalletState, action: { data: number }) =>
Object.assign({}, state, {
latestBlock: action.data,
});
export function walletReducer(state: WalletState = defaultState, action: ActionResult) { export function walletReducer(state: WalletState = defaultState, action: ActionResult) {
const handler = reducers[action.type]; const handler = reducers[action.type];
if (handler) return handler(state, action); if (handler) return handler(state, action);

View file

@ -211,11 +211,28 @@ export const selectDraftTransactionError = createSelector(
export const selectBlocks = createSelector(selectState, (state) => state.blocks); export const selectBlocks = createSelector(selectState, (state) => state.blocks);
export const selectCurrentHeight = createSelector(selectState, (state) => state.latestBlock);
export const makeSelectBlockDate = (block) => export const makeSelectBlockDate = (block) =>
createSelector( createSelector(selectBlocks, selectCurrentHeight, (blocks, latestBlock) => {
selectBlocks, // If we have the block data, look at the actual date,
(blocks) => (blocks && blocks[block] ? new Date(blocks[block].time * 1000) : undefined) // If not, try to simulate it based on 2.5 minute blocks
); // Adding this on 11/7/2018 because caling block_show for every claim is causing
// performance issues.
if (blocks && blocks[block]) {
return new Date(blocks[block].time * 1000);
}
// Pending claim
if (block < 1) {
return null;
}
const difference = latestBlock - block;
const msSincePublish = difference * 2.5 * 60 * 1000; // Number of blocks * 2.5 minutes in ms
const publishDate = Date.now() - msSincePublish;
return new Date(publishDate);
});
export const selectTransactionListFilter = createSelector( export const selectTransactionListFilter = createSelector(
selectState, selectState,