remove the uri from the failed list if the user reattempts getting the same uri (#151)

* remove uri from failed purchase uris for a new purchase
* add doDeletePurchasedUri action
* add parseFloat for costInfo.cost
* add purhcaseUriErrorMessage and more failure handling
This commit is contained in:
Akinwale Ariwodola 2019-05-27 14:59:21 +01:00 committed by GitHub
parent 98d6922e21
commit a01b919c72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 133 additions and 10 deletions

53
dist/bundle.es.js vendored
View file

@ -119,6 +119,7 @@ const SET_FILE_LIST_SORT = 'SET_FILE_LIST_SORT';
const PURCHASE_URI_STARTED = 'PURCHASE_URI_STARTED';
const PURCHASE_URI_COMPLETED = 'PURCHASE_URI_COMPLETED';
const PURCHASE_URI_FAILED = 'PURCHASE_URI_FAILED';
const DELETE_PURCHASED_URI = 'DELETE_PURCHASED_URI';
const LOADING_FILE_STARTED = 'LOADING_FILE_STARTED';
const LOADING_FILE_COMPLETED = 'LOADING_FILE_COMPLETED';
const LOADING_FILE_FAILED = 'LOADING_FILE_FAILED';
@ -341,6 +342,7 @@ var action_types = /*#__PURE__*/Object.freeze({
PURCHASE_URI_STARTED: PURCHASE_URI_STARTED,
PURCHASE_URI_COMPLETED: PURCHASE_URI_COMPLETED,
PURCHASE_URI_FAILED: PURCHASE_URI_FAILED,
DELETE_PURCHASED_URI: DELETE_PURCHASED_URI,
LOADING_FILE_STARTED: LOADING_FILE_STARTED,
LOADING_FILE_COMPLETED: LOADING_FILE_COMPLETED,
LOADING_FILE_FAILED: LOADING_FILE_FAILED,
@ -2317,6 +2319,8 @@ const selectFileListDownloadedSort = reselect.createSelector(selectState$3, stat
const selectState$4 = state => state.file || {};
const selectPurchaseUriErrorMessage = reselect.createSelector(selectState$4, state => state.purchaseUriErrorMessage);
const selectFailedPurchaseUris = reselect.createSelector(selectState$4, state => state.failedPurchaseUris);
const selectPurchasedUris = reselect.createSelector(selectState$4, state => state.purchasedUris);
@ -2402,8 +2406,7 @@ function doPurchaseUri(uri, costInfo, saveFile = true) {
}
const { cost } = costInfo;
if (cost > balance) {
if (parseFloat(cost) > balance) {
dispatch({
type: PURCHASE_URI_FAILED,
data: { uri, error: 'Insufficient credits' }
@ -2415,6 +2418,13 @@ function doPurchaseUri(uri, costInfo, saveFile = true) {
};
}
function doDeletePurchasedUri(uri) {
return {
type: DELETE_PURCHASED_URI,
data: { uri }
};
}
function doFetchFileInfo(uri) {
return (dispatch, getState) => {
const state = getState();
@ -2912,7 +2922,21 @@ const reducers$1 = {};
const defaultState$1 = {
failedPurchaseUris: [],
purchasedUris: [],
purchasedStreamingUrls: {}
purchasedStreamingUrls: {},
purchaseUriErrorMessage: ''
};
reducers$1[PURCHASE_URI_STARTED] = (state, action) => {
const { uri } = action.data;
const newFailedPurchaseUris = state.failedPurchaseUris.slice();
if (newFailedPurchaseUris.includes(uri)) {
newFailedPurchaseUris.splice(newFailedPurchaseUris.indexOf(uri), 1);
}
return _extends$4({}, state, {
failedPurchaseUris: newFailedPurchaseUris,
purchaseUriErrorMessage: ''
});
};
reducers$1[PURCHASE_URI_COMPLETED] = (state, action) => {
@ -2934,19 +2958,34 @@ reducers$1[PURCHASE_URI_COMPLETED] = (state, action) => {
return _extends$4({}, state, {
failedPurchaseUris: newFailedPurchaseUris,
purchasedUris: newPurchasedUris,
purchasedStreamingUrls: newPurchasedStreamingUrls
purchasedStreamingUrls: newPurchasedStreamingUrls,
purchaseUriErrorMessage: ''
});
};
reducers$1[PURCHASE_URI_FAILED] = (state, action) => {
const { uri } = action.data;
const { uri, error } = action.data;
const newFailedPurchaseUris = state.failedPurchaseUris.slice();
if (!newFailedPurchaseUris.includes(uri)) {
newFailedPurchaseUris.push(uri);
}
return _extends$4({}, state, {
failedPurchaseUris: newFailedPurchaseUris
failedPurchaseUris: newFailedPurchaseUris,
purchaseUriErrorMessage: error
});
};
reducers$1[DELETE_PURCHASED_URI] = (state, action) => {
const { uri } = action.data;
const newPurchasedUris = state.purchasedUris.slice();
if (newPurchasedUris.includes(uri)) {
newPurchasedUris.splice(newPurchasedUris.indexOf(uri), 1);
}
return _extends$4({}, state, {
purchasedUris: newPurchasedUris
});
};
@ -3649,6 +3688,7 @@ exports.doBalanceSubscribe = doBalanceSubscribe;
exports.doBlurSearchInput = doBlurSearchInput;
exports.doCheckAddressIsMine = doCheckAddressIsMine;
exports.doCreateChannel = doCreateChannel;
exports.doDeletePurchasedUri = doDeletePurchasedUri;
exports.doDismissError = doDismissError;
exports.doDismissToast = doDismissToast;
exports.doError = doError;
@ -3770,6 +3810,7 @@ exports.selectMyClaimsWithoutChannels = selectMyClaimsWithoutChannels;
exports.selectPendingById = selectPendingById;
exports.selectPendingClaims = selectPendingClaims;
exports.selectPlayingUri = selectPlayingUri;
exports.selectPurchaseUriErrorMessage = selectPurchaseUriErrorMessage;
exports.selectPurchasedStreamingUrls = selectPurchasedStreamingUrls;
exports.selectPurchasedUris = selectPurchasedUris;
exports.selectReceiveAddress = selectReceiveAddress;

View file

@ -51,6 +51,22 @@ declare type PurchaseUriCompleted = {
declare type PurchaseUriFailed = {
type: ACTIONS.PURCHASE_URI_FAILED,
data: {
uri: string,
error: any
},
};
declare type PurchaseUriStarted = {
type: ACTIONS.PURCHASE_URI_STARTED,
data: {
uri: string,
streamingUrl: string,
},
};
declare type DeletePurchasedUri = {
type: ACTIONS.DELETE_PURCHASED_URI,
data: {
uri: string
},

16
flow-typed/File.js vendored
View file

@ -51,6 +51,22 @@ declare type PurchaseUriCompleted = {
declare type PurchaseUriFailed = {
type: ACTIONS.PURCHASE_URI_FAILED,
data: {
uri: string,
error: any
},
};
declare type PurchaseUriStarted = {
type: ACTIONS.PURCHASE_URI_STARTED,
data: {
uri: string,
streamingUrl: string,
},
};
declare type DeletePurchasedUri = {
type: ACTIONS.DELETE_PURCHASED_URI,
data: {
uri: string
},

View file

@ -109,6 +109,7 @@ export const SET_FILE_LIST_SORT = 'SET_FILE_LIST_SORT';
export const PURCHASE_URI_STARTED = 'PURCHASE_URI_STARTED';
export const PURCHASE_URI_COMPLETED = 'PURCHASE_URI_COMPLETED';
export const PURCHASE_URI_FAILED = 'PURCHASE_URI_FAILED';
export const DELETE_PURCHASED_URI = 'DELETE_PURCHASED_URI';
export const LOADING_FILE_STARTED = 'LOADING_FILE_STARTED';
export const LOADING_FILE_COMPLETED = 'LOADING_FILE_COMPLETED';
export const LOADING_FILE_FAILED = 'LOADING_FILE_FAILED';

View file

@ -47,7 +47,7 @@ export {
doCreateChannel,
} from 'redux/actions/claims';
export { doPurchaseUri, doFileGet } from 'redux/actions/file';
export { doDeletePurchasedUri, doPurchaseUri, doFileGet } from 'redux/actions/file';
export {
doFetchFileInfo,
@ -111,6 +111,7 @@ export {
selectFailedPurchaseUris,
selectPurchasedUris,
selectPurchasedStreamingUrls,
selectPurchaseUriErrorMessage,
selectLastPurchasedUri,
makeSelectStreamingUrlForUri,
} from 'redux/selectors/file';

View file

@ -88,8 +88,7 @@ export function doPurchaseUri(uri: string, costInfo: { cost: number }, saveFile:
}
const { cost } = costInfo;
if (cost > balance) {
if (parseFloat(cost) > balance) {
dispatch({
type: ACTIONS.PURCHASE_URI_FAILED,
data: { uri, error: 'Insufficient credits' },
@ -102,3 +101,10 @@ export function doPurchaseUri(uri: string, costInfo: { cost: number }, saveFile:
dispatch(doFileGet(uri, saveFile));
};
}
export function doDeletePurchasedUri(uri: string) {
return {
type: ACTIONS.DELETE_PURCHASED_URI,
data: { uri },
};
}

View file

@ -6,6 +6,24 @@ const defaultState = {
failedPurchaseUris: [],
purchasedUris: [],
purchasedStreamingUrls: {},
purchaseUriErrorMessage: '',
};
reducers[ACTIONS.PURCHASE_URI_STARTED] = (
state: FileState,
action: PurchaseUriStarted
): FileState => {
const { uri } = action.data;
const newFailedPurchaseUris = state.failedPurchaseUris.slice();
if (newFailedPurchaseUris.includes(uri)) {
newFailedPurchaseUris.splice(newFailedPurchaseUris.indexOf(uri), 1);
}
return {
...state,
failedPurchaseUris: newFailedPurchaseUris,
purchaseUriErrorMessage: '',
};
};
reducers[ACTIONS.PURCHASE_URI_COMPLETED] = (
@ -32,6 +50,7 @@ reducers[ACTIONS.PURCHASE_URI_COMPLETED] = (
failedPurchaseUris: newFailedPurchaseUris,
purchasedUris: newPurchasedUris,
purchasedStreamingUrls: newPurchasedStreamingUrls,
purchaseUriErrorMessage: '',
};
};
@ -39,8 +58,9 @@ reducers[ACTIONS.PURCHASE_URI_FAILED] = (
state: FileState,
action: PurchaseUriFailed
): FileState => {
const { uri } = action.data;
const { uri, error } = action.data;
const newFailedPurchaseUris = state.failedPurchaseUris.slice();
if (!newFailedPurchaseUris.includes(uri)) {
newFailedPurchaseUris.push(uri);
}
@ -48,6 +68,23 @@ reducers[ACTIONS.PURCHASE_URI_FAILED] = (
return {
...state,
failedPurchaseUris: newFailedPurchaseUris,
purchaseUriErrorMessage: error,
};
};
reducers[ACTIONS.DELETE_PURCHASED_URI] = (
state: FileState,
action: DeletePurchasedUri
): FileState => {
const { uri } = action.data;
const newPurchasedUris = state.purchasedUris.slice();
if (newPurchasedUris.includes(uri)) {
newPurchasedUris.splice(newPurchasedUris.indexOf(uri), 1);
}
return {
...state,
purchasedUris: newPurchasedUris,
};
};

View file

@ -5,6 +5,11 @@ type State = { file: FileState };
export const selectState = (state: State): FileState => state.file || {};
export const selectPurchaseUriErrorMessage: (state: State) => string = createSelector(
selectState,
state => state.purchaseUriErrorMessage
);
export const selectFailedPurchaseUris: (state: State) => Array<string> = createSelector(
selectState,
state => state.failedPurchaseUris