mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-04-27 20:58:02 +00:00
Restructure the js app (#243)
* prettier * linter * add prettier, and format the code * remove common, merge it with frontend * refactor the app * better lint and code fix * travis for the frontend app * travis build script Signed-off-by: Daniel Maricic <daniel@woss.io> * lint and build * update the README.md Signed-off-by: Daniel Maricic <daniel@woss.io> * change the commands to reflect refactor Signed-off-by: Daniel Maricic <daniel@woss.io> * prettier and tslint are friends Signed-off-by: Daniel Maricic <daniel@woss.io> * code that wasn't linted properly before Signed-off-by: Daniel Maricic <daniel@woss.io> * prettier rc got deleted * workgin on making the travis pass Signed-off-by: Daniel Maricic <daniel@woss.io> * travis build please? Signed-off-by: Daniel Maricic <daniel@woss.io> * update readme.md Signed-off-by: Daniel Maricic <daniel@woss.io> * dockerfile deleted from fronted - out of scope Signed-off-by: Daniel Maricic <daniel@woss.io> * remove Signed-off-by: Daniel Maricic <daniel@woss.io> * tsconfig Signed-off-by: Daniel Maricic <daniel@woss.io> * found the reason why EOL wasn't happening Signed-off-by: Daniel Maricic <daniel@woss.io> * type for the event in the ConnectionInput as suggested * strictnullCheck to true * noImplicitAny * noUnusedParams * AfgHandling * update * fix Location.tsx * Few minor fixes * remove connection input and revert to original * esnext fixes the imports for icons and non default `* as ` * update to the tsconfig.test.json don't use commonjs please * fixed wrong comment for TIMEOUT_BASE * return totem.svg and type decraration of maybe Signed-off-by: Daniel Maricic <daniel@woss.io> Co-authored-by: Will <w.kopp@kigroup.de>
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
import { Types } from './common';
|
||||
|
||||
export interface Viewport {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export function viewport(): Viewport {
|
||||
const width = Math.max(
|
||||
document.documentElement.clientWidth,
|
||||
window.innerWidth || 0
|
||||
);
|
||||
const height = Math.max(
|
||||
document.documentElement.clientHeight,
|
||||
window.innerHeight || 0
|
||||
);
|
||||
|
||||
return { width, height };
|
||||
}
|
||||
|
||||
export function formatNumber(num: number): string {
|
||||
const input = num.toString();
|
||||
|
||||
let output = '';
|
||||
let length = input.length;
|
||||
|
||||
while (length > 3) {
|
||||
output = ',' + input.substr(length - 3, 3) + output;
|
||||
length -= 3;
|
||||
}
|
||||
|
||||
output = input.substr(0, length) + output;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
export function trimHash(hash: string, length: number): string {
|
||||
if (hash.length < length) {
|
||||
return hash;
|
||||
}
|
||||
|
||||
const side = ((length - 2) / 2) | 0;
|
||||
|
||||
return hash.substr(0, side) + '..' + hash.substr(-side, side);
|
||||
}
|
||||
|
||||
export function milliOrSecond(
|
||||
num: Types.Milliseconds | Types.PropagationTime
|
||||
): string {
|
||||
if (num < 10000) {
|
||||
return `${num}ms`;
|
||||
}
|
||||
|
||||
return `${(num / 1000) | 0}s`;
|
||||
}
|
||||
|
||||
export function secondsWithPrecision(num: number): string {
|
||||
const intString = (num | 0).toString();
|
||||
const intDigits = intString.length;
|
||||
|
||||
switch (intDigits) {
|
||||
case 1:
|
||||
return num.toFixed(3) + 's';
|
||||
case 2:
|
||||
return num.toFixed(2) + 's';
|
||||
case 3:
|
||||
return num.toFixed(1) + 's';
|
||||
default:
|
||||
return intString + 's';
|
||||
}
|
||||
}
|
||||
|
||||
export interface HashData {
|
||||
tab?: string;
|
||||
chain?: Types.ChainLabel;
|
||||
}
|
||||
|
||||
export function getHashData(): HashData {
|
||||
const { hash } = window.location;
|
||||
|
||||
if (hash[0] !== '#') {
|
||||
return {};
|
||||
}
|
||||
|
||||
const [tab, rawChain] = hash.substr(1).split('/');
|
||||
const chain = decodeURIComponent(rawChain) as Types.ChainLabel;
|
||||
|
||||
return { tab, chain };
|
||||
}
|
||||
|
||||
export function setHashData(val: HashData) {
|
||||
const update = Object.assign(getHashData(), val);
|
||||
|
||||
const { tab = '', chain = '' } = update;
|
||||
|
||||
window.location.hash = `#${tab}/${encodeURIComponent(chain)}`;
|
||||
}
|
||||
Reference in New Issue
Block a user