• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / lace / 8519959931

29 Mar 2024 01:42PM UTC coverage: 50.577% (-3.3%) from 53.839%
8519959931

push

github

b4f7c8
web-flow
chore: LW-9786 enable single pool delegation in multi-delegation view (#970)

* chore: enable single pool delegation in multi-delegation view

* fix: fix hw multi-delegation tx signing

* fix(extension): fix broken ledger connection

2172 of 5359 branches covered (40.53%)

Branch coverage included in aggregate %.

5146 of 9110 relevant lines covered (56.49%)

52.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.04
/packages/common/src/ui/lib/add-ellipsis.ts
1
/* eslint-disable no-magic-numbers */
2
const addedLength = 4;
4✔
3

4
export const truncate = (text: string, partOneLength: number, partTwoLength: number): string => {
4✔
5
  const textMinLenght = partOneLength + partTwoLength + addedLength;
×
6
  if (text.length <= textMinLenght) return text;
×
7

8
  return `${text.slice(0, partOneLength)}${text.slice(text.length - partTwoLength)}`;
×
9
};
10

11
export const addEllipsis = (text: string, partOnelength: number, partTwoLength: number): string => {
4✔
12
  const textMinLenght = partOnelength + partTwoLength + addedLength;
28✔
13
  if (text.length <= textMinLenght) return text;
28✔
14

15
  return `${text.slice(0, partOnelength)}...${text.slice(text.length - partTwoLength)}`;
16✔
16
};
17

18
const getCssStyle = (element: HTMLElement, prop: string) => window.getComputedStyle(element).getPropertyValue(prop);
168✔
19

20
const getCanvasFontSize = (el: HTMLElement) => {
4✔
21
  const fontWeight = getCssStyle(el, 'font-weight') || 'normal';
56✔
22
  const fontSize = getCssStyle(el, 'font-size') || '16px';
56✔
23
  const fontFamily = getCssStyle(el, 'font-family') || 'Times New Roman';
56✔
24

25
  return `${fontWeight} ${fontSize} ${fontFamily}`;
56✔
26
};
27

28
export const getTextWidth = (text: string, element: HTMLElement): number => {
4✔
29
  const canvas = document.createElement('canvas');
56✔
30
  const context = canvas.getContext('2d');
56✔
31

32
  context.font = getCanvasFontSize(element);
56✔
33
  return context.measureText(text).width;
56✔
34
};
35

36
export const trimTextInHalfToFitSize = (text: string, el: HTMLElement): string => {
4✔
37
  const size = el.offsetWidth - 5;
2✔
38
  const ellipsis = '...';
2✔
39
  if (size < 10) return ellipsis;
2!
40

41
  const ellipsisSize = getTextWidth(ellipsis, el);
2✔
42
  const halfTextWidthSize = Math.ceil(text.length / 2);
2✔
43

44
  let firstPart = text.slice(0, halfTextWidthSize);
2✔
45
  let secondPart = text.slice(halfTextWidthSize);
2✔
46
  // removing one char and check if it fits the half of container size
47
  while (firstPart.length > 1 && getTextWidth(firstPart, el) + ellipsisSize / 2 >= size / 2) {
2✔
48
    firstPart = firstPart.slice(0, -1);
24✔
49
  }
50
  while (secondPart.length > 1 && getTextWidth(secondPart, el) + ellipsisSize / 2 > size / 2) {
2✔
51
    secondPart = secondPart.slice(1 - secondPart.length);
22✔
52
  }
53

54
  return `${firstPart}${ellipsis}${secondPart}`;
2✔
55
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc