Skip to content
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

Add Rabby wallet support #70

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions frontend/components/wallets/EVM.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import walletConnect from '@images/wallet-connect.svg'
import metamask from '@images/metamask.svg'
import okx from '@images/okx.svg'
import phantom from '@images/phantom.svg'
import rabby from '@images/rabby.svg'

import { getInjectiveAddress } from '../../utils/getInjectiveAddress'

Expand Down Expand Up @@ -96,6 +97,7 @@ export function EVMWalletButton({
const { address, status, isConnected, connector } = useAccount()
const { connect, connectors } = useConnect()
const hasOKXWallet = typeof (window as any).okxwallet !== 'undefined'
const hasRabbyWallet = typeof (window as any).rabby !== 'undefined'

// If the wallet is connected or loadable, try to connect to it.
// Else, redirect user to the wallet webpage.
Expand All @@ -107,13 +109,16 @@ export function EVMWalletButton({
} else if (connector.name === 'OKX Wallet') {
if (hasOKXWallet) connect({ connector })
else window.open('https://www.okx.com/web3', '_blank')
} else if (connector.name === 'Rabby') {
if (hasRabbyWallet) connect({ connector })
else window.open('https://rabby.io/', '_blank')
} else {
// Wallet flow is handled pretty well by coinbase and walletconnect.
// We don't need to customize
connect({ connector })
}
},
[connect, hasOKXWallet]
[connect, hasOKXWallet, hasRabbyWallet]
)

const wallets = () => {
Expand All @@ -140,6 +145,21 @@ export function EVMWalletButton({
onSelect: () => onSelect(OKX_connector),
})

const Rabby_connector = new InjectedConnector({
chains,
options: {
name: 'Rabby',
getProvider: () =>
typeof window !== undefined ? (window as any).rabby : undefined,
},
})

allConnectors.push({
name: 'Rabby',
icon: getIcon(Rabby_connector.id as WalletIds, 'Rabby'),
onSelect: () => onSelect(Rabby_connector),
})

return allConnectors
}

Expand All @@ -155,18 +175,21 @@ export function EVMWalletButton({
onClick={disconnect}
address={isInjective ? getInjectiveAddress(address) : address}
disabled={disableOnConnect}
icon={getIcon(connector?.id as WalletIds)}
icon={getIcon(connector?.id as WalletIds, connector?.name)}
/>
)}
/>
)
}

function getIcon(id: WalletIds | undefined) {
function getIcon(id: WalletIds | undefined, name?: any) {
if (id === undefined) return undefined
if (id === 'metaMask') return metamask
if (id === 'coinbaseWallet') return coinbase
if (id === 'phantom') return phantom
if (id === 'injected') return okx
if (id === 'injected') {
if (name === 'Rabby') return rabby
return okx
}
return walletConnect
}
8 changes: 8 additions & 0 deletions frontend/images/rabby.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading