Skip to content

Commit 230b7f7

Browse files
authored
Merge pull request #17718 from Expensify/Rory-OptimisticTransactions
Optimistically generate transactions in existing IOU flows
2 parents bdb2369 + dbf456d commit 230b7f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2108
-648
lines changed

jest/setup.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ reanimatedJestUtils.setUpTests();
99
// https://reactnavigation.org/docs/testing/#mocking-native-modules
1010
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
1111

12-
// We have to mock the SQLiteStorage provider because it uses the native module SQLiteStorage, which is not available in jest.
13-
// Mocking this file in __mocks__ does not work because jest doesn't support mocking files that are not directly used in the testing project
14-
jest.mock('react-native-onyx/lib/storage/providers/SQLiteStorage', () => require('react-native-onyx/lib/storage/__mocks__'));
12+
// Mock react-native-onyx storage layer because the SQLite storage layer doesn't work in jest.
13+
// Mocking this file in __mocks__ does not work because jest doesn't support mocking files that are not directly used in the testing project,
14+
// and we only want to mock the storage layer, not the whole Onyx module.
15+
jest.mock('react-native-onyx/lib/storage', () => require('react-native-onyx/lib/storage/__mocks__'));
1516

1617
// Turn off the console logs for timing events. They are not relevant for unit tests and create a lot of noise
1718
jest.spyOn(console, 'debug').mockImplementation((...params) => {

package-lock.json

+106-62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@
4444
},
4545
"dependencies": {
4646
"@expensify/react-native-web": "0.18.15",
47-
"@formatjs/intl-getcanonicallocales": "^1.5.8",
48-
"@formatjs/intl-locale": "^2.4.21",
49-
"@formatjs/intl-numberformat": "^6.2.5",
50-
"@formatjs/intl-pluralrules": "^4.0.13",
47+
"@formatjs/intl-getcanonicallocales": "^2.2.0",
48+
"@formatjs/intl-listformat": "^7.2.2",
49+
"@formatjs/intl-locale": "^3.3.0",
50+
"@formatjs/intl-numberformat": "^8.5.0",
51+
"@formatjs/intl-pluralrules": "^5.2.2",
5152
"@gorhom/portal": "^1.0.14",
5253
"@oguzhnatly/react-native-image-manipulator": "github:Expensify/react-native-image-manipulator#c5f654fc9d0ad7cc5b89d50b34ecf8b0e3f4d050",
5354
"@onfido/react-native-sdk": "7.4.0",
@@ -109,7 +110,7 @@
109110
"react-native-key-command": "^1.0.0",
110111
"react-native-localize": "^2.2.6",
111112
"react-native-modal": "^13.0.0",
112-
"react-native-onyx": "^1.0.41",
113+
"react-native-onyx": "1.0.41",
113114
"react-native-pdf": "^6.6.2",
114115
"react-native-performance": "^4.0.0",
115116
"react-native-permissions": "^3.0.1",

src/CONST.js

+1
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ const CONST = {
391391
DROP_NATIVE_ID: 'report-dropzone',
392392
ACTIVE_DROP_NATIVE_ID: 'report-dropzone',
393393
MAXIMUM_PARTICIPANTS: 8,
394+
SPLIT_REPORTID: '-2',
394395
ACTIONS: {
395396
LIMIT: 50,
396397
TYPE: {

src/components/CurrentWalletBalance.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import withLocalize, {withLocalizePropTypes} from './withLocalize';
66
import compose from '../libs/compose';
77
import ONYXKEYS from '../ONYXKEYS';
88
import Text from './Text';
9+
import * as CurrencyUtils from '../libs/CurrencyUtils';
910

1011
const propTypes = {
1112
/** The user's wallet account */
@@ -31,10 +32,7 @@ const defaultProps = {
3132
};
3233

3334
const CurrentWalletBalance = (props) => {
34-
const formattedBalance = props.numberFormat(
35-
props.userWallet.currentBalance / 100, // Divide by 100 because balance is in cents
36-
{style: 'currency', currency: 'USD'},
37-
);
35+
const formattedBalance = CurrencyUtils.convertToDisplayString(props.userWallet.currentBalance);
3836
return (
3937
<Text
4038
style={[styles.pv5, styles.alignSelfCenter, styles.textHeadline, styles.textXXXLarge, ...props.balanceStyles]}

src/components/MoneyRequestConfirmationList.js

+11-23
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as IOUUtils from '../libs/IOUUtils';
1919
import MenuItemWithTopDescription from './MenuItemWithTopDescription';
2020
import Navigation from '../libs/Navigation/Navigation';
2121
import optionPropTypes from './optionPropTypes';
22+
import * as CurrencyUtils from '../libs/CurrencyUtils';
2223

2324
const propTypes = {
2425
/** Callback to inform parent modal of success */
@@ -31,7 +32,7 @@ const propTypes = {
3132
hasMultipleParticipants: PropTypes.bool.isRequired,
3233

3334
/** IOU amount */
34-
iouAmount: PropTypes.string.isRequired,
35+
iouAmount: PropTypes.number.isRequired,
3536

3637
/** IOU type */
3738
iouType: PropTypes.string,
@@ -104,12 +105,10 @@ class MoneyRequestConfirmationList extends Component {
104105
*/
105106
getSplitOrRequestOptions() {
106107
return [{
107-
text: this.props.translate(this.props.hasMultipleParticipants ? 'iou.split' : 'iou.request', {
108-
amount: this.props.numberFormat(
109-
this.props.iouAmount,
110-
{style: 'currency', currency: this.props.iou.selectedCurrencyCode},
111-
),
112-
}),
108+
text: this.props.translate(
109+
this.props.hasMultipleParticipants ? 'iou.split' : 'iou.request',
110+
{amount: CurrencyUtils.convertToDisplayString(this.props.iouAmount, this.props.iou.selectedCurrencyCode)},
111+
),
113112
value: this.props.hasMultipleParticipants ? CONST.IOU.MONEY_REQUEST_TYPE.SPLIT : CONST.IOU.MONEY_REQUEST_TYPE.REQUEST,
114113
}];
115114
}
@@ -136,14 +135,10 @@ class MoneyRequestConfirmationList extends Component {
136135
* @returns {Array}
137136
*/
138137
getParticipantsWithAmount(participants) {
139-
const iouAmount = IOUUtils.calculateAmount(participants, this.props.iouAmount, this.props.iou.selectedCurrencyCode);
140-
138+
const iouAmount = IOUUtils.calculateAmount(participants, this.props.iouAmount);
141139
return OptionsListUtils.getIOUConfirmationOptionsFromParticipants(
142140
participants,
143-
this.props.numberFormat(iouAmount / 100, {
144-
style: 'currency',
145-
currency: this.props.iou.selectedCurrencyCode,
146-
}),
141+
CurrencyUtils.convertToDisplayString(iouAmount, this.props.iou.selectedCurrencyCode),
147142
);
148143
}
149144

@@ -172,13 +167,10 @@ class MoneyRequestConfirmationList extends Component {
172167
const formattedUnselectedParticipants = this.getParticipantsWithoutAmount(unselectedParticipants);
173168
const formattedParticipants = _.union(formattedSelectedParticipants, formattedUnselectedParticipants);
174169

175-
const myIOUAmount = IOUUtils.calculateAmount(selectedParticipants, this.props.iouAmount, this.props.iou.selectedCurrencyCode, true);
170+
const myIOUAmount = IOUUtils.calculateAmount(selectedParticipants, this.props.iouAmount, true);
176171
const formattedMyPersonalDetails = OptionsListUtils.getIOUConfirmationOptionsFromMyPersonalDetail(
177172
this.props.currentUserPersonalDetails,
178-
this.props.numberFormat(myIOUAmount / 100, {
179-
style: 'currency',
180-
currency: this.props.iou.selectedCurrencyCode,
181-
}),
173+
CurrencyUtils.convertToDisplayString(myIOUAmount, this.props.iou.selectedCurrencyCode),
182174
);
183175

184176
sections.push({
@@ -270,18 +262,14 @@ class MoneyRequestConfirmationList extends Component {
270262
const shouldDisableButton = selectedParticipants.length === 0;
271263
const recipient = this.state.participants[0];
272264
const canModifyParticipants = this.props.canModifyParticipants && this.props.hasMultipleParticipants;
273-
const formattedAmount = this.props.numberFormat(this.props.iouAmount, {
274-
style: 'currency',
275-
currency: this.props.iou.selectedCurrencyCode,
276-
});
265+
const formattedAmount = CurrencyUtils.convertToDisplayString(this.props.iouAmount, this.props.iou.selectedCurrencyCode);
277266

278267
return (
279268
<OptionsSelector
280269
sections={this.getSections()}
281270
value=""
282271
onSelectRow={canModifyParticipants ? this.toggleOption : undefined}
283272
onConfirmSelection={this.confirm}
284-
onChangeText={this.props.onUpdateComment}
285273
selectedOptions={this.getSelectedOptions()}
286274
canSelectMultipleOptions={canModifyParticipants}
287275
disableArrowKeysActions={!canModifyParticipants}

0 commit comments

Comments
 (0)