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
9594ace4
Commit
9594ace4
authored
Jul 05, 2022
by
isstuev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dots
parent
e5104ac7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
2 deletions
+66
-2
WatchListAddressItem.tsx
ui/WatchlistTable/WatchListAddressItem.tsx
+3
-2
AddressWithDots.tsx
ui/shared/AddressWithDots.tsx
+63
-0
CopyToClipboard.tsx
ui/shared/CopyToClipboard.tsx
+0
-0
No files found.
ui/WatchlistTable/WatchListAddressItem.tsx
View file @
9594ace4
...
@@ -3,7 +3,8 @@ import Jazzicon, { jsNumberForAddress } from 'react-jazzicon';
...
@@ -3,7 +3,8 @@ import Jazzicon, { jsNumberForAddress } from 'react-jazzicon';
import
{
Box
,
Link
,
HStack
,
VStack
,
Image
,
Text
,
Icon
,
Tooltip
}
from
'
@chakra-ui/react
'
;
import
{
Box
,
Link
,
HStack
,
VStack
,
Image
,
Text
,
Icon
,
Tooltip
}
from
'
@chakra-ui/react
'
;
import
CopyToClipboard
from
'
../CopyToClipboard/CopyToClipboard
'
;
import
AddressWithDots
from
'
../shared/AddressWithDots
'
;
import
CopyToClipboard
from
'
../shared/CopyToClipboard
'
;
import
type
{
TWatchlistItem
}
from
'
../../data/watchlist
'
;
import
type
{
TWatchlistItem
}
from
'
../../data/watchlist
'
;
import
{
nbsp
}
from
'
../../lib/html-entities
'
;
import
{
nbsp
}
from
'
../../lib/html-entities
'
;
import
TokensIcon
from
'
../../icons/tokens.svg
'
;
import
TokensIcon
from
'
../../icons/tokens.svg
'
;
...
@@ -25,7 +26,7 @@ const WatchListAddressItem = ({ item }: {item: TWatchlistItem}) => {
...
@@ -25,7 +26,7 @@ const WatchListAddressItem = ({ item }: {item: TWatchlistItem}) => {
lineHeight=
"24px"
lineHeight=
"24px"
>
>
<
Tooltip
hasArrow
label=
{
item
.
address
}
>
<
Tooltip
hasArrow
label=
{
item
.
address
}
>
{
item
.
address
}
<
AddressWithDots
address=
{
item
.
address
}
/>
</
Tooltip
>
</
Tooltip
>
</
Link
>
</
Link
>
<
CopyToClipboard
text=
{
item
.
address
}
/>
<
CopyToClipboard
text=
{
item
.
address
}
/>
...
...
ui/shared/AddressWithDots.tsx
0 → 100644
View file @
9594ace4
// this component trims address like 0x123...4567 (always 4 chars after dots)
// or shows full address, if fits
// i can't do this with pure css. if you can, feel free to replace it
// if i use <span text-overflow=ellipsis>some chars</span><span>last 4 chars</span>
// i have an unremovable gap between dots and second span
// so i did it with js
import
React
,
{
useCallback
,
useEffect
,
useRef
}
from
'
react
'
;
import
_debounce
from
'
lodash/debounce
'
;
const
AddressWithDots
=
({
address
}:
{
address
:
string
})
=>
{
const
addressRef
=
useRef
<
HTMLSpanElement
>
(
null
);
const
calculateString
=
useCallback
(()
=>
{
const
addressEl
=
addressRef
.
current
;
if
(
!
addressEl
)
{
return
;
}
const
parent
=
addressRef
?.
current
?.
parentNode
as
HTMLElement
;
if
(
!
parent
)
{
return
;
}
const
shadowEl
=
document
.
createElement
(
'
span
'
);
shadowEl
.
style
.
opacity
=
'
0
'
;
parent
.
appendChild
(
shadowEl
);
shadowEl
.
textContent
=
address
;
if
(
getWidth
(
shadowEl
)
>
getWidth
(
parent
))
{
for
(
let
i
=
1
;
i
<
address
.
length
-
6
;
i
++
)
{
const
res
=
address
.
slice
(
0
,
address
.
length
-
i
-
4
)
+
'
...
'
+
address
.
slice
(
-
4
);
shadowEl
.
textContent
=
res
;
if
(
shadowEl
.
getBoundingClientRect
().
width
<
parent
.
getBoundingClientRect
().
width
)
{
addressRef
.
current
.
textContent
=
res
;
break
;
}
}
}
else
{
addressRef
.
current
.
textContent
=
address
;
}
parent
.
removeChild
(
shadowEl
);
},
[
address
]);
useEffect
(()
=>
{
calculateString
();
const
resizeHandler
=
_debounce
(
calculateString
,
50
)
window
.
addEventListener
(
'
resize
'
,
resizeHandler
)
return
function
cleanup
()
{
window
.
removeEventListener
(
'
resize
'
,
resizeHandler
)
};
},
[
calculateString
]);
return
<
span
ref=
{
addressRef
}
>
{
address
}
</
span
>;
}
function
getWidth
(
el
:
HTMLElement
)
{
return
el
.
getBoundingClientRect
().
width
;
}
export
default
AddressWithDots
;
ui/
CopyToClipboar
d/CopyToClipboard.tsx
→
ui/
share
d/CopyToClipboard.tsx
View file @
9594ace4
File moved
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