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

feat: unify connection events #1929

Merged
merged 7 commits into from
Feb 29, 2024
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
3 changes: 2 additions & 1 deletion packages/core/tests/controllers/AssetController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ describe('AssetController', () => {
walletImages: {},
networkImages: {},
connectorImages: {},
tokenImages: {}
tokenImages: {},
currencyImages: {}
tomiir marked this conversation as resolved.
Show resolved Hide resolved
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ describe('TransactionsController', () => {
transactionsByYear: {},
loading: false,
empty: false,
next: undefined
next: undefined,
coinbaseTransactions: []
tomiir marked this conversation as resolved.
Show resolved Hide resolved
})
})
})
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' }
})
tomiir marked this conversation as resolved.
Show resolved Hide resolved
}
} 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