Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
102 changes: 41 additions & 61 deletions packages/controllers/src/controllers/SendController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import { ConstantsUtil } from '../utils/ConstantsUtil.js'
import { CoreHelperUtil } from '../utils/CoreHelperUtil.js'
import { SwapApiUtil } from '../utils/SwapApiUtil.js'
import type { Event } from '../utils/TypeUtil.js'
import { withErrorBoundary } from '../utils/withErrorBoundary.js'
import { ChainController } from './ChainController.js'
import { ConnectionController } from './ConnectionController.js'
Expand Down Expand Up @@ -130,23 +131,60 @@ const controller = {
async sendToken() {
try {
SendController.setLoading(true)
EventsController.sendEvent({
type: 'track',
event: 'SEND_INITIATED',
properties: {
isSmartAccount:
getPreferredAccountType(ChainController.state.activeChain) ===
W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
token: SendController.state.token?.address || SendController.state.token?.symbol || '',
amount: SendController.state.sendTokenAmount ?? 0,
network: ChainController.state.activeCaipNetwork?.caipNetworkId || ''
}
})
switch (ChainController.state.activeCaipNetwork?.chainNamespace) {
case 'eip155':
await SendController.sendEvmToken()
break

return
case 'solana':
await SendController.sendSolanaToken()

return
break
default:
throw new Error('Unsupported chain')
}

EventsController.sendEvent({
type: 'track',
event: 'SEND_SUCCESS',
properties: {
isSmartAccount:
getPreferredAccountType(ChainController.state.activeChain) ===
W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
token: SendController.state.token?.symbol || '',
amount: SendController.state.sendTokenAmount ?? 0,
network: ChainController.state.activeCaipNetwork?.caipNetworkId || '',
hash: state.hash ?? ''
}
})

return
} catch (err) {
const event: Event = {
type: 'track',
event: 'SEND_ERROR',
properties: SendController.getSdkEventProperties(err)
}
if (ErrorUtil.isUserRejectedRequestError(err)) {
throw new UserRejectedRequestError(err)
EventsController.sendEvent({
...event,
event: 'SEND_REJECTED'
})
}

EventsController.sendEvent(event)
throw err
} finally {
SendController.setLoading(false)
Expand All @@ -171,16 +209,6 @@ const controller = {
}

if (SendController.state.token?.address) {
EventsController.sendEvent({
type: 'track',
event: 'SEND_INITIATED',
properties: {
isSmartAccount: activeAccountType === W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
token: SendController.state.token.address,
amount: SendController.state.sendTokenAmount,
network: ChainController.state.activeCaipNetwork?.caipNetworkId || ''
}
})
const { hash } = await SendController.sendERC20Token({
receiverAddress: SendController.state.receiverAddress,
tokenAddress: SendController.state.token.address,
Expand All @@ -192,16 +220,6 @@ const controller = {
state.hash = hash
}
} else {
EventsController.sendEvent({
type: 'track',
event: 'SEND_INITIATED',
properties: {
isSmartAccount: activeAccountType === W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
token: SendController.state.token.symbol || '',
amount: SendController.state.sendTokenAmount,
network: ChainController.state.activeCaipNetwork?.caipNetworkId || ''
}
})
const { hash } = await SendController.sendNativeToken({
receiverAddress: SendController.state.receiverAddress,
sendTokenAmount: SendController.state.sendTokenAmount,
Expand Down Expand Up @@ -295,19 +313,6 @@ const controller = {
value: value ?? BigInt(0)
})

EventsController.sendEvent({
type: 'track',
event: 'SEND_SUCCESS',
properties: {
isSmartAccount:
getPreferredAccountType('eip155') === W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
token: SendController.state.token?.symbol || '',
amount: params.sendTokenAmount,
network: ChainController.state.activeCaipNetwork?.caipNetworkId || '',
hash: hash || ''
}
})

ConnectionController._getClient()?.updateBalance('eip155')
SendController.resetSend()

Expand Down Expand Up @@ -343,19 +348,6 @@ const controller = {
chainNamespace: CommonConstantsUtil.CHAIN.EVM
})

EventsController.sendEvent({
type: 'track',
event: 'SEND_SUCCESS',
properties: {
isSmartAccount:
getPreferredAccountType('eip155') === W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
token: SendController.state.token?.symbol || '',
amount: params.sendTokenAmount,
network: ChainController.state.activeCaipNetwork?.caipNetworkId || '',
hash: hash || ''
}
})

SendController.resetSend()

return { hash }
Expand Down Expand Up @@ -401,18 +393,6 @@ const controller = {

ConnectionController._getClient()?.updateBalance('solana')

EventsController.sendEvent({
type: 'track',
event: 'SEND_SUCCESS',
properties: {
isSmartAccount: false,
token: SendController.state.token?.symbol || '',
amount: SendController.state.sendTokenAmount,
network: ChainController.state.activeCaipNetwork?.caipNetworkId || '',
hash: hash || ''
}
})

SendController.resetSend()
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,6 @@ export class W3mWalletSendPreviewView extends LitElement {
}
}

EventsController.sendEvent({
type: 'track',
event: isUserRejectedRequestError ? 'SEND_REJECTED' : 'SEND_ERROR',
properties: SendController.getSdkEventProperties(error)
})

SnackController.showError(errMessage)
}
}
Expand Down
Loading