Skip to content
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

Fix: Current currency is not highlighted and not marked #18059

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions src/pages/iou/IOUCurrencySelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize
import * as IOU from '../../libs/actions/IOU';
import * as CurrencySymbolUtils from '../../libs/CurrencySymbolUtils';
import {withNetwork} from '../../components/OnyxProvider';
import CONST from '../../CONST';
import themeColors from '../../styles/themes/default';
import * as Expensicons from '../../components/Icon/Expensicons';

const greenCheckmark = {src: Expensicons.Checkmark, color: themeColors.success};

/**
* IOU Currency selection for selecting currency
Expand All @@ -30,11 +35,22 @@ const propTypes = {
ISO4217: PropTypes.string,
})),

/* Onyx Props */

/** Holds data related to IOU view state, rather than the underlying IOU data. */
iou: PropTypes.shape({
/** Selected Currency Code of the current IOU */
selectedCurrencyCode: PropTypes.string,
}),

...withLocalizePropTypes,
};

const defaultProps = {
currencyList: {},
iou: {
selectedCurrencyCode: CONST.CURRENCY.USD,
},
};

class IOUCurrencySelection extends Component {
Expand Down Expand Up @@ -75,11 +91,16 @@ class IOUCurrencySelection extends Component {
* @returns {Object}
*/
getCurrencyOptions() {
return _.map(this.props.currencyList, (currencyInfo, currencyCode) => ({
text: `${currencyCode} - ${CurrencySymbolUtils.getLocalizedCurrencySymbol(this.props.preferredLocale, currencyCode)}`,
currencyCode,
keyForList: currencyCode,
}));
return _.map(this.props.currencyList, (currencyInfo, currencyCode) => {
const isSelectedCurrency = currencyCode === this.props.iou.selectedCurrencyCode;
return {
text: `${currencyCode} - ${CurrencySymbolUtils.getLocalizedCurrencySymbol(this.props.preferredLocale, currencyCode)}`,
currencyCode,
keyForList: currencyCode,
customIcon: isSelectedCurrency ? greenCheckmark : undefined,
boldStyle: isSelectedCurrency,
};
});
}

/**
Expand Down Expand Up @@ -127,6 +148,7 @@ class IOUCurrencySelection extends Component {
placeholderText={this.props.translate('common.search')}
headerMessage={headerMessage}
safeAreaPaddingBottomStyle={safeAreaPaddingBottomStyle}
initiallyFocusedOptionKey={_.get(_.find(this.state.currencyData, currency => currency.currencyCode === this.props.iou.selectedCurrencyCode), 'keyForList')}
/>
</>
)}
Expand All @@ -142,6 +164,9 @@ export default compose(
withLocalize,
withOnyx({
currencyList: {key: ONYXKEYS.CURRENCY_LIST},
iou: {
key: ONYXKEYS.IOU,
},
}),
withNetwork(),
)(IOUCurrencySelection);