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
031096d3
Unverified
Commit
031096d3
authored
Nov 21, 2022
by
Igor Stuev
Committed by
GitHub
Nov 21, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #335 from blockscout/hash-shorten-fix
use binary search in prod for the 1st time in my life
parents
ea0a22cd
c375a10a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
HashStringShortenDynamic.tsx
ui/shared/HashStringShortenDynamic.tsx
+12
-5
No files found.
ui/shared/HashStringShortenDynamic.tsx
View file @
031096d3
...
...
@@ -46,14 +46,21 @@ const HashStringShortenDynamic = ({ hash, fontWeight = '400' }: Props) => {
const
parentWidth
=
getWidth
(
parent
);
if
(
getWidth
(
shadowEl
)
>
parentWidth
)
{
for
(
let
i
=
1
;
i
<=
hash
.
length
-
TAIL_LENGTH
-
HEAD_MIN_LENGTH
;
i
++
)
{
const
res
=
hash
.
slice
(
0
,
hash
.
length
-
i
-
TAIL_LENGTH
)
+
'
...
'
+
hash
.
slice
(
-
TAIL_LENGTH
);
const
tail
=
hash
.
slice
(
-
TAIL_LENGTH
);
let
leftI
=
HEAD_MIN_LENGTH
;
let
rightI
=
hash
.
length
-
TAIL_LENGTH
;
while
(
rightI
-
leftI
>
1
)
{
const
medI
=
((
rightI
-
leftI
)
%
2
)
?
leftI
+
(
rightI
-
leftI
+
1
)
/
2
:
leftI
+
(
rightI
-
leftI
)
/
2
;
const
res
=
hash
.
slice
(
0
,
medI
)
+
'
...
'
+
tail
;
shadowEl
.
textContent
=
res
;
if
(
getWidth
(
shadowEl
)
<
parentWidth
||
i
===
hash
.
length
-
TAIL_LENGTH
-
HEAD_MIN_LENGTH
)
{
setDisplayedString
(
res
);
break
;
if
(
getWidth
(
shadowEl
)
<
parentWidth
)
{
leftI
=
medI
;
}
else
{
rightI
=
medI
;
}
}
setDisplayedString
(
hash
.
slice
(
0
,
rightI
-
1
)
+
'
...
'
+
tail
);
}
else
{
setDisplayedString
(
hash
);
}
...
...
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