Skip to content

Commit edcfacf

Browse files
authored
Merge pull request #2701 from input-output-hk/fix/ddw-694-token-toggle
[DDW-694] Fix token toggle
2 parents e916190 + fa9b2a1 commit edcfacf

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

CHANGELOG.md

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

55
### Features
66

7-
- Implemented the wallet Tokens dedicated screen ([PR 2671](https://github.com/input-output-hk/daedalus/pull/2671))
7+
- Implemented the wallet Tokens dedicated screen ([PR 2671](https://github.com/input-output-hk/daedalus/pull/2671), [PR 2701](https://github.com/input-output-hk/daedalus/pull/2701))
88

99
### Fixes
1010

source/renderer/app/components/wallet/tokens/WalletToken.js

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
2-
import React, { useState, useMemo } from 'react';
2+
import React, { useState, useMemo, useEffect } from 'react';
33
import { observer } from 'mobx-react';
44
import { defineMessages, intlShape, injectIntl } from 'react-intl';
55
import { Button } from 'react-polymorph/lib/components/Button';
@@ -66,6 +66,7 @@ type IsExpanded = boolean;
6666

6767
const WalletToken = observer((props: Props) => {
6868
const [isExpanded, setIsExpanded] = useState<IsExpanded>(false);
69+
const [arrowStyles, setArrowStyles] = useState<string | null>(null);
6970

7071
const toggleIsExpanded = () => {
7172
setIsExpanded(!isExpanded);
@@ -89,27 +90,13 @@ const WalletToken = observer((props: Props) => {
8990
onToggleFavorite,
9091
} = props;
9192

92-
const header = useMemo(() => {
93-
const { decimals, recommendedDecimals, uniqueId } = asset;
94-
const arrowStyles = classNames(styles.arrow, {
95-
[styles.isExpanded]: isExpanded,
96-
});
93+
const assetHeaderContent = useMemo(() => {
94+
const { decimals, recommendedDecimals } = asset;
9795
const hasWarning =
9896
typeof recommendedDecimals === 'number' &&
9997
decimals !== recommendedDecimals;
100-
const starIcon = isFavorite ? starFilledIcon : starNotFilledIcon;
10198
return (
102-
<div className={styles.header} onClick={toggleIsExpanded}>
103-
<button
104-
className={favoriteIconStyles}
105-
onClick={(event) => {
106-
event.persist();
107-
event.stopPropagation();
108-
onToggleFavorite({ uniqueId, isFavorite });
109-
}}
110-
>
111-
<SVGInline className={styles.warningIcon} svg={starIcon} />
112-
</button>
99+
<>
113100
<Asset
114101
asset={asset}
115102
onCopyAssetParam={onCopyAssetParam}
@@ -129,8 +116,7 @@ const WalletToken = observer((props: Props) => {
129116
className={styles.assetAmount}
130117
isShort
131118
/>
132-
<SVGInline svg={arrow} className={arrowStyles} />
133-
</div>
119+
</>
134120
);
135121
}, [
136122
anyAssetWasHovered,
@@ -142,6 +128,37 @@ const WalletToken = observer((props: Props) => {
142128
onToggleFavorite,
143129
]);
144130

131+
useEffect(
132+
() =>
133+
setArrowStyles(
134+
classNames(styles.arrow, {
135+
[styles.isExpanded]: isExpanded,
136+
})
137+
),
138+
[isExpanded]
139+
);
140+
141+
const header = useMemo(() => {
142+
const { uniqueId } = asset;
143+
const starIcon = isFavorite ? starFilledIcon : starNotFilledIcon;
144+
return (
145+
<div className={styles.header} onClick={toggleIsExpanded}>
146+
<button
147+
className={favoriteIconStyles}
148+
onClick={(event) => {
149+
event.persist();
150+
event.stopPropagation();
151+
onToggleFavorite({ uniqueId, isFavorite });
152+
}}
153+
>
154+
<SVGInline className={styles.warningIcon} svg={starIcon} />
155+
</button>
156+
{assetHeaderContent}
157+
<SVGInline svg={arrow} className={arrowStyles} />
158+
</div>
159+
);
160+
}, [asset, isExpanded, arrowStyles]);
161+
145162
const footer = useMemo(() => {
146163
return (
147164
<div className={styles.footer}>

0 commit comments

Comments
 (0)