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,6 +49,7 @@ const analytics: Analytics = {
|
|||
// @endif
|
||||
},
|
||||
apiLogView: (uri, outpoint, claimId, timeToStart) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (analyticsEnabled && (isProduction || devInternalApis)) {
|
||||
const params: {
|
||||
uri: string,
|
||||
|
@ -66,8 +67,11 @@ const analytics: Analytics = {
|
|||
params.time_to_start = timeToStart;
|
||||
}
|
||||
|
||||
Lbryio.call('file', 'view', params);
|
||||
resolve(Lbryio.call('file', 'view', params));
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
},
|
||||
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);
|
||||
triggerAnalyticsView(uri, timeToStart).then(() => {
|
||||
claimRewards();
|
||||
setPlayTime(null);
|
||||
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