Skip to content

Fix LHN display issue for money request via scan#25906

Merged
luacmartins merged 30 commits intoExpensify:mainfrom
ygshbht:fix-LHN-scan-money-request-issue3
Sep 5, 2023
Merged

Fix LHN display issue for money request via scan#25906
luacmartins merged 30 commits intoExpensify:mainfrom
ygshbht:fix-LHN-scan-money-request-issue3

Conversation

@ygshbht
Copy link
Contributor

@ygshbht ygshbht commented Aug 24, 2023

Details

Fixed Issues

$ #25778
PROPOSAL: #25778 (comment)

Tests

  1. As userA, request money from userB via Scan
  2. Notice that the LHN properly shows Scan in progress
  • Verify that no errors appear in the JS console

Offline tests

Same as Tests

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
desktop.web.mp4
Mobile Web - Chrome
android_chrome_speedup_720p.mp4
Mobile Web - Safari
safari_speedup_720p.mp4
Desktop
desktop.3.mp4
iOS
ios_speedup_720p.mp4
Android
android_trimmed_720p.mp4

@ygshbht ygshbht requested a review from a team as a code owner August 24, 2023 22:50
@melvin-bot melvin-bot bot removed the request for review from a team August 24, 2023 22:50
@melvin-bot
Copy link

melvin-bot bot commented Aug 24, 2023

@thesahindia Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@allroundexperts
Copy link
Contributor

Taking this one over!

@allroundexperts
Copy link
Contributor

allroundexperts commented Aug 28, 2023

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Screen.Recording.2023-09-05.at.10.09.39.PM.mov
Mobile Web - Chrome
Screen.Recording.2023-09-05.at.10.19.54.PM.mov
Mobile Web - Safari
Screen.Recording.2023-09-05.at.10.22.14.PM.mov
Desktop
Screen.Recording.2023-09-05.at.10.27.45.PM.mov
iOS
Screen.Recording.2023-09-05.at.10.24.47.PM.mov
Android
Screen.Recording.2023-09-05.at.10.23.58.PM.mov

@allroundexperts
Copy link
Contributor

allroundexperts commented Aug 29, 2023

Hi @ygshbht!

I'm still seeing Requested 0.00 in the LHN.

Screen.Recording.2023-08-29.at.4.58.34.AM.mov

Can you please check / confirm?

@ygshbht
Copy link
Contributor Author

ygshbht commented Aug 29, 2023

@allroundexperts can you share a screenshot or video of the issue?

@allroundexperts
Copy link
Contributor

@allroundexperts can you share a screenshot or video of the issue?

My bad. I have updated the screen recording in my original comment.

@ygshbht
Copy link
Contributor Author

ygshbht commented Aug 29, 2023

Does that need to be fixed too? As you can see its the same in the videos i have shared. There's the main chat where you request the money from and there's the all IOU requests chat. I was under the impression that only the IOU requests chat's title needs to be changed as that was mentioned in the issue and not the subtitle. Changing the subtitle will require a slightly different approach. We can certainly discuss further if that is an issue too and needs to be changed
image

@allroundexperts
Copy link
Contributor

@luacmartins Can you confirm if this is something we need to fix as part of this ticket?

@luacmartins
Copy link
Contributor

Yes, we should fix that

@ygshbht
Copy link
Contributor Author

ygshbht commented Aug 30, 2023

@allroundexperts Updated

2023-08-30.18-09-29.mp4

@allroundexperts
Copy link
Contributor

Still not fixed @ygshbht.

Screen.Recording.2023-08-31.at.5.25.29.PM.mov

@allroundexperts
Copy link
Contributor

I'm sure I did. But I'll try again.

@ygshbht
Copy link
Contributor Author

ygshbht commented Aug 31, 2023

No, I don't think it shows being scanned on that screen too. Let me see

@ygshbht
Copy link
Contributor Author

ygshbht commented Aug 31, 2023

@allroundexperts In this case since "Being scaneed" is not going to show because it is not a reportAction, what do you want to show in the LHN in case there is a message? "Being scanned" or the message? Is the situation here same like the other two?
image

@allroundexperts
Copy link
Contributor

If you see the screenshot below, the receipt scan is still in progress. But the LHN shows a Requested 0 message.
Screenshot 2023-08-31 at 6 06 26 PM

@ygshbht
Copy link
Contributor Author

ygshbht commented Aug 31, 2023

@allroundexperts In this case, I think the reportAction is late to update. Please crosscheck with Onyx data

@allroundexperts
Copy link
Contributor

I was offline 😄

@ygshbht
Copy link
Contributor Author

ygshbht commented Aug 31, 2023

@allroundexperts Oh. that makes it unclear why it would change at one place but not at another. Would you still mind checking with the Onyx data in the Application tab or any other way? Because i too have experienced reportAction not changing instantly when i manually update the Onyx data to test

@allroundexperts
Copy link
Contributor

I will and let you know. Does it not happen at your end?

@ygshbht
Copy link
Contributor Author

ygshbht commented Sep 5, 2023

@allroundexperts Updated. I've have kept the original approach of using function argument here #25906 (comment). Let me know if you'd like to change

Comment on lines +1361 to +1385
/**
* Gets all sorted transactions on an IOU report with a receipt and whose pending action is not delete
*
* @param {Object|null} iouReportID
* @returns {[Object]}
*/
function getSortedTransactionsWithReceipts(iouReportID) {
const reportActions = ReportActionsUtils.getAllReportActions(iouReportID);
const sortedReportActions = ReportActionsUtils.getSortedReportActionsForDisplay(reportActions);

return _.reduce(
sortedReportActions,
(transactions, action) => {
if (ReportActionsUtils.isMoneyRequestAction(action)) {
const transaction = TransactionUtils.getLinkedTransaction(action);
if (TransactionUtils.hasReceipt(transaction)) {
transactions.push(transaction);
}
}
return transactions;
},
[],
);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed? Why can't we just use the logic we used in the getReportPreviewMessage function?

Copy link
Contributor Author

@ygshbht ygshbht Sep 5, 2023

Choose a reason for hiding this comment

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

You could say its legacy. Currently its used here but we can remove it and just use the last reportAction like getReportPreviewMessage. In such case the dependency array of optionItem will change whenever new reportAction is added but it does so anyway
image

Copy link
Contributor

Choose a reason for hiding this comment

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

That would be better. We should try to add as less of changes as possible. The reason is that there's a lot of edge cases dependent on this code and doing such a change would just introduce regressions (which I want to avoid).

@ygshbht
Copy link
Contributor Author

ygshbht commented Sep 5, 2023

@allroundexperts Updated

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fullReport.reportID, receiptTransactions, reportActions]);

const memoizedLastTransaction = useDeepCompareMemo(lastTransaction);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we re-memoizing the already memoed transaction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The useDeepCompareMemo does the deepEqal isEqual check. So even if the transaction has not changed but the reference is (you get a new object but with the same data), this will prevent rerendering

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you always get the same object in situations where the transaction has not changed, then we dont have to use useDeepCompareMemo. We may remove it since optionItem memo does deepEqual check in optionItem. The only benefit of using useDeepCompareMemo is that this line won't have to be executed
`const item = SidebarUtils.getOptionData(fullReport, reportActions, personalDetails, preferredLocale, policy);
image

`

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think a re-render is more expensive or a deep comparison of two objects?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think its an overkill to use it

Copy link
Contributor Author

@ygshbht ygshbht Sep 5, 2023

Choose a reason for hiding this comment

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

I can agree. And its not like you cant add these optimizations when there are performance issues

Copy link
Contributor

Choose a reason for hiding this comment

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

If there is a performance issue, I think we can add it after discussion with a wider group. Let's remove that file for now and if needed, we can add it again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, Thanks!

Can you please re-test this and update the screen recordings again since we did quite some refactoring to the original PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

const lastReportAction = _.first(sortedReportActions);
return TransactionUtils.getLinkedTransaction(lastReportAction);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fullReport.reportID, receiptTransactions, reportActions]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is receiptTransactions is needed as a dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So that when the status of transaction updates (from scanning to scanned), the LHN is updated too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you mean to ask this in this context? #25906 (comment)

Copy link
Contributor Author

@ygshbht ygshbht Sep 5, 2023

Choose a reason for hiding this comment

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

I think it depends on the size of the object you are deep comparing and the component that has to be re-rendered. If the deep comparison object is small, like in this case, I think it's a negligible performance issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry yes. Let's take this there!

@luacmartins luacmartins self-requested a review September 5, 2023 16:19
@allroundexperts
Copy link
Contributor

Thanks @ygshbht!

Testing this again now.

ygshbht and others added 4 commits September 5, 2023 22:29
Co-authored-by: Carlos Martins <luacmartins@gmail.com>
Co-authored-by: Carlos Martins <luacmartins@gmail.com>
Copy link
Contributor

@allroundexperts allroundexperts left a comment

Choose a reason for hiding this comment

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

Looks good to me as well!

@melvin-bot melvin-bot bot requested a review from luacmartins September 5, 2023 19:11
@luacmartins luacmartins merged commit 1849ab1 into Expensify:main Sep 5, 2023
@OSBotify
Copy link
Contributor

OSBotify commented Sep 5, 2023

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

OSBotify commented Sep 6, 2023

🚀 Deployed to staging by https://github.com/luacmartins in version: 1.3.65-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented Sep 8, 2023

🚀 Deployed to production by https://github.com/mountiny in version: 1.3.65-7 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented Sep 8, 2023

🚀 Deployed to staging by https://github.com/luacmartins in version: 1.3.66-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/Beamanator in version: 1.3.66-3 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

// In some scenarios, a transaction might be created after reportActions have been modified.
// This can lead to situations where `lastTransaction` doesn't update and retains the previous value.
// However, performance overhead of this is minimized by using memos inside the component.
receiptTransactions: {key: ONYXKEYS.COLLECTION.TRANSACTION},
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that it was fully realized, but this means that every option in the LHN is connected to the entire transaction collection. That means that when any transaction is updated, every single option in the LHN is re-rendered. That seems like it's bad for performance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tgolen Yes, that results in additional renders. However, I don't perceive it as a significant performance issue as transaction updates are infrequent and memoization is implemented within the component. But indeed, there's room for improvement. What specific optimizations do you propose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I initally tried accessing only the transcation attached to last reportAction but that doesn't work as I explain in the comment
image

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I don't really fully understand that comment. Some of the questions I have are:

  • "In some scenarios" what scenarios exactly?
  • Where does lastTransaction come from and why doesn't it update?

It seems like if the root problem for that was fixed, then there wouldn't be a need for this workaround.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

getTransaction(lastReportAction);

OK, so it's getting the transactionID like this transactionID = reportAction.originalMessage?.IOUTransactionID ?? ''; which is fine.

The transcaction seems to be created sometime after the transactionID of reportAction is generated. So you don't have access to transcation when the reportAction gets the transactionID

I don't think that matters. As long as you have the transactionID, you can connect to Onyx with it and you'll get any updates to the object on that key.

I imagine the code should look more like this:

receiptTransaction: {
    key: ({ reportActions }) => {
        const lastReportAction = _.last(reportActions);
        if (!lastReportAction || !lastReportAction.name || lastReportAction.name !== CONST.REPORT.ACTIONS.TYPE.IOU || !lastReportAction.originalMessage || !lastReportAction.originalMessage.IOUTransactionID) {
            return `${ONYXKEYS.COLLECTION.TRANSACTION}0`; // This will always return `null` for these cases
        }

        return `${ONYXKEYS.COLLECTION.TRANSACTION}${lastReportAction.originalMessage.IOUTransactionID}`;
    }
}

Copy link
Contributor Author

@ygshbht ygshbht Oct 13, 2023

Choose a reason for hiding this comment

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

@tgolen What you say makes sense. But I'm not sure how Onyx works in detail. From what i remember this approach didn't work for me. If it does for you, the change can be implemented. If you test, please also check if the LHN is updated when the status of transaction is completed (i.e to scanned or scan failed). If i recall correclty, many times, the lastTranscation that i had was actually the second last one

Copy link
Contributor

Choose a reason for hiding this comment

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

There isn't anything magical about how Onyx works (I know because I wrote a lot of it and there are many many engineers better than me out there).

So, I think it's just running with something like what I've posted and debugging it until it works. Or also, maybe you uncover some bugs, which is great too! We all learn through this. That's better than leaving a workaround like this in the code which could have a big performance impact.

When it's all said and done though, it sounds like we're having a discussion about completely refactoring this component to not have any withOnyx() bindings, but I don't know how far away that is or when it is coming.

Copy link
Contributor Author

@ygshbht ygshbht Oct 13, 2023

Choose a reason for hiding this comment

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

You are right. Honestly, I'm very curious to know what the actual issue is here. My apologies if it appears to be a workaround. I did not see it as such; it was merely the best I could do and provided the explanation for the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants