Skip to content

Commit

Permalink
feat: unify connection events (#1929)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomiir authored Feb 29, 2024
1 parent d612339 commit b77ac55
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 20 deletions.
12 changes: 3 additions & 9 deletions packages/core/src/utils/TypeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ export interface LinkingRecord {

export type ProjectId = string

export type Platform =
| 'mobile'
| 'desktop'
| 'browser'
| 'web'
| 'qrcode'
| 'unsupported'
| 'external'
export type Platform = 'mobile' | 'desktop' | 'browser' | 'web' | 'qrcode' | 'unsupported'

export type ConnectorType = 'EXTERNAL' | 'WALLET_CONNECT' | 'INJECTED' | 'ANNOUNCED' | 'EMAIL'

Expand Down Expand Up @@ -216,7 +209,8 @@ export type Event =
type: 'track'
event: 'CONNECT_SUCCESS'
properties: {
method: 'qrcode' | 'mobile' | 'external' | 'browser' | 'email'
method: 'qrcode' | 'mobile' | 'browser' | 'email'
name: string
}
}
| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class W3mConnectingWcBrowser extends W3mConnectingWidget {
EventsController.sendEvent({
type: 'track',
event: 'CONNECT_SUCCESS',
properties: { method: 'browser' }
properties: { method: 'browser', name: this.wallet?.name || 'Unknown' }
})
} catch (error) {
EventsController.sendEvent({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BaseError, ConnectorType, Platform } from '@web3modal/core'
import type { BaseError } from '@web3modal/core'
import {
ConnectionController,
EventsController,
Expand All @@ -10,24 +10,20 @@ import {
import { customElement } from '@web3modal/ui'
import { W3mConnectingWidget } from '../../utils/w3m-connecting-widget/index.js'

const platformMap = {
INJECTED: 'browser',
ANNOUNCED: 'browser'
} as Record<ConnectorType, Platform>

@customElement('w3m-connecting-external-view')
export class W3mConnectingExternalView extends W3mConnectingWidget {
public constructor() {
super()
if (!this.connector) {
throw new Error('w3m-connecting-view: No connector provided')
}

EventsController.sendEvent({
type: 'track',
event: 'SELECT_WALLET',
properties: {
name: this.connector.name ?? 'Unknown',
platform: platformMap[this.connector.type] ?? 'external'
platform: 'browser'
}
})
this.onConnect = this.onConnectProxy.bind(this)
Expand All @@ -54,7 +50,7 @@ export class W3mConnectingExternalView extends W3mConnectingWidget {
EventsController.sendEvent({
type: 'track',
event: 'CONNECT_SUCCESS',
properties: { method: 'external' }
properties: { method: 'browser', name: this.connector.name || 'Unknown' }
})
}
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion packages/scaffold/src/views/w3m-connecting-wc-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ export class W3mConnectingWcView extends LitElement {
type: 'track',
event: 'CONNECT_SUCCESS',
properties: {
method: wcLinking ? 'mobile' : 'qrcode'
method: wcLinking ? 'mobile' : 'qrcode',
name: this.wallet?.name || 'Unknown'
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class W3mEmailVerifyOtpView extends W3mEmailOtpWidget {
EventsController.sendEvent({
type: 'track',
event: 'CONNECT_SUCCESS',
properties: { method: 'email' }
properties: { method: 'email', name: this.emailConnector.name || 'Unknown' }
})
}
} catch (error) {
Expand Down

0 comments on commit b77ac55

Please sign in to comment.