chore: prettier cleanup
This commit is contained in:
@@ -1,45 +1,57 @@
|
||||
import { prop } from "@zos/ui";
|
||||
import { TOTP } from "../../../lib/totp-quickjs";
|
||||
import { RenderExpireBar, RenderOTPValue, RenderTOTPContainer } from '../totpRenderer'
|
||||
import {
|
||||
RenderExpireBar,
|
||||
RenderOTPValue,
|
||||
RenderTOTPContainer,
|
||||
} from "../totpRenderer";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Array<TOTP>} buffer
|
||||
*
|
||||
* @param {Array<TOTP>} buffer
|
||||
*/
|
||||
export function initLoop(buffer) {
|
||||
renderContainers(buffer)
|
||||
renderTOTPs(buffer)
|
||||
renderContainers(buffer);
|
||||
renderTOTPs(buffer);
|
||||
}
|
||||
|
||||
function renderContainers(buffer) {
|
||||
for (let i = 0; i < buffer.length; i++) {
|
||||
RenderTOTPContainer(i, buffer[i].issuer, buffer[i].client)
|
||||
RenderTOTPContainer(i, buffer[i].issuer, buffer[i].client);
|
||||
}
|
||||
}
|
||||
const renderData = []
|
||||
const renderData = [];
|
||||
|
||||
function renderTOTPs(buffer) {
|
||||
for (let i = 0; i < buffer.length; i++) {
|
||||
let otpData = TOTP.copy(buffer[i]).getOTP()
|
||||
let otpData = TOTP.copy(buffer[i]).getOTP();
|
||||
renderData[i] = {
|
||||
OTP: RenderOTPValue(i, otpData.otp),
|
||||
expireBar: RenderExpireBar(i, otpData.createdTime, buffer[i].fetchTime)
|
||||
}
|
||||
expireBar: RenderExpireBar(
|
||||
i,
|
||||
otpData.createdTime,
|
||||
buffer[i].fetchTime
|
||||
),
|
||||
};
|
||||
setInterval(() => {
|
||||
const expireDif = Math.abs((((Date.now() - otpData.createdTime) / 1000)
|
||||
/ buffer[i].fetchTime) - 1)
|
||||
const expireDif = Math.abs(
|
||||
(Date.now() - otpData.createdTime) /
|
||||
1000 /
|
||||
buffer[i].fetchTime -
|
||||
1
|
||||
);
|
||||
|
||||
renderData[i].expireBar.setProperty(prop.MORE, {
|
||||
end_angle: (expireDif * 360) - 90,
|
||||
end_angle: expireDif * 360 - 90,
|
||||
color: expireDif > 0.25 ? 0x1ca9c9 : 0xfa0404,
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
if (otpData.expireTime < Date.now()) {
|
||||
otpData = TOTP.copy(buffer[i]).getOTP()
|
||||
otpData = TOTP.copy(buffer[i]).getOTP();
|
||||
renderData[i].OTP.setProperty(prop.MORE, {
|
||||
text: otpData.otp
|
||||
})
|
||||
text: otpData.otp,
|
||||
});
|
||||
}
|
||||
}, 50)
|
||||
}, 50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
import { getDeviceInfo } from '@zos/device'
|
||||
import { push } from '@zos/router'
|
||||
import { createWidget, widget, align, text_style } from '@zos/ui'
|
||||
import { getDeviceInfo } from "@zos/device";
|
||||
import { push } from "@zos/router";
|
||||
import { createWidget, widget, align, text_style } from "@zos/ui";
|
||||
|
||||
//Renderer module for TOTPs page
|
||||
|
||||
const { width, height } = getDeviceInfo()
|
||||
const buttonWidth = width - width / 20 //Width of container
|
||||
const buttonHeight = height / 4 //Height of container
|
||||
const containerColor = 0x303030 //Color of container
|
||||
const containerRadius = 20 //Corner radius of container
|
||||
const { width, height } = getDeviceInfo();
|
||||
const buttonWidth = width - width / 20; //Width of container
|
||||
const buttonHeight = height / 4; //Height of container
|
||||
const containerColor = 0x303030; //Color of container
|
||||
const containerRadius = 20; //Corner radius of container
|
||||
|
||||
const textColor = 0xa0a0a0 //Color of TOTP description text
|
||||
const textSize = 24 //Size of TOTP description text
|
||||
const statusBarPading = 65
|
||||
const textColor = 0xa0a0a0; //Color of TOTP description text
|
||||
const textSize = 24; //Size of TOTP description text
|
||||
const statusBarPading = 65;
|
||||
|
||||
/** Function for render box container for TOTP values
|
||||
*
|
||||
*
|
||||
* @param {number} position position offset of container
|
||||
* @param {string} issuer issuer of TOTP
|
||||
* @param {string} client client of TOTP
|
||||
*/
|
||||
export function RenderTOTPContainer(position, issuer, client) {
|
||||
const yPos = getYPos(position)
|
||||
const yPos = getYPos(position);
|
||||
createWidget(widget.FILL_RECT, {
|
||||
x: width / 2 - buttonWidth / 2,
|
||||
y: yPos,
|
||||
w: buttonWidth,
|
||||
h: buttonHeight,
|
||||
color: containerColor,
|
||||
radius: containerRadius
|
||||
})
|
||||
radius: containerRadius,
|
||||
});
|
||||
createWidget(widget.TEXT, {
|
||||
x: 0 + (width - buttonWidth) / 2,
|
||||
y: yPos + 10,
|
||||
@@ -40,18 +40,18 @@ export function RenderTOTPContainer(position, issuer, client) {
|
||||
align_h: align.CENTER_H,
|
||||
align_v: align.CENTER_V,
|
||||
text_style: text_style.NONE,
|
||||
text: issuer + ': ' + client
|
||||
})
|
||||
text: issuer + ": " + client,
|
||||
});
|
||||
}
|
||||
|
||||
/** Render OTP Value on container
|
||||
*
|
||||
*
|
||||
* @param {number} position position offset of container
|
||||
* @param {string} otpValue value to display
|
||||
* @returns widget with OTP
|
||||
*/
|
||||
export function RenderOTPValue(position, otpValue) {
|
||||
const yPos = getYPos(position)
|
||||
const yPos = getYPos(position);
|
||||
return createWidget(widget.TEXT, {
|
||||
x: 0,
|
||||
y: yPos + 50,
|
||||
@@ -62,21 +62,22 @@ export function RenderOTPValue(position, otpValue) {
|
||||
align_h: align.CENTER_H,
|
||||
align_v: align.CENTER_V,
|
||||
text_style: text_style.NONE,
|
||||
text: otpValue
|
||||
})
|
||||
text: otpValue,
|
||||
});
|
||||
}
|
||||
|
||||
/** Render expire bar
|
||||
*
|
||||
*
|
||||
* @param {} position position offset of container
|
||||
* @param {*} createdTime UNIX epoch time of creation
|
||||
* @param {*} fetchTime time in seconds to fetch value
|
||||
* @returns widget with bar
|
||||
*/
|
||||
export function RenderExpireBar(position, createdTime, fetchTime) {
|
||||
const yPos = getYPos(position)
|
||||
const expireDif = Math.abs((((Date.now() - createdTime) / 1000)
|
||||
/ fetchTime) - 1)
|
||||
const yPos = getYPos(position);
|
||||
const expireDif = Math.abs(
|
||||
(Date.now() - createdTime) / 1000 / fetchTime - 1
|
||||
);
|
||||
return createWidget(widget.ARC, {
|
||||
x: buttonWidth - 50,
|
||||
y: yPos + 52,
|
||||
@@ -85,13 +86,13 @@ export function RenderExpireBar(position, createdTime, fetchTime) {
|
||||
line_width: 5,
|
||||
color: expireDif > 0.25 ? 0x1ca9c9 : 0xfa0404,
|
||||
start_angle: -90,
|
||||
end_angle: (expireDif * 360) - 90,
|
||||
text: expireDif
|
||||
end_angle: expireDif * 360 - 90,
|
||||
text: expireDif,
|
||||
});
|
||||
}
|
||||
|
||||
/** Function for render 'Add' button on center of screen
|
||||
*
|
||||
*
|
||||
* @param {string} pagePath destination to page onClick ex: 'page/index'
|
||||
*/
|
||||
export function RenderAddButton(pagePath) {
|
||||
@@ -100,17 +101,19 @@ export function RenderAddButton(pagePath) {
|
||||
y: height / 2 - 20,
|
||||
w: 80,
|
||||
h: 80,
|
||||
text: '+',
|
||||
text: "+",
|
||||
radius: 50,
|
||||
text_size: 40,
|
||||
normal_color: 0x303030,
|
||||
press_color: 0x181c18,
|
||||
click_func: () => {
|
||||
push({
|
||||
url: pagePath
|
||||
})
|
||||
}
|
||||
})
|
||||
url: pagePath,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function getYPos(position) { return position * (buttonHeight + 10) + statusBarPading }
|
||||
function getYPos(position) {
|
||||
return position * (buttonHeight + 10) + statusBarPading;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user