Skip to content

Commit edb12b9

Browse files
authored
Overhaul of Addresses page and implementation of a conversion tool. (#39)
1 parent 6a25293 commit edb12b9

File tree

9 files changed

+483
-53
lines changed

9 files changed

+483
-53
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ navigation.
7474

7575
4. **Open the code and start customizing!**
7676

77-
Your site is now running at `http://localhost:3000/docs`.
77+
Your site is now running at `http://localhost:3000/`.
7878

7979
Edit to see your site update in real-time on save.
8080

components.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"prefix": ""
1212
},
1313
"aliases": {
14-
"components": "@/components",
15-
"utils": "@/lib/utils"
14+
"components": "./components",
15+
"utils": "./lib/utils"
1616
}
1717
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import React, { useState } from "react";
2+
import {
3+
blake2AsU8a,
4+
encodeAddress,
5+
decodeAddress,
6+
} from "@polkadot/util-crypto";
7+
import { hexToU8a, stringToU8a, u8aConcat, u8aToHex } from "@polkadot/util";
8+
import {
9+
Card,
10+
CardContent,
11+
CardDescription,
12+
CardFooter,
13+
CardHeader,
14+
CardTitle,
15+
} from "./ui/card";
16+
import { Button } from "./ui/button";
17+
import { BlockCopyButton } from "./ui/block-copy-button";
18+
import Link from "next/link";
19+
20+
const AddressConverter = () => {
21+
const [evmAddress, setEvmAddress] = useState("");
22+
const [substrateAddress, setSubstrateAddress] = useState("");
23+
const [substrateAddressToConvert, setSubstrateAddressToConvert] =
24+
useState("");
25+
const [evmAddressResult, setEvmAddressResult] = useState("");
26+
27+
const convertEvmToSubstrate = () => {
28+
if (!evmAddress) {
29+
setSubstrateAddress("Please enter an EVM address.");
30+
return;
31+
}
32+
const addr = hexToU8a(evmAddress);
33+
const data = stringToU8a("evm:");
34+
const res = blake2AsU8a(u8aConcat(data, addr));
35+
const output = encodeAddress(res, 42);
36+
setSubstrateAddress(output);
37+
};
38+
39+
return (
40+
<div className="mt-8">
41+
<Card>
42+
<CardHeader>
43+
<CardTitle>EVM-to-Substrate Address Converter</CardTitle>
44+
<CardDescription>
45+
Enter an EVM Address to convert to the SS58 Substrate format. To
46+
convert an SS58 address to a public key, you can use{" "}
47+
<Link
48+
className="underline font-semibold text-linkBlue"
49+
href="https://ss58.org/"
50+
>
51+
SS58.org
52+
</Link>
53+
</CardDescription>
54+
</CardHeader>
55+
<CardContent>
56+
<div className="flex items-center space-x-4">
57+
<div className="flex-1">
58+
<label
59+
htmlFor="evmAddress"
60+
className="block mb-1 text-gray-800 font-semibold"
61+
>
62+
EVM Address:
63+
</label>
64+
<input
65+
type="text"
66+
id="evmAddress"
67+
className="bg-gray-200 text-gray-800 font-mono px-4 py-2 rounded w-full"
68+
value={evmAddress}
69+
onChange={(e) => setEvmAddress(e.target.value)}
70+
placeholder="Enter EVM address"
71+
/>
72+
</div>
73+
<div className="flex-1">
74+
<label
75+
htmlFor="substrateAddress"
76+
className="block mb-1 font-semibold"
77+
>
78+
Substrate Address:
79+
</label>
80+
<div
81+
id="substrateAddress"
82+
className="bg-gray-200 px-4 py-2 font-mono rounded w-full text-gray-800"
83+
>
84+
{substrateAddress || "Waiting..."}
85+
</div>
86+
</div>
87+
<div className="ml-0 self-end flex">
88+
<BlockCopyButton
89+
name="Substrate Address"
90+
code={substrateAddress}
91+
className="h-10 w-10 rounded [&_svg]:size-4"
92+
/>
93+
</div>
94+
</div>
95+
</CardContent>
96+
<CardFooter>
97+
<Button className="w-full" onClick={convertEvmToSubstrate}>
98+
Convert
99+
</Button>
100+
</CardFooter>
101+
</Card>
102+
</div>
103+
);
104+
};
105+
106+
export default AddressConverter;

components/ui/card.tsx

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import * as React from "react";
2+
3+
import { cn } from "../../lib/utils";
4+
5+
const Card = React.forwardRef<
6+
HTMLDivElement,
7+
React.HTMLAttributes<HTMLDivElement>
8+
>(({ className, ...props }, ref) => (
9+
<div
10+
ref={ref}
11+
className={cn(
12+
"rounded-lg border bg-card text-card-foreground shadow-sm",
13+
className,
14+
)}
15+
{...props}
16+
/>
17+
));
18+
Card.displayName = "Card";
19+
20+
const CardHeader = React.forwardRef<
21+
HTMLDivElement,
22+
React.HTMLAttributes<HTMLDivElement>
23+
>(({ className, ...props }, ref) => (
24+
<div
25+
ref={ref}
26+
className={cn("flex flex-col space-y-1.5 p-6", className)}
27+
{...props}
28+
/>
29+
));
30+
CardHeader.displayName = "CardHeader";
31+
32+
const CardTitle = React.forwardRef<
33+
HTMLParagraphElement,
34+
React.HTMLAttributes<HTMLHeadingElement>
35+
>(({ className, ...props }, ref) => (
36+
<h3
37+
ref={ref}
38+
className={cn(
39+
"text-2xl font-semibold leading-none tracking-tight",
40+
className,
41+
)}
42+
{...props}
43+
/>
44+
));
45+
CardTitle.displayName = "CardTitle";
46+
47+
const CardDescription = React.forwardRef<
48+
HTMLParagraphElement,
49+
React.HTMLAttributes<HTMLParagraphElement>
50+
>(({ className, ...props }, ref) => (
51+
<p
52+
ref={ref}
53+
className={cn("text-sm text-muted-foreground", className)}
54+
{...props}
55+
/>
56+
));
57+
CardDescription.displayName = "CardDescription";
58+
59+
const CardContent = React.forwardRef<
60+
HTMLDivElement,
61+
React.HTMLAttributes<HTMLDivElement>
62+
>(({ className, ...props }, ref) => (
63+
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
64+
));
65+
CardContent.displayName = "CardContent";
66+
67+
const CardFooter = React.forwardRef<
68+
HTMLDivElement,
69+
React.HTMLAttributes<HTMLDivElement>
70+
>(({ className, ...props }, ref) => (
71+
<div
72+
ref={ref}
73+
className={cn("flex items-center p-6 pt-0", className)}
74+
{...props}
75+
/>
76+
));
77+
CardFooter.displayName = "CardFooter";
78+
79+
export {
80+
Card,
81+
CardHeader,
82+
CardFooter,
83+
CardTitle,
84+
CardDescription,
85+
CardContent,
86+
};

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "docs",
3-
"version": "1.0.0",
2+
"name": "tangle-docs",
3+
"version": "2.0.0",
44
"private": true,
5-
"description": "Webb docs",
5+
"description": "Tangle Network Documentation",
66
"scripts": {
77
"dev": "next",
88
"start": "next start",
@@ -14,13 +14,15 @@
1414
"format": "prettier --write \"{components,pages}/**/*.{mdx,ts,js,jsx,tsx,json}\" ",
1515
"format:check": "prettier --check \"{components,pages}/**/*.{mdx,ts,js,jsx,tsx,json}\" "
1616
},
17-
"author": "Webb Team",
17+
"author": "Tangle Foundation",
1818
"license": "MPL-2.0",
1919
"dependencies": {
2020
"@headlessui/react": "^1.7.7",
2121
"@heroicons/react": "1.0.6",
2222
"@mdx-js/react": "^2.2.1",
2323
"@next/third-parties": "^14.2.3",
24+
"@polkadot/util": "^12.6.2",
25+
"@polkadot/util-crypto": "^12.6.2",
2426
"@radix-ui/react-slot": "^1.0.2",
2527
"@radix-ui/react-tooltip": "^1.0.7",
2628
"@react-aria/ssr": "3.4.0",

pages/developers/_meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"integrate": "Endpoints and Other Resources",
2020
"deploy-using-hardhat": "Deploy on Tangle with Hardhat",
2121
"json-rpc-endpoints": "RPC Methods",
22-
"addresses": "EVM and Address Conversion",
22+
"addresses": "Account Addresses",
2323
"transaction-fees": "Calculating Transaction Fees",
2424
"-- contribute": {
2525
"type": "separator",

0 commit comments

Comments
 (0)