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

fix: appkit basic multichain #3658

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c135501
refactor: set base class for wallet connect connector
zoruka Jan 10, 2025
af4af5b
fix: solana adapter tests
zoruka Jan 13, 2025
68cf607
fix: universal provider adapter tests
zoruka Jan 13, 2025
1d99092
fix: bitcoin tests
zoruka Jan 13, 2025
c07493e
Merge branch 'main' of github.com:WalletConnect/web3modal into refact…
zoruka Jan 13, 2025
28f8f19
fix: broken typing on ci
zoruka Jan 13, 2025
e526828
fix: use correct chains
zoruka Jan 13, 2025
dd6b6b8
fix: formating issue
zoruka Jan 13, 2025
346b87a
test: add tests for WalletConnectConnector
zoruka Jan 13, 2025
eca29fb
fix: formating issue
zoruka Jan 13, 2025
bfd379c
fix: keep useInjectedUniversalProvider flag usage for upa
zoruka Jan 13, 2025
8000e6a
Merge branch 'main' into refactor/clean-up-wc-connector
zoruka Jan 13, 2025
63b216d
chore: add changeset
zoruka Jan 13, 2025
b1d5482
fix: missing close call
zoruka Jan 13, 2025
d78b226
fix: missing onUri for authenticate
zoruka Jan 13, 2025
141b7c8
Merge branch 'main' into refactor/clean-up-wc-connector
zoruka Jan 14, 2025
c023409
fix: email and socials displayede when no adapters present
tomiir Jan 15, 2025
5109c43
fix: issue where separatosrs showing uo when there were no adapters. …
tomiir Jan 15, 2025
b79c17b
chore: add changesets
tomiir Jan 15, 2025
85abdfe
chore: rollback labs config csp
tomiir Jan 15, 2025
9da7767
chore: remove single test
tomiir Jan 15, 2025
d68abd6
chore: remove logs
tomiir Jan 15, 2025
89b1b92
chore: remove unused import
tomiir Jan 15, 2025
6c0ed0b
Merge branch 'main' into fix/appkit-basic
tomiir Jan 15, 2025
084f069
Merge branch 'main' into fix/appkit-basic
tomiir Jan 15, 2025
e35dfcf
Merge branch 'main' into fix/appkit-basic
tomiir Jan 15, 2025
7a48e80
Merge branch 'fix/appkit-basic' of github.com:reown-com/appkit into f…
tomiir Jan 15, 2025
dfb8ae6
Merge branch 'main' of github.com:WalletConnect/web3modal into refact…
zoruka Jan 15, 2025
f2d779f
chore: refactor switchnetwork logic to use adapters abstraction
tomiir Jan 15, 2025
5637eb5
Merge branch 'refactor/clean-up-wc-connector' of github.com:reown-com…
tomiir Jan 15, 2025
9340936
fix: wc network switching
tomiir Jan 15, 2025
922ca6c
chore: remove logs
tomiir Jan 15, 2025
27f125b
Merge branch 'main' of github.com:reown-com/appkit into fix/multichai…
tomiir Jan 15, 2025
d6dccf9
chore: remove log add catch
tomiir Jan 15, 2025
86c279a
chore: fix constant typing issue
tomiir Jan 15, 2025
516eb2f
chore: solve merge issues on test file
tomiir Jan 15, 2025
6c8adb6
Merge branch 'main' into fix/multichain-network-switch
tomiir Jan 20, 2025
4a2e62c
Merge branch 'main' into fix/multichain-network-switch
tomiir Jan 20, 2025
014f221
Merge branch 'main' into fix/multichain-network-switch
tomiir Jan 28, 2025
e36bf2c
Merge branch 'main' into fix/multichain-network-switch
tomiir Jan 29, 2025
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
4 changes: 3 additions & 1 deletion packages/adapters/wagmi/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ export class WagmiAdapter extends AdapterBlueprint {
})
}

if (accountData.chainId !== prevAccountData?.chainId) {
// When it receives a non-evm chainId we shouldn't trigger this
if (accountData.chainId !== prevAccountData?.chainId && !isNaN(accountData.chainId)) {
this.emit('switchNetwork', {
address: accountData.address,
chainId: accountData.chainId
Expand Down Expand Up @@ -604,6 +605,7 @@ export class WagmiAdapter extends AdapterBlueprint {
}

public override async switchNetwork(params: AdapterBlueprint.SwitchNetworkParams) {
await super.switchNetwork(params)
tomiir marked this conversation as resolved.
Show resolved Hide resolved
await switchChain(this.wagmiConfig, { chainId: params.caipNetwork.id as number })
}

Expand Down
97 changes: 40 additions & 57 deletions packages/appkit/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import {
ConstantsUtil as UtilConstantsUtil
} from '@reown/appkit-utils'
import {
AUTH_ENABLED_CHAINS,
W3mFrameHelpers,
W3mFrameProvider,
W3mFrameRpcConstants,
Expand Down Expand Up @@ -1030,61 +1031,33 @@ export class AppKit {
if (!caipNetwork) {
return
}
if (
AccountController.state.address &&
caipNetwork.chainNamespace === ChainController.state.activeChain
) {
const adapter = this.getAdapter(ChainController.state.activeChain)
const provider = ProviderUtil.getProvider(ChainController.state.activeChain)
const providerType = ProviderUtil.state.providerIds[ChainController.state.activeChain]

const newNamespace = caipNetwork.chainNamespace
const adapter = this.getAdapter(newNamespace)
const provider = ProviderUtil.getProvider(newNamespace)
const providerType = ProviderUtil.state.providerIds[newNamespace]
const connectorId = StorageUtil.getConnectedConnectorId(newNamespace)
try {
await adapter?.switchNetwork({ caipNetwork, provider, providerType })
this.setCaipNetwork(caipNetwork)
await this.syncAccount({
address: AccountController.state.address,
chainId: caipNetwork.id,
chainNamespace: caipNetwork.chainNamespace
})
} else if (AccountController.state.address) {
const providerType =
ProviderUtil.state.providerIds[ChainController.state.activeChain as ChainNamespace]

if (providerType === UtilConstantsUtil.CONNECTOR_TYPE_AUTH) {
try {
ChainController.state.activeChain = caipNetwork.chainNamespace
await this.connectionControllerClient?.connectExternal?.({
id: ConstantsUtil.CONNECTOR_ID.AUTH,
provider: this.authProvider,
chain: caipNetwork.chainNamespace,
chainId: caipNetwork.id,
type: UtilConstantsUtil.CONNECTOR_TYPE_AUTH as ConnectorType,
caipNetwork
})
this.setCaipNetwork(caipNetwork)
} catch (error) {
const adapter = this.getAdapter(caipNetwork.chainNamespace as ChainNamespace)
await adapter?.switchNetwork({
caipNetwork,
provider: this.authProvider,
providerType
})
}
} else if (providerType === 'WALLET_CONNECT') {
this.setCaipNetwork(caipNetwork)
this.syncWalletConnectAccount()
} else {
this.setCaipNetwork(caipNetwork)
const address = this.getAddressByChainNamespace(caipNetwork.chainNamespace)

if (connectorId) {
const accounts = await adapter?.getAccounts({
namespace: newNamespace,
id: connectorId
})

const address = accounts?.accounts?.[0]?.address
if (address) {
this.syncAccount({
await this.syncAccount({
address,
chainId: caipNetwork.id,
chainNamespace: caipNetwork.chainNamespace
})
}
}
} else {
this.setCaipNetwork(caipNetwork)
} catch (error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we remove (error) part ?

this.setUnsupportedNetwork(caipNetwork.id)
}
},
// eslint-disable-next-line @typescript-eslint/require-await
Expand Down Expand Up @@ -1159,15 +1132,7 @@ export class AppKit {
}
}
})
provider.onNotConnected(() => {
const namespace = ChainController.state.activeChain as ChainNamespace
const connectorId = StorageUtil.getConnectedConnectorId(namespace)
const isConnectedWithAuth = connectorId === ConstantsUtil.CONNECTOR_ID.AUTH
if (isConnectedWithAuth) {
this.setCaipAddress(undefined, namespace)
this.setLoading(false)
}
})

provider.onConnect(async user => {
const namespace = ChainController.state.activeChain as ChainNamespace

Expand Down Expand Up @@ -1267,15 +1232,26 @@ export class AppKit {

if (namespace) {
if (isConnected && this.connectionControllerClient?.connectExternal) {
await this.connectionControllerClient?.connectExternal({
const connector = {
id: ConstantsUtil.CONNECTOR_ID.AUTH,
info: { name: ConstantsUtil.CONNECTOR_ID.AUTH },
type: UtilConstantsUtil.CONNECTOR_TYPE_AUTH as ConnectorType,
provider,
chainId: ChainController.state.activeCaipNetwork?.id,
chain: namespace
}
await this.connectionControllerClient?.connectExternal(connector)

// Connecting to one namespace connects to all
AUTH_ENABLED_CHAINS.forEach(chain => {
this.setStatus('connected', chain)
this.syncProvider({
provider,
chainNamespace: connector.chain,
type: connector.type,
id: connector.id
})
})
this.setStatus('connected', namespace)
} else if (
StorageUtil.getConnectedConnectorId(namespace) === ConstantsUtil.CONNECTOR_ID.AUTH
) {
Expand Down Expand Up @@ -1708,7 +1684,14 @@ export class AppKit {
n => n.caipNetworkId === `${chainNamespace}:${chainId}`
)

if (chainNamespace !== ConstantsUtil.CHAIN.EVM || activeCaipNetwork?.testnet) {
if (activeCaipNetwork?.testnet) {
return
}

if (chainNamespace !== ConstantsUtil.CHAIN.EVM) {
this.setProfileName(null, chainNamespace)
this.setProfileImage(null, chainNamespace)

return
}
try {
Expand Down
3 changes: 2 additions & 1 deletion packages/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export { W3mFrameSchema } from './src/W3mFrameSchema.js'
export {
W3mFrameConstants,
W3mFrameRpcConstants,
type W3mFrameConstantValue
type W3mFrameConstantValue,
AUTH_ENABLED_CHAINS
} from './src/W3mFrameConstants.js'
export { W3mFrameStorage } from './src/W3mFrameStorage.js'
export type { W3mFrameTypes } from './src/W3mFrameTypes.js'
2 changes: 2 additions & 0 deletions packages/wallet/src/W3mFrameConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const DEFAULT_LOG_LEVEL = process.env['NEXT_PUBLIC_DEFAULT_LOG_LEVEL'] ||

export const SECURE_SITE_SDK_VERSION = process.env['NEXT_PUBLIC_SECURE_SITE_SDK_VERSION'] || 3

export const AUTH_ENABLED_CHAINS = ['eip155', 'solana'] as const

export const W3mFrameConstants = {
APP_EVENT_KEY: '@w3m-app/',
FRAME_EVENT_KEY: '@w3m-frame/',
Expand Down
Loading