Skip to content

Commit 303ad53

Browse files
authored
Merge pull request #2904 from input-output-hk/feature/ddw-942-display-ascii-when-token-has-no-name
[DDW-942] Design ASCII display for when a token doesn't have a name
2 parents 7096a23 + 6bf03d9 commit 303ad53

File tree

6 files changed

+103
-7
lines changed

6 files changed

+103
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

7+
- Added ASCII name to token header when metadata name is missing ([PR 2904](https://github.com/input-output-hk/daedalus/pull/2904))
78
- Improved IPC by reducing the amount of messages from periodic events ([PR 2892](https://github.com/input-output-hk/daedalus/pull/2892))
89
- Improved RTS flags splash screen message ([PR 2901](https://github.com/input-output-hk/daedalus/pull/2901))
910
- Implemented error message when trying to leave wallet without enough ada to support tokens ([PR 2783](https://github.com/input-output-hk/daedalus/pull/2783))

source/renderer/app/components/assets/Asset.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
overflow: hidden;
7676
text-overflow: ellipsis;
7777
white-space: nowrap;
78+
79+
&.ascii {
80+
color: var(--theme-tokens-list-header-text-color);
81+
}
7882
}
7983

8084
.metadata {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import React from 'react';
2+
import BigNumber from 'bignumber.js';
3+
import { render, screen, cleanup } from '@testing-library/react';
4+
import '@testing-library/jest-dom';
5+
import Asset from './Asset';
6+
import { TestDecorator } from '../../../../../tests/_utils/TestDecorator';
7+
8+
const assetWithMetadataName = {
9+
policyId: 'policyId',
10+
assetName: '54657374636f696e',
11+
quantity: new BigNumber(1),
12+
fingerprint: 'fingerprint',
13+
metadata: {
14+
name: 'Testcoin',
15+
description: 'Test coin',
16+
},
17+
uniqueId: 'uniqueId',
18+
decimals: 1,
19+
recommendedDecimals: null,
20+
};
21+
const assetWitoutMetadataName = {
22+
policyId: 'policyId',
23+
assetName: '436f696e74657374',
24+
quantity: new BigNumber(1),
25+
fingerprint: 'fingerprint',
26+
uniqueId: 'uniqueId',
27+
decimals: 1,
28+
recommendedDecimals: null,
29+
};
30+
const assetWithoutName = {
31+
policyId: 'policyId',
32+
assetName: '',
33+
quantity: new BigNumber(1),
34+
fingerprint: 'fingerprint',
35+
uniqueId: 'uniqueId',
36+
decimals: 1,
37+
recommendedDecimals: null,
38+
};
39+
40+
describe('Asset', () => {
41+
afterEach(cleanup);
42+
43+
test('Should display asset metadata name', () => {
44+
render(
45+
<TestDecorator>
46+
<Asset asset={assetWithMetadataName} />
47+
</TestDecorator>
48+
);
49+
expect(screen.queryByTestId('assetName')).toHaveTextContent('Testcoin');
50+
});
51+
52+
test('Should display asset ASCII name when metadata name is not available', () => {
53+
render(
54+
<TestDecorator>
55+
<Asset asset={assetWitoutMetadataName} />
56+
</TestDecorator>
57+
);
58+
expect(screen.queryByTestId('assetName')).toHaveTextContent(
59+
'ASCII: Cointest'
60+
);
61+
});
62+
63+
test('Should not display asset name when metadata and ASCII name are not available', () => {
64+
render(
65+
<TestDecorator>
66+
<Asset asset={assetWithoutName} />
67+
</TestDecorator>
68+
);
69+
expect(screen.queryByTestId('assetName')).toBeNull();
70+
});
71+
});

source/renderer/app/components/assets/Asset.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { PopOver } from 'react-polymorph/lib/components/PopOver';
55
import { defineMessages, intlShape } from 'react-intl';
66
import { observer } from 'mobx-react';
77
import styles from './Asset.scss';
8-
import { ellipsis } from '../../utils/strings';
8+
import { ellipsis, hexToString } from '../../utils/strings';
99
import AssetContent from './AssetContent';
1010
import settingsIcon from '../../assets/images/asset-token-settings-ic.inline.svg';
1111
import warningIcon from '../../assets/images/asset-token-warning-ic.inline.svg';
@@ -173,8 +173,20 @@ class Asset extends Component<Props, State> {
173173
hasWarning,
174174
hasError,
175175
} = this.props;
176-
const { fingerprint, metadata, decimals, recommendedDecimals } = asset;
177-
const { name } = metadata || {};
176+
const {
177+
fingerprint,
178+
metadata,
179+
decimals,
180+
recommendedDecimals,
181+
assetName,
182+
} = asset;
183+
const hasMetadataName = !!metadata?.name;
184+
const name =
185+
metadata?.name || (assetName && `ASCII: ${hexToString(assetName)}`) || '';
186+
187+
const displayName = metadataNameChars
188+
? ellipsis(name, metadataNameChars)
189+
: name;
178190
const contentStyles = classnames([
179191
styles.pill,
180192
hasError ? styles.error : null,
@@ -196,9 +208,15 @@ class Asset extends Component<Props, State> {
196208
? fingerprint
197209
: ellipsis(fingerprint || '', startCharAmount, endCharAmount)}
198210
</div>
199-
{name && (
200-
<div className={styles.metadataName}>
201-
{metadataNameChars ? ellipsis(name, metadataNameChars) : name}
211+
{displayName && (
212+
<div
213+
data-testid="assetName"
214+
className={classnames(
215+
styles.metadataName,
216+
!hasMetadataName && styles.ascii
217+
)}
218+
>
219+
{displayName}
202220
</div>
203221
)}
204222
{hasWarning && (

source/renderer/app/components/wallet/tokens/wallet-token/WalletTokenHeader.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
.favoriteIcon {
1818
border-radius: 3px;
1919
cursor: pointer;
20+
flex-shrink: 0;
2021
height: 22px;
2122
margin-left: 10px;
2223
opacity: 0.3;
@@ -50,6 +51,7 @@
5051
.asset {
5152
margin-left: 10px;
5253
margin-right: auto;
54+
overflow: hidden;
5355
width: auto;
5456
}
5557

storybook/stories/wallets/tokens/WalletTokens.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const assets = [
3636
// @ts-ignore ts-migrate(2554) FIXME: Expected 7 arguments, but got 4.
3737
generateAssetToken(
3838
'65bc72542b0ca20391caaf66a4d4d7897d281f9c136cd3513136945b',
39-
'',
39+
'546f6b656e2077697468206c61726765206e616d65',
4040
'tokenb0ca20391caaf66a4d4d7897d281f9c136cd3513136945b2342',
4141
400
4242
),

0 commit comments

Comments
 (0)