import { LitElement, html, css } from 'lit'
import { connect } from 'pwa-helpers'
import { store } from '../store.js'
import { translate, translateUnsafeHTML } from 'lit-translate'
import '@polymer/paper-toast'
import '@material/mwc-icon-button'
class WalletProfile extends connect(store)(LitElement) {
static get properties() {
return {
wallet: { type: Object },
nodeConfig: { type: Object },
accountInfo: { type: Object },
imageUrl: { type: String },
theme: { type: String, reflect: true }
}
}
static get styles() {
return [
css`
`
]
}
constructor() {
super()
this.nodeConfig = {}
this.accountInfo = {
names: [],
addressInfo: {}
}
this.imageUrl = ''
this.theme = localStorage.getItem('qortalTheme') ? localStorage.getItem('qortalTheme') : 'light'
}
render() {
return html`
`
}
firstUpdated() {
const container = document.body.querySelector('main-app').shadowRoot.querySelector('app-view').shadowRoot;
const toast = this.shadowRoot.getElementById('toast')
const isMobile = window.matchMedia(`(max-width: ${getComputedStyle(document.body).getPropertyValue('--layout-breakpoint-tablet')})`).matches
if (isMobile) {
toast.verticalAlign = 'bottom'
toast.verticalOffset = 0
}
this.toast = container.appendChild(toast)
}
async getAllWithAddress(myAddress) {
await this.getAddressUserAvatar(myAddress)
}
getAvatar() {
if (this.accountInfo.names.length === 0) {
return html`
`
} else {
const avatarNode = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node]
const avatarUrl = avatarNode.protocol + '://' + avatarNode.domain + ':' + avatarNode.port
const url = `${avatarUrl}/arbitrary/THUMBNAIL/${this.accountInfo.names[0].name}/qortal_avatar?async=true&apiKey=${this.getApiKey()}`
return html`
`
}
}
getApiKey() {
const apiNode = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node];
let apiKey = apiNode.apiKey;
return apiKey;
}
stateChanged(state) {
this.wallet = state.app.wallet
this.nodeConfig = state.app.nodeConfig
this.accountInfo = state.app.accountInfo
}
}
window.customElements.define('wallet-profile', WalletProfile)