Commit e9d4ac66 authored by tom's avatar tom

basic get and post requests for private tags

parent b9718900
API_HOST=blockscout.com
API_BASE_PATH=/xdai/testnet/api
\ No newline at end of file
API_AUTHORIZATION_TOKEN=xxx
\ No newline at end of file
API_HOST=blockscout.com
API_BASE_PATH=/xdai/testnet/api
\ No newline at end of file
......@@ -18,6 +18,7 @@
# misc
.DS_Store
*.pem
.tools
# debug
npm-debug.log*
......
export default function getDefaultHeaders() {
return {
Accept: 'application/json',
Authorization: `Bearer ${ process.env.API_AUTHORIZATION_TOKEN }`,
'Content-type': 'application/json',
}
}
export default function getUrl(path: string) {
return `https://${ process.env.API_HOST }${ process.env.API_BASE_PATH }${ path }`
}
import type { NextApiRequest, NextApiResponse } from 'next'
import fetch from 'node-fetch';
import getDefaultHeaders from 'pages/api-helpers/getDefaultHeaders';
import getUrl from 'pages/api-helpers/getUrl';
export default async function handler(_req: NextApiRequest, res: NextApiResponse) {
const url = getUrl('/account/v1/user/tags/address');
switch (_req.method) {
case 'GET': {
const response = await fetch(url, {
method: 'GET',
headers: getDefaultHeaders(),
})
const data = await response.json();
res.status(200).json(data)
break;
}
case 'POST': {
const response = await fetch(url, {
method: 'POST',
headers: getDefaultHeaders(),
body: _req.body,
})
const data = await response.json();
res.status(200).json(data)
break;
}
default: {
res.setHeader('Allow', [ 'GET', 'POST' ])
res.status(405).end(`Method ${ _req.method } Not Allowed`)
}
}
}
......@@ -8,6 +8,7 @@ import {
TabList,
TabPanel,
TabPanels,
Button,
} from '@chakra-ui/react';
import Page from 'ui/shared/Page/Page';
......@@ -15,10 +16,16 @@ import PrivateAddressTags from 'ui/privateTags/PrivateAddressTags';
import PrivateTransactionTags from 'ui/privateTags/PrivateTransactionTags';
const PrivateTags: React.FC = () => {
const handleClick = React.useCallback(async() => {
await fetch('/api/account/private-tags/address');
}, [])
return (
<Page>
<Box h="100%">
<Heading as="h1" size="lg" marginBottom={ 8 }>Private tags</Heading>
<Button onClick={ handleClick }>click</Button>
<Tabs variant="soft-rounded" colorScheme="blue" isLazy>
<TabList marginBottom={ 8 }>
<Tab>Address</Tab>
......
......@@ -1384,6 +1384,11 @@ damerau-levenshtein@^1.0.7:
resolved "https://registry.yarnpkg.com/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz#b43d286ccbd36bc5b2f7ed41caf2d0aba1f8a6e7"
integrity sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==
data-uri-to-buffer@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz#b5db46aea50f6176428ac05b73be39a57701a64b"
integrity sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==
debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
......@@ -1814,6 +1819,14 @@ fastq@^1.6.0:
dependencies:
reusify "^1.0.4"
fetch-blob@^3.1.2, fetch-blob@^3.1.4:
version "3.2.0"
resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.2.0.tgz#f09b8d4bbd45adc6f0c20b7e787e793e309dcce9"
integrity sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==
dependencies:
node-domexception "^1.0.0"
web-streams-polyfill "^3.0.3"
file-entry-cache@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027"
......@@ -1865,6 +1878,13 @@ fontfaceobserver@2.1.0:
resolved "https://registry.yarnpkg.com/fontfaceobserver/-/fontfaceobserver-2.1.0.tgz#e2705d293e2c585a6531c2a722905657317a2991"
integrity sha512-ReOsO2F66jUa0jmv2nlM/s1MiutJx/srhAe2+TE8dJCMi02ZZOcCTxTCQFr3Yet+uODUtnr4Mewg+tNQ+4V1Ng==
formdata-polyfill@^4.0.10:
version "4.0.10"
resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz#24807c31c9d402e002ab3d8c720144ceb8848423"
integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==
dependencies:
fetch-blob "^3.1.2"
framer-motion@^6:
version "6.3.6"
resolved "https://registry.yarnpkg.com/framer-motion/-/framer-motion-6.3.6.tgz#9ca52544a7d0c74668f880eb2cab4a5de6dc71a0"
......@@ -2517,6 +2537,20 @@ next@12.1.6:
"@next/swc-win32-ia32-msvc" "12.1.6"
"@next/swc-win32-x64-msvc" "12.1.6"
node-domexception@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5"
integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==
node-fetch@^3.2.9:
version "3.2.9"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.2.9.tgz#3f6070bf854de20f21b9fe8479f823462e615d7d"
integrity sha512-/2lI+DBecVvVm9tDhjziTVjo2wmTsSxSk58saUYP0P/fRJ3xxtfMDY24+CKTkfm0Dlhyn3CSXNL0SoRiCZ8Rzg==
dependencies:
data-uri-to-buffer "^4.0.0"
fetch-blob "^3.1.4"
formdata-polyfill "^4.0.10"
normalize-path@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
......@@ -3356,6 +3390,11 @@ v8-compile-cache@^2.0.3:
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
integrity sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==
web-streams-polyfill@^3.0.3:
version "3.2.1"
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz#71c2718c52b45fd49dbeee88634b3a60ceab42a6"
integrity sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==
which-boxed-primitive@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6"
......
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