diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a0a025..2d94062 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- [Added provider constants and getTransactions API call](https://github.com/multiversx/mx-sdk-dapp-core/pull/50) - [Added pending transactions](https://github.com/multiversx/mx-sdk-dapp-core/pull/48) - [Added transaction manager](https://github.com/multiversx/mx-sdk-dapp-core/pull/41) - [Added custom web socket url support](https://github.com/multiversx/mx-sdk-dapp-core/pull/35) diff --git a/src/apiCalls/transactions/getTransactions.ts b/src/apiCalls/transactions/getTransactions.ts new file mode 100644 index 0000000..913b631 --- /dev/null +++ b/src/apiCalls/transactions/getTransactions.ts @@ -0,0 +1,63 @@ +import axios from 'axios'; +import { TRANSACTIONS_ENDPOINT } from 'apiCalls/endpoints'; +import { TransactionServerStatusesEnum } from 'types/enums.types'; +import { ServerTransactionType } from 'types/serverTransactions.types'; + +export interface GetTransactionsType { + apiAddress: string; + apiTimeout?: string | number; + sender?: string; + receiver?: string; + page?: number; + transactionSize?: number; + after?: number; + condition?: 'should' | 'must'; + before?: number; + withScResults?: boolean; + withUsername?: boolean; + status?: TransactionServerStatusesEnum; + /** + * Search in data object + */ + search?: string; +} + +export const getTransactions = ({ + apiAddress, + apiTimeout, + sender, + receiver, + page = 1, + transactionSize = 15, + condition = 'should', + withScResults = true, + after, + before, + search, + status, + withUsername +}: GetTransactionsType) => { + const params = { + sender, + receiver, + condition, + after, + before, + search, + from: (page - 1) * transactionSize, + ...(transactionSize > 0 ? { size: transactionSize } : {}), + withScResults, + withUsername, + status + }; + + const timeout = apiTimeout ? { timeout: parseInt(String(apiTimeout)) } : {}; + + return axios.get( + `${apiAddress}/${TRANSACTIONS_ENDPOINT}`, + { + params, + ...timeout + } + ); +}; diff --git a/src/constants/index.ts b/src/constants/index.ts index f5f3b16..9f201b0 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -1,8 +1,9 @@ +export * from './browser.constants'; +export * from './errorMessages.constants'; +export * from './ledger.constants'; +export * from './mvx.constants'; export * from './network.constants'; export * from './placeholders.constants'; export * from './storage.constants'; +export * from './webWalletProvider.constants'; export * from './window.constants'; -export * from './browser.constants'; -export * from './errorMessages.constants'; -export * from './mvx.constants'; -export * from './ledger.constants'; diff --git a/src/constants/webWalletProvider.constants.ts b/src/constants/webWalletProvider.constants.ts new file mode 100644 index 0000000..7684df0 --- /dev/null +++ b/src/constants/webWalletProvider.constants.ts @@ -0,0 +1,12 @@ +export { + WALLET_PROVIDER_MAINNET, + WALLET_PROVIDER_DEVNET, + WALLET_PROVIDER_TESTNET, + WALLET_PROVIDER_CONNECT_URL, + WALLET_PROVIDER_DISCONNECT_URL, + WALLET_PROVIDER_SEND_TRANSACTION_URL, + WALLET_PROVIDER_SIGN_TRANSACTION_URL, + WALLET_PROVIDER_SIGN_MESSAGE_URL, + WALLET_PROVIDER_CALLBACK_PARAM, + WALLET_PROVIDER_CALLBACK_PARAM_TX_SIGNED +} from '@multiversx/sdk-web-wallet-provider'; \ No newline at end of file