Skip to content

Commit

Permalink
Merge pull request #50 from multiversx/rt/feature/dapp-template
Browse files Browse the repository at this point in the history
Added utils
  • Loading branch information
razvantomegea authored Dec 19, 2024
1 parent 7930928 commit 41db8a7
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
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';

0 comments on commit 41db8a7

Please sign in to comment.