-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[TS migration] Migrate 'PaymentUtils.js' lib to TypeScript #27923
[TS migration] Migrate 'PaymentUtils.js' lib to TypeScript #27923
Conversation
src/libs/PaymentUtils.ts
Outdated
import {SvgProps} from 'react-native-svg'; | ||
import {FC} from 'react'; | ||
// eslint-disable-next-line import/no-named-default | ||
import {default as BankAccountModel} from './models/BankAccount'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import {default as BankAccountModel} from './models/BankAccount'; | |
import BankAccountModel from './models/BankAccount'; |
src/libs/PaymentUtils.ts
Outdated
|
||
type PaymentMethod = { | ||
description: string; | ||
icon: FC<SvgProps>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
icon: FC<SvgProps>; | |
icon: React.FC<SvgProps>; |
src/libs/PaymentUtils.ts
Outdated
function getPaymentMethodDescription(accountType: AccountType, account: BankAccount['accountData'] & Fund['accountData']): string { | ||
if (account) { | ||
if (accountType === CONST.PAYMENT_METHODS.BANK_ACCOUNT && account?.accountNumber) { | ||
return `${Localize.translateLocal('paymentMethodList.accountLastFour')} ${account?.accountNumber?.slice(-4)}`; | ||
} | ||
if (accountType === CONST.PAYMENT_METHODS.DEBIT_CARD) { | ||
return `${Localize.translateLocal('paymentMethodList.cardLastFour')} ${account?.cardNumber?.slice(-4)}`; | ||
} | ||
} | ||
return ''; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function getPaymentMethodDescription(accountType: AccountType, account: BankAccount['accountData'] & Fund['accountData']): string { | |
if (account) { | |
if (accountType === CONST.PAYMENT_METHODS.BANK_ACCOUNT && account?.accountNumber) { | |
return `${Localize.translateLocal('paymentMethodList.accountLastFour')} ${account?.accountNumber?.slice(-4)}`; | |
} | |
if (accountType === CONST.PAYMENT_METHODS.DEBIT_CARD) { | |
return `${Localize.translateLocal('paymentMethodList.cardLastFour')} ${account?.cardNumber?.slice(-4)}`; | |
} | |
} | |
return ''; | |
} | |
type AccountType = BankAccount['accountType'] | Fund['accountType']; | |
function getPaymentMethodDescription(accountType: AccountType, account: BankAccount['accountData'] | Fund['accountData']): string { | |
if (account) { | |
if (accountType === CONST.PAYMENT_METHODS.BANK_ACCOUNT && 'accountNumber' in account) { | |
return `${Localize.translateLocal('paymentMethodList.accountLastFour')} ${account.accountNumber?.slice(-4)}`; | |
} | |
if (accountType === CONST.PAYMENT_METHODS.DEBIT_CARD && 'cardNumber' in account) { | |
return `${Localize.translateLocal('paymentMethodList.cardLastFour')} ${account.cardNumber?.slice(-4)}`; | |
} | |
} | |
return ''; | |
} |
src/libs/PaymentUtils.ts
Outdated
/** | ||
* Get the PaymentMethods list | ||
*/ | ||
function formatPaymentMethods(bankAccountList: Record<string, BankAccount>, fundList: Record<string, Fund>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function formatPaymentMethods(bankAccountList: Record<string, BankAccount>, fundList: Record<string, Fund>) { | |
function formatPaymentMethods(bankAccountList: Record<string, BankAccount>, fundList: Record<string, Fund>): PaymentMethod[] |
src/libs/PaymentUtils.ts
Outdated
const {icon, iconSize} = getBankIcon(bankAccount?.accountData?.additionalData?.bankName ?? '', false); | ||
combinedPaymentMethods.push({ | ||
...bankAccount, | ||
description: getPaymentMethodDescription(bankAccount?.accountType as AccountType, bankAccount.accountData), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for assertion after changes above.
src/libs/PaymentUtils.ts
Outdated
const {icon, iconSize} = getBankIcon(card?.accountData?.bank ?? '', true); | ||
combinedPaymentMethods.push({ | ||
...card, | ||
description: getPaymentMethodDescription(card?.accountType as AccountType, card.accountData), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for assertion after changes above.
src/libs/PaymentUtils.ts
Outdated
|
||
type AccountType = 'debitCard' | 'bankAccount'; | ||
|
||
type PaymentMethod = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type PaymentMethod = { | |
type PaymentMethod = (BankAccount | Fund) & { | |
description: string; | |
icon: React.FC<SvgProps>; | |
iconSize: number; | |
}; |
import Fund from '../types/onyx/Fund'; | ||
import BankAccount from '../types/onyx/BankAccount'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change these types so that BankAccount['accountType']
is of CONST.PAYMENT_METHODS.BANK_ACCOUNT
and
Fund['accountType']
is of CONST.PAYMENT_METHODS.DEBIT_CARD
@mananjadhav Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
src/components/Icon/BankIcons.ts
Outdated
*/ | ||
|
||
export default function getBankIcon(bankName, isCard) { | ||
const bankIcon = { | ||
export default function getBankIcon(bankName: string, isCard = false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export default function getBankIcon(bankName: string, isCard = false) { | |
export default function getBankIcon(bankName: string, isCard = false): BankIcon { |
@@ -49,7 +51,7 @@ type AccountData = { | |||
|
|||
type BankAccount = { | |||
/** The bank account type */ | |||
accountType?: string; | |||
accountType?: typeof CONST.PAYMENT_METHODS.BANK_ACCOUNT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Skalakid Please check it once you are back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the codebase and i can't find any other string that accountType
can be. Also I tested the app and all bank accounts are type of CONST.PAYMENT_METHODS.BANK_ACCOUNT
. The change was suggested by @blazejkustra here. Błażej do you have any other argument why we shoudn't use string
type in accountType
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's just to be precise. Not much benefits out of it 🤷
}; | ||
|
||
type Fund = { | ||
accountData?: AccountData; | ||
accountType?: string; | ||
accountType?: typeof CONST.PAYMENT_METHODS.DEBIT_CARD; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Skalakid Please check it once you are back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving as per the TS migration guidelines.
We did not find an internal engineer to review this PR, trying to assign a random engineer to #24889 as well as to this PR... Please reach out for help on Slack if no one gets assigned! |
@mananjadhav TS process was changed recently and now C+ are responsible for the reviewer checklist. Please check C+ slack channel for more info. |
Thanks for clarifying @blazejkustra. I realized, and I will be completing this checklist today. |
Reviewer Checklist
Screenshots/VideosWebweb-payment-utils.movMobile Web - Chromemweb-chrome-payment-utils.movMobile Web - Safarimweb-safari-payment-utils.movDesktopdesktop-payment-utils.moviOSios-payment-utils.movAndroidandroid-payment-utils.mov |
@blazejkustra @joelbettner All good from my side. |
@joelbettner looks like this was merged without a test passing. Please add a note explaining why this was done and remove the |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/joelbettner in version: 1.3.78-0 🚀
|
🚀 Deployed to production by https://github.com/Beamanator in version: 1.3.78-4 🚀
|
🚀 Deployed to staging by https://github.com/joelbettner in version: 1.3.79-0 🚀
|
🚀 Deployed to production by https://github.com/jasperhuangg in version: 1.3.79-5 🚀
|
🚀 Deployed to production by https://github.com/jasperhuangg in version: 1.3.79-5 🚀
|
🚀 Deployed to production by https://github.com/jasperhuangg in version: 1.3.79-5 🚀
|
Details
Migrated PaymentUtils.js to TypeScript
Fixed Issues
$ #24889
PROPOSAL: #24889
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Web
web.mov
Mobile Web - Chrome
chrome.mov
Mobile Web - Safari
safari.mov
Desktop
desktop.mov
iOS
ios.mov
Android
android.mov