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
a88851a4
Commit
a88851a4
authored
Sep 13, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use api token from cookie
parent
840acb7f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
18 deletions
+24
-18
fetch.ts
lib/api/fetch.ts
+14
-11
handler.ts
lib/api/handler.ts
+6
-4
next.config.js
next.config.js
+1
-1
get-with-tokens.ts
pages/api/account/watchlist/get-with-tokens.ts
+2
-1
NetworkMenuLink.tsx
ui/blocks/networkMenu/NetworkMenuLink.tsx
+1
-1
No files found.
lib/api/fetch.ts
View file @
a88851a4
import
type
{
NextApiRequest
}
from
'
next
'
;
import
type
{
RequestInit
,
Response
}
from
'
node-fetch
'
;
import
nodeFetch
from
'
node-fetch
'
;
// first arg can be only a string
// FIXME migrate to RequestInfo later if needed
export
default
function
fetch
(
path
:
string
,
init
?:
RequestInit
):
Promise
<
Response
>
{
const
headers
=
{
accept
:
'
application/json
'
,
authorization
:
`Bearer
${
process
.
env
.
API_AUTHORIZATION_TOKEN
}
`
,
'
content-type
'
:
'
application/json
'
,
};
const
url
=
`https://blockscout.com
${
path
}
`
;
export
default
function
fetchFactory
(
_req
:
NextApiRequest
)
{
return
function
fetch
(
path
:
string
,
init
?:
RequestInit
):
Promise
<
Response
>
{
const
headers
=
{
accept
:
'
application/json
'
,
'
content-type
'
:
'
application/json
'
,
cookie
:
`_explorer_key=
${
_req
.
cookies
.
_explorer_key
}
`
,
};
const
url
=
`https://blockscout.com
${
path
}
`
;
return
nodeFetch
(
url
,
{
headers
,
...
init
,
});
return
nodeFetch
(
url
,
{
headers
,
...
init
,
});
};
}
lib/api/handler.ts
View file @
a88851a4
import
{
withSentry
}
from
'
@sentry/nextjs
'
;
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'
next
'
;
import
fetch
from
'
lib/api/fetch
'
;
import
fetch
Factory
from
'
lib/api/fetch
'
;
import
getUrlWithNetwork
from
'
lib/api/getUrlWithNetwork
'
;
type
Methods
=
'
GET
'
|
'
POST
'
|
'
PUT
'
|
'
DELETE
'
;
...
...
@@ -16,7 +16,8 @@ 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
,
body
:
isBodyDisallowed
?
undefined
:
_req
.
body
,
...
...
@@ -29,12 +30,13 @@ export default function createHandler(getUrl: (_req: NextApiRequest) => string,
}
let
responseError
;
const
defaultError
=
{
statusText
:
response
.
statusText
,
status
:
response
.
status
};
try
{
const
error
=
await
response
.
json
()
as
{
errors
:
unknown
};
responseError
=
error
?.
errors
||
{}
;
responseError
=
error
?.
errors
||
defaultError
;
}
catch
(
error
)
{
responseError
=
{
statusText
:
response
.
statusText
,
status
:
response
.
status
}
;
responseError
=
defaultError
;
}
res
.
status
(
500
).
json
(
responseError
);
...
...
next.config.js
View file @
a88851a4
...
...
@@ -22,7 +22,7 @@ const moduleExports = {
return
[
{
source
:
'
/
'
,
destination
:
'
/
xdai/testnet
'
,
destination
:
'
/
poa/core
'
,
permanent
:
true
,
},
];
...
...
pages/api/account/watchlist/get-with-tokens.ts
View file @
a88851a4
...
...
@@ -4,10 +4,11 @@ import type { WatchlistAddresses } from 'types/api/account';
import
type
{
Tokenlist
}
from
'
types/api/tokenlist
'
;
import
type
{
TWatchlistItem
}
from
'
types/client/account
'
;
import
fetch
from
'
lib/api/fetch
'
;
import
fetch
Factory
from
'
lib/api/fetch
'
;
import
getUrlWithNetwork
from
'
lib/api/getUrlWithNetwork
'
;
const
watchlistWithTokensHandler
=
async
(
_req
:
NextApiRequest
,
res
:
NextApiResponse
<
Array
<
TWatchlistItem
>>
)
=>
{
const
fetch
=
fetchFactory
(
_req
);
const
url
=
getUrlWithNetwork
(
_req
,
'
api/account/v1/user/watchlist
'
);
const
watchlistResponse
=
await
fetch
(
url
,
{
method
:
'
GET
'
});
...
...
ui/blocks/networkMenu/NetworkMenuLink.tsx
View file @
a88851a4
...
...
@@ -33,7 +33,7 @@ const NetworkMenuLink = ({ name, type, subType, icon, isActive, isMobile, routeN
const
pathName
=
`/
${
type
}${
subType
?
'
/
'
+
subType
:
''
}${
localPath
}
`
;
// will fix later after we agree on CI/CD workflow
const
href
=
type
===
'
xdai
'
&&
subType
===
'
testnet
'
?
pathName
:
'
https://blockscout.com
'
+
pathName
;
const
href
=
type
===
'
poa
'
&&
subType
===
'
core
'
?
pathName
:
'
https://blockscout.com
'
+
pathName
;
const
hasIcon
=
Boolean
(
icon
);
const
colors
=
useColors
({
hasIcon
});
...
...
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