enable purchases for paid content (#133)

This commit is contained in:
akinwale 2018-05-25 08:16:01 +01:00 committed by GitHub
parent 7d2e4c1e8c
commit 3c8e7d13e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 16 deletions

View file

@ -14,8 +14,9 @@ import {
} from 'react-native'; } from 'react-native';
import Colors from '../../styles/colors'; import Colors from '../../styles/colors';
import ChannelPage from '../channel'; import ChannelPage from '../channel';
import FileItemMedia from '../../component/fileItemMedia';
import FileDownloadButton from '../../component/fileDownloadButton'; import FileDownloadButton from '../../component/fileDownloadButton';
import FileItemMedia from '../../component/fileItemMedia';
import FilePrice from '../../component/filePrice';
import MediaPlayer from '../../component/mediaPlayer'; import MediaPlayer from '../../component/mediaPlayer';
import UriBar from '../../component/uriBar'; import UriBar from '../../component/uriBar';
import Video from 'react-native-video'; import Video from 'react-native-video';
@ -182,6 +183,7 @@ class FilePage extends React.PureComponent {
<FileItemMedia style={filePageStyle.thumbnail} title={title} thumbnail={metadata.thumbnail} />} <FileItemMedia style={filePageStyle.thumbnail} title={title} thumbnail={metadata.thumbnail} />}
{isPlayable && !this.state.mediaLoaded && <ActivityIndicator size="large" color={Colors.LbryGreen} style={filePageStyle.loading} />} {isPlayable && !this.state.mediaLoaded && <ActivityIndicator size="large" color={Colors.LbryGreen} style={filePageStyle.loading} />}
{!completed && !canLoadMedia && <FileDownloadButton uri={uri} style={filePageStyle.downloadButton} />} {!completed && !canLoadMedia && <FileDownloadButton uri={uri} style={filePageStyle.downloadButton} />}
{!fileInfo && <FilePrice uri={uri} style={filePageStyle.filePriceContainer} textStyle={filePageStyle.filePriceText} />}
</View> </View>
{canLoadMedia && <View style={playerBgStyle} />} {canLoadMedia && <View style={playerBgStyle} />}
{canLoadMedia && <MediaPlayer fileInfo={fileInfo} {canLoadMedia && <MediaPlayer fileInfo={fileInfo}

View file

@ -1,12 +1,15 @@
import { import {
ACTIONS, ACTIONS,
Lbry, Lbry,
doNotify,
formatCredits,
selectBalance, selectBalance,
makeSelectCostInfoForUri, makeSelectCostInfoForUri,
makeSelectFileInfoForUri, makeSelectFileInfoForUri,
makeSelectMetadataForUri,
selectDownloadingByOutpoint, selectDownloadingByOutpoint,
} from 'lbry-redux'; } from 'lbry-redux';
import { NativeModules } from 'react-native'; import { Alert, NativeModules } from 'react-native';
const DOWNLOAD_POLL_INTERVAL = 250; const DOWNLOAD_POLL_INTERVAL = 250;
@ -169,8 +172,10 @@ export function doLoadVideo(uri) {
data: { uri }, data: { uri },
}); });
console.log(`File timeout for uri ${uri}`); dispatch(doNotify({
//dispatch(doOpenModal(MODALS.FILE_TIMEOUT, { uri })); message: `File timeout for uri ${uri}`,
displayType: ['toast']
}));
} else { } else {
dispatch(doDownloadFile(uri, streamInfo)); dispatch(doDownloadFile(uri, streamInfo));
} }
@ -182,12 +187,10 @@ export function doLoadVideo(uri) {
data: { uri }, data: { uri },
}); });
console.log(`Failed to download ${uri}`); dispatch(doNotify({
/*dispatch( message: `Failed to download ${uri}, please try again. If this problem persists, visit https://lbry.io/faq/support for support.`,
doAlertError( displayType: ['toast']
`Failed to download ${uri}, please try again. If this problem persists, visit https://lbry.io/faq/support for support.` }));
)
);*/
}); });
}; };
} }
@ -197,13 +200,23 @@ export function doPurchaseUri(uri, specificCostInfo) {
const state = getState(); const state = getState();
const balance = selectBalance(state); const balance = selectBalance(state);
const fileInfo = makeSelectFileInfoForUri(uri)(state); const fileInfo = makeSelectFileInfoForUri(uri)(state);
const metadata = makeSelectMetadataForUri(uri)(state);
const title = metadata ? metadata.title : uri;
const downloadingByOutpoint = selectDownloadingByOutpoint(state); const downloadingByOutpoint = selectDownloadingByOutpoint(state);
const alreadyDownloading = fileInfo && !!downloadingByOutpoint[fileInfo.outpoint]; const alreadyDownloading = fileInfo && !!downloadingByOutpoint[fileInfo.outpoint];
function attemptPlay(cost, instantPurchaseMax = null) { function attemptPlay(cost, instantPurchaseMax = null) {
if (cost > 0 && (!instantPurchaseMax || cost > instantPurchaseMax)) { if (cost > 0 && (!instantPurchaseMax || cost > instantPurchaseMax)) {
//dispatch(doOpenModal(MODALS.AFFIRM_PURCHASE, { uri })); // display alert
console.log('Affirm purchase...'); const formattedCost = formatCredits(cost, 2);
const unit = cost === 1 ? 'credit' : 'credits';
Alert.alert('Confirm purchase',
`This will purchase "${title}" for ${formattedCost} ${unit}`,
[
{ text: 'OK', onPress: () => dispatch(doLoadVideo(uri)) },
{ text: 'Cancel', style: 'cancel' }
],
{ cancelable: true });
} else { } else {
dispatch(doLoadVideo(uri)); dispatch(doLoadVideo(uri));
} }
@ -231,15 +244,18 @@ export function doPurchaseUri(uri, specificCostInfo) {
if (cost > balance) { if (cost > balance) {
dispatch(doSetPlayingUri(null)); dispatch(doSetPlayingUri(null));
//dispatch(doOpenModal(MODALS.INSUFFICIENT_CREDITS)); dispatch(doNotify({
message: 'Insufficient credits',
displayType: ['toast']
}));
Promise.resolve(); Promise.resolve();
return; return;
} }
if (cost === 0/* || !makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state)*/) {
attemptPlay(cost); attemptPlay(cost);
} /*if (cost === 0 || !makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state)) {
/*} else { attemptPlay(cost);
} else {
const instantPurchaseMax = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_MAX)(state); const instantPurchaseMax = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_MAX)(state);
if (instantPurchaseMax.currency === 'LBC') { if (instantPurchaseMax.currency === 'LBC') {
attemptPlay(cost, instantPurchaseMax.amount); attemptPlay(cost, instantPurchaseMax.amount);

View file

@ -100,6 +100,22 @@ const filePageStyle = StyleSheet.create({
right: 0, right: 0,
bottom: 0 bottom: 0
}, },
filePriceContainer: {
backgroundColor: '#61fcd8',
justifyContent: 'center',
position: 'absolute',
right: 16,
top: 16,
width: 56,
height: 24,
borderRadius: 4
},
filePriceText: {
fontFamily: 'Metropolis-Bold',
fontSize: 12,
textAlign: 'center',
color: '#0c604b'
},
actions: { actions: {
paddingLeft: 16, paddingLeft: 16,
paddingRight: 16, paddingRight: 16,