Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion packages/appkit/exports/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const PACKAGE_VERSION = '1.8.11'
export const PACKAGE_VERSION = '1.8.12'
2 changes: 1 addition & 1 deletion packages/appkit/src/client/appkit-base-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ export abstract class AppKitBaseClient {
name: connector.info?.name || connector.name || 'Unknown',
reconnect: true,
view: RouterController.state.view,
walletRank: undefined
walletRank: connector?.explorerWallet?.order
}
})
} else {
Expand Down
107 changes: 28 additions & 79 deletions packages/appkit/tests/client/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
syncConnectedWalletInfoSpy = vi.spyOn(appKit as any, 'syncConnectedWalletInfo')
})

it('should call syncConnectedWalletInfo when using connectExternal', async () => {
it('should call following methods when connected with connectExternal', async () => {
vi.spyOn(mockEvmAdapter, 'connect').mockResolvedValue({
address: '0x123',
chainId: '1',
Expand All @@ -240,18 +240,23 @@
vi.spyOn(mockEvmAdapter, 'getAccounts').mockResolvedValue({
accounts: [{ namespace: 'eip155', address: '0x123', type: 'eoa' }]
})
})
it('should call sync connected wallet info when calling connectExternal', async () => {
vi.spyOn(mockEvmAdapter, 'connect').mockResolvedValue({
address: '0x123',
chainId: '1',
provider: {} as any,
id: 'test-connector',
type: 'INJECTED'
})
vi.spyOn(mockEvmAdapter, 'getAccounts').mockResolvedValue({
accounts: [{ namespace: 'eip155', address: '0x123', type: 'eoa' }]
vi.spyOn(EventsController, 'sendEvent').mockImplementation(() => {})
vi.spyOn(ConnectorController, 'state', 'get').mockReturnValue({
...ConnectorController.state,
allConnectors: [
{
id: 'test-connector',
name: 'Test Connector',
chain: 'eip155',
type: 'INJECTED',
explorerWallet: { order: 60, id: 'test-wallet', name: 'Test Wallet' }
}
]
})
const removeDisconnectedConnectorIdSpy = vi.spyOn(
StorageUtil,
'removeDisconnectedConnectorId'
)

await (appKit as any).connectionControllerClient.connectExternal({
id: 'test-connector',
Expand All @@ -262,28 +267,18 @@
})

expect(syncConnectedWalletInfoSpy).toHaveBeenCalledWith('eip155')
})

it('should call sync connected wallet info when calling connectExternal', async () => {
vi.spyOn(mockEvmAdapter, 'connect').mockResolvedValue({
address: '0x123',
chainId: '1',
provider: {} as any,
id: 'test-connector',
type: 'INJECTED'
})
vi.spyOn(mockEvmAdapter, 'getAccounts').mockResolvedValue({
accounts: [{ namespace: 'eip155', address: '0x123', type: 'eoa' }]
})

await (appKit as any).connectionControllerClient.connectExternal({
id: 'test-connector',
info: { name: 'Test Connector' },
type: 'INJECTED',
provider: {} as any,
chain: 'eip155'
expect(EventsController.sendEvent).toHaveBeenCalledWith({

Check failure on line 270 in packages/appkit/tests/client/connection.test.ts

View workflow job for this annotation

GitHub Actions / test

tests/client/connection.test.ts > syncConnectedWalletInfo > should be called on connection methods > should call following methods when connected with connectExternal

AssertionError: expected "sendEvent" to be called with arguments: [ { type: 'track', …(2) } ] Received: Number of calls: 0 ❯ tests/client/connection.test.ts:270:42
type: 'track',
event: 'CONNECT_SUCCESS',
properties: {
method: 'browser',
name: 'Test Connector',
view: 'Connect',
walletRank: 60
}
})

expect(syncConnectedWalletInfoSpy).toHaveBeenCalledWith('eip155')
expect(removeDisconnectedConnectorIdSpy).toHaveBeenCalledWith('test-connector', 'eip155')
expect(syncConnectedWalletInfoSpy).toHaveBeenCalledWith('eip155')
})

Expand Down Expand Up @@ -315,52 +310,6 @@
expect(syncConnectedWalletInfoSpy).toHaveBeenCalledWith('eip155')
})

it('should call removeDisconnectedConnectorId when using connectExternal', async () => {
const removeDisconnectedConnectorIdSpy = vi.spyOn(
StorageUtil,
'removeDisconnectedConnectorId'
)
vi.spyOn(mockEvmAdapter, 'connect').mockResolvedValue({
address: '0x123',
chainId: '1',
provider: {} as any,
id: 'test-connector',
type: 'INJECTED'
})

await (appKit as any).connectionControllerClient.connectExternal({
id: 'test-connector',
info: { name: 'Test Connector' },
type: 'INJECTED',
provider: {} as any,
chain: 'eip155'
})

expect(removeDisconnectedConnectorIdSpy).toHaveBeenCalledWith('test-connector', 'eip155')
})

it('should call syncConnectedWalletInfo when using reconnectExternal', async () => {
vi.spyOn(appKit as any, 'getAdapter').mockReturnValueOnce({
...mockEvmAdapter,
reconnect: vi.fn().mockResolvedValue({
address: '0x123',
chainId: '1',
provider: {} as any,
id: 'test-connector',
type: 'INJECTED'
})
})

await (appKit as any).connectionControllerClient.reconnectExternal({
id: 'test-connector',
info: { name: 'Test Connector' },
type: 'INJECTED',
provider: {} as any
})

expect(syncConnectedWalletInfoSpy).toHaveBeenCalledWith('eip155')
})

it('should call syncConnectedWalletInfo when using connectWalletConnect', async () => {
vi.spyOn(mockEvmAdapter, 'connectWalletConnect').mockResolvedValue({
clientId: 'test-client'
Expand Down
1 change: 1 addition & 0 deletions packages/controllers/src/controllers/ApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export const ApiController = {
const { data } = await ApiController.fetchWallets(params)

state.explorerWallets = data
ConnectorController.extendConnectorsWithExplorerWallets(data)

const caipNetworkIds = ChainController.getRequestedCaipNetworkIds().join(',')
state.explorerFilteredWallets = data.filter(wallet =>
Expand Down
13 changes: 13 additions & 0 deletions packages/controllers/src/controllers/ConnectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,19 @@
ChainController.setActiveNamespace(chain)
}

const connector = ConnectorController.state.allConnectors.find(c => c.id === options?.id)
const connectSuccessEventMethod = options.type === 'AUTH' ? 'email' : 'browser'
EventsController.sendEvent({
type: 'track',
event: 'CONNECT_SUCCESS',
properties: {
method: connectSuccessEventMethod,
name: connector?.name || 'Unknown',
view: RouterController.state.view,
walletRank: connector?.explorerWallet?.order
}
})

return connectData
},

Expand Down Expand Up @@ -290,8 +303,8 @@
await authConnector.provider.setPreferredAccount(accountType)
StorageUtil.setPreferredAccountTypes(
Object.entries(ChainController.state.chains).reduce((acc, [key, _]) => {
const namespace = key as ChainNamespace

Check warning on line 306 in packages/controllers/src/controllers/ConnectionController.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

'namespace' is already declared in the upper scope on line 291 column 5
const accountType = getPreferredAccountType(namespace)

Check warning on line 307 in packages/controllers/src/controllers/ConnectionController.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

'accountType' is already declared in the upper scope on line 290 column 5
if (accountType !== undefined) {
;(acc as Record<ChainNamespace, string>)[namespace] = accountType
}
Expand Down
17 changes: 17 additions & 0 deletions packages/controllers/src/controllers/ConnectorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,23 @@ const controller = {

resetConnectorIds() {
state.activeConnectorIds = { ...defaultActiveConnectors }
},

extendConnectorsWithExplorerWallets(explorerWallets: WcWallet[]) {
state.allConnectors.forEach(connector => {
const explorerWallet = explorerWallets.find(
wallet =>
wallet.id === connector.id || (wallet.rdns && wallet.rdns === connector.info?.rdns)
)

if (explorerWallet) {
connector.explorerWallet = explorerWallet
}
})

const enabledNamespaces = ConnectorController.getEnabledNamespaces()
const enabledConnectors = ConnectorController.getEnabledConnectors(enabledNamespaces)
state.connectors = ConnectorController.mergeMultiChainConnectors(enabledConnectors)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,6 @@ export class W3mConnectingWcBrowser extends W3mConnectingWidget {
}

ModalController.close()

EventsController.sendEvent({
type: 'track',
event: 'CONNECT_SUCCESS',
properties: {
method: 'browser',
name: this.wallet?.name || 'Unknown',
view: RouterController.state.view,
walletRank: this.wallet?.order
}
})
} catch (error) {
const isUserRejectedRequestError =
error instanceof AppKitError &&
Expand Down
43 changes: 1 addition & 42 deletions packages/scaffold-ui/src/partials/w3m-connector-list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,42 +98,6 @@ export class W3mConnectorList extends LitElement {
}

// -- Private ------------------------------------------ //
private mapConnectorsToExplorerWallets(
connectors: ConnectorWithProviders[],
explorerWallets: WcWallet[]
): ConnectorWithProviders[] {
return connectors.map(connector => {
if (connector.type === 'MULTI_CHAIN' && connector.connectors) {
const connectorIds = connector.connectors.map(c => c.id)
const connectorNames = connector.connectors.map(c => c.name)
const connectorRdns = connector.connectors.map(c => c.info?.rdns)

const explorerWallet = explorerWallets?.find(
wallet =>
connectorIds.includes(wallet.id) ||
connectorNames.includes(wallet.name) ||
(wallet.rdns &&
(connectorRdns.includes(wallet.rdns) || connectorIds.includes(wallet.rdns)))
)

connector.explorerWallet = explorerWallet ?? connector.explorerWallet

return connector
}

const explorerWallet = explorerWallets?.find(
wallet =>
wallet.id === connector.id ||
wallet.rdns === connector.info?.rdns ||
wallet.name === connector.name
)

connector.explorerWallet = explorerWallet ?? connector.explorerWallet

return connector
})
}

private processConnectorsByType(
connectors: ConnectorWithProviders[],
shouldFilter = true
Expand All @@ -144,13 +108,8 @@ export class W3mConnectorList extends LitElement {
}

private connectorListTemplate() {
const mappedConnectors: ConnectorWithProviders[] = this.mapConnectorsToExplorerWallets(
this.connectors,
this.explorerWallets ?? []
)

const byType = ConnectorUtil.getConnectorsByType(
mappedConnectors,
this.connectors,
this.recommended,
this.featured
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,6 @@ export class W3mConnectingExternalView extends W3mConnectingWidget {
*/
if (this.connector.id !== CommonConstantsUtil.CONNECTOR_ID.COINBASE_SDK || !this.error) {
await ConnectionController.connectExternal(this.connector, this.connector.chain)

EventsController.sendEvent({
type: 'track',
event: 'CONNECT_SUCCESS',
properties: {
method: 'browser',
name: this.connector.name || 'Unknown',
view: RouterController.state.view,
walletRank: this.wallet?.order
}
})
}
}
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,9 @@ export class W3mEmailVerifyOtpView extends W3mEmailOtpWidget {
if (namespace) {
await ConnectionController.connectExternal(this.authConnector, namespace)
} else {
throw new Error('Active chain is not set on ChainControll')
throw new Error('Active chain is not set on ChainController')
}

EventsController.sendEvent({
type: 'track',
event: 'CONNECT_SUCCESS',
properties: {
method: 'email',
name: this.authConnector.name || 'Unknown',
view: RouterController.state.view,
walletRank: undefined
}
})

if (OptionsController.state.remoteFeatures?.emailCapture) {
// Email capture is enabled, SIWXUtil will handle the data capture
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ describe('W3mConnectingWcBrowser', () => {
await fixture(html`<w3m-connecting-wc-browser></w3m-connecting-wc-browser>`)

expect(ConnectionController.connectExternal).toHaveBeenCalledWith(CONNECTOR, CONNECTOR.chain)
expect(EventsController.sendEvent).toHaveBeenCalledWith({
type: 'track',
event: 'CONNECT_SUCCESS',
properties: { method: 'browser', name: CONNECTOR.name }
})
})

it('it should throw an error if trying to connect when a connector does not exist', async () => {
Expand Down
Loading