Skip to content
Draft
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
12 changes: 6 additions & 6 deletions src/controllers/phishing/phishing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ export class PhishingController extends EventEmitter implements IPhishingControl
!domainsBlacklistedStatus || domainsBlacklistedStatus[dappId] === undefined
? 'FAILED_TO_GET'
: domainsBlacklistedStatus[dappId]
? 'BLACKLISTED'
: 'VERIFIED'
? 'BLACKLISTED'
: 'VERIFIED'
)
})

Expand Down Expand Up @@ -366,8 +366,8 @@ export class PhishingController extends EventEmitter implements IPhishingControl
!addressesBlacklistedStatus || addressesBlacklistedStatus[addr] === undefined
? 'FAILED_TO_GET'
: addressesBlacklistedStatus[addr]
? 'BLACKLISTED'
: 'VERIFIED'
? 'BLACKLISTED'
: 'VERIFIED'
)
})

Expand Down Expand Up @@ -397,11 +397,11 @@ export class PhishingController extends EventEmitter implements IPhishingControl
}

async updateAddressesBlacklistedStatus(
urls: string[],
addresses: string[],
callback: (res: { [dappId: string]: BlacklistedStatus }) => void
) {
try {
await this.#fetchAndSetAddressesBlacklistedStatus(urls, callback)
await this.#fetchAndSetAddressesBlacklistedStatus(addresses, callback)
} catch (err: any) {
this.emitError({
message: 'Failed to fetch and update addresses blacklisted status',
Expand Down
12 changes: 7 additions & 5 deletions src/controllers/signAccountOp/signAccountOp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ export class SignAccountOpController extends EventEmitter implements ISignAccoun
}

humanize() {
this.humanization = humanizeAccountOp(this.accountOp)
this.humanization = humanizeAccountOp(this.accountOp, this.emitError)
const currentHumanizationId = Date.now()
this.humanizationId = currentHumanizationId
if (this.humanization.length) {
Expand All @@ -639,20 +639,22 @@ export class SignAccountOpController extends EventEmitter implements ISignAccoun
.filter((v) => v.type === 'token' || v.type === 'address')
.map((v) => v.address)
)
.filter((addr): addr is string => Boolean(addr)),
.filter((addr): addr is string => Boolean(addr))
.map((addr) => addr.toLowerCase()),
(addressesStatus) => {
if (this.humanizationId !== currentHumanizationId) return

for (const call of this.humanization) {
if (!call.fullVisualization) continue

for (const vis of call.fullVisualization) {
const lowerCaseAddr = vis.address?.toLowerCase()
if (
(vis.type === 'token' || vis.type === 'address') &&
vis.address &&
addressesStatus[vis.address]
lowerCaseAddr &&
addressesStatus[lowerCaseAddr]
) {
vis.verification = addressesStatus[vis.address]
vis.verification = addressesStatus[lowerCaseAddr]
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/libs/humanizer/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ErrorRef } from '@/interfaces/eventEmitter'

import humanizerInfo from '../../consts/humanizer/humanizerInfo.json'
import { Message } from '../../interfaces/userRequest'
import { AccountOp } from '../accountOp/accountOp'
Expand Down Expand Up @@ -108,14 +110,21 @@ const humanizerTMModules = [
snapshotModule
]

const humanizeAccountOp = (_accountOp: AccountOp): IrCall[] => {
const humanizeAccountOp = (_accountOp: AccountOp, emitError?: (e: ErrorRef) => void): IrCall[] => {
const accountOp = parse(stringify(_accountOp))

let currentCalls: IrCall[] = accountOp.calls
humanizerCallModules.forEach((hm) => {
humanizerCallModules.forEach((hm, i) => {
try {
currentCalls = hm(accountOp, currentCalls, humanizerInfo as HumanizerMeta)
} catch (error) {
} catch (error: any) {
emitError &&
emitError({
message: `Humanizer: Failed to parse tx. Module id ${i} `,
level: 'minor',
sendCrashReport: true,
error
})
console.error(error)
// No action is needed here; we only set `currentCalls` if the module successfully resolves the calls.
}
Expand Down
10 changes: 4 additions & 6 deletions src/libs/humanizer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,19 @@ export function getImage(content: string): HumanizerVisualization {
export function getBreak(): HumanizerVisualization {
return { type: 'break', id: randomId() }
}
export function getAddressVisualization(_address: string): HumanizerVisualization {
const address = _address.toLowerCase()
return { type: 'address', address, id: randomId() }
export function getAddressVisualization(address: string): HumanizerVisualization {
return { type: 'address', address: getAddress(address), id: randomId() }
}

export function getToken(
_address: string,
address: string,
amount: bigint,
isHidden?: boolean,
chainId?: bigint
): HumanizerVisualization {
const address = _address.toLowerCase()
return {
type: 'token',
address,
address: getAddress(address),
value: BigInt(amount),
id: randomId(),
isHidden,
Expand Down
Loading