Skip to content

Commit

Permalink
refactor: connector listing logics, solana lab tests
Browse files Browse the repository at this point in the history
  • Loading branch information
enesozturk committed Sep 4, 2024
1 parent bc8fe1c commit 7a9f340
Show file tree
Hide file tree
Showing 6 changed files with 844 additions and 864 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import {
Transaction,
TransactionMessage,
VersionedTransaction,
SystemProgram
SystemProgram,
Connection
} from '@solana/web3.js'

import { useWeb3ModalAccount, useWeb3ModalProvider, type Provider } from '@web3modal/solana/react'
import { type Provider, useWeb3ModalConnection } from '@web3modal/adapter-solana/react'
import { useWeb3ModalNetwork, useWeb3ModalProvider } from '@web3modal/base/react'

import { solana } from '../../utils/ChainsUtil'
import { solana } from '@web3modal/base/chains'
import { useChakraToast } from '../Toast'
import type { Connection } from '@web3modal/base/adapters/solana/web3js'
import bs58 from 'bs58'

const PHANTOM_DEVNET_ADDRESS = '8vCyX7oB6Pc3pbWMGYYZF5pbSnAdQ7Gyr32JqxqCy8ZR'
Expand All @@ -21,8 +22,9 @@ const amountInLamports = 1_000_000

export function SolanaSignAllTransactionsTest() {
const toast = useChakraToast()
const { chainId } = useWeb3ModalAccount()
const { walletProvider, connection } = useWeb3ModalProvider()
const { chainId } = useWeb3ModalNetwork()
const { walletProvider } = useWeb3ModalProvider<Provider>('solana')
const { connection } = useWeb3ModalConnection()
const [loading, setLoading] = useState(false)

async function onSignTransaction(type: 'legacy' | 'versioned') {
Expand Down
22 changes: 20 additions & 2 deletions apps/laboratory/src/pages/library/multichain-wagmi-solana.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ import { ThemeStore } from '../../utils/StoreUtil'
import { ConstantsUtil } from '../../utils/ConstantsUtil'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { WagmiProvider } from 'wagmi'
import { arbitrum, mainnet, polygon, base, binanceSmartChain, solana } from '@web3modal/base/chains'
import {
arbitrum,
mainnet,
polygon,
base,
binanceSmartChain,
solana,
solanaTestnet,
solanaDevnet
} from '@web3modal/base/chains'
import { AppKitButtons } from '../../components/AppKitButtons'
import { HuobiWalletAdapter, SolflareWalletAdapter } from '@solana/wallet-adapter-wallets'
import { MultiChainTestsWagmiSolana } from '../../components/MultiChainTestsWagmiSolana'
Expand All @@ -24,7 +33,16 @@ const solanaWeb3JsAdapter = new SolanaWeb3JsClient({
const modal = createWeb3Modal({
adapters: [wagmiAdapter, solanaWeb3JsAdapter],
siweConfig,
caipNetworks: [mainnet, polygon, base, binanceSmartChain, arbitrum, solana],
caipNetworks: [
mainnet,
polygon,
base,
binanceSmartChain,
arbitrum,
solana,
solanaTestnet,
solanaDevnet
],
defaultCaipNetwork: mainnet,
projectId: ConstantsUtil.ProjectId,
features: {
Expand Down
32 changes: 12 additions & 20 deletions apps/laboratory/src/pages/library/solana-no-socials.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
import { createWeb3Modal, defaultSolanaConfig } from '@web3modal/solana/react'
import { createWeb3Modal } from '@web3modal/base/react'
import { SolanaWeb3JsClient } from '@web3modal/adapter-solana/react'

import { ThemeStore } from '../../utils/StoreUtil'
import { solana, solanaDevnet, solanaTestnet } from '../../utils/ChainsUtil'
import { solana, solanaDevnet, solanaTestnet } from '@web3modal/base/chains'
import { AppKitButtons } from '../../components/AppKitButtons'
import { ConstantsUtil } from '../../utils/ConstantsUtil'
import { SolanaTests } from '../../components/Solana/SolanaTests'
import { SolflareWalletAdapter } from '@solana/wallet-adapter-wallets'
import { HuobiWalletAdapter, SolflareWalletAdapter } from '@solana/wallet-adapter-wallets'

const chains = [solana, solanaTestnet, solanaDevnet]

export const solanaConfig = defaultSolanaConfig({
chains,
projectId: ConstantsUtil.ProjectId,
metadata: ConstantsUtil.Metadata,
auth: {
email: true,
socials: []
}
const solanaWeb3JsAdapter = new SolanaWeb3JsClient({
wallets: [new HuobiWalletAdapter(), new SolflareWalletAdapter()]
})

const modal = createWeb3Modal({
solanaConfig,
adapters: [solanaWeb3JsAdapter],
caipNetworks: chains,
projectId: ConstantsUtil.ProjectId,
metadata: ConstantsUtil.Metadata,
defaultChain: solana,
chains,
enableAnalytics: false,
termsConditionsUrl: 'https://walletconnect.com/terms',
privacyPolicyUrl: 'https://walletconnect.com/privacy',
customWallets: ConstantsUtil.CustomWallets,
enableSwaps: false,
wallets: [new SolflareWalletAdapter()]
features: {
email: true,
socials: []
}
})

ThemeStore.setModal(modal)
Expand Down
19 changes: 16 additions & 3 deletions packages/core/src/controllers/ConnectorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,35 @@ export const ConnectorController = {

connectors.forEach(connector => {
const { name } = connector
const connectorName = this.getConnectorName(name)

if (!name) {
if (!connectorName) {
return
}

const connectorsByName = connectorsByNameMap.get(name) || []
const connectorsByName = connectorsByNameMap.get(connectorName) || []
const haveSameConnector = connectorsByName.find(c => c.chain === connector.chain)
if (!haveSameConnector) {
connectorsByName.push(connector)
}
connectorsByNameMap.set(name, connectorsByName)
connectorsByNameMap.set(connectorName, connectorsByName)
})

return connectorsByNameMap
},

getConnectorName(name: string | undefined) {
if (!name) {
return name
}

const nameOverrideMap = {
'Trust Wallet': 'Trust'
}

return (nameOverrideMap as Record<string, string>)[name] || name
},

getUniqueConnectorsByName(connectors: Connector[]) {
const uniqueConnectors: Connector[] = []

Expand Down
12 changes: 4 additions & 8 deletions packages/scaffold-ui/src/views/w3m-networks-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ export class W3mNetworksView extends LitElement {

private async onSwitchNetwork(network: CaipNetwork) {
const isCurrentNamespaceConnected = AccountController.state.isConnected
const isNetworkNamespaceConnected = AccountController.getChainIsConnected(
network.chainNamespace
)
const isNamespaceConnected = AccountController.getChainIsConnected(network.chainNamespace)
const isEIP155Namespace = network.chainNamespace === ConstantsUtil.CHAIN.EVM
const isSameNetwork = network.id === this.network?.id
Expand All @@ -177,17 +174,16 @@ export class W3mNetworksView extends LitElement {
if (ChainController.state.noAdapters) {
RouterController.push('ConnectingWalletConnect')
} else {
// eslint-disable-next-line no-lonely-if
if (isCurrentNamespaceConnected || !isNetworkNamespaceConnected) {
NetworkController.setActiveCaipNetwork(network)
await NetworkUtil.onNetworkChange()
} else {
if (isCurrentNamespaceConnected) {
RouterController.push('SwitchActiveChain', {
switchToChain: network.chainNamespace,
navigateTo: 'Connect',
navigateWithReplace: true,
network
})
} else {
NetworkController.setActiveCaipNetwork(network)
await NetworkUtil.onNetworkChange()
}
}
}
Expand Down
Loading

0 comments on commit 7a9f340

Please sign in to comment.