fix: ensure reward claim happens after file view request
This commit is contained in:
parent
14f4401aef
commit
59872056eb
3 changed files with 29 additions and 24 deletions
|
@ -14,7 +14,7 @@ type Analytics = {
|
|||
pageView: string => void,
|
||||
setUser: Object => void,
|
||||
toggle: (boolean, ?boolean) => void,
|
||||
apiLogView: (string, string, string, ?number, ?() => void) => void,
|
||||
apiLogView: (string, string, string, ?number, ?() => void) => Promise<any>,
|
||||
apiLogPublish: () => void,
|
||||
tagFollowEvent: (string, boolean, string) => void,
|
||||
emailProvidedEvent: () => void,
|
||||
|
@ -49,25 +49,29 @@ const analytics: Analytics = {
|
|||
// @endif
|
||||
},
|
||||
apiLogView: (uri, outpoint, claimId, timeToStart) => {
|
||||
if (analyticsEnabled && (isProduction || devInternalApis)) {
|
||||
const params: {
|
||||
uri: string,
|
||||
outpoint: string,
|
||||
claim_id: string,
|
||||
time_to_start?: number,
|
||||
} = {
|
||||
uri,
|
||||
outpoint,
|
||||
claim_id: claimId,
|
||||
};
|
||||
return new Promise((resolve, reject) => {
|
||||
if (analyticsEnabled && (isProduction || devInternalApis)) {
|
||||
const params: {
|
||||
uri: string,
|
||||
outpoint: string,
|
||||
claim_id: string,
|
||||
time_to_start?: number,
|
||||
} = {
|
||||
uri,
|
||||
outpoint,
|
||||
claim_id: claimId,
|
||||
};
|
||||
|
||||
// lbry.tv streams from AWS so we don't care about the time to start
|
||||
if (timeToStart && !IS_WEB) {
|
||||
params.time_to_start = timeToStart;
|
||||
// lbry.tv streams from AWS so we don't care about the time to start
|
||||
if (timeToStart && !IS_WEB) {
|
||||
params.time_to_start = timeToStart;
|
||||
}
|
||||
|
||||
resolve(Lbryio.call('file', 'view', params));
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
|
||||
Lbryio.call('file', 'view', params);
|
||||
}
|
||||
});
|
||||
},
|
||||
apiLogSearch: () => {
|
||||
if (analyticsEnabled && isProduction) {
|
||||
|
|
|
@ -28,7 +28,7 @@ type Props = {
|
|||
title: ?string,
|
||||
floatingPlayerEnabled: boolean,
|
||||
clearPlayingUri: () => void,
|
||||
triggerAnalyticsView: (string, number) => void,
|
||||
triggerAnalyticsView: (string, number) => Promise<any>,
|
||||
claimRewards: () => void,
|
||||
};
|
||||
|
||||
|
@ -74,10 +74,11 @@ export default function FileViewer(props: Props) {
|
|||
useEffect(() => {
|
||||
if (playTime && isReadyToPlay && !hasRecordedView) {
|
||||
const timeToStart = Date.now() - playTime;
|
||||
triggerAnalyticsView(uri, timeToStart);
|
||||
claimRewards();
|
||||
setPlayTime(null);
|
||||
setHasRecordedView(false);
|
||||
triggerAnalyticsView(uri, timeToStart).then(() => {
|
||||
claimRewards();
|
||||
setHasRecordedView(false);
|
||||
setPlayTime(null);
|
||||
});
|
||||
}
|
||||
}, [setPlayTime, triggerAnalyticsView, isReadyToPlay, hasRecordedView, playTime, uri, claimRewards]);
|
||||
|
||||
|
|
|
@ -430,6 +430,6 @@ export function doAnalyticsView(uri, timeToStart) {
|
|||
return;
|
||||
}
|
||||
|
||||
analytics.apiLogView(uri, outpoint, claimId, timeToStart);
|
||||
return analytics.apiLogView(uri, outpoint, claimId, timeToStart);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue