-
-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathWalletConnect.tsx
77 lines (72 loc) · 2.93 KB
/
WalletConnect.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { useState } from 'react';
import {
selectSessions,
walletConnectDisconnectThunk,
walletConnectPairThunk,
} from '@suite-common/walletconnect';
import { Button, Column, Input, Row, Text } from '@trezor/components';
import { spacings } from '@trezor/theme';
import {
ActionButton,
ActionColumn,
SectionItem,
StatusLight,
TextColumn,
Translation,
} from 'src/components/suite';
import { useDispatch, useSelector, useTranslation } from 'src/hooks/suite';
export const WalletConnect = () => {
const dispatch = useDispatch();
const [connectionUrl, setConnectionUrl] = useState('');
const sessions = useSelector(selectSessions);
const { translationString } = useTranslation();
const handleConnect = () => {
dispatch(walletConnectPairThunk({ uri: connectionUrl }));
setConnectionUrl(''); // Clear input after attempt
};
return (
<>
<SectionItem data-test="@settings/walletconnect">
<Row flex="1">
<Input
value={connectionUrl}
onChange={e => setConnectionUrl(e.target.value)}
size="small"
placeholder={translationString('TR_WALLETCONNECT_NEW_CONNECTION_URL')}
/>
<ActionButton onClick={handleConnect}>
<Translation id="TR_CONNECT" />
</ActionButton>
</Row>
</SectionItem>
<SectionItem>
<TextColumn title={<Translation id="TR_WALLETCONNECT_SESSIONS" />} />
<ActionColumn>
<Column gap={spacings.md}>
{sessions.map(session => (
<Row key={session.topic} gap={spacings.md}>
<StatusLight variant="primary" />
<Column flex="1">
<Text>{session.peer.metadata.name}</Text>
<Text variant="tertiary">{session.peer.metadata.url}</Text>
<Text variant="tertiary">{session.topic}</Text>
</Column>
<Button
onClick={() => {
dispatch(
walletConnectDisconnectThunk({ topic: session.topic }),
);
}}
size="small"
variant="destructive"
>
<Translation id="TR_DISCONNECT" />
</Button>
</Row>
))}
</Column>
</ActionColumn>
</SectionItem>
</>
);
};