@dcl/auth-site 4.20.1-29258723513.commit-cae3306 → 4.20.1-29269215567.commit-a168e3f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/assets/{ConstantsUtil-BjWpx7T2.js → ConstantsUtil-D1WLKDE-.js} +1 -1
  2. package/assets/{ContentfulRichText-BfCmpZFl.js → ContentfulRichText-FVjmh8mR.js} +1 -1
  3. package/assets/{ExchangeController-BWl9iaFL.js → ExchangeController-BxyxYUKZ.js} +1 -1
  4. package/assets/{HelpersUtil-CfGGchds.js → HelpersUtil-DtAz3pBV.js} +1 -1
  5. package/assets/{LoginPage-DVLMDBaV.js → LoginPage-DeOWBfwU.js} +1 -1
  6. package/assets/{NetworkUtil-CfnkiECb.js → NetworkUtil-BcejqRTW.js} +1 -1
  7. package/assets/{SwapController-CYmwHGJz.js → SwapController-73H8AJso.js} +1 -1
  8. package/assets/{W3MFrameProviderSingleton-BjLnTdbd.js → W3MFrameProviderSingleton-Ch6ChvE7.js} +3 -3
  9. package/assets/{biconomy-Z4Ml6LcT.js → biconomy-D8d8IXiO.js} +1 -1
  10. package/assets/{browser-D-ehd5mn.js → browser-W1csxV8_.js} +1 -1
  11. package/assets/browser-ponyfill-mmJvcXGA.js +1 -0
  12. package/assets/{ccip-D3j6mW_p.js → ccip-D27X7965.js} +1 -1
  13. package/assets/{ccip-mqdjgI8a.js → ccip-DCHn-5Ly.js} +1 -1
  14. package/assets/{chains-DgHaRQQo.js → chains-Cn1WlLOp.js} +1 -1
  15. package/assets/{common-XZEVAD11.js → common-tpLjuIr4.js} +1 -1
  16. package/assets/{controller-D8avnVns.js → controller-UwO1SN8i.js} +2 -2
  17. package/assets/{data-capture-4EXUByXV.js → data-capture-Dh-nweo4.js} +1 -1
  18. package/assets/{email-D3adTb9O.js → email-1UrgYZj-.js} +1 -1
  19. package/assets/{embedded-wallet-B1bMmAkq.js → embedded-wallet-CLpjPJB3.js} +1 -1
  20. package/assets/{engine-CIjctzmA.js → engine-DCBK_VOQ.js} +1 -1
  21. package/assets/{estimate-l1-fee-CgWKwYl1.js → estimate-l1-fee-BiwlHSf1.js} +1 -1
  22. package/assets/{ethereum-DTOspYzU.js → ethereum--b_BvyFy.js} +1 -1
  23. package/assets/{extractIPFS-DbNQ1ZZ1.js → extractIPFS-B5PPp_Gm.js} +1 -1
  24. package/assets/{features-DGCEZ85b.js → features-C5Jgw5I-.js} +1 -1
  25. package/assets/{fetchTokenMetadata-DflkFEm7.js → fetchTokenMetadata-vXUP7U_6.js} +1 -1
  26. package/assets/{fortmatic-Da9wiqsL.js → fortmatic-vxyuQsp3.js} +1 -1
  27. package/assets/{get-ecosystem-wallet-info-Yc0jwh4E.js → get-ecosystem-wallet-info-k8z19lvl.js} +1 -1
  28. package/assets/{getBalance-CUqsth07.js → getBalance-BMgSFA2M.js} +1 -1
  29. package/assets/{getInstalledModules-5vWGWL48.js → getInstalledModules-DfESwpSd.js} +1 -1
  30. package/assets/{getNFT-DUzk33cX.js → getNFT-CR4D5mRM.js} +2 -2
  31. package/assets/{getNFT-DkfSQdYL.js → getNFT-Drb8KYgY.js} +1 -1
  32. package/assets/{if-defined-DCopXNZS.js → if-defined-BLUpxRFe.js} +1 -1
  33. package/assets/{in-app-wallet-calls-C9O-RFto.js → in-app-wallet-calls-CpSZ4AEs.js} +1 -1
  34. package/assets/{index-BATYHfSr.js → index-0Xh_8t-W.js} +1 -1
  35. package/assets/{index-ml3rUNwI.js → index-6iU19F1Q.js} +1 -1
  36. package/assets/{index-DhBkZu0c.js → index-B0b0mXhy.js} +1 -1
  37. package/assets/{index-Cl-OwcGb.js → index-B0zN8-JK.js} +1 -1
  38. package/assets/{index-DK0Bt-Wd.js → index-B61juR-E.js} +1 -1
  39. package/assets/{index-CMUvim3v.js → index-BBbd2JGA.js} +1 -1
  40. package/assets/{index-DeBgqNL8.js → index-BGImxKnk.js} +1 -1
  41. package/assets/{index-Ctf22atn.js → index-BOhMx_xq.js} +1 -1
  42. package/assets/{index-Dup8pmdS.js → index-BRSVe_Ha.js} +1 -1
  43. package/assets/{index-Cc-CvbmM.js → index-BbU4jWmF.js} +1 -1
  44. package/assets/{index-CeotffFj.js → index-BeJFBKfZ.js} +1 -1
  45. package/assets/{index-DQiBk_Ys.js → index-BfS3YMbV.js} +1 -1
  46. package/assets/{index-sBYypQxE.js → index-BgJCDn2i.js} +3 -3
  47. package/assets/{index-CJyln68U.js → index-BgXz7S15.js} +1 -1
  48. package/assets/{index-DwMcfG7D.js → index-BjMnYwkm.js} +1 -1
  49. package/assets/{index-BPuklqdK.js → index-BjRsFS7f.js} +1 -1
  50. package/assets/{index-BDaLj5Px.js → index-BnBi3XT_.js} +1 -1
  51. package/assets/{index-B3krs25g.js → index-Boyp-nKd.js} +3 -3
  52. package/assets/{index-DLiFbqtz.js → index-BqL1TOTU.js} +1 -1
  53. package/assets/{index-ByytQPhZ.js → index-BqsCFid8.js} +1 -1
  54. package/assets/{index-ipSabmF7.js → index-ButPZc2m.js} +1 -1
  55. package/assets/{index-g80snjIg.js → index-Bw38Qien.js} +1 -1
  56. package/assets/{index-sITL-8BM.js → index-BxcO2eus.js} +1 -1
  57. package/assets/{index-BO59eDsp.js → index-Byc3YIzR.js} +2 -2
  58. package/assets/{index-DvAGrr_i.js → index-C7rQpKd5.js} +1 -1
  59. package/assets/{index-DVhT4X-3.js → index-CLhB4G-z.js} +2 -2
  60. package/assets/{index-CN1IjigP.js → index-CRvP0-6j.js} +1 -1
  61. package/assets/{index-CiJidnr0.js → index-CYQL0N_2.js} +1 -1
  62. package/assets/{index-BY4NlcmY.js → index-CfRwmSIm.js} +18 -18
  63. package/assets/{index-BORF4fWz.js → index-ChZiIgQr.js} +1 -1
  64. package/assets/{index-B4pSUR6E.js → index-D4MI3QNi.js} +1 -1
  65. package/assets/{index-B4drTZRO.js → index-D7YbgLzU.js} +1 -1
  66. package/assets/{index-nO17hoA5.js → index-DbBb4_zM.js} +1 -1
  67. package/assets/{index-C8cqnNjb.js → index-Dc7LPwqa.js} +1 -1
  68. package/assets/{index-53Q8flld.js → index-Dpiro8hw.js} +1 -1
  69. package/assets/{index-ByhJb4Ih.js → index-DqsqcBWz.js} +1 -1
  70. package/assets/{index-Ccp6ERTg.js → index-Dw0jehUl.js} +1 -1
  71. package/assets/{index-_xPKVrQn.js → index-Dy0kafyd.js} +1 -1
  72. package/assets/{index-CbygmjoX.js → index-FC7wyxSL.js} +1 -1
  73. package/assets/{index-C4fiE5-u.js → index-FTloM5tR.js} +1 -1
  74. package/assets/{index-DQ0zTbeB.js → index-bVJLpFe9.js} +1 -1
  75. package/assets/{index-D7pmAMgG.js → index-gEWsoeoj.js} +1 -1
  76. package/assets/{index-pVmAeDrn.js → index-hV7VprO9.js} +1 -1
  77. package/assets/{index-DfGi8q2I.js → index-t4TDOvhg.js} +1 -1
  78. package/assets/{index-B0ZJSTkn.js → index-uMURdbl1.js} +1 -1
  79. package/assets/{index-IpYAUNd_.js → index-wa52fI50.js} +1 -1
  80. package/assets/{index-C89TfD5l.js → index-y1LmxmxV.js} +1 -1
  81. package/assets/{index-B7V-nRWu.css → index-zwxMhp39.css} +1 -1
  82. package/assets/{index.es-BwZcPOdM.js → index.es-CwJH2io5.js} +1 -1
  83. package/assets/{index.es-BYcrNAKX.js → index.es-bckiMtUI.js} +1 -1
  84. package/assets/{native-Bo5F-dEa.js → native-BxoXPUnu.js} +1 -1
  85. package/assets/{networks-LwU8vdsD.js → networks-DJg10bEc.js} +3 -3
  86. package/assets/{onramp-DTZoRR_S.js → onramp-B4pEvCie.js} +1 -1
  87. package/assets/{openzeppelin-F9RpoISL.js → openzeppelin-aTaIao0N.js} +1 -1
  88. package/assets/{ownerOf-B3Zr2zns.js → ownerOf-_31Y1xvr.js} +1 -1
  89. package/assets/{parseNft-DTgzSFLX.js → parseNft-BreIwf-v.js} +2 -2
  90. package/assets/{pay-with-exchange-DfkBevGx.js → pay-with-exchange-DWzTSiHz.js} +1 -1
  91. package/assets/{qr-overlay-CdqFzcAP.js → qr-overlay-ri_FAG95.js} +3 -3
  92. package/assets/{receive-dkrgLBnV.js → receive-BhwBfPBx.js} +1 -1
  93. package/assets/{ref-BrcF-6zM.js → ref-C6y6rEPL.js} +1 -1
  94. package/assets/{resolveImplementation-DIVc-dsH.js → resolveImplementation-DDfKMK0l.js} +1 -1
  95. package/assets/{secp256k1-Xe1NL0HC.js → secp256k1-fwuTEIeg.js} +1 -1
  96. package/assets/{send-Y70p6kOL.js → send-DQ_s7hBA.js} +1 -1
  97. package/assets/{send-eip712-transaction-XyoSUCoI.js → send-eip712-transaction-P-r3Ko22.js} +1 -1
  98. package/assets/{send-gasless-transaction-DJTroDJ7.js → send-gasless-transaction-CA021mhn.js} +2 -2
  99. package/assets/{session-proposal-C6FylYAa.js → session-proposal-2lV42kFm.js} +1 -1
  100. package/assets/{session-request-BEK1bzJi.js → session-request-BG0E-HG_.js} +2 -2
  101. package/assets/{socials-klWMjU_b.js → socials-BwTV76GY.js} +1 -1
  102. package/assets/{swaps-CIxrpugR.js → swaps-BlfTMX7q.js} +1 -1
  103. package/assets/{thirdweb-fDOh4yMb.js → thirdweb-CT38Qh_V.js} +5 -5
  104. package/assets/{totalSupply-JOkSK4qj.js → totalSupply-DKb8yY1T.js} +1 -1
  105. package/assets/{transactions-BmVnfQ2v.js → transactions-CacIfnoG.js} +1 -1
  106. package/assets/{ui-wp2UWukJ.js → ui-WV8OFH8_.js} +5 -5
  107. package/assets/{vendor-CnDTCxi8.js → vendor-0sbCgRYC.js} +1 -1
  108. package/assets/{w3m-modal-Dsf51JPh.js → w3m-modal-DD7YQQ5K.js} +1 -1
  109. package/assets/{wallets-BtCC5Qdr.js → wallets-chAGIjBC.js} +5 -5
  110. package/assets/{web-connector-CBgneeYJ.js → web-connector-B_sMPq36.js} +3 -3
  111. package/index.html +5 -5
  112. package/package.json +3 -3
  113. package/assets/browser-ponyfill-ny6VoCwj.js +0 -1
@@ -1 +1 @@
1
- import{p as t}from"./thirdweb-fDOh4yMb.js";var e={};const o={ACCOUNT_TABS:[{label:"Tokens"},{label:"Activity"}],SECURE_SITE_ORIGIN:(typeof t<"u"&&typeof e<"u"?e.NEXT_PUBLIC_SECURE_SITE_ORIGIN:void 0)||"https://secure.walletconnect.org",VIEW_DIRECTION:{Next:"next",Prev:"prev"},ANIMATION_DURATIONS:{HeaderText:120},VIEWS_WITH_LEGAL_FOOTER:["Connect","ConnectWallets","OnRampTokenSelect","OnRampFiatSelect","OnRampProviders"],VIEWS_WITH_DEFAULT_FOOTER:["Networks"]};export{o as C};
1
+ import{p as t}from"./thirdweb-CT38Qh_V.js";var e={};const o={ACCOUNT_TABS:[{label:"Tokens"},{label:"Activity"}],SECURE_SITE_ORIGIN:(typeof t<"u"&&typeof e<"u"?e.NEXT_PUBLIC_SECURE_SITE_ORIGIN:void 0)||"https://secure.walletconnect.org",VIEW_DIRECTION:{Next:"next",Prev:"prev"},ANIMATION_DURATIONS:{HeaderText:120},VIEWS_WITH_LEGAL_FOOTER:["Connect","ConnectWallets","OnRampTokenSelect","OnRampFiatSelect","OnRampProviders"],VIEWS_WITH_DEFAULT_FOOTER:["Networks"]};export{o as C};
@@ -1 +1 @@
1
- import{_ as m}from"./thirdweb-fDOh4yMb.js";import{j as e}from"./ui-wp2UWukJ.js";import{a as o}from"./vendor-CnDTCxi8.js";const p=({document:t})=>{const[r,n]=o.useState(null);return o.useEffect(()=>{m(()=>import("./rich-text-react-renderer_decentraland-ui2-BIHI7g3E.js"),[]).then(s=>{n(s.documentToReactComponents(t))})},[t]),e.jsx(e.Fragment,{children:r})};export{p as ContentfulRichText};
1
+ import{_ as m}from"./thirdweb-CT38Qh_V.js";import{j as e}from"./ui-WV8OFH8_.js";import{a as o}from"./vendor-0sbCgRYC.js";const p=({document:t})=>{const[r,n]=o.useState(null);return o.useEffect(()=>{m(()=>import("./rich-text-react-renderer_decentraland-ui2-BIHI7g3E.js"),[]).then(s=>{n(s.documentToReactComponents(t))})},[t]),e.jsx(e.Fragment,{children:r})};export{p as ContentfulRichText};
@@ -1 +1 @@
1
- import{p as k,C as l,E as w,a as E,S as A,b as U,O as x,N as P,g as f,B as N,s as I,c as L}from"./W3MFrameProviderSingleton-BjLnTdbd.js";import{g as T,a as W,f as b,b as _,c as v}from"./index-sBYypQxE.js";const D=0,C={paymentAsset:null,amount:null,tokenAmount:0,priceLoading:!1,error:null,exchanges:[],isLoading:!1,currentPayment:void 0,isPaymentInProgress:!1,paymentId:"",assets:[]},e=k(C),m={state:e,subscribe(t){return L(e,()=>t(e))},subscribeKey(t,n){return I(e,t,n)},resetState(){Object.assign(e,{...C})},async getAssetsForNetwork(t){const n=v(t),s=await m.getAssetsImageAndPrice(n),r=n.map(a=>{var c,o,p,y;const u=a.asset==="native"?f():`${a.network}:${a.asset}`,i=s.find(S=>{var g,d,h;return((h=(d=(g=S.fungibles)==null?void 0:g[0])==null?void 0:d.address)==null?void 0:h.toLowerCase())===u.toLowerCase()});return{...a,price:((o=(c=i==null?void 0:i.fungibles)==null?void 0:c[0])==null?void 0:o.price)||1,metadata:{...a.metadata,iconUrl:(y=(p=i==null?void 0:i.fungibles)==null?void 0:p[0])==null?void 0:y.iconUrl}}});return e.assets=r,r},async getAssetsImageAndPrice(t){const n=t.map(r=>r.asset==="native"?f():`${r.network}:${r.asset}`);return await Promise.all(n.map(r=>N.fetchTokenPrice({addresses:[r]})))},getTokenAmount(){var s;if(!((s=e==null?void 0:e.paymentAsset)!=null&&s.price))throw new Error("Cannot get token price");const t=P.bigNumber(e.amount??0).round(8),n=P.bigNumber(e.paymentAsset.price).round(8);return t.div(n).round(8).toNumber()},setAmount(t){var n;e.amount=t,(n=e.paymentAsset)!=null&&n.price&&(e.tokenAmount=m.getTokenAmount())},setPaymentAsset(t){e.paymentAsset=t},isPayWithExchangeEnabled(){var t;return(t=x.state.remoteFeatures)==null?void 0:t.payWithExchange},isPayWithExchangeSupported(){return m.isPayWithExchangeEnabled()&&l.state.activeCaipNetwork&&U.PAY_WITH_EXCHANGE_SUPPORTED_CHAIN_NAMESPACES.includes(l.state.activeCaipNetwork.chainNamespace)},async fetchExchanges(){var t;try{const n=m.isPayWithExchangeSupported();if(!e.paymentAsset||!n){e.exchanges=[],e.isLoading=!1;return}e.isLoading=!0;const s=await _({page:D,asset:b(e.paymentAsset.network,e.paymentAsset.asset),amount:((t=e.amount)==null?void 0:t.toString())??"0"});e.exchanges=s.exchanges.slice(0,2)}catch{throw A.showError("Unable to get exchanges"),new Error("Unable to get exchanges")}finally{e.isLoading=!1}},async getPayUrl(t,n){try{const s=Number(n.amount),r=await W({exchangeId:t,asset:b(n.network,n.asset),amount:s.toString(),recipient:`${n.network}:${n.recipient}`});return w.sendEvent({type:"track",event:"PAY_EXCHANGE_SELECTED",properties:{exchange:{id:t},configuration:{network:n.network,asset:n.asset,recipient:n.recipient,amount:s},currentPayment:{type:"exchange",exchangeId:t},source:"fund-from-exchange",headless:!1}}),r}catch(s){throw s instanceof Error&&s.message.includes("is not supported")?new Error("Asset not supported"):new Error(s.message)}},async handlePayWithExchange(t){var n;try{const s=(n=l.getAccountData())==null?void 0:n.address;if(!s)throw new Error("No account connected");if(!e.paymentAsset)throw new Error("No payment asset selected");const r=E.returnOpenHref("","popupWindow","scrollbar=yes,width=480,height=720");if(!r)throw new Error("Could not create popup window");e.isPaymentInProgress=!0,e.paymentId=crypto.randomUUID(),e.currentPayment={type:"exchange",exchangeId:t};const{network:a,asset:u}=e.paymentAsset,i={network:a,asset:u,amount:e.tokenAmount,recipient:s},c=await m.getPayUrl(t,i);if(!c){try{r.close()}catch(o){console.error("Unable to close popup window",o)}throw new Error("Unable to initiate payment")}e.currentPayment.sessionId=c.sessionId,e.currentPayment.status="IN_PROGRESS",e.currentPayment.exchangeId=t,r.location.href=c.url}catch{e.error="Unable to initiate payment",A.showError(e.error)}},async waitUntilComplete({exchangeId:t,sessionId:n,paymentId:s,retries:r=20}){const a=await m.getBuyStatus(t,n,s);if(a.status==="SUCCESS"||a.status==="FAILED")return a;if(r===0)throw new Error("Unable to get deposit status");return await new Promise(u=>{setTimeout(u,5e3)}),m.waitUntilComplete({exchangeId:t,sessionId:n,paymentId:s,retries:r-1})},async getBuyStatus(t,n,s){var r,a,u,i,c;try{if(!e.currentPayment)throw new Error("No current payment");const o=await T({sessionId:n,exchangeId:t});if(e.currentPayment.status=o.status,o.status==="SUCCESS"||o.status==="FAILED"){const p=(r=l.getAccountData())==null?void 0:r.address;e.currentPayment.result=o.txHash,e.isPaymentInProgress=!1,w.sendEvent({type:"track",event:o.status==="SUCCESS"?"PAY_SUCCESS":"PAY_ERROR",properties:{message:o.status==="FAILED"?E.parseError(e.error):void 0,source:"fund-from-exchange",paymentId:s,configuration:{network:((a=e.paymentAsset)==null?void 0:a.network)||"",asset:((u=e.paymentAsset)==null?void 0:u.asset)||"",recipient:p||"",amount:e.amount??0},currentPayment:{type:"exchange",exchangeId:(i=e.currentPayment)==null?void 0:i.exchangeId,sessionId:(c=e.currentPayment)==null?void 0:c.sessionId,result:o.txHash}}})}return o}catch{return{status:"UNKNOWN",txHash:""}}},reset(){e.currentPayment=void 0,e.isPaymentInProgress=!1,e.paymentId="",e.paymentAsset=null,e.amount=0,e.tokenAmount=0,e.priceLoading=!1,e.error=null,e.exchanges=[],e.isLoading=!1}};export{m as E};
1
+ import{p as k,C as l,E as w,a as E,S as A,b as U,O as x,N as P,g as f,B as N,s as I,c as L}from"./W3MFrameProviderSingleton-Ch6ChvE7.js";import{g as T,a as W,f as b,b as _,c as v}from"./index-BgJCDn2i.js";const D=0,C={paymentAsset:null,amount:null,tokenAmount:0,priceLoading:!1,error:null,exchanges:[],isLoading:!1,currentPayment:void 0,isPaymentInProgress:!1,paymentId:"",assets:[]},e=k(C),m={state:e,subscribe(t){return L(e,()=>t(e))},subscribeKey(t,n){return I(e,t,n)},resetState(){Object.assign(e,{...C})},async getAssetsForNetwork(t){const n=v(t),s=await m.getAssetsImageAndPrice(n),r=n.map(a=>{var c,o,p,y;const u=a.asset==="native"?f():`${a.network}:${a.asset}`,i=s.find(S=>{var g,d,h;return((h=(d=(g=S.fungibles)==null?void 0:g[0])==null?void 0:d.address)==null?void 0:h.toLowerCase())===u.toLowerCase()});return{...a,price:((o=(c=i==null?void 0:i.fungibles)==null?void 0:c[0])==null?void 0:o.price)||1,metadata:{...a.metadata,iconUrl:(y=(p=i==null?void 0:i.fungibles)==null?void 0:p[0])==null?void 0:y.iconUrl}}});return e.assets=r,r},async getAssetsImageAndPrice(t){const n=t.map(r=>r.asset==="native"?f():`${r.network}:${r.asset}`);return await Promise.all(n.map(r=>N.fetchTokenPrice({addresses:[r]})))},getTokenAmount(){var s;if(!((s=e==null?void 0:e.paymentAsset)!=null&&s.price))throw new Error("Cannot get token price");const t=P.bigNumber(e.amount??0).round(8),n=P.bigNumber(e.paymentAsset.price).round(8);return t.div(n).round(8).toNumber()},setAmount(t){var n;e.amount=t,(n=e.paymentAsset)!=null&&n.price&&(e.tokenAmount=m.getTokenAmount())},setPaymentAsset(t){e.paymentAsset=t},isPayWithExchangeEnabled(){var t;return(t=x.state.remoteFeatures)==null?void 0:t.payWithExchange},isPayWithExchangeSupported(){return m.isPayWithExchangeEnabled()&&l.state.activeCaipNetwork&&U.PAY_WITH_EXCHANGE_SUPPORTED_CHAIN_NAMESPACES.includes(l.state.activeCaipNetwork.chainNamespace)},async fetchExchanges(){var t;try{const n=m.isPayWithExchangeSupported();if(!e.paymentAsset||!n){e.exchanges=[],e.isLoading=!1;return}e.isLoading=!0;const s=await _({page:D,asset:b(e.paymentAsset.network,e.paymentAsset.asset),amount:((t=e.amount)==null?void 0:t.toString())??"0"});e.exchanges=s.exchanges.slice(0,2)}catch{throw A.showError("Unable to get exchanges"),new Error("Unable to get exchanges")}finally{e.isLoading=!1}},async getPayUrl(t,n){try{const s=Number(n.amount),r=await W({exchangeId:t,asset:b(n.network,n.asset),amount:s.toString(),recipient:`${n.network}:${n.recipient}`});return w.sendEvent({type:"track",event:"PAY_EXCHANGE_SELECTED",properties:{exchange:{id:t},configuration:{network:n.network,asset:n.asset,recipient:n.recipient,amount:s},currentPayment:{type:"exchange",exchangeId:t},source:"fund-from-exchange",headless:!1}}),r}catch(s){throw s instanceof Error&&s.message.includes("is not supported")?new Error("Asset not supported"):new Error(s.message)}},async handlePayWithExchange(t){var n;try{const s=(n=l.getAccountData())==null?void 0:n.address;if(!s)throw new Error("No account connected");if(!e.paymentAsset)throw new Error("No payment asset selected");const r=E.returnOpenHref("","popupWindow","scrollbar=yes,width=480,height=720");if(!r)throw new Error("Could not create popup window");e.isPaymentInProgress=!0,e.paymentId=crypto.randomUUID(),e.currentPayment={type:"exchange",exchangeId:t};const{network:a,asset:u}=e.paymentAsset,i={network:a,asset:u,amount:e.tokenAmount,recipient:s},c=await m.getPayUrl(t,i);if(!c){try{r.close()}catch(o){console.error("Unable to close popup window",o)}throw new Error("Unable to initiate payment")}e.currentPayment.sessionId=c.sessionId,e.currentPayment.status="IN_PROGRESS",e.currentPayment.exchangeId=t,r.location.href=c.url}catch{e.error="Unable to initiate payment",A.showError(e.error)}},async waitUntilComplete({exchangeId:t,sessionId:n,paymentId:s,retries:r=20}){const a=await m.getBuyStatus(t,n,s);if(a.status==="SUCCESS"||a.status==="FAILED")return a;if(r===0)throw new Error("Unable to get deposit status");return await new Promise(u=>{setTimeout(u,5e3)}),m.waitUntilComplete({exchangeId:t,sessionId:n,paymentId:s,retries:r-1})},async getBuyStatus(t,n,s){var r,a,u,i,c;try{if(!e.currentPayment)throw new Error("No current payment");const o=await T({sessionId:n,exchangeId:t});if(e.currentPayment.status=o.status,o.status==="SUCCESS"||o.status==="FAILED"){const p=(r=l.getAccountData())==null?void 0:r.address;e.currentPayment.result=o.txHash,e.isPaymentInProgress=!1,w.sendEvent({type:"track",event:o.status==="SUCCESS"?"PAY_SUCCESS":"PAY_ERROR",properties:{message:o.status==="FAILED"?E.parseError(e.error):void 0,source:"fund-from-exchange",paymentId:s,configuration:{network:((a=e.paymentAsset)==null?void 0:a.network)||"",asset:((u=e.paymentAsset)==null?void 0:u.asset)||"",recipient:p||"",amount:e.amount??0},currentPayment:{type:"exchange",exchangeId:(i=e.currentPayment)==null?void 0:i.exchangeId,sessionId:(c=e.currentPayment)==null?void 0:c.sessionId,result:o.txHash}}})}return o}catch{return{status:"UNKNOWN",txHash:""}}},reset(){e.currentPayment=void 0,e.isPaymentInProgress=!1,e.paymentId="",e.paymentAsset=null,e.amount=0,e.tokenAmount=0,e.priceLoading=!1,e.error=null,e.exchanges=[],e.isLoading=!1}};export{m as E};
@@ -1,4 +1,4 @@
1
- import{d as f,r as p,i as g,h}from"./index-sBYypQxE.js";import{n as m,c as v}from"./index-DhBkZu0c.js";import{C as c}from"./ConstantsUtil-BjWpx7T2.js";import{R as $,O as u}from"./W3MFrameProviderSingleton-BjLnTdbd.js";import{C as y}from"./NetworkUtil-CfnkiECb.js";const b=f`
1
+ import{d as f,r as p,i as g,h}from"./index-BgJCDn2i.js";import{n as m,c as v}from"./index-B0b0mXhy.js";import{C as c}from"./ConstantsUtil-D1WLKDE-.js";import{R as $,O as u}from"./W3MFrameProviderSingleton-Ch6ChvE7.js";import{C as y}from"./NetworkUtil-BcejqRTW.js";const b=f`
2
2
  :host {
3
3
  display: flex;
4
4
  justify-content: center;
@@ -1 +1 @@
1
- import{u as A,j as e,D as xe,C as pe,G as De,L as ie,b as ke,c as $e}from"./ui-wp2UWukJ.js";import{e as Fe,a}from"./vendor-CnDTCxi8.js";import{E as J,F as u,G as Ve,J as ze,K as Ke,M as qe,O as He,P as Ze,Q as Je,X as Qe,Y as Xe,Z as ye,_ as Ye,$ as en,a0 as nn,a1 as an,a2 as tn,a3 as sn,a4 as on,a5 as rn,a6 as ln,a7 as cn,a8 as dn,a9 as un,aa as gn,ab as hn,ac as mn,ad as wn,ae as Cn,af as fn,ag as xn,ah as pn,ai as kn,aj as yn,ak as En,al as Sn,am as jn,an as Ln,ao as _n,ap as bn,aq as In,ar as le,as as ce,at as de,au as ue,av as Tn,aw as Mn,ax as On,ay as S,az as vn,aA as An,aB as Rn,aC as Pn,aD as Wn,aE as Nn,aF as Bn,aG as Un,aH as Gn,aI as Dn,aJ as V,aK as $n,aL as Fn,aM as ge,aN as v,aO as Vn,aP as zn,aQ as Kn,aR as he,aS as me,aT as qn,aU as Hn,aV as we,aW as Zn,aX as Ce,aY as Jn,aZ as Qn,a_ as Xn,a$ as Yn,b0 as ea,b1 as na,b2 as aa,b3 as ta}from"./index-BY4NlcmY.js";import"./thirdweb-fDOh4yMb.js";const sa="https://cdn.decentraland.org/@dcl/auth-site/4.20.1-29258723513.commit-cae3306/assets/image-new1-CpZnKbBW.webp",oa="https://cdn.decentraland.org/@dcl/auth-site/4.20.1-29258723513.commit-cae3306/assets/image-new2-C5ihWkmR.webp",ra="https://cdn.decentraland.org/@dcl/auth-site/4.20.1-29258723513.commit-cae3306/assets/image-new3-DJx27VUM.webp",ia="https://cdn.decentraland.org/@dcl/auth-site/4.20.1-29258723513.commit-cae3306/assets/image-new4-Dx5Lwr3m.webp",la="https://cdn.decentraland.org/@dcl/auth-site/4.20.1-29258723513.commit-cae3306/assets/image-new5-CzVG1QYp.webp",ca="https://cdn.decentraland.org/@dcl/auth-site/4.20.1-29258723513.commit-cae3306/assets/image-new6-DgBpE6FO.webp",da=["email","metamask","google","discord","apple","x","fortmatic","coinbase","walletconnect"];function ua(t){switch(t){case"email":return u.EMAIL;case"metamask":return u.METAMASK;case"google":return u.GOOGLE;case"discord":return u.DISCORD;case"apple":return u.APPLE;case"x":return u.X;case"fortmatic":return u.FORTMATIC;case"coinbase":return u.COINBASE;case"walletconnect":return u.WALLET_CONNECT}}const ga=({isReady:t,onConnect:r})=>{var j;const[c]=Fe(),i=a.useRef(!1),g=(j=c.get("loginMethod"))==null?void 0:j.toLowerCase(),y=da.includes(g)?g:null,x=a.useCallback(()=>y?ua(y):null,[y])();return a.useEffect(()=>{if(!t||i.current||!x||J(x)&&!window.ethereum)return;const E=setTimeout(()=>{i.current=!0,r(x)},100);return()=>clearTimeout(E)},[t,x,r]),{loginMethod:y,autoLoginTriggered:i.current,resolvedConnectionOption:x}},ha=pe,ma=({open:t,onContinue:r,onClose:c})=>{const{t:i}=A();return e.jsxs(xe,{open:t,maxWidth:"xs",fullWidth:!0,children:[e.jsx(Ve,{onClick:c,"data-testid":"clock-sync-close-button",children:e.jsx(ha,{})}),e.jsxs(ze,{children:[e.jsx(Ke,{src:qe,alt:"warning"}),e.jsx(He,{children:i("clock_sync_modal.title")}),e.jsx(Ze,{children:i("clock_sync_modal.message")}),e.jsx(Je,{children:e.jsx(Qe,{variant:"contained",onClick:r,"data-testid":"clock-sync-continue-button",children:i("clock_sync_modal.continue_to_site")})})]})]})},wa=async t=>{await ye(t)},Ca=async(t,r)=>Xe(t,r),fa=t=>{const{open:r,email:c,onClose:i,onBack:g,onSuccess:y}=t,{t:l}=A(),x=a.useCallback(async(b,f)=>{const k=await Ca(b,f);return localStorage.setItem("dcl_thirdweb_user_email",b),{email:b,address:k}},[]),{otp:j,error:E,isLoading:h,hasError:m,otpInputRefs:p,handleOtpChange:R,handleOtpKeyDown:C,handleOtpPaste:P,handleResendOtp:L,isResendDisabled:_,resendText:W}=Ye({open:r,email:c,verify:x,resend:wa,onSuccess:y}),z=a.useCallback(()=>{h||i()},[h,i]),K=a.useCallback(()=>{h||g()},[h,g]),N=()=>e.jsxs(cn,{children:[e.jsx(dn,{children:e.jsx(un,{src:gn,alt:""})}),e.jsx(hn,{children:l("email_login_modal.title")}),e.jsxs(mn,{children:[l("email_login_modal.subtitle_prefix"),e.jsx("strong",{children:c}),l("email_login_modal.subtitle_suffix")]}),e.jsx(wn,{hasError:m,children:j.map((b,f)=>e.jsx(Cn,{"data-testid":`otp-input-${f}`,ref:k=>{p.current[f]=k},type:"text",inputMode:"numeric",maxLength:1,value:b,onChange:k=>R(f,k.target.value),onKeyDown:k=>C(f,k),onPaste:P,hasError:m,disabled:h,autoComplete:"one-time-code"},f))}),h&&!E&&e.jsxs(fn,{children:[e.jsx(xn,{size:16}),e.jsx(pn,{children:l("email_login_modal.verifying")})]}),E&&e.jsxs(e.Fragment,{children:[e.jsx(kn,{children:E}),e.jsx(yn,{disabled:_,onClick:_?void 0:L,children:W})]}),!E&&e.jsxs(En,{children:[l("email_login_modal.didnt_get_email"),e.jsx(Sn,{disabled:_,onClick:_?void 0:L,children:W})]})]});return e.jsxs(e.Fragment,{children:[r&&e.jsx(De,{styles:en}),e.jsxs(nn,{open:r,maxWidth:"sm",fullWidth:!0,className:an,children:[e.jsxs(tn,{children:[e.jsxs(sn,{onClick:K,disabled:h,"data-testid":"email-login-back-button",children:[e.jsx(on,{children:"‹"})," ",l("email_login_modal.back")]}),e.jsx(rn,{onClick:z,disabled:h,"data-testid":"email-login-close-button",children:"×"})]}),e.jsx(ln,{children:N()})]})]})},xa=pe,pa=({open:t,onTryAgain:r,onClose:c})=>{const{t:i}=A();return e.jsx(xe,{open:t,onClose:c,"aria-label":i("wallet_error_modal.title"),PaperProps:{sx:{background:"transparent",boxShadow:"none",overflow:"visible"}},slotProps:{backdrop:{sx:{backgroundColor:"rgba(0, 0, 0, 0.6)"}}},children:e.jsxs(jn,{children:[e.jsx(Ln,{onClick:c,"aria-label":i("common.close_window"),"data-testid":"wallet-error-close-button",children:e.jsx(xa,{sx:{fontSize:14}})}),e.jsx(_n,{children:e.jsxs("svg",{width:"30",height:"27",viewBox:"0 0 30 27",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M13.268 1.5C14.0378 0.166667 15.9623 0.166667 16.7321 1.5L28.8565 22.5C29.6263 23.8333 28.664 25.5 27.1244 25.5H2.87565C1.33605 25.5 0.373749 23.8333 1.14355 22.5L13.268 1.5Z",fill:"white",fillOpacity:"0",stroke:"white",strokeWidth:"2"}),e.jsx("path",{d:"M15 9V16",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round"}),e.jsx("circle",{cx:"15",cy:"20.5",r:"1.5",fill:"white"})]})}),e.jsx(bn,{children:i("wallet_error_modal.message")}),e.jsx(In,{variant:"contained",onClick:r,"data-testid":"wallet-error-try-again-button",children:i("wallet_error_modal.try_again")})]})})},ka=({error:t,onError:r})=>{const{t:c}=A();return t?e.jsxs(le,{children:[e.jsx(ce,{variant:"absolute"}),e.jsxs(de,{children:[e.jsx(ie,{size:"huge"}),e.jsx(ue,{children:c("common.something_went_wrong")}),e.jsx(Tn,{children:t}),r&&e.jsx(Mn,{onClick:r,"data-testid":"confirming-login-retry-button",children:c("common.try_again")})]})]}):e.jsxs(le,{children:[e.jsx(ce,{variant:"absolute"}),e.jsxs(de,{children:[e.jsx(ie,{size:"huge"}),e.jsx(ue,{children:c("login.confirming_login")}),e.jsx(On,{children:e.jsx(ke,{color:"inherit",size:40})})]})]})},fe=[sa,oa,ra,ia,la,ca],ya=["newUser","newuser","new-user","new_user"],ba=()=>{const{t}=A(),[r,c]=a.useState(ya.some(n=>new URLSearchParams(window.location.search).has(n))),[i,g]=a.useState(S.CONNECTING_WALLET),[y,l]=a.useState(!1),[x,j]=a.useState(!1),[E,h]=a.useState(!1),[m,p]=a.useState(),{redirect:R,redirectTo:C,skipSetup:P}=vn(),{initialized:L,flags:_,variants:W}=a.useContext(An),z=Rn(W),[K,N]=a.useState(()=>new URLSearchParams(window.location.search).get("walletError")==="rejected"),[b,f]=a.useState(""),[k,Q]=a.useState(!1),[Ee,O]=a.useState(null),[Se,B]=a.useState(!1),[X,q]=a.useState(null),Y=a.useMemo(()=>{if(!C)return"";try{const n=C.startsWith("/")?new URL(C,window.location.origin):new URL(C);return n.pathname.includes("/play")?(n.searchParams.append("guest","true"),n.toString()):""}catch{return""}},[C]),je=!!Y,[H,Le]=a.useState(0),[_e,ee]=a.useState(0),[Z,ne]=a.useState(!1),[be]=Pn(),{ensureProfile:ae}=Wn(),{identity:te,getIdentitySignature:U}=Nn(),{trackLoginClick:G,trackLoginSuccess:D,trackGuestLogin:se}=Bn(),Ie=a.useCallback(async()=>{await se()},[se]),I=a.useCallback(()=>{const n=new URLSearchParams(window.location.search);return Un(n)},[]),T=a.useCallback(async(n,s,o=null,w)=>{!P&&n&&!await ae(n,o??te,{redirectTo:C,referrer:s})||(Gn(n),R(),w==null||w())},[P,C,te,ae,R]),$=a.useCallback(async()=>await Dn()?!0:(l(!1),j(!0),!1),[]),Te=a.useCallback(async n=>{f(n),Q(!0),O(null),p(u.EMAIL),G({method:u.EMAIL,type:V.WEB2});try{await $n.disconnect(),await Fn()}catch{}ge({checkpointId:2,action:"reached",source:"auth",userIdentifier:n,identifierType:"email",email:n,metadata:{loginMethod:u.EMAIL}});try{await ye(n),h(!0)}catch(s){const o=v(s,"Error sending verification code");p(void 0),o==="Failed to fetch"||o!=null&&o.toLowerCase().includes("network")?O(t("login.errors.network_error")):o!=null&&o.toLowerCase().includes("invalid email")?O(t("login.errors.invalid_email")):O(o||t("login.errors.failed_send_code"))}finally{Q(!1)}},[G,t]),M=a.useCallback(async n=>{var w,F;if(!L)return;if(n===u.EMAIL){const d=document.getElementById("dcl-email-input");d&&(d.scrollIntoView({behavior:"smooth",block:"center"}),d.focus());return}const s=Vn(n),o=s?V.WEB2:V.WEB3;p(n),G({method:n,type:o});try{if(s)l(!0),g(S.LOADING_MAGIC),await zn(n,Kn(_[he.MAGIC_TEST]),C);else{if(J(n)&&!window.ethereum)throw new Error("No wallet extension detected. Please install MetaMask or another Ethereum wallet.");l(!0),g(S.CONNECTING_WALLET);const d=await me(n);ge({checkpointId:2,action:"reached",source:"auth",userIdentifier:((w=d.account)==null?void 0:w.toLowerCase())??"",identifierType:"wallet",wallet:(F=d.account)==null?void 0:F.toLowerCase(),metadata:{loginMethod:n}}),g(S.WAITING_FOR_SIGNATURE);const Ue=await U(d);localStorage.removeItem("dcl_thirdweb_user_email"),localStorage.removeItem("dcl_magic_user_email"),await D({ethAddress:d.account??void 0,type:o});const Ge=I();await $()&&await T(d.account??"",Ge,Ue,()=>l(!1))}}catch(d){qn(d)?console.info("User rejected login signature in wallet — not reporting to Sentry"):v(d,"Error during login connection",{sentryTags:{isWeb2Wallet:s,connectionType:n}}),Hn(d)&&d.name==="ErrorUnlockingWallet"?g(S.ERROR_LOCKED_WALLET):g(S.ERROR)}},[g,l,p,C,_[he.MAGIC_TEST],G,D,T,L,$,I,U]),Me=a.useCallback(()=>{l(!1),p(void 0),g(S.CONNECTING_WALLET)},[l]),Oe=a.useCallback(()=>{N(!1);const n=new URLSearchParams(window.location.search);n.delete("walletError");const s=n.toString(),o=`${window.location.pathname}${s?`?${s}`:""}`;window.history.replaceState({},"",o)},[]),ve=a.useCallback(()=>{N(!1);const n=new URLSearchParams(window.location.search);n.delete("walletError");const s=n.toString(),o=`${window.location.pathname}${s?`?${s}`:""}`;window.history.replaceState({},"",o),M(u.METAMASK)},[M]),Ae=a.useCallback(()=>{h(!1),f(""),p(void 0)},[]),Re=a.useCallback(()=>{h(!1),f(""),p(void 0)},[]),Pe=a.useCallback(async n=>{h(!1),B(!0),q(null);try{const s=n.address.toLowerCase(),o=await U();await D({ethAddress:s,type:V.WEB2});const w=I();await $()?await T(s,w,o,()=>B(!1)):B(!1)}catch(s){const o=v(s,"Error completing email login",{sentryTags:{connectionType:u.EMAIL}});q(o||t("login.errors.something_went_wrong"))}},[D,$,T,I,U,t]),We=a.useCallback(()=>{O(null)},[]),Ne=a.useCallback(()=>{B(!1),q(null),h(!0)},[]);ga({isReady:L,onConnect:M});const Be=a.useCallback(()=>{m&&M(m)},[m,M]),oe=a.useCallback(async()=>{if(j(!1),!m)return;const n=I();if(J(m)&&!window.ethereum){v(new Error("No wallet extension detected"),"Wallet extension not available for clock sync continue");return}try{const s=await me(m);await T(s.account??"",n,null,()=>l(!1))}catch(s){v(s,"Error during clock sync continue flow"),g(S.ERROR),l(!0)}},[m,T,I]);if(a.useEffect(()=>{const s=fe.length-1,o=setInterval(()=>{Le(w=>(ee(w),ne(!0),w>=s?0:w+1))},5e3);return()=>clearInterval(o)},[]),a.useEffect(()=>{if(!Z)return;const n=setTimeout(()=>{ee(H),ne(!1)},1e3);return()=>clearTimeout(n)},[Z,H]),!L)return e.jsx(we,{style:{display:"flex",justifyContent:"center",alignItems:"center"},children:e.jsx(ke,{size:80})});const re=fe;return e.jsxs(we,{children:[e.jsx($e,{children:e.jsxs(Zn,{children:[e.jsx(Ce,{isVisible:!0,style:{backgroundImage:`url(${re[_e]})`},"aria-hidden":!0}),e.jsx(Ce,{isVisible:Z,style:{backgroundImage:`url(${re[H]})`},"aria-hidden":!0})]})}),Se&&!x&&e.jsx(ka,{error:X,onError:X?Ne:void 0}),e.jsx(pa,{open:K,onTryAgain:ve,onClose:Oe}),e.jsx(ma,{open:x,onContinue:oe,onClose:oe}),e.jsx(Jn,{open:y,state:i,onClose:Me,onTryAgain:Be,providerType:m?Qn(m):null}),e.jsx(fa,{open:E,email:b,onClose:Ae,onBack:Re,onSuccess:Pe}),e.jsx(Xn,{children:e.jsxs(Yn,{children:[e.jsxs(ea,{children:[e.jsx(na,{onConnect:M,onEmailSubmit:Te,onEmailChange:We,loadingOption:m,connectionOptions:be.connectionOptions,isNewUser:r,signInOptionsMode:z,isEmailLoading:k,emailError:Ee}),r&&e.jsxs(aa,{children:[t("login.already_have_account")," ",e.jsx("span",{onClick:()=>c(!1),children:t("login.sign_in")})]})]}),je&&e.jsxs(ta,{children:[t("login.quick_dive")," ",e.jsx("a",{href:Y,onClick:Ie,children:t("login.explore_as_guest")})]})]})})]})};export{ba as LoginPage};
1
+ import{u as A,j as e,D as xe,C as pe,G as De,L as ie,b as ke,c as $e}from"./ui-WV8OFH8_.js";import{e as Fe,a}from"./vendor-0sbCgRYC.js";import{E as J,F as u,G as Ve,J as ze,K as Ke,M as qe,O as He,P as Ze,Q as Je,X as Qe,Y as Xe,Z as ye,_ as Ye,$ as en,a0 as nn,a1 as an,a2 as tn,a3 as sn,a4 as on,a5 as rn,a6 as ln,a7 as cn,a8 as dn,a9 as un,aa as gn,ab as hn,ac as mn,ad as wn,ae as Cn,af as fn,ag as xn,ah as pn,ai as kn,aj as yn,ak as En,al as Sn,am as jn,an as Ln,ao as _n,ap as bn,aq as In,ar as le,as as ce,at as de,au as ue,av as Tn,aw as Mn,ax as On,ay as S,az as vn,aA as An,aB as Rn,aC as Pn,aD as Wn,aE as Nn,aF as Bn,aG as Un,aH as Gn,aI as Dn,aJ as V,aK as $n,aL as Fn,aM as ge,aN as v,aO as Vn,aP as zn,aQ as Kn,aR as he,aS as me,aT as qn,aU as Hn,aV as we,aW as Zn,aX as Ce,aY as Jn,aZ as Qn,a_ as Xn,a$ as Yn,b0 as ea,b1 as na,b2 as aa,b3 as ta}from"./index-CfRwmSIm.js";import"./thirdweb-CT38Qh_V.js";const sa="https://cdn.decentraland.org/@dcl/auth-site/4.20.1-29269215567.commit-a168e3f/assets/image-new1-CpZnKbBW.webp",oa="https://cdn.decentraland.org/@dcl/auth-site/4.20.1-29269215567.commit-a168e3f/assets/image-new2-C5ihWkmR.webp",ra="https://cdn.decentraland.org/@dcl/auth-site/4.20.1-29269215567.commit-a168e3f/assets/image-new3-DJx27VUM.webp",ia="https://cdn.decentraland.org/@dcl/auth-site/4.20.1-29269215567.commit-a168e3f/assets/image-new4-Dx5Lwr3m.webp",la="https://cdn.decentraland.org/@dcl/auth-site/4.20.1-29269215567.commit-a168e3f/assets/image-new5-CzVG1QYp.webp",ca="https://cdn.decentraland.org/@dcl/auth-site/4.20.1-29269215567.commit-a168e3f/assets/image-new6-DgBpE6FO.webp",da=["email","metamask","google","discord","apple","x","fortmatic","coinbase","walletconnect"];function ua(t){switch(t){case"email":return u.EMAIL;case"metamask":return u.METAMASK;case"google":return u.GOOGLE;case"discord":return u.DISCORD;case"apple":return u.APPLE;case"x":return u.X;case"fortmatic":return u.FORTMATIC;case"coinbase":return u.COINBASE;case"walletconnect":return u.WALLET_CONNECT}}const ga=({isReady:t,onConnect:r})=>{var j;const[c]=Fe(),i=a.useRef(!1),g=(j=c.get("loginMethod"))==null?void 0:j.toLowerCase(),y=da.includes(g)?g:null,x=a.useCallback(()=>y?ua(y):null,[y])();return a.useEffect(()=>{if(!t||i.current||!x||J(x)&&!window.ethereum)return;const E=setTimeout(()=>{i.current=!0,r(x)},100);return()=>clearTimeout(E)},[t,x,r]),{loginMethod:y,autoLoginTriggered:i.current,resolvedConnectionOption:x}},ha=pe,ma=({open:t,onContinue:r,onClose:c})=>{const{t:i}=A();return e.jsxs(xe,{open:t,maxWidth:"xs",fullWidth:!0,children:[e.jsx(Ve,{onClick:c,"data-testid":"clock-sync-close-button",children:e.jsx(ha,{})}),e.jsxs(ze,{children:[e.jsx(Ke,{src:qe,alt:"warning"}),e.jsx(He,{children:i("clock_sync_modal.title")}),e.jsx(Ze,{children:i("clock_sync_modal.message")}),e.jsx(Je,{children:e.jsx(Qe,{variant:"contained",onClick:r,"data-testid":"clock-sync-continue-button",children:i("clock_sync_modal.continue_to_site")})})]})]})},wa=async t=>{await ye(t)},Ca=async(t,r)=>Xe(t,r),fa=t=>{const{open:r,email:c,onClose:i,onBack:g,onSuccess:y}=t,{t:l}=A(),x=a.useCallback(async(b,f)=>{const k=await Ca(b,f);return localStorage.setItem("dcl_thirdweb_user_email",b),{email:b,address:k}},[]),{otp:j,error:E,isLoading:h,hasError:m,otpInputRefs:p,handleOtpChange:R,handleOtpKeyDown:C,handleOtpPaste:P,handleResendOtp:L,isResendDisabled:_,resendText:W}=Ye({open:r,email:c,verify:x,resend:wa,onSuccess:y}),z=a.useCallback(()=>{h||i()},[h,i]),K=a.useCallback(()=>{h||g()},[h,g]),N=()=>e.jsxs(cn,{children:[e.jsx(dn,{children:e.jsx(un,{src:gn,alt:""})}),e.jsx(hn,{children:l("email_login_modal.title")}),e.jsxs(mn,{children:[l("email_login_modal.subtitle_prefix"),e.jsx("strong",{children:c}),l("email_login_modal.subtitle_suffix")]}),e.jsx(wn,{hasError:m,children:j.map((b,f)=>e.jsx(Cn,{"data-testid":`otp-input-${f}`,ref:k=>{p.current[f]=k},type:"text",inputMode:"numeric",maxLength:1,value:b,onChange:k=>R(f,k.target.value),onKeyDown:k=>C(f,k),onPaste:P,hasError:m,disabled:h,autoComplete:"one-time-code"},f))}),h&&!E&&e.jsxs(fn,{children:[e.jsx(xn,{size:16}),e.jsx(pn,{children:l("email_login_modal.verifying")})]}),E&&e.jsxs(e.Fragment,{children:[e.jsx(kn,{children:E}),e.jsx(yn,{disabled:_,onClick:_?void 0:L,children:W})]}),!E&&e.jsxs(En,{children:[l("email_login_modal.didnt_get_email"),e.jsx(Sn,{disabled:_,onClick:_?void 0:L,children:W})]})]});return e.jsxs(e.Fragment,{children:[r&&e.jsx(De,{styles:en}),e.jsxs(nn,{open:r,maxWidth:"sm",fullWidth:!0,className:an,children:[e.jsxs(tn,{children:[e.jsxs(sn,{onClick:K,disabled:h,"data-testid":"email-login-back-button",children:[e.jsx(on,{children:"‹"})," ",l("email_login_modal.back")]}),e.jsx(rn,{onClick:z,disabled:h,"data-testid":"email-login-close-button",children:"×"})]}),e.jsx(ln,{children:N()})]})]})},xa=pe,pa=({open:t,onTryAgain:r,onClose:c})=>{const{t:i}=A();return e.jsx(xe,{open:t,onClose:c,"aria-label":i("wallet_error_modal.title"),PaperProps:{sx:{background:"transparent",boxShadow:"none",overflow:"visible"}},slotProps:{backdrop:{sx:{backgroundColor:"rgba(0, 0, 0, 0.6)"}}},children:e.jsxs(jn,{children:[e.jsx(Ln,{onClick:c,"aria-label":i("common.close_window"),"data-testid":"wallet-error-close-button",children:e.jsx(xa,{sx:{fontSize:14}})}),e.jsx(_n,{children:e.jsxs("svg",{width:"30",height:"27",viewBox:"0 0 30 27",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M13.268 1.5C14.0378 0.166667 15.9623 0.166667 16.7321 1.5L28.8565 22.5C29.6263 23.8333 28.664 25.5 27.1244 25.5H2.87565C1.33605 25.5 0.373749 23.8333 1.14355 22.5L13.268 1.5Z",fill:"white",fillOpacity:"0",stroke:"white",strokeWidth:"2"}),e.jsx("path",{d:"M15 9V16",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round"}),e.jsx("circle",{cx:"15",cy:"20.5",r:"1.5",fill:"white"})]})}),e.jsx(bn,{children:i("wallet_error_modal.message")}),e.jsx(In,{variant:"contained",onClick:r,"data-testid":"wallet-error-try-again-button",children:i("wallet_error_modal.try_again")})]})})},ka=({error:t,onError:r})=>{const{t:c}=A();return t?e.jsxs(le,{children:[e.jsx(ce,{variant:"absolute"}),e.jsxs(de,{children:[e.jsx(ie,{size:"huge"}),e.jsx(ue,{children:c("common.something_went_wrong")}),e.jsx(Tn,{children:t}),r&&e.jsx(Mn,{onClick:r,"data-testid":"confirming-login-retry-button",children:c("common.try_again")})]})]}):e.jsxs(le,{children:[e.jsx(ce,{variant:"absolute"}),e.jsxs(de,{children:[e.jsx(ie,{size:"huge"}),e.jsx(ue,{children:c("login.confirming_login")}),e.jsx(On,{children:e.jsx(ke,{color:"inherit",size:40})})]})]})},fe=[sa,oa,ra,ia,la,ca],ya=["newUser","newuser","new-user","new_user"],ba=()=>{const{t}=A(),[r,c]=a.useState(ya.some(n=>new URLSearchParams(window.location.search).has(n))),[i,g]=a.useState(S.CONNECTING_WALLET),[y,l]=a.useState(!1),[x,j]=a.useState(!1),[E,h]=a.useState(!1),[m,p]=a.useState(),{redirect:R,redirectTo:C,skipSetup:P}=vn(),{initialized:L,flags:_,variants:W}=a.useContext(An),z=Rn(W),[K,N]=a.useState(()=>new URLSearchParams(window.location.search).get("walletError")==="rejected"),[b,f]=a.useState(""),[k,Q]=a.useState(!1),[Ee,O]=a.useState(null),[Se,B]=a.useState(!1),[X,q]=a.useState(null),Y=a.useMemo(()=>{if(!C)return"";try{const n=C.startsWith("/")?new URL(C,window.location.origin):new URL(C);return n.pathname.includes("/play")?(n.searchParams.append("guest","true"),n.toString()):""}catch{return""}},[C]),je=!!Y,[H,Le]=a.useState(0),[_e,ee]=a.useState(0),[Z,ne]=a.useState(!1),[be]=Pn(),{ensureProfile:ae}=Wn(),{identity:te,getIdentitySignature:U}=Nn(),{trackLoginClick:G,trackLoginSuccess:D,trackGuestLogin:se}=Bn(),Ie=a.useCallback(async()=>{await se()},[se]),I=a.useCallback(()=>{const n=new URLSearchParams(window.location.search);return Un(n)},[]),T=a.useCallback(async(n,s,o=null,w)=>{!P&&n&&!await ae(n,o??te,{redirectTo:C,referrer:s})||(Gn(n),R(),w==null||w())},[P,C,te,ae,R]),$=a.useCallback(async()=>await Dn()?!0:(l(!1),j(!0),!1),[]),Te=a.useCallback(async n=>{f(n),Q(!0),O(null),p(u.EMAIL),G({method:u.EMAIL,type:V.WEB2});try{await $n.disconnect(),await Fn()}catch{}ge({checkpointId:2,action:"reached",source:"auth",userIdentifier:n,identifierType:"email",email:n,metadata:{loginMethod:u.EMAIL}});try{await ye(n),h(!0)}catch(s){const o=v(s,"Error sending verification code");p(void 0),o==="Failed to fetch"||o!=null&&o.toLowerCase().includes("network")?O(t("login.errors.network_error")):o!=null&&o.toLowerCase().includes("invalid email")?O(t("login.errors.invalid_email")):O(o||t("login.errors.failed_send_code"))}finally{Q(!1)}},[G,t]),M=a.useCallback(async n=>{var w,F;if(!L)return;if(n===u.EMAIL){const d=document.getElementById("dcl-email-input");d&&(d.scrollIntoView({behavior:"smooth",block:"center"}),d.focus());return}const s=Vn(n),o=s?V.WEB2:V.WEB3;p(n),G({method:n,type:o});try{if(s)l(!0),g(S.LOADING_MAGIC),await zn(n,Kn(_[he.MAGIC_TEST]),C);else{if(J(n)&&!window.ethereum)throw new Error("No wallet extension detected. Please install MetaMask or another Ethereum wallet.");l(!0),g(S.CONNECTING_WALLET);const d=await me(n);ge({checkpointId:2,action:"reached",source:"auth",userIdentifier:((w=d.account)==null?void 0:w.toLowerCase())??"",identifierType:"wallet",wallet:(F=d.account)==null?void 0:F.toLowerCase(),metadata:{loginMethod:n}}),g(S.WAITING_FOR_SIGNATURE);const Ue=await U(d);localStorage.removeItem("dcl_thirdweb_user_email"),localStorage.removeItem("dcl_magic_user_email"),await D({ethAddress:d.account??void 0,type:o});const Ge=I();await $()&&await T(d.account??"",Ge,Ue,()=>l(!1))}}catch(d){qn(d)?console.info("User rejected login signature in wallet — not reporting to Sentry"):v(d,"Error during login connection",{sentryTags:{isWeb2Wallet:s,connectionType:n}}),Hn(d)&&d.name==="ErrorUnlockingWallet"?g(S.ERROR_LOCKED_WALLET):g(S.ERROR)}},[g,l,p,C,_[he.MAGIC_TEST],G,D,T,L,$,I,U]),Me=a.useCallback(()=>{l(!1),p(void 0),g(S.CONNECTING_WALLET)},[l]),Oe=a.useCallback(()=>{N(!1);const n=new URLSearchParams(window.location.search);n.delete("walletError");const s=n.toString(),o=`${window.location.pathname}${s?`?${s}`:""}`;window.history.replaceState({},"",o)},[]),ve=a.useCallback(()=>{N(!1);const n=new URLSearchParams(window.location.search);n.delete("walletError");const s=n.toString(),o=`${window.location.pathname}${s?`?${s}`:""}`;window.history.replaceState({},"",o),M(u.METAMASK)},[M]),Ae=a.useCallback(()=>{h(!1),f(""),p(void 0)},[]),Re=a.useCallback(()=>{h(!1),f(""),p(void 0)},[]),Pe=a.useCallback(async n=>{h(!1),B(!0),q(null);try{const s=n.address.toLowerCase(),o=await U();await D({ethAddress:s,type:V.WEB2});const w=I();await $()?await T(s,w,o,()=>B(!1)):B(!1)}catch(s){const o=v(s,"Error completing email login",{sentryTags:{connectionType:u.EMAIL}});q(o||t("login.errors.something_went_wrong"))}},[D,$,T,I,U,t]),We=a.useCallback(()=>{O(null)},[]),Ne=a.useCallback(()=>{B(!1),q(null),h(!0)},[]);ga({isReady:L,onConnect:M});const Be=a.useCallback(()=>{m&&M(m)},[m,M]),oe=a.useCallback(async()=>{if(j(!1),!m)return;const n=I();if(J(m)&&!window.ethereum){v(new Error("No wallet extension detected"),"Wallet extension not available for clock sync continue");return}try{const s=await me(m);await T(s.account??"",n,null,()=>l(!1))}catch(s){v(s,"Error during clock sync continue flow"),g(S.ERROR),l(!0)}},[m,T,I]);if(a.useEffect(()=>{const s=fe.length-1,o=setInterval(()=>{Le(w=>(ee(w),ne(!0),w>=s?0:w+1))},5e3);return()=>clearInterval(o)},[]),a.useEffect(()=>{if(!Z)return;const n=setTimeout(()=>{ee(H),ne(!1)},1e3);return()=>clearTimeout(n)},[Z,H]),!L)return e.jsx(we,{style:{display:"flex",justifyContent:"center",alignItems:"center"},children:e.jsx(ke,{size:80})});const re=fe;return e.jsxs(we,{children:[e.jsx($e,{children:e.jsxs(Zn,{children:[e.jsx(Ce,{isVisible:!0,style:{backgroundImage:`url(${re[_e]})`},"aria-hidden":!0}),e.jsx(Ce,{isVisible:Z,style:{backgroundImage:`url(${re[H]})`},"aria-hidden":!0})]})}),Se&&!x&&e.jsx(ka,{error:X,onError:X?Ne:void 0}),e.jsx(pa,{open:K,onTryAgain:ve,onClose:Oe}),e.jsx(ma,{open:x,onContinue:oe,onClose:oe}),e.jsx(Jn,{open:y,state:i,onClose:Me,onTryAgain:Be,providerType:m?Qn(m):null}),e.jsx(fa,{open:E,email:b,onClose:Ae,onBack:Re,onSuccess:Pe}),e.jsx(Xn,{children:e.jsxs(Yn,{children:[e.jsxs(ea,{children:[e.jsx(na,{onConnect:M,onEmailSubmit:Te,onEmailChange:We,loadingOption:m,connectionOptions:be.connectionOptions,isNewUser:r,signInOptionsMode:z,isEmailLoading:k,emailError:Ee}),r&&e.jsxs(aa,{children:[t("login.already_have_account")," ",e.jsx("span",{onClick:()=>c(!1),children:t("login.sign_in")})]})]}),je&&e.jsxs(ta,{children:[t("login.quick_dive")," ",e.jsx("a",{href:Y,onClick:Ie,children:t("login.explore_as_guest")})]})]})})]})};export{ba as LoginPage};
@@ -1 +1 @@
1
- import{p as N}from"./thirdweb-fDOh4yMb.js";var o={};const s={WC_NAME_SUFFIX:".reown.id",WC_NAME_SUFFIX_LEGACY:".wcn.id",BLOCKCHAIN_API_RPC_URL:"https://rpc.walletconnect.org",PULSE_API_URL:"https://pulse.walletconnect.org",W3M_API_URL:"https://api.web3modal.org",CONNECTOR_ID:{WALLET_CONNECT:"walletConnect",INJECTED:"injected",WALLET_STANDARD:"announced",COINBASE:"coinbaseWallet",COINBASE_SDK:"coinbaseWalletSDK",BASE_ACCOUNT:"baseAccount",SAFE:"safe",LEDGER:"ledger",OKX:"okx",EIP6963:"eip6963",AUTH:"AUTH"},CONNECTOR_NAMES:{AUTH:"Auth"},AUTH_CONNECTOR_SUPPORTED_CHAINS:["eip155","solana"],LIMITS:{PENDING_TRANSACTIONS:99},CHAIN:{EVM:"eip155",SOLANA:"solana",POLKADOT:"polkadot",BITCOIN:"bip122",TON:"ton",TRON:"tron"},CHAIN_NAME_MAP:{eip155:"EVM Networks",solana:"Solana",polkadot:"Polkadot",bip122:"Bitcoin",cosmos:"Cosmos",sui:"Sui",stacks:"Stacks",ton:"TON",tron:"TRON"},ADAPTER_TYPES:{BITCOIN:"bitcoin",SOLANA:"solana",WAGMI:"wagmi",ETHERS:"ethers",ETHERS5:"ethers5",TON:"ton",TRON:"tron"},USDT_CONTRACT_ADDRESSES:["0xdac17f958d2ee523a2206206994597c13d831ec7","0xc2132d05d31c914a87c6611c10748aeb04b58e8f","0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7","0x919C1c267BC06a7039e03fcc2eF738525769109c","0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e","0x55d398326f99059fF775485246999027B3197955","0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9"],SOLANA_SPL_TOKEN_ADDRESSES:{SOL:"So11111111111111111111111111111111111111112"},NATIVE_IMAGE_IDS_BY_NAMESPACE:{eip155:"ba0ba0cd-17c6-4806-ad93-f9d174f17900",solana:"3e8119e5-2a6f-4818-c50c-1937011d5900",bip122:"0b4838db-0161-4ffe-022d-532bf03dba00"},TOKEN_SYMBOLS_BY_ADDRESS:{"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48":"USDC","0x833589fcd6edb6e08f4c7c32d4f71b54bda02913":"USDC","0x0b2c639c533813f4aa9d7837caf62653d097ff85":"USDC","0xaf88d065e77c8cc2239327c5edb3a432268e5831":"USDC","0x3c499c542cef5e3811e1192ce70d8cc03d5c3359":"USDC","0x2791bca1f2de4661ed88a30c99a7a9449aa84174":"USDC",EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v:"USDC","0xdac17f958d2ee523a2206206994597c13d831ec7":"USDT","0x94b008aa00579c1307b0ef2c499ad98a8ce58e58":"USDT","0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9":"USDT","0xc2132d05d31c914a87c6611c10748aeb04b58e8f":"USDT",Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB:"USDT"},HTTP_STATUS_CODES:{SERVER_ERROR:500,TOO_MANY_REQUESTS:429,SERVICE_UNAVAILABLE:503,FORBIDDEN:403},UNSUPPORTED_NETWORK_NAME:"Unknown Network",SECURE_SITE_SDK_ORIGIN:(typeof N<"u"&&typeof o<"u"?o.NEXT_PUBLIC_SECURE_SITE_ORIGIN:void 0)||"https://secure.walletconnect.org",REMOTE_FEATURES_ALERTS:{MULTI_WALLET_NOT_ENABLED:{DEFAULT:{displayMessage:"Multi-Wallet Not Enabled",debugMessage:"Multi-wallet support is not enabled. Please enable it in your AppKit configuration at cloud.reown.com."},CONNECTIONS_HOOK:{displayMessage:"Multi-Wallet Not Enabled",debugMessage:"Multi-wallet support is not enabled. Please enable it in your AppKit configuration at cloud.reown.com to use the useAppKitConnections hook."},CONNECTION_HOOK:{displayMessage:"Multi-Wallet Not Enabled",debugMessage:"Multi-wallet support is not enabled. Please enable it in your AppKit configuration at cloud.reown.com to use the useAppKitConnection hook."}},HEADLESS_NOT_ENABLED:{DEFAULT:{displayMessage:"",debugMessage:"Headless support is not enabled. Please enable it with the features.headless option in the AppKit configuration and make sure your current plan supports it."}}},IS_DEVELOPMENT:typeof N<"u"&&!1,DEFAULT_ALLOWED_ANCESTORS:["http://localhost:*","https://localhost:*","http://127.0.0.1:*","https://127.0.0.1:*","https://*.pages.dev","https://*.vercel.app","https://*.ngrok-free.app","https://secure-mobile.walletconnect.com","https://secure-mobile.walletconnect.org"],METMASK_CONNECTOR_NAME:"MetaMask",TRUST_CONNECTOR_NAME:"Trust Wallet",SOLFLARE_CONNECTOR_NAME:"Solflare",PHANTOM_CONNECTOR_NAME:"Phantom",COIN98_CONNECTOR_NAME:"Coin98",MAGIC_EDEN_CONNECTOR_NAME:"Magic Eden",BACKPACK_CONNECTOR_NAME:"Backpack",BITGET_CONNECTOR_NAME:"Bitget Wallet",FRONTIER_CONNECTOR_NAME:"Frontier",XVERSE_CONNECTOR_NAME:"Xverse Wallet",LEATHER_CONNECTOR_NAME:"Leather",OKX_CONNECTOR_NAME:"OKX Wallet",BINANCE_CONNECTOR_NAME:"Binance Wallet",EIP155:"eip155",ADD_CHAIN_METHOD:"wallet_addEthereumChain",EIP6963_ANNOUNCE_EVENT:"eip6963:announceProvider",EIP6963_REQUEST_EVENT:"eip6963:requestProvider",CONNECTOR_RDNS_MAP:{coinbaseWallet:"com.coinbase.wallet",coinbaseWalletSDK:"com.coinbase.wallet"},CONNECTOR_TYPE_EXTERNAL:"EXTERNAL",CONNECTOR_TYPE_WALLET_CONNECT:"WALLET_CONNECT",CONNECTOR_TYPE_INJECTED:"INJECTED",CONNECTOR_TYPE_ANNOUNCED:"ANNOUNCED",CONNECTOR_TYPE_AUTH:"AUTH",CONNECTOR_TYPE_MULTI_CHAIN:"MULTI_CHAIN",CONNECTOR_TYPE_W3M_AUTH:"AUTH"},C={caipNetworkIdToNumber(e){return e?Number(e.split(":")[1]):void 0},parseEvmChainId(e){return typeof e=="string"?this.caipNetworkIdToNumber(e):e},getNetworksByNamespace(e,a){return(e==null?void 0:e.filter(E=>E.chainNamespace===a))||[]},getFirstNetworkByNamespace(e,a){return this.getNetworksByNamespace(e,a)[0]},getNetworkNameByCaipNetworkId(e,a){var t;if(!a)return;const E=e.find(_=>_.caipNetworkId===a);if(E)return E.name;const[c]=a.split(":");return((t=s.CHAIN_NAME_MAP)==null?void 0:t[c])||void 0}},n=["eip155","solana","polkadot","bip122","cosmos","sui","stacks"];export{n as A,s as C,C as N};
1
+ import{p as N}from"./thirdweb-CT38Qh_V.js";var o={};const s={WC_NAME_SUFFIX:".reown.id",WC_NAME_SUFFIX_LEGACY:".wcn.id",BLOCKCHAIN_API_RPC_URL:"https://rpc.walletconnect.org",PULSE_API_URL:"https://pulse.walletconnect.org",W3M_API_URL:"https://api.web3modal.org",CONNECTOR_ID:{WALLET_CONNECT:"walletConnect",INJECTED:"injected",WALLET_STANDARD:"announced",COINBASE:"coinbaseWallet",COINBASE_SDK:"coinbaseWalletSDK",BASE_ACCOUNT:"baseAccount",SAFE:"safe",LEDGER:"ledger",OKX:"okx",EIP6963:"eip6963",AUTH:"AUTH"},CONNECTOR_NAMES:{AUTH:"Auth"},AUTH_CONNECTOR_SUPPORTED_CHAINS:["eip155","solana"],LIMITS:{PENDING_TRANSACTIONS:99},CHAIN:{EVM:"eip155",SOLANA:"solana",POLKADOT:"polkadot",BITCOIN:"bip122",TON:"ton",TRON:"tron"},CHAIN_NAME_MAP:{eip155:"EVM Networks",solana:"Solana",polkadot:"Polkadot",bip122:"Bitcoin",cosmos:"Cosmos",sui:"Sui",stacks:"Stacks",ton:"TON",tron:"TRON"},ADAPTER_TYPES:{BITCOIN:"bitcoin",SOLANA:"solana",WAGMI:"wagmi",ETHERS:"ethers",ETHERS5:"ethers5",TON:"ton",TRON:"tron"},USDT_CONTRACT_ADDRESSES:["0xdac17f958d2ee523a2206206994597c13d831ec7","0xc2132d05d31c914a87c6611c10748aeb04b58e8f","0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7","0x919C1c267BC06a7039e03fcc2eF738525769109c","0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e","0x55d398326f99059fF775485246999027B3197955","0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9"],SOLANA_SPL_TOKEN_ADDRESSES:{SOL:"So11111111111111111111111111111111111111112"},NATIVE_IMAGE_IDS_BY_NAMESPACE:{eip155:"ba0ba0cd-17c6-4806-ad93-f9d174f17900",solana:"3e8119e5-2a6f-4818-c50c-1937011d5900",bip122:"0b4838db-0161-4ffe-022d-532bf03dba00"},TOKEN_SYMBOLS_BY_ADDRESS:{"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48":"USDC","0x833589fcd6edb6e08f4c7c32d4f71b54bda02913":"USDC","0x0b2c639c533813f4aa9d7837caf62653d097ff85":"USDC","0xaf88d065e77c8cc2239327c5edb3a432268e5831":"USDC","0x3c499c542cef5e3811e1192ce70d8cc03d5c3359":"USDC","0x2791bca1f2de4661ed88a30c99a7a9449aa84174":"USDC",EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v:"USDC","0xdac17f958d2ee523a2206206994597c13d831ec7":"USDT","0x94b008aa00579c1307b0ef2c499ad98a8ce58e58":"USDT","0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9":"USDT","0xc2132d05d31c914a87c6611c10748aeb04b58e8f":"USDT",Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB:"USDT"},HTTP_STATUS_CODES:{SERVER_ERROR:500,TOO_MANY_REQUESTS:429,SERVICE_UNAVAILABLE:503,FORBIDDEN:403},UNSUPPORTED_NETWORK_NAME:"Unknown Network",SECURE_SITE_SDK_ORIGIN:(typeof N<"u"&&typeof o<"u"?o.NEXT_PUBLIC_SECURE_SITE_ORIGIN:void 0)||"https://secure.walletconnect.org",REMOTE_FEATURES_ALERTS:{MULTI_WALLET_NOT_ENABLED:{DEFAULT:{displayMessage:"Multi-Wallet Not Enabled",debugMessage:"Multi-wallet support is not enabled. Please enable it in your AppKit configuration at cloud.reown.com."},CONNECTIONS_HOOK:{displayMessage:"Multi-Wallet Not Enabled",debugMessage:"Multi-wallet support is not enabled. Please enable it in your AppKit configuration at cloud.reown.com to use the useAppKitConnections hook."},CONNECTION_HOOK:{displayMessage:"Multi-Wallet Not Enabled",debugMessage:"Multi-wallet support is not enabled. Please enable it in your AppKit configuration at cloud.reown.com to use the useAppKitConnection hook."}},HEADLESS_NOT_ENABLED:{DEFAULT:{displayMessage:"",debugMessage:"Headless support is not enabled. Please enable it with the features.headless option in the AppKit configuration and make sure your current plan supports it."}}},IS_DEVELOPMENT:typeof N<"u"&&!1,DEFAULT_ALLOWED_ANCESTORS:["http://localhost:*","https://localhost:*","http://127.0.0.1:*","https://127.0.0.1:*","https://*.pages.dev","https://*.vercel.app","https://*.ngrok-free.app","https://secure-mobile.walletconnect.com","https://secure-mobile.walletconnect.org"],METMASK_CONNECTOR_NAME:"MetaMask",TRUST_CONNECTOR_NAME:"Trust Wallet",SOLFLARE_CONNECTOR_NAME:"Solflare",PHANTOM_CONNECTOR_NAME:"Phantom",COIN98_CONNECTOR_NAME:"Coin98",MAGIC_EDEN_CONNECTOR_NAME:"Magic Eden",BACKPACK_CONNECTOR_NAME:"Backpack",BITGET_CONNECTOR_NAME:"Bitget Wallet",FRONTIER_CONNECTOR_NAME:"Frontier",XVERSE_CONNECTOR_NAME:"Xverse Wallet",LEATHER_CONNECTOR_NAME:"Leather",OKX_CONNECTOR_NAME:"OKX Wallet",BINANCE_CONNECTOR_NAME:"Binance Wallet",EIP155:"eip155",ADD_CHAIN_METHOD:"wallet_addEthereumChain",EIP6963_ANNOUNCE_EVENT:"eip6963:announceProvider",EIP6963_REQUEST_EVENT:"eip6963:requestProvider",CONNECTOR_RDNS_MAP:{coinbaseWallet:"com.coinbase.wallet",coinbaseWalletSDK:"com.coinbase.wallet"},CONNECTOR_TYPE_EXTERNAL:"EXTERNAL",CONNECTOR_TYPE_WALLET_CONNECT:"WALLET_CONNECT",CONNECTOR_TYPE_INJECTED:"INJECTED",CONNECTOR_TYPE_ANNOUNCED:"ANNOUNCED",CONNECTOR_TYPE_AUTH:"AUTH",CONNECTOR_TYPE_MULTI_CHAIN:"MULTI_CHAIN",CONNECTOR_TYPE_W3M_AUTH:"AUTH"},C={caipNetworkIdToNumber(e){return e?Number(e.split(":")[1]):void 0},parseEvmChainId(e){return typeof e=="string"?this.caipNetworkIdToNumber(e):e},getNetworksByNamespace(e,a){return(e==null?void 0:e.filter(E=>E.chainNamespace===a))||[]},getFirstNetworkByNamespace(e,a){return this.getNetworksByNamespace(e,a)[0]},getNetworkNameByCaipNetworkId(e,a){var t;if(!a)return;const E=e.find(_=>_.caipNetworkId===a);if(E)return E.name;const[c]=a.split(":");return((t=s.CHAIN_NAME_MAP)==null?void 0:t[c])||void 0}},n=["eip155","solana","polkadot","bip122","cosmos","sui","stacks"];export{n as A,s as C,C as N};
@@ -1 +1 @@
1
- import{N as T,w as O,p as x,R as A,S as w,d as B,E as D,e as M,W as F,C as g,B as N,a as L,f as v,A as z,h as R,b as _,g as H,i as V,s as $,c as q}from"./W3MFrameProviderSingleton-BjLnTdbd.js";import{C as P}from"./NetworkUtil-CfnkiECb.js";const I={getGasPriceInEther(n,t){const o=t*n;return Number(o)/1e18},getGasPriceInUSD(n,t,o){const s=I.getGasPriceInEther(t,o);return T.bigNumber(n).times(s).toNumber()},getPriceImpact({sourceTokenAmount:n,sourceTokenPriceInUSD:t,toTokenPriceInUSD:o,toTokenAmount:s}){const c=T.bigNumber(n).times(t),r=T.bigNumber(s).times(o);return c.minus(r).div(c).times(100).toNumber()},getMaxSlippage(n,t){const o=T.bigNumber(n).div(100);return T.multiply(t,o).toNumber()},getProviderFee(n,t=.0085){return T.bigNumber(n).times(t).toString()},isInsufficientNetworkTokenForGas(n,t){const o=t||"0";return T.bigNumber(n).eq(0)?!0:T.bigNumber(T.bigNumber(o)).gt(n)},isInsufficientSourceTokenForSwap(n,t,o){var r,d;const s=(d=(r=o==null?void 0:o.find(l=>l.address===t))==null?void 0:r.quantity)==null?void 0:d.numeric;return T.bigNumber(s||"0").lt(n)}},G=15e4,Q=6,k={initializing:!1,initialized:!1,loadingPrices:!1,loadingQuote:!1,loadingApprovalTransaction:!1,loadingBuildTransaction:!1,loadingTransaction:!1,switchingTokens:!1,fetchError:!1,approvalTransaction:void 0,swapTransaction:void 0,transactionError:void 0,sourceToken:void 0,sourceTokenAmount:"",sourceTokenPriceInUSD:0,toToken:void 0,toTokenAmount:"",toTokenPriceInUSD:0,networkPrice:"0",networkBalanceInUSD:"0",networkTokenSymbol:"",inputError:void 0,slippage:_.CONVERT_SLIPPAGE_TOLERANCE,tokens:void 0,popularTokens:void 0,suggestedTokens:void 0,foundTokens:void 0,myTokensWithBalance:void 0,tokensPriceMap:{},gasFee:"0",gasPriceInUSD:0,priceImpact:void 0,maxSlippage:void 0,providerFee:void 0},e=x({...k}),E={state:e,subscribe(n){return q(e,()=>n(e))},subscribeKey(n,t){return $(e,n,t)},getParams(){var i,u,p,f,S,h,y,C,b;const n=g.state.activeChain,t=((i=g.getAccountData(n))==null?void 0:i.caipAddress)??g.state.activeCaipAddress,o=L.getPlainAddress(t),s=H(),c=V.getConnectorId(g.state.activeChain);if(!o)throw new Error("No address found to swap the tokens from.");const r=!((u=e.toToken)!=null&&u.address)||!((p=e.toToken)!=null&&p.decimals),d=!((f=e.sourceToken)!=null&&f.address)||!((S=e.sourceToken)!=null&&S.decimals)||!T.bigNumber(e.sourceTokenAmount).gt(0),l=!e.sourceTokenAmount;return{networkAddress:s,fromAddress:o,fromCaipAddress:t,sourceTokenAddress:(h=e.sourceToken)==null?void 0:h.address,toTokenAddress:(y=e.toToken)==null?void 0:y.address,toTokenAmount:e.toTokenAmount,toTokenDecimals:(C=e.toToken)==null?void 0:C.decimals,sourceTokenAmount:e.sourceTokenAmount,sourceTokenDecimals:(b=e.sourceToken)==null?void 0:b.decimals,invalidToToken:r,invalidSourceToken:d,invalidSourceTokenAmount:l,availableToSwap:t&&!r&&!d&&!l,isAuthConnector:c===P.CONNECTOR_ID.AUTH}},async setSourceToken(n){if(!n){e.sourceToken=n,e.sourceTokenAmount="",e.sourceTokenPriceInUSD=0;return}e.sourceToken=n,await a.setTokenPrice(n.address,"sourceToken")},setSourceTokenAmount(n){e.sourceTokenAmount=n},async setToToken(n){if(!n){e.toToken=n,e.toTokenAmount="",e.toTokenPriceInUSD=0;return}e.toToken=n,await a.setTokenPrice(n.address,"toToken")},setToTokenAmount(n){e.toTokenAmount=n?T.toFixed(n,Q):""},async setTokenPrice(n,t){let o=e.tokensPriceMap[n]||0;o||(e.loadingPrices=!0,o=await a.getAddressPrice(n)),t==="sourceToken"?e.sourceTokenPriceInUSD=o:t==="toToken"&&(e.toTokenPriceInUSD=o),e.loadingPrices&&(e.loadingPrices=!1),a.getParams().availableToSwap&&!e.switchingTokens&&a.swapTokens()},async switchTokens(){if(!(e.initializing||!e.initialized||e.switchingTokens)){e.switchingTokens=!0;try{const n=e.toToken?{...e.toToken}:void 0,t=e.sourceToken?{...e.sourceToken}:void 0,o=n&&e.toTokenAmount===""?"1":e.toTokenAmount;a.setSourceTokenAmount(o),a.setToTokenAmount(""),await a.setSourceToken(n),await a.setToToken(t),e.switchingTokens=!1,a.swapTokens()}catch(n){throw e.switchingTokens=!1,n}}},resetState(){e.myTokensWithBalance=k.myTokensWithBalance,e.tokensPriceMap=k.tokensPriceMap,e.initialized=k.initialized,e.initializing=k.initializing,e.switchingTokens=k.switchingTokens,e.sourceToken=k.sourceToken,e.sourceTokenAmount=k.sourceTokenAmount,e.sourceTokenPriceInUSD=k.sourceTokenPriceInUSD,e.toToken=k.toToken,e.toTokenAmount=k.toTokenAmount,e.toTokenPriceInUSD=k.toTokenPriceInUSD,e.networkPrice=k.networkPrice,e.networkTokenSymbol=k.networkTokenSymbol,e.networkBalanceInUSD=k.networkBalanceInUSD,e.inputError=k.inputError},resetValues(){var o;const{networkAddress:n}=a.getParams(),t=(o=e.tokens)==null?void 0:o.find(s=>s.address===n);a.setSourceToken(t),a.setToToken(void 0)},getApprovalLoadingState(){return e.loadingApprovalTransaction},clearError(){e.transactionError=void 0},async initializeState(){if(!e.initializing){if(e.initializing=!0,!e.initialized)try{await a.fetchTokens(),e.initialized=!0}catch{e.initialized=!1,w.showError("Failed to initialize swap"),A.goBack()}e.initializing=!1}},async fetchTokens(){var o;const{networkAddress:n}=a.getParams();await a.getNetworkTokenPrice(),await a.getMyTokensWithBalance();const t=(o=e.myTokensWithBalance)==null?void 0:o.find(s=>s.address===n);t&&(e.networkTokenSymbol=t.symbol,a.setSourceToken(t),a.setSourceTokenAmount("0"))},async getTokenList(){var t,o;const n=(t=g.state.activeCaipNetwork)==null?void 0:t.caipNetworkId;if(!(e.caipNetworkId===n&&e.tokens))try{e.tokensLoading=!0;const s=await v.getTokenList(n);e.tokens=s,e.caipNetworkId=n,e.popularTokens=s.sort((i,u)=>i.symbol<u.symbol?-1:i.symbol>u.symbol?1:0);const r=(n&&((o=_.SUGGESTED_TOKENS_BY_CHAIN)==null?void 0:o[n])||[]).map(i=>s.find(u=>u.symbol===i)).filter(i=>!!i),l=(_.SWAP_SUGGESTED_TOKENS||[]).map(i=>s.find(u=>u.symbol===i)).filter(i=>!!i).filter(i=>!r.some(u=>u.address===i.address));e.suggestedTokens=[...r,...l]}catch{e.tokens=[],e.popularTokens=[],e.suggestedTokens=[]}finally{e.tokensLoading=!1}},async getAddressPrice(n){var i,u;const t=e.tokensPriceMap[n];if(t)return t;const o=await N.fetchTokenPrice({addresses:[n]}),s=(o==null?void 0:o.fungibles)||[],c=[...e.tokens||[],...e.myTokensWithBalance||[]],r=(i=c==null?void 0:c.find(p=>p.address===n))==null?void 0:i.symbol,d=((u=s.find(p=>p.symbol.toLowerCase()===(r==null?void 0:r.toLowerCase())))==null?void 0:u.price)||0,l=parseFloat(d.toString());return e.tokensPriceMap[n]=l,l},async getNetworkTokenPrice(){var c;const{networkAddress:n}=a.getParams(),o=(c=(await N.fetchTokenPrice({addresses:[n]}).catch(()=>(w.showError("Failed to fetch network token price"),{fungibles:[]}))).fungibles)==null?void 0:c[0],s=(o==null?void 0:o.price.toString())||"0";e.tokensPriceMap[n]=parseFloat(s),e.networkTokenSymbol=(o==null?void 0:o.symbol)||"",e.networkPrice=s},async getMyTokensWithBalance(n){var s;const t=await R.getMyTokensWithBalance({forceUpdate:n,caipNetwork:g.state.activeCaipNetwork,address:(s=g.getAccountData())==null?void 0:s.address}),o=v.mapBalancesToSwapTokens(t);o&&(await a.getInitialGasPrice(),a.setBalances(o))},setBalances(n){const{networkAddress:t}=a.getParams(),o=g.state.activeCaipNetwork;if(!o)return;const s=n.find(c=>c.address===t);n.forEach(c=>{e.tokensPriceMap[c.address]=c.price||0}),e.myTokensWithBalance=n.filter(c=>c.address.startsWith(o.caipNetworkId)),e.networkBalanceInUSD=s?T.multiply(s.quantity.numeric,s.price).toString():"0"},async getInitialGasPrice(){var t,o;const n=await v.fetchGasPrice();if(!n)return{gasPrice:null,gasPriceInUSD:null};switch((o=(t=g.state)==null?void 0:t.activeCaipNetwork)==null?void 0:o.chainNamespace){case P.CHAIN.SOLANA:return e.gasFee=n.standard??"0",e.gasPriceInUSD=T.multiply(n.standard,e.networkPrice).div(1e9).toNumber(),{gasPrice:BigInt(e.gasFee),gasPriceInUSD:Number(e.gasPriceInUSD)};case P.CHAIN.EVM:default:const s=n.standard??"0",c=BigInt(s),r=BigInt(G),d=I.getGasPriceInUSD(e.networkPrice,r,c);return e.gasFee=s,e.gasPriceInUSD=d,{gasPrice:c,gasPriceInUSD:d}}},async swapTokens(){var r,d,l;const n=(r=g.getAccountData())==null?void 0:r.address,t=e.sourceToken,o=e.toToken,s=T.bigNumber(e.sourceTokenAmount).gt(0);if(s||a.setToTokenAmount(""),!o||!t||e.loadingPrices||!s||!n)return;e.loadingQuote=!0;const c=T.bigNumber(e.sourceTokenAmount).times(10**t.decimals).round(0).toFixed(0);try{const i=await N.fetchSwapQuote({userAddress:n,from:t.address,to:o.address,gasPrice:e.gasFee,amount:c.toString()});e.loadingQuote=!1;const u=(l=(d=i==null?void 0:i.quotes)==null?void 0:d[0])==null?void 0:l.toAmount;if(!u){z.open({displayMessage:"Incorrect amount",debugMessage:"Please enter a valid amount"},"error");return}const p=T.bigNumber(u).div(10**o.decimals).toString();a.setToTokenAmount(p),a.hasInsufficientToken(e.sourceTokenAmount,t.address)?e.inputError="Insufficient balance":(e.inputError=void 0,a.setTransactionDetails())}catch(i){const u=await v.handleSwapError(i);e.loadingQuote=!1,e.inputError=u||"Insufficient balance"}},async getTransaction(){const{fromCaipAddress:n,availableToSwap:t}=a.getParams(),o=e.sourceToken,s=e.toToken;if(!(!n||!t||!o||!s||e.loadingQuote))try{e.loadingBuildTransaction=!0;const c=await v.fetchSwapAllowance({userAddress:n,tokenAddress:o.address,sourceTokenAmount:e.sourceTokenAmount,sourceTokenDecimals:o.decimals});let r;return c?r=await a.createSwapTransaction():r=await a.createAllowanceTransaction(),e.loadingBuildTransaction=!1,e.fetchError=!1,r}catch{A.goBack(),w.showError("Failed to check allowance"),e.loadingBuildTransaction=!1,e.approvalTransaction=void 0,e.swapTransaction=void 0,e.fetchError=!0;return}},async createAllowanceTransaction(){const{fromCaipAddress:n,sourceTokenAddress:t,toTokenAddress:o}=a.getParams();if(!(!n||!o)){if(!t)throw new Error("createAllowanceTransaction - No source token address found.");try{const s=await N.generateApproveCalldata({from:t,to:o,userAddress:n}),c=L.getPlainAddress(s.tx.from);if(!c)throw new Error("SwapController:createAllowanceTransaction - address is required");const r={data:s.tx.data,to:c,gasPrice:BigInt(s.tx.eip155.gasPrice),value:BigInt(s.tx.value),toAmount:e.toTokenAmount};return e.swapTransaction=void 0,e.approvalTransaction={data:r.data,to:r.to,gasPrice:r.gasPrice,value:r.value,toAmount:r.toAmount},{data:r.data,to:r.to,gasPrice:r.gasPrice,value:r.value,toAmount:r.toAmount}}catch{A.goBack(),w.showError("Failed to create approval transaction"),e.approvalTransaction=void 0,e.swapTransaction=void 0,e.fetchError=!0;return}}},async createSwapTransaction(){var d;const{networkAddress:n,fromCaipAddress:t,sourceTokenAmount:o}=a.getParams(),s=e.sourceToken,c=e.toToken;if(!t||!o||!s||!c)return;const r=(d=B.parseUnits(o,s.decimals))==null?void 0:d.toString();try{const l=await N.generateSwapCalldata({userAddress:t,from:s.address,to:c.address,amount:r,disableEstimate:!0}),i=s.address===n,u=BigInt(l.tx.eip155.gas),p=BigInt(l.tx.eip155.gasPrice),f=L.getPlainAddress(l.tx.to);if(!f)throw new Error("SwapController:createSwapTransaction - address is required");const S={data:l.tx.data,to:f,gas:u,gasPrice:p,value:BigInt(i?r??"0":"0"),toAmount:e.toTokenAmount};return e.gasPriceInUSD=I.getGasPriceInUSD(e.networkPrice,u,p),e.approvalTransaction=void 0,e.swapTransaction=S,S}catch{A.goBack(),w.showError("Failed to create transaction"),e.approvalTransaction=void 0,e.swapTransaction=void 0,e.fetchError=!0;return}},onEmbeddedWalletApprovalSuccess(){w.showLoading("Approve limit increase in your wallet"),A.replace("SwapPreview")},async sendTransactionForApproval(n){var c,r,d;const{fromAddress:t,isAuthConnector:o}=a.getParams();e.loadingApprovalTransaction=!0,o?A.pushTransactionStack({onSuccess:a.onEmbeddedWalletApprovalSuccess}):w.showLoading("Approve limit increase in your wallet");try{await B.sendTransaction({address:t,to:n.to,data:n.data,value:n.value,chainNamespace:P.CHAIN.EVM}),await a.swapTokens(),await a.getTransaction(),e.approvalTransaction=void 0,e.loadingApprovalTransaction=!1}catch(l){const i=l;e.transactionError=i==null?void 0:i.displayMessage,e.loadingApprovalTransaction=!1,w.showError((i==null?void 0:i.displayMessage)||"Transaction error"),D.sendEvent({type:"track",event:"SWAP_APPROVAL_ERROR",properties:{message:(i==null?void 0:i.displayMessage)||(i==null?void 0:i.message)||"Unknown",network:((c=g.state.activeCaipNetwork)==null?void 0:c.caipNetworkId)||"",swapFromToken:((r=a.state.sourceToken)==null?void 0:r.symbol)||"",swapToToken:((d=a.state.toToken)==null?void 0:d.symbol)||"",swapFromAmount:a.state.sourceTokenAmount||"",swapToAmount:a.state.toTokenAmount||"",isSmartAccount:M(P.CHAIN.EVM)===F.ACCOUNT_TYPES.SMART_ACCOUNT}})}},async sendTransactionForSwap(n){var d,l,i,u,p,f,S,h,y,C,b,W;if(!n)return;const{fromAddress:t,toTokenAmount:o,isAuthConnector:s}=a.getParams();e.loadingTransaction=!0;const c=`Swapping ${(d=e.sourceToken)==null?void 0:d.symbol} to ${T.formatNumberToLocalString(o,3)} ${(l=e.toToken)==null?void 0:l.symbol}`,r=`Swapped ${(i=e.sourceToken)==null?void 0:i.symbol} to ${T.formatNumberToLocalString(o,3)} ${(u=e.toToken)==null?void 0:u.symbol}`;s?A.pushTransactionStack({onSuccess(){A.replace("Account"),w.showLoading(c),E.resetState()}}):w.showLoading("Confirm transaction in your wallet");try{const U=[(p=e.sourceToken)==null?void 0:p.address,(f=e.toToken)==null?void 0:f.address].join(","),m=await B.sendTransaction({address:t,to:n.to,data:n.data,value:n.value,chainNamespace:P.CHAIN.EVM});return e.loadingTransaction=!1,w.showSuccess(r),D.sendEvent({type:"track",event:"SWAP_SUCCESS",properties:{network:((S=g.state.activeCaipNetwork)==null?void 0:S.caipNetworkId)||"",swapFromToken:((h=a.state.sourceToken)==null?void 0:h.symbol)||"",swapToToken:((y=a.state.toToken)==null?void 0:y.symbol)||"",swapFromAmount:a.state.sourceTokenAmount||"",swapToAmount:a.state.toTokenAmount||"",isSmartAccount:M(P.CHAIN.EVM)===F.ACCOUNT_TYPES.SMART_ACCOUNT}}),E.resetState(),s||A.replace("Account"),E.getMyTokensWithBalance(U),m}catch(U){const m=U;e.transactionError=m==null?void 0:m.displayMessage,e.loadingTransaction=!1,w.showError((m==null?void 0:m.displayMessage)||"Transaction error"),D.sendEvent({type:"track",event:"SWAP_ERROR",properties:{message:(m==null?void 0:m.displayMessage)||(m==null?void 0:m.message)||"Unknown",network:((C=g.state.activeCaipNetwork)==null?void 0:C.caipNetworkId)||"",swapFromToken:((b=a.state.sourceToken)==null?void 0:b.symbol)||"",swapToToken:((W=a.state.toToken)==null?void 0:W.symbol)||"",swapFromAmount:a.state.sourceTokenAmount||"",swapToAmount:a.state.toTokenAmount||"",isSmartAccount:M(P.CHAIN.EVM)===F.ACCOUNT_TYPES.SMART_ACCOUNT}});return}},hasInsufficientToken(n,t){return I.isInsufficientSourceTokenForSwap(n,t,e.myTokensWithBalance)},setTransactionDetails(){const{toTokenAddress:n,toTokenDecimals:t}=a.getParams();!n||!t||(e.gasPriceInUSD=I.getGasPriceInUSD(e.networkPrice,BigInt(e.gasFee),BigInt(G)),e.priceImpact=I.getPriceImpact({sourceTokenAmount:e.sourceTokenAmount,sourceTokenPriceInUSD:e.sourceTokenPriceInUSD,toTokenPriceInUSD:e.toTokenPriceInUSD,toTokenAmount:e.toTokenAmount}),e.maxSlippage=I.getMaxSlippage(e.slippage,e.toTokenAmount),e.providerFee=I.getProviderFee(e.sourceTokenAmount))}},a=O(E);export{a as S};
1
+ import{N as T,w as O,p as x,R as A,S as w,d as B,E as D,e as M,W as F,C as g,B as N,a as L,f as v,A as z,h as R,b as _,g as H,i as V,s as $,c as q}from"./W3MFrameProviderSingleton-Ch6ChvE7.js";import{C as P}from"./NetworkUtil-BcejqRTW.js";const I={getGasPriceInEther(n,t){const o=t*n;return Number(o)/1e18},getGasPriceInUSD(n,t,o){const s=I.getGasPriceInEther(t,o);return T.bigNumber(n).times(s).toNumber()},getPriceImpact({sourceTokenAmount:n,sourceTokenPriceInUSD:t,toTokenPriceInUSD:o,toTokenAmount:s}){const c=T.bigNumber(n).times(t),r=T.bigNumber(s).times(o);return c.minus(r).div(c).times(100).toNumber()},getMaxSlippage(n,t){const o=T.bigNumber(n).div(100);return T.multiply(t,o).toNumber()},getProviderFee(n,t=.0085){return T.bigNumber(n).times(t).toString()},isInsufficientNetworkTokenForGas(n,t){const o=t||"0";return T.bigNumber(n).eq(0)?!0:T.bigNumber(T.bigNumber(o)).gt(n)},isInsufficientSourceTokenForSwap(n,t,o){var r,d;const s=(d=(r=o==null?void 0:o.find(l=>l.address===t))==null?void 0:r.quantity)==null?void 0:d.numeric;return T.bigNumber(s||"0").lt(n)}},G=15e4,Q=6,k={initializing:!1,initialized:!1,loadingPrices:!1,loadingQuote:!1,loadingApprovalTransaction:!1,loadingBuildTransaction:!1,loadingTransaction:!1,switchingTokens:!1,fetchError:!1,approvalTransaction:void 0,swapTransaction:void 0,transactionError:void 0,sourceToken:void 0,sourceTokenAmount:"",sourceTokenPriceInUSD:0,toToken:void 0,toTokenAmount:"",toTokenPriceInUSD:0,networkPrice:"0",networkBalanceInUSD:"0",networkTokenSymbol:"",inputError:void 0,slippage:_.CONVERT_SLIPPAGE_TOLERANCE,tokens:void 0,popularTokens:void 0,suggestedTokens:void 0,foundTokens:void 0,myTokensWithBalance:void 0,tokensPriceMap:{},gasFee:"0",gasPriceInUSD:0,priceImpact:void 0,maxSlippage:void 0,providerFee:void 0},e=x({...k}),E={state:e,subscribe(n){return q(e,()=>n(e))},subscribeKey(n,t){return $(e,n,t)},getParams(){var i,u,p,f,S,h,y,C,b;const n=g.state.activeChain,t=((i=g.getAccountData(n))==null?void 0:i.caipAddress)??g.state.activeCaipAddress,o=L.getPlainAddress(t),s=H(),c=V.getConnectorId(g.state.activeChain);if(!o)throw new Error("No address found to swap the tokens from.");const r=!((u=e.toToken)!=null&&u.address)||!((p=e.toToken)!=null&&p.decimals),d=!((f=e.sourceToken)!=null&&f.address)||!((S=e.sourceToken)!=null&&S.decimals)||!T.bigNumber(e.sourceTokenAmount).gt(0),l=!e.sourceTokenAmount;return{networkAddress:s,fromAddress:o,fromCaipAddress:t,sourceTokenAddress:(h=e.sourceToken)==null?void 0:h.address,toTokenAddress:(y=e.toToken)==null?void 0:y.address,toTokenAmount:e.toTokenAmount,toTokenDecimals:(C=e.toToken)==null?void 0:C.decimals,sourceTokenAmount:e.sourceTokenAmount,sourceTokenDecimals:(b=e.sourceToken)==null?void 0:b.decimals,invalidToToken:r,invalidSourceToken:d,invalidSourceTokenAmount:l,availableToSwap:t&&!r&&!d&&!l,isAuthConnector:c===P.CONNECTOR_ID.AUTH}},async setSourceToken(n){if(!n){e.sourceToken=n,e.sourceTokenAmount="",e.sourceTokenPriceInUSD=0;return}e.sourceToken=n,await a.setTokenPrice(n.address,"sourceToken")},setSourceTokenAmount(n){e.sourceTokenAmount=n},async setToToken(n){if(!n){e.toToken=n,e.toTokenAmount="",e.toTokenPriceInUSD=0;return}e.toToken=n,await a.setTokenPrice(n.address,"toToken")},setToTokenAmount(n){e.toTokenAmount=n?T.toFixed(n,Q):""},async setTokenPrice(n,t){let o=e.tokensPriceMap[n]||0;o||(e.loadingPrices=!0,o=await a.getAddressPrice(n)),t==="sourceToken"?e.sourceTokenPriceInUSD=o:t==="toToken"&&(e.toTokenPriceInUSD=o),e.loadingPrices&&(e.loadingPrices=!1),a.getParams().availableToSwap&&!e.switchingTokens&&a.swapTokens()},async switchTokens(){if(!(e.initializing||!e.initialized||e.switchingTokens)){e.switchingTokens=!0;try{const n=e.toToken?{...e.toToken}:void 0,t=e.sourceToken?{...e.sourceToken}:void 0,o=n&&e.toTokenAmount===""?"1":e.toTokenAmount;a.setSourceTokenAmount(o),a.setToTokenAmount(""),await a.setSourceToken(n),await a.setToToken(t),e.switchingTokens=!1,a.swapTokens()}catch(n){throw e.switchingTokens=!1,n}}},resetState(){e.myTokensWithBalance=k.myTokensWithBalance,e.tokensPriceMap=k.tokensPriceMap,e.initialized=k.initialized,e.initializing=k.initializing,e.switchingTokens=k.switchingTokens,e.sourceToken=k.sourceToken,e.sourceTokenAmount=k.sourceTokenAmount,e.sourceTokenPriceInUSD=k.sourceTokenPriceInUSD,e.toToken=k.toToken,e.toTokenAmount=k.toTokenAmount,e.toTokenPriceInUSD=k.toTokenPriceInUSD,e.networkPrice=k.networkPrice,e.networkTokenSymbol=k.networkTokenSymbol,e.networkBalanceInUSD=k.networkBalanceInUSD,e.inputError=k.inputError},resetValues(){var o;const{networkAddress:n}=a.getParams(),t=(o=e.tokens)==null?void 0:o.find(s=>s.address===n);a.setSourceToken(t),a.setToToken(void 0)},getApprovalLoadingState(){return e.loadingApprovalTransaction},clearError(){e.transactionError=void 0},async initializeState(){if(!e.initializing){if(e.initializing=!0,!e.initialized)try{await a.fetchTokens(),e.initialized=!0}catch{e.initialized=!1,w.showError("Failed to initialize swap"),A.goBack()}e.initializing=!1}},async fetchTokens(){var o;const{networkAddress:n}=a.getParams();await a.getNetworkTokenPrice(),await a.getMyTokensWithBalance();const t=(o=e.myTokensWithBalance)==null?void 0:o.find(s=>s.address===n);t&&(e.networkTokenSymbol=t.symbol,a.setSourceToken(t),a.setSourceTokenAmount("0"))},async getTokenList(){var t,o;const n=(t=g.state.activeCaipNetwork)==null?void 0:t.caipNetworkId;if(!(e.caipNetworkId===n&&e.tokens))try{e.tokensLoading=!0;const s=await v.getTokenList(n);e.tokens=s,e.caipNetworkId=n,e.popularTokens=s.sort((i,u)=>i.symbol<u.symbol?-1:i.symbol>u.symbol?1:0);const r=(n&&((o=_.SUGGESTED_TOKENS_BY_CHAIN)==null?void 0:o[n])||[]).map(i=>s.find(u=>u.symbol===i)).filter(i=>!!i),l=(_.SWAP_SUGGESTED_TOKENS||[]).map(i=>s.find(u=>u.symbol===i)).filter(i=>!!i).filter(i=>!r.some(u=>u.address===i.address));e.suggestedTokens=[...r,...l]}catch{e.tokens=[],e.popularTokens=[],e.suggestedTokens=[]}finally{e.tokensLoading=!1}},async getAddressPrice(n){var i,u;const t=e.tokensPriceMap[n];if(t)return t;const o=await N.fetchTokenPrice({addresses:[n]}),s=(o==null?void 0:o.fungibles)||[],c=[...e.tokens||[],...e.myTokensWithBalance||[]],r=(i=c==null?void 0:c.find(p=>p.address===n))==null?void 0:i.symbol,d=((u=s.find(p=>p.symbol.toLowerCase()===(r==null?void 0:r.toLowerCase())))==null?void 0:u.price)||0,l=parseFloat(d.toString());return e.tokensPriceMap[n]=l,l},async getNetworkTokenPrice(){var c;const{networkAddress:n}=a.getParams(),o=(c=(await N.fetchTokenPrice({addresses:[n]}).catch(()=>(w.showError("Failed to fetch network token price"),{fungibles:[]}))).fungibles)==null?void 0:c[0],s=(o==null?void 0:o.price.toString())||"0";e.tokensPriceMap[n]=parseFloat(s),e.networkTokenSymbol=(o==null?void 0:o.symbol)||"",e.networkPrice=s},async getMyTokensWithBalance(n){var s;const t=await R.getMyTokensWithBalance({forceUpdate:n,caipNetwork:g.state.activeCaipNetwork,address:(s=g.getAccountData())==null?void 0:s.address}),o=v.mapBalancesToSwapTokens(t);o&&(await a.getInitialGasPrice(),a.setBalances(o))},setBalances(n){const{networkAddress:t}=a.getParams(),o=g.state.activeCaipNetwork;if(!o)return;const s=n.find(c=>c.address===t);n.forEach(c=>{e.tokensPriceMap[c.address]=c.price||0}),e.myTokensWithBalance=n.filter(c=>c.address.startsWith(o.caipNetworkId)),e.networkBalanceInUSD=s?T.multiply(s.quantity.numeric,s.price).toString():"0"},async getInitialGasPrice(){var t,o;const n=await v.fetchGasPrice();if(!n)return{gasPrice:null,gasPriceInUSD:null};switch((o=(t=g.state)==null?void 0:t.activeCaipNetwork)==null?void 0:o.chainNamespace){case P.CHAIN.SOLANA:return e.gasFee=n.standard??"0",e.gasPriceInUSD=T.multiply(n.standard,e.networkPrice).div(1e9).toNumber(),{gasPrice:BigInt(e.gasFee),gasPriceInUSD:Number(e.gasPriceInUSD)};case P.CHAIN.EVM:default:const s=n.standard??"0",c=BigInt(s),r=BigInt(G),d=I.getGasPriceInUSD(e.networkPrice,r,c);return e.gasFee=s,e.gasPriceInUSD=d,{gasPrice:c,gasPriceInUSD:d}}},async swapTokens(){var r,d,l;const n=(r=g.getAccountData())==null?void 0:r.address,t=e.sourceToken,o=e.toToken,s=T.bigNumber(e.sourceTokenAmount).gt(0);if(s||a.setToTokenAmount(""),!o||!t||e.loadingPrices||!s||!n)return;e.loadingQuote=!0;const c=T.bigNumber(e.sourceTokenAmount).times(10**t.decimals).round(0).toFixed(0);try{const i=await N.fetchSwapQuote({userAddress:n,from:t.address,to:o.address,gasPrice:e.gasFee,amount:c.toString()});e.loadingQuote=!1;const u=(l=(d=i==null?void 0:i.quotes)==null?void 0:d[0])==null?void 0:l.toAmount;if(!u){z.open({displayMessage:"Incorrect amount",debugMessage:"Please enter a valid amount"},"error");return}const p=T.bigNumber(u).div(10**o.decimals).toString();a.setToTokenAmount(p),a.hasInsufficientToken(e.sourceTokenAmount,t.address)?e.inputError="Insufficient balance":(e.inputError=void 0,a.setTransactionDetails())}catch(i){const u=await v.handleSwapError(i);e.loadingQuote=!1,e.inputError=u||"Insufficient balance"}},async getTransaction(){const{fromCaipAddress:n,availableToSwap:t}=a.getParams(),o=e.sourceToken,s=e.toToken;if(!(!n||!t||!o||!s||e.loadingQuote))try{e.loadingBuildTransaction=!0;const c=await v.fetchSwapAllowance({userAddress:n,tokenAddress:o.address,sourceTokenAmount:e.sourceTokenAmount,sourceTokenDecimals:o.decimals});let r;return c?r=await a.createSwapTransaction():r=await a.createAllowanceTransaction(),e.loadingBuildTransaction=!1,e.fetchError=!1,r}catch{A.goBack(),w.showError("Failed to check allowance"),e.loadingBuildTransaction=!1,e.approvalTransaction=void 0,e.swapTransaction=void 0,e.fetchError=!0;return}},async createAllowanceTransaction(){const{fromCaipAddress:n,sourceTokenAddress:t,toTokenAddress:o}=a.getParams();if(!(!n||!o)){if(!t)throw new Error("createAllowanceTransaction - No source token address found.");try{const s=await N.generateApproveCalldata({from:t,to:o,userAddress:n}),c=L.getPlainAddress(s.tx.from);if(!c)throw new Error("SwapController:createAllowanceTransaction - address is required");const r={data:s.tx.data,to:c,gasPrice:BigInt(s.tx.eip155.gasPrice),value:BigInt(s.tx.value),toAmount:e.toTokenAmount};return e.swapTransaction=void 0,e.approvalTransaction={data:r.data,to:r.to,gasPrice:r.gasPrice,value:r.value,toAmount:r.toAmount},{data:r.data,to:r.to,gasPrice:r.gasPrice,value:r.value,toAmount:r.toAmount}}catch{A.goBack(),w.showError("Failed to create approval transaction"),e.approvalTransaction=void 0,e.swapTransaction=void 0,e.fetchError=!0;return}}},async createSwapTransaction(){var d;const{networkAddress:n,fromCaipAddress:t,sourceTokenAmount:o}=a.getParams(),s=e.sourceToken,c=e.toToken;if(!t||!o||!s||!c)return;const r=(d=B.parseUnits(o,s.decimals))==null?void 0:d.toString();try{const l=await N.generateSwapCalldata({userAddress:t,from:s.address,to:c.address,amount:r,disableEstimate:!0}),i=s.address===n,u=BigInt(l.tx.eip155.gas),p=BigInt(l.tx.eip155.gasPrice),f=L.getPlainAddress(l.tx.to);if(!f)throw new Error("SwapController:createSwapTransaction - address is required");const S={data:l.tx.data,to:f,gas:u,gasPrice:p,value:BigInt(i?r??"0":"0"),toAmount:e.toTokenAmount};return e.gasPriceInUSD=I.getGasPriceInUSD(e.networkPrice,u,p),e.approvalTransaction=void 0,e.swapTransaction=S,S}catch{A.goBack(),w.showError("Failed to create transaction"),e.approvalTransaction=void 0,e.swapTransaction=void 0,e.fetchError=!0;return}},onEmbeddedWalletApprovalSuccess(){w.showLoading("Approve limit increase in your wallet"),A.replace("SwapPreview")},async sendTransactionForApproval(n){var c,r,d;const{fromAddress:t,isAuthConnector:o}=a.getParams();e.loadingApprovalTransaction=!0,o?A.pushTransactionStack({onSuccess:a.onEmbeddedWalletApprovalSuccess}):w.showLoading("Approve limit increase in your wallet");try{await B.sendTransaction({address:t,to:n.to,data:n.data,value:n.value,chainNamespace:P.CHAIN.EVM}),await a.swapTokens(),await a.getTransaction(),e.approvalTransaction=void 0,e.loadingApprovalTransaction=!1}catch(l){const i=l;e.transactionError=i==null?void 0:i.displayMessage,e.loadingApprovalTransaction=!1,w.showError((i==null?void 0:i.displayMessage)||"Transaction error"),D.sendEvent({type:"track",event:"SWAP_APPROVAL_ERROR",properties:{message:(i==null?void 0:i.displayMessage)||(i==null?void 0:i.message)||"Unknown",network:((c=g.state.activeCaipNetwork)==null?void 0:c.caipNetworkId)||"",swapFromToken:((r=a.state.sourceToken)==null?void 0:r.symbol)||"",swapToToken:((d=a.state.toToken)==null?void 0:d.symbol)||"",swapFromAmount:a.state.sourceTokenAmount||"",swapToAmount:a.state.toTokenAmount||"",isSmartAccount:M(P.CHAIN.EVM)===F.ACCOUNT_TYPES.SMART_ACCOUNT}})}},async sendTransactionForSwap(n){var d,l,i,u,p,f,S,h,y,C,b,W;if(!n)return;const{fromAddress:t,toTokenAmount:o,isAuthConnector:s}=a.getParams();e.loadingTransaction=!0;const c=`Swapping ${(d=e.sourceToken)==null?void 0:d.symbol} to ${T.formatNumberToLocalString(o,3)} ${(l=e.toToken)==null?void 0:l.symbol}`,r=`Swapped ${(i=e.sourceToken)==null?void 0:i.symbol} to ${T.formatNumberToLocalString(o,3)} ${(u=e.toToken)==null?void 0:u.symbol}`;s?A.pushTransactionStack({onSuccess(){A.replace("Account"),w.showLoading(c),E.resetState()}}):w.showLoading("Confirm transaction in your wallet");try{const U=[(p=e.sourceToken)==null?void 0:p.address,(f=e.toToken)==null?void 0:f.address].join(","),m=await B.sendTransaction({address:t,to:n.to,data:n.data,value:n.value,chainNamespace:P.CHAIN.EVM});return e.loadingTransaction=!1,w.showSuccess(r),D.sendEvent({type:"track",event:"SWAP_SUCCESS",properties:{network:((S=g.state.activeCaipNetwork)==null?void 0:S.caipNetworkId)||"",swapFromToken:((h=a.state.sourceToken)==null?void 0:h.symbol)||"",swapToToken:((y=a.state.toToken)==null?void 0:y.symbol)||"",swapFromAmount:a.state.sourceTokenAmount||"",swapToAmount:a.state.toTokenAmount||"",isSmartAccount:M(P.CHAIN.EVM)===F.ACCOUNT_TYPES.SMART_ACCOUNT}}),E.resetState(),s||A.replace("Account"),E.getMyTokensWithBalance(U),m}catch(U){const m=U;e.transactionError=m==null?void 0:m.displayMessage,e.loadingTransaction=!1,w.showError((m==null?void 0:m.displayMessage)||"Transaction error"),D.sendEvent({type:"track",event:"SWAP_ERROR",properties:{message:(m==null?void 0:m.displayMessage)||(m==null?void 0:m.message)||"Unknown",network:((C=g.state.activeCaipNetwork)==null?void 0:C.caipNetworkId)||"",swapFromToken:((b=a.state.sourceToken)==null?void 0:b.symbol)||"",swapToToken:((W=a.state.toToken)==null?void 0:W.symbol)||"",swapFromAmount:a.state.sourceTokenAmount||"",swapToAmount:a.state.toTokenAmount||"",isSmartAccount:M(P.CHAIN.EVM)===F.ACCOUNT_TYPES.SMART_ACCOUNT}});return}},hasInsufficientToken(n,t){return I.isInsufficientSourceTokenForSwap(n,t,e.myTokensWithBalance)},setTransactionDetails(){const{toTokenAddress:n,toTokenDecimals:t}=a.getParams();!n||!t||(e.gasPriceInUSD=I.getGasPriceInUSD(e.networkPrice,BigInt(e.gasFee),BigInt(G)),e.priceImpact=I.getPriceImpact({sourceTokenAmount:e.sourceTokenAmount,sourceTokenPriceInUSD:e.sourceTokenPriceInUSD,toTokenPriceInUSD:e.toTokenPriceInUSD,toTokenAmount:e.toTokenAmount}),e.maxSlippage=I.getMaxSlippage(e.slippage,e.toTokenAmount),e.providerFee=I.getProviderFee(e.sourceTokenAmount))}},a=O(E);export{a as S};