diff --git a/lib/actions/report-actions.js b/lib/actions/report-actions.js --- a/lib/actions/report-actions.js +++ b/lib/actions/report-actions.js @@ -1,8 +1,14 @@ // @flow -import type { AuthMetadata } from '../shared/identity-client-context'; +import * as React from 'react'; + +import { + IdentityClientContext, + type AuthMetadata, +} from '../shared/identity-client-context.js'; import type { ClientReportCreationRequest, + ReportsServiceSendReportsAction, ReportCreationResponse, } from '../types/report-types.js'; import { sendReports as callSendReports } from '../utils/reports-service.js'; @@ -27,6 +33,22 @@ return { id }; }; +function useSendReports(): ReportsServiceSendReportsAction { + const identityContext = React.useContext(IdentityClientContext); + const getAuthMetadata = identityContext?.getAuthMetadata; + + return React.useCallback( + async request => { + let authMetadata; + if (getAuthMetadata) { + authMetadata = await getAuthMetadata(); + } + return callSendReports(request, authMetadata); + }, + [getAuthMetadata], + ); +} + const sendReportsActionTypes = Object.freeze({ started: 'SEND_REPORTS_STARTED', success: 'SEND_REPORTS_SUCCESS', @@ -40,4 +62,5 @@ sendReport, sendReportsActionTypes, queueReportsActionType, + useSendReports, }; diff --git a/lib/socket/report-handler.react.js b/lib/socket/report-handler.react.js --- a/lib/socket/report-handler.react.js +++ b/lib/socket/report-handler.react.js @@ -2,18 +2,21 @@ import * as React from 'react'; -import { sendReportsActionTypes } from '../actions/report-actions.js'; +import { + sendReportsActionTypes, + useSendReports, +} from '../actions/report-actions.js'; import { queuedReports as queuedReportsSelector } from '../selectors/socket-selectors.js'; import { type ClientReportCreationRequest, type ClearDeliveredReportsPayload, + type ReportsServiceSendReportsAction, } from '../types/report-types.js'; import { type DispatchActionPromise, useDispatchActionPromise, } from '../utils/redux-promise-utils.js'; import { useSelector } from '../utils/redux-utils.js'; -import { sendReports } from '../utils/reports-service.js'; type BaseProps = { +canSendReports: boolean, @@ -22,6 +25,7 @@ ...BaseProps, +queuedReports: $ReadOnlyArray, +dispatchActionPromise: DispatchActionPromise, + +sendReports: ReportsServiceSendReportsAction, }; class ReportHandler extends React.PureComponent { componentDidMount() { @@ -69,7 +73,7 @@ async sendReports( reports: $ReadOnlyArray, ): Promise { - await sendReports(reports); + await this.props.sendReports(reports); return { reports }; } } @@ -78,12 +82,14 @@ React.memo(function ConnectedReportHandler(props) { const queuedReports = useSelector(queuedReportsSelector); const dispatchActionPromise = useDispatchActionPromise(); + const callSendReports = useSendReports(); return ( ); }); diff --git a/lib/types/report-types.js b/lib/types/report-types.js --- a/lib/types/report-types.js +++ b/lib/types/report-types.js @@ -204,6 +204,9 @@ export type ReportsServiceSendReportsResponse = { +reportIDs: $ReadOnlyArray, }; +export type ReportsServiceSendReportsAction = ( + request: ReportsServiceSendReportsRequest, +) => Promise; // Keyserver specific types type ReportInfo = { diff --git a/native/crash.react.js b/native/crash.react.js --- a/native/crash.react.js +++ b/native/crash.react.js @@ -155,21 +155,25 @@ actions: actionLogger.actions, }: any); const sanitizedReduxReport = sanitizeReduxReport(rawReduxReport); - const result = await sendReport({ - type: reportTypes.ERROR, - platformDetails: { - platform: Platform.OS, - codeVersion, - stateVersion: persistConfig.version, + const authMetadata = await commCoreModule.getCommServicesAuthMetadata(); + const result = await sendReport( + { + type: reportTypes.ERROR, + platformDetails: { + platform: Platform.OS, + codeVersion, + stateVersion: persistConfig.version, + }, + errors: this.props.errorData.map(data => ({ + errorMessage: data.error.message, + stack: data.error.stack, + componentStack: data.info && data.info.componentStack, + })), + ...sanitizedReduxReport, + id: generateReportID(), }, - errors: this.props.errorData.map(data => ({ - errorMessage: data.error.message, - stack: data.error.stack, - componentStack: data.info && data.info.componentStack, - })), - ...sanitizedReduxReport, - id: generateReportID(), - }); + authMetadata, + ); this.setState({ errorReportID: result.id, doneWaiting: true,