Skip to content

Commit

Permalink
Merge pull request #30156 from dukenv0307/fix/29769
Browse files Browse the repository at this point in the history
Update optimistic data for unit currency
  • Loading branch information
srikarparsi committed Oct 25, 2023
2 parents 11b629e + 5fffb48 commit c81a509
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ function clearAvatarErrors(policyID) {
* @param {String} currency
*/
function updateGeneralSettings(policyID, name, currency) {
const policy = allPolicies[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`];
const distanceUnit = _.find(_.values(policy.customUnits), (unit) => unit.name === CONST.CUSTOM_UNITS.NAME_DISTANCE);
const distanceRate = _.find(_.values(distanceUnit ? distanceUnit.rates : {}), (rate) => rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE);
const optimisticData = [
{
// We use SET because it's faster than merge and avoids a race condition when setting the currency and navigating the user to the Bank account page in confirmCurrencyChangeAndHideModal
Expand All @@ -601,6 +604,21 @@ function updateGeneralSettings(policyID, name, currency) {
},
name,
outputCurrency: currency,
...(distanceUnit
? {
customUnits: {
[distanceUnit.customUnitID]: {
...distanceUnit,
rates: {
[distanceRate.customUnitRateID]: {
...distanceRate,
currency,
},
},
},
},
}
: {}),
},
},
];
Expand All @@ -626,6 +644,13 @@ function updateGeneralSettings(policyID, name, currency) {
errorFields: {
generalSettings: ErrorUtils.getMicroSecondOnyxError('workspace.editor.genericFailureMessage'),
},
...(distanceUnit
? {
customUnits: {
[distanceUnit.customUnitID]: distanceUnit,
},
}
: {}),
},
},
];
Expand Down

0 comments on commit c81a509

Please sign in to comment.