@@ -12,7 +12,6 @@ import {LockedAccountContext} from '@components/LockedAccountModalProvider';
1212import useLocalize from '@hooks/useLocalize' ;
1313import useNetwork from '@hooks/useNetwork' ;
1414import useOnyx from '@hooks/useOnyx' ;
15- import usePolicy from '@hooks/usePolicy' ;
1615import useThemeStyles from '@hooks/useThemeStyles' ;
1716import { isCurrencySupportedForDirectReimbursement } from '@libs/actions/Policy/Policy' ;
1817import { getCurrentUserAccountID } from '@libs/actions/Report' ;
@@ -89,7 +88,6 @@ function SettlementButton({
8988 const styles = useThemeStyles ( ) ;
9089 const { translate} = useLocalize ( ) ;
9190 const { isOffline} = useNetwork ( ) ;
92-
9391 // The app would crash due to subscribing to the entire report collection if chatReportID is an empty string. So we should have a fallback ID here.
9492 // eslint-disable-next-line rulesdir/no-default-id-values
9593 const [ chatReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReportID || CONST . DEFAULT_NUMBER_ID } ` , { canBeMissing : true } ) ;
@@ -109,18 +107,14 @@ function SettlementButton({
109107 const [ fundList = { } ] = useOnyx ( ONYXKEYS . FUND_LIST , { canBeMissing : true } ) ;
110108 const [ policies ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY , { canBeMissing : true } ) ;
111109 const currentUserAccountID = getCurrentUserAccountID ( ) . toString ( ) ;
112-
113- // Passing `undefined` to ensure we use the Onyx connection from PolicyUtils,
114- // since `useOnyx` only returns snapshot data on the SearchPage.
115- // By passing `undefined`, we fall back to the function's default value.
116- const activeAdminPolicies = getActiveAdminWorkspaces ( undefined , currentUserAccountID ) . sort ( ( a , b ) => ( a . name || '' ) . localeCompare ( b . name || '' ) ) ;
110+ const activeAdminPolicies = getActiveAdminWorkspaces ( policies , currentUserAccountID ) . sort ( ( a , b ) => ( a . name || '' ) . localeCompare ( b . name || '' ) ) ;
117111 const reportID = iouReport ?. reportID ;
118112
119113 const hasPreferredPaymentMethod = ! ! lastPaymentMethod ;
120114 const isLoadingLastPaymentMethod = isLoadingOnyxValue ( lastPaymentMethodResult ) ;
121115 const policy = policies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ] ;
122- const lastPaymentPolicy = usePolicy ( lastPaymentMethod ) ;
123-
116+ const isLastPaymentPolicy = ! Object . values ( { ... CONST . PAYMENT_METHODS , ... CONST . IOU . PAYMENT_TYPE } ) . includes ( lastPaymentMethod as PaymentMethod ) ;
117+ const lastPaymentPolicy = isLastPaymentPolicy ? policies ?. [ ` ${ ONYXKEYS . COLLECTION . POLICY } ${ lastPaymentMethod } ` ] : undefined ;
124118 const [ bankAccountList = { } ] = useOnyx ( ONYXKEYS . BANK_ACCOUNT_LIST , { canBeMissing : true } ) ;
125119 const bankAccount = bankAccountList [ lastBankAccountID ?? CONST . DEFAULT_NUMBER_ID ] ;
126120 const isExpenseReport = isExpenseReportUtil ( iouReport ) ;
0 commit comments