Skip to content

Commit e540c01

Browse files
authored
Public tags: protocol tag for transaction list (#3182)
Resolves #2976
1 parent bc878ba commit e540c01

17 files changed

+106
-14
lines changed

mocks/txs/tx.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/* eslint-disable max-len */
2+
import type { AddressParam } from 'types/api/addressParams';
23
import type { Transaction } from 'types/api/transaction';
34

45
import * as addressMock from 'mocks/address/address';
56
import { publicTag, privateTag, watchlistName } from 'mocks/address/tag';
67
import * as interopMock from 'mocks/interop/interop';
8+
import { protocolTag } from 'mocks/metadata/address';
79
import * as tokenTransferMock from 'mocks/tokens/tokenTransfer';
810
import * as decodedInputDataMock from 'mocks/txs/decodedInputData';
911

@@ -88,8 +90,24 @@ export const withWatchListNames: Transaction = {
8890
} as Transaction['to'],
8991
};
9092

93+
export const withProtocolTag: Transaction = {
94+
...base,
95+
hash: '0x62d597ebcf3e8d60096dd0363bc2f0f5e2df27ba1dacd696c51aa7c9409f3194',
96+
to: {
97+
...(base.to as AddressParam),
98+
metadata: {
99+
tags: [ protocolTag ],
100+
reputation: null,
101+
},
102+
private_tags: [],
103+
watchlist_names: [],
104+
public_tags: [],
105+
},
106+
};
107+
91108
export const withPendingUpdate: Transaction = {
92-
...withWatchListNames,
109+
...withProtocolTag,
110+
hash: '0x62d597ebcf3e8d60096dd0363bc2f0f5e2df27ba1dacd696c51aa7c9409f3133',
93111
is_pending_update: true,
94112
};
95113

ui/home/LatestTxs.pw.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import { Box } from '@chakra-ui/react';
12
import React from 'react';
23

4+
import type { AddressParam } from 'types/api/addressParams';
5+
36
import * as txMock from 'mocks/txs/tx';
47
import * as socketServer from 'playwright/fixtures/socketServer';
58
import { test as base, expect, devices } from 'playwright/lib';
9+
import * as pwConfig from 'playwright/utils/config';
610

711
import LatestTxs from './LatestTxs';
812

@@ -37,6 +41,50 @@ test('default view +@dark-mode', async({ render, mockApiResponse }) => {
3741
await expect(component).toHaveScreenshot();
3842
});
3943

44+
test.describe('small desktop', () => {
45+
test.use({ viewport: pwConfig.viewport.md });
46+
test('one tag', async({ render, mockApiResponse }) => {
47+
await mockApiResponse('general:homepage_txs', [
48+
{
49+
...txMock.withProtocolTag,
50+
to: {
51+
...txMock.withProtocolTag.to,
52+
metadata: {
53+
tags: [ {
54+
slug: 'aerodrome',
55+
name: 'Very long protocol name that should be truncated',
56+
tagType: 'protocol',
57+
ordinal: 0,
58+
meta: null,
59+
} ],
60+
reputation: null,
61+
},
62+
} as AddressParam,
63+
},
64+
]);
65+
66+
const component = await render(
67+
<Box maxW="800px">
68+
<LatestTxs/>
69+
</Box>,
70+
);
71+
await expect(component).toHaveScreenshot();
72+
});
73+
74+
test('two or more tags', async({ render, mockApiResponse }) => {
75+
await mockApiResponse('general:homepage_txs', [
76+
txMock.withWatchListNames,
77+
]);
78+
79+
const component = await render(
80+
<Box maxW="800px">
81+
<LatestTxs/>
82+
</Box>,
83+
);
84+
await expect(component).toHaveScreenshot();
85+
});
86+
});
87+
4088
test.describe('socket', () => {
4189
test.describe.configure({ mode: 'serial' });
4290

ui/home/LatestTxsItem.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import config from 'configs/app';
1313
import { Skeleton } from 'toolkit/chakra/skeleton';
1414
import AddressFromTo from 'ui/shared/address/AddressFromTo';
1515
import TxEntity from 'ui/shared/entities/tx/TxEntity';
16+
import EntityTag from 'ui/shared/EntityTags/EntityTag';
1617
import TxStatus from 'ui/shared/statusTag/TxStatus';
1718
import TimeWithTooltip from 'ui/shared/time/TimeWithTooltip';
1819
import TxFee from 'ui/shared/tx/TxFee';
@@ -30,15 +31,25 @@ const LatestTxsItem = ({ tx, isLoading }: Props) => {
3031
const dataTo = tx.to ? tx.to : tx.created_contract;
3132
const columnNum = config.UI.views.tx.hiddenFields?.value && config.UI.views.tx.hiddenFields?.tx_fee ? 2 : 3;
3233

34+
const protocolTag = tx.to?.metadata?.tags?.find(tag => tag.tagType === 'protocol');
35+
36+
const tagsCount = [
37+
1, // tx type
38+
1, // tx status
39+
...(tx.from?.watchlist_names || []),
40+
...(tx.to?.watchlist_names || []),
41+
protocolTag,
42+
].filter(Boolean).length;
43+
3344
return (
3445
<Grid
3546
gridTemplateColumns={{
36-
lg: columnNum === 2 ? '3fr minmax(auto, 180px)' : '3fr minmax(auto, 180px) 170px',
37-
xl: columnNum === 2 ? '3fr minmax(auto, 250px)' : '3fr minmax(auto, 275px) 170px',
47+
lg: columnNum === 2 ? '3fr minmax(auto, 200px)' : '3fr minmax(auto, 200px) 170px',
48+
xl: columnNum === 2 ? '3fr minmax(auto, 270px)' : '3fr minmax(auto, 300px) 170px',
3849
}}
39-
gridGap={ 8 }
50+
gridGap={ 3 }
4051
width="100%"
41-
minW="700px"
52+
minW={ columnNum === 2 ? '700px' : '750px' }
4253
borderBottom="1px solid"
4354
borderColor="border.divider"
4455
p={ 4 }
@@ -47,10 +58,11 @@ const LatestTxsItem = ({ tx, isLoading }: Props) => {
4758
<Flex overflow="hidden" w="100%">
4859
<TxAdditionalInfo tx={ tx } isLoading={ isLoading } my="3px"/>
4960
<Box ml={ 3 } w="calc(100% - 40px)">
50-
<HStack flexWrap="wrap" my="3px">
61+
<HStack flexWrap={ tagsCount <= 3 ? 'nowrap' : 'wrap' } my="3px">
5162
<TxType types={ tx.transaction_types } isLoading={ isLoading }/>
5263
<TxStatus status={ tx.status } errorText={ tx.status === 'error' ? tx.result : undefined } isLoading={ isLoading }/>
5364
<TxWatchListTags tx={ tx } isLoading={ isLoading }/>
65+
{ protocolTag && <EntityTag data={ protocolTag } isLoading={ isLoading } minW="0"/> }
5466
</HStack>
5567
<Flex
5668
alignItems="center"

ui/home/LatestTxsItemMobile.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import config from 'configs/app';
1313
import { Skeleton } from 'toolkit/chakra/skeleton';
1414
import AddressFromTo from 'ui/shared/address/AddressFromTo';
1515
import TxEntity from 'ui/shared/entities/tx/TxEntity';
16+
import EntityTag from 'ui/shared/EntityTags/EntityTag';
1617
import TxStatus from 'ui/shared/statusTag/TxStatus';
1718
import TimeWithTooltip from 'ui/shared/time/TimeWithTooltip';
1819
import TxFee from 'ui/shared/tx/TxFee';
@@ -29,6 +30,8 @@ type Props = {
2930
const LatestTxsItem = ({ tx, isLoading }: Props) => {
3031
const dataTo = tx.to ? tx.to : tx.created_contract;
3132

33+
const protocolTag = tx.to?.metadata?.tags?.find(tag => tag.tagType === 'protocol');
34+
3235
return (
3336
<Box
3437
width="100%"
@@ -38,10 +41,11 @@ const LatestTxsItem = ({ tx, isLoading }: Props) => {
3841
display={{ base: 'block', lg: 'none' }}
3942
>
4043
<Flex justifyContent="space-between">
41-
<HStack flexWrap="wrap">
44+
<HStack>
4245
<TxType types={ tx.transaction_types } isLoading={ isLoading }/>
4346
<TxStatus status={ tx.status } errorText={ tx.status === 'error' ? tx.result : undefined } isLoading={ isLoading }/>
4447
<TxWatchListTags tx={ tx } isLoading={ isLoading }/>
48+
{ protocolTag && <EntityTag data={ protocolTag } isLoading={ isLoading } minW="0"/> }
4549
</HStack>
4650
<TxAdditionalInfo tx={ tx } isMobile isLoading={ isLoading }/>
4751
</Flex>
1.17 KB
Loading
1.21 KB
Loading
21.1 KB
Loading
23.2 KB
Loading
961 Bytes
Loading
563 Bytes
Loading

0 commit comments

Comments
 (0)