Merge pull request #101 from lbryio/time
estimate claim date with block height
This commit is contained in:
commit
5edee274b2
7 changed files with 811 additions and 730 deletions
1399
dist/bundle.js
vendored
1399
dist/bundle.js
vendored
File diff suppressed because it is too large
Load diff
|
@ -58,6 +58,7 @@ export const WALLET_LOCK_FAILED = 'WALLET_LOCK_FAILED';
|
|||
export const WALLET_STATUS_START = 'WALLET_STATUS_START';
|
||||
export const WALLET_STATUS_COMPLETED = 'WALLET_STATUS_COMPLETED';
|
||||
export const SET_TRANSACTION_LIST_FILTER = 'SET_TRANSACTION_LIST_FILTER';
|
||||
export const UPDATE_CURRENT_HEIGHT = 'UPDATE_CURRENT_HEIGHT';
|
||||
|
||||
// Claims
|
||||
export const FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED';
|
||||
|
|
|
@ -88,6 +88,7 @@ export {
|
|||
doWalletUnlock,
|
||||
doWalletStatus,
|
||||
doSetTransactionListFilter,
|
||||
doUpdateBlockHeight,
|
||||
} from 'redux/actions/wallet';
|
||||
|
||||
// utils
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import * as ACTIONS from 'constants/action_types';
|
||||
import Lbry from 'lbry';
|
||||
import Lbryapi from 'lbryapi';
|
||||
import { buildURI, normalizeURI } from 'lbryURI';
|
||||
import { normalizeURI } from 'lbryURI';
|
||||
import { doNotify } from 'redux/actions/notifications';
|
||||
import { selectMyClaimsRaw, selectResolvingUris } from 'redux/selectors/claims';
|
||||
import { batchActions } from 'util/batchActions';
|
||||
import { doFetchTransactions } from 'redux/actions/wallet';
|
||||
|
||||
export function doResolveUris(uris) {
|
||||
return (dispatch, getState) => {
|
||||
|
@ -72,7 +73,7 @@ export function doAbandonClaim(txid, nout) {
|
|||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const myClaims = selectMyClaimsRaw(state);
|
||||
const { claim_id: claimId, name } = myClaims.find(
|
||||
const { claim_id: claimId } = myClaims.find(
|
||||
(claim) => claim.txid === txid && claim.nout === nout
|
||||
);
|
||||
|
||||
|
@ -109,8 +110,11 @@ export function doAbandonClaim(txid, nout) {
|
|||
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(doFetchTransactions());
|
||||
} else {
|
||||
dispatch(
|
||||
doNotify({
|
||||
|
|
|
@ -9,7 +9,7 @@ export function doUpdateBalance() {
|
|||
const {
|
||||
wallet: { balance: balanceInStore },
|
||||
} = getState();
|
||||
Lbry.account_balance().then(balance => {
|
||||
Lbry.account_balance().then((balance) => {
|
||||
if (balanceInStore !== balance) {
|
||||
dispatch({
|
||||
type: ACTIONS.UPDATE_BALANCE,
|
||||
|
@ -23,19 +23,19 @@ export function doUpdateBalance() {
|
|||
}
|
||||
|
||||
export function doBalanceSubscribe() {
|
||||
return dispatch => {
|
||||
return (dispatch) => {
|
||||
dispatch(doUpdateBalance());
|
||||
setInterval(() => dispatch(doUpdateBalance()), 5000);
|
||||
};
|
||||
}
|
||||
|
||||
export function doFetchTransactions() {
|
||||
return dispatch => {
|
||||
return (dispatch) => {
|
||||
dispatch({
|
||||
type: ACTIONS.FETCH_TRANSACTIONS_STARTED,
|
||||
});
|
||||
|
||||
Lbry.transaction_list().then(results => {
|
||||
Lbry.transaction_list().then((results) => {
|
||||
dispatch({
|
||||
type: ACTIONS.FETCH_TRANSACTIONS_COMPLETED,
|
||||
data: {
|
||||
|
@ -47,8 +47,8 @@ export function doFetchTransactions() {
|
|||
}
|
||||
|
||||
export function doFetchBlock(height) {
|
||||
return dispatch => {
|
||||
Lbry.block_show({ height }).then(block => {
|
||||
return (dispatch) => {
|
||||
Lbry.block_show({ height }).then((block) => {
|
||||
dispatch({
|
||||
type: ACTIONS.FETCH_BLOCK_SUCCESS,
|
||||
data: { block },
|
||||
|
@ -58,13 +58,13 @@ export function doFetchBlock(height) {
|
|||
}
|
||||
|
||||
export function doGetNewAddress() {
|
||||
return dispatch => {
|
||||
return (dispatch) => {
|
||||
dispatch({
|
||||
type: ACTIONS.GET_NEW_ADDRESS_STARTED,
|
||||
});
|
||||
|
||||
// Removed localStorage use, since address is expected to be stored in redux store
|
||||
Lbry.address_unused().then(address => {
|
||||
Lbry.address_unused().then((address) => {
|
||||
dispatch({
|
||||
type: ACTIONS.GET_NEW_ADDRESS_COMPLETED,
|
||||
data: { address },
|
||||
|
@ -74,12 +74,12 @@ export function doGetNewAddress() {
|
|||
}
|
||||
|
||||
export function doCheckAddressIsMine(address) {
|
||||
return dispatch => {
|
||||
return (dispatch) => {
|
||||
dispatch({
|
||||
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());
|
||||
|
||||
dispatch({
|
||||
|
@ -110,7 +110,7 @@ export function doSendDraftTransaction(address, amount) {
|
|||
type: ACTIONS.SEND_TRANSACTION_STARTED,
|
||||
});
|
||||
|
||||
const successCallback = response => {
|
||||
const successCallback = (response) => {
|
||||
if (response.txid) {
|
||||
dispatch({
|
||||
type: ACTIONS.SEND_TRANSACTION_COMPLETED,
|
||||
|
@ -141,7 +141,7 @@ export function doSendDraftTransaction(address, amount) {
|
|||
}
|
||||
};
|
||||
|
||||
const errorCallback = error => {
|
||||
const errorCallback = (error) => {
|
||||
dispatch({
|
||||
type: ACTIONS.SEND_TRANSACTION_FAILED,
|
||||
data: { error: error.message },
|
||||
|
@ -213,7 +213,7 @@ export function doSendTip(amount, claimId, uri, successCallback, errorCallback)
|
|||
}
|
||||
};
|
||||
|
||||
const error = err => {
|
||||
const error = (err) => {
|
||||
dispatch(
|
||||
doNotify({
|
||||
message: __(`There was an error sending support funds.`),
|
||||
|
@ -245,12 +245,12 @@ export function doSendTip(amount, claimId, uri, successCallback, errorCallback)
|
|||
}
|
||||
|
||||
export function doWalletEncrypt(newPassword) {
|
||||
return dispatch => {
|
||||
return (dispatch) => {
|
||||
dispatch({
|
||||
type: ACTIONS.WALLET_ENCRYPT_START,
|
||||
});
|
||||
|
||||
Lbry.account_encrypt({ new_password: newPassword }).then(result => {
|
||||
Lbry.account_encrypt({ new_password: newPassword }).then((result) => {
|
||||
if (result === true) {
|
||||
dispatch({
|
||||
type: ACTIONS.WALLET_ENCRYPT_COMPLETED,
|
||||
|
@ -267,12 +267,12 @@ export function doWalletEncrypt(newPassword) {
|
|||
}
|
||||
|
||||
export function doWalletUnlock(password) {
|
||||
return dispatch => {
|
||||
return (dispatch) => {
|
||||
dispatch({
|
||||
type: ACTIONS.WALLET_UNLOCK_START,
|
||||
});
|
||||
|
||||
Lbry.account_unlock({ password }).then(result => {
|
||||
Lbry.account_unlock({ password }).then((result) => {
|
||||
if (result === true) {
|
||||
dispatch({
|
||||
type: ACTIONS.WALLET_UNLOCK_COMPLETED,
|
||||
|
@ -289,12 +289,12 @@ export function doWalletUnlock(password) {
|
|||
}
|
||||
|
||||
export function doWalletLock() {
|
||||
return dispatch => {
|
||||
return (dispatch) => {
|
||||
dispatch({
|
||||
type: ACTIONS.WALLET_LOCK_START,
|
||||
});
|
||||
|
||||
Lbry.wallet_lock().then(result => {
|
||||
Lbry.wallet_lock().then((result) => {
|
||||
if (result === true) {
|
||||
dispatch({
|
||||
type: ACTIONS.WALLET_LOCK_COMPLETED,
|
||||
|
@ -311,12 +311,12 @@ export function doWalletLock() {
|
|||
}
|
||||
|
||||
export function doWalletDecrypt() {
|
||||
return dispatch => {
|
||||
return (dispatch) => {
|
||||
dispatch({
|
||||
type: ACTIONS.WALLET_DECRYPT_START,
|
||||
});
|
||||
|
||||
Lbry.account_decrypt().then(result => {
|
||||
Lbry.account_decrypt().then((result) => {
|
||||
if (result === true) {
|
||||
dispatch({
|
||||
type: ACTIONS.WALLET_DECRYPT_COMPLETED,
|
||||
|
@ -333,12 +333,12 @@ export function doWalletDecrypt() {
|
|||
}
|
||||
|
||||
export function doWalletStatus() {
|
||||
return dispatch => {
|
||||
return (dispatch) => {
|
||||
dispatch({
|
||||
type: ACTIONS.WALLET_STATUS_START,
|
||||
});
|
||||
|
||||
Lbry.status().then(status => {
|
||||
Lbry.status().then((status) => {
|
||||
if (status && status.wallet) {
|
||||
dispatch({
|
||||
type: ACTIONS.WALLET_STATUS_COMPLETED,
|
||||
|
@ -355,3 +355,15 @@ export function doSetTransactionListFilter(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,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ type ActionResult = {
|
|||
type WalletState = {
|
||||
balance: any,
|
||||
blocks: any,
|
||||
latestBlock: number,
|
||||
transactions: any,
|
||||
fetchingTransactions: boolean,
|
||||
gettingNewAddress: boolean,
|
||||
|
@ -40,6 +41,7 @@ type WalletState = {
|
|||
const defaultState = {
|
||||
balance: undefined,
|
||||
blocks: {},
|
||||
latestBlock: undefined,
|
||||
transactions: {},
|
||||
fetchingTransactions: false,
|
||||
gettingNewAddress: false,
|
||||
|
@ -281,6 +283,11 @@ reducers[ACTIONS.SET_TRANSACTION_LIST_FILTER] = (state: WalletState, action: {})
|
|||
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) {
|
||||
const handler = reducers[action.type];
|
||||
if (handler) return handler(state, action);
|
||||
|
|
|
@ -211,11 +211,28 @@ export const selectDraftTransactionError = createSelector(
|
|||
|
||||
export const selectBlocks = createSelector(selectState, (state) => state.blocks);
|
||||
|
||||
export const selectCurrentHeight = createSelector(selectState, (state) => state.latestBlock);
|
||||
|
||||
export const makeSelectBlockDate = (block) =>
|
||||
createSelector(
|
||||
selectBlocks,
|
||||
(blocks) => (blocks && blocks[block] ? new Date(blocks[block].time * 1000) : undefined)
|
||||
);
|
||||
createSelector(selectBlocks, selectCurrentHeight, (blocks, latestBlock) => {
|
||||
// If we have the block data, look at the actual date,
|
||||
// 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(
|
||||
selectState,
|
||||
|
|
Loading…
Reference in a new issue