Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- [Removed index file from apiCalls folder](https://github.com/multiversx/mx-sdk-dapp/pull/1663)
- [~~Removed unused~~ Added comment togetActiveTransactionsStatus method](https://github.com/multiversx/mx-sdk-dapp/pull/1662)
- [Fixed coverage badge title](https://github.com/multiversx/mx-sdk-dapp/pull/1661)
- [Fixed coverage badge](https://github.com/multiversx/mx-sdk-dapp/pull/1660)

Expand Down
2 changes: 1 addition & 1 deletion coverage-total.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schemaVersion": 1,
"label": "Coverage",
"message": "75.85%",
"message": "76.71%",
"color": "yellow"
}
3 changes: 3 additions & 0 deletions scripts/template-dapps-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ git clone https://github.com/multiversx/mx-template-dapp.git
echo "cd mx-template-dapp..."
cd mx-template-dapp

echo "git checkout development..."
git checkout development

echo "Installing dependencies mx-template-dapp..."
yarn install

Expand Down
1 change: 1 addition & 0 deletions src/__mocks__/data/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './account';
export * from './testToken';
export * from './networkConfig';
export * from './dappConfig';
export * from './socketResponse';
Expand Down
62 changes: 62 additions & 0 deletions src/__mocks__/data/testToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { testAddress } from '__mocks__/accountConfig';

export const testToken = {
type: 'FungibleESDT',
identifier: 'TEST-e3d1b7',
name: 'TEST',
ticker: 'TEST',
owner: testAddress,
minted: '0',
burnt: '0',
initialMinted: '1000000000000000000000000000',
decimals: 18,
isPaused: false,
assets: {
website: 'https://test.io',
description: 'Test token is a test token for testing the token details.',
status: 'active',
pngUrl:
'https://tools.multiversx.com/assets-cdn/devnet/tokens/TEST-e3d1b7/icon.png',
svgUrl:
'https://tools.multiversx.com/assets-cdn/devnet/tokens/TEST-e3d1b7/icon.svg',
lockedAccounts: {
[testAddress]: 'Locked Account #1'
},
extraTokens: ['TEST-e3d1b7', 'TEST-e3d1b7'],
ledgerSignature:
'30450221009c58ae35af3a770221bd6e1fd8ad023d23e49e52cbca64f1a225c497935ee30402203fc97dae339a44872bc0415e684c35e0990720ba977ce6dabebfe72e6dc37591',
social: {
email: 'hello@test.io',
blog: 'https://medium.com/@test',
twitter: 'https://twitter.com/test',
telegram: 'https://t.me/test',
discord: 'https://discord.gg/test'
}
},
transactions: 1754,
transactionsLastUpdatedAt: 1762511057,
transfers: 40882,
transfersLastUpdatedAt: 1762511183,
accounts: 416,
accountsLastUpdatedAt: 1762513938,
canUpgrade: true,
canMint: false,
canBurn: false,
canChangeOwner: true,
canAddSpecialRoles: true,
canPause: true,
canFreeze: true,
canWipe: true,
price: 3.114724747645395,
marketCap: 3114724747.6453953,
supply: '1000000000',
circulatingSupply: '1000000000',
mexPairType: 'core',
totalLiquidity: 1963.9864633925347,
totalVolume24h: 0,
isLowLiquidity: true,
lowLiquidityThresholdPercent: 0.5,
tradesCount: 8273,
balance: '663088410050705591065',
valueUsd: 2065.3378806617707
};
5 changes: 5 additions & 0 deletions src/__mocks__/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
socketResponse,
websocketConfig
} from './data';
import { testToken } from './data/testToken';
import { wrapEgldContract } from './data/wrapEgldContract';

export const mockResponse =
Expand Down Expand Up @@ -49,6 +50,10 @@ const handlers = [
`${testNetwork.apiAddress}/accounts/${testAddress}`,
mockResponse(account)
),
rest.get(
`${testNetwork.apiAddress}/tokens/${testToken.identifier}`,
mockResponse(testToken)
),
rest.get(
`${testNetwork.apiAddress}/accounts/${wrapEgldContract.address}`,
mockResponse(wrapEgldContract)
Expand Down
2 changes: 1 addition & 1 deletion src/apiCalls/account/getScamAddressData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
import { getCleanApiAddress } from 'apiCalls/utils';
import { getCleanApiAddress } from 'apiCalls/utils/getCleanApiAddress';
import { TIMEOUT } from 'constants/index';
import { ScamInfoType } from 'types/account.types';
import { ACCOUNTS_ENDPOINT } from '../endpoints';
Expand Down
1 change: 0 additions & 1 deletion src/apiCalls/account/index.ts

This file was deleted.

48 changes: 48 additions & 0 deletions src/apiCalls/account/tests/getAccountFromApi.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { server, rest, testNetwork } from '__mocks__';
import { ACCOUNTS_ENDPOINT } from 'apiCalls/endpoints';
import { getAccountFromApi } from '../getAccountFromApi';

describe('getAccountFromApi tests', () => {
afterEach(() => {
server.resetHandlers();
});
it('should return null when address is empty', async () => {
const account = await getAccountFromApi({
address: '',
baseURL: testNetwork.apiAddress
});
expect(account).toBeNull();
});
it('should return null and log an error if account is not found', async () => {
const missingAccountAddress =
'erd1qqqqqqqqqqqqqpgqc978caxxxxxxxxxxxxxxxxxxxxxxxxxxxxplllss';

const consoleSpy = jest
.spyOn(console, 'error')
.mockImplementation(() => undefined);

server.use(
rest.get(
`${testNetwork.apiAddress}/${ACCOUNTS_ENDPOINT}/${missingAccountAddress}`,
(_req, res, ctx) => {
return res(ctx.status(404), ctx.json({ error: 'account not found' }));
}
)
);

try {
const account = await getAccountFromApi({
address: missingAccountAddress,
baseURL: testNetwork.apiAddress
});

expect(account).toBeNull();
expect(consoleSpy).toHaveBeenCalledWith(
'error fetching configuration for ',
missingAccountAddress
);
} finally {
consoleSpy.mockRestore();
}
});
});
3 changes: 1 addition & 2 deletions src/apiCalls/configuration/getGasStationMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from 'axios';
import { getCleanApiAddress } from 'apiCalls/configuration/getCleanApiAddress';
import { GAS_STATION_ENDPOINT } from 'apiCalls/endpoints';
import { NetworkType } from 'types/network.types';

interface IGasStationApiResponse {
Expand All @@ -8,8 +9,6 @@ interface IGasStationApiResponse {
faster: number;
}

const GAS_STATION_ENDPOINT = 'transactions/ppu';

export async function getGasStationMetadataFromApi(
shard: number,
customApiAddress?: string
Expand Down
2 changes: 0 additions & 2 deletions src/apiCalls/configuration/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/apiCalls/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const ROLES_ENDPOINT = 'roles';
export const SC_RESULTS_ENDPOINT = 'sc-results';
export const STAKE_ENDPOINT = 'stake';
export const TOKENS_ENDPOINT = 'tokens';
export const GAS_STATION_ENDPOINT = 'transactions/ppu';
export const TRANSACTIONS_COUNT_ENDPOINT = 'transactions/count';
export const TRANSACTIONS_BATCH = 'batch';
export const TRANSACTIONS_ENDPOINT = 'transactions';
Expand Down
6 changes: 0 additions & 6 deletions src/apiCalls/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/apiCalls/tokens/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const tx = {
};

describe('getServerTransactionsByHashes', () => {
afterEach(() => {
server.resetHandlers();
});

it('returns transactions for provided hashes', async () => {
const hash = tx.txHash;

Expand Down
3 changes: 3 additions & 0 deletions src/apiCalls/transactions/tests/getTransactionByHash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ describe('getTransactionByHash', () => {
jest.resetAllMocks();
(networkSelector as jest.Mock).mockReturnValue(testNetwork);
});
afterEach(() => {
server.resetHandlers();
});

it('returns a transaction for the provided hash', async () => {
// Use MSW to intercept the request to testNetwork.apiAddress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ describe('getTransactionsByHashes test', () => {
}
});
});
afterEach(() => {
server.resetHandlers();
});

it('maps server transactions to tracked results for provided pending hashes', async () => {
const pending = { ...mockPendingTransaction };
Expand Down
3 changes: 0 additions & 3 deletions src/apiCalls/utils/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/apiCalls/websocket/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { testAddress } from '__mocks__';
import { account } from '__mocks__/data';
import { account, testToken } from '__mocks__/data';
import { getPersistedTokenDetails } from 'apiCalls/tokens/getPersistedTokenDetails';
import { AssetType } from 'types/account.types';
import { TransactionServerStatusesEnum } from 'types/enums.types';
Expand Down Expand Up @@ -27,7 +27,7 @@ jest.mock('utils/operations/timeRemaining', () => ({

const mockTransactionBase: ServerTransactionType = {
txHash: 'tx1',
tokenIdentifier: 'TEST-123',
tokenIdentifier: testToken.identifier,
sender: testAddress,
receiver: account.address,
senderShard: 0,
Expand Down Expand Up @@ -85,6 +85,14 @@ const mockParams = {
};

describe('TransactionsTableController', () => {
beforeEach(() => {
(getPersistedTokenDetails as jest.Mock).mockResolvedValue({
assets: {
lockedAccounts: {}
}
});
});

it('should handle locked accounts', async () => {
(getPersistedTokenDetails as jest.Mock).mockResolvedValue({
assets: {
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './apiCalls';
export * from './controllers';
export * from './constants';
export * from './services';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('createToastsFromTransactions', () => {

afterEach(() => {
jest.spyOn(Date, 'now').mockRestore();
server.resetHandlers();
});

const mockTransactionsEndpoint = (
Expand Down
3 changes: 3 additions & 0 deletions src/managers/ToastManager/tests/ToastManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ describe('ToastManager subscription reacts to transaction completion', () => {
)
);
});
afterEach(() => {
server.resetHandlers();
});

it('moves toast from pending to completed when status changes to success and starts lifetime', async () => {
const startTime = 1_700_000_000_000; // arbitrary
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { io } from 'socket.io-client';
import { getWebsocketUrl } from 'apiCalls/websocket';
import { getWebsocketUrl } from 'apiCalls/websocket/getWebsocketUrl';
import {
WebsocketConnectionStatusEnum,
websocketConnection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HWProvider } from '@multiversx/sdk-hw-provider/out';
import { BigNumber } from 'bignumber.js';

import { ACCOUNTS_ENDPOINT } from 'apiCalls';
import { ACCOUNTS_ENDPOINT } from 'apiCalls/endpoints';
import { IEventBus } from 'lib/sdkDappUi';
import { LedgerConnectStateManager } from 'managers/internal/LedgerConnectStateManager/LedgerConnectStateManager';
import { getExplorerAddress } from 'methods/network/getExplorerAddress';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumber } from 'bignumber.js';
import { ACCOUNTS_ENDPOINT } from 'apiCalls';
import { ACCOUNTS_ENDPOINT } from 'apiCalls/endpoints';
import { getPersistedTokenDetails } from 'apiCalls/tokens/getPersistedTokenDetails';
import { MULTI_TRANSFER_EGLD_TOKEN } from 'constants/mvx.constants';
import { safeWindow } from 'constants/window.constants';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getAccountFromApi } from 'apiCalls/account';
import { getAccountFromApi } from 'apiCalls/account/getAccountFromApi';
import { getScamAddressData } from 'apiCalls/account/getScamAddressData';
import { SigningErrorsEnum } from 'types/enums.types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { account, mockResponse, rest, server } from '__mocks__';
import {
testAddress,
testNetwork,
testReceiver
} from '__mocks__/accountConfig';
import { Transaction } from 'lib/sdkCore';
import {
MultiSignTransactionType,
Expand Down Expand Up @@ -32,7 +38,11 @@ jest.mock('methods/network/getExplorerAddress', () => ({
getExplorerAddress: jest.fn(() => 'http://devnet-explorer.multiversx.com')
}));

describe('getCommonData', () => {
describe('getCommonData tests', () => {
afterEach(() => {
server.resetHandlers();
});

it('should return the common data without ppu', async () => {
const commonData = await getCommonData({
...mockData,
Expand Down Expand Up @@ -110,6 +120,35 @@ describe('getCommonData', () => {
}
});
});
it('should work for transactions signed by guardian', async () => {
// Use MSW to intercept the request to testNetwork.apiAddress
server.use(
rest.get(
`${testNetwork.apiAddress}/accounts/${testAddress}`, // fetching the account of the sender
mockResponse({
...account,
activeGuardianAddress: testReceiver,
activeGuardianActivationEpoch: 351,
activeGuardianServiceUid: 'MultiversXSafeguard'
})
)
);
const customMockData = {
...mockData,
allTransactions: [
// keep one transaction
{
...mockGetCommonDataInput.allTransactions[0],
transaction: Transaction.newFromPlainObject(
mockGetCommonDataInput.allTransactions[0].transaction
)
}
],
address: testReceiver // we are logged in as the guardianAddress
};
const commonData = await getCommonData(customMockData);
expect(commonData.commonData.address).toBe(testReceiver);
});
});

describe('when the gas limit is updated', () => {
Expand Down
1 change: 1 addition & 0 deletions src/utils/transactions/getActiveTransactionsStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface GetActiveTransactionsStatusReturnType {
pending: boolean;
}

// This helper function is used in some projects like NextJS to check the active transaction status
export function getActiveTransactionsStatus(): GetActiveTransactionsStatusReturnType {
const state = getState();
const timedOutTransactions = timedOutTransactionsSelector(state);
Expand Down
Loading