Optimistically generate transactions in existing IOU flows#17718
Optimistically generate transactions in existing IOU flows#17718luacmartins merged 92 commits intomainfrom
Conversation
| authEndpoint: `${CONFIG.EXPENSIFY.DEFAULT_API_ROOT}api?command=AuthenticatePusher`, | ||
| }); | ||
|
|
||
| PusherHelper.setup(); |
There was a problem hiding this comment.
Didn't end up needing this PusherHelper change, but I do think it's a potentially useful abstraction, so I left it here. I can remove it if you prefer
src/libs/ReportUtils.js
Outdated
| */ | ||
| function buildOptimisticIOUReportAction(type, amount, currency, comment, participants, paymentType = '', iouTransactionID = '', iouReportID = '', isSettlingUp = false) { | ||
| const IOUTransactionID = iouTransactionID || NumberUtils.rand64(); | ||
| function buildOptimisticIOUReportAction(type, amount, currency, comment, participants, iouTransactionID, paymentType = '', iouReportID = '', isSettlingUp = false) { |
There was a problem hiding this comment.
Review note: iouTransactionID became a required param because it needs to be associated with an actual transaction in Onyx and not an ID generated on the fly here.
There was a problem hiding this comment.
This diff looks worse than it is. Tests were failing, and all I did was:
- Wrap all tests in a single
describe, which is the most common pattern we have for tests, and makes it easier to run or debug all the tests in a file in VSCode or JetBrains IDEs. (this is why the diff looks crazy) - Changed the method signature of
createIOUReportActionandcancelMoneyRequeststo account for the fact thatIOUTransactionIDbecame a required param inReportUtils.buildOptimisticIOUReportAction - Changed the method signature of
cancelMoneyRequestto account for2
|
@roryabraham the github actions job2 is still failing, have you been able to look into that? |
10a072d to
74bef77
Compare
|
@mountiny @s77rt I reverted the last two commits (force-pushed so they're just gone), but yeah they were causing tests to fail and were just for an unbenchmarked performance optimization suggested here. I was kind of unsure about the change anyways since it didn't really follow our patterns. I think this is fine |
|
I still think |
Agree. FWIW, the same code already exists in |
Co-authored-by: Carlos Martins <cmartins@expensify.com>
Co-authored-by: Carlos Martins <cmartins@expensify.com>
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/luacmartins in version: 1.3.11-0 🚀
|
|
🚀 Deployed to production by https://github.com/roryabraham in version: 1.3.12-0 🚀
|
| failureData.push({ | ||
| onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
| key: optimisticChatReportData.key, | ||
| value: { | ||
| errorFields: { | ||
| createChat: { | ||
| [DateUtils.getMicroseconds()]: Localize.translateLocal('report.genericCreateReportFailureMessage'), | ||
| }, | ||
| }, | ||
| }, | ||
| }); |
There was a problem hiding this comment.
This caused a regression #18839. We already set an error for the report action (in line 883) and we are setting another error for the report itself. This resulted in redundant error messages.
| * Takes an amount as a floating point number and converts it to an integer amount. | ||
| * For example, given [25, USD], return 2500. | ||
| * Given [25.50, USD] return 2550. | ||
| * Given [2500, JPY], return 2500. | ||
| * | ||
| * @note we do not currently support any currencies with more than two decimal places. Sorry Tunisia :( | ||
| * | ||
| * @param {String} currency | ||
| * @param {Number} amountAsFloat | ||
| * @returns {Number} | ||
| */ | ||
| function convertToSmallestUnit(currency, amountAsFloat) { | ||
| const currencyUnit = getCurrencyUnit(currency); | ||
| return Math.trunc(amountAsFloat * currencyUnit); | ||
| } |
There was a problem hiding this comment.
Is this supposed to be used for the amount of a transaction we send to the backend? If that's the case, this is wrong. If in the front end we input 25 JPY, the backend expects 2500. The backend ALWAYS works in "cents", even with currencies that don't have cents.
There was a problem hiding this comment.
Investigating this bug: #23235
I'm not sure if this is the cause, but it may be it.



Details
Optimistically generate transactions for IOU flows and maintain their state under the new transaction Onyx collection.
Fixed Issues
$ https://github.com/Expensify/Expensify/issues/277227
Tests
Request Money
pendingActionfield in Onyx.RequestMoneyapi endpoint to just immediately throw a 400 error.errorsfield.Split Bill
For the following steps, let's assume we have 3 fresh accounts, A, B, and C.
SplitBillAPI endpoint to throw an error.Offline tests
Included above.
QA Steps
Maybe controversial, but everything we've changed here should be covered by regression tests already, and we aren't expecting any new or changed behaviors from a user perspective here. So this is No QA, just regressions only.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Web
web.mov
Mobile Web - Chrome
AndroidmWeb.mov
Mobile Web - Safari
iOSWeb.mov
Desktop
DesktopOffline.mov
DesktopComesBackOnline.mov
iOS
iOS.mov
Android
Android.mov