diff --git a/CHANGELOG.md b/CHANGELOG.md index 14d2481..ff0d4ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [0.11.0] - 2024-03-28 + +### Added Changes +- Added `chainId` param to `useEtherspotNfts` hook's `getTransactions` and `getTransaction` methods +- Fixed `useEtherspotNfts` hook's `getTransactions` method returned result to match back-end changes + +### Breaking Changes +- Transactions returned by `useEtherspotNfts` hook's `getTransactions` method are now different type called `UserOpTransaction` + ## [0.10.1] - 2024-03-20 ### Added Changes diff --git a/__mocks__/@etherspot/prime-sdk.js b/__mocks__/@etherspot/prime-sdk.js index 19f52d4..3d92949 100644 --- a/__mocks__/@etherspot/prime-sdk.js +++ b/__mocks__/@etherspot/prime-sdk.js @@ -137,18 +137,18 @@ export class DataUtils { ]; if (chainId !== 1) { - return { items: [] }; + return { transactions: [] }; } if (account === defaultAccountAddress) { - return { items: accountTransactions }; + return { transactions: accountTransactions }; } if (account === otherAccountAddress) { - return { items: [{ hash: '0x69', value: '0' }] }; + return { transactions: [{ hash: '0x69', value: '0' }] }; } - return { items: [] }; + return { transactions: [] }; } getTransaction({ hash, chainId }) { if (hash !== '0x42' || chainId !== 1) return; diff --git a/package-lock.json b/package-lock.json index 5919c07..d58b052 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@etherspot/transaction-kit", - "version": "0.10.1", + "version": "0.11.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@etherspot/transaction-kit", - "version": "0.10.1", + "version": "0.11.0", "license": "MIT", "dependencies": { "@etherspot/eip1271-verification-util": "0.1.2", diff --git a/package.json b/package.json index 822c643..e608134 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@etherspot/transaction-kit", "description": "React Etherspot Transaction Kit", - "version": "0.10.1", + "version": "0.11.0", "main": "dist/cjs/index.js", "scripts": { "rollup:build": "NODE_OPTIONS=--max-old-space-size=8192 rollup -c", diff --git a/src/hooks/useEtherspotHistory.ts b/src/hooks/useEtherspotHistory.ts index 2a72ee1..52a40d5 100644 --- a/src/hooks/useEtherspotHistory.ts +++ b/src/hooks/useEtherspotHistory.ts @@ -4,9 +4,12 @@ import { useMemo } from 'react'; // hooks import useEtherspot from './useEtherspot'; +// types +import { UserOpTransaction } from '../types/EtherspotTransactionKit'; + interface IEtherspotHistoryHook { - getAccountTransactions: (accountAddress?: string) => Promise; - getAccountTransaction: (hash: string) => Promise; + getAccountTransactions: (accountAddress?: string, chainId?: number) => Promise; + getAccountTransaction: (hash: string, chainId?: number) => Promise; } /** @@ -14,18 +17,21 @@ interface IEtherspotHistoryHook { * @param chainId {number | undefined} - Chain ID * @returns {IEtherspotHistoryHook} - hook methods to fetch Etherspot transactions history */ -const useEtherspotHistory = (chainId: number): IEtherspotHistoryHook => { - const { getDataService, getSdk, chainId: defaultChainId } = useEtherspot(); +const useEtherspotHistory = (chainId?: number): IEtherspotHistoryHook => { + const { getDataService, getSdk, chainId: etherspotChainId } = useEtherspot(); - const historyChainId = useMemo(() => { + const defaultChainId = useMemo(() => { if (chainId) return chainId; - return defaultChainId; - }, [chainId, defaultChainId]); + return etherspotChainId; + }, [chainId, etherspotChainId]); - const getAccountTransactions = async (accountAddress?: string): Promise => { + const getAccountTransactions = async ( + accountAddress?: string, + historyChainId: number = defaultChainId, + ): Promise => { const sdkForChainId = await getSdk(historyChainId); - let transactions: Transaction[] = []; + let transactions: UserOpTransaction[] = []; const transactionsForAccount = accountAddress ?? await sdkForChainId.getCounterFactualAddress(); if (!transactionsForAccount) { @@ -35,9 +41,7 @@ const useEtherspotHistory = (chainId: number): IEtherspotHistoryHook => { try { const dataService = getDataService(); - // TODO: fix once available on Prime SDK - // @ts-ignore - ({ items: transactions } = await dataService.getTransactions({ + ({ transactions } = await dataService.getTransactions({ account: transactionsForAccount, chainId: +historyChainId, })); @@ -53,7 +57,10 @@ const useEtherspotHistory = (chainId: number): IEtherspotHistoryHook => { return transactions; }; - const getAccountTransaction = async (hash: string): Promise => { + const getAccountTransaction = async ( + hash: string, + historyChainId: number = defaultChainId, + ): Promise => { try { const dataService = getDataService(); return dataService.getTransaction({ hash, chainId: +historyChainId }); diff --git a/src/types/EtherspotTransactionKit.ts b/src/types/EtherspotTransactionKit.ts index ff81798..ff85e85 100644 --- a/src/types/EtherspotTransactionKit.ts +++ b/src/types/EtherspotTransactionKit.ts @@ -3,6 +3,7 @@ import { BigNumber, BigNumberish, BytesLike } from 'ethers'; import { Route } from '@lifi/types'; import { PaymasterApi } from '@etherspot/prime-sdk'; import { ExchangeOffer } from '@etherspot/prime-sdk/dist/sdk/data'; +import { TransactionStatuses } from '@etherspot/prime-sdk/dist/sdk/data/constants'; export interface ITransaction { id?: string; @@ -116,4 +117,69 @@ interface UserOp { signature: EtherspotPromiseOrValue; } +// TODO: remove once available on Prime SDK +interface EtherspotErc20TransfersEntity { + from: string; + to: string; + value: number; + asset?: string; + address: string; + decimal: number; +} + +// TODO: remove once available on Prime SDK +interface EtherspotNativeTransfersEntity { + from: string; + to: string; + value: string; + asset?: string; + address: string; + decimal: number; + data: string; +} + +// TODO: remove once available on Prime SDK +interface EtherspotNftTransfersEntity { + from: string; + to: string; + value: number; + tokenId: number; + asset?: string; + category: string; + address: string; +} + +// TODO: remove once available on Prime SDK +export interface UserOpTransaction { + chainId: number; + sender: string; + target?: string | null; + transactionHash: string; + userOpHash: string; + actualGasCost: number; + actualGasUsed: number; + success: TransactionStatuses; + timestamp: number; + paymaster: string; + value: number; + blockExplorerUrl: string; + input: string; + nonce: number; + initCode?: string; + callData?: string; + accountGasLimits?: string; + gasFees?: string; + callGasLimit: BigNumber; + verificationGasLimit: BigNumber; + preVerificationGas: BigNumber; + maxFeePerGas: BigNumber; + maxPriorityFeePerGas: BigNumber; + paymasterAndData?: string; + signature?: string; + beneficiary?: string; + nativeTransfers?: EtherspotNativeTransfersEntity[]; + erc20Transfers?: EtherspotErc20TransfersEntity[]; + nftTransfers?: EtherspotNftTransfersEntity[]; +} + export type AccountTemplate = 'etherspot' | 'zeroDev' | 'simpleAccount';