lbry-desktop/ui/js/selectors/wallet.js

81 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-06-06 23:19:12 +02:00
import { createSelector } from "reselect";
import { selectCurrentPage, selectDaemonReady } from "selectors/app";
2017-04-22 15:17:01 +02:00
2017-06-06 06:21:55 +02:00
export const _selectState = state => state.wallet || {};
2017-04-22 15:17:01 +02:00
export const selectBalance = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.balance || 0
2017-06-06 06:21:55 +02:00
);
2017-04-22 15:17:01 +02:00
export const selectTransactions = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.transactions || {}
2017-06-06 06:21:55 +02:00
);
2017-04-22 15:17:01 +02:00
export const selectTransactionsById = createSelector(
2017-04-22 15:17:01 +02:00
selectTransactions,
2017-06-06 23:19:12 +02:00
transactions => transactions.byId || {}
2017-06-06 06:21:55 +02:00
);
2017-04-22 15:17:01 +02:00
export const selectTransactionItems = createSelector(
selectTransactionsById,
2017-06-06 23:19:12 +02:00
byId => {
const transactionItems = [];
const txids = Object.keys(byId);
txids.forEach(txid => {
const tx = byId[txid];
transactionItems.push({
id: txid,
2017-06-06 23:19:12 +02:00
date: tx.timestamp ? new Date(parseInt(tx.timestamp) * 1000) : null,
amount: parseFloat(tx.value),
});
});
return transactionItems.reverse();
2017-04-22 15:17:01 +02:00
}
2017-06-06 06:21:55 +02:00
);
2017-04-22 15:17:01 +02:00
export const selectIsFetchingTransactions = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.fetchingTransactions
2017-06-06 06:21:55 +02:00
);
2017-04-22 15:17:01 +02:00
export const selectReceiveAddress = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.receiveAddress
2017-06-06 06:21:55 +02:00
);
2017-04-22 15:17:01 +02:00
export const selectGettingNewAddress = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.gettingNewAddress
2017-06-06 06:21:55 +02:00
);
2017-04-22 15:17:01 +02:00
export const shouldCheckAddressIsMine = createSelector(
_selectState,
selectCurrentPage,
selectReceiveAddress,
selectDaemonReady,
(state, page, address, daemonReady) => {
2017-06-06 23:19:12 +02:00
if (!daemonReady) return false;
if (address === undefined) return false;
if (state.addressOwnershipChecked) return false;
2017-04-22 15:17:01 +02:00
2017-06-06 23:19:12 +02:00
return true;
2017-04-22 15:17:01 +02:00
}
2017-06-06 06:21:55 +02:00
);
2017-04-23 07:55:47 +02:00
export const selectDraftTransaction = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.draftTransaction || {}
2017-06-06 06:21:55 +02:00
);
2017-04-23 07:55:47 +02:00
export const selectDraftTransactionAmount = createSelector(
selectDraftTransaction,
2017-06-06 23:19:12 +02:00
draft => draft.amount
2017-06-06 06:21:55 +02:00
);
2017-04-23 07:55:47 +02:00
export const selectDraftTransactionAddress = createSelector(
selectDraftTransaction,
2017-06-06 23:19:12 +02:00
draft => draft.address
2017-06-06 06:21:55 +02:00
);