Skip to content

Commit

Permalink
feat(frontend): add token prop to transaction card components
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioVentilii committed Nov 14, 2024
1 parent 63ee792 commit 2d6f0dd
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import Transaction from '$lib/components/transactions/Transaction.svelte';
import { i18n } from '$lib/stores/i18n.store';
import { modalStore } from '$lib/stores/modal.store';
import type { Token } from '$lib/types/token';
export let transaction: BtcTransactionUi;
export let token: Token | undefined = undefined;
let value: bigint | undefined;
let timestamp: bigint | undefined;
Expand All @@ -26,6 +28,7 @@
{type}
timestamp={Number(timestamp)}
{status}
{token}
>
{label}
</Transaction>
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import { isSupportedEthToken } from '$eth/utils/eth.utils';
import { isTransactionPending } from '$eth/utils/transactions.utils';
import Transaction from '$lib/components/transactions/Transaction.svelte';
import { tokenSymbol } from '$lib/derived/token.derived';
import { i18n } from '$lib/stores/i18n.store';
import { modalStore } from '$lib/stores/modal.store';
import { token } from '$lib/stores/token.store';
import type { TransactionStatus } from '$lib/types/transaction';
import { replacePlaceholders } from '$lib/utils/i18n.utils';
import type { Token } from '$lib/types/token';

Check failure on line 12 in src/frontend/src/eth/components/transactions/EthTransaction.svelte

View workflow job for this annotation

GitHub Actions / lint

`$lib/types/token` type import should occur before type import of `$lib/types/transaction`
export let transaction: EthTransactionUi;
export let token: Token | undefined = undefined;
let value: BigNumber;
let timestamp: number | undefined;
Expand All @@ -28,10 +28,10 @@
$: ({ value, timestamp, displayTimestamp, uiType: type } = transaction);
let ckTokenSymbol: string;
$: ckTokenSymbol = isSupportedEthToken($token)
? $token.twinTokenSymbol
$: ckTokenSymbol = isSupportedEthToken(token)
? token.twinTokenSymbol
: // TODO: $token could be undefined, that's why we cast as `Erc20Token | undefined`; adjust the cast once we're sure that $token is never undefined
(($token as Erc20Token | undefined)?.twinTokenSymbol ?? '');
((token as Erc20Token | undefined)?.twinTokenSymbol ?? '');
let label: string;
$: label =
Expand All @@ -41,7 +41,7 @@
? $i18n.transaction.label.converting_ck_token
: $i18n.transaction.label.ck_token_converted,
{
$twinToken: $tokenSymbol ?? '',
$twinToken: token?.symbol ?? '',
$ckToken: ckTokenSymbol
}
)
Expand All @@ -51,7 +51,7 @@
? $i18n.transaction.label.converting_twin_token
: $i18n.transaction.label.ck_token_sent,
{
$twinToken: $tokenSymbol ?? '',
$twinToken: token?.symbol ?? '',
$ckToken: ckTokenSymbol
}
)
Expand All @@ -72,6 +72,7 @@
{type}
timestamp={transactionDate}
{status}
{token}
>
{label}
</Transaction>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import { modalStore } from '$lib/stores/modal.store';
import type { OptionEthAddress } from '$lib/types/address';
import type { Transaction as TransactionType } from '$lib/types/transaction';
import { token } from '$lib/stores/token.store';

Check failure on line 24 in src/frontend/src/eth/components/transactions/EthTransactions.svelte

View workflow job for this annotation

GitHub Actions / lint

`$lib/stores/token.store` import should occur before type import of `$lib/types/address`
let ckMinterInfoAddresses: OptionEthAddress[] = [];
$: ckMinterInfoAddresses = toCkMinterInfoAddresses({
Expand Down Expand Up @@ -49,7 +50,7 @@
<EthTransactionsSkeletons>
{#each sortedTransactionsUi as transaction (transaction.hash)}
<div transition:slide={SLIDE_DURATION}>
<EthTransaction {transaction} />
<EthTransaction {transaction} token={$token} />
</div>
{/each}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{#if nonNullish(transactions) && transactions.length > 0}
{#each transactions as transaction, index (`${transaction.id}-${index}`)}
<div in:slide={SLIDE_DURATION}>
<svelte:component this={transaction.component} {transaction} />
<svelte:component this={transaction.component} {transaction} token={transaction.token} />
</div>
{/each}
{/if}
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/lib/types/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
TransactionStatusSchema,
TransactionTypeSchema
} from '$lib/schema/transaction.schema';
import type { Token } from '$lib/types/token';
import type { TransactionResponse } from '@ethersproject/abstract-provider';
import type { BigNumber } from '@ethersproject/bignumber';
import type { FeeData } from '@ethersproject/providers';
Expand Down Expand Up @@ -36,5 +37,6 @@ export type TransactionUiCommon = Pick<Transaction, 'blockNumber' | 'from' | 'to
export type AnyTransactionUi = BtcTransactionUi | EthTransactionUi | IcTransactionUi;

export type AllTransactionsUi = (AnyTransactionUi & {
token: Token;
component: ComponentType;
})[];
9 changes: 8 additions & 1 deletion src/frontend/src/lib/utils/transactions.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ export const mapAllTransactionsUi = ({
networkId: SEPOLIA_NETWORK_ID
});

return tokens.reduce<AllTransactionsUi>((acc, { id: tokenId, network: { id: networkId } }) => {
return tokens.reduce<AllTransactionsUi>((acc, token) => {
const {
id: tokenId,
network: { id: networkId }
} = token;

if (isNetworkIdBTCMainnet(networkId)) {
if (isNullish($btcTransactions)) {
return acc;
Expand All @@ -63,6 +68,7 @@ export const mapAllTransactionsUi = ({
...acc,
...($btcTransactions[tokenId] ?? []).map(({ data: transaction }) => ({
...transaction,
token,
component: BtcTransaction
}))
];
Expand All @@ -82,6 +88,7 @@ export const mapAllTransactionsUi = ({
: ckEthMinterInfoAddressesMainnet,
$ethAddress: $ethAddress
}),
token,
component: EthTransaction
}))
];
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/src/tests/lib/utils/transactions.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('transactions.utils', () => {
const expectedBtcMainnetTransactions: AllTransactionsUi = [
...mockBtcMainnetTransactions.map((transaction) => ({
...transaction,
token: BTC_MAINNET_TOKEN,
component: BtcTransaction
}))
];
Expand All @@ -68,6 +69,7 @@ describe('transactions.utils', () => {
...transaction,
id: transaction.hash,
uiType,
token: ETHEREUM_TOKEN,
component: EthTransaction
}))
];
Expand All @@ -77,6 +79,7 @@ describe('transactions.utils', () => {
...transaction,
id: transaction.hash,
uiType,
token: SEPOLIA_TOKEN,
component: EthTransaction
}))
];
Expand All @@ -86,6 +89,7 @@ describe('transactions.utils', () => {
...transaction,
id: transaction.hash,
uiType,
token: PEPE_TOKEN,
component: EthTransaction
}))
];
Expand Down

0 comments on commit 2d6f0dd

Please sign in to comment.