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: 5.0 missing events #2393

Merged
merged 17 commits into from
Jun 12, 2024
Merged
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
4 changes: 3 additions & 1 deletion apps/laboratory/tests/shared/utils/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export class Email {
}

getOtpCodeFromBody(body: string): string {
const match = body.match(OTP_CODE_REGEX)
const cleanedBody = body.replace(/https:\/\/s1\.designmodo\.com\/postcards\/[^\s]+\s?/gu, '')

const match = cleanedBody.match(OTP_CODE_REGEX)
if (match) {
// Remove empty space in OTP code 111 111
return match[0].replace(' ', '')
Expand Down
327 changes: 157 additions & 170 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/cdn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"main": "dist/wagmi.js",
"type": "module",
"files": [
"dist"
"dist",
"!tsconfig.tsbuildinfo"
],
"scripts": {
"build:clean": "rm -rf dist",
Expand Down
1 change: 0 additions & 1 deletion packages/cdn/tsconfig.tsbuildinfo

This file was deleted.

21 changes: 21 additions & 0 deletions packages/core/src/controllers/ConnectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import type {
WriteContractArgs
} from '../utils/TypeUtil.js'
import { TransactionsController } from './TransactionsController.js'
import { type W3mFrameTypes } from '@web3modal/wallet'
import { ModalController } from './ModalController.js'
import { ConnectorController } from './ConnectorController.js'
import { EventsController } from './EventsController.js'
import { NetworkController } from './NetworkController.js'

// -- Types --------------------------------------------- //
export interface ConnectExternalOptions {
Expand Down Expand Up @@ -98,6 +103,22 @@ export const ConnectionController = {
StorageUtil.setConnectedConnector(options.type)
},

async setPreferredAccountType(accountType: W3mFrameTypes.AccountType) {
ModalController.setLoading(true)
const authConnector = ConnectorController.getAuthConnector()
if (!authConnector) {
return
}
await authConnector?.provider.setPreferredAccount(accountType)
await this.reconnectExternal(authConnector)
ModalController.setLoading(false)
EventsController.sendEvent({
type: 'track',
event: 'SET_PREFERRED_ACCOUNT_TYPE',
properties: { accountType, network: NetworkController.state.caipNetwork?.id || '' }
})
},

async signMessage(message: string) {
return this._getClient().signMessage(message)
},
Expand Down
51 changes: 51 additions & 0 deletions packages/core/src/controllers/SendController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { AccountController } from './AccountController.js'
import { ConnectionController } from './ConnectionController.js'
import { SnackController } from './SnackController.js'
import { CoreHelperUtil } from '../utils/CoreHelperUtil.js'
import { EventsController } from './EventsController.js'
import { NetworkController } from './NetworkController.js'
import { W3mFrameRpcConstants } from '@web3modal/wallet'

// -- Types --------------------------------------------- //

Expand Down Expand Up @@ -91,6 +94,18 @@ export const SendController = {

sendToken() {
if (this.state.token?.address && this.state.sendTokenAmount && this.state.receiverAddress) {
EventsController.sendEvent({
type: 'track',
event: 'SEND_INITIATED',
properties: {
isSmartAccount:
AccountController.state.preferredAccountType ===
W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
token: this.state.token.address,
amount: this.state.sendTokenAmount,
network: NetworkController.state.caipNetwork?.id || ''
}
})
this.sendERC20Token({
receiverAddress: this.state.receiverAddress,
tokenAddress: this.state.token.address,
Expand All @@ -103,6 +118,18 @@ export const SendController = {
this.state.gasPrice &&
this.state.token?.quantity.decimals
) {
EventsController.sendEvent({
svenvoskamp marked this conversation as resolved.
Show resolved Hide resolved
type: 'track',
event: 'SEND_INITIATED',
properties: {
isSmartAccount:
AccountController.state.preferredAccountType ===
W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
token: this.state.token?.symbol,
amount: this.state.sendTokenAmount,
network: NetworkController.state.caipNetwork?.id || ''
}
})
this.sendNativeToken({
receiverAddress: this.state.receiverAddress,
sendTokenAmount: this.state.sendTokenAmount,
Expand Down Expand Up @@ -135,8 +162,32 @@ export const SendController = {
gasPrice: params.gasPrice
})
SnackController.showSuccess('Transaction started')
EventsController.sendEvent({
type: 'track',
event: 'SEND_SUCCESS',
properties: {
isSmartAccount:
AccountController.state.preferredAccountType ===
W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
token: this.state.token?.symbol || '',
amount: params.sendTokenAmount,
network: NetworkController.state.caipNetwork?.id || ''
}
})
this.resetSend()
} catch (error) {
EventsController.sendEvent({
type: 'track',
event: 'SEND_ERROR',
properties: {
isSmartAccount:
AccountController.state.preferredAccountType ===
W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
token: this.state.token?.symbol || '',
amount: params.sendTokenAmount,
network: NetworkController.state.caipNetwork?.id || ''
}
})
SnackController.showError('Something went wrong')
}
},
Expand Down
30 changes: 30 additions & 0 deletions packages/core/src/controllers/SwapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { CoreHelperUtil } from '../utils/CoreHelperUtil.js'
import { BlockchainApiController } from './BlockchainApiController.js'
import { OptionsController } from './OptionsController.js'
import { SwapCalculationUtil } from '../utils/SwapCalculationUtil.js'
import { EventsController } from './EventsController.js'
import { W3mFrameRpcConstants } from '@web3modal/wallet'

// -- Constants ---------------------------------------- //
export const INITIAL_GAS_LIMIT = 150000
Expand Down Expand Up @@ -721,6 +723,20 @@ export const SwapController = {

state.loadingTransaction = false
SnackController.showSuccess(snackbarSuccessMessage)
EventsController.sendEvent({
type: 'track',
event: 'SWAP_SUCCESS',
properties: {
network: NetworkController.state.caipNetwork?.id || '',
swapFromToken: this.state.sourceToken?.symbol || '',
swapToToken: this.state.toToken?.symbol || '',
swapfromAmount: this.state.sourceTokenAmount || '',
swapToAmount: this.state.toTokenAmount || '',
isSmartAccount:
AccountController.state.preferredAccountType ===
W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT
}
})
SwapController.resetState()
SwapController.getMyTokensWithBalance(forceUpdateAddresses)

Expand All @@ -730,6 +746,20 @@ export const SwapController = {
state.transactionError = error?.shortMessage
state.loadingTransaction = false
SnackController.showError(error?.shortMessage || 'Transaction error')
EventsController.sendEvent({
type: 'track',
event: 'SWAP_ERROR',
properties: {
network: NetworkController.state.caipNetwork?.id || '',
swapFromToken: this.state.sourceToken?.symbol || '',
swapToToken: this.state.toToken?.symbol || '',
swapfromAmount: this.state.sourceTokenAmount || '',
swapToAmount: this.state.toTokenAmount || '',
isSmartAccount:
AccountController.state.preferredAccountType ===
W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT
}
})

return undefined
}
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/controllers/TransactionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { OptionsController } from './OptionsController.js'
import { EventsController } from './EventsController.js'
import { SnackController } from './SnackController.js'
import { BlockchainApiController } from './BlockchainApiController.js'
import { AccountController } from './AccountController.js'
import { W3mFrameRpcConstants } from '@web3modal/wallet'

// -- Types --------------------------------------------- //
type TransactionByMonthMap = Record<number, Transaction[]>
Expand Down Expand Up @@ -80,7 +82,10 @@ export const TransactionsController = {
properties: {
address: accountAddress,
projectId,
cursor: state.next
cursor: state.next,
isSmartAccount:
AccountController.state.preferredAccountType ===
W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT
}
})
SnackController.showError('Failed to fetch transactions')
Expand Down
Loading
Loading