Skip to content

Commit

Permalink
refactor: required chain params and remove scaffolds, move solana uti…
Browse files Browse the repository at this point in the history
…ls to scaffold-utils (#2730)
  • Loading branch information
enesozturk authored Aug 22, 2024
1 parent 543585f commit d9e6bd2
Show file tree
Hide file tree
Showing 84 changed files with 624 additions and 3,148 deletions.
5 changes: 1 addition & 4 deletions apps/laboratory/tests/shared/pages/ModalPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ export class ModalPage {
return value!
}

async getConnectUri(timingRecords?: TimingRecords, goToPage = true): Promise<string> {
if (goToPage) {
await this.page.goto(this.url)
}
async getConnectUri(timingRecords?: TimingRecords): Promise<string> {
await this.connectButton.click()
const connect = this.page.getByTestId('wallet-selector-walletconnect')
await connect.waitFor({
Expand Down
6 changes: 1 addition & 5 deletions apps/laboratory/tests/wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ sampleWalletTest.afterAll(async () => {

// -- Tests --------------------------------------------------------------------
sampleWalletTest('it should switch networks and sign', async ({ library }) => {
if (library === 'solana') {
return
}

const chains = ['Polygon', 'Ethereum']
const chains = library === 'solana' ? ['Solana Testnet', 'Solana'] : ['Polygon', 'Ethereum']

async function processChain(index: number) {
if (index >= chains.length) {
Expand Down
4 changes: 2 additions & 2 deletions packages/base/adapters/evm/ethers/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
SendTransactionArgs,
Token,
WriteContractArgs
} from '@web3modal/scaffold'
} from '@web3modal/core'
import { ConstantsUtil, PresetsUtil, HelpersUtil } from '@web3modal/scaffold-utils'
import { ConstantsUtil as CommonConstantsUtil } from '@web3modal/common'
import EthereumProvider, { OPTIONAL_METHODS } from '@walletconnect/ethereum-provider'
Expand Down Expand Up @@ -1254,7 +1254,7 @@ export class EVMEthersClient {
const registeredWcNames = await this.appKit?.getWalletConnectName(address)
if (registeredWcNames?.[0]) {
const wcName = registeredWcNames[0]
this.appKit?.setProfileName(wcName.name)
this.appKit?.setProfileName(wcName.name, this.chain)
} else {
this.appKit?.setProfileName(null, this.chain)
}
Expand Down
32 changes: 16 additions & 16 deletions packages/base/adapters/evm/ethers5/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
PublicStateControllerState,
SendTransactionArgs,
Token
} from '@web3modal/scaffold'
} from '@web3modal/core'
import { ConstantsUtil, PresetsUtil, HelpersUtil } from '@web3modal/scaffold-utils'
import { ConstantsUtil as CommonConstantsUtil } from '@web3modal/common'
import EthereumProvider, { OPTIONAL_METHODS } from '@walletconnect/ethereum-provider'
Expand Down Expand Up @@ -584,7 +584,7 @@ export class EVMEthers5Client {
imageUrl: chainImages?.[chain.chainId]
}) as CaipNetwork
)
this.appKit?.setRequestedCaipNetworks(requestedCaipNetworks ?? [])
this.appKit?.setRequestedCaipNetworks(requestedCaipNetworks ?? [], this.chain)
}

private async checkActiveWalletConnectProvider() {
Expand Down Expand Up @@ -861,14 +861,14 @@ export class EVMEthers5Client {
const chainId = EthersStoreUtil.state.chainId
const isConnected = EthersStoreUtil.state.isConnected

this.appKit?.resetAccount()
this.appKit?.resetAccount(this.chain)

if (isConnected && address && chainId) {
const caipAddress: CaipAddress = `${ConstantsUtil.EIP155}:${chainId}:${address}`

this.appKit?.setIsConnected(isConnected)
this.appKit?.setIsConnected(isConnected, this.chain)

this.appKit?.setCaipAddress(caipAddress)
this.appKit?.setCaipAddress(caipAddress, this.chain)
this.syncConnectedWalletInfo()

await Promise.all([
Expand Down Expand Up @@ -904,12 +904,12 @@ export class EVMEthers5Client {
})
if (isConnected && address) {
const caipAddress: CaipAddress = `${ConstantsUtil.EIP155}:${chainId}:${address}`
this.appKit?.setCaipAddress(caipAddress)
this.appKit?.setCaipAddress(caipAddress, this.chain)
if (chain.explorerUrl) {
const url = `${chain.explorerUrl}/address/${address}`
this.appKit?.setAddressExplorerUrl(url)
this.appKit?.setAddressExplorerUrl(url, this.chain)
} else {
this.appKit?.setAddressExplorerUrl(undefined)
this.appKit?.setAddressExplorerUrl(undefined, this.chain)
}
if (this.hasSyncedConnectedAccount) {
await this.syncBalance(address)
Expand All @@ -929,7 +929,7 @@ export class EVMEthers5Client {
const registeredWcNames = await this.appKit?.getWalletConnectName(address)
if (registeredWcNames?.[0]) {
const wcName = registeredWcNames[0]
this.appKit?.setProfileName(wcName.name)
this.appKit?.setProfileName(wcName.name, this.chain)
} else {
this.appKit?.setProfileName(null, this.chain)
}
Expand All @@ -948,8 +948,8 @@ export class EVMEthers5Client {
const name = identity?.name
const avatar = identity?.avatar

this.appKit?.setProfileName(name)
this.appKit?.setProfileImage(avatar)
this.appKit?.setProfileName(name, this.chain)
this.appKit?.setProfileImage(avatar, this.chain)

if (!name) {
await this.syncWalletConnectName(address)
Expand All @@ -961,14 +961,14 @@ export class EVMEthers5Client {
const avatar = await ensProvider.getAvatar(address)

if (name) {
this.appKit?.setProfileName(name)
this.appKit?.setProfileName(name, this.chain)
}
if (avatar) {
this.appKit?.setProfileImage(avatar)
this.appKit?.setProfileImage(avatar, this.chain)
}
} else {
this.appKit?.setProfileName(null)
this.appKit?.setProfileImage(null)
this.appKit?.setProfileName(null, this.chain)
this.appKit?.setProfileImage(null, this.chain)
}
}
}
Expand All @@ -986,7 +986,7 @@ export class EVMEthers5Client {
if (JsonRpcProvider) {
const balance = await JsonRpcProvider.getBalance(address)
const formattedBalance = utils.formatEther(balance)
this.appKit?.setBalance(formattedBalance, chain.currency)
this.appKit?.setBalance(formattedBalance, chain.currency, this.chain)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/base/adapters/evm/wagmi/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import type {
SendTransactionArgs,
SocialProvider,
WriteContractArgs
} from '@web3modal/scaffold'
} from '@web3modal/core'
import { formatUnits, parseUnits } from 'viem'
import type { Hex } from 'viem'
import { ConstantsUtil, PresetsUtil, HelpersUtil } from '@web3modal/scaffold-utils'
Expand Down
4 changes: 2 additions & 2 deletions packages/base/adapters/evm/wagmi/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { CoreHelperUtil } from '@web3modal/scaffold'
import { ConstantsUtil as CommonConstantsUtil } from '@web3modal/common'
import { ConstantsUtil, PresetsUtil } from '@web3modal/scaffold-utils'
import { EthereumProvider } from '@walletconnect/ethereum-provider'
import { getChainsFromAccounts } from '@walletconnect/utils'
import { fallback, http, type Hex } from 'viem'

import type { CaipNetwork, CaipNetworkId } from '@web3modal/scaffold'
import type { CaipNetwork, CaipNetworkId } from '@web3modal/core'
import type { Chain } from '@wagmi/core/chains'
import type { Connector } from '@wagmi/core'
import { CoreHelperUtil } from '@web3modal/core'

export function getCaipDefaultChain(chain?: Chain) {
if (!chain) {
Expand Down
2 changes: 1 addition & 1 deletion packages/base/adapters/evm/wagmi/utils/provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { http } from '@wagmi/core'
import type { Chain } from '@wagmi/core/chains'
import { CoreHelperUtil } from '@web3modal/scaffold'
import { CoreHelperUtil } from '@web3modal/core'
import { ConstantsUtil, PresetsUtil } from '@web3modal/scaffold-utils'

// -- Helpers ------------------------------------------------------------------
Expand Down
11 changes: 8 additions & 3 deletions packages/base/adapters/solana/web3js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { ConstantsUtil, PresetsUtil } from '@web3modal/scaffold-utils'
import { ConstantsUtil as CommonConstantsUtil } from '@web3modal/common'

import { SolConstantsUtil, SolHelpersUtil, SolStoreUtil } from './utils/scaffold/index.js'
import { SolConstantsUtil, SolHelpersUtil, SolStoreUtil } from '@web3modal/scaffold-utils/solana'

import type { BaseWalletAdapter } from '@solana/wallet-adapter-base'
import { PublicKey, type Commitment, type ConnectionConfig } from '@solana/web3.js'
Expand All @@ -23,10 +23,15 @@ import type {
Connector,
CaipAddress,
CaipNetwork
} from '@web3modal/scaffold'
} from '@web3modal/core'
import type { Chain as AvailableChain } from '@web3modal/common'

import type { ProviderType, Chain, Provider, SolStoreUtilState } from './utils/scaffold/index.js'
import type {
ProviderType,
Chain,
Provider,
SolStoreUtilState
} from '@web3modal/scaffold-utils/solana'
import { watchStandard } from './utils/watchStandard.js'
import { WalletConnectProvider } from './providers/WalletConnectProvider.js'
import type { AppKit } from '../../../src/client.js'
Expand Down
4 changes: 2 additions & 2 deletions packages/base/adapters/solana/web3js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ export { SolanaWeb3JsClient } from './client.js'

// -- Types -----------------------------------------------------------
export type { Web3ModalClientOptions } from './client.js'
export type * from './utils/scaffold/SolanaTypesUtil.js'
export type * from '@web3modal/scaffold-utils/solana'
export type * from '@solana/wallet-adapter-base'

// -- Utils -----------------------------------------------------------
export * from './utils/defaultConfig.js'
export * from './utils/scaffold/SolanaStoreUtil.js'
export * from '@web3modal/scaffold-utils/solana'

// -- Constants -------------------------------------------------------
export { solana, solanaDevnet, solanaTestnet } from './utils/chains.js'
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type AnyTransaction,
type Chain,
type Provider
} from '../utils/scaffold/index.js'
} from '@web3modal/scaffold-utils/solana'
import { ProviderEventEmitter } from './shared/ProviderEventEmitter.js'
import type { SessionTypes } from '@walletconnect/types'
import base58 from 'bs58'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
type Chain,
type GetActiveChain,
type Provider
} from '../utils/scaffold/index.js'
} from '@web3modal/scaffold-utils/solana'
import base58 from 'bs58'
import { WalletStandardFeatureNotSupportedError } from './shared/Errors.js'
import { ProviderEventEmitter } from './shared/ProviderEventEmitter.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ProviderEventEmitterMethods } from '../../utils/scaffold/index.js'
import type { ProviderEventEmitterMethods } from '@web3modal/scaffold-utils/solana'

type Listeners = {
[Event in ProviderEventEmitterMethods.Event]: Array<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeAll, describe, expect, it, vi } from 'vitest'
import type { Provider } from '../utils/scaffold/SolanaTypesUtil.js'
import type { Provider } from '@web3modal/scaffold-utils/solana'
import { WalletConnectProvider } from '../providers/WalletConnectProvider.js'
import { mockUniversalProvider } from './mocks/UniversalProvider.js'
import { WalletStandardProvider } from '../providers/WalletStandardProvider.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mockUniversalProvider, mockUniversalProviderSession } from './mocks/Uni
import { WalletConnectProvider } from '../providers/WalletConnectProvider.js'
import { TestConstants } from './util/TestConstants.js'
import { mockLegacyTransaction, mockVersionedTransaction } from './mocks/Transaction.js'
import { type Chain } from '../utils/scaffold/index.js'
import { type Chain } from '@web3modal/scaffold-utils/solana'

describe('WalletConnectProvider specific tests', () => {
let provider = mockUniversalProvider()
Expand Down
2 changes: 1 addition & 1 deletion packages/base/adapters/solana/web3js/utils/chains.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConstantsUtil } from '@web3modal/common'
import type { Chain } from './scaffold/index.js'
import type { Chain } from '@web3modal/scaffold-utils/solana'

export const solana = {
chainId: '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@web3modal/polyfills'

import type { Chain, Metadata, Provider, ProviderType } from './scaffold/index.js'
import type { Chain, Metadata, Provider, ProviderType } from '@web3modal/scaffold-utils/solana'

declare global {
interface Navigator {
Expand Down
6 changes: 0 additions & 6 deletions packages/base/adapters/solana/web3js/utils/scaffold/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getWallets } from '@wallet-standard/app'
import { WalletStandardProvider } from '../providers/WalletStandardProvider.js'
import { isWalletAdapterCompatibleStandardWallet } from '@solana/wallet-adapter-base'
import type { Wallet } from '@wallet-standard/base'
import { SolStoreUtil } from './scaffold/SolanaStoreUtil.js'
import { SolStoreUtil } from '@web3modal/scaffold-utils/solana'

const { get, on } = getWallets()
let standardAdapters: WalletStandardProvider[] = wrapWalletsWithAdapters(get())
Expand Down
4 changes: 2 additions & 2 deletions packages/base/exports/react.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ConstantsUtil } from '@web3modal/scaffold-utils'
import { getWeb3Modal } from '@web3modal/scaffold-react'
import { AppKit } from '../src/client.js'
import type { AppKitOptions } from '../utils/TypesUtil.js'
import { getWeb3Modal } from '../utils/library/react/index.js'

// -- Views ------------------------------------------------------------
export * from '@web3modal/scaffold-ui'

// -- Hooks ------------------------------------------------------------
export * from '@web3modal/scaffold-react'
export * from '../utils/library/react/index.js'

// -- Utils & Other -----------------------------------------------------
export type * from '@web3modal/core'
Expand Down
4 changes: 2 additions & 2 deletions packages/base/exports/vue.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ConstantsUtil } from '@web3modal/scaffold-utils'
import { getWeb3Modal } from '@web3modal/scaffold-vue'
import { AppKit } from '../src/client.js'
import type { AppKitOptions } from '../utils/TypesUtil.js'
import { getWeb3Modal } from '../utils/library/vue/index.js'

// -- Views ------------------------------------------------------------
export * from '@web3modal/scaffold-ui'

// -- Hooks ------------------------------------------------------------
export * from '@web3modal/scaffold-vue'
export * from '../utils/library/vue/index.js'

// -- Utils & Other -----------------------------------------------------
export type * from '@web3modal/core'
Expand Down
19 changes: 15 additions & 4 deletions packages/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@
"types": "./dist/types/adapters/solana/web3js/index.d.ts",
"import": "./dist/esm/adapters/solana/web3js/index.js",
"default": "./dist/esm/adapters/solana/web3js/index.js"
},
"./utils/library/react": {
"types": "./dist/types/utils/library/react/index.d.ts",
"import": "./dist/esm/utils/library/react/index.js",
"default": "./dist/esm/utils/library/react/index.js"
},
"./utils/library/vue": {
"types": "./dist/types/utils/library/vue/index.d.ts",
"import": "./dist/esm/utils/library/vue/index.js",
"default": "./dist/esm/utils/library/vue/index.js"
}
},
"scripts": {
Expand Down Expand Up @@ -67,11 +77,8 @@
"@web3modal/common": "workspace:*",
"@web3modal/core": "workspace:*",
"@web3modal/polyfills": "workspace:*",
"@web3modal/scaffold": "workspace:*",
"@web3modal/scaffold-react": "workspace:*",
"@web3modal/scaffold-ui": "workspace:*",
"@web3modal/scaffold-utils": "workspace:*",
"@web3modal/scaffold-vue": "workspace:*",
"@web3modal/siwe": "workspace:*",
"@web3modal/ui": "workspace:*",
"@web3modal/wallet": "workspace:*",
Expand All @@ -90,9 +97,13 @@
"devDependencies": {
"@types/bn.js": "5.1.5",
"@vitest/coverage-v8": "2.0.5",
"@vue/runtime-core": "3.4.3",
"@types/react": "18.2.0",
"@types/react-dom": "18.2.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"vitest": "2.0.3"
"vitest": "2.0.3",
"vue": "3.4.3"
},
"keywords": [
"web3",
Expand Down
Loading

0 comments on commit d9e6bd2

Please sign in to comment.