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

fix: fix base token being displayed as ERC20 #2714

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Pill } from '@bloomwalletio/ui'
import { Activity, StardustActivityType, isEvmTokenActivity } from '@core/activity'
import { getTokenFromActivity } from '@core/activity/utils/getTokenFromActivity'
import { BASE_TOKEN_ID } from '@core/token'
import { BASE_TOKEN_ID, TokenStandard } from '@core/token'
import { getNftByIdForAccount } from '@core/nfts/stores'
import { selectedAccountIndex } from '@core/account/stores'
import { NetworkNamespace } from '@core/network/enums'
Expand Down Expand Up @@ -53,8 +53,13 @@
standardPill = ''
} else if (isEvmTokenActivity(activity)) {
const standard = activity.tokenTransfer.standard
standardPill = standard
typePill = standard === NftStandard.Erc721 || standard === NftStandard.Irc27 ? 'nft' : 'token'
standardPill = standard === TokenStandard.BaseToken ? '' : standard
typePill =
standard === NftStandard.Erc721 || standard === NftStandard.Irc27
? 'nft'
: standard === TokenStandard.BaseToken
? 'baseCoin'
: 'token'
} else if (activity.type === EvmActivityType.ContractCall) {
typePill = ''
standardPill = convertCamelCaseToPhrase(activity.method ?? '')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { IParsedInput } from '@core/layer-2/interfaces'
export type EvmTokenApprovalActivity = BaseEvmActivity & {
type: EvmActivityType.TokenApproval
tokenTransfer: {
standard: TokenStandard.Erc20 | TokenStandard.Irc30 | NftStandard.Irc27 | NftStandard.Erc721
standard:
| TokenStandard.BaseToken
| TokenStandard.Erc20
| TokenStandard.Irc30
| NftStandard.Irc27
| NftStandard.Erc721
tokenId: string
rawAmount: bigint
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
} from '@core/activity/types'
import { parseSmartContractDataFromTransactionData } from '@core/layer-2/utils/parseSmartContractDataFromTransactionData'
import { IEvmNetwork } from '@core/network'
import { NftStandard } from '@core/nfts'
import { BASE_TOKEN_ID, TokenStandard } from '@core/token'
import { BASE_TOKEN_ID } from '@core/token'
import { LocalEvmTransaction } from '@core/transactions'
import { SubjectType } from '@core/wallet'
import { generateBaseEvmActivity } from './generateBaseEvmActivity'
Expand Down Expand Up @@ -81,7 +80,7 @@ export async function generateEvmActivityFromLocalEvmTransaction(
...baseActivity,
type: EvmActivityType.TokenTransfer,
tokenTransfer: {
standard: TokenStandard.Erc20,
standard: parsedData.standard,
tokenId: parsedData.tokenId,
rawAmount: parsedData.rawAmount,
},
Expand All @@ -91,7 +90,7 @@ export async function generateEvmActivityFromLocalEvmTransaction(
...baseActivity,
type: EvmActivityType.TokenTransfer,
tokenTransfer: {
standard: NftStandard.Erc721,
standard: parsedData.standard,
tokenId: parsedData.nftId,
rawAmount: BigInt(1),
},
Expand All @@ -101,7 +100,7 @@ export async function generateEvmActivityFromLocalEvmTransaction(
...baseActivity,
type: EvmActivityType.TokenApproval,
tokenTransfer: {
standard: TokenStandard.Erc20,
standard: parsedData.standard,
tokenId: parsedData.tokenId,
rawAmount: parsedData.rawAmount,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export function getSmartContractDataFromBlockscoutTransaction(
| undefined
let tokenTransfer:
| {
standard: TokenStandard.Erc20 | TokenStandard.Irc30 | NftStandard.Irc27 | NftStandard.Erc721
standard:
| TokenStandard.BaseToken
| TokenStandard.Erc20
| TokenStandard.Irc30
| NftStandard.Irc27
| NftStandard.Erc721
tokenId: string
rawAmount: bigint
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function getTokenIdFromActivity(activity: Activity): string | undefined {
return BASE_TOKEN_ID
} else if (isEvmTokenActivity(activity)) {
if (
activity.tokenTransfer.standard === TokenStandard.BaseToken ||
activity.tokenTransfer.standard === TokenStandard.Erc20 ||
activity.tokenTransfer.standard === TokenStandard.Irc30
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface IParsedCoinTransfer extends Omit<IParsedSmartContractData, 'typ

export interface IParsedTokenTransfer extends Omit<IParsedSmartContractData, 'type'> {
type: ParsedSmartContractType.TokenTransfer
standard: TokenStandard.Erc20 | TokenStandard.Irc30
standard: TokenStandard.Erc20 | TokenStandard.Irc30 | TokenStandard.BaseToken
tokenId: string
rawAmount: bigint
}
Expand All @@ -22,7 +22,7 @@ export interface IParsedNftTransfer extends Omit<IParsedSmartContractData, 'type

export interface IParsedTokenApproval extends Omit<IParsedSmartContractData, 'type'> {
type: ParsedSmartContractType.TokenApproval
standard: TokenStandard.Erc20
standard: TokenStandard.Erc20 | TokenStandard.BaseToken
spender: string
tokenId: string
rawAmount: bigint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,26 +180,42 @@ function parseSmartContractDataWithErc20Abi(
case 'transfer': {
return {
type: ParsedSmartContractType.TokenTransfer,
standard: TokenStandard.Erc20,
tokenId: recipientAddress,
rawAmount: BigInt(decodedData.inputs._value.value),
rawData,
rawMethod,
parsedMethod,
recipientAddress: decodedData.inputs._to.value,
...(recipientAddress === ISC_BASE_COIN_ADDRESS
? {
standard: TokenStandard.BaseToken,
tokenId: BASE_TOKEN_ID,
rawAmount: BigInt(decodedData.inputs._value.value) * BigInt(10 ** 12),
}
: {
standard: TokenStandard.Erc20,
tokenId: recipientAddress,
rawAmount: BigInt(decodedData.inputs._value.value),
}),
}
}
case 'approve': {
return {
type: ParsedSmartContractType.TokenApproval,
standard: TokenStandard.Erc20,
tokenId: recipientAddress,
spender: decodedData.inputs._spender.value,
rawAmount: BigInt(decodedData.inputs._value.value),
rawData,
rawMethod,
parsedMethod,
recipientAddress,
...(recipientAddress === ISC_BASE_COIN_ADDRESS
? {
standard: TokenStandard.BaseToken,
tokenId: BASE_TOKEN_ID,
rawAmount: BigInt(decodedData.inputs._value.value) * BigInt(10 ** 12),
}
: {
standard: TokenStandard.Erc20,
tokenId: recipientAddress,
rawAmount: BigInt(decodedData.inputs._value.value),
}),
}
}
default: {
Expand Down
Loading