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
d4b7f2ce
Commit
d4b7f2ce
authored
Aug 25, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
store network info in cookies
parent
357c7ce7
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
32 additions
and
9 deletions
+32
-9
.env.development
.env.development
+0
-2
.env.production
.env.production
+0
-2
fetch.ts
lib/api/fetch.ts
+1
-1
handler.ts
lib/api/handler.ts
+11
-1
cookies.ts
lib/cookies.ts
+3
-1
next.config.js
next.config.js
+1
-1
NetworkMenu.tsx
ui/navigation/networkMenu/NetworkMenu.tsx
+15
-0
NetworkMenuLink.tsx
ui/navigation/networkMenu/NetworkMenuLink.tsx
+1
-1
No files found.
.env.development
deleted
100644 → 0
View file @
357c7ce7
API_HOST=blockscout.com
API_BASE_PATH=/xdai/testnet/api
\ No newline at end of file
.env.production
deleted
100644 → 0
View file @
357c7ce7
API_HOST=blockscout.com
API_BASE_PATH=/xdai/testnet/api
\ No newline at end of file
lib/api/fetch.ts
View file @
d4b7f2ce
...
@@ -9,7 +9,7 @@ export default function fetch(path: string, init?: RequestInit): Promise<Respons
...
@@ -9,7 +9,7 @@ export default function fetch(path: string, init?: RequestInit): Promise<Respons
authorization
:
`Bearer
${
process
.
env
.
API_AUTHORIZATION_TOKEN
}
`
,
authorization
:
`Bearer
${
process
.
env
.
API_AUTHORIZATION_TOKEN
}
`
,
'
content-type
'
:
'
application/json
'
,
'
content-type
'
:
'
application/json
'
,
};
};
const
url
=
`https://
${
process
.
env
.
API_HOST
}${
process
.
env
.
API_BASE_PATH
}
${
path
}
`
;
const
url
=
`https://
blockscout.com
${
path
}
`
;
return
nodeFetch
(
url
,
{
return
nodeFetch
(
url
,
{
headers
,
headers
,
...
...
lib/api/handler.ts
View file @
d4b7f2ce
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'
next
'
;
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'
next
'
;
import
fetch
from
'
lib/api/fetch
'
;
import
fetch
from
'
lib/api/fetch
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
type
Methods
=
'
GET
'
|
'
POST
'
|
'
PUT
'
|
'
DELETE
'
;
type
Methods
=
'
GET
'
|
'
POST
'
|
'
PUT
'
|
'
DELETE
'
;
...
@@ -8,7 +9,16 @@ export default function handler<TRes>(getUrl: (_req: NextApiRequest) => string,
...
@@ -8,7 +9,16 @@ export default function handler<TRes>(getUrl: (_req: NextApiRequest) => string,
return
async
(
_req
:
NextApiRequest
,
res
:
NextApiResponse
<
TRes
>
)
=>
{
return
async
(
_req
:
NextApiRequest
,
res
:
NextApiResponse
<
TRes
>
)
=>
{
if
(
_req
.
method
&&
allowedMethods
.
includes
(
_req
.
method
as
Methods
))
{
if
(
_req
.
method
&&
allowedMethods
.
includes
(
_req
.
method
as
Methods
))
{
const
isBodyDisallowed
=
_req
.
method
===
'
GET
'
||
_req
.
method
===
'
HEAD
'
;
const
isBodyDisallowed
=
_req
.
method
===
'
GET
'
||
_req
.
method
===
'
HEAD
'
;
const
response
=
await
fetch
(
getUrl
(
_req
),
{
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
response
=
await
fetch
(
url
,
{
method
:
_req
.
method
,
method
:
_req
.
method
,
body
:
isBodyDisallowed
?
undefined
:
_req
.
body
,
body
:
isBodyDisallowed
?
undefined
:
_req
.
body
,
});
});
...
...
lib/cookies.ts
View file @
d4b7f2ce
...
@@ -4,7 +4,9 @@ import { Cookies } from 'typescript-cookie';
...
@@ -4,7 +4,9 @@ import { Cookies } from 'typescript-cookie';
import
isBrowser
from
'
./isBrowser
'
;
import
isBrowser
from
'
./isBrowser
'
;
export
enum
NAMES
{
export
enum
NAMES
{
NAV_BAR_COLLAPSED
=
'
nav_bar_collapsed
'
NAV_BAR_COLLAPSED
=
'
nav_bar_collapsed
'
,
NETWORK_TYPE
=
'
network_type
'
,
NETWORK_SUB_TYPE
=
'
network_sub_type
'
,
}
}
export
function
get
(
name
?:
string
|
undefined
|
null
)
{
export
function
get
(
name
?:
string
|
undefined
|
null
)
{
...
...
next.config.js
View file @
d4b7f2ce
...
@@ -11,7 +11,7 @@ module.exports = withReactSvg({
...
@@ -11,7 +11,7 @@ module.exports = withReactSvg({
return
[
return
[
{
{
source
:
'
/
'
,
source
:
'
/
'
,
destination
:
'
/xdai/
main
net
'
,
destination
:
'
/xdai/
test
net
'
,
permanent
:
true
,
permanent
:
true
,
},
},
];
];
...
...
ui/navigation/networkMenu/NetworkMenu.tsx
View file @
d4b7f2ce
import
{
Popover
,
PopoverTrigger
,
Icon
,
useColorModeValue
,
Button
}
from
'
@chakra-ui/react
'
;
import
{
Popover
,
PopoverTrigger
,
Icon
,
useColorModeValue
,
Button
}
from
'
@chakra-ui/react
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
networksIcon
from
'
icons/networks.svg
'
;
import
networksIcon
from
'
icons/networks.svg
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
getDefaultTransitionProps
from
'
theme/utils/getDefaultTransitionProps
'
;
import
getDefaultTransitionProps
from
'
theme/utils/getDefaultTransitionProps
'
;
import
NetworkMenuPopup
from
'
./NetworkMenuPopup
'
;
import
NetworkMenuPopup
from
'
./NetworkMenuPopup
'
;
...
@@ -11,6 +13,19 @@ interface Props {
...
@@ -11,6 +13,19 @@ interface Props {
}
}
const
NetworkMenu
=
({
isCollapsed
}:
Props
)
=>
{
const
NetworkMenu
=
({
isCollapsed
}:
Props
)
=>
{
const
router
=
useRouter
();
const
networkType
=
router
.
query
.
network_type
;
const
networkSubType
=
router
.
query
.
network_sub_type
;
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
]);
return
(
return
(
<
Popover
openDelay=
{
300
}
placement=
"right-start"
gutter=
{
22
}
isLazy
>
<
Popover
openDelay=
{
300
}
placement=
"right-start"
gutter=
{
22
}
isLazy
>
<
PopoverTrigger
>
<
PopoverTrigger
>
...
...
ui/navigation/networkMenu/NetworkMenuLink.tsx
View file @
d4b7f2ce
...
@@ -32,7 +32,7 @@ const NetworkMenuLink = ({ name, type, subType, icon, isActive, routeName, isAcc
...
@@ -32,7 +32,7 @@ const NetworkMenuLink = ({ name, type, subType, icon, isActive, routeName, isAcc
const
pathName
=
`/
${
type
}
/
${
subType
}${
localPath
}
`
;
const
pathName
=
`/
${
type
}
/
${
subType
}${
localPath
}
`
;
// will fix later after we agree on CI/CD workflow
// will fix later after we agree on CI/CD workflow
const
href
=
type
===
'
xdai
'
?
pathName
:
'
https://blockscout.com
'
+
pathName
;
const
href
=
type
===
'
xdai
'
&&
subType
===
'
testnet
'
?
pathName
:
'
https://blockscout.com
'
+
pathName
;
const
hasIcon
=
Boolean
(
icon
);
const
hasIcon
=
Boolean
(
icon
);
const
colors
=
useColors
({
hasIcon
});
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