Skip to content

Commit af473a8

Browse files
authored
feat: [lw-12558] change btc wallet icon option to orange in dropdown (#1863)
* feat: [lw-12558] change btc wallet icon option to orange in dropdown * feat: [lw-12723] fix incorrect avatar image on active btc wallet
1 parent 9e5cf7d commit af473a8

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed

apps/browser-extension-wallet/src/components/DropdownMenu/DropdownMenu.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@
5353
.profileDropdownTrigger {
5454
flex-shrink: 0;
5555
}
56+
57+
.walletOptionBitcoin > div {
58+
background: var(--data-orange);
59+
}

apps/browser-extension-wallet/src/components/DropdownMenu/DropdownMenu.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { ProfileDropdown } from '@input-output-hk/lace-ui-toolkit';
1616
import { useWalletAvatar } from '@hooks';
1717
import { getUiWalletType } from '@src/utils/get-ui-wallet-type';
1818
import i18n from 'i18next';
19+
import { WalletType } from '@cardano-sdk/web-extension';
20+
import { useCurrentBlockchain, Blockchain } from '@src/multichain';
1921

2022
export interface DropdownMenuProps {
2123
isPopup?: boolean;
@@ -29,6 +31,7 @@ const addEllipsis = (text: string, length: number) => (text.length > length ? `$
2931

3032
export const DropdownMenu = ({ isPopup }: DropdownMenuProps): React.ReactElement => {
3133
const analytics = useAnalyticsContext();
34+
const { blockchain } = useCurrentBlockchain();
3235
const {
3336
walletUI: { isDropdownMenuOpen = false },
3437
setIsDropdownMenuOpen,
@@ -51,6 +54,19 @@ export const DropdownMenu = ({ isPopup }: DropdownMenuProps): React.ReactElement
5154

5255
useEffect(() => () => setIsDropdownMenuOpen(false), [setIsDropdownMenuOpen]);
5356

57+
const walletType = getUiWalletType(walletDisplayInfo?.walletType);
58+
59+
const isBitcoinWallet = walletDisplayInfo?.walletType !== WalletType.Script && blockchain === Blockchain.Bitcoin;
60+
const customBitcoinProfile = isBitcoinWallet
61+
? {
62+
customProfileComponent: (
63+
<span className={styles.walletOptionBitcoin}>
64+
<ProfileDropdown.WalletIcon type={walletType} testId={'wallet-option-icon'} />
65+
</span>
66+
)
67+
}
68+
: undefined;
69+
5470
return (
5571
<Dropdown
5672
overlayClassName={styles.overlay}
@@ -74,9 +90,9 @@ export const DropdownMenu = ({ isPopup }: DropdownMenuProps): React.ReactElement
7490
fallbackText: walletDisplayInfo?.walletName,
7591
imageSrc: activeWalletAvatar
7692
}
77-
: undefined
93+
: customBitcoinProfile
7894
}
79-
type={getUiWalletType(walletDisplayInfo?.walletType)}
95+
type={walletType}
8096
id="menu"
8197
/>
8298
</div>

apps/browser-extension-wallet/src/components/MainMenu/DropdownMenuOverlay/DropdownMenuOverlay.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,7 @@
223223
background: var(--switch-checked-bg-color) !important;
224224
}
225225
}
226+
227+
.walletOptionBitcoin > div {
228+
background: var(--data-orange);
229+
}

apps/browser-extension-wallet/src/components/MainMenu/DropdownMenuOverlay/components/UserInfo.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ export const UserInfo = ({
114114
const renderWalletOption = useCallback(
115115
({ wallet, lastActiveAccount: acc }: RenderWalletOptionsParams) => {
116116
const walletAvatar = getAvatar(wallet.walletId);
117+
const walletType = getUiWalletType(wallet.type);
118+
119+
const isBitcoinWallet = wallet.type !== WalletType.Script && wallet.blockchainName === 'Bitcoin';
120+
const customBitcoinProfile = isBitcoinWallet
121+
? {
122+
customProfileComponent: (
123+
<span className={styles.walletOptionBitcoin}>
124+
<ProfileDropdown.WalletIcon type={walletType} testId={'wallet-option-icon'} />
125+
</span>
126+
)
127+
}
128+
: undefined;
117129

118130
return (
119131
<ProfileDropdown.WalletOption
@@ -142,14 +154,14 @@ export const UserInfo = ({
142154
text: t('multiWallet.activated.wallet', { walletName: wallet.metadata.name })
143155
});
144156
}}
145-
type={getUiWalletType(wallet.type)}
157+
type={walletType}
146158
profile={
147159
walletAvatar
148160
? {
149161
fallbackText: fullWalletName,
150162
imageSrc: walletAvatar
151163
}
152-
: undefined
164+
: customBitcoinProfile
153165
}
154166
{...(wallet.type !== WalletType.Script &&
155167
wallet.blockchainName !== 'Bitcoin' && {

apps/browser-extension-wallet/src/hooks/useWalletAvatar.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { useLocalStorage } from '@hooks/useLocalStorage';
22
import { getAssetImageUrl } from '@utils/get-asset-image-url';
33
import { useWalletStore } from '@stores';
44
import { useGetHandles } from '@hooks/useGetHandles';
5-
import { useCallback } from 'react';
5+
import { useCallback, useEffect, useState } from 'react';
66
import { walletRepository } from '@lib/wallet-api-ui';
7+
import { useWalletManager } from './useWalletManager';
78

89
interface UseWalletAvatar {
910
activeWalletAvatar: string;
@@ -13,10 +14,20 @@ interface UseWalletAvatar {
1314

1415
export const useWalletAvatar = (): UseWalletAvatar => {
1516
const { cardanoWallet, environmentName } = useWalletStore();
17+
const [activeWalletId, setActiveWalletId] = useState<string>('');
18+
19+
const { getActiveWalletId } = useWalletManager();
20+
21+
useEffect(() => {
22+
// eslint-disable-next-line promise/catch-or-return
23+
getActiveWalletId().then((id) => {
24+
setActiveWalletId(id);
25+
});
26+
}, [getActiveWalletId]);
27+
1628
const [handle] = useGetHandles();
1729
const [avatars, { updateLocalStorage: setUserAvatar }] = useLocalStorage('userAvatar');
1830

19-
const activeWalletId = cardanoWallet?.source.wallet.walletId;
2031
const { accountIndex, metadata } = cardanoWallet?.source.account ?? {};
2132
const handleImage = handle?.profilePic;
2233
const activeWalletAvatar =

0 commit comments

Comments
 (0)