Skip to content

Commit

Permalink
Merge branch 'V4' into chore/onramp-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomiir authored Feb 29, 2024
2 parents 9223cbb + b77ac55 commit 5149996
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 21 deletions.
9 changes: 8 additions & 1 deletion packages/core/src/controllers/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface NetworkControllerState {
caipNetwork?: CaipNetwork
requestedCaipNetworks?: CaipNetwork[]
approvedCaipNetworkIds?: CaipNetworkId[]
allowUnsupportedChain?: boolean
}

type StateKey = keyof NetworkControllerState
Expand Down Expand Up @@ -56,7 +57,9 @@ export const NetworkController = {
setCaipNetwork(caipNetwork: NetworkControllerState['caipNetwork']) {
state.caipNetwork = caipNetwork
PublicStateController.set({ selectedNetworkId: caipNetwork?.id })
this.checkIfSupportedNetwork()
if (!this.state.allowUnsupportedChain) {
this.checkIfSupportedNetwork()
}
},

setDefaultCaipNetwork(caipNetwork: NetworkControllerState['caipNetwork']) {
Expand All @@ -69,6 +72,10 @@ export const NetworkController = {
state.requestedCaipNetworks = requestedNetworks
},

setAllowUnsupportedChain(allowUnsupportedChain: NetworkControllerState['allowUnsupportedChain']) {
state.allowUnsupportedChain = allowUnsupportedChain
},

getRequestedCaipNetworks() {
const { approvedCaipNetworkIds, requestedCaipNetworks } = state

Expand Down
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
5 changes: 5 additions & 0 deletions packages/scaffold/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface LibraryOptions {
enableAnalytics?: OptionsControllerState['enableAnalytics']
metadata?: OptionsControllerState['metadata']
enableOnramp?: OptionsControllerState['enableOnramp']
allowUnsupportedChain?: NetworkControllerState['allowUnsupportedChain']
_sdkVersion: OptionsControllerState['sdkVersion']
}

Expand Down Expand Up @@ -236,6 +237,10 @@ export class Web3ModalScaffold {
if (options.enableOnramp) {
OptionsController.setOnrampEnabled(Boolean(options.enableOnramp))
}

if (options.allowUnsupportedChain) {
NetworkController.setAllowUnsupportedChain(options.allowUnsupportedChain)
}
}

private async initOrContinue() {
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 5149996

Please sign in to comment.