Skip to content

Instantly share code, notes, and snippets.

@wolfadex
Created December 15, 2022 03:28
Show Gist options
  • Save wolfadex/77a74a3e668329058037ba70580a0bf7 to your computer and use it in GitHub Desktop.
Save wolfadex/77a74a3e668329058037ba70580a0bf7 to your computer and use it in GitHub Desktop.
customElements.define(
"custom-image",
class extends HTMLElement {
constructor() {
this.imgEl = document.createElement("img");
this.appendChild(this.imgEl);
}
connectedCallback() {
this.render();
}
attributeChangeCallback(name, newValue, oldValue) {
if (name === "uri" && newValue !== oldValue) {
this.render();
}
}
set mint(val) {
this._mint = mint;
this.render();
}
async render() {
const uri = this.getAttribute("uri");
const metaData = await getMetaData(uri);
const imageData = await getLogo(this._mint, metaData);
this.imgEl.setAttribute("src", imageData);
}
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment