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-08-21 05:38:34 +02:00
|
|
|
state => 0 //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
|
|
|
|
2017-04-22 18:07:46 +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
|
|
|
|
2017-04-22 18:07:46 +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];
|
2017-04-22 18:07:46 +02:00
|
|
|
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
|
|
|
|
2017-08-20 23:42:00 +02:00
|
|
|
export const selectRecentTransactions = createSelector(
|
|
|
|
selectTransactionItems,
|
|
|
|
transactions => {
|
|
|
|
let threshold = new Date();
|
|
|
|
threshold.setDate(threshold.getDate() - 7);
|
|
|
|
return transactions.filter(transaction => {
|
|
|
|
return transaction.date > threshold;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
export const selectHasTransactions = createSelector(
|
|
|
|
selectTransactionItems,
|
|
|
|
transactions => {
|
|
|
|
return transactions && transactions.length > 0;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
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
|
|
|
|
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
|
|
|
);
|