|
| 1 | +import{p as m,s as C,a as b,r as y,O as w,i as x,c as f,b as p,S as _,x as h,d as v,E as c,e as E,A as I,C as $,M as O,R}from"./index-B8poDV1B.js";const s=m({status:"uninitialized"}),u={state:s,subscribeKey(t,e){return C(s,t,e)},subscribe(t){return b(s,()=>t(s))},_getClient(){if(!s._client)throw new Error("SIWEController client not set");return s._client},async getNonce(t){const n=await this._getClient().getNonce(t);return this.setNonce(n),n},async getSession(){const e=await this._getClient().getSession();return e&&(this.setSession(e),this.setStatus("success")),e},createMessage(t){const n=this._getClient().createMessage(t);return this.setMessage(n),n},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"),(e=t.onSignOut)==null||e.call(t)},onSignIn(t){var n;const e=this._getClient();(n=e.onSignIn)==null||n.call(e,t)},onSignOut(){var e;const t=this._getClient();(e=t.onSignOut)==null||e.call(t)},setSIWEClient(t){s._client=y(t),s.status="ready",w.setIsSiweEnabled(t.options.enabled)},setNonce(t){s.nonce=t},setStatus(t){s.status=t},setMessage(t){s.message=t},setSession(t){s.session=t}},W=x` |
| 2 | + :host { |
| 3 | + display: flex; |
| 4 | + justify-content: center; |
| 5 | + gap: var(--wui-spacing-2xl); |
| 6 | + } |
| 7 | +
|
| 8 | + wui-visual-thumbnail:nth-child(1) { |
| 9 | + z-index: 1; |
| 10 | + } |
| 11 | +`;var j=function(t,e,n,a){var o=arguments.length,i=o<3?e:a===null?a=Object.getOwnPropertyDescriptor(e,n):a,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(t,e,n,a);else for(var l=t.length-1;l>=0;l--)(r=t[l])&&(i=(o<3?r(i):o>3?r(e,n,i):r(e,n))||i);return o>3&&i&&Object.defineProperty(e,n,i),i};let g=class extends p{constructor(){var e;super(...arguments),this.dappImageUrl=(e=w.state.metadata)==null?void 0:e.icons,this.walletImageUrl=_.getConnectedWalletImageUrl()}firstUpdated(){var n;const e=(n=this.shadowRoot)==null?void 0:n.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 h` |
| 12 | + <wui-visual-thumbnail |
| 13 | + ?borderRadiusFull=${!0} |
| 14 | + .imageSrc=${(e=this.dappImageUrl)==null?void 0:e[0]} |
| 15 | + ></wui-visual-thumbnail> |
| 16 | + <wui-visual-thumbnail .imageSrc=${this.walletImageUrl}></wui-visual-thumbnail> |
| 17 | + `}createAnimation(e,n){e.animate([{transform:"translateX(0px)"},{transform:n}],{duration:1600,easing:"cubic-bezier(0.56, 0, 0.48, 1)",direction:"alternate",iterations:1/0})}};g.styles=W;g=j([f("w3m-connecting-siwe")],g);var S=function(t,e,n,a){var o=arguments.length,i=o<3?e:a===null?a=Object.getOwnPropertyDescriptor(e,n):a,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(t,e,n,a);else for(var l=t.length-1;l>=0;l--)(r=t[l])&&(i=(o<3?r(i):o>3?r(e,n,i):r(e,n))||i);return o>3&&i&&Object.defineProperty(e,n,i),i};let d=class extends p{constructor(){var e;super(...arguments),this.dappName=(e=w.state.metadata)==null?void 0:e.name,this.isSigning=!1}render(){return h` |
| 18 | + <wui-flex justifyContent="center" .padding=${["2xl","0","xxl","0"]}> |
| 19 | + <w3m-connecting-siwe></w3m-connecting-siwe> |
| 20 | + </wui-flex> |
| 21 | + <wui-flex |
| 22 | + .padding=${["0","4xl","l","4xl"]} |
| 23 | + gap="s" |
| 24 | + justifyContent="space-between" |
| 25 | + > |
| 26 | + <wui-text variant="paragraph-500" align="center" color="fg-100" |
| 27 | + >${this.dappName??"Dapp"} needs to connect to your wallet</wui-text |
| 28 | + > |
| 29 | + </wui-flex> |
| 30 | + <wui-flex |
| 31 | + .padding=${["0","3xl","l","3xl"]} |
| 32 | + gap="s" |
| 33 | + justifyContent="space-between" |
| 34 | + > |
| 35 | + <wui-text variant="small-400" align="center" color="fg-200" |
| 36 | + >Sign this message to prove you own this wallet and proceed. Canceling will disconnect |
| 37 | + you.</wui-text |
| 38 | + > |
| 39 | + </wui-flex> |
| 40 | + <wui-flex .padding=${["l","xl","xl","xl"]} gap="s" justifyContent="space-between"> |
| 41 | + <wui-button |
| 42 | + size="md" |
| 43 | + ?fullwidth=${!0} |
| 44 | + variant="shade" |
| 45 | + @click=${this.onCancel.bind(this)} |
| 46 | + data-testid="w3m-connecting-siwe-cancel" |
| 47 | + > |
| 48 | + Cancel |
| 49 | + </wui-button> |
| 50 | + <wui-button |
| 51 | + size="md" |
| 52 | + ?fullwidth=${!0} |
| 53 | + variant="fill" |
| 54 | + @click=${this.onSign.bind(this)} |
| 55 | + ?loading=${this.isSigning} |
| 56 | + data-testid="w3m-connecting-siwe-sign" |
| 57 | + > |
| 58 | + ${this.isSigning?"Signing...":"Sign"} |
| 59 | + </wui-button> |
| 60 | + </wui-flex> |
| 61 | + `}async onSign(){this.isSigning=!0,c.sendEvent({event:"CLICK_SIGN_SIWE_MESSAGE",type:"track"});try{u.setStatus("loading");const e=await u.signIn();return u.setStatus("success"),c.sendEvent({event:"SIWE_AUTH_SUCCESS",type:"track"}),e}catch{return E.showError("Signature declined"),u.setStatus("error"),c.sendEvent({event:"SIWE_AUTH_ERROR",type:"track"})}finally{this.isSigning=!1}}async onCancel(){const{isConnected:e}=I.state;e?(await $.disconnect(),O.close()):R.push("Connect"),c.sendEvent({event:"CLICK_CANCEL_SIWE",type:"track"})}};S([v()],d.prototype,"isSigning",void 0);d=S([f("w3m-connecting-siwe-view")],d);export{u as SIWEController,g as W3mConnectingSiwe,d as W3mConnectingSiweView}; |
0 commit comments