Skip to content

Commit

Permalink
Add browsers const
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Jul 29, 2024
1 parent b122efa commit 53f89d0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
14 changes: 6 additions & 8 deletions components/views/GetWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import WalletTypeCard from '../WalletTypeCard'
import ChromeIcon from '../Icons/chrome.svg'
import { Wallet } from '../../data/wallets'
import { getBrowserFromUserAgent, getUserAgent } from '../../helpers/platform'
import { getBrowserInfo } from '../../helpers/browsers'

interface GetWalletProps {
onBack: () => void
Expand All @@ -18,12 +19,9 @@ export default function GetWallet({
wallet,
onGetQRCode,
}: GetWalletProps) {
const browser = getBrowserFromUserAgent(getUserAgent())
const browserInfo = getBrowserInfo(getUserAgent())
const browserInstallLink =
wallet.installLink?.[browser] || wallet.installLink?.browser
const browserName = wallet.installLink?.[browser]
? browser.charAt(0).toUpperCase() + browser.slice(1)
: 'Browser'
wallet.installLink?.[browserInfo.id] || wallet.installLink?.browser

return (
<ViewLayout
Expand All @@ -36,13 +34,13 @@ export default function GetWallet({
<Stack flexGrow={1} alignItems="center" spacing={4} px={6} pb={6}>
{wallet.installLink?.browser && (
<WalletTypeCard
icon={ChromeIcon}
title={`${wallet.name} for ${browserName}}`}
icon={browserInfo.icon}
title={`${wallet.name} for ${browserInfo.name}}`}
description={
'Access your wallet directly from your preferred web browser.'
}
button={{
text: `Add to ${browserName}`,
text: `Add to ${browserInfo.name}`,
href: browserInstallLink,
}}
></WalletTypeCard>
Expand Down
12 changes: 6 additions & 6 deletions helpers/browsers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export enum BrowserType {
CHROME = 'chrome',
}
import { BROWSERS } from './constants'

export function getBrowserType(userAgent: string): BrowserType | null {
export function getBrowserInfo(
userAgent: string
): typeof BROWSERS[keyof typeof BROWSERS] {
if (userAgent.includes('Chrome')) {
return BrowserType.CHROME
return BROWSERS.CHROME
}

return null
return BROWSERS.BROWSER
}
14 changes: 14 additions & 0 deletions helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Enum from 'enum-xyz'
import ChromeIcon from '../assets/images/chrome-icon.svg'

const { AUTHN, CANARYNET, TESTNET, PREVIEWNET, MAINNET, LOCAL, EMULATOR } =
Enum.String({ casing: 'lowercase' })
Expand Down Expand Up @@ -91,3 +92,16 @@ export const AVAILABLE_FEATURES = [
description: 'This wallet supports the Ethereum Virtual Machine.',
},
] as const

export const BROWSERS = {
CHROME: {
id: 'chrome',
name: 'Chrome',
icon: ChromeIcon,
},
BROWSER: {
id: 'browser',
name: 'Browser',
icon: ChromeIcon,
},
} as const

0 comments on commit 53f89d0

Please sign in to comment.