@aptos-labs/wallet-adapter-mui-design 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
18
+ mod
19
+ ));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/index.tsx
23
+ var src_exports = {};
24
+ module.exports = __toCommonJS(src_exports);
25
+
26
+ // src/WalletConnector.tsx
27
+ var import_react3 = require("react");
28
+
29
+ // src/WalletButton.tsx
30
+ var import_material2 = require("@mui/material");
31
+ var import_react2 = require("react");
32
+ var import_wallet_adapter_react2 = require("@aptos-labs/wallet-adapter-react");
33
+
34
+ // src/WalletMenu.tsx
35
+ var import_material = require("@mui/material");
36
+ var import_wallet_adapter_react = require("@aptos-labs/wallet-adapter-react");
37
+ var import_react = require("react");
38
+ var import_jsx_runtime = require("react/jsx-runtime");
39
+
40
+ // src/WalletButton.tsx
41
+ var import_AccountBalanceWalletOutlined = __toESM(require("@mui/icons-material/AccountBalanceWalletOutlined"));
42
+ var import_jsx_runtime = require("react/jsx-runtime");
43
+
44
+ // src/WalletModel.tsx
45
+ var import_material3 = require("@mui/material");
46
+ var import_wallet_adapter_react3 = require("@aptos-labs/wallet-adapter-react");
47
+ var import_WarningAmberOutlined = __toESM(require("@mui/icons-material/WarningAmberOutlined"));
48
+ var import_Close = __toESM(require("@mui/icons-material/Close"));
49
+ var import_jsx_runtime = require("react/jsx-runtime");
50
+
51
+ // src/WalletConnector.tsx
52
+ var import_jsx_runtime = require("react/jsx-runtime");
package/dist/index.mjs ADDED
@@ -0,0 +1,47 @@
1
+ // src/WalletConnector.tsx
2
+ import { useState as useState3 } from "react";
3
+
4
+ // src/WalletButton.tsx
5
+ import { Avatar, Button, Typography } from "@mui/material";
6
+ import { useState as useState2 } from "react";
7
+ import { useWallet as useWallet2 } from "@aptos-labs/wallet-adapter-react";
8
+
9
+ // src/WalletMenu.tsx
10
+ import {
11
+ List,
12
+ ListItem,
13
+ ListItemButton,
14
+ ListItemText,
15
+ Popover,
16
+ Tooltip
17
+ } from "@mui/material";
18
+ import { useWallet } from "@aptos-labs/wallet-adapter-react";
19
+ import { useState } from "react";
20
+ import { jsx, jsxs } from "react/jsx-runtime";
21
+
22
+ // src/WalletButton.tsx
23
+ import AccountBalanceWalletOutlinedIcon from "@mui/icons-material/AccountBalanceWalletOutlined";
24
+ import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
25
+
26
+ // src/WalletModel.tsx
27
+ import {
28
+ Box,
29
+ Button as Button2,
30
+ ListItem as ListItem2,
31
+ ListItemAvatar,
32
+ ListItemButton as ListItemButton2,
33
+ ListItemText as ListItemText2,
34
+ Typography as Typography2,
35
+ useTheme,
36
+ Grid,
37
+ IconButton,
38
+ Dialog,
39
+ Stack
40
+ } from "@mui/material";
41
+ import { useWallet as useWallet3 } from "@aptos-labs/wallet-adapter-react";
42
+ import LanOutlinedIcon from "@mui/icons-material/WarningAmberOutlined";
43
+ import CloseIcon from "@mui/icons-material/Close";
44
+ import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
45
+
46
+ // src/WalletConnector.tsx
47
+ import { Fragment as Fragment3, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@aptos-labs/wallet-adapter-mui-design",
3
+ "version": "0.0.0",
4
+ "description": "Aptos Wallet Adapter mui design",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "license": "Apache-2.0",
9
+ "exports": {
10
+ ".": {
11
+ "require": "./dist/index.js",
12
+ "import": "./dist/index.mjs",
13
+ "types": "./dist/index.d.ts"
14
+ },
15
+ "./dist/index.css": {
16
+ "import": "./dist/index.css",
17
+ "require": "./dist/index.css"
18
+ }
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/aptos-labs/aptos-wallet-adapter.git"
23
+ },
24
+ "homepage": "https://github.com/aptos-labs/aptos-wallet-adapter",
25
+ "bugs": {
26
+ "url": "https://github.com/aptos-labs/aptos-wallet-adapter/issues"
27
+ },
28
+ "author": "aptoslabs.com",
29
+ "keywords": [
30
+ "Aptos",
31
+ "Aptos Labs",
32
+ "Wallet",
33
+ "Wallet Adapter",
34
+ "Wallet Adapter Provider",
35
+ "React"
36
+ ],
37
+ "scripts": {
38
+ "build": "tsup src/index.tsx --format esm,cjs --dts --external react",
39
+ "dev": "tsup src/index.tsx --format esm,cjs --watch --dts --external react",
40
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
41
+ "lint": "TIMING=1 eslint \"src/**/*.ts*\""
42
+ },
43
+ "devDependencies": {
44
+ "@aptos-labs/wallet-adapter-tsconfig": "workspace:*",
45
+ "@types/react": "^18.0.17",
46
+ "@types/react-dom": "^18.0.6",
47
+ "eslint": "^8.15.0",
48
+ "tsup": "^5.10.1",
49
+ "typescript": "^4.5.3"
50
+ },
51
+ "dependencies": {
52
+ "@aptos-labs/wallet-adapter-react": "*",
53
+ "@babel/core": "^7.0.0",
54
+ "@emotion/react": "^11.10.5",
55
+ "@emotion/styled": "^11.10.5",
56
+ "@mui/icons-material": "^5.11.0",
57
+ "@mui/material": "^5.11.6",
58
+ "aptos": "^1.3.17",
59
+ "react": "^18",
60
+ "react-dom": "^18.2.0",
61
+ "react-router-dom": "^6.8.0"
62
+ }
63
+ }
@@ -0,0 +1,70 @@
1
+ import { Avatar, Button, Typography } from "@mui/material";
2
+ import { useState } from "react";
3
+ import { useWallet } from "@aptos-labs/wallet-adapter-react";
4
+ import WalletMenu from "./WalletMenu";
5
+ import React from "react";
6
+ import { truncateAddress } from "./utils";
7
+ import AccountBalanceWalletOutlinedIcon from "@mui/icons-material/AccountBalanceWalletOutlined";
8
+
9
+ type WalletButtonProps = {
10
+ handleModalOpen: () => void;
11
+ handleNavigate?: () => void;
12
+ };
13
+
14
+ export default function WalletButton({
15
+ handleModalOpen,
16
+ handleNavigate,
17
+ }: WalletButtonProps): JSX.Element {
18
+ const { connected, account, wallet } = useWallet();
19
+
20
+ const [popoverAnchor, setPopoverAnchor] = useState<HTMLButtonElement | null>(
21
+ null
22
+ );
23
+ const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
24
+ setPopoverAnchor(event.currentTarget);
25
+ };
26
+
27
+ const handlePopoverClose = () => {
28
+ setPopoverAnchor(null);
29
+ };
30
+
31
+ const onConnectWalletClick = () => {
32
+ handlePopoverClose();
33
+ handleModalOpen();
34
+ };
35
+
36
+ return (
37
+ <>
38
+ <Button
39
+ size="large"
40
+ variant="contained"
41
+ onClick={connected ? handleClick : onConnectWalletClick}
42
+ className="wallet-button"
43
+ sx={{ borderRadius: "10px" }}
44
+ >
45
+ {connected ? (
46
+ <>
47
+ <Avatar
48
+ alt={wallet?.name}
49
+ src={wallet?.icon}
50
+ sx={{ width: 24, height: 24 }}
51
+ />
52
+ <Typography noWrap ml={2}>
53
+ {truncateAddress(account?.address!)}
54
+ </Typography>
55
+ </>
56
+ ) : (
57
+ <>
58
+ <AccountBalanceWalletOutlinedIcon sx={{ marginRight: 1 }} />
59
+ <Typography noWrap>Connect Wallet</Typography>
60
+ </>
61
+ )}
62
+ </Button>
63
+ <WalletMenu
64
+ popoverAnchor={popoverAnchor}
65
+ handlePopoverClose={handlePopoverClose}
66
+ handleNavigate={handleNavigate}
67
+ />
68
+ </>
69
+ );
70
+ }
@@ -0,0 +1,31 @@
1
+ import { useState } from "react";
2
+ import WalletButton from "./WalletButton";
3
+ import WalletsModal from "./WalletModel";
4
+
5
+ type WalletConnectorProps = {
6
+ networkSupport?: string;
7
+ handleNavigate?: () => void;
8
+ };
9
+
10
+ export default function WalletConnector({
11
+ networkSupport,
12
+ handleNavigate,
13
+ }: WalletConnectorProps) {
14
+ const [modalOpen, setModalOpen] = useState(false);
15
+ const handleModalOpen = () => setModalOpen(true);
16
+ const handleClose = () => setModalOpen(false);
17
+
18
+ return (
19
+ <>
20
+ <WalletButton
21
+ handleModalOpen={handleModalOpen}
22
+ handleNavigate={handleNavigate}
23
+ />
24
+ <WalletsModal
25
+ handleClose={handleClose}
26
+ modalOpen={modalOpen}
27
+ networkSupport={networkSupport}
28
+ />
29
+ </>
30
+ );
31
+ }
@@ -0,0 +1,88 @@
1
+ import {
2
+ List,
3
+ ListItem,
4
+ ListItemButton,
5
+ ListItemText,
6
+ Popover,
7
+ Tooltip,
8
+ } from "@mui/material";
9
+ import { useWallet } from "@aptos-labs/wallet-adapter-react";
10
+ import React, { useState } from "react";
11
+
12
+ type WalletMenuProps = {
13
+ popoverAnchor: HTMLButtonElement | null;
14
+ handlePopoverClose: () => void;
15
+ handleNavigate?: () => void;
16
+ };
17
+
18
+ export default function WalletMenu({
19
+ popoverAnchor,
20
+ handlePopoverClose,
21
+ handleNavigate,
22
+ }: WalletMenuProps): JSX.Element {
23
+ const { account, disconnect } = useWallet();
24
+ const popoverOpen = Boolean(popoverAnchor);
25
+ const id = popoverOpen ? "wallet-popover" : undefined;
26
+
27
+ const onAccountOptionClicked = () => {
28
+ handleNavigate && handleNavigate();
29
+ handlePopoverClose();
30
+ };
31
+
32
+ const handleLogout = () => {
33
+ disconnect();
34
+ handlePopoverClose();
35
+ };
36
+
37
+ const [tooltipOpen, setTooltipOpen] = useState<boolean>(false);
38
+
39
+ const copyAddress = async (event: React.MouseEvent<HTMLDivElement>) => {
40
+ await navigator.clipboard.writeText(account?.address!);
41
+
42
+ setTooltipOpen(true);
43
+
44
+ setTimeout(() => {
45
+ setTooltipOpen(false);
46
+ }, 2000);
47
+ };
48
+
49
+ return (
50
+ <Popover
51
+ id={id}
52
+ open={popoverOpen}
53
+ anchorEl={popoverAnchor}
54
+ onClose={handlePopoverClose}
55
+ anchorOrigin={{
56
+ vertical: "bottom",
57
+ horizontal: "left",
58
+ }}
59
+ >
60
+ <List>
61
+ <Tooltip
62
+ title="Copied"
63
+ placement="bottom-end"
64
+ open={tooltipOpen}
65
+ disableFocusListener
66
+ disableHoverListener
67
+ disableTouchListener
68
+ >
69
+ <ListItem disablePadding>
70
+ <ListItemButton onClick={copyAddress}>
71
+ <ListItemText primary="Copy Address" />
72
+ </ListItemButton>
73
+ </ListItem>
74
+ </Tooltip>
75
+ <ListItem disablePadding>
76
+ <ListItemButton onClick={onAccountOptionClicked}>
77
+ <ListItemText primary="Account" />
78
+ </ListItemButton>
79
+ </ListItem>
80
+ <ListItem disablePadding>
81
+ <ListItemButton onClick={handleLogout}>
82
+ <ListItemText primary="Logout" />
83
+ </ListItemButton>
84
+ </ListItem>
85
+ </List>
86
+ </Popover>
87
+ );
88
+ }
@@ -0,0 +1,212 @@
1
+ import {
2
+ Box,
3
+ Button,
4
+ ListItem,
5
+ ListItemAvatar,
6
+ ListItemButton,
7
+ ListItemText,
8
+ Typography,
9
+ useTheme,
10
+ Grid,
11
+ IconButton,
12
+ Dialog,
13
+ Stack,
14
+ } from "@mui/material";
15
+ import { useWallet, WalletName } from "@aptos-labs/wallet-adapter-react";
16
+ import { grey } from "./aptosColorPalette";
17
+ import LanOutlinedIcon from "@mui/icons-material/WarningAmberOutlined";
18
+ import CloseIcon from "@mui/icons-material/Close";
19
+
20
+ type WalletsModalProps = {
21
+ handleClose: () => void;
22
+ modalOpen: boolean;
23
+ networkSupport?: string;
24
+ };
25
+
26
+ export default function WalletsModal({
27
+ handleClose,
28
+ modalOpen,
29
+ networkSupport,
30
+ }: WalletsModalProps): JSX.Element {
31
+ const { wallets, connect } = useWallet();
32
+
33
+ const theme = useTheme();
34
+
35
+ const onWalletSelect = (walletName: WalletName) => {
36
+ connect(walletName);
37
+ handleClose();
38
+ };
39
+
40
+ const renderWalletsList = () => {
41
+ return wallets.map((wallet) => {
42
+ const option = wallet;
43
+ const icon = option.icon;
44
+ return (
45
+ <Grid key={option.name} xs={12} paddingY={0.5} item>
46
+ {wallet.readyState === "Installed" ? (
47
+ <ListItem disablePadding>
48
+ <ListItemButton
49
+ alignItems="center"
50
+ disableGutters
51
+ onClick={() => onWalletSelect(option.name)}
52
+ sx={{
53
+ background:
54
+ theme.palette.mode === "dark" ? grey[700] : grey[200],
55
+ padding: "1rem 3rem",
56
+ borderRadius: "10px",
57
+ display: "flex",
58
+ gap: "1rem",
59
+ }}
60
+ >
61
+ <ListItemAvatar
62
+ sx={{
63
+ display: "flex",
64
+ alignItems: "center",
65
+ width: "2rem",
66
+ height: "2rem",
67
+ minWidth: "0",
68
+ color: `${theme.palette.text.primary}`,
69
+ }}
70
+ >
71
+ <Box
72
+ component="img"
73
+ src={icon}
74
+ sx={{ width: "100%", height: "100%" }}
75
+ />
76
+ </ListItemAvatar>
77
+ <ListItemText
78
+ primary={option.name}
79
+ primaryTypographyProps={{
80
+ fontSize: 18,
81
+ }}
82
+ />
83
+ <Button
84
+ variant="contained"
85
+ size="small"
86
+ className="wallet-connect-button"
87
+ >
88
+ Connect
89
+ </Button>
90
+ </ListItemButton>
91
+ </ListItem>
92
+ ) : (
93
+ <ListItem
94
+ alignItems="center"
95
+ sx={{
96
+ borderRadius: `${theme.shape.borderRadius}px`,
97
+ background:
98
+ theme.palette.mode === "dark" ? grey[700] : grey[200],
99
+ padding: "1rem 3rem",
100
+ gap: "1rem",
101
+ }}
102
+ >
103
+ <ListItemAvatar
104
+ sx={{
105
+ display: "flex",
106
+ alignItems: "center",
107
+ width: "2rem",
108
+ height: "2rem",
109
+ minWidth: "0",
110
+ opacity: "0.25",
111
+ }}
112
+ >
113
+ <Box
114
+ component="img"
115
+ src={icon}
116
+ sx={{ width: "100%", height: "100%" }}
117
+ />
118
+ </ListItemAvatar>
119
+ <ListItemText
120
+ sx={{
121
+ opacity: "0.25",
122
+ }}
123
+ primary={option.name}
124
+ primaryTypographyProps={{
125
+ fontSize: 18,
126
+ }}
127
+ />
128
+ <Button
129
+ LinkComponent={"a"}
130
+ href={option.url}
131
+ target="_blank"
132
+ size="small"
133
+ className="wallet-connect-install"
134
+ >
135
+ Install
136
+ </Button>
137
+ </ListItem>
138
+ )}
139
+ </Grid>
140
+ );
141
+ });
142
+ };
143
+
144
+ return (
145
+ <Dialog
146
+ open={modalOpen}
147
+ onClose={handleClose}
148
+ aria-labelledby="wallet selector modal"
149
+ aria-describedby="select a wallet to connect"
150
+ sx={{ borderRadius: "5px" }}
151
+ >
152
+ <Stack
153
+ sx={{
154
+ display: "flex",
155
+ flexDirection: "column",
156
+ top: "50%",
157
+ left: "50%",
158
+ width: 500,
159
+ bgcolor: "background.paper",
160
+ boxShadow: 24,
161
+ p: 3,
162
+ }}
163
+ >
164
+ <IconButton
165
+ onClick={handleClose}
166
+ sx={{
167
+ position: "absolute",
168
+ right: 12,
169
+ top: 12,
170
+ color: grey[450],
171
+ }}
172
+ >
173
+ <CloseIcon />
174
+ </IconButton>
175
+ <Typography align="center" variant="h5" pt={2}>
176
+ Connect Wallet
177
+ </Typography>
178
+ <Box
179
+ sx={{
180
+ display: "flex",
181
+ gap: 0.5,
182
+ alignItems: "center",
183
+ justifyContent: "center",
184
+ mb: 4,
185
+ }}
186
+ >
187
+ {networkSupport && (
188
+ <>
189
+ <LanOutlinedIcon
190
+ sx={{
191
+ fontSize: "0.9rem",
192
+ color: grey[400],
193
+ }}
194
+ />
195
+ <Typography
196
+ sx={{
197
+ display: "inline-flex",
198
+ fontSize: "0.9rem",
199
+ color: grey[400],
200
+ }}
201
+ align="center"
202
+ >
203
+ {networkSupport} only
204
+ </Typography>
205
+ </>
206
+ )}
207
+ </Box>
208
+ <Box>{renderWalletsList()}</Box>
209
+ </Stack>
210
+ </Dialog>
211
+ );
212
+ }
@@ -0,0 +1,14 @@
1
+ // Grey Palette
2
+ export const grey = {
3
+ 50: "#fafafa",
4
+ 100: "#f4f4f5",
5
+ 200: "#e4e4e7",
6
+ 300: "#d4d4d8",
7
+ 400: "#a1a1aa",
8
+ 450: "#909099",
9
+ 500: "#4f5352",
10
+ 600: "#363a39",
11
+ 700: "#272b2a",
12
+ 800: "#1b1f1e",
13
+ 900: "#121615",
14
+ };
package/src/index.tsx ADDED
@@ -0,0 +1 @@
1
+ export * from "./WalletConnector";
package/src/utils.tsx ADDED
@@ -0,0 +1,36 @@
1
+ function truncate(
2
+ str: string,
3
+ frontLen: number,
4
+ backLen: number,
5
+ truncateStr: string
6
+ ) {
7
+ if (!str) {
8
+ return "";
9
+ }
10
+
11
+ if (!Number.isInteger(frontLen) || !Number.isInteger(backLen)) {
12
+ throw `${frontLen} and ${backLen} should be an Integer`;
13
+ }
14
+
15
+ var strLen = str.length;
16
+ // Setting default values
17
+ frontLen = frontLen;
18
+ backLen = backLen;
19
+ truncateStr = truncateStr || "…";
20
+ if (
21
+ (frontLen === 0 && backLen === 0) ||
22
+ frontLen >= strLen ||
23
+ backLen >= strLen ||
24
+ frontLen + backLen >= strLen
25
+ ) {
26
+ return str;
27
+ } else if (backLen === 0) {
28
+ return str.slice(0, frontLen) + truncateStr;
29
+ } else {
30
+ return str.slice(0, frontLen) + truncateStr + str.slice(strLen - backLen);
31
+ }
32
+ }
33
+
34
+ export function truncateAddress(accountAddress: string) {
35
+ return truncate(accountAddress, 6, 4, "…");
36
+ }