otomato-sdk 2.0.199 → 2.0.200
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -69,3 +69,56 @@ export function getComputeERC20Variable(amount, chainId, contractAddress) {
|
|
|
69
69
|
// Construct the computeERC20Amount formula
|
|
70
70
|
return `{{computeERC20Amount(${formattedAmount}, ${chainId}, '${formattedContractAddress}')}}`;
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Formats a number to a string with a specified number of non-zero decimal digits.
|
|
74
|
+
* If the number is less than 1 and starts with zeros after the decimal point,
|
|
75
|
+
* it will show decimals until the first N non-zero digits are reached.
|
|
76
|
+
* Otherwise, it will show up to N decimal digits.
|
|
77
|
+
*
|
|
78
|
+
* @param value - The number to format.
|
|
79
|
+
* @param nonZeroDecimals - The number of non-zero decimal digits to show (default is 2).
|
|
80
|
+
* @returns string - The formatted number as a string.
|
|
81
|
+
*/
|
|
82
|
+
export function formatNonZeroDecimals(value, nonZeroDecimals = 2) {
|
|
83
|
+
if (value === 0) {
|
|
84
|
+
return "0";
|
|
85
|
+
}
|
|
86
|
+
const sign = value < 0 ? "-" : "";
|
|
87
|
+
const absValue = Math.abs(value);
|
|
88
|
+
// Convert to string, handling scientific notation
|
|
89
|
+
let str = absValue.toString();
|
|
90
|
+
// Handle scientific notation
|
|
91
|
+
if (str.includes('e')) {
|
|
92
|
+
const [mantissa, exponent] = str.split('e');
|
|
93
|
+
const exp = parseInt(exponent);
|
|
94
|
+
if (exp < 0) {
|
|
95
|
+
// Convert scientific notation to decimal
|
|
96
|
+
const decimalPlaces = Math.abs(exp) + mantissa.replace('.', '').length - 1;
|
|
97
|
+
str = absValue.toFixed(decimalPlaces);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const decimalIndex = str.indexOf('.');
|
|
101
|
+
if (decimalIndex === -1) {
|
|
102
|
+
return sign + str;
|
|
103
|
+
}
|
|
104
|
+
const integerPart = str.substring(0, decimalIndex);
|
|
105
|
+
const decimalPart = str.substring(decimalIndex + 1);
|
|
106
|
+
let nonZeroCount = 0;
|
|
107
|
+
let result = integerPart + ".";
|
|
108
|
+
for (let i = 0; i < decimalPart.length; i++) {
|
|
109
|
+
result += decimalPart[i];
|
|
110
|
+
if (decimalPart[i] !== '0') {
|
|
111
|
+
nonZeroCount++;
|
|
112
|
+
if (nonZeroCount === nonZeroDecimals) {
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Remove trailing zeros and decimal point if needed
|
|
118
|
+
result = result.replace(/\.?0+$/, '');
|
|
119
|
+
if (result.endsWith('.')) {
|
|
120
|
+
result = result.slice(0, -1);
|
|
121
|
+
}
|
|
122
|
+
return sign + result;
|
|
123
|
+
}
|
|
124
|
+
console.log(formatNonZeroDecimals(0.0000000000000001)); // 0.0000000000000001
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.0.
|
|
1
|
+
export declare const SDK_VERSION = "2.0.200";
|
|
2
2
|
export declare function compareVersions(v1: string, v2: string): number;
|
|
@@ -23,3 +23,14 @@ export declare function compareAddresses(address1: string, address2: string): bo
|
|
|
23
23
|
* @returns string - A formatted string to be used as a variable in the workflow.
|
|
24
24
|
*/
|
|
25
25
|
export declare function getComputeERC20Variable(amount: string, chainId: any, contractAddress: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Formats a number to a string with a specified number of non-zero decimal digits.
|
|
28
|
+
* If the number is less than 1 and starts with zeros after the decimal point,
|
|
29
|
+
* it will show decimals until the first N non-zero digits are reached.
|
|
30
|
+
* Otherwise, it will show up to N decimal digits.
|
|
31
|
+
*
|
|
32
|
+
* @param value - The number to format.
|
|
33
|
+
* @param nonZeroDecimals - The number of non-zero decimal digits to show (default is 2).
|
|
34
|
+
* @returns string - The formatted number as a string.
|
|
35
|
+
*/
|
|
36
|
+
export declare function formatNonZeroDecimals(value: number, nonZeroDecimals?: number): string;
|