11import React from 'react' ;
22import { Keyboard } from 'react-native' ;
3- import { withOnyx } from 'react-native-onyx' ;
4- import type { OnyxEntry } from 'react-native-onyx' ;
53import CurrencySelectionList from '@components/CurrencySelectionList' ;
64import type { CurrencyListItem } from '@components/CurrencySelectionList/types' ;
75import useLocalize from '@hooks/useLocalize' ;
8- import * as CurrencyUtils from '@libs/CurrencyUtils' ;
6+ import useOnyx from '@hooks/useOnyx' ;
7+ import { isValidCurrencyCode } from '@libs/CurrencyUtils' ;
98import Navigation from '@libs/Navigation/Navigation' ;
10- import * as ReportUtils from '@libs/ReportUtils' ;
9+ import { getTransactionDetails } from '@libs/ReportUtils' ;
1110import { appendParam } from '@libs/Url' ;
12- import * as IOU from '@userActions/IOU' ;
11+ import { setMoneyRequestCurrency } from '@userActions/IOU' ;
1312import CONST from '@src/CONST' ;
1413import ONYXKEYS from '@src/ONYXKEYS' ;
1514import type SCREENS from '@src/SCREENS' ;
16- import type { Transaction } from '@src/types/onyx' ;
1715import StepScreenWrapper from './StepScreenWrapper' ;
1816import withFullTransactionOrNotFound from './withFullTransactionOrNotFound' ;
1917import type { WithFullTransactionOrNotFoundProps } from './withFullTransactionOrNotFound' ;
2018
21- type IOURequestStepCurrencyOnyxProps = {
22- /** The draft transaction object being modified in Onyx */
23- draftTransaction : OnyxEntry < Transaction > ;
24- /** List of recently used currencies */
25- recentlyUsedCurrencies : OnyxEntry < string [ ] > ;
26- } ;
27-
28- type IOURequestStepCurrencyProps = IOURequestStepCurrencyOnyxProps & WithFullTransactionOrNotFoundProps < typeof SCREENS . MONEY_REQUEST . STEP_CURRENCY > ;
19+ type IOURequestStepCurrencyProps = WithFullTransactionOrNotFoundProps < typeof SCREENS . MONEY_REQUEST . STEP_CURRENCY > ;
2920
3021function IOURequestStepCurrency ( {
3122 route : {
3223 params : { backTo, pageIndex, transactionID, action, currency : selectedCurrency = '' } ,
3324 } ,
34- draftTransaction,
35- recentlyUsedCurrencies,
3625} : IOURequestStepCurrencyProps ) {
3726 const { translate} = useLocalize ( ) ;
38- const { currency : originalCurrency = '' } = ReportUtils . getTransactionDetails ( draftTransaction ) ?? { } ;
39- const currency = CurrencyUtils . isValidCurrencyCode ( selectedCurrency ) ? selectedCurrency : originalCurrency ;
27+ const [ draftTransaction ] = useOnyx ( `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ transactionID } ` , { canBeMissing : true } ) ;
28+ const [ recentlyUsedCurrencies ] = useOnyx ( ONYXKEYS . RECENTLY_USED_CURRENCIES , { canBeMissing : true } ) ;
29+ const { currency : originalCurrency = '' } = getTransactionDetails ( draftTransaction ) ?? { } ;
30+ const currency = isValidCurrencyCode ( selectedCurrency ) ? selectedCurrency : originalCurrency ;
4031
4132 const navigateBack = ( selectedCurrencyValue = '' ) => {
4233 // If the currency selection was done from the confirmation step (eg. + > submit expense > manual > confirm > amount > currency)
@@ -57,7 +48,7 @@ function IOURequestStepCurrency({
5748 const confirmCurrencySelection = ( option : CurrencyListItem ) => {
5849 Keyboard . dismiss ( ) ;
5950 if ( pageIndex !== CONST . IOU . PAGE_INDEX . CONFIRM ) {
60- IOU . setMoneyRequestCurrency ( transactionID , option . currencyCode , action === CONST . IOU . ACTION . EDIT ) ;
51+ setMoneyRequestCurrency ( transactionID , option . currencyCode , action === CONST . IOU . ACTION . EDIT ) ;
6152 }
6253
6354 Navigation . setNavigationActionToMicrotaskQueue ( ( ) => navigateBack ( option . currencyCode ) ) ;
@@ -90,19 +81,7 @@ function IOURequestStepCurrency({
9081
9182IOURequestStepCurrency . displayName = 'IOURequestStepCurrency' ;
9283
93- const IOURequestStepCurrencyWithOnyx = withOnyx < IOURequestStepCurrencyProps , IOURequestStepCurrencyOnyxProps > ( {
94- draftTransaction : {
95- key : ( { route} ) => {
96- const transactionID = route ?. params ?. transactionID ?? - 1 ;
97- return `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ transactionID } ` ;
98- } ,
99- } ,
100- recentlyUsedCurrencies : {
101- key : ONYXKEYS . RECENTLY_USED_CURRENCIES ,
102- } ,
103- } ) ( IOURequestStepCurrency ) ;
104-
10584/* eslint-disable rulesdir/no-negated-variables */
106- const IOURequestStepCurrencyWithFullTransactionOrNotFound = withFullTransactionOrNotFound ( IOURequestStepCurrencyWithOnyx ) ;
85+ const IOURequestStepCurrencyWithFullTransactionOrNotFound = withFullTransactionOrNotFound ( IOURequestStepCurrency ) ;
10786
10887export default IOURequestStepCurrencyWithFullTransactionOrNotFound ;
0 commit comments