Skip to content

Commit

Permalink
Pass in apiClient into decodeTransactions
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook committed Apr 29, 2024
1 parent 4dca70c commit 1d522f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 6 additions & 2 deletions packages/kit/src/components/TxnDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -38,19 +39,22 @@ 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<DecodingType | undefined>(undefined)
const [transferProps, setTransferProps] = useState<TransferProps[]>([])
const [awardItemProps, setAwardItemProps] = useState<AwardItemProps[]>([])

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[])
}
Expand Down
9 changes: 4 additions & 5 deletions packages/kit/src/utils/txnDecoding.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -242,12 +241,11 @@ type DecodedTxnData =
| ERC1155SafeTransferFromTxnData
| AwardItemTxnData

const decodeTxnData = async (txns: commons.transaction.TransactionEncoded[]): Promise<TxnData> => {
const decodeTxnData = async (apiClient: SequenceAPIClient, txns: commons.transaction.TransactionEncoded[]): Promise<TxnData> => {
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)
Expand All @@ -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<TxnProps[]> => {
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)

Expand Down

0 comments on commit 1d522f4

Please sign in to comment.