mirror of
https://github.com/hanzonet/explore.git
synced 2026-10-30 18:16:57 +00:00
* create settings context with simple address format toggler * transform base16 hash to bech32 hash * add ENV variables * add snippet to address page * add redirect for bech32 addresses * change address format in search * add provider to tests * update demo values * migrate from Buffer to Uint8Array and add tests * bug fixes and screenshots updates * review fixes * roll back changes in env values * update screenshots
21 lines
828 B
TypeScript
21 lines
828 B
TypeScript
import type { NextRequest, NextResponse } from 'next/server';
|
|
|
|
import type { AddressFormat } from 'types/views/address';
|
|
|
|
import config from 'configs/app';
|
|
import * as cookiesLib from 'lib/cookies';
|
|
|
|
export default function addressFormatMiddleware(req: NextRequest, res: NextResponse) {
|
|
const addressFormatCookie = req.cookies.get(cookiesLib.NAMES.ADDRESS_FORMAT);
|
|
const defaultFormat = config.UI.views.address.hashFormat.availableFormats[0];
|
|
|
|
if (addressFormatCookie) {
|
|
const isValidCookie = config.UI.views.address.hashFormat.availableFormats.includes(addressFormatCookie.value as AddressFormat);
|
|
if (!isValidCookie) {
|
|
res.cookies.set(cookiesLib.NAMES.ADDRESS_FORMAT, defaultFormat, { path: '/' });
|
|
}
|
|
} else {
|
|
res.cookies.set(cookiesLib.NAMES.ADDRESS_FORMAT, defaultFormat, { path: '/' });
|
|
}
|
|
}
|