Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Migrate 'SettlementButton.js' component to TypeScript PART-2 #35877

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/SettlementButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function SettlementButton({
}

if (iouPaymentType === CONST.IOU.REPORT_ACTION_TYPE.APPROVE) {
IOU.approveMoneyRequest(iouReport);
IOU.approveMoneyRequest(iouReport ?? {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZhenjaHorbach @mountiny
shouldn't this be moved to the if check? Are we sure we want to pass in an empty object to that function when the report action type is approved and I would assume - ready to process? Seems some of the keys would end up like report_undefined etc.

Copy link
Contributor Author

@ZhenjaHorbach ZhenjaHorbach Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory this may never happen )
But following the iouReport typing it can be null

And you mean not call IOU.approveMoneyRequest when iouReport is empty ?

Copy link
Contributor

@Swor71 Swor71 Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well imo if that can happen the function should handle such case.

also, if it can be null as you say, it will crash, if you attempt to access any props on it

I am not familiar with this part of the code, just stumbled upon that today when we were fixing the latest main merge on a different pr so I am not sure if not calling IOU.approveMoneyRequest in such case is valid, just applying some logic here, but it might be flawed as stated above.

return;
}

Expand Down
5 changes: 2 additions & 3 deletions src/libs/API/parameters/PayMoneyRequestParams.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type CONST from '@src/CONST';
import type DeepValueOf from '@src/types/utils/DeepValueOf';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';

type PayMoneyRequestParams = {
iouReportID: string;
chatReportID: string;
reportActionID: string;
paymentMethodType: DeepValueOf<typeof CONST.IOU.PAYMENT_TYPE>;
paymentMethodType: PaymentMethodType;
};

export default PayMoneyRequestParams;
5 changes: 2 additions & 3 deletions src/libs/API/parameters/SendMoneyParams.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type CONST from '@src/CONST';
import type DeepValueOf from '@src/types/utils/DeepValueOf';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';

type SendMoneyParams = {
iouReportID: string;
chatReportID: string;
reportActionID: string;
paymentMethodType: DeepValueOf<typeof CONST.IOU.PAYMENT_TYPE>;
paymentMethodType: PaymentMethodType;
transactionID: string;
newIOUReportDetails: string;
createdReportActionID: string;
Expand Down
6 changes: 2 additions & 4 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ import type SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import type {Participant, Split} from '@src/types/onyx/IOU';
import type {ErrorFields, Errors} from '@src/types/onyx/OnyxCommon';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import type ReportAction from '@src/types/onyx/ReportAction';
import type {OnyxData} from '@src/types/onyx/Request';
import type {Comment, Receipt, ReceiptSource, TaxRate, TransactionChanges, WaypointCollection} from '@src/types/onyx/Transaction';
import type DeepValueOf from '@src/types/utils/DeepValueOf';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import * as Policy from './Policy';
Expand All @@ -63,8 +63,6 @@ type MoneyRequestRoute = StackScreenProps<MoneyRequestNavigatorParamList, typeof

type IOURequestType = ValueOf<typeof CONST.IOU.REQUEST_TYPE>;

type PaymentMethodType = DeepValueOf<typeof CONST.IOU.PAYMENT_TYPE>;

type OneOnOneIOUReport = OnyxTypes.Report | undefined | null;

type MoneyRequestInformation = {
Expand Down Expand Up @@ -3255,7 +3253,7 @@ function sendMoneyWithWallet(report: OnyxTypes.Report, amount: number, currency:
Report.notifyNewAction(params.chatReportID, managerID);
}

function approveMoneyRequest(expenseReport: OnyxTypes.Report) {
function approveMoneyRequest(expenseReport: OnyxTypes.Report | EmptyObject) {
const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`] ?? null;

const optimisticApprovedReportAction = ReportUtils.buildOptimisticApprovedReportAction(expenseReport.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID);
Expand Down
Loading