import{p as x,r as A,O as S,s as v,a as E,i as T,c as m,b as y,S as I,x as b,d as N,M as C,E as d,N as g,A as l,W as p,e as h,C as O,R}from"./e2e-dLafmRE2.js";import"./relativeTime-B9tlMMn3.js";import"./secp256k1-DaeOdK4W.js";import"./dayjs.min-CibmpzzL.js";const s=x({status:"uninitialized"}),u={state:s,subscribeKey(e,t){return E(s,e,t)},subscribe(e){return v(s,()=>e(s))},_getClient(){if(!s._client)throw new Error("SIWEController client not set");return s._client},async getNonce(e){const n=await this._getClient().getNonce(e);return this.setNonce(n),n},async getSession(){try{const t=await this._getClient().getSession();return t&&(this.setSession(t),this.setStatus("success")),t}catch{return}},createMessage(e){const n=this._getClient().createMessage(e);return this.setMessage(n),n},async verifyMessage(e){return await this._getClient().verifyMessage(e)},async signIn(){return await this._getClient().signIn()},async signOut(){const e=this._getClient();await e.signOut(),this.setStatus("ready"),this.setSession(void 0),e.onSignOut?.()},onSignIn(e){this._getClient().onSignIn?.(e)},onSignOut(){this._getClient().onSignOut?.()},setSIWEClient(e){s._client=A(e),s.status="ready",S.setIsSiweEnabled(e.options.enabled)},setNonce(e){s.nonce=e},setStatus(e){s.status=e},setMessage(e){s.message=e},setSession(e){s.session=e,s.status=e?"success":"ready"}},U=T`
  :host {
    display: flex;
    justify-content: center;
    gap: var(--wui-spacing-2xl);
  }

  wui-visual-thumbnail:nth-child(1) {
    z-index: 1;
  }
`;var W=function(e,t,n,a){var r=arguments.length,i=r<3?t:a===null?a=Object.getOwnPropertyDescriptor(t,n):a,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(e,t,n,a);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(i=(r<3?o(i):r>3?o(t,n,i):o(t,n))||i);return r>3&&i&&Object.defineProperty(t,n,i),i};let w=class extends y{constructor(){super(...arguments),this.dappImageUrl=S.state.metadata?.icons,this.walletImageUrl=I.getConnectedWalletImageUrl()}firstUpdated(){const t=this.shadowRoot?.querySelectorAll("wui-visual-thumbnail");t?.[0]&&this.createAnimation(t[0],"translate(18px)"),t?.[1]&&this.createAnimation(t[1],"translate(-18px)")}render(){return b`
      <wui-visual-thumbnail
        ?borderRadiusFull=${!0}
        .imageSrc=${this.dappImageUrl?.[0]}
      ></wui-visual-thumbnail>
      <wui-visual-thumbnail .imageSrc=${this.walletImageUrl}></wui-visual-thumbnail>
    `}createAnimation(t,n){t.animate([{transform:"translateX(0px)"},{transform:n}],{duration:1600,easing:"cubic-bezier(0.56, 0, 0.48, 1)",direction:"alternate",iterations:1/0})}};w.styles=U;w=W([m("w3m-connecting-siwe")],w);var _=function(e,t,n,a){var r=arguments.length,i=r<3?t:a===null?a=Object.getOwnPropertyDescriptor(t,n):a,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(e,t,n,a);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(i=(r<3?o(i):r>3?o(t,n,i):o(t,n))||i);return r>3&&i&&Object.defineProperty(t,n,i),i};let f=class extends y{constructor(){super(...arguments),this.dappName=S.state.metadata?.name,this.isSigning=!1}render(){return this.onRender(),b`
      <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"
          @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&&C.close()}async onSign(){this.isSigning=!0,d.sendEvent({event:"CLICK_SIGN_SIWE_MESSAGE",type:"track",properties:{network:g.state.caipNetwork?.id||"",isSmartAccount:l.state.preferredAccountType===p.ACCOUNT_TYPES.SMART_ACCOUNT}});try{u.setStatus("loading");const t=await u.signIn();return u.setStatus("success"),d.sendEvent({event:"SIWE_AUTH_SUCCESS",type:"track",properties:{network:g.state.caipNetwork?.id||"",isSmartAccount:l.state.preferredAccountType===p.ACCOUNT_TYPES.SMART_ACCOUNT}}),t}catch{const a=l.state.preferredAccountType===p.ACCOUNT_TYPES.SMART_ACCOUNT;return a?h.showError("This application might not support Smart Accounts"):h.showError("Signature declined"),u.setStatus("error"),d.sendEvent({event:"SIWE_AUTH_ERROR",type:"track",properties:{network:g.state.caipNetwork?.id||"",isSmartAccount:a}})}finally{this.isSigning=!1}}async onCancel(){const{isConnected:t}=l.state;t?(await O.disconnect(),C.close()):R.push("Connect"),d.sendEvent({event:"CLICK_CANCEL_SIWE",type:"track",properties:{network:g.state.caipNetwork?.id||"",isSmartAccount:l.state.preferredAccountType===p.ACCOUNT_TYPES.SMART_ACCOUNT}})}};_([N()],f.prototype,"isSigning",void 0);f=_([m("w3m-connecting-siwe-view")],f);export{u as SIWEController,w as W3mConnectingSiwe,f as W3mConnectingSiweView};
//# sourceMappingURL=index-BsSg2xHy.js.map
