Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
69bf9bd5
Commit
69bf9bd5
authored
Oct 15, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delete network cookie
parent
0bc8d8f3
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
13 additions
and
38 deletions
+13
-38
config.ts
configs/app/config.ts
+4
-5
fetch.ts
lib/api/fetch.ts
+1
-1
getUrlWithNetwork.ts
lib/api/getUrlWithNetwork.ts
+5
-12
handler.ts
lib/api/handler.ts
+1
-1
cookies.ts
lib/cookies.ts
+0
-2
index.ts
pages/api/account/csrf/index.ts
+1
-1
get-with-tokens.ts
pages/api/account/watchlist/get-with-tokens.ts
+1
-1
Page.tsx
ui/shared/Page/Page.tsx
+0
-15
No files found.
configs/app/config.ts
View file @
69bf9bd5
...
...
@@ -7,10 +7,6 @@ const baseUrl = [
process
.
env
.
NEXT_PUBLIC_VERCEL_URL
||
process
.
env
.
NEXT_PUBLIC_APP_HOST
,
process
.
env
.
NEXT_PUBLIC_APP_PORT
?
'
:
'
+
process
.
env
.
NEXT_PUBLIC_APP_PORT
:
''
,
].
join
(
''
);
const
apiUrl
=
[
process
.
env
.
NEXT_PUBLIC_API_ENDPOINT
||
'
https://blockscout.com
'
,
process
.
env
.
NEXT_PUBLIC_API_BASE_PATH
,
].
filter
(
Boolean
).
join
(
''
);
const
config
=
Object
.
freeze
({
env
,
...
...
@@ -41,7 +37,10 @@ const config = Object.freeze({
host
:
process
.
env
.
NEXT_PUBLIC_APP_HOST
,
port
:
process
.
env
.
NEXT_PUBLIC_APP_PORT
,
baseUrl
,
apiUrl
,
api
:
{
endpoint
:
process
.
env
.
NEXT_PUBLIC_API_ENDPOINT
||
'
https://blockscout.com
'
,
basePath
:
process
.
env
.
NEXT_PUBLIC_API_BASE_PATH
||
''
,
},
});
export
default
config
;
lib/api/fetch.ts
View file @
69bf9bd5
...
...
@@ -15,7 +15,7 @@ export default function fetchFactory(_req: NextApiRequest) {
'
content-type
'
:
'
application/json
'
,
cookie
:
`
${
cookies
.
NAMES
.
API_TOKEN
}
=
${
_req
.
cookies
[
cookies
.
NAMES
.
API_TOKEN
]
}
`
,
};
const
url
=
new
URL
(
path
,
appConfig
.
api
Url
);
const
url
=
new
URL
(
path
,
appConfig
.
api
.
endpoint
);
httpLogger
.
logger
.
info
({
message
:
'
Trying to call API
'
,
...
...
lib/api/getUrlWithNetwork.ts
View file @
69bf9bd5
// import * as Sentry from '@sentry/nextjs';
import
appConfig
from
'
configs/app/config
'
;
import
type
{
NextApiRequest
}
from
'
next
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
export
default
function
getUrlWithNetwork
(
_req
:
NextApiRequest
,
path
:
string
)
{
const
networkType
=
_req
.
cookies
[
cookies
.
NAMES
.
NETWORK_TYPE
];
const
networkSubType
=
_req
.
cookies
[
cookies
.
NAMES
.
NETWORK_SUB_TYPE
];
// if (!networkType) {
// TODO setup sentry for NodeJS
// we probably do not need to if we will do api request from client directly
// Sentry.captureException(new Error('Incorrect network'), { extra: { networkType, networkSubType } });
// }
return
`/
${
networkType
}${
networkSubType
?
'
/
'
+
networkSubType
:
''
}
/
${
path
}
`
;
return
[
appConfig
.
api
.
basePath
,
path
,
].
filter
(
Boolean
).
join
(
''
);
}
lib/api/handler.ts
View file @
69bf9bd5
...
...
@@ -18,7 +18,7 @@ export default function createHandler(getUrl: (_req: NextApiRequest) => string,
const
isBodyDisallowed
=
_req
.
method
===
'
GET
'
||
_req
.
method
===
'
HEAD
'
;
const
url
=
getUrlWithNetwork
(
_req
,
`api
${
getUrl
(
_req
)
}
`
);
const
url
=
getUrlWithNetwork
(
_req
,
`
/
api
${
getUrl
(
_req
)
}
`
);
const
fetch
=
fetchFactory
(
_req
);
const
response
=
await
fetch
(
url
,
{
method
:
_req
.
method
,
...
...
lib/cookies.ts
View file @
69bf9bd5
...
...
@@ -5,8 +5,6 @@ import isBrowser from './isBrowser';
export
enum
NAMES
{
NAV_BAR_COLLAPSED
=
'
nav_bar_collapsed
'
,
NETWORK_TYPE
=
'
network_type
'
,
NETWORK_SUB_TYPE
=
'
network_sub_type
'
,
API_TOKEN
=
'
_explorer_key
'
,
}
...
...
pages/api/account/csrf/index.ts
View file @
69bf9bd5
...
...
@@ -7,7 +7,7 @@ import { httpLogger } from 'lib/api/logger';
export
default
async
function
csrfHandler
(
_req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
httpLogger
(
_req
,
res
);
const
url
=
getUrlWithNetwork
(
_req
,
`api/account/v1/get_csrf`
);
const
url
=
getUrlWithNetwork
(
_req
,
`
/
api/account/v1/get_csrf`
);
const
fetch
=
fetchFactory
(
_req
);
const
response
=
await
fetch
(
url
);
...
...
pages/api/account/watchlist/get-with-tokens.ts
View file @
69bf9bd5
...
...
@@ -12,7 +12,7 @@ const watchlistWithTokensHandler = async(_req: NextApiRequest, res: NextApiRespo
httpLogger
(
_req
,
res
);
const
fetch
=
fetchFactory
(
_req
);
const
url
=
getUrlWithNetwork
(
_req
,
'
api/account/v1/user/watchlist
'
);
const
url
=
getUrlWithNetwork
(
_req
,
'
/
api/account/v1/user/watchlist
'
);
const
watchlistResponse
=
await
fetch
(
url
,
{
method
:
'
GET
'
});
const
watchlistData
=
await
watchlistResponse
.
json
()
as
WatchlistAddresses
;
...
...
ui/shared/Page/Page.tsx
View file @
69bf9bd5
import
{
Flex
}
from
'
@chakra-ui/react
'
;
import
{
useQuery
}
from
'
@tanstack/react-query
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
PageContent
from
'
ui/shared/Page/PageContent
'
;
import
Header
from
'
ui/snippets/header/Header
'
;
...
...
@@ -15,23 +13,10 @@ interface Props {
}
const
Page
=
({
children
,
wrapChildren
=
true
}:
Props
)
=>
{
const
router
=
useRouter
();
const
fetch
=
useFetch
();
const
networkType
=
router
.
query
.
network_type
;
const
networkSubType
=
router
.
query
.
network_sub_type
;
useQuery
<
unknown
,
unknown
,
unknown
>
([
'
csrf
'
],
async
()
=>
await
fetch
(
'
/api/account/csrf
'
));
React
.
useEffect
(()
=>
{
if
(
typeof
networkType
===
'
string
'
)
{
cookies
.
set
(
cookies
.
NAMES
.
NETWORK_TYPE
,
networkType
);
}
if
(
typeof
networkSubType
===
'
string
'
)
{
cookies
.
set
(
cookies
.
NAMES
.
NETWORK_SUB_TYPE
,
networkSubType
);
}
},
[
networkType
,
networkSubType
]);
const
renderedChildren
=
wrapChildren
?
(
<
PageContent
>
{
children
}
</
PageContent
>
)
:
children
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment