Skip to content

Commit

Permalink
Links for wallets (#2265)
Browse files Browse the repository at this point in the history
* Add links for wallets

* Change logic around support banner

Show non-supported banner regardless if user wallet is connected or not

* Fix TS errors
  • Loading branch information
kattylucy authored Jul 10, 2024
1 parent abd0ac2 commit 8d8f2e7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
8 changes: 4 additions & 4 deletions centrifuge-app/src/components/SupportedBrowserBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useWallet } from '@centrifuge/centrifuge-react'
import { Banner, Text } from '@centrifuge/fabric'
import * as React from 'react'
import { getSupportedBrowser } from '../utils/getSupportedBrowser'

export const SupportedBrowserBanner = () => {
const wallet = useWallet()
const storageKey = 'browser-banner-seen'
const isSupported = navigator.userAgent.indexOf('Chrome') > -1
const browser = getSupportedBrowser()
const isSupported = browser !== 'unknown'
const [isOpen, setIsOpen] = React.useState(false)

React.useEffect(() => {
Expand All @@ -17,7 +17,7 @@ export const SupportedBrowserBanner = () => {
setIsOpen(false)
}

if (isSupported || !wallet.connectedNetwork) {
if (isSupported) {
return null
}

Expand Down
11 changes: 11 additions & 0 deletions centrifuge-app/src/utils/getSupportedBrowser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Function to detect the browser
export const getSupportedBrowser = () => {
const userAgent = navigator.userAgent
if (userAgent.includes('Chrome') && !userAgent.includes('Edg')) {
return 'chrome'
} else if (userAgent.includes('Firefox')) {
return 'firefox'
} else {
return 'unknown'
}
}
33 changes: 29 additions & 4 deletions centrifuge-react/src/components/WalletProvider/WalletDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getSupportedBrowser } from '@centrifuge/centrifuge-app/src/utils/getSupportedBrowser'
import {
Button,
Card,
Expand Down Expand Up @@ -34,12 +35,36 @@ type Props = {
showFinoa?: boolean
}

type WalletFn = {
installUrl: string
extensionName?: string
}

const title = {
networks: 'Connect wallet',
wallets: 'Connect wallet',
accounts: 'Choose account',
}

const walletsList: { [key: string]: string } = {
talisman: 'talisman-wallet-extension',
'subwallet-js': 'subwallet',
'polkadot-js': 'polkadot-js-extension',
'fearless-wallet': 'fearless-wallet',
metamask: 'ether-metamask',
}

const getAdjustedInstallUrl = (wallet: WalletFn): string => {
const browser = getSupportedBrowser()
const { installUrl } = wallet
if (browser === 'firefox') {
const extensionName = wallet.extensionName ?? 'metamask'
return `https://addons.mozilla.org/en-US/firefox/addon/${walletsList[extensionName]}/`
} else {
return installUrl
}
}

export function WalletDialog({ evmChains: allEvmChains, showAdvancedAccounts, showTestNets, showFinoa }: Props) {
const evmChains = Object.keys(allEvmChains)
.filter((chainId) => (!showTestNets ? !(allEvmChains as any)[chainId].isTestnet : true))
Expand Down Expand Up @@ -198,8 +223,8 @@ export function WalletDialog({ evmChains: allEvmChains, showAdvancedAccounts, sh
}
>
<Grid minColumnWidth={120} mt={3} gap={1}>
{shownWallets.map((wallet) =>
wallet.installed ? (
{shownWallets.map((wallet) => {
return wallet.installed ? (
<SelectButton
key={wallet.title}
logo={<Logo icon={wallet.logo.src} />}
Expand All @@ -221,15 +246,15 @@ export function WalletDialog({ evmChains: allEvmChains, showAdvancedAccounts, sh
) : (
<SelectAnchor
key={wallet.title}
href={wallet.installUrl}
href={getAdjustedInstallUrl(wallet)}
logo={<Logo icon={wallet.logo.src} />}
iconRight={<IconDownload size="iconSmall" color="textPrimary" />}
muted={isMuted(selectedNetwork!)}
>
{wallet.title}
</SelectAnchor>
)
)}
})}
</Grid>
</SelectionStep>
</>
Expand Down

0 comments on commit 8d8f2e7

Please sign in to comment.