mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +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
27 lines
817 B
TypeScript
27 lines
817 B
TypeScript
import { useRouter } from 'next/router';
|
|
import React from 'react';
|
|
|
|
import config from 'configs/app';
|
|
import { fromBech32Address, isBech32Address } from 'lib/address/bech32';
|
|
|
|
export default function useCheckAddressFormat(hash: string) {
|
|
const router = useRouter();
|
|
const hasBech32Format = config.UI.views.address.hashFormat.availableFormats.includes('bech32') && isBech32Address(hash);
|
|
const [ isLoading, setIsLoading ] = React.useState(hasBech32Format);
|
|
|
|
React.useEffect(() => {
|
|
if (!isLoading) {
|
|
return;
|
|
}
|
|
|
|
const base16Hash = fromBech32Address(hash);
|
|
if (base16Hash !== hash) {
|
|
router.replace({ pathname: '/address/[hash]', query: { ...router.query, hash: base16Hash } });
|
|
} else {
|
|
setIsLoading(false);
|
|
}
|
|
}, [ hash, isLoading, router ]);
|
|
|
|
return isLoading;
|
|
}
|