Commit 3cc098e9 authored by tom's avatar tom

remove link

parent 75aca5c0
const PATHS = require('../../lib/link/paths.json');
const oldUrls = [ const oldUrls = [
{ {
oldPath: '/account/tag_transaction', oldPath: '/account/tag_transaction',
newPath: `${ PATHS.private_tags }?tab=tx`, newPath: '/account/tag_address?tab=tx',
}, },
{ {
oldPath: '/pending-transactions', oldPath: '/pending-transactions',
newPath: `${ PATHS.txs }?tab=pending`, newPath: '/txs?tab=pending',
}, },
{ {
oldPath: '/tx/:hash/internal-transactions', oldPath: '/tx/:hash/internal-transactions',
newPath: `${ PATHS.tx }?tab=internal`, newPath: '/tx/:hash?tab=internal',
}, },
{ {
oldPath: '/tx/:hash/logs', oldPath: '/tx/:hash/logs',
newPath: `${ PATHS.tx }?tab=logs`, newPath: '/tx/:hash?tab=logs',
}, },
{ {
oldPath: '/tx/:hash/raw-trace', oldPath: '/tx/:hash/raw-trace',
newPath: `${ PATHS.tx }?tab=raw_trace`, newPath: '/tx/:hash?tab=raw_trace',
}, },
{ {
oldPath: '/tx/:hash/state', oldPath: '/tx/:hash/state',
newPath: `${ PATHS.tx }?tab=state`, newPath: '/tx/:hash?tab=state',
}, },
{ {
oldPath: '/uncles', oldPath: '/uncles',
newPath: `${ PATHS.blocks }?tab=uncles`, newPath: '/blocks?tab=uncles',
}, },
{ {
oldPath: '/reorgs', oldPath: '/reorgs',
newPath: `${ PATHS.blocks }?tab=reorgs`, newPath: '/blocks?tab=reorgs',
}, },
{ {
oldPath: '/block/:height/transactions', oldPath: '/block/:height/transactions',
newPath: `${ PATHS.block }?tab=txs`, newPath: '/block/:height?tab=txs',
}, },
{ {
oldPath: '/address/:hash/transactions', oldPath: '/address/:hash/transactions',
newPath: `${ PATHS.address_index }`, newPath: '/address/:hash',
}, },
{ {
oldPath: '/address/:hash/token-transfers', oldPath: '/address/:hash/token-transfers',
newPath: `${ PATHS.address_index }?tab=token_transfers`, newPath: '/address/:hash?tab=token_transfers',
}, },
{ {
oldPath: '/address/:hash/tokens', oldPath: '/address/:hash/tokens',
newPath: `${ PATHS.address_index }?tab=tokens`, newPath: '/address/:hash?tab=tokens',
}, },
{ {
oldPath: '/address/:hash/internal-transactions', oldPath: '/address/:hash/internal-transactions',
newPath: `${ PATHS.address_index }?tab=internal_txns`, newPath: '/address/:hash?tab=internal_txns',
}, },
{ {
oldPath: '/address/:hash/coin-balances', oldPath: '/address/:hash/coin-balances',
newPath: `${ PATHS.address_index }?tab=coin_balance_history`, newPath: '/address/:hash?tab=coin_balance_history',
}, },
{ {
oldPath: '/address/:hash/validations', oldPath: '/address/:hash/validations',
newPath: `${ PATHS.address_index }?tab=blocks_validated`, newPath: '/address/:hash?tab=blocks_validated',
}, },
{ {
oldPath: '/address/:hash/tokens/:token_hash/token-transfers', oldPath: '/address/:hash/tokens/:token_hash/token-transfers',
newPath: `${ PATHS.address_index }?tab=token_transfers&token=:token_hash`, newPath: '/address/:hash?tab=token_transfers&token=:token_hash',
}, },
// contract verification // contract verification
{ {
oldPath: '/address/:hash/contract_verifications/new', oldPath: '/address/:hash/contract_verifications/new',
newPath: `${ PATHS.address_contract_verification }`, newPath: '/address/:hash/contract_verification',
}, },
{ {
oldPath: '/address/:hash/verify-via-flattened-code/new', oldPath: '/address/:hash/verify-via-flattened-code/new',
newPath: `${ PATHS.address_contract_verification }?method=flatten_source_code`, newPath: '/address/:hash/contract_verification?method=flatten_source_code',
}, },
{ {
oldPath: '/address/:hash/verify-via-standard-json-input/new', oldPath: '/address/:hash/verify-via-standard-json-input/new',
newPath: `${ PATHS.address_contract_verification }?method=standard_input`, newPath: '/address/:hash/contract_verification?method=standard_input',
}, },
{ {
oldPath: '/address/:hash/verify-via-metadata-json/new', oldPath: '/address/:hash/verify-via-metadata-json/new',
newPath: `${ PATHS.address_contract_verification }?method=sourcify`, newPath: '/address/:hash/contract_verification?method=sourcify',
}, },
{ {
oldPath: '/address/:hash/verify-via-multi-part-files/new', oldPath: '/address/:hash/verify-via-multi-part-files/new',
newPath: `${ PATHS.address_contract_verification }?method=multi_part_file`, newPath: '/address/:hash/contract_verification?method=multi_part_file',
}, },
{ {
oldPath: '/address/:hash/verify-vyper-contract/new', oldPath: '/address/:hash/verify-vyper-contract/new',
newPath: `${ PATHS.address_contract_verification }?method=vyper_contract`, newPath: '/address/:hash/contract_verification?method=vyper_contract',
}, },
]; ];
......
import appConfig from 'configs/app/config';
import { ROUTES } from './routes';
import type { RouteName } from './routes';
const PATH_PARAM_REGEXP = /\/:(\w+)/g;
/**
* @deprecated Please consider to use "import { route } from 'nextjs-routes';" instead
*/
export default function link(
routeName: RouteName,
urlParams?: Record<string, Array<string> | string | undefined>,
queryParams?: Record<string, string>,
): string {
const route = ROUTES[routeName];
if (!route) {
return '';
}
const path = route.pattern.replace(PATH_PARAM_REGEXP, (_, paramName: string) => {
let paramValue = urlParams?.[paramName];
if (Array.isArray(paramValue)) {
// FIXME we don't have yet params as array, but typescript says that we could
// dunno know how to manage it, fix me if you find an issue
paramValue = paramValue.join(',');
}
return paramValue ? `/${ paramValue }` : '';
});
// const baseUrl = routeName === 'auth' ? appConfig.authUrl : appConfig.baseUrl;
const baseUrl = appConfig.baseUrl;
const url = new URL(path, baseUrl);
queryParams && Object.entries(queryParams).forEach(([ key, value ]) => {
url.searchParams.append(key, value);
});
return url.toString();
}
{
"network_index": "/",
"watchlist": "/account/watchlist",
"private_tags": "/account/tag_address",
"public_tags": "/account/public_tags_request",
"api_keys": "/account/api_key",
"custom_abi": "/account/custom_abi",
"profile": "/auth/profile",
"txs": "/txs",
"tx": "/tx/:hash",
"blocks": "/blocks",
"block": "/block/:height",
"tokens": "/tokens",
"token_index": "/token/:hash",
"token_instance_item": "/token/:hash/instance/:id",
"address_index": "/address/:hash",
"address_contract_verification": "/address/:hash/contract_verification",
"accounts": "/accounts",
"apps": "/apps",
"app_index": "/apps/:id",
"search_results": "/search-results",
"auth": "/auth/auth0",
"stats": "/stats",
"visualize_sol2uml": "/visualize/sol2uml",
"csv_export": "/csv-export"
}
import appConfig from 'configs/app/config';
// import PATHS from './paths.json';
export interface Route {
pattern: string;
crossNetworkNavigation?: boolean; // route will not change when switching networks
}
export type RouteName = keyof typeof ROUTES;
export const ROUTES = {
// NETWORK MAIN PAGE
// network_index: {
// pattern: PATHS.network_index,
// crossNetworkNavigation: true,
// },
// ACCOUNT
// watchlist: {
// pattern: PATHS.watchlist,
// },
// private_tags: {
// pattern: PATHS.private_tags,
// },
// public_tags: {
// pattern: PATHS.public_tags,
// },
// api_keys: {
// pattern: PATHS.api_keys,
// },
// custom_abi: {
// pattern: PATHS.custom_abi,
// },
// profile: {
// pattern: PATHS.profile,
// },
// TRANSACTIONS
// txs: {
// pattern: PATHS.txs,
// crossNetworkNavigation: true,
// },
// tx: {
// pattern: PATHS.tx,
// },
// BLOCKS
// blocks: {
// pattern: PATHS.blocks,
// crossNetworkNavigation: true,
// },
// block: {
// pattern: PATHS.block,
// },
// TOKENS
// tokens: {
// pattern: PATHS.tokens,
// crossNetworkNavigation: true,
// },
// token_index: {
// pattern: PATHS.token_index,
// crossNetworkNavigation: true,
// },
// token_instance_item: {
// pattern: PATHS.token_instance_item,
// },
// ADDRESSES
// address_index: {
// pattern: PATHS.address_index,
// crossNetworkNavigation: true,
// },
// address_contract_verification: {
// pattern: PATHS.address_contract_verification,
// crossNetworkNavigation: true,
// },
// ACCOUNTS
// accounts: {
// pattern: PATHS.accounts,
// crossNetworkNavigation: true,
// },
// APPS
// apps: {
// pattern: PATHS.apps,
// },
// app_index: {
// pattern: PATHS.app_index,
// },
// stats: {
// pattern: PATHS.stats,
// },
// SEARCH
// search_results: {
// pattern: PATHS.search_results,
// },
// VISUALIZE
// visualize_sol2uml: {
// pattern: PATHS.visualize_sol2uml,
// },
// csv_export: {
// pattern: PATHS.csv_export,
// },
// AUTH
// todo_tom need add page to the app
// auth: {
// pattern: PATHS.auth,
// },
};
// !!! for development purpose only !!!
// don't wanna strict ROUTES to type "Record<string, Route>"
// otherwise we lose benefit of using "keyof typeof ROUTES" for possible route names (it will be any string then)
// but we still want typescript to tell us if routes follow its interface
// so we do this simple type-checking here
//
// another option is to create common enum with all possible route names and use it across the project
// but it is a little bit overwhelming as it seems right now
function checkRoutes(route: Record<string, Route>) {
return route;
}
if (appConfig.isDev) {
checkRoutes(ROUTES);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment