diff --git a/packages/kit/src/components/TxnDetails/index.tsx b/packages/kit/src/components/TxnDetails/index.tsx index 6379c836..3bdad4af 100644 --- a/packages/kit/src/components/TxnDetails/index.tsx +++ b/packages/kit/src/components/TxnDetails/index.tsx @@ -11,6 +11,7 @@ import { commons } from '@0xsequence/core' import { DecodingType, TransferProps, AwardItemProps, decodeTransactions } from '../../utils/txnDecoding' import { ContractType, TokenBalance } from '@0xsequence/indexer' import { getAddress } from 'ethers/lib/utils' +import { useAPIClient } from '../../hooks' interface TxnDetailsProps { address: string @@ -38,7 +39,7 @@ export const TxnDetailsSkeleton = () => { // @ts-ignore-next-line export const TxnDetails = ({ address, txs, chainId }: TxnDetailsProps) => { - const { chains } = useConfig() + const apiClient = useAPIClient() // const { fiatCurrency } = useSettings() const [decodingType, setDecodingType] = useState(undefined) @@ -46,11 +47,14 @@ export const TxnDetails = ({ address, txs, chainId }: TxnDetailsProps) => { const [awardItemProps, setAwardItemProps] = useState([]) const getTxnProps = async () => { - const decodedTxnDatas = await decodeTransactions(address, txs) + const decodedTxnDatas = await decodeTransactions(apiClient, address, txs) + setDecodingType(decodedTxnDatas[0].type) + if (decodedTxnDatas[0].type === 'transfer') { setTransferProps(decodedTxnDatas as TransferProps[]) } + if (decodedTxnDatas[0].type === 'awardItem') { setAwardItemProps(decodedTxnDatas as AwardItemProps[]) } diff --git a/packages/kit/src/utils/txnDecoding.ts b/packages/kit/src/utils/txnDecoding.ts index af0cc0b2..1bb92ab2 100644 --- a/packages/kit/src/utils/txnDecoding.ts +++ b/packages/kit/src/utils/txnDecoding.ts @@ -1,8 +1,7 @@ -import { ContractCall } from '@0xsequence/api' +import { ContractCall, SequenceAPIClient } from '@0xsequence/api' import { commons } from '@0xsequence/core' import { ContractType, TxnTransferType } from '@0xsequence/indexer' import { BigNumber, BigNumberish, BytesLike, ethers } from 'ethers' -import { getNetworkConfigAndClients } from './clients' import { getAddress } from 'ethers/lib/utils' interface TransactionEncodedWithCall extends commons.transaction.TransactionEncoded { @@ -242,12 +241,11 @@ type DecodedTxnData = | ERC1155SafeTransferFromTxnData | AwardItemTxnData -const decodeTxnData = async (txns: commons.transaction.TransactionEncoded[]): Promise => { +const decodeTxnData = async (apiClient: SequenceAPIClient, txns: commons.transaction.TransactionEncoded[]): Promise => { const mainModule = new ethers.utils.Interface(mainModuleAbi) const callData = mainModule.encodeFunctionData('selfExecute', [txns]) try { - const { apiClient } = getNetworkConfigAndClients(1) // chainId passed here doesn't matter since we get apiClient const { call } = await apiClient.decodeContractCall({ callData }) return createTxnData('', call, 0, callData) @@ -257,11 +255,12 @@ const decodeTxnData = async (txns: commons.transaction.TransactionEncoded[]): Pr } export const decodeTransactions = async ( + apiClient: SequenceAPIClient, accountAddress: string, txns: commons.transaction.Transaction[] ): Promise => { const encodedTxns = encodeTransactions(txns) - const decodedTxnDatas = (await decodeTxnData(encodedTxns)).objs as DecodedTxnData[] + const decodedTxnDatas = (await decodeTxnData(apiClient, encodedTxns)).objs as DecodedTxnData[] const from = getAddress(accountAddress)