Skip to content

Commit 472d7d5

Browse files
Lw 9170 multi wallet integration (#892)
* fix(ui): use correct derivation path for displaying accounts * feat(ui): disable account delete btn for active or the only account * feat(ui): add onActivateClick handler for profile dropdown * fix(ui): do not fire onClick in profile dropdown when clicking on arrow * fix(core): start from account #0 in select account step * fix(extension): clear background page once finished with create wallet flow if create wallet flow finishes without explicitly calling setBackgroundPage() then it would break the routing, as background page would be defined forever * feat(extension): wire up multi-account components temporarily use native prompt dialog for password input; does not have a prompt to connect hardware wallet, or any error handling when deriving xpub * feat(extension): wire up add wallet components * fix(extension): connect to hw device asap when adding account If it takes more than some time (probably 50ms), Chrome will reject hardware device connection with an error that says WebHID connections must be initiated from user gesture. Apparently, fetching wallets from repository can sometimes take longer. This fix updates useWalletManager addAccount method to take in the entire AnyBip32Wallet object instead of just walletId, so that it doesn't have to fetch the wallet object from indexeddb in service worker. Consequently, some validations from addAccount can be removed, because it's signature no longer accepts walletId of a script wallet. Also it has to trust that wallet actually exists, otherwise it will reject with an error that comes from the WalletRepository (it is no longer a responsibility of this method to check the existence of the wallet). * feat(extension): do not copy address when clicking on active wallet clicking on a wallet in dropdown menu activates it removing copy feature makes the behavior more predictable * feat(ui): add colorScheme option to ExtraSmall also decouple button color scheme from size scheme and set minWidth for ExtraSmall button, which is currently only used for profile dropdown account item * feat: replace edit/delete buttons with a single Disable button temporary design until we apply a larger re-design * fix: remove all relative imports from cardano-sdk * fix(extension): connect trezor device before exporting xpub onboarding, adding wallet, adding accounts and dapp transacations are now working * chore: bump sdk packages required for correctly bundling trezor * chore: build service worker script in development mode after removing imports from dist/cjs, service worker no longer loads this is a temporary solution * test(extension): mock initializeTrezorTransport method --------- Co-authored-by: Piotr Czeglik <piotr.czeglik@iohk.io>
1 parent d1fda44 commit 472d7d5

File tree

53 files changed

+1202
-544
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1202
-544
lines changed

apps/browser-extension-wallet/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@
4040
},
4141
"dependencies": {
4242
"@ant-design/icons": "^4.7.0",
43-
"@cardano-sdk/cardano-services-client": "0.17.6",
44-
"@cardano-sdk/core": "0.28.2",
45-
"@cardano-sdk/dapp-connector": "0.12.9",
46-
"@cardano-sdk/input-selection": "0.12.20",
47-
"@cardano-sdk/tx-construction": "0.17.10",
43+
"@cardano-sdk/cardano-services-client": "0.17.7",
44+
"@cardano-sdk/core": "0.28.3",
45+
"@cardano-sdk/dapp-connector": "0.12.10",
46+
"@cardano-sdk/input-selection": "0.12.21",
47+
"@cardano-sdk/tx-construction": "0.17.11",
4848
"@cardano-sdk/util": "0.15.0",
49-
"@cardano-sdk/wallet": "0.34.2",
50-
"@cardano-sdk/web-extension": "0.24.5",
49+
"@cardano-sdk/wallet": "0.34.3",
50+
"@cardano-sdk/web-extension": "0.24.6",
5151
"@emurgo/cip14-js": "~3.0.1",
5252
"@koralabs/handles-public-api-interfaces": "^1.6.6",
5353
"@lace/cardano": "0.1.0",

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React from 'react';
22
import cn from 'classnames';
33
import { Dropdown } from 'antd';
44
import { Button } from '@lace/common';
@@ -14,15 +14,20 @@ import { PostHogAction } from '@providers/AnalyticsProvider/analyticsTracker';
1414
import { ProfileDropdown } from '@lace/ui';
1515
import { useGetHandles } from '@hooks';
1616
import { getAssetImageUrl } from '@src/utils/get-asset-image-url';
17+
import { getActiveWalletSubtitle } from '@src/utils/get-wallet-subtitle';
18+
import { getUiWalletType } from '@src/utils/get-ui-wallet-type';
1719

1820
export interface DropdownMenuProps {
1921
isPopup?: boolean;
2022
}
2123

2224
export const DropdownMenu = ({ isPopup }: DropdownMenuProps): React.ReactElement => {
2325
const analytics = useAnalyticsContext();
24-
const { walletInfo } = useWalletStore();
25-
const [open, setOpen] = useState(false);
26+
const {
27+
cardanoWallet,
28+
walletUI: { isDropdownMenuOpen },
29+
setIsDropdownMenuOpen
30+
} = useWalletStore();
2631
const [handle] = useGetHandles();
2732
const handleImage = handle?.profilePic;
2833
const Chevron = isPopup ? ChevronSmall : ChevronNormal;
@@ -32,34 +37,37 @@ export const DropdownMenu = ({ isPopup }: DropdownMenuProps): React.ReactElement
3237
};
3338

3439
const handleDropdownState = (openDropdown: boolean) => {
35-
setOpen(openDropdown);
40+
setIsDropdownMenuOpen(openDropdown);
3641
if (openDropdown) {
3742
sendAnalyticsEvent(PostHogAction.UserWalletProfileIconClick);
3843
}
3944
};
4045

46+
const walletName = cardanoWallet.source.wallet.metadata.name;
47+
4148
return (
4249
<Dropdown
4350
destroyPopupOnHide
4451
onOpenChange={handleDropdownState}
4552
overlay={<DropdownMenuOverlay isPopup={isPopup} sendAnalyticsEvent={sendAnalyticsEvent} />}
4653
placement="bottomRight"
54+
open={isDropdownMenuOpen}
4755
trigger={['click']}
4856
>
4957
{process.env.USE_MULTI_WALLET === 'true' ? (
5058
<div className={styles.profileDropdownTrigger}>
5159
<ProfileDropdown.Trigger
52-
title={walletInfo.name}
53-
subtitle="Account #0"
60+
title={walletName}
61+
subtitle={getActiveWalletSubtitle(cardanoWallet.source.account)}
5462
profile={
5563
handleImage
5664
? {
57-
fallback: walletInfo.name,
65+
fallback: walletName,
5866
imageSrc: getAssetImageUrl(handleImage)
5967
}
6068
: undefined
6169
}
62-
type={process.env.USE_SHARED_WALLET === 'true' ? 'shared' : 'cold'}
70+
type={getUiWalletType(cardanoWallet.source.wallet.type)}
6371
id="menu"
6472
/>
6573
</div>
@@ -71,7 +79,7 @@ export const DropdownMenu = ({ isPopup }: DropdownMenuProps): React.ReactElement
7179
data-testid="header-menu-button"
7280
>
7381
<span className={cn(styles.content, { [styles.isPopup]: isPopup })}>
74-
<UserAvatar walletName={walletInfo.name} isPopup={isPopup} />
82+
<UserAvatar walletName={walletName} isPopup={isPopup} />
7583
<Chevron
7684
className={cn(styles.chevron, { [styles.open]: open })}
7785
data-testid={`chevron-${open ? 'up' : 'down'}`}

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
}
5959

6060
.walletStatusInfo {
61+
margin-left: 8px;
6162
cursor: default;
6263
display: flex;
6364
}
@@ -73,46 +74,51 @@
7374
border-radius: 12px !important;
7475
background-color: var(--bg-color-container, #ffffff) !important;
7576
color: var(--text-color-primary);
77+
7678
&:hover {
7779
background: var(--light-mode-light-grey, var(--dark-mode-mid-grey, #efefef)) !important;
7880
}
81+
7982
&.cta {
8083
cursor: pointer;
8184
}
8285
}
86+
8387
.menuItemTheme {
8488
:global {
8589
button.ant-switch {
8690
height: size_unit(3);
8791
width: size_unit(5.5);
8892
}
8993

90-
.ant-switch > div.ant-switch-handle {
94+
.ant-switch>div.ant-switch-handle {
9195
height: size_unit(2.5);
9296
width: size_unit(2.5);
9397
}
9498

95-
.ant-switch > span.ant-switch-inner svg {
99+
.ant-switch>span.ant-switch-inner svg {
96100
margin-top: 1px;
97101
}
98102

99-
.ant-switch.ant-switch-checked > span.ant-switch-inner {
103+
.ant-switch.ant-switch-checked>span.ant-switch-inner {
100104
margin: 0 size_unit(35) 0 size_unit(0.5);
101105
}
102106

103-
.ant-switch.ant-switch-checked > div.ant-switch-handle {
107+
.ant-switch.ant-switch-checked>div.ant-switch-handle {
104108
left: calc(100% - 20px - 2px);
105109
}
106110
}
107111

108112
display: flex;
109113
justify-content: space-between !important;
114+
110115
&:hover {
111116
background: transparent !important;
112117
}
113118
}
114119
}
115120
}
121+
116122
.separator {
117123
display: flex;
118124
height: 1.5px;
@@ -141,12 +147,14 @@
141147
display: flex;
142148
align-items: center;
143149
justify-content: center;
150+
144151
span {
145152
color: var(--dark-mode-mid-black, var(--text-color-white, #ffffff));
146153
font-size: var(--body);
147154
text-transform: uppercase;
148155
font-weight: 700;
149156
}
157+
150158
.avatar {
151159
font-size: size_unit(4);
152160
cursor: pointer;
@@ -156,6 +164,7 @@
156164
height: 26px;
157165
width: 26px;
158166
}
167+
159168
.userAvatarImage {
160169
border-radius: 30px;
161170
}
@@ -178,7 +187,8 @@
178187
font-size: 16px;
179188
}
180189

181-
.popUpContainer, .extendedContainer {
190+
.popUpContainer,
191+
.extendedContainer {
182192
@include scroll-bar-style;
183193
overflow-y: scroll;
184194
margin: size_unit(1) size_unit(1) size_unit(1) 0;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { WalletAccounts } from './components/WalletAccounts';
1919
import { AddSharedWalletLink } from '@components/MainMenu/DropdownMenuOverlay/components/AddSharedWalletLink';
2020
import { useWalletStore } from '@stores';
2121
import classNames from 'classnames';
22+
import { AnyBip32Wallet } from '@cardano-sdk/web-extension';
23+
import { Wallet } from '@lace/cardano';
2224

2325
interface Props extends MenuProps {
2426
isPopup?: boolean;
@@ -35,9 +37,10 @@ export const DropdownMenuOverlay: VFC<Props> = ({
3537
...props
3638
}): React.ReactElement => {
3739
const [currentSection, setCurrentSection] = useState<Sections>(Sections.Main);
38-
const { environmentName } = useWalletStore();
40+
const { environmentName, setManageAccountsWallet } = useWalletStore();
3941

40-
const openWalletAccounts = () => {
42+
const openWalletAccounts = (wallet: AnyBip32Wallet<Wallet.WalletMetadata, Wallet.AccountMetadata>) => {
43+
setManageAccountsWallet(wallet);
4144
setCurrentSection(Sections.WalletAccounts);
4245
};
4346

0 commit comments

Comments
 (0)