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

84 lines
1.9 KiB
JavaScript
Raw Normal View History

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