Skip to content

Commit 9c9db76

Browse files
feat(frontend): add simultaneous connect of Vara and Ethereum wallets (#754)
1 parent edbd084 commit 9c9db76

Some content is hidden

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

43 files changed

+558
-421
lines changed

js/frontend/src/app.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { Outlet, ScrollRestoration } from 'react-router-dom';
22

33
import { ErrorBoundary, Header } from './components';
4-
import { useAccountSync } from './features/wallet';
54
import { WithProviders } from './providers';
65

76
function Component() {
8-
useAccountSync();
9-
107
return (
118
<>
129
<Header />

js/frontend/src/components/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ import { Card } from './card';
33
import { CopyButton } from './copy-button';
44
import { Input, Checkbox, Radio, Select, Textarea } from './form';
55
import { FormattedBalance } from './formatted-balance';
6-
import { Container, Header, ErrorBoundary, PrivateRoute, Skeleton, TruncatedText } from './layout';
6+
import { Container, Header, ErrorBoundary, Skeleton, TruncatedText } from './layout';
77
import { LinkButton } from './link-button';
88
import { TokenSVG } from './token-svg';
99
import { Tooltip } from './tooltip';
1010

1111
export {
1212
Header,
1313
Container,
14-
PrivateRoute,
1514
Input,
1615
Checkbox,
1716
Radio,

js/frontend/src/components/layout/header/header.module.scss

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
padding-top: 20px;
33
padding-bottom: 20px;
44

5-
display: grid;
6-
grid-template-columns: minmax(0, max-content) max-content 1fr;
5+
display: flex;
76
align-items: center;
87
gap: 32px;
98

10-
@include breakpoint(555px) {
11-
grid-template-columns: minmax(0, max-content) 1fr;
12-
gap: 16px;
9+
@include sm {
10+
flex-direction: column;
1311
}
1412
}
1513

@@ -26,10 +24,20 @@
2624
fill: #00ffc4;
2725
}
2826
}
27+
28+
&Container {
29+
display: flex;
30+
align-items: center;
31+
gap: 32px;
32+
}
2933
}
3034

3135
.wallet {
3236
margin-left: auto;
37+
38+
@include sm {
39+
margin-left: 0;
40+
}
3341
}
3442

3543
.nav {

js/frontend/src/components/layout/header/header.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useAccount } from '@gear-js/react-hooks';
21
import { CSSProperties, useRef, useState, useEffect } from 'react';
32
import { Link, NavLink, useLocation } from 'react-router-dom';
43

@@ -8,17 +7,15 @@ import { TransactionsCounter } from '@/features/history';
87
import { NetworkSwitch } from '@/features/network-switch';
98
import { LockedBalanceTooltip } from '@/features/token-tracker';
109
import { Wallet } from '@/features/wallet';
11-
import { useEthAccount } from '@/hooks';
10+
import { useAccountsConnection } from '@/hooks';
1211

1312
import { Container } from '../container';
1413

1514
import { LINKS } from './consts';
1615
import styles from './header.module.scss';
1716

1817
function Header() {
19-
const { account } = useAccount();
20-
const ethAccount = useEthAccount();
21-
const isAnyAccount = account || ethAccount.isConnected;
18+
const { isAnyAccount } = useAccountsConnection();
2219

2320
const { pathname } = useLocation();
2421
const [linksStyle, setLinksStyle] = useState<CSSProperties>();
@@ -69,11 +66,13 @@ function Header() {
6966
return (
7067
<header className={styles.header}>
7168
<Container className={styles.mainContainer}>
72-
<Link to={ROUTE.HOME} className={styles.logo}>
73-
<LogoSVG />
74-
</Link>
69+
<div className={styles.logoContainer}>
70+
<Link to={ROUTE.HOME} className={styles.logo}>
71+
<LogoSVG />
72+
</Link>
7573

76-
<NetworkSwitch />
74+
<NetworkSwitch />
75+
</div>
7776

7877
<Wallet className={styles.wallet} />
7978
</Container>
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Container } from './container';
22
import { ErrorBoundary } from './error-boundary';
33
import { Header } from './header';
4-
import { PrivateRoute } from './private-route';
54
import { Skeleton } from './skeleton';
65
import { TruncatedText } from './truncated-text';
76

8-
export { Container, Header, PrivateRoute, ErrorBoundary, Skeleton, TruncatedText };
7+
export { Container, Header, ErrorBoundary, Skeleton, TruncatedText };

js/frontend/src/components/layout/private-route/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

js/frontend/src/components/layout/private-route/private-route.tsx

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useAccount } from '@gear-js/react-hooks';
2+
3+
import { useEthAccount } from '@/hooks';
4+
5+
function useAccountsFilter() {
6+
const { account } = useAccount();
7+
const ethAccount = useEthAccount();
8+
9+
const addresses = [account?.decodedAddress, ethAccount.address?.toLowerCase()].filter((value) => Boolean(value));
10+
const isAvailable = addresses.length > 0;
11+
12+
return { addresses, isAvailable };
13+
}
14+
15+
export { useAccountsFilter };

js/frontend/src/features/history/hooks/use-pending-txs-count.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
import { useAccount } from '@gear-js/react-hooks';
21
import { useQueryClient } from '@tanstack/react-query';
32

4-
import { useEthAccount } from '@/hooks';
5-
63
import { TransfersCountQueryQuery } from '../graphql/graphql';
74
import { Status, TransferFilter } from '../types';
85

6+
import { useAccountsFilter } from './use-accounts-filter';
97
import { useTransactionsCountQueryKey, useTransactionsCount } from './use-transactions-count';
108

119
function usePendingTxsCountFilter() {
12-
const { account } = useAccount();
13-
const ethAccount = useEthAccount();
14-
15-
const accountAddress = account?.decodedAddress || ethAccount.address?.toLowerCase();
16-
17-
const filter = { sender: { equalTo: accountAddress }, status: { equalTo: Status.AwaitingPayment } } as TransferFilter;
18-
const enabled = Boolean(accountAddress);
10+
const { addresses, isAvailable } = useAccountsFilter();
1911

20-
return { filter, enabled };
12+
return {
13+
filter: { sender: { in: addresses }, status: { equalTo: Status.AwaitingPayment } } as TransferFilter,
14+
enabled: isAvailable,
15+
};
2116
}
2217

2318
function useOptimisticPendingTxsCountUpdate() {

js/frontend/src/features/history/hooks/use-transaction-filters.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { HexString } from '@gear-js/api';
2-
import { useAccount } from '@gear-js/react-hooks';
32
import { zodResolver } from '@hookform/resolvers/zod';
43
import { useMemo } from 'react';
54
import { useForm } from 'react-hook-form';
65
import { useSearchParams } from 'react-router-dom';
76
import { z } from 'zod';
87

9-
import { useDebounce, useEthAccount } from '@/hooks';
8+
import { useDebounce } from '@/hooks';
109
import { asOptionalField, isNumeric } from '@/utils';
1110

1211
import { DEFAULT_VALUES, FIELD_NAME } from '../consts';
1312
import { Status, TransferFilter } from '../types';
1413

14+
import { useAccountsFilter } from './use-accounts-filter';
15+
1516
const SCHEMA = z.object({
1617
[FIELD_NAME.TIMESTAMP]: z.string(),
1718
[FIELD_NAME.STATUS]: asOptionalField(
@@ -30,14 +31,11 @@ const SCHEMA = z.object({
3031
});
3132

3233
function useTransactionFilters() {
33-
const { account } = useAccount();
34-
const ethAccount = useEthAccount();
35-
const accountAddress = account?.decodedAddress || ethAccount.address;
36-
34+
const accountsFilter = useAccountsFilter();
3735
const [searchParams] = useSearchParams();
3836

3937
const getOwnerDefaultValue = () => {
40-
if (!accountAddress) return DEFAULT_VALUES[FIELD_NAME.OWNER];
38+
if (!accountsFilter.isAvailable) return DEFAULT_VALUES[FIELD_NAME.OWNER];
4139

4240
const owner = searchParams.get('owner');
4341

@@ -101,14 +99,14 @@ function useTransactionFilters() {
10199
filter.blockNumber = { equalTo: debouncedSearch } as TransferFilter['blockNumber'];
102100
}
103101

104-
if (owner && accountAddress) {
105-
filter.sender = { includesInsensitive: accountAddress } as TransferFilter['sender'];
102+
if (owner && accountsFilter.isAvailable) {
103+
filter.sender = { in: accountsFilter.addresses } as TransferFilter['sender'];
106104
}
107105

108106
if (Object.keys(filter).length === 0) return;
109107

110108
return filter;
111-
}, [timestamp, status, asset, searchError, debouncedSearch, owner, accountAddress]);
109+
}, [timestamp, status, asset, searchError, debouncedSearch, owner, accountsFilter]);
112110

113111
return { form, filters };
114112
}

0 commit comments

Comments
 (0)