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
1dc819a6
Unverified
Commit
1dc819a6
authored
Aug 30, 2022
by
tom goriunov
Committed by
GitHub
Aug 30, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #115 from blockscout/merge-fix
fix watchlist request
parents
ceb2d373
dc810c3e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
10 deletions
+20
-10
getUrlWithNetwork.ts
lib/api/getUrlWithNetwork.ts
+15
-0
handler.ts
lib/api/handler.ts
+2
-9
get-with-tokens.ts
pages/api/account/watchlist/get-with-tokens.ts
+3
-1
No files found.
lib/api/getUrlWithNetwork.ts
0 → 100644
View file @
1dc819a6
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
||
!
networkSubType
)
{
// eslint-disable-next-line no-console
console
.
error
(
`Incorrect network: NETWORK_TYPE=
${
networkType
}
NETWORK_SUB_TYPE=
${
networkSubType
}
`
);
}
return
`/
${
networkType
}
/
${
networkSubType
}
/
${
path
}
`
;
}
lib/api/handler.ts
View file @
1dc819a6
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'
next
'
;
import
fetch
from
'
lib/api/fetch
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
getUrlWithNetwork
from
'
lib/api/getUrlWithNetwork
'
;
type
Methods
=
'
GET
'
|
'
POST
'
|
'
PUT
'
|
'
DELETE
'
;
...
...
@@ -9,15 +9,8 @@ export default function handler<TRes, TErrRes>(getUrl: (_req: NextApiRequest) =>
return
async
(
_req
:
NextApiRequest
,
res
:
NextApiResponse
<
TRes
|
TErrRes
>
)
=>
{
if
(
_req
.
method
&&
allowedMethods
.
includes
(
_req
.
method
as
Methods
))
{
const
isBodyDisallowed
=
_req
.
method
===
'
GET
'
||
_req
.
method
===
'
HEAD
'
;
const
networkType
=
_req
.
cookies
[
cookies
.
NAMES
.
NETWORK_TYPE
];
const
networkSubType
=
_req
.
cookies
[
cookies
.
NAMES
.
NETWORK_SUB_TYPE
];
if
(
!
networkType
||
!
networkSubType
)
{
// eslint-disable-next-line no-console
console
.
error
(
`Incorrect network: NETWORK_TYPE=
${
networkType
}
NETWORK_SUB_TYPE=
${
networkSubType
}
`
);
}
const
url
=
`/
${
networkType
}
/
${
networkSubType
}
/api
${
getUrl
(
_req
)
}
`
;
const
url
=
getUrlWithNetwork
(
_req
,
`/api
${
getUrl
(
_req
)
}
`
);
const
response
=
await
fetch
(
url
,
{
method
:
_req
.
method
,
body
:
isBodyDisallowed
?
undefined
:
_req
.
body
,
...
...
pages/api/account/watchlist/get-with-tokens.ts
View file @
1dc819a6
...
...
@@ -5,9 +5,11 @@ import type { Tokenlist } from 'types/api/tokenlist';
import
type
{
TWatchlistItem
}
from
'
types/client/account
'
;
import
fetch
from
'
lib/api/fetch
'
;
import
getUrlWithNetwork
from
'
lib/api/getUrlWithNetwork
'
;
const
watchlistWithTokensHandler
=
async
(
_req
:
NextApiRequest
,
res
:
NextApiResponse
<
Array
<
TWatchlistItem
>>
)
=>
{
const
watchlistResponse
=
await
fetch
(
'
/account/v1/user/watchlist
'
,
{
method
:
'
GET
'
});
const
url
=
getUrlWithNetwork
(
_req
,
'
api/account/v1/user/watchlist
'
);
const
watchlistResponse
=
await
fetch
(
url
,
{
method
:
'
GET
'
});
const
watchlistData
=
await
watchlistResponse
.
json
()
as
WatchlistAddresses
;
...
...
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