diff --git a/src/style.css b/src/style.css index edb7663..1970da4 100644 --- a/src/style.css +++ b/src/style.css @@ -101,4 +101,14 @@ fieldset { label { font-weight: 300; +} + +.timer { + width: 24px; + height: 24px; + border-radius: 24px; + padding: 8px; + display: flex; + justify-content: center; + align-items: center; } \ No newline at end of file diff --git a/src/tokenListItem.ts b/src/tokenListItem.ts index 1526524..c16ce3c 100644 --- a/src/tokenListItem.ts +++ b/src/tokenListItem.ts @@ -1,14 +1,48 @@ -import {displayToken} from './token' -export function displayTokenListItem(account: string, secret: string, element: HTMLDivElement){ +import { displayToken } from "./token"; +var secondsSinceEpoch: number; +var secondsSinceStart: number; +var secondsRemaining: number; +secondsSinceStart = 0; +secondsRemaining = 30; +const period = 30; +var token; - return element.innerHTML = `
+export function displayTokenListItem( + account: string, + secret: string, + element: HTMLDivElement +) { + function countdown() { + secondsSinceEpoch = Math.ceil(Date.now() / 1000) - 1; + secondsSinceStart = 0 + (secondsSinceEpoch % period); + secondsRemaining = period - (secondsSinceEpoch % period); + const timerDiv = document.getElementById(`timer-${account}`); + const tokenDiv = document.getElementById(`secret-${account}`) + if (timerDiv && tokenDiv) { + timerDiv.innerHTML = secondsRemaining.toString(); + timerDiv.style.background = `conic-gradient(transparent ${ + (100 / 30) * secondsSinceStart + }%, ${secondsRemaining < 10 ? "salmon" : "gainsboro"} 0)`; + token = displayToken(secret) + tokenDiv.innerHTML = token; + } + + } + setInterval(() => { + countdown(); + }, 1000); + return (element.innerHTML = `

${account}

-

${displayToken(secret)}

+

-
`; -} \ No newline at end of file +
+ +

+

+
`); +} diff --git a/src/tokenTimer.ts b/src/tokenTimer.ts new file mode 100644 index 0000000..a352253 --- /dev/null +++ b/src/tokenTimer.ts @@ -0,0 +1,28 @@ +import { displayToken } from "./token"; + +class Timer { + constructor(public counter = 30, public element: HTMLDivElement, public account: string, public secret: string) { + + let intervalId = setInterval(() => { + this.counter = this.counter - 1; + console.log(this.counter) + if(this.counter === 0) clearInterval(intervalId) + element.innerHTML = `
+
+ +

${account}

+
+
+ +

${displayToken(secret)}

+
+
+ +

${this.counter}

+
` + return this.element + + }, 1000) + } +} +export default Timer \ No newline at end of file