From 796eb2b52f2923bbe9f17cb4f7aa48e9d5a65e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Thu, 5 Oct 2023 02:09:39 +1300 Subject: [PATCH] refactor: use switch case to always show approve button as the default case (#1104) * refactor: use switch case to alway show approve button as the default case * fix: workaround for incomplete account origin migration --- .../pages/Sign/substrate/FooterContent.tsx | 77 +++++++++++-------- .../ui/domains/Account/AccountTypeIcon.tsx | 7 +- .../ui/domains/Sign/SignHardwareEthereum.tsx | 2 + .../ui/domains/Sign/SignHardwareSubstrate.tsx | 2 + 4 files changed, 54 insertions(+), 34 deletions(-) diff --git a/apps/extension/src/ui/apps/popup/pages/Sign/substrate/FooterContent.tsx b/apps/extension/src/ui/apps/popup/pages/Sign/substrate/FooterContent.tsx index 9ca3304d6f..242ebe9f81 100644 --- a/apps/extension/src/ui/apps/popup/pages/Sign/substrate/FooterContent.tsx +++ b/apps/extension/src/ui/apps/popup/pages/Sign/substrate/FooterContent.tsx @@ -58,39 +58,50 @@ export const FooterContent = ({ withFee = false }: { withFee?: boolean }) => { return ( <> {withFee && } - {account.origin === AccountType.Talisman && ( -
- - -
- )} - {account.origin && [AccountType.Dcent, AccountType.Ledger].includes(account.origin) && ( - - - - )} - {account.origin === AccountType.Qr && ( - - - - )} + {(() => { + switch (account.origin) { + case AccountType.Dcent: + case AccountType.Ledger: + case // @ts-expect-error incomplete migration, remove once migration is completed + "HARDWARE": + return ( + + + + ) + case AccountType.Qr: + return ( + + + + ) + case AccountType.Talisman: + default: + return ( +
+ + +
+ ) + } + })()} ) } diff --git a/apps/extension/src/ui/domains/Account/AccountTypeIcon.tsx b/apps/extension/src/ui/domains/Account/AccountTypeIcon.tsx index e7cc7ff39f..490466021f 100644 --- a/apps/extension/src/ui/domains/Account/AccountTypeIcon.tsx +++ b/apps/extension/src/ui/domains/Account/AccountTypeIcon.tsx @@ -17,7 +17,12 @@ export const AccountTypeIcon: FC = ({ origin, showLinked, const { Icon, tooltip } = useMemo(() => { if (!!showLinked && origin === AccountType.Talisman) return { Icon: LinkIcon, tooltip: t("Local account") } - if (origin === AccountType.Ledger) return { Icon: UsbIcon, tooltip: t("Ledger account") } + if ( + origin === AccountType.Ledger || + // @ts-expect-error incomplete migration, remove once migration is completed + origin === "HARDWARE" + ) + return { Icon: UsbIcon, tooltip: t("Ledger account") } if (origin === AccountType.Qr) return { Icon: PolkadotVaultIcon, tooltip: t("Polkadot Vault account") } if (origin === AccountType.Watched) return { Icon: EyeIcon, tooltip: t("Watched account") } diff --git a/apps/extension/src/ui/domains/Sign/SignHardwareEthereum.tsx b/apps/extension/src/ui/domains/Sign/SignHardwareEthereum.tsx index 5ec9e4ea76..d55c8ec301 100644 --- a/apps/extension/src/ui/domains/Sign/SignHardwareEthereum.tsx +++ b/apps/extension/src/ui/domains/Sign/SignHardwareEthereum.tsx @@ -26,6 +26,8 @@ const getSignHardwareComponent = (account: AccountJsonAny | null) => { case AccountType.Dcent: return SignDcentEthereum case AccountType.Ledger: + case // @ts-expect-error incomplete migration, remove once migration is completed + "HARDWARE": return SignLedgerEthereum default: throw new Error(`Unknown sign hardware component for account origin ${account?.origin}`) diff --git a/apps/extension/src/ui/domains/Sign/SignHardwareSubstrate.tsx b/apps/extension/src/ui/domains/Sign/SignHardwareSubstrate.tsx index 4ebb6262d0..5a7d35ca60 100644 --- a/apps/extension/src/ui/domains/Sign/SignHardwareSubstrate.tsx +++ b/apps/extension/src/ui/domains/Sign/SignHardwareSubstrate.tsx @@ -25,6 +25,8 @@ const getSignHardwareComponent = (account: AccountJsonAny | null) => { case AccountType.Dcent: return SignDcentSubstrate case AccountType.Ledger: + case // @ts-expect-error incomplete migration, remove once migration is completed + "HARDWARE": return SignLedgerSubstrate default: throw new Error(`Unknown sign hardware component for account origin ${account?.origin}`)