tangled
alpha
login
or
join now
yoginth.com
/
hey
1
fork
atom
Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿
1
fork
atom
overview
issues
pulls
pipelines
refactor: move from common helpers to respective apps
Yoginth
11 months ago
335d11ef
e6ffba3b
+54
3 changed files
expand all
collapse all
unified
split
apps
web
src
helpers
formatAddress.ts
getTokenImage.ts
splitNumber.ts
+19
apps/web/src/helpers/formatAddress.ts
···
1
1
+
import { isAddress } from "viem";
2
2
+
3
3
+
const formatAddress = (address: string | null, sliceSize = 4): string => {
4
4
+
if (!address) {
5
5
+
return "";
6
6
+
}
7
7
+
8
8
+
const formattedAddress = address.toLowerCase();
9
9
+
10
10
+
if (isAddress(formattedAddress)) {
11
11
+
const start = formattedAddress.slice(0, sliceSize);
12
12
+
const end = formattedAddress.slice(formattedAddress.length - sliceSize);
13
13
+
return `${start}…${end}`;
14
14
+
}
15
15
+
16
16
+
return formattedAddress;
17
17
+
};
18
18
+
19
19
+
export default formatAddress;
+12
apps/web/src/helpers/getTokenImage.ts
···
1
1
+
import { STATIC_IMAGES_URL } from "@hey/data/constants";
2
2
+
3
3
+
const getTokenImage = (symbol?: string): string => {
4
4
+
if (!symbol) {
5
5
+
return "";
6
6
+
}
7
7
+
8
8
+
const symbolLowerCase = symbol?.toLowerCase() || "";
9
9
+
return `${STATIC_IMAGES_URL}/tokens/${symbolLowerCase}.svg`;
10
10
+
};
11
11
+
12
12
+
export default getTokenImage;
+23
apps/web/src/helpers/splitNumber.ts
···
1
1
+
const splitNumber = (num = 1, parts = 1): number[] => {
2
2
+
const n = Math.floor(num / parts);
3
3
+
const numbers: number[] = [];
4
4
+
5
5
+
for (let i = 0; i < parts; i++) {
6
6
+
numbers.push(n);
7
7
+
}
8
8
+
9
9
+
if (numbers.reduce((a, b) => a + b, 0) === num) {
10
10
+
return numbers;
11
11
+
}
12
12
+
13
13
+
for (let i = 0; i < parts; i++) {
14
14
+
numbers[i]++;
15
15
+
if (numbers.reduce((a, b) => a + b, 0) === num) {
16
16
+
return numbers;
17
17
+
}
18
18
+
}
19
19
+
20
20
+
return numbers;
21
21
+
};
22
22
+
23
23
+
export default splitNumber;