Additional tipping fixes/changes

- [x] Display empty message on empty filtered Tx list
- [ ] Tipping form has to stay open until success is detected(or closed
by user)
- [ ] Storing the older transaction list, and refreshing the new one in
the background.

Tip Box shown until valid Txn or manually cancelled

Cleanup of show tip box logic
This commit is contained in:
hackrush 2017-09-16 16:32:54 +05:30 committed by Jeremy Kauffman
parent c3a9eee10a
commit ae81843c05
11 changed files with 75 additions and 42 deletions

View file

@ -4,6 +4,14 @@ import { doOpenModal, doShowSnackBar } from "actions/app";
import * as types from "constants/action_types"; import * as types from "constants/action_types";
import * as modals from "constants/modal_types"; import * as modals from "constants/modal_types";
export function doShowTipBox() {
return { type: types.SHOW_TIP_BOX };
}
export function doHideTipBox() {
return { type: types.HIDE_TIP_BOX };
}
export function doSendSupport(amount, claim_id) { export function doSendSupport(amount, claim_id) {
return function(dispatch, getState) { return function(dispatch, getState) {
const state = getState(); const state = getState();
@ -22,6 +30,7 @@ export function doSendSupport(amount, claim_id) {
dispatch({ dispatch({
type: types.SUPPORT_TRANSACTION_COMPLETED, type: types.SUPPORT_TRANSACTION_COMPLETED,
}); });
dispatch(doHideTipBox);
dispatch( dispatch(
doShowSnackBar({ doShowSnackBar({
message: __(`You sent ${amount} LBC as support, Mahalo!`), message: __(`You sent ${amount} LBC as support, Mahalo!`),
@ -32,7 +41,7 @@ export function doSendSupport(amount, claim_id) {
} else { } else {
dispatch({ dispatch({
type: types.SUPPORT_TRANSACTION_FAILED, type: types.SUPPORT_TRANSACTION_FAILED,
data: { error: results }, data: { error: results.code },
}); });
dispatch(doOpenModal(modals.TRANSACTION_FAILED)); dispatch(doOpenModal(modals.TRANSACTION_FAILED));
} }
@ -41,7 +50,7 @@ export function doSendSupport(amount, claim_id) {
const errorCallback = error => { const errorCallback = error => {
dispatch({ dispatch({
type: types.SUPPORT_TRANSACTION_FAILED, type: types.SUPPORT_TRANSACTION_FAILED,
data: { error: error.message }, data: { error: error.code },
}); });
dispatch(doOpenModal(modals.TRANSACTION_FAILED)); dispatch(doOpenModal(modals.TRANSACTION_FAILED));
}; };

View file

@ -9,6 +9,7 @@ import { doOpenFileInShell, doOpenFileInFolder } from "actions/file_info";
import { makeSelectClaimIsMine } from "selectors/claims"; import { makeSelectClaimIsMine } from "selectors/claims";
import { doPurchaseUri, doLoadVideo, doStartDownload } from "actions/content"; import { doPurchaseUri, doLoadVideo, doStartDownload } from "actions/content";
import { doNavigate } from "actions/navigation"; import { doNavigate } from "actions/navigation";
import { doShowTipBox } from "actions/claims";
import FileActions from "./view"; import FileActions from "./view";
const select = (state, props) => ({ const select = (state, props) => ({
@ -25,6 +26,7 @@ const perform = dispatch => ({
startDownload: uri => dispatch(doPurchaseUri(uri)), startDownload: uri => dispatch(doPurchaseUri(uri)),
restartDownload: (uri, outpoint) => dispatch(doStartDownload(uri, outpoint)), restartDownload: (uri, outpoint) => dispatch(doStartDownload(uri, outpoint)),
editClaim: claimId => dispatch(doNavigate("/publish", { id: claimId })), editClaim: claimId => dispatch(doNavigate("/publish", { id: claimId })),
showTipBox: () => dispatch(doShowTipBox()),
}); });
export default connect(select, perform)(FileActions); export default connect(select, perform)(FileActions);

View file

@ -4,10 +4,6 @@ import FileDownloadLink from "component/fileDownloadLink";
import * as modals from "constants/modal_types"; import * as modals from "constants/modal_types";
class FileActions extends React.PureComponent { class FileActions extends React.PureComponent {
handleSupportButtonClicked() {
this.props.onTipShow();
}
render() { render() {
const { const {
fileInfo, fileInfo,
@ -37,7 +33,7 @@ class FileActions extends React.PureComponent {
button="text" button="text"
icon="icon-gift" icon="icon-gift"
label={__("Support")} label={__("Support")}
onClick={this.handleSupportButtonClicked.bind(this)} onClick={this.props.showTipBox}
/> />
<Link <Link
button="text" button="text"

View file

@ -1,12 +1,13 @@
import React from "react"; import React from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { doSendSupport } from "actions/claims"; import { doSendSupport, doHideTipBox } from "actions/claims";
import TipLink from "./view"; import TipLink from "./view";
const select = state => ({}); const select = state => ({});
const perform = dispatch => ({ const perform = dispatch => ({
sendSupport: (amount, claim_id) => dispatch(doSendSupport(amount, claim_id)), sendSupport: (amount, claim_id) => dispatch(doSendSupport(amount, claim_id)),
hideTipBox: () => dispatch(doHideTipBox()),
}); });
export default connect(select, perform)(TipLink); export default connect(select, perform)(TipLink);

View file

@ -7,7 +7,7 @@ class TipLink extends React.PureComponent {
super(props); super(props);
this.state = { this.state = {
tipAmount: 1.0, tipAmount: 0.0,
}; };
} }
@ -15,11 +15,10 @@ class TipLink extends React.PureComponent {
let claim_id = this.props.claim_id; let claim_id = this.props.claim_id;
let amount = this.state.tipAmount; let amount = this.state.tipAmount;
this.props.sendSupport(amount, claim_id); this.props.sendSupport(amount, claim_id);
this.props.onTipHide();
} }
handleSupportCancelButtonClicked() { handleSupportCancelButtonClicked() {
this.props.onTipHide(); this.props.hideTipBox();
} }
handleSupportPriceChange(event) { handleSupportPriceChange(event) {

View file

@ -125,13 +125,26 @@ class TransactionTableBody extends React.PureComponent {
render() { render() {
const { transactions, filter } = this.props; const { transactions, filter } = this.props;
let transactionList = transactions
.filter(this.filterList, this)
.filter(this.removeFeeTx, this)
.map(this.renderBody, this);
if (transactionList.length == 0) {
return (
<tbody>
<tr>
<td className="empty" colSpan="3">
{__("There are no transactions of this type.")}
</td>
</tr>
</tbody>
);
}
return ( return (
<tbody> <tbody>
{transactions {transactionList}
.filter(this.filterList, this)
.filter(this.removeFeeTx, this)
.map(this.renderBody, this)}
</tbody> </tbody>
); );
} }

View file

@ -136,6 +136,8 @@ export const FETCH_REWARD_CONTENT_COMPLETED = "FETCH_REWARD_CONTENT_COMPLETED";
export const SUPPORT_TRANSACTION_STARTED = "SUPPORT_TRANSACTION_STARTED"; export const SUPPORT_TRANSACTION_STARTED = "SUPPORT_TRANSACTION_STARTED";
export const SUPPORT_TRANSACTION_COMPLETED = "SUPPORT_TRANSACTION_COMPLETED"; export const SUPPORT_TRANSACTION_COMPLETED = "SUPPORT_TRANSACTION_COMPLETED";
export const SUPPORT_TRANSACTION_FAILED = "SUPPORT_TRANSACTION_FAILED"; export const SUPPORT_TRANSACTION_FAILED = "SUPPORT_TRANSACTION_FAILED";
export const HIDE_TIP_BOX = "HIDE_TIP_BOX";
export const SHOW_TIP_BOX = "SHOW_TIP_BOX";
//Language //Language
export const DOWNLOAD_LANGUAGE_SUCCEEDED = "DOWNLOAD_LANGUAGE_SUCCEEDED"; export const DOWNLOAD_LANGUAGE_SUCCEEDED = "DOWNLOAD_LANGUAGE_SUCCEEDED";

View file

@ -9,6 +9,7 @@ import {
makeSelectClaimForUri, makeSelectClaimForUri,
makeSelectContentTypeForUri, makeSelectContentTypeForUri,
makeSelectMetadataForUri, makeSelectMetadataForUri,
selectShowTipBox,
} from "selectors/claims"; } from "selectors/claims";
import { makeSelectCostInfoForUri } from "selectors/cost_info"; import { makeSelectCostInfoForUri } from "selectors/cost_info";
import { selectShowNsfw } from "selectors/settings"; import { selectShowNsfw } from "selectors/settings";
@ -20,6 +21,7 @@ const select = (state, props) => ({
costInfo: makeSelectCostInfoForUri(props.uri)(state), costInfo: makeSelectCostInfoForUri(props.uri)(state),
metadata: makeSelectMetadataForUri(props.uri)(state), metadata: makeSelectMetadataForUri(props.uri)(state),
obscureNsfw: !selectShowNsfw(state), obscureNsfw: !selectShowNsfw(state),
showTipBox: selectShowTipBox(state),
fileInfo: makeSelectFileInfoForUri(props.uri)(state), fileInfo: makeSelectFileInfoForUri(props.uri)(state),
rewardedContentClaimIds: selectRewardContentClaimIds(state, props), rewardedContentClaimIds: selectRewardContentClaimIds(state, props),
}); });

View file

@ -71,18 +71,6 @@ class FilePage extends React.PureComponent {
} }
} }
handleTipShow() {
this.setState({
showTipBox: true,
});
}
handleTipHide() {
this.setState({
showTipBox: false,
});
}
render() { render() {
const { const {
claim, claim,
@ -91,10 +79,9 @@ class FilePage extends React.PureComponent {
contentType, contentType,
uri, uri,
rewardedContentClaimIds, rewardedContentClaimIds,
showTipBox,
} = this.props; } = this.props;
const { showTipBox } = this.state;
if (!claim || !metadata) { if (!claim || !metadata) {
return ( return (
<span className="empty">{__("Empty claim or metadata info.")}</span> <span className="empty">{__("Empty claim or metadata info.")}</span>
@ -156,10 +143,7 @@ class FilePage extends React.PureComponent {
</Link> </Link>
: uriIndicator} : uriIndicator}
</div> </div>
<FileActions <FileActions uri={uri} />
uri={uri}
onTipShow={this.handleTipShow.bind(this)}
/>
</div> </div>
{!showTipBox && {!showTipBox &&
<div className="card__content card__subtext card__subtext card__subtext--allow-newlines"> <div className="card__content card__subtext card__subtext card__subtext--allow-newlines">
@ -179,13 +163,7 @@ class FilePage extends React.PureComponent {
/> />
</div> </div>
: ""} : ""}
{showTipBox {showTipBox ? <TipLink claim_id={claim.claim_id} /> : ""}
? <TipLink
onTipShow={this.handleTipShow.bind(this)}
onTipHide={this.handleTipHide.bind(this)}
claim_id={claim.claim_id}
/>
: ""}
{!showTipBox && {!showTipBox &&
<div className="card__content"> <div className="card__content">
<Link <Link

View file

@ -1,7 +1,14 @@
import * as types from "constants/action_types"; import * as types from "constants/action_types";
const reducers = {}; const reducers = {};
const defaultState = {};
const buildSupportTransaction = () => ({
tipBoxShown: false,
});
const defaultState = {
supportTransaction: buildSupportTransaction(),
};
reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) { reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) {
const { uri, certificate, claim } = action.data; const { uri, certificate, claim } = action.data;
@ -189,6 +196,22 @@ reducers[types.CREATE_CHANNEL_COMPLETED] = function(state, action) {
}); });
}; };
reducers[types.HIDE_TIP_BOX] = function(state, action) {
return Object.assign({}, state, {
supportTransaction: buildSupportTransaction(),
});
};
reducers[types.SHOW_TIP_BOX] = function(state, action) {
const newSupportTransaction = Object.assign({}, state.supportTransaction, {
tipBoxShown: true,
});
return Object.assign({}, state, {
supportTransaction: newSupportTransaction,
});
};
reducers[types.SUPPORT_TRANSACTION_STARTED] = function(state, action) { reducers[types.SUPPORT_TRANSACTION_STARTED] = function(state, action) {
const newSupportTransaction = Object.assign({}, state.supportTransaction, { const newSupportTransaction = Object.assign({}, state.supportTransaction, {
sendingSupport: true, sendingSupport: true,
@ -200,13 +223,16 @@ reducers[types.SUPPORT_TRANSACTION_STARTED] = function(state, action) {
}; };
reducers[types.SUPPORT_TRANSACTION_COMPLETED] = function(state, action) { reducers[types.SUPPORT_TRANSACTION_COMPLETED] = function(state, action) {
return Object.assign({}, state); return Object.assign({}, state, {
supportTransaction: buildSupportTransaction(),
});
}; };
reducers[types.SUPPORT_TRANSACTION_FAILED] = function(state, action) { reducers[types.SUPPORT_TRANSACTION_FAILED] = function(state, action) {
const newSupportTransaction = Object.assign({}, state.supportTransaction, { const newSupportTransaction = Object.assign({}, state.supportTransaction, {
sendingSupport: false, sendingSupport: false,
error: action.data.error, error: action.data.error,
tipBoxShown: true,
}); });
return Object.assign({}, state, { return Object.assign({}, state, {

View file

@ -174,3 +174,8 @@ export const selectMyChannelClaims = createSelector(
return claims; return claims;
} }
); );
export const selectShowTipBox = createSelector(
_selectState,
state => state.supportTransaction.tipBoxShown
);