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

chore: serialize name and icon for wallet info #3493

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions .changeset/forty-cheetahs-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@reown/appkit': patch
'@reown/appkit-core': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit-utils': patch
'@reown/appkit-cdn': patch
'@reown/appkit-cli': patch
'@reown/appkit-common': patch
'@reown/appkit-experimental': patch
'@reown/appkit-polyfills': patch
'@reown/appkit-scaffold-ui': patch
'@reown/appkit-siwe': patch
'@reown/appkit-siwx': patch
'@reown/appkit-ui': patch
'@reown/appkit-wallet': patch
'@reown/appkit-wallet-button': patch
---

Fixes issue where walletInfo would be undefined or empty
8 changes: 4 additions & 4 deletions packages/adapters/ethers/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,17 @@ export class EthersAdapter extends AdapterBlueprint {
connectors.forEach(connector => {
const key = connector === 'coinbase' ? 'coinbaseWalletSDK' : connector

const injectedConnector = connector === ConstantsUtil.INJECTED_CONNECTOR_ID
const isInjectedConnector = connector === ConstantsUtil.INJECTED_CONNECTOR_ID

if (this.namespace) {
this.addConnector({
id: key,
explorerId: PresetsUtil.ConnectorExplorerIds[key],
imageUrl: options?.connectorImages?.[key],
name: PresetsUtil.ConnectorNamesMap[key],
name: PresetsUtil.ConnectorNamesMap[key] || key,
imageId: PresetsUtil.ConnectorImageIds[key],
type: PresetsUtil.ConnectorTypesMap[key] ?? 'EXTERNAL',
info: injectedConnector ? undefined : { rdns: key },
info: isInjectedConnector ? undefined : { rdns: key },
chain: this.namespace,
chains: [],
provider: this.ethersConfig?.[connector as keyof ProviderType] as Provider
Expand Down Expand Up @@ -308,7 +308,7 @@ export class EthersAdapter extends AdapterBlueprint {
id: info?.rdns || '',
type,
imageUrl: info?.icon,
name: info?.name,
name: info?.name || 'Unknown',
provider,
info,
chain: this.namespace,
Expand Down
8 changes: 4 additions & 4 deletions packages/adapters/ethers5/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,17 @@ export class Ethers5Adapter extends AdapterBlueprint {
connectors.forEach(connector => {
const key = connector === 'coinbase' ? 'coinbaseWalletSDK' : connector

const injectedConnector = connector === ConstantsUtil.INJECTED_CONNECTOR_ID
const isInjectedConnector = connector === ConstantsUtil.INJECTED_CONNECTOR_ID

if (this.namespace) {
this.addConnector({
id: key,
explorerId: PresetsUtil.ConnectorExplorerIds[key],
imageUrl: options?.connectorImages?.[key],
name: PresetsUtil.ConnectorNamesMap[key],
name: PresetsUtil.ConnectorNamesMap[key] || key,
imageId: PresetsUtil.ConnectorImageIds[key],
type: PresetsUtil.ConnectorTypesMap[key] ?? 'EXTERNAL',
info: injectedConnector ? undefined : { rdns: key },
info: isInjectedConnector ? undefined : { rdns: key },
chain: this.namespace,
chains: [],
provider: this.ethersConfig?.[connector as keyof ProviderType] as Provider
Expand Down Expand Up @@ -309,7 +309,7 @@ export class Ethers5Adapter extends AdapterBlueprint {
id: info?.rdns || '',
type,
imageUrl: info?.icon,
name: info?.name,
name: info?.name || '',
provider,
info,
chain: this.namespace,
Expand Down
1 change: 1 addition & 0 deletions packages/adapters/solana/src/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const mockCaipNetworks = CaipNetworksUtil.extendCaipNetworks(mockNetworks, {

const mockWalletConnectConnector = {
id: 'walletconnect',
name: 'WalletConnect',
provider: mockWalletConnectProvider,
type: 'WALLET_CONNECT' as ConnectorType,
chains: mockNetworks,
Expand Down
18 changes: 8 additions & 10 deletions packages/appkit/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export class AppKit {
})
}

public subscribeWalletInfo(callback: (newState: ConnectedWalletInfo) => void) {
public subscribeWalletInfo(callback: (newState?: ConnectedWalletInfo) => void) {
return AccountController.subscribeKey('connectedWalletInfo', callback)
}

Expand Down Expand Up @@ -1599,17 +1599,15 @@ export class AppKit {
private syncConnectedWalletInfo(chainNamespace: ChainNamespace) {
const currentActiveWallet = StorageUtil.getConnectedConnector()
const providerType = ProviderUtil.state.providerIds[chainNamespace]

if (
providerType === UtilConstantsUtil.CONNECTOR_TYPE_ANNOUNCED ||
providerType === UtilConstantsUtil.CONNECTOR_TYPE_INJECTED
) {
if (currentActiveWallet) {
const connector = this.getConnectors().find(c => c.id === currentActiveWallet)

if (connector?.info) {
this.setConnectedWalletInfo({ ...connector.info }, chainNamespace)
}
const connector = this.getConnectors().find(c => c.id === currentActiveWallet)
if (connector) {
const { info, name, imageUrl } = connector
const icon = imageUrl || this.getConnectorImage(connector)
this.setConnectedWalletInfo({ name, icon, ...info }, chainNamespace)
}
} else if (providerType === UtilConstantsUtil.CONNECTOR_TYPE_WALLET_CONNECT) {
const provider = ProviderUtil.getProvider(chainNamespace)
Expand Down Expand Up @@ -1830,14 +1828,14 @@ export class AppKit {
}

private createAuthProvider() {
const emailEnabled =
const isEmailEnabled =
this.options?.features?.email === undefined
? CoreConstantsUtil.DEFAULT_FEATURES.email
: this.options?.features?.email
const socialsEnabled = this.options?.features?.socials
? this.options?.features?.socials?.length > 0
: CoreConstantsUtil.DEFAULT_FEATURES.socials
if (this.options?.projectId && (emailEnabled || socialsEnabled)) {
if (this.options?.projectId && (isEmailEnabled || socialsEnabled)) {
this.authProvider = W3mFrameProviderSingleton.getInstance({
projectId: this.options.projectId,
onTimeout: () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/appkit/src/tests/appkit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,12 @@ describe('Base', () => {

it('should get connector image', () => {
vi.mocked(AssetUtil.getConnectorImage).mockReturnValue('connector-image-url')
const result = appKit.getConnectorImage({ id: 'metamask', type: 'INJECTED', chain: 'eip155' })
const result = appKit.getConnectorImage({
id: 'metamask',
type: 'INJECTED',
chain: 'eip155',
name: 'Metamask'
})
expect(AssetUtil.getConnectorImage).toHaveBeenCalledWith({
id: 'metamask',
type: 'INJECTED',
Expand Down
9 changes: 4 additions & 5 deletions packages/core/src/controllers/ConnectorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,13 @@ export const ConnectorController = {

connectorsByNameMap.forEach(keyConnectors => {
const firstItem = keyConnectors[0]

const isAuthConnector = firstItem?.id === 'ID_AUTH'

if (keyConnectors.length > 1) {
if (keyConnectors.length > 1 && firstItem) {
mergedConnectors.push({
name: firstItem?.name,
imageUrl: firstItem?.imageUrl,
imageId: firstItem?.imageId,
name: firstItem.name,
imageUrl: firstItem.imageUrl,
imageId: firstItem.imageId,
connectors: [...keyConnectors],
type: isAuthConnector ? 'AUTH' : 'MULTI_CHAIN',
// These values are just placeholders, we don't use them in multi-chain connector select screen
Expand Down
14 changes: 6 additions & 8 deletions packages/core/src/utils/TypeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ export type CaipNetworkCoinbaseNetwork =
| 'OP Mainnet'
| 'Celo'

export type ConnectedWalletInfo =
| {
name?: string
icon?: string
[key: string]: unknown
}
| undefined
export type ConnectedWalletInfo = {
name: string
icon?: string
[key: string]: unknown
}

export interface LinkingRecord {
redirect: string
Expand Down Expand Up @@ -87,7 +85,7 @@ export type SocialProvider =
export type Connector = {
id: string
type: ConnectorType
name?: string
name: string
imageId?: string
explorerId?: string
imageUrl?: string
Expand Down
1 change: 1 addition & 0 deletions packages/core/tests/controllers/EnsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ describe('EnsController', () => {
provider: { getEmail: () => '[email protected]' } as unknown as W3mFrameProvider,
id: 'ID_AUTH',
type: 'AUTH',
name: 'AuthPovider',
chain: ConstantsUtil.CHAIN.EVM
})

Expand Down
7 changes: 6 additions & 1 deletion packages/core/tests/controllers/RouterController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@

it('should update state correctly on push() with data', () => {
RouterController.push('ConnectingExternal', {
connector: { id: 'test', type: 'WALLET_CONNECT', chain: ConstantsUtil.CHAIN.EVM }
connector: {
id: 'test',
name: 'wcConnector',
type: 'WALLET_CONNECT',
chain: ConstantsUtil.CHAIN.EVM
}
})
expect(RouterController.state).toEqual({

Check failure on line 79 in packages/core/tests/controllers/RouterController.test.ts

View workflow job for this annotation

GitHub Actions / test

tests/controllers/RouterController.test.ts > RouterController > should update state correctly on push() with data

AssertionError: expected { view: 'ConnectingExternal', …(3) } to deeply equal { view: 'ConnectingExternal', …(3) } - Expected + Received Object { "data": Object { "connector": Object { "chain": "eip155", "id": "test", + "name": "wcConnector", "type": "WALLET_CONNECT", }, }, "history": Array [ "Account", "Networks", "ConnectingExternal", ], "transactionStack": Array [], "view": "ConnectingExternal", } ❯ tests/controllers/RouterController.test.ts:79:36
view: 'ConnectingExternal',
history: ['Account', 'Networks', 'ConnectingExternal'],
data: {
Expand Down
5 changes: 5 additions & 0 deletions packages/scaffold-ui/test/WalletUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { WcWallet } from '@reown/appkit-core'
// Connectors
const mockMetamaskConnector = {
info: { rdns: 'io.metamask' },
name: 'Metamask',
id: '1',
explorerId: '1',
chain: 'eip155' as const,
Expand All @@ -19,20 +20,23 @@ const mockMetamaskConnector = {

const mockRainbowConnector = {
info: { rdns: 'io.rainbow' },
name: 'Rainbow',
id: '2',
explorerId: '2',
chain: 'eip155' as const,
type: 'ANNOUNCED' as const
}
const mockMetamaskMobileConnector = {
info: { rdns: 'io.metamask.mobile' },
name: 'Metamask',
id: '4',
explorerId: '4',
chain: 'eip155' as const,
type: 'ANNOUNCED' as const
}
const mockCoinbaseconnector = {
info: { rdns: 'io.coinbase' },
name: 'Coinbase',
id: '5',
explorerId: '5',
chain: 'eip155' as const,
Expand Down Expand Up @@ -202,6 +206,7 @@ describe('WalletUtil', () => {
{
type: 'ANNOUNCED' as const,
info: { rdns: 'io.someotherwallet' },
name: '',
id: '1233',
chain: 'eip155' as const
}
Expand Down
2 changes: 1 addition & 1 deletion packages/siwx/tests/configs/CloudAuthSIWX.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Issued At: 2024-12-05T16:02:32.905Z`)
const fetchSpy = vi.spyOn(global, 'fetch')

vi.spyOn(localStorage, 'getItem').mockReturnValueOnce('mock_nonce_token')
AccountController.state.connectedWalletInfo = {}
AccountController.state.connectedWalletInfo = undefined
vi.spyOn(AccountController.state, 'connectedWalletInfo', 'get').mockReturnValueOnce({
name: 'mock_wallet_name',
icon: 'mock_wallet_icon'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ describe('AppKitWalletButton', () => {
id: 'metamask',
explorerId: MetaMask.id,
type: 'ANNOUNCED',
chain: 'eip155'
chain: 'eip155',
name: 'MetaMask'
})

vi.spyOn(ConnectorController, 'getConnector').mockReturnValue({
Expand Down
Loading