2017-04-22 15:17:01 +02:00
|
|
|
import { createSelector } from 'reselect'
|
|
|
|
import {
|
|
|
|
selectCurrentPage,
|
2017-04-22 15:46:04 +02:00
|
|
|
selectDaemonReady,
|
2017-04-22 15:17:01 +02:00
|
|
|
} from 'selectors/app'
|
|
|
|
|
|
|
|
export const _selectState = state => state.wallet || {}
|
|
|
|
|
|
|
|
export const selectBalance = createSelector(
|
|
|
|
_selectState,
|
2017-04-22 18:07:46 +02:00
|
|
|
(state) => state.balance || 0
|
2017-04-22 15:17:01 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
export const selectTransactions = createSelector(
|
|
|
|
_selectState,
|
2017-04-22 18:07:46 +02:00
|
|
|
(state) => state.transactions || {}
|
2017-04-22 15:17:01 +02:00
|
|
|
)
|
|
|
|
|
2017-04-22 18:07:46 +02:00
|
|
|
export const selectTransactionsById = createSelector(
|
2017-04-22 15:17:01 +02:00
|
|
|
selectTransactions,
|
2017-04-22 18:07:46 +02:00
|
|
|
(transactions) => transactions.byId || {}
|
|
|
|
)
|
2017-04-22 15:17:01 +02:00
|
|
|
|
2017-04-22 18:07:46 +02:00
|
|
|
export const selectTransactionItems = createSelector(
|
|
|
|
selectTransactionsById,
|
|
|
|
(byId) => {
|
2017-04-22 15:17:01 +02:00
|
|
|
const transactionItems = []
|
2017-04-22 18:07:46 +02:00
|
|
|
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 shouldFetchTransactions = createSelector(
|
|
|
|
selectCurrentPage,
|
|
|
|
selectTransactions,
|
|
|
|
selectIsFetchingTransactions,
|
|
|
|
(page, transactions, fetching) => {
|
|
|
|
if (page != 'wallet') return false
|
|
|
|
if (fetching) return false
|
|
|
|
if (transactions.length != 0) return false
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectReceiveAddress = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.receiveAddress
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectGettingNewAddress = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.gettingNewAddress
|
|
|
|
)
|
|
|
|
|
|
|
|
export const shouldGetReceiveAddress = createSelector(
|
|
|
|
selectReceiveAddress,
|
|
|
|
selectGettingNewAddress,
|
|
|
|
selectDaemonReady,
|
|
|
|
(address, fetching, daemonReady) => {
|
|
|
|
if (!daemonReady) return false
|
|
|
|
if (fetching) return false
|
2017-04-22 15:46:04 +02:00
|
|
|
if (address) return false
|
2017-04-22 15:17:01 +02:00
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
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,
|
2017-04-24 09:25:27 +02:00
|
|
|
(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
|
|
|
|
)
|