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

feat(frontend): add IC transactions in AllTransactionsList #3589

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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import { ethTransactionsStore } from '$eth/stores/eth-transactions.store';
import type { EthTransactionUi } from '$eth/types/eth-transaction';
import IcTransactionModal from '$icp/components/transactions/IcTransactionModal.svelte';
import { btcStatusesStore } from '$icp/stores/btc.store';
import { icTransactionsStore } from '$icp/stores/ic-transactions.store';
import type { IcTransactionUi } from '$icp/types/ic-transaction';
import { ckEthMinterInfoStore } from '$icp-eth/stores/cketh.store';
import TransactionsPlaceholder from '$lib/components/transactions/TransactionsPlaceholder.svelte';
Expand All @@ -24,15 +26,14 @@
import { mapAllTransactionsUi, sortTransactions } from '$lib/utils/transactions.utils';

let transactions: AllTransactionsUi;
// TODO: add icTransactions and btcStatuses
$: transactions = mapAllTransactionsUi({
tokens: $enabledTokens,
$btcTransactions: $btcTransactionsStore,
$ethTransactions: $ethTransactionsStore,
$ckEthMinterInfo: $ckEthMinterInfoStore,
$ethAddress: $ethAddress,
$icTransactions: {},
$btcStatuses: {}
$icTransactions: $icTransactionsStore,
$btcStatuses: $btcStatusesStore
});

let sortedTransactions: AllTransactionsUi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import * as networkEnv from '$env/networks.env';
import { ETHEREUM_NETWORK_ID, SEPOLIA_NETWORK_ID } from '$env/networks.env';
import * as ethEnv from '$env/networks.eth.env';
import { BTC_MAINNET_TOKEN_ID } from '$env/tokens.btc.env';
import { ETHEREUM_TOKEN_ID } from '$env/tokens.env';
import { ETHEREUM_TOKEN_ID, ICP_TOKEN_ID } from '$env/tokens.env';
import { ethTransactionsStore } from '$eth/stores/eth-transactions.store';
import { icTransactionsStore } from '$icp/stores/ic-transactions.store';
import AllTransactionsList from '$lib/components/transactions/AllTransactionsList.svelte';
import * as transactionsUtils from '$lib/utils/transactions.utils';
import { createMockBtcTransactionsUi } from '$tests/mocks/btc.mock';
import { createMockEthTransactions } from '$tests/mocks/eth-transactions.mock';
import en from '$tests/mocks/i18n.mock';
import { createMockIcTransactionsUi } from '$tests/mocks/ic-transactions.mock';
import { render } from '@testing-library/svelte';

describe('AllTransactionsList', () => {
Expand All @@ -35,8 +37,9 @@ describe('AllTransactionsList', () => {
describe('when the transactions list is not empty', () => {
const btcTransactionsNumber = 5;
const ethTransactionsNumber = 3;
const icTransactionsNumber = 7;

beforeEach(() => {
beforeAll(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it expected to run it just once now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes indeed! since I just want to set once for the entire test, I just need the stores to be non-empty for all of them

vi.resetAllMocks();

vi.spyOn(btcEnv, 'BTC_MAINNET_ENABLED', 'get').mockImplementation(() => true);
Expand All @@ -46,19 +49,27 @@ describe('AllTransactionsList', () => {
ETHEREUM_NETWORK_ID,
SEPOLIA_NETWORK_ID
]);
});

btcTransactionsStore.append({
tokenId: BTC_MAINNET_TOKEN_ID,
transactions: createMockBtcTransactionsUi(btcTransactionsNumber).map((transaction) => ({
data: transaction,
certified: false
}))
});

ethTransactionsStore.add({
tokenId: ETHEREUM_TOKEN_ID,
transactions: createMockEthTransactions(ethTransactionsNumber)
btcTransactionsStore.append({
tokenId: BTC_MAINNET_TOKEN_ID,
transactions: createMockBtcTransactionsUi(btcTransactionsNumber).map((transaction) => ({
data: transaction,
certified: false
}))
});

ethTransactionsStore.add({
tokenId: ETHEREUM_TOKEN_ID,
transactions: createMockEthTransactions(ethTransactionsNumber)
});

icTransactionsStore.append({
tokenId: ICP_TOKEN_ID,
transactions: createMockIcTransactionsUi(icTransactionsNumber).map((transaction) => ({
data: transaction,
certified: false
}))
});
});

it('should not render the placeholder', () => {
Expand All @@ -74,7 +85,9 @@ describe('AllTransactionsList', () => {
(el) => el.parentElement === container
);

expect(transactionComponents).toHaveLength(btcTransactionsNumber + ethTransactionsNumber);
expect(transactionComponents).toHaveLength(
btcTransactionsNumber + ethTransactionsNumber + icTransactionsNumber
);
});
});
});
3 changes: 2 additions & 1 deletion src/frontend/src/tests/mocks/ic-transactions.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const createMockIcTransactionsUi = (n: number): IcTransactionUi[] =>
Array.from({ length: n }, () => ({
id: crypto.randomUUID(),
type: 'send',
status: 'executed'
status: 'executed',
value: BigInt(1)
}));