Skip to content

Commit 0b71844

Browse files
authored
feat: change url to allow request from metamask (#46)
1 parent 0aaaadf commit 0b71844

23 files changed

+188
-47
lines changed

apps/etdstats/lib/Layout.tsx

+16-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
NextCirculatProgressBar,
88
UniversalSearchButton,
99
} from "ui";
10+
import { useBlockInfo } from "./hooks/useBlockInfo";
1011
import { db } from "./models/SearchModel";
1112
import { DrawerWidth } from "./settings/ui";
1213

@@ -16,6 +17,7 @@ export default function Layout(props: {
1617
}) {
1718
const router = useRouter();
1819
const [open, setOpen] = React.useState(false);
20+
const { blockInfoResult } = useBlockInfo({});
1921

2022
const search = useCallback(async (value: string) => {
2123
const result = await db.searchResults
@@ -34,8 +36,8 @@ export default function Layout(props: {
3436
<Box>
3537
<AppBar
3638
sx={{
37-
width: { sm: `calc(100% - ${DrawerWidth}px )` },
38-
ml: { sm: `${DrawerWidth}px` },
39+
width: { md: `calc(100% - ${DrawerWidth}px )` },
40+
ml: { md: `${DrawerWidth}px` },
3941
}}
4042
>
4143
<Toolbar
@@ -48,21 +50,26 @@ export default function Layout(props: {
4850
<UniversalSearchButton
4951
drawerWidth={DrawerWidth}
5052
onSearch={async (v) => {
51-
await router.push(`/info/${v}`);
53+
await router.push(`/tx/${v}`);
5254
}}
5355
onType={search}
5456
/>
5557
</Stack>
5658
<Stack direction={"row"} alignItems="center" spacing={2}>
5759
<NextCirculatProgressBar size={20} />
58-
<ConnectWalletButton />
60+
{blockInfoResult.data && (
61+
<ConnectWalletButton
62+
chainId={blockInfoResult.data!.chainId}
63+
rpc={blockInfoResult.data!.rpc}
64+
/>
65+
)}
5966
</Stack>
6067
</Toolbar>
6168
</AppBar>
6269
<Box component={"nav"}>
6370
<Drawer
6471
variant="temporary"
65-
open={open}
72+
open={false}
6673
ModalProps={{
6774
keepMounted: true,
6875
}}
@@ -79,7 +86,7 @@ export default function Layout(props: {
7986
<Drawer
8087
variant="permanent"
8188
sx={{
82-
display: { xs: "none", sm: "block" },
89+
display: { sm: "none", md: "block", xs: "none" },
8390
"& .MuiDrawer-paper": {
8491
boxSizing: "border-box",
8592
width: DrawerWidth,
@@ -94,11 +101,11 @@ export default function Layout(props: {
94101
mt={5}
95102
component="main"
96103
sx={{
97-
width: { sm: `calc(100% - ${DrawerWidth}px )` },
98-
pl: { sm: `${DrawerWidth}px` },
104+
width: { md: `calc(100% - ${DrawerWidth}px )` },
105+
pl: { md: `${DrawerWidth}px` },
99106
}}
100107
>
101-
<Box sx={{ paddingX: { md: 25, sm: 3, xs: 3 } }}>{props.children}</Box>
108+
<Box sx={{ paddingX: { lg: 25, sm: 3, xs: 3 } }}>{props.children}</Box>
102109
</Box>
103110
</Box>
104111
);

apps/etdstats/lib/Menu.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const menus: Menu[] = [
3535
{
3636
name: "Info",
3737
icon: <InfoIcon />,
38-
href: "/info",
38+
href: "/tx",
3939
},
4040
];
4141

apps/etdstats/lib/components/display/BlockDisplay.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const columns: GridColDef[] = [
3434
headerName: "Hash",
3535
flex: 10,
3636
renderCell: (rowData) => (
37-
<Link href={`/info/${rowData.value}`}>{rowData.value}</Link>
37+
<Link href={`/tx/${rowData.value}`}>{rowData.value}</Link>
3838
),
3939
},
4040
{
@@ -55,7 +55,7 @@ export default function TransactionDisplay({ data }: Props) {
5555

5656
const navTo = useCallback(async (id: string) => {
5757
console.log("navTo", id);
58-
await router.push(`/info/${id}`);
58+
await router.push(`/tx/${id}`);
5959
}, []);
6060

6161
return (

apps/etdstats/lib/components/display/TransactionDisplay.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function TransactionDisplay({ data }: Props) {
2121

2222
const navTo = useCallback(async (id: string) => {
2323
console.log("navTo", id);
24-
await router.push(`/info/${id}`);
24+
await router.push(`/tx/${id}`);
2525
}, []);
2626

2727
return (

apps/etdstats/lib/components/display/UserDisplay.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const columns: GridColDef[] = [
5757
flex: 4,
5858
sortable: false,
5959
renderCell: (rowData) => (
60-
<Link href={`/info/${rowData.value}`} noWrap>
60+
<Link href={`/tx/${rowData.value}`} noWrap>
6161
{rowData.value}
6262
</Link>
6363
),
@@ -133,7 +133,7 @@ export default function TransactionDisplay({ data, id, currentPage }: Props) {
133133
const onPageChange = useCallback(
134134
async (page: number) => {
135135
setLoading(true);
136-
await router.push(`/info/${id}?page=${page}`, undefined, {
136+
await router.push(`/tx/${id}?page=${page}`, undefined, {
137137
scroll: false,
138138
});
139139
setPage(page);

apps/etdstats/lib/components/table/GeneralBlockTable.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ const columns: GridColDef[] = [
1616
{
1717
headerName: "#",
1818
field: "id",
19-
flex: 1,
19+
flex: 4,
2020
},
2121
{
2222
field: "hash",
2323
headerName: "Hash",
2424
flex: 10,
2525
renderCell: (rowData) => (
26-
<Link href={`/info/${rowData.value}`}>{rowData.value}</Link>
26+
<Link href={`/tx/${rowData.value}`}>{rowData.value}</Link>
2727
),
2828
},
2929
{

apps/etdstats/lib/components/table/GeneralTransactionTable.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const columns: GridColDef[] = [
3333
headerName: "Hash",
3434
flex: 10,
3535
renderCell: (rowData) => (
36-
<Link href={`/info/${rowData.value}`}>{rowData.value}</Link>
36+
<Link href={`/tx/${rowData.value}`}>{rowData.value}</Link>
3737
),
3838
},
3939
{
File renamed without changes.
File renamed without changes.

node_packages/openapi_client/src/block_info_service.ts

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export interface BlockInfoResponse {
1515
difficultyChangePercentage: "string";
1616
blockTimeHistory: string[];
1717
difficultyHistory: string[];
18+
chainId: string;
19+
rpc: string;
1820
}
1921

2022
export interface PaginationResponse<T> {

node_packages/openapi_specs/specs/block_info_service.yaml

+7-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ components:
142142
schemas:
143143
block-info:
144144
type: object
145-
required: [ "numBlocks", "numTransactions", "blockTime", "blockTimeHistory", "difficultyHistory" ]
145+
required: [ "numBlocks", "numTransactions", "blockTime", "blockTimeHistory", "difficultyHistory", "chainId" ]
146146
properties:
147147
numBlocks:
148148
type: number
@@ -174,5 +174,10 @@ components:
174174
description: List of blocks' difficulty
175175
items:
176176
type: number
177-
177+
chainId:
178+
type: string
179+
description: ChainID in hex string
180+
rpc:
181+
type: number
182+
description: RPC URL
178183

node_packages/openapi_specs/src/analytics_service.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"openapi": "3.0.0",
33
"info": {
44
"description": "This belongs part of ETDStats microservices which will provide a analytics service",
5-
"version": "0.22.0",
5+
"version": "1.1.0",
66
"title": "Analytics service",
77
"termsOfService": "https://github.com/etherdata-blockchain"
88
},

node_packages/openapi_specs/src/block_info_service.json

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"openapi": "3.0.0",
33
"info": {
44
"description": "This belongs part of ETDStats microservices which will provide a analytics service",
5-
"version": "0.22.0",
5+
"version": "1.1.0",
66
"title": "Block Info service",
77
"termsOfService": "https://github.com/etherdata-blockchain"
88
},
@@ -489,7 +489,8 @@
489489
"numTransactions",
490490
"blockTime",
491491
"blockTimeHistory",
492-
"difficultyHistory"
492+
"difficultyHistory",
493+
"chainId"
493494
],
494495
"properties": {
495496
"numBlocks": {
@@ -531,6 +532,14 @@
531532
"items": {
532533
"type": "number"
533534
}
535+
},
536+
"chainId": {
537+
"type": "string",
538+
"description": "ChainID in hex string"
539+
},
540+
"rpc": {
541+
"type": "number",
542+
"description": "RPC URL"
534543
}
535544
}
536545
}

node_packages/openapi_specs/src/health_service.spec.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"openapi": "3.0.0",
33
"info": {
44
"description": "This belongs part of ETDStats microservices which will provide a health check",
5-
"version": "0.22.0",
5+
"version": "1.1.0",
66
"title": "Health service",
77
"termsOfService": "https://github.com/etherdata-blockchain"
88
},

node_packages/openapi_specs/src/node_service.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"openapi": "3.0.0",
33
"info": {
44
"description": "This belongs part of ETDStats microservices which will provide a node service. Pending!",
5-
"version": "0.22.0",
5+
"version": "1.1.0",
66
"title": "Node service",
77
"termsOfService": "https://github.com/etherdata-blockchain"
88
},

node_packages/openapi_specs/src/transaction_service.spec.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"openapi": "3.0.0",
33
"info": {
44
"description": "This belongs part of ETDStats microservices which will provide a transaction and block services",
5-
"version": "0.22.0",
5+
"version": "1.1.0",
66
"title": "Transaction service",
77
"termsOfService": "https://github.com/etherdata-blockchain"
88
},
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,94 @@
11
import React, { useCallback } from "react";
22
import AccountBalanceWalletIcon from "@mui/icons-material/AccountBalanceWallet";
3-
import { Fade, IconButton, Tooltip } from "@mui/material";
3+
import {
4+
Box,
5+
Fade,
6+
IconButton,
7+
ListItem,
8+
ListItemText,
9+
Menu,
10+
MenuItem,
11+
Paper,
12+
Popover,
13+
Tooltip,
14+
Typography,
15+
List,
16+
ListItemButton,
17+
Card,
18+
Divider,
19+
} from "@mui/material";
420
import { useMetaMask } from "metamask-react";
21+
import { useRouter } from "next/router";
22+
import Link from "next/link";
523

6-
export function ConnectWalletButton() {
7-
const { status, connect } = useMetaMask();
24+
interface Props {
25+
chainId: string;
26+
rpc: string;
27+
}
28+
29+
export function ConnectWalletButton({ chainId, rpc }: Props) {
30+
const { status, connect, addChain, account } = useMetaMask();
31+
const router = useRouter();
32+
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
833

9-
const onClick = useCallback(() => {
10-
if (status === "connected") {
11-
return;
12-
}
34+
const onClick = useCallback(
35+
async (e: any) => {
36+
if (status === "connected") {
37+
setAnchorEl(e.currentTarget);
38+
return;
39+
}
40+
let getUrl = window.location;
41+
let baseUrl =
42+
getUrl.protocol +
43+
"//" +
44+
getUrl.host +
45+
"/" +
46+
getUrl.pathname.split("/")[1];
1347

14-
connect();
15-
}, [status]);
48+
await connect();
49+
await addChain({
50+
chainId: chainId,
51+
chainName: "Etherdata Network",
52+
rpcUrls: [rpc],
53+
nativeCurrency: {
54+
name: "ETD",
55+
symbol: "ETD",
56+
decimals: 18,
57+
},
58+
blockExplorerUrls: [baseUrl],
59+
});
60+
},
61+
[status]
62+
);
1663

1764
return (
18-
<Fade in={status !== "unavailable"}>
19-
<Tooltip title={status}>
20-
<IconButton
21-
color={status === "connected" ? "success" : "default"}
22-
onClick={onClick}
65+
<>
66+
<Fade in={status !== "unavailable"}>
67+
<Tooltip title={status}>
68+
<IconButton
69+
color={status === "connected" ? "success" : "default"}
70+
onClick={onClick}
71+
>
72+
<AccountBalanceWalletIcon />
73+
</IconButton>
74+
</Tooltip>
75+
</Fade>
76+
<Menu
77+
onClose={() => setAnchorEl(null)}
78+
anchorEl={anchorEl}
79+
open={Boolean(anchorEl)}
80+
anchorOrigin={{ vertical: "bottom", horizontal: "left" }}
81+
>
82+
<MenuItem
83+
onClick={async () => {
84+
await router.push(`/tx/${account}`);
85+
setAnchorEl(null);
86+
}}
2387
>
24-
<AccountBalanceWalletIcon />
25-
</IconButton>
26-
</Tooltip>
27-
</Fade>
88+
Profile
89+
</MenuItem>
90+
<MenuItem>Settings</MenuItem>
91+
</Menu>
92+
</>
2893
);
2994
}

services/block_info_service/Package.resolved

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"pins" : [
3+
{
4+
"identity" : "alamofire",
5+
"kind" : "remoteSourceControl",
6+
"location" : "https://github.com/Alamofire/Alamofire",
7+
"state" : {
8+
"revision" : "354dda32d89fc8cd4f5c46487f64957d355f53d8",
9+
"version" : "5.6.1"
10+
}
11+
},
312
{
413
"identity" : "async-http-client",
514
"kind" : "remoteSourceControl",

0 commit comments

Comments
 (0)