Skip to content

Commit

Permalink
refactor: use switch case to always show approve button as the defaul…
Browse files Browse the repository at this point in the history
…t case (#1104)

* refactor: use switch case to alway show approve button as the default case

* fix: workaround for incomplete account origin migration
  • Loading branch information
tien authored Oct 4, 2023
1 parent 6a5ce33 commit 796eb2b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,50 @@ export const FooterContent = ({ withFee = false }: { withFee?: boolean }) => {
return (
<>
{withFee && <EstimatedFeesRow />}
{account.origin === AccountType.Talisman && (
<div className="grid w-full grid-cols-2 gap-12">
<Button disabled={processing} onClick={reject}>
{t("Cancel")}
</Button>
<Button disabled={processing} processing={processing} primary onClick={approve}>
{t("Approve")}
</Button>
</div>
)}
{account.origin && [AccountType.Dcent, AccountType.Ledger].includes(account.origin) && (
<Suspense fallback={null}>
<SignHardwareSubstrate
fee={withFee ? fee?.toString() : undefined}
payload={request.payload}
onSigned={approveHardware}
onCancel={reject}
containerId="main"
/>
</Suspense>
)}
{account.origin === AccountType.Qr && (
<Suspense fallback={null}>
<QrSubstrate
payload={request.payload}
account={account as AccountJsonQr}
genesisHash={chain?.genesisHash ?? account?.genesisHash ?? undefined}
onSignature={approveQr}
onReject={reject}
containerId="main"
/>
</Suspense>
)}
{(() => {
switch (account.origin) {
case AccountType.Dcent:
case AccountType.Ledger:
case // @ts-expect-error incomplete migration, remove once migration is completed
"HARDWARE":
return (
<Suspense fallback={null}>
<SignHardwareSubstrate
fee={withFee ? fee?.toString() : undefined}
payload={request.payload}
onSigned={approveHardware}
onCancel={reject}
containerId="main"
/>
</Suspense>
)
case AccountType.Qr:
return (
<Suspense fallback={null}>
<QrSubstrate
payload={request.payload}
account={account as AccountJsonQr}
genesisHash={chain?.genesisHash ?? account?.genesisHash ?? undefined}
onSignature={approveQr}
onReject={reject}
containerId="main"
/>
</Suspense>
)
case AccountType.Talisman:
default:
return (
<div className="grid w-full grid-cols-2 gap-12">
<Button disabled={processing} onClick={reject}>
{t("Cancel")}
</Button>
<Button disabled={processing} processing={processing} primary onClick={approve}>
{t("Approve")}
</Button>
</div>
)
}
})()}
</>
)
}
7 changes: 6 additions & 1 deletion apps/extension/src/ui/domains/Account/AccountTypeIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ export const AccountTypeIcon: FC<AccountTypeIconProps> = ({ 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") }
Expand Down
2 changes: 2 additions & 0 deletions apps/extension/src/ui/domains/Sign/SignHardwareEthereum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
2 changes: 2 additions & 0 deletions apps/extension/src/ui/domains/Sign/SignHardwareSubstrate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down

0 comments on commit 796eb2b

Please sign in to comment.