forked from Prompt-Hash-Stellar/prompt-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.ts
More file actions
39 lines (35 loc) · 953 Bytes
/
Copy pathformat.ts
File metadata and controls
39 lines (35 loc) · 953 Bytes
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
/**
* Converts stroops (smallest unit) to XLM string
* 1 XLM = 10,000,000 stroops
*/
export function stroopsToXlmString(stroops: bigint): string {
const xlm = Number(stroops) / 10_000_000;
return xlm.toString();
}
/**
* Converts XLM to stroops
*/
export function xlmToStroops(xlm: number | string): bigint {
const val = typeof xlm === "string" ? parseFloat(xlm) : xlm;
return BigInt(Math.round(val * 10_000_000));
}
/**
* Formats a price in stroops as a human-readable XLM label.
*/
export function formatPriceLabel(stroops: bigint): string {
const xlmStr = stroopsToXlmString(stroops);
return `${xlmStr} XLM`;
}
/**
* Formats an address for display (truncated)
*/
export function formatAddress(
address: string,
prefixLength = 8,
suffixLength = 4,
): string {
if (address.length <= prefixLength + suffixLength) {
return address;
}
return `${address.slice(0, prefixLength)}...${address.slice(-suffixLength)}`;
}