From 0532e8a73380147ddf6cdbfcfe12410b75ddeeca Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Wed, 15 Feb 2023 02:25:28 +0100 Subject: [PATCH] synchronize local storage --- templates/cashu/wallet.html | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/templates/cashu/wallet.html b/templates/cashu/wallet.html index 9638f347e..4336b173a 100644 --- a/templates/cashu/wallet.html +++ b/templates/cashu/wallet.html @@ -2721,7 +2721,23 @@ page_container %} this.tab = 'settings' } }, - + registerLocalStorageSyncHook: function () { + // makes sure that local storage stays up to date + // in multiple tabs of the same window + window.addEventListener('storage', e => { + console.log(`Key Changed: ${e.key}`) + console.log(`New Value: ${e.newValue}`) + localStorage.setItem(e.key, e.newValue) + // if these were the proofs, reload them + if (e.key == 'cashu.proofs') { + this.proofs = JSON.parse(localStorage.getItem('cashu.proofs')) + } + // if these were the activeMintUrl, reload + if (e.key == 'cashu.activeMintURL') { + this.activateMint(e.newValue) + } + }) + }, notifySuccess: async function (message, position = 'top') { this.$q.notify({ timeout: 5000, @@ -2981,6 +2997,9 @@ page_container %} await this.activateMint(startupMintUrl) } + // Local storage sync hook + this.registerLocalStorageSyncHook() + // PWA install hook this.registerPWAEventHook()