Skip to content

Commit e962962

Browse files
authored
feat(ng): dapp connection screen (#480)
1 parent 1b20ebb commit e962962

Some content is hidden

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

41 files changed

+1434
-376
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import {
2+
accordionSummaryClasses,
3+
Accordion as K2Accordion,
4+
AccordionDetails as K2AccordionDetails,
5+
AccordionSummary as K2AccordionSummary,
6+
styled,
7+
typographyClasses,
8+
} from '@avalabs/k2-alpine';
9+
import { MdError } from 'react-icons/md';
10+
11+
export const Accordion = styled(K2Accordion)(({ theme }) => ({
12+
marginBottom: theme.spacing(0),
13+
borderRadius: theme.shape.mediumBorderRadius,
14+
boxShadow: '0px 5px 30px 0px rgba(0, 0, 0, 0.15)',
15+
backgroundColor:
16+
theme.palette.mode === 'light'
17+
? theme.palette.surface.primary
18+
: theme.palette.background.paper,
19+
}));
20+
21+
export const AccordionSummary = styled(K2AccordionSummary)(({ theme }) => ({
22+
[`&.${accordionSummaryClasses.root}`]: {
23+
minHeight: 42,
24+
height: 42,
25+
paddingBlock: theme.spacing(1),
26+
paddingInline: theme.spacing(1.5),
27+
justifyContent: 'unset',
28+
},
29+
'& .accordion-header-container': {
30+
alignItems: 'center',
31+
gap: theme.spacing(1),
32+
[`& > .${typographyClasses.root}`]: {
33+
width: '100%',
34+
},
35+
},
36+
'& .accordion-header-icon': {
37+
display: 'flex',
38+
margin: 0,
39+
lineHeight: 1,
40+
},
41+
[`& .${accordionSummaryClasses.content}`]: {
42+
margin: 0,
43+
overflow: 'hidden',
44+
textOverflow: 'ellipsis',
45+
whiteSpace: 'nowrap',
46+
},
47+
[`& .${accordionSummaryClasses.expandIconWrapper}`]: {
48+
color: theme.palette.text.disabled,
49+
},
50+
}));
51+
52+
export const AccordionDetails = styled(K2AccordionDetails)(({ theme }) => ({
53+
paddingInline: theme.spacing(1.5),
54+
}));
55+
56+
export const ErrorIcon = styled(MdError)(({ theme }) => ({
57+
color: theme.palette.error.main,
58+
flexShrink: 0,
59+
}));
60+
61+
export const Shrinkable = styled('span')(({ theme }) => ({
62+
width: '100%',
63+
opacity: 1,
64+
transition: theme.transitions.create(['width', 'opacity']),
65+
66+
[`.${accordionSummaryClasses.root}:hover &`]: {
67+
width: '0%',
68+
opacity: 0,
69+
},
70+
}));
Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1-
import { CircularProgress, Stack, Typography } from '@avalabs/k2-alpine';
1+
import {
2+
CircularProgress,
3+
Stack,
4+
Typography,
5+
TypographyProps,
6+
} from '@avalabs/k2-alpine';
27
import { WalletDetails } from '@core/types';
38
import { useSettingsContext, useWalletTotalBalance } from '@core/ui';
4-
import { cloneElement, FC, ReactElement, useState } from 'react';
9+
import {
10+
cloneElement,
11+
FC,
12+
MouseEventHandler,
13+
PropsWithChildren,
14+
ReactElement,
15+
useState,
16+
} from 'react';
517
import { useTranslation } from 'react-i18next';
6-
import { RenamableTitle } from '../../RenamableTitle';
18+
import { RenamableTitle } from '../../pages/AccountManagement/components/RenamableTitle';
719
import * as Styled from './Styled';
820
import { WalletIconProps } from '@/components/WalletIcon';
9-
interface WalletCardProps {
21+
import { useHistory } from 'react-router-dom';
22+
import { URL_SEARCH_TOKENS } from '@/pages/AccountManagement/utils/searchParams';
23+
interface WalletCardProps extends PropsWithChildren {
1024
id: WalletDetails['id'];
1125
name: WalletDetails['name'];
1226
icon: ReactElement<WalletIconProps>;
1327
initialExpanded: boolean;
14-
children: ReactElement[];
1528
disableRename?: boolean;
1629
}
1730

@@ -24,12 +37,30 @@ export const WalletCard: FC<WalletCardProps> = ({
2437
name,
2538
}) => {
2639
const { t } = useTranslation();
40+
const { push } = useHistory();
2741
const { isLoading, hasErrorOccurred, totalBalanceInCurrency } =
2842
useWalletTotalBalance(id);
2943
const { currencyFormatter } = useSettingsContext();
3044

3145
const [isExpanded, setIsExpanded] = useState(initialExpanded);
32-
const Title = disableRename ? Typography : RenamableTitle;
46+
const sharedTitleProps: TypographyProps = {
47+
width: 1,
48+
variant: 'subtitle3',
49+
whiteSpace: 'nowrap',
50+
overflow: 'hidden',
51+
textOverflow: 'ellipsis',
52+
};
53+
54+
const handleRename: MouseEventHandler<HTMLButtonElement> = (event) => {
55+
event.preventDefault();
56+
event.stopPropagation();
57+
push({
58+
pathname: '/account-management/rename',
59+
search: new URLSearchParams({
60+
[URL_SEARCH_TOKENS.wallet]: id,
61+
}).toString(),
62+
});
63+
};
3364

3465
return (
3566
<>
@@ -48,17 +79,13 @@ export const WalletCard: FC<WalletCardProps> = ({
4879
gap={0.5}
4980
width="calc(100% - 32px)"
5081
>
51-
<Title
52-
type="wallet"
53-
tokenId={id}
54-
width={1}
55-
variant="subtitle3"
56-
whiteSpace="nowrap"
57-
overflow="hidden"
58-
textOverflow="ellipsis"
59-
>
60-
{name}
61-
</Title>
82+
{disableRename ? (
83+
<Typography {...sharedTitleProps}>{name}</Typography>
84+
) : (
85+
<RenamableTitle {...sharedTitleProps} onRename={handleRename}>
86+
{name}
87+
</RenamableTitle>
88+
)}
6289
{isLoading && <CircularProgress size={14} />}
6390
{!isLoading && !hasErrorOccurred && (
6491
<Typography variant="body3" color="text.disabled">
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { WalletCard } from './WalletCard';

apps/next/src/localization/locales/en/translation.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"Accounts deleted": "Accounts deleted",
2626
"Accounts updated": "Accounts updated",
2727
"Action was not approved. Please try again.": "Action was not approved. Please try again.",
28+
"Active account is accessible by default": "Active account is accessible by default",
2829
"Activity": "Activity",
2930
"Add Avalanche C-Chain Address": "Add Avalanche C-Chain Address",
3031
"Add Avalanche X/P-Chain Address": "Add Avalanche X/P-Chain Address",
@@ -33,6 +34,7 @@
3334
"Add RPC URL": "Add RPC URL",
3435
"Add Solana": "Add Solana",
3536
"Add Solana Address": "Add Solana Address",
37+
"Add Solana accounts first to use the Solana network": "Add Solana accounts first to use the Solana network",
3638
"Add Token": "Add Token",
3739
"Add a display name for your wallet. You can change it at any time in the settings.": "Add a display name for your wallet. You can change it at any time in the settings.",
3840
"Add a name so that it is easier to find later.": "Add a name so that it is easier to find later.",
@@ -66,7 +68,6 @@
6668
"Approval transaction failed": "Approval transaction failed",
6769
"Approve": "Approve",
6870
"Approves all {{token}}": "Approves all {{token}}",
69-
"Approving will give this dApp access to your active account.": "Approving will give this dApp access to your active account.",
7071
"Are you sure that you want to cancel this request?": "Are you sure that you want to cancel this request?",
7172
"Are you sure you want to delete selected accounts?": "Are you sure you want to delete selected accounts?",
7273
"Are you sure you want to delete this contact?": "Are you sure you want to delete this contact?",
@@ -130,11 +131,15 @@
130131
"Confirm addresses": "Confirm addresses",
131132
"Confirm new password": "Confirm new password",
132133
"Confirm password": "Confirm password",
134+
"Connect": "Connect",
135+
"Connect 1 account": "Connect 1 account",
133136
"Connect the Ledger device to your computer": "Connect the Ledger device to your computer",
134137
"Connect with WalletConnect": "Connect with WalletConnect",
135138
"Connect your Keystone": "Connect your Keystone",
136139
"Connect your Ledger": "Connect your Ledger",
137140
"Connect your Ledger device and open the Avalanche app": "Connect your Ledger device and open the Avalanche app",
141+
"Connect {{count}} accounts": "Connect {{count}} accounts",
142+
"Connect {{count}} accounts_plural": "Connect {{count}} accounts",
138143
"Connected": "Connected",
139144
"Connected sites": "Connected sites",
140145
"Contact created": "Contact created",
@@ -160,6 +165,7 @@
160165
"Could not connect.": "Could not connect.",
161166
"Could not swap {{srcAmount}} {{srcToken}} to {{destAmount}} {{destToken}}": "Could not swap {{srcAmount}} {{srcToken}} to {{destAmount}} {{destToken}}",
162167
"Create new account": "Create new account",
168+
"Creating Solana addresses...": "Creating Solana addresses...",
163169
"Currency": "Currency",
164170
"Current password": "Current password",
165171
"Current password is incorrect": "Current password is incorrect",
@@ -187,6 +193,7 @@
187193
"Do not share this phrase with anyone! These words can be used to steal all your accounts.": "Do not share this phrase with anyone! These words can be used to steal all your accounts.",
188194
"Do you really want to save?": "Do you really want to save?",
189195
"Do you want to add Solana to your wallet?": "Do you want to add Solana to your wallet?",
196+
"Do you want to allow <b>{{dappUrl}}</b> to access your wallet?": "Do you want to allow <b>{{dappUrl}}</b> to access your wallet?",
190197
"Do you want to sign this message?": "Do you want to sign this message?",
191198
"Done": "Done",
192199
"Download Ledger Live to update": "Download Ledger Live to update",
@@ -533,6 +540,7 @@
533540
"Sending this token is not supported yet.": "Sending this token is not supported yet.",
534541
"Sending this type of token is not supported by Core": "Sending this type of token is not supported by Core",
535542
"Set a limit that you will allow to automatically spend.": "Set a limit that you will allow to automatically spend.",
543+
"Set up": "Set up",
536544
"Settings": "Settings",
537545
"Show me Trending Tokens": "Show me Trending Tokens",
538546
"Show password": "Show password",
@@ -545,6 +553,7 @@
545553
"Slippage tolerance exceeded, increase the slippage and try again.": "Slippage tolerance exceeded, increase the slippage and try again.",
546554
"Slow": "Slow",
547555
"Solana": "Solana",
556+
"Solana is not supported by this wallet": "Solana is not supported by this wallet",
548557
"Some of the required parameters are invalid.": "Some of the required parameters are invalid.",
549558
"Some of the required parameters are missing.": "Some of the required parameters are missing.",
550559
"Something bad happened please try again later!": "Something bad happened please try again later!",
@@ -603,6 +612,7 @@
603612
"This token contract is missing a required method.": "This token contract is missing a required method.",
604613
"This transaction has been flagged as malicious. <span>I understand the risk and want to proceed anyway.</span>": "This transaction has been flagged as malicious. <span>I understand the risk and want to proceed anyway.</span>",
605614
"This transaction would likely fail": "This transaction would likely fail",
615+
"This wallet does not support the requested network": "This wallet does not support the requested network",
606616
"This wallet is already imported": "This wallet is already imported",
607617
"This wallet is already imported.": "This wallet is already imported.",
608618
"To proceed, please retry.": "To proceed, please retry.",

apps/next/src/pages/AccountManagement/components/RenamableTitle.tsx

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ import {
99
} from '@avalabs/k2-alpine';
1010
import { FC, MouseEventHandler } from 'react';
1111
import { MdModeEdit } from 'react-icons/md';
12-
import { useHistory } from 'react-router-dom';
13-
import { URL_SEARCH_TOKENS } from '../utils/searchParams';
1412

1513
type Props = TypographyProps & {
16-
type: 'account' | 'wallet';
17-
tokenId: string;
14+
onRename: MouseEventHandler<HTMLButtonElement>;
1815
};
1916

2017
const RenameButton = styled(IconButton)(({ theme }) => ({
@@ -33,24 +30,10 @@ const RenameButton = styled(IconButton)(({ theme }) => ({
3330

3431
export const RenamableTitle: FC<Props> = ({
3532
children,
36-
type,
37-
tokenId,
33+
onRename,
3834
width,
3935
...props
4036
}) => {
41-
const { push } = useHistory();
42-
43-
const handleClick: MouseEventHandler<HTMLButtonElement> = (event) => {
44-
event.preventDefault();
45-
event.stopPropagation();
46-
push({
47-
pathname: '/account-management/rename',
48-
search: new URLSearchParams({
49-
[URL_SEARCH_TOKENS[type]]: tokenId,
50-
}).toString(),
51-
});
52-
};
53-
5437
return (
5538
<Box
5639
display="flex"
@@ -66,7 +49,7 @@ export const RenamableTitle: FC<Props> = ({
6649
>
6750
{children}
6851
</Typography>
69-
<RenameButton onClick={handleClick} size="small">
52+
<RenameButton onClick={onRename} size="small">
7053
<MdModeEdit size={12} color={props.color} />
7154
</RenameButton>
7255
</Box>

apps/next/src/pages/AccountManagement/components/Wallets/components/AccountListItem/AccountListItem.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ export const AccountListItem: FC<Props> = ({ account, active, onSelect }) => {
7070
},
7171
};
7272

73+
const handleRename: MouseEventHandler<HTMLButtonElement> = (event) => {
74+
event.preventDefault();
75+
event.stopPropagation();
76+
history.push({
77+
pathname: '/account-management/rename',
78+
search: new URLSearchParams({
79+
[URL_SEARCH_TOKENS.account]: account.id,
80+
}).toString(),
81+
});
82+
};
83+
7384
return (
7485
<ListItem disablePadding>
7586
<Styled.ListItemButton
@@ -83,9 +94,8 @@ export const AccountListItem: FC<Props> = ({ account, active, onSelect }) => {
8394
<ListItemText
8495
primary={
8596
<RenamableTitle
97+
onRename={handleRename}
8698
variant="subtitle3"
87-
type="account"
88-
tokenId={account.id}
8999
component="span"
90100
>
91101
{account.name}
Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,10 @@
11
import {
2-
accordionSummaryClasses,
3-
Accordion as K2Accordion,
4-
AccordionDetails as K2AccordionDetails,
5-
AccordionSummary as K2AccordionSummary,
62
ListItemButton as K2ListItemButton,
73
listItemButtonClasses,
84
styled,
9-
typographyClasses,
105
} from '@avalabs/k2-alpine';
116
import { MdError } from 'react-icons/md';
127

13-
export const Accordion = styled(K2Accordion)(({ theme }) => ({
14-
marginBottom: theme.spacing(0),
15-
borderRadius: theme.shape.mediumBorderRadius,
16-
boxShadow: '0px 5px 30px 0px rgba(0, 0, 0, 0.15)',
17-
backgroundColor:
18-
theme.palette.mode === 'light'
19-
? theme.palette.surface.primary
20-
: theme.palette.background.paper,
21-
}));
22-
23-
export const AccordionSummary = styled(K2AccordionSummary)(({ theme }) => ({
24-
[`&.${accordionSummaryClasses.root}`]: {
25-
minHeight: 42,
26-
height: 42,
27-
paddingBlock: theme.spacing(1),
28-
paddingInline: theme.spacing(1.5),
29-
justifyContent: 'unset',
30-
},
31-
'& .accordion-header-container': {
32-
alignItems: 'end',
33-
gap: theme.spacing(1),
34-
[`& > .${typographyClasses.root}`]: {
35-
width: '100%',
36-
},
37-
},
38-
'& .accordion-header-icon': {
39-
display: 'block',
40-
margin: 0,
41-
},
42-
[`& .${accordionSummaryClasses.content}`]: {
43-
margin: 0,
44-
overflow: 'hidden',
45-
textOverflow: 'ellipsis',
46-
whiteSpace: 'nowrap',
47-
},
48-
[`& .${accordionSummaryClasses.expandIconWrapper}`]: {
49-
color: theme.palette.text.disabled,
50-
},
51-
}));
52-
53-
export const AccordionDetails = styled(K2AccordionDetails)(({ theme }) => ({
54-
paddingInline: theme.spacing(1.5),
55-
}));
56-
578
export const ErrorIcon = styled(MdError)(({ theme }) => ({
589
color: theme.palette.error.main,
5910
flexShrink: 0,
@@ -71,14 +22,3 @@ export const ListItemButton = styled(K2ListItemButton)(({ theme }) => ({
7122
backgroundColor: theme.palette.background.paper,
7223
},
7324
}));
74-
75-
export const Shrinkable = styled('span')(({ theme }) => ({
76-
width: '100%',
77-
opacity: 1,
78-
transition: theme.transitions.create(['width', 'opacity']),
79-
80-
[`.${accordionSummaryClasses.root}:hover &`]: {
81-
width: '0%',
82-
opacity: 0,
83-
},
84-
}));

0 commit comments

Comments
 (0)