Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added utils #50

Merged
merged 5 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
63 changes: 63 additions & 0 deletions src/apiCalls/transactions/getTransactions.ts
Original file line number Diff line number Diff line change
@@ -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<ServerTransactionType[]>(
`${apiAddress}/${TRANSACTIONS_ENDPOINT}`,
{
params,
...timeout
}
);
};
9 changes: 5 additions & 4 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -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';
12 changes: 12 additions & 0 deletions src/constants/webWalletProvider.constants.ts
Original file line number Diff line number Diff line change
@@ -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';
Loading