import PeraWalletLogo from "../../../asset/icon/PeraWallet.svg"; import HelpIcon from "../../../asset/icon/Help.svg"; import SendIcon from "../../../asset/icon/Send.svg"; import Lottie from "@evanhahn/lottie-web-light"; import { PERA_WALLET_CONNECT_MODAL_ID, removeModalWrapperFromDOM } from "../../peraWalletConnectModalUtils"; import styles from "./_pera-wallet-connect-modal-pending-message.scss"; import {isIOS} from "../../../util/device/deviceUtils"; import { CONNECT_AUDIO_URL, CONNECT_TIMEOUT_INTERVAL, PERA_LOADER_ANIMATION_URL } from "./util/peraWalletConnectModalPendingMessageConstants"; const peraWalletConnectModalPendingMessageTemplate = document.createElement("template"); peraWalletConnectModalPendingMessageTemplate.innerHTML = `
`; const peraWalletConnectTryAgainView = ` `; export class PeraWalletConnectModalPendingMessageSection extends HTMLElement { constructor() { super(); this.attachShadow({mode: "open"}); if (this.shadowRoot) { const styleSheet = document.createElement("style"); styleSheet.textContent = styles; this.shadowRoot.append( peraWalletConnectModalPendingMessageTemplate.content.cloneNode(true), styleSheet ); } } connectedCallback() { const cancelButton = this.shadowRoot?.getElementById( "pera-wallet-connect-modal-pending-message-cancel-button" ); cancelButton?.addEventListener("click", () => { this.onClose(); }); this.addAudioForConnection(); this.renderLottieAnimation(); setTimeout(() => { peraWalletConnectModalPendingMessageTemplate.innerHTML = peraWalletConnectTryAgainView; if (this.shadowRoot) { const styleSheet = document.createElement("style"); styleSheet.textContent = styles; this.shadowRoot.innerHTML = ""; this.shadowRoot.append( peraWalletConnectModalPendingMessageTemplate.content.cloneNode(true), styleSheet ); const tryAgainButton = this.shadowRoot?.getElementById( "pera-wallet-connect-modal-pending-message-try-again-button" ); tryAgainButton?.addEventListener("click", () => { this.onClose(); }); } }, CONNECT_TIMEOUT_INTERVAL); } onClose() { removeModalWrapperFromDOM(PERA_WALLET_CONNECT_MODAL_ID); } addAudioForConnection() { const shouldUseSound = this.getAttribute("should-use-sound"); if (shouldUseSound === "true" && isIOS()) { const connectAudioWrapper = this.shadowRoot?.getElementById( "pera-wallet-connect-modal-pending-message-audio-wrapper" ); const audio = document.createElement("audio"); audio.src = CONNECT_AUDIO_URL; audio.autoplay = true; audio.loop = true; connectAudioWrapper?.appendChild(audio); } } renderLottieAnimation() { const lottieWrapper = this.shadowRoot?.getElementById( "pera-wallet-connect-modal-pending-message-animation-wrapper" ); if (lottieWrapper) { Lottie.loadAnimation({ container: lottieWrapper, renderer: "svg", loop: true, autoplay: true, path: PERA_LOADER_ANIMATION_URL }); } } }