import HelpIcon from '../../../asset/icon/Help.svg'; import SendIcon from '../../../asset/icon/Send.svg'; import DeflyWalletLogo from '../../../asset/icon/DeflyWallet.svg'; import { DEFLY_WALLET_CONNECT_MODAL_ID, removeModalWrapperFromDOM } from '../../deflyWalletConnectModalUtils'; import styles from './_defly-wallet-connect-modal-pending-message.scss'; import { isIOS } from '../../../util/device/deviceUtils'; import { CONNECT_AUDIO_URL, CONNECT_TIMEOUT_INTERVAL } from './util/deflyWalletConnectModalPendingMessageConstants'; const deflyWalletConnectModalPendingMessageTemplate = document.createElement('template'); deflyWalletConnectModalPendingMessageTemplate.innerHTML = `
`; const deflyWalletConnectTryAgainView = ` `; export class DeflyWalletConnectModalPendingMessageSection extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); if (this.shadowRoot) { const styleSheet = document.createElement('style'); styleSheet.textContent = styles; this.shadowRoot.append( deflyWalletConnectModalPendingMessageTemplate.content.cloneNode(true), styleSheet ); } } connectedCallback() { const cancelButton = this.shadowRoot?.getElementById( 'defly-wallet-connect-modal-pending-message-cancel-button' ); cancelButton?.addEventListener('click', () => { this.onClose(); }); this.addAudioForConnection(); setTimeout(() => { deflyWalletConnectModalPendingMessageTemplate.innerHTML = deflyWalletConnectTryAgainView; if (this.shadowRoot) { const styleSheet = document.createElement('style'); styleSheet.textContent = styles; this.shadowRoot.innerHTML = ''; this.shadowRoot.append( deflyWalletConnectModalPendingMessageTemplate.content.cloneNode(true), styleSheet ); const tryAgainButton = this.shadowRoot?.getElementById( 'defly-wallet-connect-modal-pending-message-try-again-button' ); tryAgainButton?.addEventListener('click', () => { this.onClose(); }); } }, CONNECT_TIMEOUT_INTERVAL); } onClose() { removeModalWrapperFromDOM(DEFLY_WALLET_CONNECT_MODAL_ID); } addAudioForConnection() { const shouldUseSound = this.getAttribute('should-use-sound'); if (shouldUseSound === 'true' && isIOS()) { const connectAudioWrapper = this.shadowRoot?.getElementById( 'defly-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); } } }