Skip to content

Commit bc12ce0

Browse files
authored
Merge pull request Expensify#63539 from nkdengineer/fix/62368
fix: paying elsewhere and cancelling payment gets button reset
2 parents 9c6c327 + 4c29e25 commit bc12ce0

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/hooks/usePaymentOptions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ function usePaymentOptions({
7272
if (typeof paymentMethod?.[policyIDKey] === 'string') {
7373
return paymentMethod?.[policyIDKey];
7474
}
75-
return (paymentMethod?.[policyIDKey] as LastPaymentMethodType)?.lastUsed;
75+
if (typeof (paymentMethod?.[policyIDKey] as LastPaymentMethodType)?.lastUsed === 'string') {
76+
return (paymentMethod?.[policyIDKey] as LastPaymentMethodType).lastUsed;
77+
}
78+
return (paymentMethod?.[policyIDKey] as LastPaymentMethodType)?.lastUsed.name;
7679
},
7780
});
7881

src/libs/actions/IOU.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10965,7 +10965,7 @@ function checkIfScanFileCanBeRead(
1096510965

1096610966
/** Save the preferred payment method for a policy */
1096710967
function savePreferredPaymentMethod(policyID: string, paymentMethod: PaymentMethodType, type: ValueOf<typeof CONST.LAST_PAYMENT_METHOD> | undefined) {
10968-
Onyx.merge(`${ONYXKEYS.NVP_LAST_PAYMENT_METHOD}`, {[policyID]: type ? {[type]: paymentMethod, [CONST.LAST_PAYMENT_METHOD.LAST_USED]: paymentMethod} : paymentMethod});
10968+
Onyx.merge(`${ONYXKEYS.NVP_LAST_PAYMENT_METHOD}`, {[policyID]: type ? {[type]: paymentMethod, [CONST.LAST_PAYMENT_METHOD.LAST_USED]: {name: paymentMethod}} : paymentMethod});
1096910969
}
1097010970

1097110971
/** Get report policy id of IOU request */

src/libs/actions/Search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function getLastPolicyPaymentMethod(policyID: string | undefined, lastPaymentMet
7777
if (typeof lastPaymentMethods?.[policyID] === 'string') {
7878
lastPolicyPaymentMethod = lastPaymentMethods?.[policyID] as ValueOf<typeof CONST.IOU.PAYMENT_TYPE>;
7979
} else {
80-
lastPolicyPaymentMethod = (lastPaymentMethods?.[policyID] as LastPaymentMethodType)?.lastUsed as ValueOf<typeof CONST.IOU.PAYMENT_TYPE>;
80+
lastPolicyPaymentMethod = (lastPaymentMethods?.[policyID] as LastPaymentMethodType)?.lastUsed.name as ValueOf<typeof CONST.IOU.PAYMENT_TYPE>;
8181
}
8282

8383
return lastPolicyPaymentMethod;

src/types/onyx/LastPaymentMethod.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@
33
*/
44
type LastPaymentMethodType = {
55
/** The default last payment method */
6-
lastUsed: string;
6+
lastUsed: {
7+
/** The name of the last payment method */
8+
name: string;
9+
};
710
/** The lastPaymentMethod of an IOU */
8-
Iou: string;
11+
Iou: {
12+
/** The name of the last payment method */
13+
name: string;
14+
};
915
/** The lastPaymentMethod of an Expense */
10-
Expense: string;
16+
Expense: {
17+
/** The name of the last payment method */
18+
name: string;
19+
};
1120
/** The lastPaymentMethod of an Invoice */
12-
Invoice: string;
21+
Invoice: {
22+
/** The name of the last payment method */
23+
name: string;
24+
};
1325
};
1426

1527
/** Record of last payment methods, indexed by policy id */

0 commit comments

Comments
 (0)