Skip to content

Commit

Permalink
Added getTransactionsByHashes.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
razvantomegea committed Dec 4, 2024
1 parent 590c727 commit 9d77761
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/apiCalls/transactions/getTransactionsByHashes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import axios from 'axios';
import { TRANSACTIONS_ENDPOINT } from 'apiCalls/endpoints';

import { networkSelector } from 'store/selectors';
import { getState } from 'store/store';
import {
GetTransactionsByHashesReturnType,
PendingTransactionsType
} from 'types/transactions.types';

export const getTransactionsByHashes = async (
pendingTransactions: PendingTransactionsType
): Promise<GetTransactionsByHashesReturnType> => {
const { apiAddress } = networkSelector(getState());
const hashes = pendingTransactions.map((tx) => tx.hash);

const { data: responseData } = await axios.get(
`${apiAddress}/${TRANSACTIONS_ENDPOINT}`,
{
params: {
hashes: hashes.join(','),
withScResults: true
}
}
);

return pendingTransactions.map(({ hash, previousStatus }) => {
const txOnNetwork = responseData.find(
(txResponse: any) => txResponse?.txHash === hash
);

return {
hash,
data: txOnNetwork?.data,
invalidTransaction: txOnNetwork == null,
status: txOnNetwork?.status,
results: txOnNetwork?.results,
sender: txOnNetwork?.sender,
receiver: txOnNetwork?.receiver,
previousStatus,
hasStatusChanged: txOnNetwork && txOnNetwork.status !== previousStatus
};
});
};

0 comments on commit 9d77761

Please sign in to comment.