Skip to content

Commit

Permalink
feat(frontend): add IC transactions in AllTransactionsList (#3589)
Browse files Browse the repository at this point in the history
# Motivation

After PR #3568, we add the IC transactions in the UI.
  • Loading branch information
AntonioVentilii authored Nov 15, 2024
1 parent 739464b commit 809e5dc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
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(() => {
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)
}));

0 comments on commit 809e5dc

Please sign in to comment.