-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAccountInfoSheet.tsx
130 lines (108 loc) · 3.18 KB
/
AccountInfoSheet.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import React from "react";
import styled from "@emotion/styled";
import copy from "copy-to-clipboard";
import { BN } from "@compolabs/spark-orderbook-ts-sdk";
import copyIcon from "@assets/icons/copy.svg";
import linkIcon from "@assets/icons/link.svg";
import logoutIcon from "@assets/icons/logout.svg";
import { useWallet } from "@hooks/useWallet";
import { useStores } from "@stores";
import { getExplorerLinkByAddress } from "@utils/getExplorerLink";
import { FuelNetwork } from "@blockchain";
import Divider from "../Divider";
import Sheet from "../Sheet";
import { SmartFlex } from "../SmartFlex";
import Text from "../Text";
interface Props {
isOpen: boolean;
onClose: () => void;
}
const AccountInfoSheet: React.FC<Props> = ({ isOpen, onClose }) => {
const { disconnect } = useWallet();
const { accountStore, notificationStore, balanceStore } = useStores();
const bcNetwork = FuelNetwork.getInstance();
const ethBalance = BN.formatUnits(
balanceStore.getWalletBalance(bcNetwork!.getTokenBySymbol("ETH").assetId) ?? BN.ZERO,
bcNetwork?.getTokenBySymbol("ETH").decimals,
)?.toFormat(4);
const handleAddressCopy = () => {
accountStore.address && copy(accountStore.address);
notificationStore.info({ text: "Your address was copied" });
onClose();
};
const handleDisconnect = () => {
disconnect();
onClose();
};
const actions = [
{
icon: copyIcon,
action: handleAddressCopy,
title: "Copy address",
active: true,
},
{
icon: linkIcon,
action: () => window.open(getExplorerLinkByAddress(accountStore.address!)),
title: "View in Explorer",
active: true,
},
];
const renderActions = () => {
return actions.map(
({ title, action, active, icon }) =>
active && (
<ActionItem key={title} center="y" onClick={action}>
<Icon alt="ETH" src={icon} />
<Text type="BUTTON_SECONDARY" primary>
{title}
</Text>
</ActionItem>
),
);
};
return (
<Sheet isOpen={isOpen} header onClose={onClose}>
<SmartFlex column>
<TokenContainer center="y" gap="8px">
<Icon alt="ETH" src={bcNetwork?.getTokenBySymbol("ETH").logo} />
<Text type="H" primary>{`${ethBalance} ETH`}</Text>
</TokenContainer>
<Divider />
<SmartFlex center="y" column>
{renderActions()}
</SmartFlex>
<Divider />
<FooterContainer>
<ActionItem center="y" onClick={handleDisconnect}>
<Icon alt="ETH" src={logoutIcon} />
<Text type="BUTTON_SECONDARY" primary>
Disconnect
</Text>
</ActionItem>
</FooterContainer>
</SmartFlex>
</Sheet>
);
};
export default AccountInfoSheet;
const TokenContainer = styled(SmartFlex)`
padding: 8px 16px;
`;
const ActionItem = styled(SmartFlex)`
padding: 8px 16px;
gap: 4px;
width: 100%;
transition: background-color 150ms;
&:hover,
&:focus {
background-color: ${({ theme }) => theme.colors.borderPrimary};
}
`;
const Icon = styled.img`
width: 24px;
height: 24px;
`;
const FooterContainer = styled(SmartFlex)`
margin-bottom: 40px;
`;