Skip to content

Instantly share code, notes, and snippets.

@ibelick
ibelick / home.tsx
Created February 16, 2022 14:33
Next.js basic GetStaticProps+GetStaticPaths with TypeScript
import type { GetStaticPaths, GetStaticProps, NextPage } from "next";
import { ParsedUrlQuery } from "querystring";
interface Data {
title: string;
}
interface HomePageProps {
data: Data;
}
@ibelick
ibelick / home.tsx
Created February 15, 2022 14:11
Next.js basic GetStaticProps with TypeScript
import { GetStaticProps, NextPage } from "next";
interface Data {
title: string;
}
interface HomePageProps {
data: Data;
}
@ibelick
ibelick / ButtonConnectWallet.tsx
Created February 14, 2022 14:56
Simple connect to MetaMask with React + TypeScript
const ButtonConnectWallet: React.FC = () => {
const [address, setAddress] = useState<string | null>(null);
const connectWallet = async () => {
if (!window?.ethereum) {
alert("No wallet found. Please install MetaMask.");
return;
}
try {
@ibelick
ibelick / truncateEthAddress.ts
Created February 14, 2022 14:29
utility to truncate Ethereum addresses to a more readable format
export const truncateEthAddress = (address: string) => {
const truncateRegex = /^(0x[a-zA-Z0-9]{4})[a-zA-Z0-9]+([a-zA-Z0-9]{4})$/;
const match = address.match(truncateRegex);
if (!match) return address;
return `${match[1]}…${match[2]}`;
};