-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.ts
100 lines (83 loc) · 2.62 KB
/
helper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
export function makeid(length: Number, msg: any) {
var result = "";
var characters =
msg.currentChain === "ethereum"
? "ABCDEFabcdef0123456"
: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
export function textToDisplay(msg: any) {
let prefix = "";
if (msg.currentChain === "ethereum") {
prefix = "0x";
}
if (msg.currentChain === "polkadot") {
prefix = "1";
}
if (msg.currentChain === "kusama") {
prefix = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(
Math.floor(Math.random() * 26)
);
}
const address =
prefix === "0x" || ""
? prefix + makeid(msg.currentCount - 2, msg)
: prefix + makeid(msg.currentCount, msg);
const addressBegin =
prefix === "0x" || ""
? prefix + makeid(msg.currentCount / 2 - 2, msg)
: prefix + makeid(msg.currentCount / 2, msg);
const addressEnd = makeid(msg.currentCount / 2, msg);
return [address, addressBegin, addressEnd];
}
export function createAddress(msg: any) {
let prefix = "";
if (msg.currentChain === "ethereum") {
prefix = "0x";
}
if (msg.currentChain === "polkadot") {
prefix = "1";
}
if (msg.currentChain === "kusama") {
prefix = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(
Math.floor(Math.random() * 26)
);
}
let address: string;
if (msg.currentChain === "ethereum") {
address = prefix + makeid(msg.currentCount - 2, msg);
}
if (msg.currentChain === "polkadot" || msg.currentChain === "kusama") {
address = prefix + makeid(msg.currentCount - 1, msg);
}
if (msg.currentChain === "any") {
address = makeid(msg.currentCount, msg);
}
return address;
}
export function addressFormatted(address: any, msg: any) {
let characters: any;
if (msg.currentEllipsis === "none" || msg.currentEllipsis === "None") {
characters = address;
}
if (msg.currentEllipsis === "center" || msg.currentEllipsis === "Center") {
characters =
address.substring(0, msg.currentCount / 2 - 2) +
"..." +
address.substring(msg.currentCount / 2, msg.currentCount - 1);
}
if (msg.currentEllipsis === "start" || msg.currentEllipsis === "Start") {
characters = "..." + address.substring(3);
}
if (msg.currentEllipsis === "end" || msg.currentEllipsis === "End") {
characters = address.substring(0, msg.currentCount - 3) + "...";
}
return characters;
}
export function capitalizeFirstLetter(string: string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}