11import Onyx from 'react-native-onyx' ;
2- import type { OnyxCollection } from 'react-native-onyx' ;
2+ import type { OnyxEntry } from 'react-native-onyx' ;
33import * as API from '@libs/API' ;
44import { WRITE_COMMANDS } from '@libs/API/types' ;
55import CONST from '@src/CONST' ;
66import ONYXKEYS from '@src/ONYXKEYS' ;
7- import type * as OnyxTypes from '@src/types/onyx' ;
7+ import type { Policy } from '@src/types/onyx' ;
88
9- let allPolicies : OnyxCollection < OnyxTypes . Policy > ;
10- Onyx . connect ( {
11- key : ONYXKEYS . COLLECTION . POLICY ,
12- waitForCollectionCallback : true ,
13- callback : ( value ) => ( allPolicies = value ) ,
14- } ) ;
15-
16- function resetNonUSDBankAccount ( policyID : string | undefined ) {
17- if ( ! policyID ) {
18- throw new Error ( 'Missing Policy ID when attempting to reset' ) ;
9+ function resetNonUSDBankAccount ( policy : OnyxEntry < Policy > ) {
10+ if ( ! policy ) {
11+ throw new Error ( 'Missing policy when attempting to reset' ) ;
1912 }
2013
21- const policy = allPolicies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ] ?? ( { } as OnyxTypes . Policy ) ;
22-
2314 API . write (
2415 WRITE_COMMANDS . RESET_BANK_ACCOUNT_SETUP ,
25- { policyID} ,
16+ { policyID : policy . id } ,
2617 {
2718 optimisticData : [
2819 {
@@ -37,7 +28,7 @@ function resetNonUSDBankAccount(policyID: string | undefined) {
3728 } ,
3829 {
3930 onyxMethod : Onyx . METHOD . MERGE ,
40- key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
31+ key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policy . id } ` ,
4132 value : {
4233 achAccount : null ,
4334 } ,
@@ -63,7 +54,7 @@ function resetNonUSDBankAccount(policyID: string | undefined) {
6354 } ,
6455 {
6556 onyxMethod : Onyx . METHOD . MERGE ,
66- key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
57+ key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policy . id } ` ,
6758 value : {
6859 achAccount : policy ?. achAccount ,
6960 } ,
0 commit comments