Skip to content

Commit

Permalink
add selectedCurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
luacmartins committed Jul 16, 2021
1 parent 8d8745b commit 8f10ad7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 23 deletions.
10 changes: 3 additions & 7 deletions src/libs/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,9 @@ function processNetworkRequestQueue() {
}

// If we have a request then we need to check if it can be persisted in case we close the tab while offline
const retryableRequests = [];
_.each(networkRequestQueue, (request) => {
if ((request.data.doNotRetry || request.data.forceNetworkRequest) && !request.data.persist) {
return request.resolve();
}
retryableRequests.push(request);
});
const retryableRequests = _.filter(networkRequestQueue, request => (
!request.data.doNotRetry && request.data.persist
));
Onyx.set(ONYXKEYS.NETWORK_REQUEST_QUEUE, retryableRequests);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/PersonalDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function fetchCurrencyPreferences() {
isRetrievingCurrency: true,
});

API.GetPreferredCurrency({...coords, doNotRetry: true})
API.GetPreferredCurrency({...coords})
.then((data) => {
currency = data.currency;
})
Expand Down
17 changes: 14 additions & 3 deletions src/pages/iou/IOUCurrencySelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ const propTypes = {

// Currency Symbol of the Preferred Currency
preferredCurrencySymbol: PropTypes.string,

// Preferred Currency Code of the current user
selectedCurrencyCode: PropTypes.string,

// Currency Symbol of the Preferred Currency
selectedCurrencySymbol: PropTypes.string,
}),

// The currency list constant object from Onyx
Expand All @@ -51,7 +57,12 @@ const propTypes = {
};

const defaultProps = {
myPersonalDetails: {preferredCurrencyCode: CONST.CURRENCY.USD, preferredCurrencySymbol: '$'},
myPersonalDetails: {
preferredCurrencyCode: CONST.CURRENCY.USD,
preferredCurrencySymbol: '$',
selectedCurrencyCode: CONST.CURRENCY.USD,
selectedCurrencySymbol: '$',
},
currencyList: {},
};

Expand Down Expand Up @@ -151,8 +162,8 @@ class IOUCurrencySelection extends Component {
*/
confirmCurrencySelection() {
Onyx.merge(ONYXKEYS.MY_PERSONAL_DETAILS, {
preferredCurrencyCode: this.state.selectedCurrency.currencyCode,
preferredCurrencySymbol: this.state.selectedCurrency.currencySymbol,
selectedCurrencyCode: this.state.selectedCurrency.currencyCode,
selectedCurrencySymbol: this.state.selectedCurrency.currencySymbol,
});
Navigation.goBack();
}
Expand Down
33 changes: 21 additions & 12 deletions src/pages/iou/IOUModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import React, {Component} from 'react';
import {View, TouchableOpacity} from 'react-native';
import PropTypes from 'prop-types';
import lodashGet from 'lodash/get';
import {withOnyx} from 'react-native-onyx';
import Onyx, {withOnyx} from 'react-native-onyx';
import IOUAmountPage from './steps/IOUAmountPage';
import IOUParticipantsPage from './steps/IOUParticipantsPage';
import IOUConfirmPage from './steps/IOUConfirmPage';
import Header from '../../components/Header';
import styles from '../../styles/styles';
import Icon from '../../components/Icon';
import * as PersonalDetails from '../../libs/actions/PersonalDetails';
import {createIOUSplit, createIOUTransaction} from '../../libs/actions/IOU';
import {Close, BackArrow} from '../../components/Icon/Expensicons';
import Navigation from '../../libs/Navigation/Navigation';
Expand Down Expand Up @@ -46,6 +45,12 @@ const propTypes = {

// Currency Symbol of the Preferred Currency
preferredCurrencySymbol: PropTypes.string,

// Selected Currency Code of the current IOU
selectedCurrencyCode: PropTypes.string,

// Currency Symbol of the Selected Currency
selectedCurrencySymbol: PropTypes.string,
}),

// Holds data related to IOU view state, rather than the underlying IOU data.
Expand Down Expand Up @@ -83,6 +88,8 @@ const defaultProps = {
myPersonalDetails: {
preferredCurrencyCode: CONST.CURRENCY.USD,
preferredCurrencySymbol: '$',
selectedCurrencyCode: CONST.CURRENCY.USD,
selectedCurrencySymbol: '$',
},
iouType: '',
};
Expand All @@ -103,7 +110,6 @@ class IOUModal extends Component {
this.addParticipants = this.addParticipants.bind(this);
this.createTransaction = this.createTransaction.bind(this);
this.updateComment = this.updateComment.bind(this);
this.getReady = this.getReady.bind(this);
const participants = lodashGet(props, 'report.participants', []);
const participantsWithDetails = getPersonalDetailsForLogins(participants, props.personalDetails)
.map(personalDetails => ({
Expand Down Expand Up @@ -142,17 +148,20 @@ class IOUModal extends Component {
Navigation.dismissModal();
}

if (prevProps.myPersonalDetails.preferredCurrencyCode
!== this.props.myPersonalDetails.preferredCurrencyCode) {
if (prevProps.myPersonalDetails.selectedCurrencyCode
!== this.props.myPersonalDetails.selectedCurrencyCode) {
this.updateSelectedCurrency({
currencyCode: this.props.myPersonalDetails.preferredCurrencyCode,
currencySymbol: this.props.myPersonalDetails.preferredCurrencySymbol,
currencyCode: this.props.myPersonalDetails.selectedCurrencyCode,
currencySymbol: this.props.myPersonalDetails.selectedCurrencySymbol,
});
}
}

getReady() {
PersonalDetails.fetchCurrencyPreferences();
componentWillUnmount() {
Onyx.merge(ONYXKEYS.MY_PERSONAL_DETAILS, {
selectedCurrencyCode: this.props.myPersonalDetails.preferredCurrencyCode,
selectedCurrencySymbol: this.props.myPersonalDetails.preferredCurrencySymbol,
});
}

/**
Expand Down Expand Up @@ -280,7 +289,7 @@ class IOUModal extends Component {
const currentStep = this.steps[this.state.currentStepIndex];
const reportID = lodashGet(this.props, 'route.params.reportID', '');
return (
<ScreenWrapper onTransitionEnd={this.getReady}>
<ScreenWrapper>
{({didScreenTransitionEnd}) => (
<KeyboardAvoidingView>
<View style={[styles.headerBar]}>
Expand Down Expand Up @@ -317,9 +326,9 @@ class IOUModal extends Component {
</View>
<View style={[styles.pRelative, styles.flex1]}>
<FullScreenLoadingIndicator
visible={!didScreenTransitionEnd || this.props.iou.isRetrievingCurrency}
visible={!didScreenTransitionEnd}
/>
{didScreenTransitionEnd && !this.props.iou.isRetrievingCurrency && (
{didScreenTransitionEnd && (
<>
{currentStep === Steps.IOUAmount && (
<IOUAmountPage
Expand Down

0 comments on commit 8f10ad7

Please sign in to comment.