From ced56e0a1cfe880524ebb7b0854e39f3052404cb Mon Sep 17 00:00:00 2001
From: AlphaX-Projects <77661270+AlphaX-Projects@users.noreply.github.com>
Date: Thu, 27 Jun 2024 19:55:20 +0200
Subject: [PATCH] Added name and avatar to login section
---
.../components/login-view/login-section.js | 40 ++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/core/src/components/login-view/login-section.js b/core/src/components/login-view/login-section.js
index 4c98f03e..faa7e20c 100644
--- a/core/src/components/login-view/login-section.js
+++ b/core/src/components/login-view/login-section.js
@@ -48,6 +48,8 @@ class LoginSection extends connect(store)(LitElement) {
backedUpWalletJSON: { type: Object },
backedUpSeedLoading: { type: Boolean },
nodeConfig: { type: Object },
+ names: { type: Array },
+ namesAvatar: { type: String },
theme: { type: String, reflect: true }
}
}
@@ -66,6 +68,8 @@ class LoginSection extends connect(store)(LitElement) {
this.selectedWallet = {}
this.loginErrorMessage = ''
this.saveInBrowser = false
+ this.names = []
+ this.namesAvatar = ''
this.theme = localStorage.getItem('qortalTheme') ? localStorage.getItem('qortalTheme') : 'light'
this.loginOptions = [
@@ -311,7 +315,7 @@ class LoginSection extends connect(store)(LitElement) {
- account_circle
+ ${this.namesAvatar}
${this.selectedWallet.address0}
@@ -417,9 +421,38 @@ class LoginSection extends connect(store)(LitElement) {
return html`${translate("login.lp8")}`
}
+ renderLoginAvatar(renderAddress) {
+ const avatarNode = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node]
+ const avatarUrl = avatarNode.protocol + '://' + avatarNode.domain + ':' + avatarNode.port
+ const namesUrl = `${avatarUrl}/names/address/${renderAddress}?limit=0&reverse=true`
+
+ this.namesAvatar = ''
+
+ if (this.isEmptyArray(this.names)) {
+ fetch(namesUrl).then(response => {
+ return response.json()
+ }).then(data => {
+ this.names = data
+ if (this.isEmptyArray(this.names)) {
+ this.namesAvatar = html`
account_circle`
+ } else {
+ const url = `${avatarUrl}/arbitrary/THUMBNAIL/${this.names[0].name}/qortal_avatar?async=true`
+ this.namesAvatar = html`
+
![](${url})
+
+
${this.names[0].name}
+
+ `
+ }
+ })
+ }
+ }
+
selectWallet(wallet) {
this.selectedWallet = wallet
this.selectedPage = 'unlockStored'
+ this.names = []
+ this.renderLoginAvatar(this.selectedWallet.address0)
}
toDeleteWallet(deleteAddress) {
@@ -668,6 +701,11 @@ class LoginSection extends connect(store)(LitElement) {
this.selectedPage = this.hasStoredWallets ? 'storedWallet' : 'loginOptions'
this.shadowRoot.querySelector('#deleteWalletDialog').close()
}
+
+ isEmptyArray(arr) {
+ if (!arr) { return true }
+ return arr.length === 0
+ }
}
window.customElements.define('login-section', LoginSection)
\ No newline at end of file