]> zoso.dev Git - nemo-wallet.git/commitdiff
Fix account duplication on select. Fix account select not being reset on wallet change.
authorChris Duncan <chris@zoso.dev>
Sat, 26 Oct 2024 07:19:42 +0000 (00:19 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 26 Oct 2024 07:19:42 +0000 (00:19 -0700)
app/pages/nemo-wallet.html

index 2e86cd62806bed76b8be70e508feae35719f4e37..d0fdec440445c4d4cefda5c8c8d0c733d5886351 100644 (file)
                                default: {
                                        try {
                                                await reloadAccountSelect()
+                                               document.getElementById('account').value = ''
                                        } catch (err) {
                                                walletSelect.value = ''
                                                console.error(err)
                }
 
                async function selectAccount () {
-                       const accountSelect = document.querySelector('#account')
-                       const walletId = document.querySelector('#wallet')?.value
+                       const accountSelect = document.getElementById('account')
+                       const walletId = document.getElementById('wallet')?.value
                        if (walletId == null || walletId === '') {
                                accountSelect.value = ''
                                accountSelect.setAttribute('disabled', '')
                        accountSelect.removeAttribute('disabled')
                        if (accountSelect.value === '_new') {
                                try {
-                                       return await document.querySelector('#account-new').showModal()
+                                       return await document.getElementById('account-new').showModal()
                                } catch (err) {
                                        accountSelect.value = ''
                                        console.error(err)
                                if (!select) {
                                        throw new TypeError(`Select ${id} not found`)
                                }
-                               const oldOptions = [select.children].filter(o => o.tagName === 'option')
-                               for (const oldOption of oldOptions) {
-                                       if (oldOption.value.substring(0, 1) === '_') {
-                                               oldOption.remove()
-                                       }
-                               }
+                               ([...select.children])
+                                       .filter(o => o.tagName.toLowerCase() === 'option')
+                                       .filter(o => typeof o.value === 'string')
+                                       .filter(o => o.value.length > 0)
+                                       .filter(o => o.value.substring(0, 1) !== '_')
+                                       .map(o => o.remove())
                                options.map(o => select.add(new Option(o.text, o.value)))
                        } catch (err) {
                                console.error(err)