Skip to content

Commit

Permalink
Merge branch 'main' into fix/approved-caip-networks-data-upa
Browse files Browse the repository at this point in the history
  • Loading branch information
zoruka authored Sep 19, 2024
2 parents 90642b9 + a181a19 commit 9369844
Show file tree
Hide file tree
Showing 27 changed files with 455 additions and 225 deletions.
38 changes: 38 additions & 0 deletions .changeset/small-parents-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit-wallet': patch
'@reown/appkit-core': patch
'@apps/demo': patch
'@apps/gallery': patch
'@apps/laboratory': patch
'@examples/html-ethers': patch
'@examples/html-ethers5': patch
'@examples/html-wagmi': patch
'@examples/next-ethers': patch
'@examples/next-wagmi': patch
'@examples/react-ethers': patch
'@examples/react-ethers5': patch
'@examples/react-solana': patch
'@examples/react-wagmi': patch
'@examples/vue-ethers5': patch
'@examples/vue-solana': patch
'@examples/vue-wagmi': patch
'@reown/appkit-adapter-polkadot': patch
'@reown/appkit': patch
'@reown/appkit-utils': patch
'@reown/appkit-cdn': patch
'@reown/appkit-common': patch
'@reown/appkit-ethers': patch
'@reown/appkit-ethers5': patch
'@reown/appkit-polyfills': patch
'@reown/appkit-scaffold-ui': patch
'@reown/appkit-siwe': patch
'@reown/appkit-solana': patch
'@reown/appkit-ui': patch
'@reown/appkit-wagmi': patch
---

Add Solana CoinbaseWalletProvider to allow connecting with coinbase extension
38 changes: 38 additions & 0 deletions .changeset/wise-bobcats-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-utils': patch
'@reown/appkit': patch
'@reown/appkit-common': patch
'@reown/appkit-wallet': patch
'@reown/appkit-core': patch
'@apps/demo': patch
'@apps/gallery': patch
'@apps/laboratory': patch
'@examples/html-ethers': patch
'@examples/html-ethers5': patch
'@examples/html-wagmi': patch
'@examples/next-ethers': patch
'@examples/next-wagmi': patch
'@examples/react-ethers': patch
'@examples/react-ethers5': patch
'@examples/react-solana': patch
'@examples/react-wagmi': patch
'@examples/vue-ethers5': patch
'@examples/vue-solana': patch
'@examples/vue-wagmi': patch
'@reown/appkit-adapter-polkadot': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit-cdn': patch
'@reown/appkit-ethers': patch
'@reown/appkit-ethers5': patch
'@reown/appkit-polyfills': patch
'@reown/appkit-scaffold-ui': patch
'@reown/appkit-siwe': patch
'@reown/appkit-solana': patch
'@reown/appkit-ui': patch
'@reown/appkit-wagmi': patch
---

Updates the localstorage keys
23 changes: 5 additions & 18 deletions apps/laboratory/src/pages/library/multichain-wagmi-solana.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,21 @@ import { ConstantsUtil } from '../../utils/ConstantsUtil'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { WagmiProvider } from 'wagmi'
import {
arbitrum,
mainnet,
polygon,
base,
binanceSmartChain,
solana,
solanaTestnet,
solanaDevnet,
arbitrum,
optimism,
zkSync,
sepolia
solanaTestnet,
solanaDevnet
} from '@reown/appkit/networks'
import { AppKitButtons } from '../../components/AppKitButtons'
import { HuobiWalletAdapter, SolflareWalletAdapter } from '@solana/wallet-adapter-wallets'
import { MultiChainTestsWagmiSolana } from '../../components/MultiChainTestsWagmiSolana'

const queryClient = new QueryClient()

const networks = [mainnet, optimism, polygon, zkSync, arbitrum, sepolia]
const networks = [mainnet, polygon, solana, arbitrum, optimism, solanaTestnet, solanaDevnet]

const wagmiAdapter = new WagmiAdapter({
ssr: true,
Expand All @@ -39,16 +35,7 @@ const solanaWeb3JsAdapter = new SolanaAdapter({

const modal = createAppKit({
adapters: [wagmiAdapter, solanaWeb3JsAdapter],
networks: [
mainnet,
polygon,
base,
binanceSmartChain,
arbitrum,
solana,
solanaTestnet,
solanaDevnet
],
networks,
defaultNetwork: mainnet,
projectId: ConstantsUtil.ProjectId,
features: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test.skip('it should show disabled networks', async () => {
await modalPage.closeModal()
})

test('it should switch networks and sign', async () => {
test.only('it should switch networks and sign', async () => {
const chains = ['Polygon', 'Solana']

async function processChain(index: number) {
Expand Down
2 changes: 1 addition & 1 deletion apps/laboratory/tests/shared/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export async function expectConnection(
await modalValidator.expectConnected()
await walletValidator.expectConnected()
await modalValidator.page.evaluate(
`window.localStorage.setItem('WALLETCONNECT_DEEPLINK_CHOICE', '')`
`window.localStorage.setItem('@appkit/deeplink_choice', JSON.stringify({ href: '', name: '' }))`
)
}
4 changes: 4 additions & 0 deletions apps/laboratory/tests/shared/validators/ModalValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export class ModalValidator {
async expectRejectedSign() {
// We use Chakra Toast and it's not quite straightforward to set the `data-testid` attribute on the toast element.
await expect(this.page.getByText(ConstantsUtil.SigningFailedToastTitle)).toBeVisible()
const closeButton = this.page.locator('#toast-close-button')

await expect(closeButton).toBeVisible()
await closeButton.click()
}

async expectSwitchedNetwork(network: string) {
Expand Down
30 changes: 18 additions & 12 deletions packages/adapters/ethers/src/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { EthersHelpersUtil, type ProviderId, type ProviderType } from '@reown/ap
import { ConstantsUtil } from '@reown/appkit-utils'
import { arbitrum, mainnet, polygon } from '@reown/appkit/networks'
import { ProviderUtil } from '@reown/appkit/store'
import { SafeLocalStorage } from '@reown/appkit-common'
import { WcConstantsUtil, type BlockchainApiLookupEnsName } from '@reown/appkit'
import { SafeLocalStorage, SafeLocalStorageKeys } from '@reown/appkit-common'
import { type BlockchainApiLookupEnsName } from '@reown/appkit'
import { InfuraProvider, JsonRpcProvider } from 'ethers'

import type { CaipNetwork, ChainNamespace } from '@reown/appkit-common'
Expand Down Expand Up @@ -519,8 +519,14 @@ describe('EthersAdapter', () => {
const mockProvider = { request: vi.fn() }
await client['setProvider'](mockProvider as any, 'injected', 'MetaMask')

expect(SafeLocalStorage.setItem).toHaveBeenCalledWith(WcConstantsUtil.WALLET_ID, 'injected')
expect(SafeLocalStorage.setItem).toHaveBeenCalledWith(WcConstantsUtil.WALLET_NAME, 'MetaMask')
expect(SafeLocalStorage.setItem).toHaveBeenCalledWith(
SafeLocalStorageKeys.WALLET_ID,
'injected'
)
expect(SafeLocalStorage.setItem).toHaveBeenCalledWith(
SafeLocalStorageKeys.WALLET_NAME,
'MetaMask'
)
expect(mockAppKit.setCaipNetwork).toHaveBeenCalled()
expect(mockAppKit.setCaipAddress).toHaveBeenCalled()
expect(ProviderUtil.setProviderId).toHaveBeenCalledWith('eip155', 'injected')
Expand Down Expand Up @@ -557,7 +563,7 @@ describe('EthersAdapter', () => {
)[1]
await disconnectHandler()

expect(SafeLocalStorage.removeItem).toHaveBeenCalledWith(WcConstantsUtil.WALLET_ID)
expect(SafeLocalStorage.removeItem).toHaveBeenCalledWith(SafeLocalStorageKeys.WALLET_ID)
expect(mockProvider.removeListener).toHaveBeenCalledTimes(3)
})

Expand Down Expand Up @@ -595,9 +601,9 @@ describe('EthersAdapter', () => {
}

vi.spyOn(SafeLocalStorage, 'getItem').mockImplementation(key => {
if (key === WcConstantsUtil.WALLET_ID) return ConstantsUtil.INJECTED_CONNECTOR_ID
if (key === WcConstantsUtil.WALLET_NAME) return 'MetaMask'
return null
if (key === SafeLocalStorageKeys.WALLET_ID) return ConstantsUtil.INJECTED_CONNECTOR_ID
if (key === SafeLocalStorageKeys.WALLET_NAME) return 'MetaMask'
return undefined
})

vi.spyOn(client as any, 'setProvider').mockImplementation(() => Promise.resolve())
Expand All @@ -613,7 +619,7 @@ describe('EthersAdapter', () => {

client['checkActiveProviders'](mockConfig as ProviderType)

expect(SafeLocalStorage.getItem).toHaveBeenCalledWith(WcConstantsUtil.WALLET_ID)
expect(SafeLocalStorage.getItem).toHaveBeenCalledWith(SafeLocalStorageKeys.WALLET_ID)
expect(client['setProvider']).toHaveBeenCalledWith(
mockInjectedProvider,
ConstantsUtil.INJECTED_CONNECTOR_ID
Expand All @@ -625,7 +631,7 @@ describe('EthersAdapter', () => {
})

it('should not set provider when wallet ID is not found', () => {
vi.spyOn(SafeLocalStorage, 'getItem').mockReturnValue(null)
vi.spyOn(SafeLocalStorage, 'getItem').mockReturnValue(undefined)

const mockConfig = {
injected: mockInjectedProvider,
Expand All @@ -635,7 +641,7 @@ describe('EthersAdapter', () => {

client['checkActiveProviders'](mockConfig as ProviderType)

expect(SafeLocalStorage.getItem).toHaveBeenCalledWith(WcConstantsUtil.WALLET_ID)
expect(SafeLocalStorage.getItem).toHaveBeenCalledWith(SafeLocalStorageKeys.WALLET_ID)
expect(client['setProvider']).not.toHaveBeenCalled()
expect(client['setupProviderListeners']).not.toHaveBeenCalled()
})
Expand All @@ -649,7 +655,7 @@ describe('EthersAdapter', () => {

client['checkActiveProviders'](mockConfig as ProviderType)

expect(SafeLocalStorage.getItem).toHaveBeenCalledWith(WcConstantsUtil.WALLET_ID)
expect(SafeLocalStorage.getItem).toHaveBeenCalledWith(SafeLocalStorageKeys.WALLET_ID)
expect(client['setProvider']).not.toHaveBeenCalled()
expect(client['setupProviderListeners']).not.toHaveBeenCalled()
})
Expand Down
30 changes: 18 additions & 12 deletions packages/adapters/ethers5/src/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { EthersHelpersUtil, type ProviderId, type ProviderType } from '@reown/ap
import { ConstantsUtil } from '@reown/appkit-utils'
import { arbitrum, mainnet, polygon } from '@reown/appkit/networks'
import { ProviderUtil } from '@reown/appkit/store'
import { SafeLocalStorage } from '@reown/appkit-common'
import { WcConstantsUtil, type BlockchainApiLookupEnsName } from '@reown/appkit'
import { SafeLocalStorage, SafeLocalStorageKeys } from '@reown/appkit-common'
import { type BlockchainApiLookupEnsName } from '@reown/appkit'
import { ethers } from 'ethers5'
import type { CaipNetwork, ChainNamespace } from '@reown/appkit-common'

Expand Down Expand Up @@ -524,8 +524,14 @@ describe('EthersAdapter', () => {
const mockProvider = { request: vi.fn() }
await client['setProvider'](mockProvider as any, 'injected', 'MetaMask')

expect(SafeLocalStorage.setItem).toHaveBeenCalledWith(WcConstantsUtil.WALLET_ID, 'injected')
expect(SafeLocalStorage.setItem).toHaveBeenCalledWith(WcConstantsUtil.WALLET_NAME, 'MetaMask')
expect(SafeLocalStorage.setItem).toHaveBeenCalledWith(
SafeLocalStorageKeys.WALLET_ID,
'injected'
)
expect(SafeLocalStorage.setItem).toHaveBeenCalledWith(
SafeLocalStorageKeys.WALLET_NAME,
'MetaMask'
)
expect(mockAppKit.setCaipNetwork).toHaveBeenCalled()
expect(ProviderUtil.setProviderId).toHaveBeenCalledWith('eip155', 'injected')
expect(ProviderUtil.setProvider).toHaveBeenCalledWith('eip155', mockProvider)
Expand Down Expand Up @@ -561,7 +567,7 @@ describe('EthersAdapter', () => {
)[1]
await disconnectHandler()

expect(SafeLocalStorage.removeItem).toHaveBeenCalledWith(WcConstantsUtil.WALLET_ID)
expect(SafeLocalStorage.removeItem).toHaveBeenCalledWith(SafeLocalStorageKeys.WALLET_ID)
expect(mockProvider.removeListener).toHaveBeenCalledTimes(3)
})

Expand Down Expand Up @@ -599,9 +605,9 @@ describe('EthersAdapter', () => {
}

vi.spyOn(SafeLocalStorage, 'getItem').mockImplementation(key => {
if (key === WcConstantsUtil.WALLET_ID) return ConstantsUtil.INJECTED_CONNECTOR_ID
if (key === WcConstantsUtil.WALLET_NAME) return 'MetaMask'
return null
if (key === SafeLocalStorageKeys.WALLET_ID) return ConstantsUtil.INJECTED_CONNECTOR_ID
if (key === SafeLocalStorageKeys.WALLET_NAME) return 'MetaMask'
return undefined
})

vi.spyOn(client as any, 'setProvider').mockImplementation(() => Promise.resolve())
Expand All @@ -617,7 +623,7 @@ describe('EthersAdapter', () => {

client['checkActiveProviders'](mockConfig as ProviderType)

expect(SafeLocalStorage.getItem).toHaveBeenCalledWith(WcConstantsUtil.WALLET_ID)
expect(SafeLocalStorage.getItem).toHaveBeenCalledWith(SafeLocalStorageKeys.WALLET_ID)
expect(client['setProvider']).toHaveBeenCalledWith(
mockInjectedProvider,
ConstantsUtil.INJECTED_CONNECTOR_ID
Expand All @@ -629,7 +635,7 @@ describe('EthersAdapter', () => {
})

it('should not set provider when wallet ID is not found', () => {
vi.spyOn(SafeLocalStorage, 'getItem').mockReturnValue(null)
vi.spyOn(SafeLocalStorage, 'getItem').mockReturnValue(undefined)

const mockConfig = {
injected: mockInjectedProvider,
Expand All @@ -639,7 +645,7 @@ describe('EthersAdapter', () => {

client['checkActiveProviders'](mockConfig as ProviderType)

expect(SafeLocalStorage.getItem).toHaveBeenCalledWith(WcConstantsUtil.WALLET_ID)
expect(SafeLocalStorage.getItem).toHaveBeenCalledWith(SafeLocalStorageKeys.WALLET_ID)
expect(client['setProvider']).not.toHaveBeenCalled()
expect(client['setupProviderListeners']).not.toHaveBeenCalled()
})
Expand All @@ -653,7 +659,7 @@ describe('EthersAdapter', () => {

client['checkActiveProviders'](mockConfig as ProviderType)

expect(SafeLocalStorage.getItem).toHaveBeenCalledWith(WcConstantsUtil.WALLET_ID)
expect(SafeLocalStorage.getItem).toHaveBeenCalledWith(SafeLocalStorageKeys.WALLET_ID)
expect(client['setProvider']).not.toHaveBeenCalled()
expect(client['setupProviderListeners']).not.toHaveBeenCalled()
})
Expand Down
40 changes: 28 additions & 12 deletions packages/adapters/solana/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { ProviderUtil } from '@reown/appkit/store'
import { W3mFrameProviderSingleton } from '@reown/appkit/auth-provider'
import { ConstantsUtil } from '@reown/appkit-utils'
import { createSendTransaction } from './utils/createSendTransaction.js'
import { CoinbaseWalletProvider } from './providers/CoinbaseWalletProvider.js'

export interface AdapterOptions {
connectionSettings?: Commitment | ConnectionConfig
Expand Down Expand Up @@ -140,14 +141,10 @@ export class SolanaAdapter implements ChainAdapter {
this.networkControllerClient = {
switchCaipNetwork: async caipNetwork => {
if (caipNetwork) {
SafeLocalStorage.setItem(
SafeLocalStorageKeys.ACTIVE_CAIP_NETWORK,
JSON.stringify(caipNetwork)
)
try {
await this.switchNetwork(caipNetwork)
} catch (error) {
// SolStoreUtil.setError(error)
console.warn('Error switching network', error)
}
}
},
Expand Down Expand Up @@ -326,15 +323,23 @@ export class SolanaAdapter implements ChainAdapter {
})

EventsController.subscribe(state => {
if (state.data.event === 'SELECT_WALLET' && state.data.properties?.name === 'Phantom') {
if (state.data.event === 'SELECT_WALLET') {
const isMobile = CoreHelperUtil.isMobile()
const isClient = CoreHelperUtil.isClient()
if (isMobile && isClient && !('phantom' in window)) {
const href = window.location.href
const protocol = href.startsWith('https') ? 'https' : 'http'
const host = href.split('/')[2]
const ref = `${protocol}://${host}`
window.location.href = `https://phantom.app/ul/browse/${href}?ref=${ref}`

if (isMobile && isClient) {
if (state.data.properties?.name === 'Phantom' && !('phantom' in window)) {
const href = window.location.href
const protocol = href.startsWith('https') ? 'https' : 'http'
const host = href.split('/')[2]
const ref = `${protocol}://${host}`
window.location.href = `https://phantom.app/ul/browse/${href}?ref=${ref}`
}

if (state.data.properties?.name === 'Coinbase Wallet' && !('coinbaseSolana' in window)) {
const href = window.location.href
window.location.href = `https://go.cb-w.com/dapp?cb_url=${href}`
}
}
}
})
Expand Down Expand Up @@ -634,6 +639,17 @@ export class SolanaAdapter implements ChainAdapter {
this.addProvider(this.authProvider)
}

if ('coinbaseSolana' in window) {
this.addProvider(
new CoinbaseWalletProvider({
// @ts-expect-error - window is not typed
provider: window.coinbaseSolana,
chains: this.caipNetworks,
getActiveChain: () => this.appKit?.getCaipNetwork(this.chainNamespace)
})
)
}

if (this.appKit && this.caipNetworks[0]) {
watchStandard(this.appKit, this.caipNetworks[0], standardAdapters =>
this.addProvider.bind(this)(...standardAdapters)
Expand Down
Loading

0 comments on commit 9369844

Please sign in to comment.