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

Nova Wallet EVM #1448

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions src/sections/web3-connect/constants/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const MOBILE_PROVIDERS: WalletProviderType[] = [
WalletProviderType.Phantom,
WalletProviderType.Enkrypt,
WalletProviderType.NovaWallet,
WalletProviderType.NovaWalletEvm,
WalletProviderType.WalletConnect,
]

Expand All @@ -28,6 +29,7 @@ export const EVM_PROVIDERS: WalletProviderType[] = [
WalletProviderType.MetaMask,
WalletProviderType.TalismanEvm,
WalletProviderType.SubwalletEvm,
WalletProviderType.NovaWalletEvm,
WalletProviderType.Phantom,
WalletProviderType.WalletConnect,
]
Expand All @@ -41,6 +43,11 @@ export const SUBSTRATE_PROVIDERS: WalletProviderType[] = [
WalletProviderType.WalletConnect,
]

export const NOVA_WALLET_PROVIDERS: WalletProviderType[] = [
WalletProviderType.NovaWallet,
WalletProviderType.NovaWalletEvm,
]

export const ALTERNATIVE_PROVIDERS: WalletProviderType[] = [
WalletProviderType.ExternalWallet,
]
18 changes: 17 additions & 1 deletion src/sections/web3-connect/providers/Web3ConnectProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,26 @@ import {
DESKTOP_PROVIDERS,
EVM_PROVIDERS,
MOBILE_PROVIDERS,
NOVA_WALLET_PROVIDERS,
SUBSTRATE_PROVIDERS,
} from "sections/web3-connect/constants/providers"
import { POLKADOT_CAIP_ID_MAP } from "sections/web3-connect/wallets/WalletConnect"

const useWalletProviders = (mode: WalletMode, chain?: string) => {
const isDesktop = useMedia(theme.viewport.gte.sm)

const context = useMemo(() => {
const wallets = getSupportedWallets()
const isNovaWallet = wallets.some(
({ type, wallet }) =>
NOVA_WALLET_PROVIDERS.includes(type) && wallet.installed,
)

return {
isNovaWallet,
}
}, [])

return useMemo(() => {
const wallets = getSupportedWallets()

Expand All @@ -35,6 +48,9 @@ const useWalletProviders = (mode: WalletMode, chain?: string) => {
const defaultProviders = wallets
.filter((provider) => {
if (isEvmMode) return EVM_PROVIDERS.includes(provider.type)
if (context.isNovaWallet)
return NOVA_WALLET_PROVIDERS.includes(provider.type)

const byScreen = isDesktop
? DESKTOP_PROVIDERS.includes(provider.type)
: MOBILE_PROVIDERS.includes(provider.type)
Expand Down Expand Up @@ -68,7 +84,7 @@ const useWalletProviders = (mode: WalletMode, chain?: string) => {
defaultProviders,
alternativeProviders,
}
}, [isDesktop, mode, chain])
}, [mode, context, isDesktop, chain])
}

export const Web3ConnectProviders = () => {
Expand Down
22 changes: 22 additions & 0 deletions src/sections/web3-connect/wallets/NovaWalletEvm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import NovaWalletLogo from "assets/icons/NovaWallet.svg"

import { MetaMask } from "./MetaMask"
import { isNovaWalletEvm } from "utils/metamask"

export class NovaWalletEvm extends MetaMask {
extensionName = "nova-wallet-evm"
title = "Nova Wallet EVM"
installUrl = "https://novawallet.io"
logo = {
src: NovaWalletLogo,
alt: "Nova Wallet Logo",
}

get installed() {
return isNovaWalletEvm(window.ethereum)
}

get rawExtension() {
return window.ethereum
}
}
8 changes: 8 additions & 0 deletions src/sections/web3-connect/wallets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { H160, isEvmAddress } from "utils/evm"
import { SubWalletEvm } from "sections/web3-connect/wallets/SubWalletEvm"
import { SubWallet } from "sections/web3-connect/wallets/SubWallet"
import { EIP6963AnnounceProviderEvent } from "sections/web3-connect/types"
import { NovaWalletEvm } from "sections/web3-connect/wallets/NovaWalletEvm"

export enum WalletProviderType {
MetaMask = "metamask",
Expand All @@ -19,6 +20,7 @@ export enum WalletProviderType {
SubwalletEvm = "subwallet-evm",
PolkadotJS = "polkadot-js",
NovaWallet = "nova-wallet",
NovaWalletEvm = "nova-wallet-evm",
Phantom = "phantom",
Enkrypt = "enkrypt",
WalletConnect = "walletconnect",
Expand Down Expand Up @@ -54,6 +56,11 @@ const onMetaMaskLikeAccountChange =
}

const novaWallet: Wallet = new NovaWallet()
const novaWalletEvm: Wallet = new NovaWalletEvm({
onAccountsChanged: onMetaMaskLikeAccountChange(
WalletProviderType.NovaWalletEvm,
),
})
const talismanEvm: Wallet = new TalismanEvm({
onAccountsChanged: onMetaMaskLikeAccountChange(
WalletProviderType.TalismanEvm,
Expand Down Expand Up @@ -95,6 +102,7 @@ export let SUPPORTED_WALLET_PROVIDERS: WalletProvider[] = [
subwalletEvm,
subwallet,
novaWallet,
novaWalletEvm,
walletConnect,
externalWallet,
].map((wallet) => ({
Expand Down
13 changes: 12 additions & 1 deletion src/utils/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import UniversalProvider from "@walletconnect/universal-provider/dist/types/Univ
import { chainsMap } from "@galacticcouncil/xcm-cfg"
import { EvmParachain } from "@galacticcouncil/xcm-core"

const METAMASK_LIKE_CHECKS = ["isTalisman", "isSubWallet", "isPhantom"] as const
const METAMASK_LIKE_CHECKS = [
"isTalisman",
"isSubWallet",
"isPhantom",
"isNovaWallet",
] as const
type MetaMaskLikeChecksValues = (typeof METAMASK_LIKE_CHECKS)[number]

type MetaMaskLikeChecks = {
Expand Down Expand Up @@ -76,6 +81,12 @@ export function isPhantom(provider: Maybe<ExternalProvider>) {
return isMetaMaskLike(provider) && !!provider?.isPhantom
}

export function isNovaWalletEvm(
provider: Maybe<ExternalProvider>,
): provider is Required<MetaMaskLikeProvider> {
return isMetaMaskLike(provider) && !!provider?.isNovaWallet
}

export function isEthereumProvider(
provider: Maybe<ExternalProvider>,
): provider is Required<MetaMaskLikeProvider | UniversalProvider> {
Expand Down
Loading