Skip to content

Commit

Permalink
feat: show verified badge and tooltip for contracts on activities (#2286
Browse files Browse the repository at this point in the history
)

* cleanup contract field

* remove smartcontract fallback

* update icon for smart contracts

* improve3 check if address is magic contract

* PR fixes

* rename

---------

Co-authored-by: Tuditi <[email protected]>
  • Loading branch information
MarkNerdi and Tuditi authored Apr 9, 2024
1 parent 773a364 commit d5be7ff
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { truncateString } from '@core/utils/string'
import { Subject, SubjectType } from '@core/wallet'
import { NetworkAvatar } from '@ui'
import { Text } from '@bloomwalletio/ui'
import { IconName, Text, TooltipIcon } from '@bloomwalletio/ui'
import { localize } from '@core/i18n'
export let subject: Subject | undefined
Expand All @@ -21,7 +21,7 @@
case SubjectType.Contact:
return truncateString(subject.contact.name, 13, 0)
case SubjectType.SmartContract:
return truncateString(subject.name, 13, 0)
return subject.name ? truncateString(subject.name, 13, 0) : truncateString(subject.address, 5, 5)
case SubjectType.Account:
return truncateString(subject.account.name, 13, 0)
case SubjectType.Network:
Expand All @@ -36,10 +36,20 @@
{#if networkId}
<NetworkAvatar size="xs" {networkId} />
{/if}
<Text
type={subject?.type === SubjectType.Address ? 'pre-sm' : 'sm'}
fontWeight={isSelectedAccount ? 'semibold' : 'medium'}
>
{getDisplayedSubject(subject)}
</Text>
<div class="flex flex-row items-center gap-1">
{#if subject?.type === SubjectType.SmartContract}
<TooltipIcon
icon={subject.verified ? IconName.FileCheck : IconName.FileCode}
size="xs"
textColor={subject.verified ? 'success' : 'secondary'}
tooltip={localize(`general.${subject.verified ? 'verified' : 'unverified'}`)}
/>
{/if}
<Text
type={subject?.type === SubjectType.Address ? 'pre-sm' : 'sm'}
fontWeight={isSelectedAccount ? 'semibold' : 'medium'}
>
{getDisplayedSubject(subject)}
</Text>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
standardPill = standard
typePill = standard === NftStandard.Erc721 || standard === NftStandard.Irc27 ? 'nft' : 'token'
} else if (activity.type === EvmActivityType.ContractCall) {
typePill = activity.verified ? 'verified' : 'unverified'
typePill = ''
standardPill = convertCamelCaseToPhrase(activity.method ?? '')
} else {
typePill = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
items={[
{
key: localize('general.contractAddress'),
value: activity.contractAddress || undefined,
onClick: () => onExplorerClick(activity.contractAddress ?? ''),
value: activity.contract?.address || undefined,
onClick: () => onExplorerClick(activity.contract?.address ?? ''),
},
{
key: localize('general.verified'),
value: activity.verified ? localize('general.yes') : localize('general.no'),
value: activity.contract?.verified ? localize('general.yes') : localize('general.no'),
},
{
key: localize('general.methodName'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { NetworkNamespace } from '@core/network/enums'
import { BaseActivity } from '../base-activity.type'
import { ISmartContractSubject } from '@core/wallet'

export type BaseEvmActivity = BaseActivity & {
namespace: NetworkNamespace.Evm

contractAddress?: string
contract?: ISmartContractSubject
estimatedGasFee?: bigint
maxGasFee?: bigint
transactionFee?: bigint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { BaseEvmActivity } from './base-evm-activity.type'

export type EvmContractCallActivity = BaseEvmActivity & {
type: EvmActivityType.ContractCall
verified: boolean
rawData: string

methodId?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export type EvmTokenTransferActivity = BaseEvmActivity & {
tokenId: string
rawAmount: bigint
}
verified: boolean
rawData: string

methodId?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Converter, HEX_PREFIX } from '@core/utils'
import { EvmContractCallActivity } from '@core/activity/types/evm/evm-contract-call-activity.type'
import { SubjectType } from '@core/wallet'
import { ActivityDirection } from '@core/activity/enums'
import { localize } from '@core/i18n'
import { WEI_PER_GLOW } from '@core/layer-2/constants'
import { getMethodForEvmTransaction } from '@core/layer-2'
import { addMethodToRegistry, getMethodFromRegistry } from '@core/layer-2/stores/method-registry.store'
Expand Down Expand Up @@ -137,16 +136,19 @@ async function generateBaseEvmActivityFromBlockscoutTransaction(
baseActivity.recipient = {
type: SubjectType.SmartContract,
address: blockscoutTransaction.to.hash.toLowerCase(),
name: blockscoutTransaction.to.name ?? localize('general.smartContract'),
name: blockscoutTransaction.to.name ?? '',
verified: blockscoutTransaction.to.is_verified,
}
baseActivity.contractAddress = blockscoutTransaction.to.hash.toLowerCase()
baseActivity.contract = structuredClone(baseActivity.recipient)
}
if (blockscoutTransaction.from.is_contract) {
baseActivity.sender = {
type: SubjectType.SmartContract,
address: blockscoutTransaction.from.hash.toLowerCase(),
name: blockscoutTransaction.from.name ?? localize('general.smartContract'),
name: blockscoutTransaction.from.name ?? '',
verified: blockscoutTransaction.from.is_verified,
}
baseActivity.contract = structuredClone(baseActivity.sender)
}
baseActivity.subject =
baseActivity.direction === ActivityDirection.Outgoing ? baseActivity.recipient : baseActivity.sender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { BASE_TOKEN_ID, TokenStandard } from '@core/token'
import { LocalEvmTransaction } from '@core/transactions'
import { Converter } from '@core/utils/convert'
import { generateBaseEvmActivity } from './generateBaseEvmActivity'
import { SubjectType } from '@core/wallet'

export async function generateEvmActivityFromLocalEvmTransaction(
transaction: LocalEvmTransaction,
Expand Down Expand Up @@ -53,7 +54,12 @@ export async function generateEvmActivityFromLocalEvmTransaction(
parameters,
methodId: data.substring(0, 10),
rawData: data,
contractAddress: to?.toString().toLowerCase(),
contract: {
type: SubjectType.SmartContract,
address: to?.toString().toLowerCase(),
name: '',
verified: false,
},
} as EvmContractCallActivity
} else {
const tokenTransfer =
Expand All @@ -72,7 +78,12 @@ export async function generateEvmActivityFromLocalEvmTransaction(
return {
...baseActivity,
type: EvmActivityType.TokenTransfer,
contractAddress: to?.toString().toLowerCase(),
contract: {
type: SubjectType.SmartContract,
address: to?.toString().toLowerCase(),
name: '',
verified: false,
},
tokenTransfer,
} as EvmTokenTransferActivity
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BaseEvmActivity, EvmCoinTransferActivity, EvmTokenTransferActivity } fr
import { IBlockscoutTransaction } from '@auxiliary/blockscout'
import { ActivityAction, ActivityDirection, InclusionState } from '@core/activity/enums'
import { getAddressFromAccountForNetwork } from '@core/account'
import { getSubjectFromAddress, isSubjectInternal } from '@core/wallet'
import { ISmartContractSubject, SubjectType, getSubjectFromAddress, isSubjectInternal } from '@core/wallet'
import { EvmActivityType } from '@core/activity/enums/evm'
import { BASE_TOKEN_ID, TokenStandard } from '@core/token'
import { NftStandard } from '@core/nfts'
Expand Down Expand Up @@ -64,6 +64,22 @@ export async function generateEvmTokenTransferActivityFromBlockscoutTokenTransfe
return
}

const contract: ISmartContractSubject | undefined = blockscoutTokenTransfer.to.is_contract
? {
type: SubjectType.SmartContract,
address: blockscoutTokenTransfer.to.hash.toLowerCase(),
name: blockscoutTokenTransfer.to.name ?? '',
verified: blockscoutTokenTransfer.to.is_verified,
}
: blockscoutTokenTransfer.from.is_contract
? {
type: SubjectType.SmartContract,
address: blockscoutTokenTransfer.from.hash.toLowerCase(),
name: blockscoutTokenTransfer.from.name ?? '',
verified: blockscoutTokenTransfer.from.is_verified,
}
: undefined

const baseActivity: BaseEvmActivity = {
namespace: NetworkNamespace.Evm,

Expand All @@ -84,8 +100,7 @@ export async function generateEvmTokenTransferActivityFromBlockscoutTokenTransfe
subject,
direction,
isInternal,

contractAddress: blockscoutTokenTransfer.token.address.toLowerCase(),
contract,
transactionFee,
}

Expand Down Expand Up @@ -126,11 +141,10 @@ export async function generateEvmTokenTransferActivityFromBlockscoutTokenTransfe
rawAmount,
},

verified: blockscoutTransaction?.to.is_verified ?? false,
methodId: blockscoutTransaction?.decoded_input?.method_id ?? blockscoutTransaction?.method,
method,
parameters,
rawData: blockscoutTransaction?.raw_input ?? '',
contractAddress: blockscoutTransaction?.to?.hash.toLowerCase(),
contract,
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const ISC_MAGIC_CONTRACT_ADDRESS = '0x1074000000000000000000000000000000000000'
export const ISC_BASE_COIN_ADDRESS = '0x1074010000000000000000000000000000000000'
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface ISmartContractSubject {
type: SubjectType.SmartContract
name: string
address: string
verified: boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { findActiveAccountWithAddress } from '@core/profile/actions'
import { SubjectType } from '../enums'
import { Subject } from '../types'
import { getNetworkFromAddress } from '@core/layer-2/actions'
import { ISC_MAGIC_CONTRACT_ADDRESS } from '@core/layer-2'
import { ISC_MAGIC_CONTRACT_ADDRESS, ISC_BASE_COIN_ADDRESS } from '@core/layer-2'
import { localize } from '@core/i18n'

export function getSubjectFromAddress(address: string, networkId: NetworkId): Subject {
Expand All @@ -13,8 +13,8 @@ export function getSubjectFromAddress(address: string, networkId: NetworkId): Su
return { type: SubjectType.Account, account, address }
}

if (address === ISC_MAGIC_CONTRACT_ADDRESS) {
return { type: SubjectType.SmartContract, name: localize('general.magicContract'), address }
if (address === ISC_MAGIC_CONTRACT_ADDRESS || address === ISC_BASE_COIN_ADDRESS) {
return { type: SubjectType.SmartContract, name: localize('general.magicContract'), address, verified: true }
}

const network = getNetworkFromAddress(address)
Expand Down

0 comments on commit d5be7ff

Please sign in to comment.