-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Optimistically generate transactions in existing IOU flows #17718
Conversation
authEndpoint: `${CONFIG.EXPENSIFY.DEFAULT_API_ROOT}api?command=AuthenticatePusher`, | ||
}); | ||
|
||
PusherHelper.setup(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
* @returns {Object} | ||
*/ | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
createIOUReportAction
andcancelMoneyRequests
to account for the fact thatIOUTransactionID
became a required param inReportUtils.buildOptimisticIOUReportAction
- Changed the method signature of
cancelMoneyRequest
to account for2
Cool. We just have some RORY_DEBUG logs 😅 |
@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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
Agree. FWIW, the same code already exists in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Investigating this bug: #23235
I'm not sure if this is the cause, but it may be it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing here: #24175
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
pendingAction
field in Onyx.RequestMoney
api endpoint to just immediately throw a 400 error.errors
field.Split Bill
For the following steps, let's assume we have 3 fresh accounts, A, B, and C.
SplitBill
API 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 Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.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