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
cab4c85d
Commit
cab4c85d
authored
Sep 12, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor the rest
parent
036dcde5
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
40 additions
and
26 deletions
+40
-26
useBasePath.tsx
lib/hooks/useBasePath.tsx
+0
-6
link.ts
lib/link/link.ts
+3
-1
routes.ts
lib/link/routes.ts
+16
-1
NetworkLogo.tsx
ui/blocks/networkMenu/NetworkLogo.tsx
+3
-2
SearchBar.tsx
ui/blocks/searchBar/SearchBar.tsx
+5
-4
PrivateTags.tsx
ui/pages/PrivateTags.tsx
+4
-4
AddressLinkWithTooltip.tsx
ui/shared/AddressLinkWithTooltip.tsx
+6
-5
Token.tsx
ui/shared/Token.tsx
+3
-3
No files found.
lib/hooks/useBasePath.tsx
deleted
100644 → 0
View file @
036dcde5
import
{
useRouter
}
from
'
next/router
'
;
export
default
function
useBasePath
()
{
const
router
=
useRouter
();
return
`/
${
router
.
query
.
network_type
}
/
${
router
.
query
.
network_sub_type
}
`
;
}
lib/link/link.ts
View file @
cab4c85d
import
isBrowser
from
'
lib/isBrowser
'
;
import
{
ROUTES
}
from
'
./routes
'
;
import
{
ROUTES
}
from
'
./routes
'
;
import
type
{
RouteName
}
from
'
./routes
'
;
import
type
{
RouteName
}
from
'
./routes
'
;
...
@@ -14,7 +16,7 @@ export function link(routeName: RouteName, urlParams?: Record<string, string | u
...
@@ -14,7 +16,7 @@ export function link(routeName: RouteName, urlParams?: Record<string, string | u
return
paramValue
?
`/
${
paramValue
}
`
:
''
;
return
paramValue
?
`/
${
paramValue
}
`
:
''
;
});
});
const
url
=
new
URL
(
path
,
window
.
location
.
origin
);
const
url
=
new
URL
(
path
,
isBrowser
()
?
window
.
location
.
origin
:
'
https://blockscout.com
'
);
queryParams
&&
Object
.
entries
(
queryParams
).
forEach
(([
key
,
value
])
=>
{
queryParams
&&
Object
.
entries
(
queryParams
).
forEach
(([
key
,
value
])
=>
{
url
.
searchParams
.
append
(
key
,
value
);
url
.
searchParams
.
append
(
key
,
value
);
...
...
lib/link/routes.ts
View file @
cab4c85d
...
@@ -76,15 +76,30 @@ export const ROUTES = {
...
@@ -76,15 +76,30 @@ export const ROUTES = {
pattern
:
`
${
BASE_PATH
}
/tokens`
,
pattern
:
`
${
BASE_PATH
}
/tokens`
,
crossNetworkNavigation
:
true
,
crossNetworkNavigation
:
true
,
},
},
token_index
:
{
pattern
:
`
${
BASE_PATH
}
/token/[id]`
,
crossNetworkNavigation
:
true
,
},
// ADDRESSES
address_index
:
{
pattern
:
`
${
BASE_PATH
}
/address/[id]`
,
crossNetworkNavigation
:
true
,
},
// APPS
// APPS
apps
:
{
apps
:
{
pattern
:
`
${
BASE_PATH
}
/apps`
,
pattern
:
`
${
BASE_PATH
}
/apps`
,
},
},
// SEARCH
search_results
:
{
pattern
:
`
${
BASE_PATH
}
/apps`
,
},
// ??? what URL will be here
// ??? what URL will be here
other
:
{
other
:
{
pattern
:
`
${
BASE_PATH
}
/
other
`
,
pattern
:
`
${
BASE_PATH
}
/
search-results
`
,
},
},
};
};
...
...
ui/blocks/networkMenu/NetworkLogo.tsx
View file @
cab4c85d
...
@@ -4,8 +4,8 @@ import React from 'react';
...
@@ -4,8 +4,8 @@ import React from 'react';
import
type
{
FunctionComponent
,
SVGAttributes
}
from
'
react
'
;
import
type
{
FunctionComponent
,
SVGAttributes
}
from
'
react
'
;
import
blockscoutLogo
from
'
icons/logo.svg
'
;
import
blockscoutLogo
from
'
icons/logo.svg
'
;
import
useBasePath
from
'
lib/hooks/useBasePath
'
;
import
useNetwork
from
'
lib/hooks/useNetwork
'
;
import
useNetwork
from
'
lib/hooks/useNetwork
'
;
import
useLink
from
'
lib/link/useLink
'
;
import
getDefaultTransitionProps
from
'
theme/utils/getDefaultTransitionProps
'
;
import
getDefaultTransitionProps
from
'
theme/utils/getDefaultTransitionProps
'
;
interface
Props
{
interface
Props
{
...
@@ -15,7 +15,8 @@ interface Props {
...
@@ -15,7 +15,8 @@ interface Props {
const
NetworkLogo
=
({
isCollapsed
,
onClick
}:
Props
)
=>
{
const
NetworkLogo
=
({
isCollapsed
,
onClick
}:
Props
)
=>
{
const
logoColor
=
useColorModeValue
(
'
blue.600
'
,
'
white
'
);
const
logoColor
=
useColorModeValue
(
'
blue.600
'
,
'
white
'
);
const
href
=
useBasePath
();
const
link
=
useLink
();
const
href
=
link
(
'
network_index
'
);
const
network
=
useNetwork
();
const
network
=
useNetwork
();
const
logo
=
network
?.
logo
;
const
logo
=
network
?.
logo
;
...
...
ui/blocks/searchBar/SearchBar.tsx
View file @
cab4c85d
import
type
{
ChangeEvent
,
FormEvent
}
from
'
react
'
;
import
type
{
ChangeEvent
,
FormEvent
}
from
'
react
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
useBasePath
from
'
lib/hooks/useBasePath
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useLink
from
'
lib/link/useLink
'
;
import
SearchBarDesktop
from
'
./SearchBarDesktop
'
;
import
SearchBarDesktop
from
'
./SearchBarDesktop
'
;
import
SearchBarMobile
from
'
./SearchBarMobile
'
;
import
SearchBarMobile
from
'
./SearchBarMobile
'
;
const
SearchBar
=
()
=>
{
const
SearchBar
=
()
=>
{
const
[
value
,
setValue
]
=
React
.
useState
(
''
);
const
[
value
,
setValue
]
=
React
.
useState
(
''
);
const
basePath
=
useBasePath
();
const
link
=
useLink
();
const
isMobile
=
useIsMobile
();
const
isMobile
=
useIsMobile
();
const
handleChange
=
React
.
useCallback
((
event
:
ChangeEvent
<
HTMLInputElement
>
)
=>
{
const
handleChange
=
React
.
useCallback
((
event
:
ChangeEvent
<
HTMLInputElement
>
)
=>
{
...
@@ -18,8 +18,9 @@ const SearchBar = () => {
...
@@ -18,8 +18,9 @@ const SearchBar = () => {
const
handleSubmit
=
React
.
useCallback
((
event
:
FormEvent
<
HTMLFormElement
>
)
=>
{
const
handleSubmit
=
React
.
useCallback
((
event
:
FormEvent
<
HTMLFormElement
>
)
=>
{
event
.
preventDefault
();
event
.
preventDefault
();
window
.
location
.
assign
(
`https://blockscout.com
${
basePath
}
/search-results?q=
${
value
}
`
);
const
url
=
link
(
'
search_results
'
,
undefined
,
{
q
:
value
});
},
[
value
,
basePath
]);
window
.
location
.
assign
(
url
);
},
[
link
,
value
]);
if
(
isMobile
)
{
if
(
isMobile
)
{
return
(
return
(
...
...
ui/pages/PrivateTags.tsx
View file @
cab4c85d
...
@@ -8,7 +8,7 @@ import {
...
@@ -8,7 +8,7 @@ import {
}
from
'
@chakra-ui/react
'
;
}
from
'
@chakra-ui/react
'
;
import
React
,
{
useCallback
,
useState
}
from
'
react
'
;
import
React
,
{
useCallback
,
useState
}
from
'
react
'
;
import
use
BasePath
from
'
lib/hooks/useBasePath
'
;
import
use
Link
from
'
lib/link/useLink
'
;
import
PrivateAddressTags
from
'
ui/privateTags/PrivateAddressTags
'
;
import
PrivateAddressTags
from
'
ui/privateTags/PrivateAddressTags
'
;
import
PrivateTransactionTags
from
'
ui/privateTags/PrivateTransactionTags
'
;
import
PrivateTransactionTags
from
'
ui/privateTags/PrivateTransactionTags
'
;
import
Page
from
'
ui/shared/Page
'
;
import
Page
from
'
ui/shared/Page
'
;
...
@@ -25,13 +25,13 @@ type Props = {
...
@@ -25,13 +25,13 @@ type Props = {
const
PrivateTags
=
({
tab
}:
Props
)
=>
{
const
PrivateTags
=
({
tab
}:
Props
)
=>
{
const
[
,
setActiveTab
]
=
useState
<
TabName
>
(
tab
);
const
[
,
setActiveTab
]
=
useState
<
TabName
>
(
tab
);
const
basePath
=
useBasePath
();
const
link
=
useLink
();
const
onChangeTab
=
useCallback
((
index
:
number
)
=>
{
const
onChangeTab
=
useCallback
((
index
:
number
)
=>
{
setActiveTab
(
TABS
[
index
]);
setActiveTab
(
TABS
[
index
]);
const
newUrl
=
basePath
+
'
/account/
'
+
(
TABS
[
index
]
===
'
address
'
?
'
tag_address
'
:
'
tag_transaction
'
);
const
newUrl
=
link
(
TABS
[
index
]
===
'
address
'
?
'
private_tags_address
'
:
'
private_tags_tx
'
);
history
.
replaceState
(
history
.
state
,
''
,
newUrl
);
history
.
replaceState
(
history
.
state
,
''
,
newUrl
);
},
[
setActiveTab
,
basePath
]);
},
[
link
]);
return
(
return
(
<
Page
>
<
Page
>
...
...
ui/shared/AddressLinkWithTooltip.tsx
View file @
cab4c85d
...
@@ -2,7 +2,7 @@ import { Flex, Link } from '@chakra-ui/react';
...
@@ -2,7 +2,7 @@ import { Flex, Link } from '@chakra-ui/react';
import
type
{
HTMLChakraProps
}
from
'
@chakra-ui/system
'
;
import
type
{
HTMLChakraProps
}
from
'
@chakra-ui/system
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
use
BasePath
from
'
lib/hooks/useBasePath
'
;
import
use
Link
from
'
lib/link/useLink
'
;
import
AddressWithDots
from
'
./AddressWithDots
'
;
import
AddressWithDots
from
'
./AddressWithDots
'
;
import
CopyToClipboard
from
'
./CopyToClipboard
'
;
import
CopyToClipboard
from
'
./CopyToClipboard
'
;
...
@@ -18,14 +18,15 @@ interface Props extends HTMLChakraProps<'div'> {
...
@@ -18,14 +18,15 @@ interface Props extends HTMLChakraProps<'div'> {
}
}
const
AddressLinkWithTooltip
=
({
address
,
type
=
'
address
'
,
truncated
,
withCopy
=
true
,
...
styles
}:
Props
)
=>
{
const
AddressLinkWithTooltip
=
({
address
,
type
=
'
address
'
,
truncated
,
withCopy
=
true
,
...
styles
}:
Props
)
=>
{
const
basePath
=
useBasePath
();
const
link
=
useLink
();
let
url
;
let
url
;
if
(
type
===
'
transaction
'
)
{
if
(
type
===
'
transaction
'
)
{
url
=
basePath
+
'
/tx/
'
+
address
;
url
=
link
(
'
tx_index
'
,
{
id
:
address
})
;
}
else
if
(
type
===
'
token
'
)
{
}
else
if
(
type
===
'
token
'
)
{
url
=
basePath
+
'
/address/
'
+
address
+
'
/tokens#address-tabs
'
;
url
=
link
(
'
token_index
'
,
{
id
:
address
})
;
}
else
{
}
else
{
url
=
basePath
+
'
/address/
'
+
address
;
url
=
link
(
'
address_index
'
,
{
id
:
address
})
;
}
}
return
(
return
(
<
Flex
columnGap=
{
2
}
alignItems=
"center"
overflow=
"hidden"
maxW=
"100%"
{
...
styles
}
>
<
Flex
columnGap=
{
2
}
alignItems=
"center"
overflow=
"hidden"
maxW=
"100%"
{
...
styles
}
>
...
...
ui/shared/Token.tsx
View file @
cab4c85d
...
@@ -3,7 +3,7 @@ import React from 'react';
...
@@ -3,7 +3,7 @@ import React from 'react';
import
tokeIcon
from
'
icons/tokens/toke.svg
'
;
import
tokeIcon
from
'
icons/tokens/toke.svg
'
;
import
usdtIcon
from
'
icons/tokens/usdt.svg
'
;
import
usdtIcon
from
'
icons/tokens/usdt.svg
'
;
import
use
BasePath
from
'
lib/hooks/useBasePath
'
;
import
use
Link
from
'
lib/link/useLink
'
;
// temporary solution
// temporary solution
// don't know where to get icons and addresses yet
// don't know where to get icons and addresses yet
...
@@ -29,13 +29,13 @@ interface Props {
...
@@ -29,13 +29,13 @@ interface Props {
const
Token
=
({
symbol
,
className
}:
Props
)
=>
{
const
Token
=
({
symbol
,
className
}:
Props
)
=>
{
const
token
=
TOKENS
[
symbol
as
keyof
typeof
TOKENS
];
const
token
=
TOKENS
[
symbol
as
keyof
typeof
TOKENS
];
const
basePath
=
useBasePath
();
const
link
=
useLink
();
if
(
!
token
)
{
if
(
!
token
)
{
return
null
;
return
null
;
}
}
const
url
=
basePath
+
'
/token/
'
+
token
.
address
;
const
url
=
link
(
'
token_index
'
,
{
id
:
token
.
address
})
;
return
(
return
(
<
Center
className=
{
className
}
>
<
Center
className=
{
className
}
>
...
...
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