diff --git a/static/display.js b/static/display.js new file mode 100644 index 0000000..eda8a22 --- /dev/null +++ b/static/display.js @@ -0,0 +1,250 @@ +const padString = num => num.toString().padStart(2, '0') + +const secondsToTime = seconds => { + const hours = Math.floor(seconds / 3600) + const minutes = Math.floor((seconds % 3600) / 60) + const secs = Math.floor(seconds % 60) + return `${padString(hours)}:${padString(minutes)}:${padString(secs)}` +} + +const progress = (startSeconds, currentSeconds) => { + return 1 - (startSeconds - currentSeconds) / startSeconds +} + +const mapCharge = (obj, oldObj = {}) => { + let charge = {...oldObj, ...obj} + charge.displayUrl = ['/satspay/', obj.id].join('') + charge.expanded = oldObj.expanded || false + charge.extra = + charge.extra && typeof charge.extra == 'string' + ? JSON.parse(charge.extra) + : charge.extra + const now = new Date().getTime() / 1000 + const then = new Date(charge.timestamp).getTime() / 1000 + const chargeTimeSeconds = charge.time * 60 + const secondsSinceCreated = chargeTimeSeconds - now + then + charge.timeSecondsLeft = chargeTimeSeconds - now + then + charge.timeLeft = + charge.timeSecondsLeft <= 0 + ? '00:00:00' + : secondsToTime(charge.timeSecondsLeft) + charge.progress = progress(charge.time * 60, secondsSinceCreated) + return charge +} + +if (window.app) { + window.app.component('satspay-paid', { + props: ['charge'], + template: ` +
+ Redirecting after 5 seconds +
+
+ SatsPayServer, create Onchain/LN charges.
WARNING: If
+ using with the WatchOnly extension, we highly recommend using
+ a fresh extended public Key specifically for SatsPayServer!
+
+ Created by,
+ Ben Arc,
+ motorina0
+
- Redirecting after 5 seconds -
-
- SatsPayServer, create Onchain/LN charges.
WARNING: If using with the
- WatchOnly extension, we highly reccomend using a fresh extended public Key
- specifically for SatsPayServer!
-
- Created by,
- Ben Arc,
- motorina0
-