Connect with Pera Web to continue
`;
const mobileWalletOption = `
`;
return {
mobileWalletOption: document
.createRange()
.createContextualFragment(mobileWalletOption),
webWalletOption: document.createRange().createContextualFragment(webWalletOption)
};
}
const peraWalletConnectModalDesktopModeDefaultView = `
`;
peraWalletConnectModalDesktopMode.innerHTML =
peraWalletConnectModalDesktopModeDefaultView;
export class PeraWalletModalDesktopMode extends HTMLElement {
constructor() {
super();
this.attachShadow({mode: "open"});
if (this.shadowRoot) {
this.shadowRoot.append(
peraWalletConnectModalDesktopMode.content.cloneNode(true),
styleSheet,
accordionStyleSheet
);
this.shadowRoot.addEventListener("click", (event) => {
this.handleAccordion(event as MouseEvent);
});
const isCompactMode = this.getAttribute("compact-mode") === "true";
if (isCompactMode) {
const modalDesktopMode = this.shadowRoot.getElementById(
"pera-wallet-connect-modal-desktop-mode"
);
modalDesktopMode?.classList.add(
"pera-wallet-connect-modal-desktop-mode--compact"
);
}
const desktopModeDefaultView = this.shadowRoot?.querySelector(
".pera-wallet-connect-modal-desktop-mode__default-view"
);
const shouldPromoteMobile = this.getAttribute("promote-mobile") === "true";
const {webWalletOption, mobileWalletOption} =
getConnectOptions(shouldPromoteMobile);
if (shouldPromoteMobile) {
desktopModeDefaultView?.appendChild(mobileWalletOption);
desktopModeDefaultView?.appendChild(webWalletOption);
} else {
desktopModeDefaultView?.appendChild(webWalletOption);
desktopModeDefaultView?.appendChild(mobileWalletOption);
}
}
}
connectedCallback() {
const shouldDisplayNewBadge = this.getAttribute("should-display-new-badge");
const peraWalletNewLabel = this.shadowRoot?.getElementById("pera-web-new-label");
if (shouldDisplayNewBadge === "false") {
peraWalletNewLabel?.setAttribute("style", "display:none");
}
this.handleChangeView();
}
handleChangeView() {
const downloadPeraButton = this.shadowRoot?.getElementById(
"pera-wallet-connect-modal-desktop-mode-download-pera-button"
);
const backButton = this.shadowRoot?.getElementById(
"pera-wallet-connect-modal-download-pera-view-back-button"
);
const webWalletLaunchButton = this.shadowRoot?.getElementById(
"pera-wallet-connect-web-wallet-launch-button"
);
if (downloadPeraButton) {
downloadPeraButton.addEventListener("click", () => {
this.onClickDownload();
});
}
if (backButton) {
backButton.addEventListener("click", () => {
this.onClickBack();
});
}
if (webWalletLaunchButton) {
webWalletLaunchButton.addEventListener("click", () => {
this.webWalletConnect();
});
}
this.renderQRCode();
this.checkWebWalletAvaliability();
}
webWalletConnect() {
if (this.getAttribute("is-web-wallet-avaliable") === "true") {
// @ts-ignore ts-2339
window.onWebWalletConnect();
}
}
handleAccordion(event: MouseEvent) {
if (event.target instanceof Element) {
if (!event.target.classList.contains("pera-wallet-accordion-toggle__button"))
return;
if (this.shadowRoot && event.target.parentElement?.parentElement) {
const accordionItem = event.target.parentElement?.parentElement;
if (!accordionItem) return;
if (accordionItem.classList.contains("pera-wallet-accordion-item--active")) {
return;
}
const accordionItems = this.shadowRoot.querySelectorAll(
".pera-wallet-accordion-item.pera-wallet-accordion-item--active"
);
for (let i = 0; i < accordionItems.length; i++) {
accordionItems[i].classList.remove("pera-wallet-accordion-item--active");
}
accordionItem.classList.toggle("pera-wallet-accordion-item--active");
}
}
}
renderQRCode() {
const isWebWalletAvailable = this.getAttribute("is-web-wallet-avaliable");
const isCompactMode = this.getAttribute("compact-mode") === "true";
const singleAccount = this.getAttribute("single-account") === "true";
let URI = this.getAttribute("uri");
if (singleAccount) {
URI = `${URI}&singleAccount=true`;
}
/* eslint-disable no-magic-numbers */
let size = isWebWalletAvailable === "false" ? 250 : 205;
if (isCompactMode) {
size = 190;
}
/* eslint-enable no-magic-numbers */
if (URI) {
const qrCode = new QRCodeStyling({
width: size,
height: size,
type: "svg",
data: URI,
image: PeraWalletLogoWithBlackBackground,
dotsOptions: {
color: "#000",
type: "extra-rounded"
},
imageOptions: {
crossOrigin: "anonymous",
margin: 8
},
cornersSquareOptions: {type: "extra-rounded"},
cornersDotOptions: {
type: "dot"
}
});
const qrWrapper = this.shadowRoot?.getElementById(
"pera-wallet-connect-modal-connect-qr-code"
);
if (qrWrapper) {
qrCode.append(qrWrapper);
}
}
}
onClickDownload() {
if (this.shadowRoot) {
const modalDesktopMode = this.shadowRoot.getElementById(
"pera-wallet-connect-modal-desktop-mode"
);
if (modalDesktopMode) {
modalDesktopMode.classList.remove(
"pera-wallet-connect-modal-desktop-mode--default"
);
modalDesktopMode.classList.add(
"pera-wallet-connect-modal-desktop-mode--download"
);
}
}
}
onClickBack() {
if (this.shadowRoot) {
const modalDesktopMode = this.shadowRoot.getElementById(
"pera-wallet-connect-modal-desktop-mode"
);
if (modalDesktopMode) {
modalDesktopMode.classList.add("pera-wallet-connect-modal-desktop-mode--default");
modalDesktopMode.classList.remove(
"pera-wallet-connect-modal-desktop-mode--download"
);
}
}
}
checkWebWalletAvaliability() {
if (this.getAttribute("is-web-wallet-avaliable") === "false") {
const desktopModeDefaultView = this.shadowRoot?.querySelector(
".pera-wallet-connect-modal-desktop-mode__default-view"
);
desktopModeDefaultView?.classList.add(
"pera-wallet-connect-modal-desktop-mode__default-view--web-wallet-not-avaliable"
);
}
}
}