Skip to content

Commit

Permalink
LBC Purchase Modal: repeat fund check instead of failing silently
Browse files Browse the repository at this point in the history
## Issue
The purchase button invokes the modal, and the modal just fails silently when there's insufficient funds.

## Change
I believe we used to show the button differently when the funds are insufficient (grayed out?).

Given the purchase button + claim overlay refactoring, it's probably easier now to just let the user click the button, and inform in the modal if there's insufficient funds. The file page already have the same "insufficient fund" warning.
  • Loading branch information
infinite-persistence committed Aug 29, 2023
1 parent 0e0e06f commit 2e0c400
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ui/modal/modalAffirmPurchase/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { connect } from 'react-redux';
import { doPlayUri, doSetPlayingUri } from 'redux/actions/content';
import { selectPlayingUri } from 'redux/selectors/content';
import { selectInsufficientCreditsForUri, selectPlayingUri } from 'redux/selectors/content';
import { doHideModal, doAnaltyicsPurchaseEvent } from 'redux/actions/app';
import { makeSelectMetadataForUri } from 'redux/selectors/claims';
import ModalAffirmPurchase from './view';

const select = (state, props) => ({
isInsufficientCredits: selectInsufficientCreditsForUri(state, props.uri),
metadata: makeSelectMetadataForUri(props.uri)(state),
playingUri: selectPlayingUri(state),
});
Expand Down
22 changes: 21 additions & 1 deletion ui/modal/modalAffirmPurchase/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React from 'react';
import classnames from 'classnames';
import analytics from 'analytics';
import ClaimInsufficientCredits from 'component/claimInsufficientCredits';
import FilePrice from 'component/filePrice';
import { Modal } from 'modal/modal';
import Card from 'component/common/card';
Expand All @@ -13,6 +14,7 @@ import { isURIEqual } from 'util/lbryURI';
const ANIMATION_LENGTH = 2500;

type Props = {
isInsufficientCredits: boolean,
closeModal: () => void,
loadVideo: (string, (GetResponse) => void) => void,
uri: string,
Expand All @@ -25,7 +27,17 @@ type Props = {
};

function ModalAffirmPurchase(props: Props) {
const { closeModal, loadVideo, metadata, uri, analyticsPurchaseEvent, playingUri, setPlayingUri, cancelCb } = props;
const {
isInsufficientCredits,
closeModal,
loadVideo,
metadata,
uri,
analyticsPurchaseEvent,
playingUri,
setPlayingUri,
cancelCb,
} = props;
const [success, setSuccess] = React.useState(false);
const [purchasing, setPurchasing] = React.useState(false);
const modalTitle = __('Confirm Purchase');
Expand Down Expand Up @@ -81,6 +93,14 @@ function ModalAffirmPurchase(props: Props) {
// eslint-disable-next-line react-hooks/exhaustive-deps -- on mount
}, []);

if (isInsufficientCredits) {
return (
<Modal type="card" isOpen onAborted={cancelPurchase}>
<Card title={__('Insufficient credits')} subtitle={<ClaimInsufficientCredits uri={uri} />} />
</Modal>
);
}

return (
<Modal type="card" isOpen contentLabel={modalTitle} onAborted={cancelPurchase}>
<Card
Expand Down

0 comments on commit 2e0c400

Please sign in to comment.