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
c14b164b
Commit
c14b164b
authored
Sep 14, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correct links for network with no sub type
parent
568a2dc3
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
5 deletions
+31
-5
useNetwork.tsx
lib/hooks/useNetwork.tsx
+5
-2
link.ts
lib/link/link.ts
+10
-0
findNetwork.ts
lib/networks/findNetwork.ts
+13
-0
getAvailablePaths.ts
lib/networks/getAvailablePaths.ts
+1
-1
getNetworkTitle.ts
lib/networks/getNetworkTitle.ts
+2
-2
No files found.
lib/hooks/useNetwork.tsx
View file @
c14b164b
import
{
useRouter
}
from
'
next/router
'
;
import
NETWORKS
from
'
lib/networks/availableNetworks
'
;
import
findNetwork
from
'
lib/networks/findNetwork
'
;
export
default
function
useNetwork
()
{
const
router
=
useRouter
();
const
selectedNetwork
=
NETWORKS
.
find
((
network
)
=>
router
.
query
.
network_type
===
network
.
type
&&
router
.
query
.
network_sub_type
===
network
.
subType
);
const
selectedNetwork
=
findNetwork
({
network_type
:
typeof
router
.
query
.
network_type
===
'
string
'
?
router
.
query
.
network_type
:
''
,
network_sub_type
:
typeof
router
.
query
.
network_type
===
'
string
'
?
router
.
query
.
network_type
:
undefined
,
});
return
selectedNetwork
;
}
lib/link/link.ts
View file @
c14b164b
import
isBrowser
from
'
lib/isBrowser
'
;
import
findNetwork
from
'
lib/networks/findNetwork
'
;
import
{
ROUTES
}
from
'
./routes
'
;
import
type
{
RouteName
}
from
'
./routes
'
;
...
...
@@ -11,7 +12,16 @@ export function link(routeName: RouteName, urlParams?: Record<string, string | u
return
''
;
}
const
network
=
findNetwork
({
network_type
:
urlParams
?.
network_type
||
''
,
network_sub_type
:
urlParams
?.
network_sub_type
,
});
const
path
=
route
.
pattern
.
replace
(
PATH_PARAM_REGEXP
,
(
_
,
paramName
:
string
)
=>
{
if
(
paramName
===
'
network_sub_type
'
&&
!
network
?.
subType
)
{
return
''
;
}
const
paramValue
=
urlParams
?.[
paramName
];
return
paramValue
?
`/
${
paramValue
}
`
:
''
;
});
...
...
lib/networks/findNetwork.ts
0 → 100644
View file @
c14b164b
import
availableNetworks
from
'
lib/networks/availableNetworks
'
;
interface
Params
{
network_type
:
string
;
network_sub_type
?:
string
;
}
export
default
function
findNetwork
(
params
:
Params
)
{
return
availableNetworks
.
find
((
network
)
=>
network
.
type
===
params
.
network_type
&&
network
.
subType
?
network
.
subType
===
params
.
network_sub_type
:
network
.
type
===
params
.
network_type
,
);
}
lib/networks/getAvailablePaths.ts
View file @
c14b164b
import
NETWORKS
from
'
./availableNetworks
'
;
export
default
function
getAvailablePaths
()
{
return
NETWORKS
.
map
(({
type
,
subType
})
=>
({
params
:
{
network_type
:
type
,
network_sub_type
:
subType
}
}));
return
NETWORKS
.
map
(({
type
,
subType
})
=>
({
params
:
{
network_type
:
type
,
network_sub_type
:
subType
||
'
mainnet
'
}
}));
}
lib/networks/getNetworkTitle.ts
View file @
c14b164b
import
NETWORKS
from
'
./availableNetworks
'
;
import
findNetwork
from
'
./findNetwork
'
;
export
default
function
getNetworkTitle
({
network_type
:
type
,
network_sub_type
:
subType
}:
{
network_type
?:
string
;
network_sub_type
?:
string
})
{
const
currentNetwork
=
NETWORKS
.
find
(
n
=>
n
.
type
===
type
&&
n
.
subType
===
subType
);
const
currentNetwork
=
findNetwork
({
network_type
:
type
||
''
,
network_sub_type
:
subType
}
);
if
(
currentNetwork
)
{
return
currentNetwork
.
name
+
(
currentNetwork
.
shortName
?
` (
${
currentNetwork
.
shortName
}
)`
:
''
)
+
'
Explorer
'
;
}
...
...
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