Skip to content

Commit

Permalink
Merge commit 'adbfdc0022b4fe99a26638fc5a21ec8576d5b912' into chore/up…
Browse files Browse the repository at this point in the history
…date-web3-to-4.8
  • Loading branch information
MarkNerdi committed May 17, 2024
2 parents 09bcf47 + adbfdc0 commit faaa5bb
Show file tree
Hide file tree
Showing 32 changed files with 785 additions and 398 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
import { EvmTransactionData } from '@core/layer-2/types'
import { EvmTransactionDetails } from '@views/dashboard/send-flow/views/components'
import {
IParsedInput,
ParsedSmartContractType,
calculateEstimatedGasFeeFromTransactionData,
calculateMaxGasFeeFromTransactionData,
getHexEncodedTransaction,
getMethodForEvmTransaction,
parseSmartContractDataFromTransactionData,
} from '@core/layer-2'
import { getTokenFromSelectedAccountTokens } from '@core/token/stores'
import { getTransferInfoFromTransactionData } from '@core/layer-2/utils/getTransferInfoFromTransactionData'
import { TokenTransferData } from '@core/wallet'
import { Nft } from '@core/nfts'
import { Alert, Link, Table, Text } from '@bloomwalletio/ui'
import { PopupId, closePopup, modifyPopupState, openPopup } from '@desktop/auxiliary/popup'
import { truncateString } from '@core/utils'
import { Converter, truncateString } from '@core/utils'
import { openUrlInBrowser } from '@core/app'
import { StardustActivityType } from '@core/activity'
import { BASE_TOKEN_ID } from '@core/token/constants'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { LedgerAppName } from '@core/ledger'
Expand Down Expand Up @@ -53,34 +53,61 @@
let baseCoinTransfer: TokenTransferData | undefined
let isSmartContractCall = false
let methodName: string | undefined = undefined
let parameters: Record<string, string> | undefined = undefined
let inputs: IParsedInput[] | undefined = undefined
let busy = false
setTokenTransfer()
function setTokenTransfer(): void {
const transferInfo = getTransferInfoFromTransactionData(preparedTransaction, evmNetwork)
switch (transferInfo?.type) {
case StardustActivityType.Basic: {
setTransactionInformation()
function setTransactionInformation(): void {
if (!preparedTransaction.data) {
baseCoinTransfer = {
token: getTokenFromSelectedAccountTokens(BASE_TOKEN_ID, evmNetwork.id),
rawAmount: Converter.bigIntLikeToBigInt(preparedTransaction.value),
} as TokenTransferData
return
}
const parsedData = parseSmartContractDataFromTransactionData(
{
to: preparedTransaction.to?.toString(),
data: String(preparedTransaction.data),
value: preparedTransaction.value,
},
evmNetwork
)
methodName = parsedData?.parsedMethod?.name
inputs = parsedData?.parsedMethod?.inputs
switch (parsedData?.type) {
case ParsedSmartContractType.CoinTransfer: {
const transfer = {
token: getTokenFromSelectedAccountTokens(transferInfo.tokenId, evmNetwork.id),
rawAmount: transferInfo.rawAmount,
token: getTokenFromSelectedAccountTokens(BASE_TOKEN_ID, evmNetwork.id),
rawAmount: parsedData.rawAmount,
} as TokenTransferData
if (!transfer.token) {
return
}
if (transferInfo.tokenId === BASE_TOKEN_ID) {
baseCoinTransfer = transfer
} else {
tokenTransfer = transfer
baseCoinTransfer = transfer
break
}
case ParsedSmartContractType.TokenTransfer: {
const transfer = {
token: getTokenFromSelectedAccountTokens(parsedData.tokenId, evmNetwork.id),
rawAmount: parsedData.rawAmount,
} as TokenTransferData
if (!transfer.token) {
return
}
tokenTransfer = transfer
break
}
case StardustActivityType.Nft: {
nft = getNftByIdForAccount($selectedAccount.index, transferInfo.nftId)
case ParsedSmartContractType.NftTransfer: {
nft = getNftByIdForAccount($selectedAccount?.index as number, parsedData.nftId)
break
}
case StardustActivityType.SmartContract: {
case ParsedSmartContractType.SmartContract: {
isSmartContractCall = true
break
}
Expand Down Expand Up @@ -147,13 +174,6 @@
}
}
$: void setMethodName(preparedTransaction)
function setMethodName(preparedTransaction: EvmTransactionData): void {
const [method, _parameters] = getMethodForEvmTransaction(String(preparedTransaction.data ?? '')) ?? []
methodName = method
parameters = _parameters
}
function getSuccessMessage(): string {
const recipient = truncateString(String(preparedTransaction.to), 6, 6)
const assetName =
Expand Down Expand Up @@ -216,7 +236,7 @@
onClick: () => onExplorerClick(String(preparedTransaction.to)),
},
{ key: localize('general.methodName'), value: methodName },
{ key: localize('general.parameters'), value: parameters },
{ key: localize('general.parameters'), value: inputs },
{ key: localize('general.data'), value: String(preparedTransaction.data), copyable: true },
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
isDepthSearch = true
recoverAccountsPayload = {
accountStartIndex: isSingleAccountSearch ? $selectedAccountIndex : accountGapLimit,
accountGapLimit: 0,
accountGapLimit: 1,
addressGapLimit: isSingleAccountSearch
? addressGapLimit
: (searchCount - depthSearchCount) * addressGapLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
startTime: campaign.startTime,
endTime: campaign.endTime,
url: campaign.url,
chainId: campaign.evmNetwork,
chainId: campaign.chain,
listingStatus: campaign.listingStatus,
ERC20Reward: campaign.ERC20Reward,
} as ICampaign
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
const recoverAccountsPayload: RecoverAccountsPayload = {
accountStartIndex,
accountGapLimit,
addressGapLimit: 0,
addressGapLimit: 1,
syncOptions: { ...DEFAULT_SYNC_OPTIONS, addressStartIndex: 0 },
}
Expand All @@ -72,7 +72,7 @@
depthSearch = true
recoverAccountsPayload = {
accountStartIndex: accountGapLimit,
accountGapLimit: 0,
accountGapLimit: 1,
addressGapLimit: (searchCount - depthSearchCount) * addressGapLimit,
syncOptions: { ...DEFAULT_SYNC_OPTIONS, addressStartIndex: 0 },
}
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Bloom Labs Ltd <[email protected]>",
"license": "PolyForm Strict License 1.0.0",
"dependencies": {
"@bloomwalletio/ui": "0.20.22",
"@bloomwalletio/ui": "0.21.0",
"@ethereumjs/common": "4.3.0",
"@ethereumjs/rlp": "5.0.2",
"@ethereumjs/tx": "5.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
{
key: localize('general.inputs'),
value: activity.parameters,
value: activity.inputs,
},
{
key: localize('general.data'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface IWatchlistName {
interface IDecodedInput {
method_call: string
method_id: string
parameters: Record<string, string> // IDecodedInputParameters
parameters: { name: string; type: string; value: unknown }[] // IDecodedInputParameters
}

interface ITokenTransfer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { EvmActivityType } from '@core/activity/enums/evm'
import { BaseEvmActivity } from './base-evm-activity.type'
import { IParsedInput } from '@core/layer-2'

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

methodId?: string
method?: string
parameters?: Record<string, string>
inputs?: IParsedInput[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EvmActivityType } from '@core/activity/enums/evm'
import { TokenStandard } from '@core/token'
import { NftStandard } from '@core/nfts'
import { BaseEvmActivity } from './base-evm-activity.type'
import { IParsedInput } from '@core/layer-2/interfaces'

export type EvmTokenMintingActivity = BaseEvmActivity & {
type: EvmActivityType.TokenMinting
Expand All @@ -14,5 +15,5 @@ export type EvmTokenMintingActivity = BaseEvmActivity & {

methodId?: string
method?: string
parameters?: Record<string, string>
inputs?: IParsedInput[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EvmActivityType } from '@core/activity/enums/evm'
import { TokenStandard } from '@core/token'
import { NftStandard } from '@core/nfts'
import { BaseEvmActivity } from './base-evm-activity.type'
import { IParsedInput } from '@core/layer-2/interfaces'

export type EvmTokenTransferActivity = BaseEvmActivity & {
type: EvmActivityType.TokenTransfer
Expand All @@ -14,5 +15,5 @@ export type EvmTokenTransferActivity = BaseEvmActivity & {

methodId?: string
method?: string
parameters?: Record<string, string>
inputs?: IParsedInput[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import { IAccountState } from '@core/account'
import { IEvmNetwork } from '@core/network'
import { LocalEvmTransaction, buildPersistedEvmTransactionFromBlockscoutTransaction } from '@core/transactions'
import { generateEvmActivityFromLocalEvmTransaction } from './generateEvmActivityFromLocalEvmTransaction'
import { BaseEvmActivity, EvmActivity, EvmCoinTransferActivity } from '@core/activity/types'
import { BaseEvmActivity, EvmActivity, EvmCoinTransferActivity, EvmTokenTransferActivity } from '@core/activity/types'
import { BASE_TOKEN_ID } from '@core/token'
import { generateBaseEvmActivity } from './generateBaseEvmActivity'
import { EvmActivityType } from '@core/activity/enums/evm'
import { Converter, HEX_PREFIX } from '@core/utils'
import { Converter } 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 { getMethodForEvmTransaction } from '@core/layer-2'
import { addMethodToRegistry, getMethodFromRegistry } from '@core/layer-2/stores/method-registry.store'
import { getSmartContractDataFromBlockscoutTransaction } from './getSmartContractDataFromBlockscoutTransaction'

export async function generateEvmActivityFromBlockscoutTransaction(
blockscoutTransaction: IBlockscoutTransaction,
Expand Down Expand Up @@ -52,42 +51,51 @@ async function generateEvmContractCallActivityFromBlockscoutTransaction(
localTransaction: LocalEvmTransaction | undefined,
evmNetwork: IEvmNetwork,
account: IAccountState
): Promise<EvmContractCallActivity> {
): Promise<EvmActivity> {
const baseActivity = await generateBaseEvmActivityFromBlockscoutTransaction(
blockscoutTransaction,
localTransaction,
evmNetwork,
account
)

let method: string | undefined
let parameters: Record<string, string> | undefined
if (blockscoutTransaction.decoded_input) {
// if decoded input is available we know the method and parameters and contract is verified
const { method_id, method_call, parameters: _parameters } = blockscoutTransaction.decoded_input
method = blockscoutTransaction.method
parameters = _parameters
const methodId = blockscoutTransaction.decoded_input?.method_id ?? blockscoutTransaction.method // `method` is the methodId if the inputs cannot be decoded
const rawData = blockscoutTransaction.raw_input

if (!getMethodFromRegistry(HEX_PREFIX + method_id)) {
const fourBytePrefix = HEX_PREFIX + method_id
addMethodToRegistry(fourBytePrefix, method_call)
}
} else {
const [_method, _parameters] = getMethodForEvmTransaction(blockscoutTransaction.raw_input) ?? []
method = _method
parameters = _parameters
}
const smartContractData = blockscoutTransaction
? getSmartContractDataFromBlockscoutTransaction(blockscoutTransaction, evmNetwork)
: undefined

return {
...baseActivity,
type: EvmActivityType.ContractCall,
verified: blockscoutTransaction.to.is_verified,
methodId: blockscoutTransaction.decoded_input?.method_id ?? blockscoutTransaction.method, // `method` is the methodId if the inputs cannot be decoded
method,
parameters: parameters,
rawData: blockscoutTransaction.raw_input,
contractAddress: blockscoutTransaction.to?.hash.toLowerCase(),
} as EvmContractCallActivity
switch (smartContractData?.type) {
case EvmActivityType.CoinTransfer:
return {
...baseActivity,
type: EvmActivityType.CoinTransfer,
baseTokenTransfer: smartContractData.baseTokenTransfer,
methodId,
method: smartContractData.method,
inputs: smartContractData.inputs,
} as EvmCoinTransferActivity
case EvmActivityType.TokenTransfer:
return {
...baseActivity,
type: EvmActivityType.TokenTransfer,
tokenTransfer: smartContractData.tokenTransfer,
methodId,
method: smartContractData.method,
inputs: smartContractData.inputs,
} as EvmTokenTransferActivity
case EvmActivityType.ContractCall:
default:
return {
...baseActivity,
type: EvmActivityType.ContractCall,
rawData,
methodId,
method: smartContractData?.method,
inputs: smartContractData?.inputs,
} as EvmContractCallActivity
}
}

async function generateEvmCoinTransferActivityFromBlockscoutTransaction(
Expand Down
Loading

0 comments on commit faaa5bb

Please sign in to comment.