"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index.es-CGSE4wpm.cjs"),o=n.proxy({status:"uninitialized"}),u={state:o,subscribeKey(t,e){return n.subscribeKey(o,t,e)},subscribe(t){return n.subscribe(o,()=>t(o))},_getClient(){if(!o._client)throw new Error("SIWEController client not set");return o._client},async getNonce(t){const i=await this._getClient().getNonce(t);return this.setNonce(i),i},async getSession(){try{const e=await this._getClient().getSession();return e&&(this.setSession(e),this.setStatus("success")),e}catch{return}},createMessage(t){const i=this._getClient().createMessage(t);return this.setMessage(i),i},async verifyMessage(t){return await this._getClient().verifyMessage(t)},async signIn(){return await this._getClient().signIn()},async signOut(){var e;const t=this._getClient();await t.signOut(),this.setStatus("ready"),this.setSession(void 0),(e=t.onSignOut)==null||e.call(t)},onSignIn(t){var i;const e=this._getClient();(i=e.onSignIn)==null||i.call(e,t)},onSignOut(){var e;const t=this._getClient();(e=t.onSignOut)==null||e.call(t)},setSIWEClient(t){o._client=n.ref(t),o.status="ready",n.OptionsController.setIsSiweEnabled(t.options.enabled)},setNonce(t){o.nonce=t},setStatus(t){o.status=t},setMessage(t){o.message=t},setSession(t){o.session=t,o.status=t?"success":"ready"}},d=n.i`
  :host {
    display: flex;
    justify-content: center;
    gap: var(--wui-spacing-2xl);
  }

  wui-visual-thumbnail:nth-child(1) {
    z-index: 1;
  }
`;var C=function(t,e,i,r){var a=arguments.length,s=a<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,i):r,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(t,e,i,r);else for(var l=t.length-1;l>=0;l--)(c=t[l])&&(s=(a<3?c(s):a>3?c(e,i,s):c(e,i))||s);return a>3&&s&&Object.defineProperty(e,i,s),s};exports.W3mConnectingSiwe=class extends n.h{constructor(){var e;super(...arguments),this.dappImageUrl=(e=n.OptionsController.state.metadata)==null?void 0:e.icons,this.walletImageUrl=n.StorageUtil.getConnectedWalletImageUrl()}firstUpdated(){var i;const e=(i=this.shadowRoot)==null?void 0:i.querySelectorAll("wui-visual-thumbnail");e!=null&&e[0]&&this.createAnimation(e[0],"translate(18px)"),e!=null&&e[1]&&this.createAnimation(e[1],"translate(-18px)")}render(){var e;return n.ke`
      <wui-visual-thumbnail
        ?borderRadiusFull=${!0}
        .imageSrc=${(e=this.dappImageUrl)==null?void 0:e[0]}
      ></wui-visual-thumbnail>
      <wui-visual-thumbnail .imageSrc=${this.walletImageUrl}></wui-visual-thumbnail>
    `}createAnimation(e,i){e.animate([{transform:"translateX(0px)"},{transform:i}],{duration:1600,easing:"cubic-bezier(0.56, 0, 0.48, 1)",direction:"alternate",iterations:1/0})}};exports.W3mConnectingSiwe.styles=d;exports.W3mConnectingSiwe=C([n.customElement("w3m-connecting-siwe")],exports.W3mConnectingSiwe);var g=function(t,e,i,r){var a=arguments.length,s=a<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,i):r,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(t,e,i,r);else for(var l=t.length-1;l>=0;l--)(c=t[l])&&(s=(a<3?c(s):a>3?c(e,i,s):c(e,i))||s);return a>3&&s&&Object.defineProperty(e,i,s),s};exports.W3mConnectingSiweView=class extends n.h{constructor(){var e;super(...arguments),this.dappName=(e=n.OptionsController.state.metadata)==null?void 0:e.name,this.isSigning=!1,this.isCancelling=!1}render(){return this.onRender(),n.ke`
      <wui-flex justifyContent="center" .padding=${["2xl","0","xxl","0"]}>
        <w3m-connecting-siwe></w3m-connecting-siwe>
      </wui-flex>
      <wui-flex
        .padding=${["0","4xl","l","4xl"]}
        gap="s"
        justifyContent="space-between"
      >
        <wui-text variant="paragraph-500" align="center" color="fg-100"
          >${this.dappName??"Dapp"} needs to connect to your wallet</wui-text
        >
      </wui-flex>
      <wui-flex
        .padding=${["0","3xl","l","3xl"]}
        gap="s"
        justifyContent="space-between"
      >
        <wui-text variant="small-400" align="center" color="fg-200"
          >Sign this message to prove you own this wallet and proceed. Canceling will disconnect
          you.</wui-text
        >
      </wui-flex>
      <wui-flex .padding=${["l","xl","xl","xl"]} gap="s" justifyContent="space-between">
        <wui-button
          size="lg"
          borderRadius="xs"
          fullWidth
          variant="neutral"
          ?loading=${this.isCancelling}
          @click=${this.onCancel.bind(this)}
          data-testid="w3m-connecting-siwe-cancel"
        >
          Cancel
        </wui-button>
        <wui-button
          size="lg"
          borderRadius="xs"
          fullWidth
          variant="main"
          @click=${this.onSign.bind(this)}
          ?loading=${this.isSigning}
          data-testid="w3m-connecting-siwe-sign"
        >
          ${this.isSigning?"Signing...":"Sign"}
        </wui-button>
      </wui-flex>
    `}onRender(){u.state.session&&n.ModalController.close()}async onSign(){var e,i,r;this.isSigning=!0,n.EventsController.sendEvent({event:"CLICK_SIGN_SIWE_MESSAGE",type:"track",properties:{network:((e=n.NetworkController.state.caipNetwork)==null?void 0:e.id)||"",isSmartAccount:n.AccountController.state.preferredAccountType===n.W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT}});try{u.setStatus("loading");const a=await u.signIn();return u.setStatus("success"),n.EventsController.sendEvent({event:"SIWE_AUTH_SUCCESS",type:"track",properties:{network:((i=n.NetworkController.state.caipNetwork)==null?void 0:i.id)||"",isSmartAccount:n.AccountController.state.preferredAccountType===n.W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT}}),a}catch{const c=n.AccountController.state.preferredAccountType===n.W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT;return c?n.SnackController.showError("This application might not support Smart Accounts"):n.SnackController.showError("Signature declined"),u.setStatus("error"),n.EventsController.sendEvent({event:"SIWE_AUTH_ERROR",type:"track",properties:{network:((r=n.NetworkController.state.caipNetwork)==null?void 0:r.id)||"",isSmartAccount:c}})}finally{this.isSigning=!1}}async onCancel(){var i;this.isCancelling=!0,n.AccountController.state.isConnected?(await n.ConnectionController.disconnect(),n.ModalController.close()):n.RouterController.push("Connect"),this.isCancelling=!1,n.EventsController.sendEvent({event:"CLICK_CANCEL_SIWE",type:"track",properties:{network:((i=n.NetworkController.state.caipNetwork)==null?void 0:i.id)||"",isSmartAccount:n.AccountController.state.preferredAccountType===n.W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT}})}};g([n.r()],exports.W3mConnectingSiweView.prototype,"isSigning",void 0);g([n.r()],exports.W3mConnectingSiweView.prototype,"isCancelling",void 0);exports.W3mConnectingSiweView=g([n.customElement("w3m-connecting-siwe-view")],exports.W3mConnectingSiweView);exports.formatMessage=n.zf;exports.getDidAddress=n.Li;exports.getDidChainId=n.zi;exports.SIWEController=u;
