Skip to content

Commit

Permalink
(W3B.BZ): V0.1.0 - cached token calls + collections viewer + fixes & …
Browse files Browse the repository at this point in the history
…patches
  • Loading branch information
LFBarreto committed Jan 30, 2022
1 parent 3ea76eb commit 9567a22
Show file tree
Hide file tree
Showing 39 changed files with 4,080 additions and 300 deletions.
21 changes: 19 additions & 2 deletions cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ module.exports = [
const isSameOrigin = self.origin === url.origin;
if (!isSameOrigin) return false;
const pathname = url.pathname;
console.log("SW", pathname, isSameOrigin);
if (pathname.startsWith("/api/blobbz")) return true;
if (pathname.startsWith("/api/blobbz/")) return true;
return false;
},
handler: "CacheFirst",
Expand All @@ -143,6 +142,24 @@ module.exports = [
},
},
},
{
urlPattern: ({ url }) => {
const isSameOrigin = self.origin === url.origin;
if (!isSameOrigin) return false;
const pathname = url.pathname;
if (pathname.startsWith("/api/blobbz/")) return false;
if (pathname.startsWith("/api/blobbz?page=")) return true;
return false;
},
handler: "CacheFirst",
options: {
cacheName: "blobz-collection-cache",
expiration: {
maxEntries: 52,
maxAgeSeconds: 5, // 5 min
},
},
},
{
urlPattern: ({ url }) => {
const isSameOrigin = self.origin === url.origin;
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "w3bbz",
"private": true,
"version": "0.1.0",
"scripts": {
"dev": "next dev",
"build": "next build",
Expand All @@ -9,19 +10,16 @@
"typecheck": "tsc --p . --noEmit"
},
"dependencies": {
"@types/ioredis": "^4.28.7",
"@types/styled-system": "^5.1.15",
"ethers": "^5.5.3",
"ioredis": "^4.28.3",
"lodash": "^4.17.21",
"modern-normalize": "^1.1.0",
"next": "12.0.8",
"next-i18next": "^10.2.0",
"next-pwa": "^5.4.4",
"qrcode-generator": "^1.4.4",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-use": "^17.3.2",
"rxjs": "^7.5.2",
"styled-components": "^5.2.3",
"styled-system": "^5.1.5",
"swr": "^1.2.0",
Expand All @@ -31,6 +29,8 @@
"@types/react-dom": "^17.0.11",
"@types/styled-components": "^5.1.20",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@types/ioredis": "^4.28.7",
"@types/styled-system": "^5.1.15",
"eslint": "^8.7.0",
"eslint-config-next": "^12.0.8",
"eslint-config-prettier": "^8.3.0",
Expand Down
58 changes: 1 addition & 57 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
SmileyContainer,
} from "../src/components";
import "modern-normalize";
import "../styles/global.css";

function MyApp({ Component, pageProps }: AppProps): JSX.Element {
return (
Expand All @@ -20,63 +21,6 @@ function MyApp({ Component, pageProps }: AppProps): JSX.Element {
name="viewport"
content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no, user-scalable=no, viewport-fit=cover"
/>
<meta name="application-name" content="W3BBZ" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta
name="apple-mobile-web-app-status-bar-style"
content="black-translucent"
/>
<meta name="apple-mobile-web-app-title" content="W3BBZ" />
<meta name="description" content="W3BBZ" />
<meta name="format-detection" content="telephone=no" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="msapplication-config" content="/icons/browserconfig.xml" />
<meta name="msapplication-tap-highlight" content="no" />

<link
rel="preload"
href="/fonts/tinier.regular.woff2"
as="font"
type="font/woff2"
/>
<link
rel="preload"
href="/fonts/tiny.regular.woff2"
as="font"
type="font/woff2"
/>
<link
rel="preload"
href="/fonts/5by7.bold.woff2"
as="font"
type="font/woff2"
/>
<link
rel="preload"
href="/fonts/5by7.regular.woff2"
as="font"
type="font/woff2"
/>
<link
rel="preload"
href="/fonts/FuturaLT-Bold.woff2"
as="font"
type="font/woff2"
/>

<link rel="apple-touch-icon" href="/iconx72.png" />
<link rel="apple-touch-icon" sizes="152x152" href="/iconx152.png" />
<link rel="apple-touch-icon" sizes="180x180" href="/iconx180.png" />
<link rel="apple-touch-icon" sizes="167x167" href="/iconx167.png" />

<link rel="icon" type="image/png" sizes="32x32" href="/iconx32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/iconx16.png" />
<link rel="shortcut icon" href="/favicon.ico" />

<meta property="og:type" content="website" />
<meta property="og:title" content="W3BBZ" />

<link rel="manifest" href="/manifest.json" />
<title>W3bbz</title>
</Head>
<Wagmi>
Expand Down
81 changes: 80 additions & 1 deletion pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React from "react";
import Document, { DocumentContext } from "next/document";
import Document, {
DocumentContext,
Html,
Head,
Main,
NextScript,
} from "next/document";
import { ServerStyleSheet } from "styled-components";
import { AppType } from "next/dist/shared/lib/utils";

Expand Down Expand Up @@ -29,4 +35,77 @@ export default class MyDocument extends Document {
sheet.seal();
}
}

render() {
return (
<Html lang="en">
<Head>
<meta name="application-name" content="W3BBZ" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta
name="apple-mobile-web-app-status-bar-style"
content="black-translucent"
/>
<meta name="apple-mobile-web-app-title" content="W3BBZ" />
<meta name="description" content="W3BBZ" />
<meta name="format-detection" content="telephone=no" />
<meta name="mobile-web-app-capable" content="yes" />
<meta
name="msapplication-config"
content="/icons/browserconfig.xml"
/>
<meta name="msapplication-tap-highlight" content="no" />

<link
rel="preload"
href="/fonts/tinier.regular.woff2"
as="font"
type="font/woff2"
/>
<link
rel="preload"
href="/fonts/tiny.regular.woff2"
as="font"
type="font/woff2"
/>
<link
rel="preload"
href="/fonts/5by7.bold.woff2"
as="font"
type="font/woff2"
/>
<link
rel="preload"
href="/fonts/5by7.regular.woff2"
as="font"
type="font/woff2"
/>
<link
rel="preload"
href="/fonts/FuturaLT-Bold.woff2"
as="font"
type="font/woff2"
/>

<link rel="apple-touch-icon" href="/iconx72.png" />
<link rel="apple-touch-icon" sizes="152x152" href="/iconx152.png" />
<link rel="apple-touch-icon" sizes="180x180" href="/iconx180.png" />
<link rel="apple-touch-icon" sizes="167x167" href="/iconx167.png" />

<link rel="icon" type="image/png" sizes="32x32" href="/iconx32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/iconx16.png" />
<link rel="shortcut icon" href="/favicon.ico" />

<meta property="og:type" content="website" />
<meta property="og:title" content="W3BBZ" />

<link rel="manifest" href="/manifest.json" />
</Head>
<body className="loading">
<Main />
<NextScript />
</body>
</Html>
);
}
}
1 change: 1 addition & 0 deletions pages/about/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function About() {
<meta property="og:image" content="https://w3b.bz/iconx512.png" />
</Head>
<Articles
pt={153}
articlesJSON={{
title: "About",
subTitle:
Expand Down
19 changes: 17 additions & 2 deletions pages/api/blobbz/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const CONTRACT_ADDRESS =
process.env.BLOBZ_CONTRACT_ADDRESS ||
process.env.NEXT_PUBLIC_BLOBZ_CONTRACT_ADDRESS;

const VERSION = process.env.VERSION_ID || process.env.NEXT_PUBLIC_VERSION_ID;

const INFURA_ID = process.env.INFURA_ID || process.env.NEXT_PUBLIC_INFURA_ID;

const headers = {
Expand All @@ -21,6 +23,7 @@ const requestID = 42;
const tokenURIHex = "0xc87b56dd";
const pad32 = Array(32).fill("00").join("");
const JSON_PREFIX = "data:application/json;base64,";
const SVG_PREFIX = "data:image/svg+xml;base64,";

const padValue = (value: string) => (pad32 + value).substr(value.length);

Expand Down Expand Up @@ -57,7 +60,7 @@ export default async function blobbzHandler(
query: { id },
} = req;
const nId = parseInt(id);
const cacheID = "tokenURI:" + CONTRACT_ADDRESS;
const cacheID = "tokenURI:" + VERSION + ":" + CONTRACT_ADDRESS;

const cache = await redis.hget(cacheID, id);

Expand All @@ -78,7 +81,19 @@ export default async function blobbzHandler(
const tokenURI = hexResult
.substr(hexResult.indexOf(JSON_PREFIX))
.replace(/\x00+/g, "");
const parsedResult = { tokenURI };
const metadata = JSON.parse(
Buffer.from(tokenURI.replace(JSON_PREFIX, ""), "base64").toString(
"binary"
)
);

metadata.image = Buffer.from(
metadata.image.replace(SVG_PREFIX, ""),
"base64"
).toString("binary");

const parsedResult = { metadata, id };

redis.hset(cacheID, id, JSON.stringify(parsedResult));
return res.status(200).json(parsedResult);
});
Expand Down
Loading

1 comment on commit 9567a22

@vercel
Copy link

@vercel vercel bot commented on 9567a22 Jan 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

Please sign in to comment.