@dcl/shop 0.1.0-30098548645.commit-d41f1c2 → 0.1.0-30124433292.commit-3681582

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 (171) hide show
  1. package/assets/{Activity-BqXTjVty.js → Activity-BK4KMnMS.js} +1 -1
  2. package/assets/{AnimatedBackground-B1wSbdZF.js → AnimatedBackground-DHyYRjGJ.js} +1 -1
  3. package/assets/{Assets-uNZ9-jka.js → Assets-DHSZ3Pma.js} +1 -1
  4. package/assets/{Assets.styles-C-xsD5dl.js → Assets.styles-ZcMNqA4L.js} +1 -1
  5. package/assets/{Authorizations-W1UUdrPD.js → Authorizations-B1N9MIgm.js} +1 -1
  6. package/assets/{Cart-Blw7vVhV.js → Cart-C4-D4ZHb.js} +1 -1
  7. package/assets/{CircularProgress-BFfCy1Hd.js → CircularProgress-xCRBPMNy.js} +1 -1
  8. package/assets/{Collection-DQPRvrkF.js → Collection-CF3fcBSY.js} +1 -1
  9. package/assets/{CollectionCarousel-D2Bi7Sgm.js → CollectionCarousel-DthPMnK1.js} +1 -1
  10. package/assets/{Creator-DPwgF8OQ.js → Creator-Dmo0SJOI.js} +1 -1
  11. package/assets/{CssVarsProvider-Cp4XcbYa.js → CssVarsProvider-Dpy58zet.js} +1 -1
  12. package/assets/{ExchangeController-DdMMOoWf.js → ExchangeController-B1_76-TU.js} +1 -1
  13. package/assets/{GetCredits-BbXMUpEL.js → GetCredits-CYn7AQqe.js} +1 -1
  14. package/assets/{HelpersUtil-CQPNVThh.js → HelpersUtil-XNHJPIP0.js} +1 -1
  15. package/assets/{ImportListings-DvBSRPqC.js → ImportListings-DDXI7JNI.js} +1 -1
  16. package/assets/{ItemDetail-CVK9Pwv2.js → ItemDetail-BHfN4ZbY.js} +3 -3
  17. package/assets/{LoadMore-Co82ACWq.js → LoadMore-BDrBHvfL.js} +1 -1
  18. package/assets/{MarketCheckout-CXF5RWuK.js → MarketCheckout-BpU-AwKt.js} +1 -1
  19. package/assets/{MyAssets-BPoXrFd-.js → MyAssets-BMY2c3n3.js} +1 -1
  20. package/assets/{MyFavorites-BLOtKEJq.js → MyFavorites-CKBsIu3I.js} +1 -1
  21. package/assets/{NotFound-B-Y9Dm45.js → NotFound-aVJwRiRB.js} +1 -1
  22. package/assets/{PrimaryListModal-cAIZGy2D.js → PrimaryListModal-DyCfH9JF.js} +1 -1
  23. package/assets/{StoreSettings-Bos_AZlO.js → StoreSettings-BvggmHJN.js} +5 -5
  24. package/assets/{Success-DNHF9FcH.js → Success-BKxe9orQ.js} +1 -1
  25. package/assets/{SwapController-Bk4YDtlv.js → SwapController-Cxz_R-cp.js} +1 -1
  26. package/assets/{Tooltip-CMiyDsYT.js → Tooltip-CQVkHZL8.js} +1 -1
  27. package/assets/{TradeService-B-E0tJaw.js → TradeService-DzeeSa-6.js} +1 -1
  28. package/assets/{W3MFrameProviderSingleton-B4WegxTX.js → W3MFrameProviderSingleton-nlgW21N5.js} +3 -3
  29. package/assets/{WebCryptoP256-CIN8LP5I.js → WebCryptoP256-DlMsvJ_V.js} +1 -1
  30. package/assets/{authorizations-xecfPSH8.js → authorizations-Bu5ynTut.js} +1 -1
  31. package/assets/{basic-DrYgU33R.js → basic-BpONuYnG.js} +1 -1
  32. package/assets/{biconomy-BkGZoSRG.js → biconomy-D17Pt1Vm.js} +1 -1
  33. package/assets/{builder-CdMpbqLu.js → builder-WRm0Yifb.js} +1 -1
  34. package/assets/{buy-DnDBBIJp.js → buy-Bg6ayEVg.js} +1 -1
  35. package/assets/buy-gasless-DHSR8j9W.js +1 -0
  36. package/assets/{cart-checkout-DldS-zcM.js → cart-checkout-srmBjqa3.js} +1 -1
  37. package/assets/{categories-q4cmLb4w.js → categories-CPkgFcrW.js} +1 -1
  38. package/assets/{ccip-Iagv6b6U.js → ccip-DHhCpQzR.js} +1 -1
  39. package/assets/{ccip-6xULYkiQ.js → ccip-em6DABSU.js} +1 -1
  40. package/assets/{collection-9XqBYepL.js → collection-CnhLIVpI.js} +1 -1
  41. package/assets/{controller-CGXADiD7.js → controller-Cie4Aw3d.js} +2 -2
  42. package/assets/{core-ClJQ0SHg.js → core-Bt2V3toO.js} +4 -4
  43. package/assets/{custom-CRZtbdh1.js → custom-cOOMqA6K.js} +1 -1
  44. package/assets/{data-capture-Brtecicz.js → data-capture-BZ7A5Z5k.js} +1 -1
  45. package/assets/{email-Dc521KI9.js → email-DXloZ8qA.js} +1 -1
  46. package/assets/{embedded-wallet-qO37cv4b.js → embedded-wallet-CgkpmBAb.js} +1 -1
  47. package/assets/{emotion-styled.browser.esm-CdNioFJM.js → emotion-styled.browser.esm-DfoKy-pj.js} +1 -1
  48. package/assets/{engine-C38d94-_.js → engine-CzYvnB17.js} +1 -1
  49. package/assets/{errors-BHedmHUe.js → errors-BImf8DDM.js} +1 -1
  50. package/assets/{estimate-l1-fee-BIFy_-EC.js → estimate-l1-fee-gOwRw5z4.js} +1 -1
  51. package/assets/{execute-CxvgrSL8.js → execute-ud83RGqS.js} +2 -2
  52. package/assets/{features-CLCrkR7s.js → features-DxPH-haZ.js} +1 -1
  53. package/assets/{fetchTokenMetadata-ChVieTUE.js → fetchTokenMetadata-DChqEGuz.js} +2 -2
  54. package/assets/{get-ecosystem-wallet-info-zShJZuFf.js → get-ecosystem-wallet-info-xUSXAeJm.js} +1 -1
  55. package/assets/{getBalance-D426yGLP.js → getBalance-D8OfNiEw.js} +1 -1
  56. package/assets/{getNFT-DbYpgeGV.js → getNFT-DkedtIa4.js} +1 -1
  57. package/assets/{getNFT-DDdhWmh5.js → getNFT-EuseX6lY.js} +1 -1
  58. package/assets/{getOverlayAlpha-DF26uj8z.js → getOverlayAlpha-zAle2GuY.js} +1 -1
  59. package/assets/{hashTypedData-DBErsqac.js → hashTypedData-Dqmk47xN.js} +1 -1
  60. package/assets/{hashTypedData-ZQ4gFkel.js → hashTypedData-abS_7cer.js} +1 -1
  61. package/assets/{import-ZCCl3Kgl.js → import-CuPZVchc.js} +1 -1
  62. package/assets/{in-app-CpdkUQeY.js → in-app-Cd-d2j0h.js} +1 -1
  63. package/assets/{in-app-wallet-calls-dlczJBmg.js → in-app-wallet-calls-BqANuQ3r.js} +1 -1
  64. package/assets/{index-Dum_hwGS.js → index-0NSEGJZv.js} +1 -1
  65. package/assets/{index-BqBeehVu.js → index-5GF4A0S-.js} +1 -1
  66. package/assets/{index-BUxPYCpI.js → index-AqK7feCi.js} +1 -1
  67. package/assets/{index-BPE4c8Hm.js → index-B-mtLlzK.js} +1 -1
  68. package/assets/{index-BmClkpNO.js → index-B0r7CJWG.js} +1 -1
  69. package/assets/{index-C_96F6p3.js → index-B9yNV6c0.js} +1 -1
  70. package/assets/{index-CwuYCSTt.js → index-BTqEklxp.js} +1 -1
  71. package/assets/{index-DjNqY58Q.js → index-BdxV9LV_.js} +1 -1
  72. package/assets/{index-Be_wjnpZ.js → index-BlhIwuOI.js} +1 -1
  73. package/assets/{index-dOPjS08E.js → index-BqxxuGEO.js} +3 -3
  74. package/assets/{index-BTEpBP4F.js → index-BrXKLFgO.js} +1 -1
  75. package/assets/{index-DTSWcrXA.js → index-BsIDqh4z.js} +1 -1
  76. package/assets/{index-DHqnjZXk.js → index-Bu0ceOeP.js} +1 -1
  77. package/assets/{index-ej1HeaVq.js → index-C1M0bOpf.js} +1 -1
  78. package/assets/{index-N282EqWL.js → index-C3X5jLeD.js} +9 -9
  79. package/assets/{index-DsmEu83d.js → index-CAjhZgPW.js} +2 -2
  80. package/assets/{index-DUHukso9.js → index-CDlAE_WC.js} +1 -1
  81. package/assets/{index-CmFvRPK_.js → index-CGFMFn1H.js} +1 -1
  82. package/assets/{index-Cf3Ptwp7.js → index-CSLEY4ca.js} +1 -1
  83. package/assets/{index-oDGz3alu.js → index-CYPATMbH.js} +1 -1
  84. package/assets/{index-DkV39niV.js → index-CcInJPMR.js} +1 -1
  85. package/assets/{index-SeXxQE7d.js → index-Cd1kOVjp.js} +1 -1
  86. package/assets/{index-uRCNAkhD.js → index-CecaRjyr.js} +1 -1
  87. package/assets/{index-DZWZ4ZjC.js → index-Cr_ncTLI.js} +1 -1
  88. package/assets/{index-CtyVceSL.js → index-Cvc29q-I.js} +3 -3
  89. package/assets/{index-BYL4Amcw.js → index-D2LsYIdq.js} +1 -1
  90. package/assets/{index-GYAvpxvp.js → index-D39xHY3d.js} +1 -1
  91. package/assets/{index-PtVfNA02.js → index-D73PUnuv.js} +1 -1
  92. package/assets/{index-BwP2pQ92.js → index-DCkcZnW5.js} +1 -1
  93. package/assets/{index-BoQpPvsJ.js → index-DFIVRio9.js} +3 -3
  94. package/assets/{index-Dz6EILW5.js → index-DGn6VaO-.js} +1 -1
  95. package/assets/{index-Dw9WIdKs.js → index-DIlSeQzV.js} +1 -1
  96. package/assets/{index-BCFHpbdv.js → index-DLy3F1PO.js} +1 -1
  97. package/assets/{index-Dkdo-C-7.js → index-DM6W5d9P.js} +2 -2
  98. package/assets/{index-dc-VQ6_u.js → index-DMknz5cu.js} +1 -1
  99. package/assets/{index-CnNzrERF.js → index-DVlSY8mP.js} +1 -1
  100. package/assets/{index-CO8EAj61.js → index-DY_9EV49.js} +2 -2
  101. package/assets/{index-hSbfPxTM.js → index-DZ6ajsXs.js} +1 -1
  102. package/assets/{index-DWo6WByw.js → index-DebzClIH.js} +1 -1
  103. package/assets/{index-xEDt5tK0.js → index-DgKLBFdD.js} +1 -1
  104. package/assets/{index-D9WRMnJQ.js → index-Djb9RTtv.js} +1 -1
  105. package/assets/{index-CIVsEPCC.js → index-DmoKb6B-.js} +1 -1
  106. package/assets/{index-Ix0aAVOz.js → index-DpPkDpzv.js} +1 -1
  107. package/assets/{index-DCT6sOxM.js → index-M8HIp82S.js} +1 -1
  108. package/assets/{index-DXsS9lM4.js → index-NN1ViCJc.js} +1 -1
  109. package/assets/{index-BpsxTpFt.js → index-Z8Wo_kwk.js} +1 -1
  110. package/assets/{index-C8X5uQxK.js → index-Za0RNTve.js} +1 -1
  111. package/assets/{index-LwWUxbJ1.js → index-ixz0SMZY.js} +1 -1
  112. package/assets/{index-GctTWB_u.js → index-kMsmgOxf.js} +1 -1
  113. package/assets/{index-DTFks6GD.js → index-q0JQZ3dR.js} +1 -1
  114. package/assets/{index-BfgxxLyc.js → index-v11xmkay.js} +1 -1
  115. package/assets/{index-C8gW1uS_.js → index-wyA7ZE7I.js} +1 -1
  116. package/assets/{index.es-BAkCd3hx.js → index.es-C181Dk-6.js} +4 -4
  117. package/assets/{index.es-mQdmYoWw.js → index.es-DKJYmPMf.js} +1 -1
  118. package/assets/{index.es-8l4m8O48.js → index.es-nYWt2I6x.js} +1 -1
  119. package/assets/{localBatchGatewayRequest-C-QF008k.js → localBatchGatewayRequest-kTkh-9Y1.js} +1 -1
  120. package/assets/{mana-rate-B5qogWAy.js → mana-rate-BRTVWI6W.js} +1 -1
  121. package/assets/{networks-DTf6JA_i.js → networks-Bum5JTBr.js} +1 -1
  122. package/assets/{onramp-C6_Jmv_4.js → onramp-CFmv1zZR.js} +1 -1
  123. package/assets/{openzeppelin-BI3jzvYe.js → openzeppelin-zgph3CRe.js} +1 -1
  124. package/assets/{parseNft-BJiElQOd.js → parseNft-CZwNnq-K.js} +2 -2
  125. package/assets/{parseSignature-YsYfChHW.js → parseSignature-BEnVvaTZ.js} +3 -3
  126. package/assets/{parseSignature-BTArmdp-.js → parseSignature-CmSsHC25.js} +1 -1
  127. package/assets/{passkeys-ClpAr2XQ.js → passkeys-BLHHj7-d.js} +1 -1
  128. package/assets/{pay-with-exchange-BrMLcJvy.js → pay-with-exchange-BV1nqwHf.js} +1 -1
  129. package/assets/{qr-overlay-DFoBAvax.js → qr-overlay-DNUGuQ9g.js} +1 -1
  130. package/assets/{receive-2v3kqZfq.js → receive-DX5PX0qv.js} +1 -1
  131. package/assets/{resolveImplementation-Cz7jydx-.js → resolveImplementation-DtRRnBJY.js} +1 -1
  132. package/assets/{rpc-DcYX9vLT.js → rpc-N5gKnuFD.js} +1 -1
  133. package/assets/{secp256k1-Du_5cnvk.js → secp256k1-B3NLODsT.js} +1 -1
  134. package/assets/{secp256k1-CRO1xSNd.js → secp256k1-CbGQ7AnW.js} +1 -1
  135. package/assets/{secp256k1-D0kj9oiG.js → secp256k1-Cs17P-H6.js} +1 -1
  136. package/assets/{send-EHrmCt5p.js → send-DuAfQv20.js} +1 -1
  137. package/assets/{send-batch-transaction-DrLYa7mf.js → send-batch-transaction-CK1FAK6a.js} +1 -1
  138. package/assets/{send-eip712-transaction-DWQC0CYI.js → send-eip712-transaction-CCANsdcR.js} +2 -2
  139. package/assets/{send-gasless-transaction-DraXgpfw.js → send-gasless-transaction-DMAXE9_o.js} +2 -2
  140. package/assets/{send-transaction-Di96Go1T.js → send-transaction-CGlKSvcE.js} +2 -2
  141. package/assets/{sendRawTransaction-CzOwT9zB.js → sendRawTransaction-BGxuVTrM.js} +3 -3
  142. package/assets/{serializeTransaction-BVfMAhW_.js → serializeTransaction-CCiQEbVK.js} +1 -1
  143. package/assets/{session-proposal-DQbScMFK.js → session-proposal-B5yk7mT0.js} +1 -1
  144. package/assets/{session-request-BSJWiNx1.js → session-request-C2C-LgcL.js} +2 -2
  145. package/assets/{signing-BTj_vr30.js → signing-peFpZpgT.js} +3 -3
  146. package/assets/{socials-Ca0m8Bc6.js → socials-Cjx6YfeD.js} +1 -1
  147. package/assets/{swaps-Bxufbu_7.js → swaps-DHGkT6CC.js} +1 -1
  148. package/assets/{thirdweb-BSXHM0bk.js → thirdweb-p9nuhkCz.js} +3 -3
  149. package/assets/{to-serializable-transaction-BiEB81zL.js → to-serializable-transaction-CnZ3cWe2.js} +2 -2
  150. package/assets/{trade-encoding-6_dO5FYh.js → trade-encoding-Dp_icjFZ.js} +1 -1
  151. package/assets/{transactionReceipt-WUy2-DIs.js → transactionReceipt-BGOacWj7.js} +1 -1
  152. package/assets/{transactions-Ddu0qS1y.js → transactions-BBxZRzis.js} +1 -1
  153. package/assets/{useCreditPacks-BXDDD38Z.js → useCreditPacks-CTza1Tus.js} +1 -1
  154. package/assets/{useInfiniteGrid-BokrX5YA.js → useInfiniteGrid-Mx1HAG8J.js} +1 -1
  155. package/assets/useManaRate-BP0fvx6U.js +1 -0
  156. package/assets/{useStore-DL2tZW7o.js → useStore-45Le9Qaw.js} +1 -1
  157. package/assets/useTheme-CgBOLs_h.js +1 -0
  158. package/assets/{useTheme-Tgfl6yPv.js → useTheme-XtIUuPdU.js} +1 -1
  159. package/assets/{verifyHash-DEKVRRCg.js → verifyHash-zHFDxXH3.js} +1 -1
  160. package/assets/{w3m-modal-BOayHahj.js → w3m-modal-CTLy-nbk.js} +1 -1
  161. package/assets/{w3m-modal-DGk65SCN.js → w3m-modal-DFuYjjkX.js} +1 -1
  162. package/assets/{wait-for-tx-receipt-C-yyIlse.js → wait-for-tx-receipt-kY7a907-.js} +1 -1
  163. package/assets/{wallets-CKstZZYA.js → wallets-B-yYAVWE.js} +5 -5
  164. package/assets/{web-connector-Df1Nw4jg.js → web-connector-DXFq0InF.js} +3 -3
  165. package/assets/{writeContract-EXXVPkwI.js → writeContract-8JrxZEN1.js} +1 -1
  166. package/assets/{zoraTestnet-Dj9qFBkp.js → zoraTestnet-5571NyS8.js} +1 -1
  167. package/index.html +11 -11
  168. package/package.json +2 -2
  169. package/assets/buy-gasless-DITQks7J.js +0 -1
  170. package/assets/useManaRate-CtZMBb6a.js +0 -1
  171. package/assets/useTheme-B-xHZMoE.js +0 -1
@@ -1,4 +1,4 @@
1
- import{r as l,j as c}from"./react-BXazHbBy.js";import{s as u,B as p,t as d}from"./index-N282EqWL.js";const a=u.div`
1
+ import{r as l,j as c}from"./react-BXazHbBy.js";import{s as u,B as p,t as d}from"./index-C3X5jLeD.js";const a=u.div`
2
2
  display: flex;
3
3
  justify-content: center;
4
4
  padding: 28px 0 8px;
@@ -1,3 +1,3 @@
1
- import{u as z,r as h,j as r}from"./react-BXazHbBy.js";import{u as O,a as V,b as Y,t,c as y,C as b,f as S,d as H,e as w,g as $,i as D,h as J,j as p,k as M,l as q,s as X,B as Z}from"./index-N282EqWL.js";import{m as j}from"./mana-rate-B5qogWAy.js";import{b as Q}from"./buy-DnDBBIJp.js";import{b as ee,w as re,S as ae,G as te}from"./buy-gasless-DITQks7J.js";import{g as se}from"./authorizations-xecfPSH8.js";import{i as ie}from"./errors-BHedmHUe.js";import{E as ce}from"./ErrorNotice-Cmr8aXJs.js";const F=X(Z)`
1
+ import{u as z,r as h,j as r}from"./react-BXazHbBy.js";import{u as O,a as V,b as Y,t,c as y,C as b,f as S,d as H,e as w,g as $,i as D,h as J,j as p,k as M,l as q,s as X,B as Z}from"./index-C3X5jLeD.js";import{m as j}from"./mana-rate-BRTVWI6W.js";import{b as Q}from"./buy-Bg6ayEVg.js";import{b as ee,w as re,S as ae,G as te}from"./buy-gasless-DHSR8j9W.js";import{g as se}from"./authorizations-Bu5ynTut.js";import{i as ie}from"./errors-BImf8DDM.js";import{E as ce}from"./ErrorNotice-Cmr8aXJs.js";const F=X(Z)`
2
2
  flex: 1;
3
3
  `;function K(e){if(ie(e))return t("errors.rejected");const d=(e.message??"").toLowerCase();return d.includes("insufficient")?t("marketCheckout.error.insufficient",{currency:w.name}):d.includes("not found")||d.includes("no active listing")||d.includes("404")?t("marketCheckout.error.soldOrRemoved"):d.includes("your own listing")?t("errors.cantBuyOwn"):t("marketCheckout.error.generic")}function de(e){return{id:e.tradeId,tradeId:e.tradeId,name:e.name,creator:e.creator,contractAddress:e.contractAddress,itemId:e.itemId,category:e.category,wearableCategory:e.wearableCategory??void 0,rarity:e.rarity,network:e.network,chainId:e.chainId,thumbnail:e.thumbnail,priceCredits:0,gender:null,isSmart:!1}}function fe({listing:e,rate:d,onClose:A,onSold:R}){const{session:i}=O(),{data:n,isError:B}=V(i),o=Y(),N=z(),[g,f]=h.useState("confirm"),[C,E]=h.useState(t("marketCheckout.lockingPrice")),[U,v]=h.useState(null),[a,W]=h.useState(null),l=h.useRef(null),G=Math.ceil(j(e.manaWei,d)/10);h.useEffect(()=>{let u=!1;if(!i){f("error"),v(t("buyModal.signInToCheckout"));return}return(async()=>{try{const s=await $(e.tradeId);if(!s)throw new Error("not found");if(D(s,i.address))throw new Error("You can't buy your own listing.");const k=j(e.manaWei,d);if(!Number.isFinite(k)||k<=0)throw new Error("price unavailable");const{credit:m,maxCreditedValue:T,usdCents:P}=await J(i.identity,k,e.tradeId);if(u){y(i.identity,[m.id]).catch(()=>{});return}l.current=m.id,W({trade:s,credit:m,maxCreditedValue:T,usdCents:P,credits:Math.ceil(P/10)}),E("")}catch(s){if(u)return;console.error("[market] authorize failed",s),p(q(s)?"Shop Purchase Cancelled":"Shop Purchase Failed",{step:"authorize",error_code:M(s),value_usd:Math.round(j(e.manaWei,d))/100}),f("error"),v(K(s))}})(),()=>{u=!0,l.current&&i&&(y(i.identity,[l.current]).catch(()=>{}),l.current=null)}},[]);const x=!!a&&n!=null&&n.credits<a.credits;async function L(){if(!i||!a)return;if(x){p("Shop Buy Credits Prompted",{from:"item_checkout",credits_needed:a.credits,credits_balance:(n==null?void 0:n.credits)??0,shortfall:Math.max(0,a.credits-((n==null?void 0:n.credits)??0))}),y(i.identity,[a.credit.id]).catch(()=>{}),l.current=null,N("/credits");return}f("working"),v(null);let u=!1;try{E(t("marketCheckout.confirming"));const c={trade:a.trade,buyer:i.address,signer:i.signer,credits:[a.credit],maxCreditedValue:a.maxCreditedValue};let s;if(se())try{s=await ee(c),await re(s),u=!0}catch(m){if(m instanceof ae)u=!0;else if(m instanceof te)s=await Q(c);else throw m}else s=await Q(c);l.current=null,p("Shop Completed Purchase",{items:[{item_id:e.itemId??null,contract_address:e.contractAddress,token_id:null,price_usd:a.usdCents/100}],value_credits:a.credits,value_usd:a.usdCents/100,purchase_type:"item",is_primary:!0,payment_type:"credits",no_crypto_step:u,transaction_hash:s??null}),o.invalidateQueries({queryKey:["usd-balance"]}),o.invalidateQueries({queryKey:["detail-trade"]}),o.invalidateQueries({queryKey:["shop-item"]}),o.invalidateQueries({queryKey:["item-resales",e.contractAddress,e.itemId]}),o.invalidateQueries({queryKey:["shop-items"]}),o.invalidateQueries({queryKey:["catalog-items"]}),o.invalidateQueries({queryKey:["my-assets"]}),o.invalidateQueries({queryKey:["purchases"]});const k={items:[de(e)],txHash:s};N("/success",{state:k})}catch(c){console.error("[market] buy now failed",c),y(i.identity,[a.credit.id]).catch(()=>{}),l.current=null,p(q(c)?"Shop Purchase Cancelled":"Shop Purchase Failed",{step:"submit",error_code:M(c),value_usd:a.usdCents/100}),o.invalidateQueries({queryKey:["usd-balance"]}),v(K(c)),f("error");const s=(c.message??"").toLowerCase();(s.includes("not found")||s.includes("no active listing")||s.includes("404"))&&R()}}function I(){i&&a&&y(i.identity,[a.credit.id]).catch(()=>{}),l.current=null,A()}const _=g==="working";return r.jsxs("div",{className:"mkt-modal",role:"dialog","aria-modal":"true","aria-label":t("buyModal.dialogAria",{name:e.name}),children:[r.jsx("div",{className:"mkt-modal__scrim",onClick:_?void 0:I,"aria-hidden":!0}),r.jsxs("div",{className:"mkt-modal__card",children:[r.jsxs("div",{className:"mkt-modal__head",children:[r.jsx("div",{className:"mkt-modal__thumb",children:e.thumbnail?r.jsx("img",{src:e.thumbnail,alt:""}):null}),r.jsxs("div",{children:[r.jsx("div",{className:"mkt-modal__name",title:e.name,children:e.name||t("buyModal.itemFallback")}),r.jsx("span",{className:"chip chip--rarity",children:e.rarity})]})]}),r.jsx("div",{className:"mkt-modal__price",children:a?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"mkt-modal__price-label",children:t("marketCheckout.finalPrice")}),r.jsxs("div",{className:"mkt-modal__price-value",children:[r.jsx(b,{className:"mkt-modal__diamond"}),S(a.credits)]}),r.jsxs("div",{className:"mkt-modal__price-sub muted",children:[t("marketCheckout.lockedForPurchase")," · $",(a.usdCents/100).toFixed(2)]})]}):r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"mkt-modal__price-label",children:t("marketCheckout.todaysPrice")}),r.jsxs("div",{className:"mkt-modal__price-value mkt-modal__price-value--approx",children:[r.jsx("span",{className:"mkt-modal__approx","aria-hidden":!0,children:"≈"}),r.jsx(b,{className:"mkt-modal__diamond"}),S(G)]}),r.jsx("div",{className:"mkt-modal__price-sub muted",children:C||t("marketCheckout.lockingPrice")})]})}),i?r.jsxs("div",{className:"mkt-modal__balance muted",children:[t("marketCheckout.yourBalance")," ",r.jsx(b,{className:"ccy-mark"})," ",H(n,B)]}):null,x?r.jsx("p",{className:"muted mkt-modal__note",children:t("marketCheckout.needMore",{currency:w.name})}):null,C&&g==="working"?r.jsx("p",{className:"muted mkt-modal__note",children:C}):null,r.jsx(ce,{message:U,className:"mkt-modal__note"}),r.jsxs("div",{className:"mkt-modal__actions",children:[r.jsx(F,{variant:"ghost",onClick:I,disabled:_,children:t("buyModal.cancel")}),r.jsx(F,{variant:"purple",onClick:()=>void L(),disabled:_||!a,children:_?t("marketCheckout.buying"):x?t("nav.getCredits",{currency:w.name}):t("marketCheckout.confirmPurchase")})]})]})]})}export{fe as M};
@@ -1,4 +1,4 @@
1
- import{L as Ie,b as et,r as d,j as t}from"./react-BXazHbBy.js";import{s as i,G as s,I,m as tt,t as n,u as st,b as ot,H as pe,o as O,B as rt,A as D,j as nt,J as at,g as it,K as lt,F as ct,p as ke,L as dt,M as mt}from"./index-N282EqWL.js";import{f as pt}from"./import-ZCCl3Kgl.js";import{f as ut}from"./builder-CdMpbqLu.js";import{c as ft}from"./buy-DnDBBIJp.js";import{P as ht,p as xt}from"./PrimaryListModal-cAIZGy2D.js";import{R as Q,C as yt,a as gt,F as bt,S as U,b as ue}from"./categories-q4cmLb4w.js";import{L as wt}from"./LoadMore-Co82ACWq.js";import{D as fe,F as he,R as St,a as jt,b as $t,c as Ct,d as It,S as kt,e as vt,f as At,g as Et,h as Tt,i as Ft,j as Rt,k as _t,C as Ot,l as Lt,m as Pt,n as zt,M as Kt}from"./Assets.styles-C-xsD5dl.js";import{u as Mt}from"./useInfiniteGrid-BokrX5YA.js";import{E as H}from"./ErrorNotice-Cmr8aXJs.js";import{n as ve}from"./emotion-CSxEP8yM.js";import"./dcl-schemas-BICTSpB5.js";import"./sentry-CLqlZ0dX.js";import"./ethers-BJDbBwOP.js";import"./intl-CBcMB1D2.js";import"./mana-rate-B5qogWAy.js";import"./index-HN6Rk25C.js";import"./trade-encoding-6_dO5FYh.js";import"./authorizations-xecfPSH8.js";import"./sendMetaTransaction-CiO3jI6F.js";import"./errors-BHedmHUe.js";import"./Tooltip-CMiyDsYT.js";i.div`
1
+ import{L as Ie,b as et,r as d,j as t}from"./react-BXazHbBy.js";import{s as i,G as s,I,m as tt,t as n,u as st,b as ot,H as pe,o as O,B as rt,A as D,j as nt,J as at,g as it,K as lt,F as ct,p as ke,L as dt,M as mt}from"./index-C3X5jLeD.js";import{f as pt}from"./import-CuPZVchc.js";import{f as ut}from"./builder-WRm0Yifb.js";import{c as ft}from"./buy-Bg6ayEVg.js";import{P as ht,p as xt}from"./PrimaryListModal-DyCfH9JF.js";import{R as Q,C as yt,a as gt,F as bt,S as U,b as ue}from"./categories-CPkgFcrW.js";import{L as wt}from"./LoadMore-BDrBHvfL.js";import{D as fe,F as he,R as St,a as jt,b as $t,c as Ct,d as It,S as kt,e as vt,f as At,g as Et,h as Tt,i as Ft,j as Rt,k as _t,C as Ot,l as Lt,m as Pt,n as zt,M as Kt}from"./Assets.styles-ZcMNqA4L.js";import{u as Mt}from"./useInfiniteGrid-Mx1HAG8J.js";import{E as H}from"./ErrorNotice-Cmr8aXJs.js";import{n as ve}from"./emotion-CSxEP8yM.js";import"./dcl-schemas-BICTSpB5.js";import"./sentry-CLqlZ0dX.js";import"./ethers-BJDbBwOP.js";import"./intl-CBcMB1D2.js";import"./mana-rate-BRTVWI6W.js";import"./index-HN6Rk25C.js";import"./trade-encoding-Dp_icjFZ.js";import"./authorizations-Bu5ynTut.js";import"./sendMetaTransaction-CiO3jI6F.js";import"./errors-BImf8DDM.js";import"./Tooltip-CQVkHZL8.js";i.div`
2
2
  display: flex;
3
3
  flex-direction: column;
4
4
  gap: 4px;
@@ -1,3 +1,3 @@
1
- import{r as n,j as s,L as m}from"./react-BXazHbBy.js";import{m as c,t,n as l,I as d,A as p,s as v,B as x}from"./index-N282EqWL.js";import{L as h}from"./LoadMore-Co82ACWq.js";import"./dcl-schemas-BICTSpB5.js";import"./sentry-CLqlZ0dX.js";import"./ethers-BJDbBwOP.js";import"./intl-CBcMB1D2.js";const u=v(x)`
1
+ import{r as n,j as s,L as m}from"./react-BXazHbBy.js";import{m as c,t,n as l,I as d,A as p,s as v,B as x}from"./index-C3X5jLeD.js";import{L as h}from"./LoadMore-BDrBHvfL.js";import"./dcl-schemas-BICTSpB5.js";import"./sentry-CLqlZ0dX.js";import"./ethers-BJDbBwOP.js";import"./intl-CBcMB1D2.js";const u=v(x)`
2
2
  margin-top: 12px;
3
3
  `,r=24;function E(){c({title:t("nav.myFavorites"),noindex:!0});const a=l(e=>Object.values(e.items)),[i,o]=n.useState(r);return a.length===0?s.jsxs("div",{className:"favorites-empty",children:[s.jsx(d,{name:"heart",size:40,color:"var(--muted-2)"}),s.jsx("p",{className:"favorites-empty__title",children:t("myFavorites.emptyTitle")}),s.jsx("p",{className:"muted",children:t("myFavorites.emptyBody")}),s.jsx(u,{as:m,to:"/assets",variant:"purple",children:t("notFound.cta")})]}):s.jsxs("section",{className:"favorites",children:[s.jsxs("div",{className:"favorites__head",children:[s.jsx("h1",{children:t("nav.myFavorites")}),s.jsx("span",{className:"favorites__count",children:t("myFavorites.itemCount",{count:a.length})})]}),s.jsx("div",{className:"grid",children:a.slice(0,i).map(e=>s.jsx(p,{item:e},e.id))}),s.jsx(h,{hasNextPage:i<a.length,isFetching:!1,onLoadMore:()=>o(e=>e+r)})]})}export{E as MyFavorites};
@@ -1 +1 @@
1
- import{j as t,L as n}from"./react-BXazHbBy.js";import{m as s,t as o,I as e,B as a}from"./index-N282EqWL.js";import"./dcl-schemas-BICTSpB5.js";import"./sentry-CLqlZ0dX.js";import"./ethers-BJDbBwOP.js";import"./intl-CBcMB1D2.js";function c(){return s({title:o("seo.notFound.title"),noindex:!0}),t.jsxs("div",{className:"notfound","data-testid":"notfound",children:[t.jsx(e,{name:"cart",className:"notfound__ico"}),t.jsx("h1",{className:"notfound__title",children:o("notFound.title")}),t.jsx("p",{className:"muted",children:o("notFound.body")}),t.jsx(a,{as:n,to:"/assets",variant:"purple",children:o("notFound.cta")})]})}export{c as NotFound,c as default};
1
+ import{j as t,L as n}from"./react-BXazHbBy.js";import{m as s,t as o,I as e,B as a}from"./index-C3X5jLeD.js";import"./dcl-schemas-BICTSpB5.js";import"./sentry-CLqlZ0dX.js";import"./ethers-BJDbBwOP.js";import"./intl-CBcMB1D2.js";function c(){return s({title:o("seo.notFound.title"),noindex:!0}),t.jsxs("div",{className:"notfound","data-testid":"notfound",children:[t.jsx(e,{name:"cart",className:"notfound__ico"}),t.jsx("h1",{className:"notfound__title",children:o("notFound.title")}),t.jsx("p",{className:"muted",children:o("notFound.body")}),t.jsx(a,{as:n,to:"/assets",variant:"purple",children:o("notFound.cta")})]})}export{c as NotFound,c as default};
@@ -1,4 +1,4 @@
1
- import{u as R,r as g,j as t}from"./react-BXazHbBy.js";import{w as U,s,G as e,b as G,af as V,H as X,ag as Y,p as J,t as r,I as L,C as P,e as C,ah as Z,q as ee,j as K,K as te,F as ie,k as re}from"./index-N282EqWL.js";import{d as se}from"./dcl-schemas-BICTSpB5.js";import{i as ne,e as oe,c as ae}from"./trade-encoding-6_dO5FYh.js";import{f as le}from"./errors-BHedmHUe.js";import{E as ce}from"./ErrorNotice-Cmr8aXJs.js";function T(i,d){return d.kind==="listed"?{...i,isOnSale:!0,listingPrice:d.priceCredits,tradeId:d.tradeId??i.tradeId}:{...i,isOnSale:!1,listingPrice:void 0,tradeId:void 0}}function _e(i,d,p){const{address:u,contractAddress:l,tokenId:m}=d;if(!l||!m)return;const f=`${l}-${m}`;i.cancelQueries({queryKey:["owned-token",l,m]}),i.cancelQueries({queryKey:["secondary-sale-state"]}),u&&i.cancelQueries({queryKey:["my-assets",u]});const b=p.kind==="gone";i.setQueriesData({queryKey:["owned-token",l,m]},n=>n&&(b?null:T(n,p)));const $=u?["my-assets",u]:["my-assets"];i.setQueriesData({queryKey:$},n=>n!=null&&n.pages?{...n,pages:n.pages.map(c=>{if(b){const a=c.items.filter(x=>!(x.contractAddress===l&&x.tokenId===m));return{...c,items:a,total:Math.max(0,c.total-(c.items.length-a.length))}}return{...c,items:c.items.map(a=>a.contractAddress===l&&a.tokenId===m?T(a,p):a)}})}:n),i.setQueriesData({queryKey:["secondary-sale-state"]},n=>{var a;if(!n)return n;const c={...n};return p.kind==="removed"||p.kind==="gone"?delete c[f]:c[f]={priceCredits:p.priceCredits,tradeId:p.tradeId??((a=c[f])==null?void 0:a.tradeId)??""},c})}function de(i){return!!i&&!U(i.providerType)}const Q=s.div`
1
+ import{u as R,r as g,j as t}from"./react-BXazHbBy.js";import{w as U,s,G as e,b as G,af as V,H as X,ag as Y,p as J,t as r,I as L,C as P,e as C,ah as Z,q as ee,j as K,K as te,F as ie,k as re}from"./index-C3X5jLeD.js";import{d as se}from"./dcl-schemas-BICTSpB5.js";import{i as ne,e as oe,c as ae}from"./trade-encoding-Dp_icjFZ.js";import{f as le}from"./errors-BImf8DDM.js";import{E as ce}from"./ErrorNotice-Cmr8aXJs.js";function T(i,d){return d.kind==="listed"?{...i,isOnSale:!0,listingPrice:d.priceCredits,tradeId:d.tradeId??i.tradeId}:{...i,isOnSale:!1,listingPrice:void 0,tradeId:void 0}}function _e(i,d,p){const{address:u,contractAddress:l,tokenId:m}=d;if(!l||!m)return;const f=`${l}-${m}`;i.cancelQueries({queryKey:["owned-token",l,m]}),i.cancelQueries({queryKey:["secondary-sale-state"]}),u&&i.cancelQueries({queryKey:["my-assets",u]});const b=p.kind==="gone";i.setQueriesData({queryKey:["owned-token",l,m]},n=>n&&(b?null:T(n,p)));const $=u?["my-assets",u]:["my-assets"];i.setQueriesData({queryKey:$},n=>n!=null&&n.pages?{...n,pages:n.pages.map(c=>{if(b){const a=c.items.filter(x=>!(x.contractAddress===l&&x.tokenId===m));return{...c,items:a,total:Math.max(0,c.total-(c.items.length-a.length))}}return{...c,items:c.items.map(a=>a.contractAddress===l&&a.tokenId===m?T(a,p):a)}})}:n),i.setQueriesData({queryKey:["secondary-sale-state"]},n=>{var a;if(!n)return n;const c={...n};return p.kind==="removed"||p.kind==="gone"?delete c[f]:c[f]={priceCredits:p.priceCredits,tradeId:p.tradeId??((a=c[f])==null?void 0:a.tradeId)??""},c})}function de(i){return!!i&&!U(i.providerType)}const Q=s.div`
2
2
  position: fixed;
3
3
  inset: 0;
4
4
  z-index: 10000;
@@ -1,8 +1,8 @@
1
- import{j as s,u as se,r as n,L as te}from"./react-BXazHbBy.js";import{t as a,G as C,s as _,N as ae,m as ie,u as re,b as ne,I as E,B as P,K as R}from"./index-N282EqWL.js";import{u as oe,d as le,t as ce,L as de,i as B,a as v,s as me}from"./useStore-DL2tZW7o.js";import{E as M}from"./ErrorNotice-Cmr8aXJs.js";import"./dcl-schemas-BICTSpB5.js";import"./sentry-CLqlZ0dX.js";import"./ethers-BJDbBwOP.js";import"./intl-CBcMB1D2.js";const ue="https://cdn.decentraland.org/@dcl/shop/0.1.0-30098548645.commit-d41f1c2/assets/template-cover-1-BETekfHg.jpeg",pe="https://cdn.decentraland.org/@dcl/shop/0.1.0-30098548645.commit-d41f1c2/assets/template-cover-2-Dni9s0i_.jpeg",ge=Object.assign({"../assets/creator-covers/template-cover-1.jpeg":ue,"../assets/creator-covers/template-cover-2.jpeg":pe}),f=Object.entries(ge).sort(([i],[d])=>i.localeCompare(d)).map(([i,d])=>({name:i.split("/").pop(),url:d})),ve=ae`
1
+ import{j as s,u as se,r as n,L as te}from"./react-BXazHbBy.js";import{t as a,G as C,s as _,N as ae,m as ie,u as re,b as ne,I as E,B as P,K as R}from"./index-C3X5jLeD.js";import{u as oe,d as le,t as ce,L as de,i as B,a as v,s as me}from"./useStore-45Le9Qaw.js";import{E as M}from"./ErrorNotice-Cmr8aXJs.js";import"./dcl-schemas-BICTSpB5.js";import"./sentry-CLqlZ0dX.js";import"./ethers-BJDbBwOP.js";import"./intl-CBcMB1D2.js";const ue="https://cdn.decentraland.org/@dcl/shop/0.1.0-30124433292.commit-3681582/assets/template-cover-1-BETekfHg.jpeg",pe="https://cdn.decentraland.org/@dcl/shop/0.1.0-30124433292.commit-3681582/assets/template-cover-2-Dni9s0i_.jpeg",ge=Object.assign({"../assets/creator-covers/template-cover-1.jpeg":ue,"../assets/creator-covers/template-cover-2.jpeg":pe}),h=Object.entries(ge).sort(([i],[d])=>i.localeCompare(d)).map(([i,d])=>({name:i.split("/").pop(),url:d})),ve=ae`
2
2
  to {
3
3
  transform: rotate(360deg);
4
4
  }
5
- `,fe=_.div`
5
+ `,he=_.div`
6
6
  display: flex;
7
7
  align-items: center;
8
8
  justify-content: center;
@@ -16,7 +16,7 @@ import{j as s,u as se,r as n,L as te}from"./react-BXazHbBy.js";import{t as a,G a
16
16
  flex-direction: column;
17
17
  text-align: center;
18
18
  }
19
- `,he=_.span`
19
+ `,fe=_.span`
20
20
  flex: none;
21
21
  border-radius: 50%;
22
22
  border-style: solid;
@@ -46,8 +46,8 @@ import{j as s,u as se,r as n,L as te}from"./react-BXazHbBy.js";import{t as a,G a
46
46
  `,xe=_.span`
47
47
  font-size: 14px;
48
48
  font-weight: 600;
49
- `;function _e({label:i,size:d="medium",direction:b="column",className:j}){return s.jsxs(fe,{className:j,"data-testid":"spinner-box","data-direction":b,role:"status","aria-live":"polite","aria-label":i?void 0:a("spinner.loading"),children:[s.jsx(he,{"data-testid":"spinner-box-ring","data-size":d,"aria-hidden":!0}),i?s.jsx(xe,{children:i}):null]})}const be=_(P)`
49
+ `;function _e({label:i,size:d="medium",direction:b="column",className:j}){return s.jsxs(he,{className:j,"data-testid":"spinner-box","data-direction":b,role:"status","aria-live":"polite","aria-label":i?void 0:a("spinner.loading"),children:[s.jsx(fe,{"data-testid":"spinner-box-ring","data-size":d,"aria-hidden":!0}),i?s.jsx(xe,{children:i}):null]})}const be=_(P)`
50
50
  align-self: center;
51
51
  min-width: 200px;
52
52
  margin-top: 8px;
53
- `,O=1e6,A={cover:"",coverName:"",coverHash:"",description:"",links:{website:"",twitter:"",discord:"",facebook:""}};function D(i){return`${(i/1e6).toLocaleString(void 0,{maximumFractionDigits:2})}MB`}function ye(){ie({title:a("seo.storeSettings.title"),noindex:!0});const{session:i,signIn:d}=re(),b=se(),j=ne(),c=i==null?void 0:i.address,{data:S,isLoading:F}=oe(c),[r,m]=n.useState(A),[L,y]=n.useState(A),[k,p]=n.useState(),[g,$]=n.useState(!1),[o,N]=n.useState(null),[h,K]=n.useState({}),z=n.useRef(null);n.useEffect(()=>{if(S){const e=le(S);m(e),y(e),p(void 0),N(e.cover?{url:e.cover,name:e.coverName,hash:e.coverHash}:null)}},[S]),n.useEffect(()=>{let e=!1;return Promise.all(f.map(async t=>[t.name,await ce(t.url)])).then(t=>{e||K(Object.fromEntries(t))}).catch(()=>{}),()=>{e=!0}},[]);const x=n.useMemo(()=>{const e=f.find(l=>r.coverName===`cover/${l.name}`);if(e)return e.name;const t=r.coverHash?f.find(l=>h[l.name]===r.coverHash):void 0;return t==null?void 0:t.name},[r.coverName,r.coverHash,h]);n.useEffect(()=>{o!=null&&o.hash&&f.some(e=>h[e.name]===o.hash)&&N(null)},[h,o]);const I=k!==void 0&&k>O,V=n.useMemo(()=>de.filter(e=>!B(e,r.links[e])),[r.links]),Y=I||V.length>0,w=n.useMemo(()=>JSON.stringify(r)!==JSON.stringify(L),[r,L]),G=w&&!Y&&!g;if(n.useEffect(()=>{if(!w)return;const e=t=>{t.preventDefault()};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[w]),!i)return s.jsxs("section",{className:"store-settings store-settings--signin","aria-label":a("storeSettings.title"),children:[s.jsx("h1",{className:"store-settings__title",children:a("storeSettings.title")}),s.jsx("p",{className:"muted",children:a("storeSettings.signInPrompt")}),s.jsx(be,{variant:"purple",onClick:d,children:a("storeSettings.signIn")})]});function q(e,t){p(void 0),m(l=>({...l,cover:t,coverName:`cover/${e}`,coverHash:""}))}const J=["image/png","image/jpeg","image/webp"];function Q(e){var H;const t=(H=e.target.files)==null?void 0:H[0];if(!t||!J.includes(t.type))return;p(t.size);const l=`cover/${t.name}`,u=new FileReader;u.onload=()=>{const T=u.result;N({url:T,name:l,hash:""}),m(ee=>({...ee,cover:T,coverName:l,coverHash:""}))},u.readAsDataURL(t)}function U(){o&&(p(void 0),m(e=>({...e,cover:o.url,coverName:o.name,coverHash:o.hash})))}function W(e,t){const l=t?(v[e]+t).replace(/\s/g,""):"";m(u=>({...u,links:{...u.links,[e]:l}}))}function X(e){const t=r.links[e];return e==="website"?t:t.replace(v[e],"")}async function Z(){if(!(!c||!i)){$(!0);try{await me(c,r,i.identity),y(r),p(void 0),await j.invalidateQueries({queryKey:["store",c.toLowerCase()]}),R.success(a("storeSettings.saved")),b(`/assets/creator/${c}`)}catch{R.error(a("storeSettings.saveError"))}finally{$(!1)}}}return s.jsxs("section",{className:"store-settings","aria-label":a("storeSettings.title"),children:[s.jsxs("div",{className:"store-settings__head",children:[s.jsxs("div",{className:"store-settings__heading",children:[c?s.jsx(te,{className:"store-settings__back",to:`/assets/creator/${c}`,title:a("storeSettings.back"),"aria-label":a("storeSettings.back"),children:s.jsx(E,{name:"arrow-left"})}):null,s.jsx("h1",{className:"store-settings__title",children:a("storeSettings.title")})]}),c?s.jsxs("a",{className:"store-settings__guest",href:`/assets/creator/${c}`,target:"_blank",rel:"noopener noreferrer",children:[a("storeSettings.seeAsGuest"),s.jsx(E,{name:"external-link"})]}):null]}),F?s.jsx(_e,{size:"large",label:a("storeSettings.loading"),className:"store-settings__loading"}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"field",children:[s.jsx("span",{className:"field__label",children:a("storeSettings.cover")}),s.jsxs("div",{className:"cover-picker",role:"group","aria-label":a("storeSettings.cover"),children:[f.map(e=>{const t=x===e.name;return s.jsx("button",{type:"button",className:`cover-picker__tile${t?" is-selected":""}`,"data-testid":"cover-picker-tile","data-selected":t,"aria-pressed":t,onClick:()=>q(e.name,e.url),children:s.jsx("img",{src:e.url,alt:"",loading:"lazy"})},e.name)}),o?s.jsx("button",{type:"button",className:`cover-picker__tile cover-picker__tile--custom${x?"":" is-selected"}`,"data-testid":"cover-picker-tile","data-variant":"custom","data-selected":!x,"aria-pressed":!x,onClick:U,children:s.jsx("img",{src:o.url,alt:""})}):null,s.jsxs("button",{type:"button",className:"cover-picker__tile cover-picker__upload","data-testid":"cover-picker-tile","data-variant":"upload",onClick:()=>{var e;return(e=z.current)==null?void 0:e.click()},children:[s.jsx(E,{name:"upload"}),s.jsx("span",{children:a("storeSettings.upload")})]}),s.jsx("input",{ref:z,type:"file",accept:"image/png, image/jpeg, image/webp",className:"cover-picker__input","data-testid":"cover-picker-input",onChange:Q})]}),I?s.jsx(M,{message:a("storeSettings.sizeError",{max:D(O),current:D(k)})}):null]}),s.jsxs("label",{className:"field",children:[s.jsx("span",{className:"field__label",children:a("storeSettings.description")}),s.jsx("textarea",{value:r.description,rows:4,disabled:g,onChange:e=>m(t=>({...t,description:e.target.value}))})]}),s.jsxs("label",{className:"field",children:[s.jsx("span",{className:"field__label",children:a("storeSettings.website")}),s.jsx("input",{type:"url",value:r.links.website,placeholder:v.website,disabled:g,onChange:e=>m(t=>({...t,links:{...t.links,website:e.target.value.replace(/\s/g,"")}}))}),B("website",r.links.website)?null:s.jsx(M,{message:a("storeSettings.linkError",{value:v.website})})]}),["twitter","discord","facebook"].map(e=>s.jsxs("label",{className:"field",children:[s.jsx("span",{className:"field__label",children:a(`storeSettings.${e}`)}),s.jsxs("div",{className:"field__prefixed",children:[s.jsx("span",{className:"field__prefix",children:v[e]}),s.jsx("input",{type:"text",value:X(e),disabled:g,onChange:t=>W(e,t.target.value)})]})]},e)),s.jsx("div",{className:"store-settings__actions",children:s.jsx(P,{variant:"purple",className:"store-settings__save","data-testid":"store-settings-save",onClick:()=>void Z(),disabled:!G,children:g?a("storeSettings.saving"):a("storeSettings.save")})})]})]})}export{ye as StoreSettings,ye as default};
53
+ `,O=1e6,A={cover:"",coverName:"",coverHash:"",description:"",links:{website:"",twitter:"",discord:"",facebook:""}};function D(i){return`${(i/1e6).toLocaleString(void 0,{maximumFractionDigits:2})}MB`}function ye(){ie({title:a("seo.storeSettings.title"),noindex:!0});const{session:i,signIn:d}=re(),b=se(),j=ne(),c=i==null?void 0:i.address,{data:S,isLoading:F}=oe(c),[r,m]=n.useState(A),[L,y]=n.useState(A),[k,p]=n.useState(),[g,$]=n.useState(!1),[o,N]=n.useState(null),[f,K]=n.useState({}),z=n.useRef(null);n.useEffect(()=>{if(S){const e=le(S);m(e),y(e),p(void 0),N(e.cover?{url:e.cover,name:e.coverName,hash:e.coverHash}:null)}},[S]),n.useEffect(()=>{let e=!1;return Promise.all(h.map(async t=>[t.name,await ce(t.url)])).then(t=>{e||K(Object.fromEntries(t))}).catch(()=>{}),()=>{e=!0}},[]);const x=n.useMemo(()=>{const e=h.find(l=>r.coverName===`cover/${l.name}`);if(e)return e.name;const t=r.coverHash?h.find(l=>f[l.name]===r.coverHash):void 0;return t==null?void 0:t.name},[r.coverName,r.coverHash,f]);n.useEffect(()=>{o!=null&&o.hash&&h.some(e=>f[e.name]===o.hash)&&N(null)},[f,o]);const I=k!==void 0&&k>O,V=n.useMemo(()=>de.filter(e=>!B(e,r.links[e])),[r.links]),Y=I||V.length>0,w=n.useMemo(()=>JSON.stringify(r)!==JSON.stringify(L),[r,L]),G=w&&!Y&&!g;if(n.useEffect(()=>{if(!w)return;const e=t=>{t.preventDefault()};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[w]),!i)return s.jsxs("section",{className:"store-settings store-settings--signin","aria-label":a("storeSettings.title"),children:[s.jsx("h1",{className:"store-settings__title",children:a("storeSettings.title")}),s.jsx("p",{className:"muted",children:a("storeSettings.signInPrompt")}),s.jsx(be,{variant:"purple",onClick:d,children:a("storeSettings.signIn")})]});function q(e,t){p(void 0),m(l=>({...l,cover:t,coverName:`cover/${e}`,coverHash:""}))}const J=["image/png","image/jpeg","image/webp"];function Q(e){var H;const t=(H=e.target.files)==null?void 0:H[0];if(!t||!J.includes(t.type))return;p(t.size);const l=`cover/${t.name}`,u=new FileReader;u.onload=()=>{const T=u.result;N({url:T,name:l,hash:""}),m(ee=>({...ee,cover:T,coverName:l,coverHash:""}))},u.readAsDataURL(t)}function U(){o&&(p(void 0),m(e=>({...e,cover:o.url,coverName:o.name,coverHash:o.hash})))}function W(e,t){const l=t?(v[e]+t).replace(/\s/g,""):"";m(u=>({...u,links:{...u.links,[e]:l}}))}function X(e){const t=r.links[e];return e==="website"?t:t.replace(v[e],"")}async function Z(){if(!(!c||!i)){$(!0);try{await me(c,r,i.identity),y(r),p(void 0),await j.invalidateQueries({queryKey:["store",c.toLowerCase()]}),R.success(a("storeSettings.saved")),b(`/assets/creator/${c}`)}catch{R.error(a("storeSettings.saveError"))}finally{$(!1)}}}return s.jsxs("section",{className:"store-settings","aria-label":a("storeSettings.title"),children:[s.jsxs("div",{className:"store-settings__head",children:[s.jsxs("div",{className:"store-settings__heading",children:[c?s.jsx(te,{className:"store-settings__back",to:`/assets/creator/${c}`,title:a("storeSettings.back"),"aria-label":a("storeSettings.back"),children:s.jsx(E,{name:"arrow-left"})}):null,s.jsx("h1",{className:"store-settings__title",children:a("storeSettings.title")})]}),c?s.jsxs("a",{className:"store-settings__guest",href:`/assets/creator/${c}`,target:"_blank",rel:"noopener noreferrer",children:[a("storeSettings.seeAsGuest"),s.jsx(E,{name:"external-link"})]}):null]}),F?s.jsx(_e,{size:"large",label:a("storeSettings.loading"),className:"store-settings__loading"}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"field",children:[s.jsx("span",{className:"field__label",children:a("storeSettings.cover")}),s.jsxs("div",{className:"cover-picker",role:"group","aria-label":a("storeSettings.cover"),children:[h.map(e=>{const t=x===e.name;return s.jsx("button",{type:"button",className:`cover-picker__tile${t?" is-selected":""}`,"data-testid":"cover-picker-tile","data-selected":t,"aria-pressed":t,onClick:()=>q(e.name,e.url),children:s.jsx("img",{src:e.url,alt:"",loading:"lazy"})},e.name)}),o?s.jsx("button",{type:"button",className:`cover-picker__tile cover-picker__tile--custom${x?"":" is-selected"}`,"data-testid":"cover-picker-tile","data-variant":"custom","data-selected":!x,"aria-pressed":!x,onClick:U,children:s.jsx("img",{src:o.url,alt:""})}):null,s.jsxs("button",{type:"button",className:"cover-picker__tile cover-picker__upload","data-testid":"cover-picker-tile","data-variant":"upload",onClick:()=>{var e;return(e=z.current)==null?void 0:e.click()},children:[s.jsx(E,{name:"upload"}),s.jsx("span",{children:a("storeSettings.upload")})]}),s.jsx("input",{ref:z,type:"file",accept:"image/png, image/jpeg, image/webp",className:"cover-picker__input","data-testid":"cover-picker-input",onChange:Q})]}),I?s.jsx(M,{message:a("storeSettings.sizeError",{max:D(O),current:D(k)})}):null]}),s.jsxs("label",{className:"field",children:[s.jsx("span",{className:"field__label",children:a("storeSettings.description")}),s.jsx("textarea",{value:r.description,rows:4,disabled:g,onChange:e=>m(t=>({...t,description:e.target.value}))})]}),s.jsxs("label",{className:"field",children:[s.jsx("span",{className:"field__label",children:a("storeSettings.website")}),s.jsx("input",{type:"url",value:r.links.website,placeholder:v.website,disabled:g,onChange:e=>m(t=>({...t,links:{...t.links,website:e.target.value.replace(/\s/g,"")}}))}),B("website",r.links.website)?null:s.jsx(M,{message:a("storeSettings.linkError",{value:v.website})})]}),["twitter","discord","facebook"].map(e=>s.jsxs("label",{className:"field",children:[s.jsx("span",{className:"field__label",children:a(`storeSettings.${e}`)}),s.jsxs("div",{className:"field__prefixed",children:[s.jsx("span",{className:"field__prefix",children:v[e]}),s.jsx("input",{type:"text",value:X(e),disabled:g,onChange:t=>W(e,t.target.value)})]})]},e)),s.jsx("div",{className:"store-settings__actions",children:s.jsx(P,{variant:"purple",className:"store-settings__save","data-testid":"store-settings-save",onClick:()=>void Z(),disabled:!G,children:g?a("storeSettings.saving"):a("storeSettings.save")})})]})]})}export{ye as StoreSettings,ye as default};
@@ -1,4 +1,4 @@
1
- import{a as v,u as k,j as s,N as w,r as p}from"./react-BXazHbBy.js";import{u as y,m as b,t as e,w as C,C as f,x as A,y as S,p as g,s as B,B as I,z as L,e as E}from"./index-N282EqWL.js";import{w as T,S as F}from"./buy-gasless-DITQks7J.js";import"./dcl-schemas-BICTSpB5.js";import"./sentry-CLqlZ0dX.js";import"./ethers-BJDbBwOP.js";import"./intl-CBcMB1D2.js";import"./authorizations-xecfPSH8.js";import"./index-HN6Rk25C.js";import"./sendMetaTransaction-CiO3jI6F.js";import"./trade-encoding-6_dO5FYh.js";const j=B(I)`
1
+ import{a as v,u as k,j as s,N as w,r as p}from"./react-BXazHbBy.js";import{u as y,m as b,t as e,w as C,C as f,x as A,y as S,p as g,s as B,B as I,z as L,e as E}from"./index-C3X5jLeD.js";import{w as T,S as F}from"./buy-gasless-DHSR8j9W.js";import"./dcl-schemas-BICTSpB5.js";import"./sentry-CLqlZ0dX.js";import"./ethers-BJDbBwOP.js";import"./intl-CBcMB1D2.js";import"./authorizations-Bu5ynTut.js";import"./index-HN6Rk25C.js";import"./sendMetaTransaction-CiO3jI6F.js";import"./trade-encoding-Dp_icjFZ.js";const j=B(I)`
2
2
  min-width: 160px;
3
3
  text-align: center;
4
4
  `,M=c=>new Promise(t=>setTimeout(t,c));function P(c,t){const[a,i]=p.useState(c?"pending":"confirmed"),m=t?`${t.owner}-${t.contractAddress}-${t.itemId}`:"";return p.useEffect(()=>{if(!c)return;let r=!1;return(async()=>{let h=!1;for(let n=0;n<20&&!r;n++)try{await T(c,{timeoutMs:15e3}),h=!0;break}catch(d){if(d instanceof F)continue;r||i("failed");return}if(!r){if(!h){i("timed-out");return}if(!t){i("confirmed");return}i("indexing");for(let n=0;n<40&&!r;n++){if(await L(t.owner,t.contractAddress,t.itemId)){r||i("confirmed");return}await M(3e3)}r||i("timed-out")}})(),()=>{r=!0}},[c,m]),a}const R=g.chainId===80002?"https://decentraland.zone/jump":"https://decentraland.org/jump",W=g.chainId===80002?"https://amoy.polygonscan.com/tx/":"https://polygonscan.com/tx/";function V(){const{state:c}=v(),t=k(),{session:a}=y(),i=c==null?void 0:c.txHash,m=(c==null?void 0:c.items)??[],r=c!=null&&c.creditsAdded&&c.creditsAdded>0?c.creditsAdded:null,l=m[0],h=a!=null&&a.address&&(l!=null&&l.contractAddress)&&(l!=null&&l.itemId)?{owner:a.address,contractAddress:l.contractAddress,itemId:l.itemId}:null,n=P(c!=null&&c.settled?void 0:i,h);b({title:e("seo.success.title"),noindex:!0});const d=m;if(d.length===0)return s.jsx(w,{to:"/assets",replace:!0});const _=d[0],u=!!i&&C(a==null?void 0:a.providerType)?s.jsx("a",{className:"success__receipt",href:`${W}${i}`,target:"_blank",rel:"noreferrer",children:e("success.viewTransaction")}):null;return n!=="confirmed"?s.jsx("div",{className:"success",children:s.jsx("div",{className:"success__status",children:n==="pending"||n==="indexing"?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"spinner success__spinner","aria-hidden":!0}),s.jsx("h1",{className:"success__title",children:n==="indexing"?e("success.finalizing"):e("success.processing")}),s.jsx("p",{className:"success__sub",children:n==="indexing"?s.jsxs(s.Fragment,{children:[e("success.indexingBefore")," ",d.length===1?s.jsx("strong",{children:_.name}):e("success.itemCount",{count:d.length})," ",e("success.indexingAfter")]}):s.jsxs(s.Fragment,{children:[e("success.confirmingBefore")," ",d.length===1?s.jsx("strong",{children:_.name}):e("success.itemCount",{count:d.length})," ",e("success.confirmingAfter")]})}),u?s.jsx("div",{className:"success__links",children:u}):null]}):n==="timed-out"?s.jsxs(s.Fragment,{children:[s.jsx("h1",{className:"success__title",children:e("success.stillProcessingTitle")}),s.jsxs("p",{className:"success__sub",children:[e("success.timedOutBefore")," ",s.jsx("button",{className:"link",onClick:()=>t("/activity"),children:e("nav.activity")})," ",e("success.timedOutAfter")]}),u?s.jsx("div",{className:"success__links",children:u}):null,s.jsxs("div",{className:"success__actions",children:[s.jsx(j,{variant:"purple",onClick:()=>t("/activity"),children:e("success.viewActivity")}),s.jsx(j,{variant:"ghost",onClick:()=>t("/assets"),children:e("success.keepShopping")})]})]}):s.jsxs(s.Fragment,{children:[s.jsx("h1",{className:"success__title",children:e("success.failedTitle")}),s.jsx("p",{className:"success__sub",children:e("success.failedBody")}),u?s.jsx("div",{className:"success__links",children:u}):null,s.jsx("div",{className:"success__actions",children:s.jsx(j,{variant:"purple",onClick:()=>t("/assets"),children:e("success.backToShop")})})]})})}):s.jsx("div",{className:"success",children:s.jsxs("div",{className:"success-done",children:[s.jsxs("div",{className:"success-banner",role:"status",children:[s.jsx("span",{className:"success-banner__check","aria-hidden":!0,children:s.jsxs("svg",{viewBox:"0 0 60 60",width:"60",height:"60",children:[s.jsx("circle",{cx:"30",cy:"30",r:"30",fill:"#34ce77"}),s.jsx("path",{d:"M18 31l8 8 16-18",fill:"none",stroke:"#fff",strokeWidth:"4.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),s.jsxs("p",{className:"success-banner__text",children:[s.jsx("b",{children:e("success.bannerTitle")})," ",e("success.bannerBody")]})]}),s.jsxs("div",{className:"success-list",children:[r?s.jsxs("div",{className:"success-credits","data-testid":"success-credits",children:[s.jsx(f,{className:"success-credits__ico"}),s.jsxs("p",{className:"success-credits__text",children:[s.jsx("span",{className:"success-credits__amount",children:e("getCredits.creditsAmount",{credits:r,currency:E.name})})," ",s.jsx("span",{className:"success-credits__added",children:e("getCredits.creditsAdded")})]})]}):null,d.map((o,N)=>{const x=o.quantity??1;return s.jsxs("div",{className:"success-list__row",children:[N>0?s.jsx("span",{className:"success-list__divider","aria-hidden":!0}):null,s.jsxs("div",{className:"success-row",children:[s.jsxs("div",{className:"success-row__thumb",children:[o.thumbnail?s.jsx("img",{src:o.thumbnail,alt:""}):null,s.jsx("span",{className:"success-row__check","aria-hidden":!0,children:s.jsx("svg",{viewBox:"0 0 18 18",width:"12",height:"12",children:s.jsx("path",{d:"M4 9l3.5 3.5L14 5",fill:"none",stroke:"#fff",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),s.jsxs("div",{className:"success-row__info",children:[s.jsxs("div",{className:"success-row__name",title:o.name,children:[o.name||e("buyModal.itemFallback"),x>1?s.jsx("span",{className:"success-row__qty",children:e("cartCheckout.qty",{count:x})}):null]}),o.creator?s.jsx(A,{address:o.creator,className:"success-row__creator",linkToProfile:!0}):null]}),s.jsxs("div",{className:"success-row__price",children:[s.jsx(f,{className:"success-row__price-ico"}),s.jsx("span",{children:S(o.priceCredits*x)})]})]})]},o.id)})]}),u?s.jsx("div",{className:"success__links success-done__receipt",children:u}):null,s.jsxs("div",{className:"success-ctas",children:[s.jsx("button",{className:"success-cta success-cta--ghost",onClick:()=>t("/my-assets"),children:e("success.myAssets")}),s.jsxs("a",{className:"success-cta success-cta--ruby",href:R,target:"_blank",rel:"noreferrer",children:[e("success.tryInWorld"),s.jsx("span",{className:"success-cta__jump","aria-hidden":!0,children:s.jsx("svg",{viewBox:"0 0 24 24",width:"20",height:"20",children:s.jsx("path",{d:"M5 12h12M13 7l5 5-5 5",fill:"none",stroke:"#fcfcfc",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})]})})}export{V as Success,V as default};
@@ -1 +1 @@
1
- import{N as T,j as G,R as I,S as f,k as B,E as M,l as F,W as L,C as g,B as N,b as W,m as E,A as O,n as z,d as _,g as R,o as H,e as V,i as q,p as $}from"./W3MFrameProviderSingleton-B4WegxTX.js";import{au as C}from"./NetworkUtil-xdrSr8Td.js";const b={getGasPriceInEther(n,o){const t=o*n;return Number(t)/1e18},getGasPriceInUSD(n,o,t){const s=b.getGasPriceInEther(o,t);return T.bigNumber(n).times(s).toNumber()},getPriceImpact({sourceTokenAmount:n,sourceTokenPriceInUSD:o,toTokenPriceInUSD:t,toTokenAmount:s}){const c=T.bigNumber(n).times(o),r=T.bigNumber(s).times(t);return c.minus(r).div(c).times(100).toNumber()},getMaxSlippage(n,o){const t=T.bigNumber(n).div(100);return T.multiply(o,t).toNumber()},getProviderFee(n,o=.0085){return T.bigNumber(n).times(o).toString()},isInsufficientNetworkTokenForGas(n,o){const t=o||"0";return T.bigNumber(n).eq(0)?!0:T.bigNumber(T.bigNumber(t)).gt(n)},isInsufficientSourceTokenForSwap(n,o,t){var r,d;const s=(d=(r=t==null?void 0:t.find(l=>l.address===o))==null?void 0:r.quantity)==null?void 0:d.numeric;return T.bigNumber(s||"0").lt(n)}},x=15e4,Q=6,m={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=$({...m}),D={state:e,subscribe(n){return q(e,()=>n(e))},subscribeKey(n,o){return V(e,n,o)},getParams(){var i,u,p,w,h,y,A,S,P;const n=g.state.activeChain,o=((i=g.getAccountData(n))==null?void 0:i.caipAddress)??g.state.activeCaipAddress,t=W.getPlainAddress(o),s=R(),c=H.getConnectorId(g.state.activeChain);if(!t)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=!((w=e.sourceToken)!=null&&w.address)||!((h=e.sourceToken)!=null&&h.decimals)||!T.bigNumber(e.sourceTokenAmount).gt(0),l=!e.sourceTokenAmount;return{networkAddress:s,fromAddress:t,fromCaipAddress:o,sourceTokenAddress:(y=e.sourceToken)==null?void 0:y.address,toTokenAddress:(A=e.toToken)==null?void 0:A.address,toTokenAmount:e.toTokenAmount,toTokenDecimals:(S=e.toToken)==null?void 0:S.decimals,sourceTokenAmount:e.sourceTokenAmount,sourceTokenDecimals:(P=e.sourceToken)==null?void 0:P.decimals,invalidToToken:r,invalidSourceToken:d,invalidSourceTokenAmount:l,availableToSwap:o&&!r&&!d&&!l,isAuthConnector:c===C.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,o){let t=e.tokensPriceMap[n]||0;t||(e.loadingPrices=!0,t=await a.getAddressPrice(n)),o==="sourceToken"?e.sourceTokenPriceInUSD=t:o==="toToken"&&(e.toTokenPriceInUSD=t),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,o=e.sourceToken?{...e.sourceToken}:void 0,t=n&&e.toTokenAmount===""?"1":e.toTokenAmount;a.setSourceTokenAmount(t),a.setToTokenAmount(""),await a.setSourceToken(n),await a.setToToken(o),e.switchingTokens=!1,a.swapTokens()}catch(n){throw e.switchingTokens=!1,n}}},resetState(){e.myTokensWithBalance=m.myTokensWithBalance,e.tokensPriceMap=m.tokensPriceMap,e.initialized=m.initialized,e.initializing=m.initializing,e.switchingTokens=m.switchingTokens,e.sourceToken=m.sourceToken,e.sourceTokenAmount=m.sourceTokenAmount,e.sourceTokenPriceInUSD=m.sourceTokenPriceInUSD,e.toToken=m.toToken,e.toTokenAmount=m.toTokenAmount,e.toTokenPriceInUSD=m.toTokenPriceInUSD,e.networkPrice=m.networkPrice,e.networkTokenSymbol=m.networkTokenSymbol,e.networkBalanceInUSD=m.networkBalanceInUSD,e.inputError=m.inputError},resetValues(){var t;const{networkAddress:n}=a.getParams(),o=(t=e.tokens)==null?void 0:t.find(s=>s.address===n);a.setSourceToken(o),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,f.showError("Failed to initialize swap"),I.goBack()}e.initializing=!1}},async fetchTokens(){var t;const{networkAddress:n}=a.getParams();await a.getNetworkTokenPrice(),await a.getMyTokensWithBalance();const o=(t=e.myTokensWithBalance)==null?void 0:t.find(s=>s.address===n);o&&(e.networkTokenSymbol=o.symbol,a.setSourceToken(o),a.setSourceTokenAmount("0"))},async getTokenList(){var o,t;const n=(o=g.state.activeCaipNetwork)==null?void 0:o.caipNetworkId;if(!(e.caipNetworkId===n&&e.tokens))try{e.tokensLoading=!0;const s=await E.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&&((t=_.SUGGESTED_TOKENS_BY_CHAIN)==null?void 0:t[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 o=e.tokensPriceMap[n];if(o)return o;const t=await N.fetchTokenPrice({addresses:[n]}),s=(t==null?void 0:t.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(),t=(c=(await N.fetchTokenPrice({addresses:[n]}).catch(()=>(f.showError("Failed to fetch network token price"),{fungibles:[]}))).fungibles)==null?void 0:c[0],s=(t==null?void 0:t.price.toString())||"0";e.tokensPriceMap[n]=parseFloat(s),e.networkTokenSymbol=(t==null?void 0:t.symbol)||"",e.networkPrice=s},async getMyTokensWithBalance(n){var s;const o=await z.getMyTokensWithBalance({forceUpdate:n,caipNetwork:g.state.activeCaipNetwork,address:(s=g.getAccountData())==null?void 0:s.address}),t=E.mapBalancesToSwapTokens(o);t&&(await a.getInitialGasPrice(),a.setBalances(t))},setBalances(n){const{networkAddress:o}=a.getParams(),t=g.state.activeCaipNetwork;if(!t)return;const s=n.find(c=>c.address===o);n.forEach(c=>{e.tokensPriceMap[c.address]=c.price||0}),e.myTokensWithBalance=n.filter(c=>c.address.startsWith(t.caipNetworkId)),e.networkBalanceInUSD=s?T.multiply(s.quantity.numeric,s.price).toString():"0"},async getInitialGasPrice(){var o,t;const n=await E.fetchGasPrice();if(!n)return{gasPrice:null,gasPriceInUSD:null};switch((t=(o=g.state)==null?void 0:o.activeCaipNetwork)==null?void 0:t.chainNamespace){case C.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 C.CHAIN.EVM:default:const s=n.standard??"0",c=BigInt(s),r=BigInt(x),d=b.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,o=e.sourceToken,t=e.toToken,s=T.bigNumber(e.sourceTokenAmount).gt(0);if(s||a.setToTokenAmount(""),!t||!o||e.loadingPrices||!s||!n)return;e.loadingQuote=!0;const c=T.bigNumber(e.sourceTokenAmount).times(10**o.decimals).round(0).toFixed(0);try{const i=await N.fetchSwapQuote({userAddress:n,from:o.address,to:t.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){O.open({displayMessage:"Incorrect amount",debugMessage:"Please enter a valid amount"},"error");return}const p=T.bigNumber(u).div(10**t.decimals).toString();a.setToTokenAmount(p),a.hasInsufficientToken(e.sourceTokenAmount,o.address)?e.inputError="Insufficient balance":(e.inputError=void 0,a.setTransactionDetails())}catch(i){const u=await E.handleSwapError(i);e.loadingQuote=!1,e.inputError=u||"Insufficient balance"}},async getTransaction(){const{fromCaipAddress:n,availableToSwap:o}=a.getParams(),t=e.sourceToken,s=e.toToken;if(!(!n||!o||!t||!s||e.loadingQuote))try{e.loadingBuildTransaction=!0;const c=await E.fetchSwapAllowance({userAddress:n,tokenAddress:t.address,sourceTokenAmount:e.sourceTokenAmount,sourceTokenDecimals:t.decimals});let r;return c?r=await a.createSwapTransaction():r=await a.createAllowanceTransaction(),e.loadingBuildTransaction=!1,e.fetchError=!1,r}catch{I.goBack(),f.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:o,toTokenAddress:t}=a.getParams();if(!(!n||!t)){if(!o)throw new Error("createAllowanceTransaction - No source token address found.");try{const s=await N.generateApproveCalldata({from:o,to:t,userAddress:n}),c=W.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{I.goBack(),f.showError("Failed to create approval transaction"),e.approvalTransaction=void 0,e.swapTransaction=void 0,e.fetchError=!0;return}}},async createSwapTransaction(){var d,l;const{networkAddress:n,fromCaipAddress:o,sourceTokenAmount:t}=a.getParams(),s=e.sourceToken,c=e.toToken;if(!o||!t||!s||!c)return;let r=(d=B.parseUnits(t,s.decimals))==null?void 0:d.toString();try{const i=s.address===n;let u=await N.generateSwapCalldata({userAddress:o,from:s.address,to:c.address,amount:r,disableEstimate:!0}),p=BigInt(u.tx.eip155.gas),w=BigInt(u.tx.eip155.gasPrice);if(i&&r){const A=(l=e.myTokensWithBalance)==null?void 0:l.find(S=>S.address===n);if(A){const S=parseInt(A.quantity.decimals,10),P=B.parseUnits(A.quantity.numeric,S)??0n,v=p*w;if(BigInt(r)+v>P){const k=P>v?P-v:0n;k>0n&&(u=await N.generateSwapCalldata({userAddress:o,from:s.address,to:c.address,amount:k.toString(),disableEstimate:!0}),r=k.toString(),p=BigInt(u.tx.eip155.gas),w=BigInt(u.tx.eip155.gasPrice))}}}const h=W.getPlainAddress(u.tx.to);if(!h)throw new Error("SwapController:createSwapTransaction - address is required");const y={data:u.tx.data,to:h,gas:p,gasPrice:w,value:BigInt(i?r??"0":"0"),toAmount:e.toTokenAmount};return e.gasPriceInUSD=b.getGasPriceInUSD(e.networkPrice,p,w),e.approvalTransaction=void 0,e.swapTransaction=y,y}catch{I.goBack(),f.showError("Failed to create transaction"),e.approvalTransaction=void 0,e.swapTransaction=void 0,e.fetchError=!0;return}},onEmbeddedWalletApprovalSuccess(){f.showLoading("Approve limit increase in your wallet"),I.replace("SwapPreview")},async sendTransactionForApproval(n){var c,r,d;const{fromAddress:o,isAuthConnector:t}=a.getParams();e.loadingApprovalTransaction=!0,t?I.pushTransactionStack({onSuccess:a.onEmbeddedWalletApprovalSuccess}):f.showLoading("Approve limit increase in your wallet");try{await B.sendTransaction({address:o,to:n.to,data:n.data,value:n.value,chainNamespace:C.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,f.showError((i==null?void 0:i.displayMessage)||"Transaction error"),M.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:F(C.CHAIN.EVM)===L.ACCOUNT_TYPES.SMART_ACCOUNT}})}},async sendTransactionForSwap(n){var d,l,i,u,p,w,h,y,A,S,P,v;if(!n)return;const{fromAddress:o,toTokenAmount:t,isAuthConnector:s}=a.getParams();e.loadingTransaction=!0;const c=`Swapping ${(d=e.sourceToken)==null?void 0:d.symbol} to ${T.formatNumberToLocalString(t,3)} ${(l=e.toToken)==null?void 0:l.symbol}`,r=`Swapped ${(i=e.sourceToken)==null?void 0:i.symbol} to ${T.formatNumberToLocalString(t,3)} ${(u=e.toToken)==null?void 0:u.symbol}`;s?I.pushTransactionStack({onSuccess(){I.replace("Account"),f.showLoading(c),D.resetState()}}):f.showLoading("Confirm transaction in your wallet");try{const U=[(p=e.sourceToken)==null?void 0:p.address,(w=e.toToken)==null?void 0:w.address].join(","),k=await B.sendTransaction({address:o,to:n.to,data:n.data,value:n.value,chainNamespace:C.CHAIN.EVM});return e.loadingTransaction=!1,f.showSuccess(r),M.sendEvent({type:"track",event:"SWAP_SUCCESS",properties:{network:((h=g.state.activeCaipNetwork)==null?void 0:h.caipNetworkId)||"",swapFromToken:((y=a.state.sourceToken)==null?void 0:y.symbol)||"",swapToToken:((A=a.state.toToken)==null?void 0:A.symbol)||"",swapFromAmount:a.state.sourceTokenAmount||"",swapToAmount:a.state.toTokenAmount||"",isSmartAccount:F(C.CHAIN.EVM)===L.ACCOUNT_TYPES.SMART_ACCOUNT}}),D.resetState(),s||I.replace("Account"),D.getMyTokensWithBalance(U),k}catch(U){const k=U;e.transactionError=k==null?void 0:k.displayMessage,e.loadingTransaction=!1,f.showError((k==null?void 0:k.displayMessage)||"Transaction error"),M.sendEvent({type:"track",event:"SWAP_ERROR",properties:{message:(k==null?void 0:k.displayMessage)||(k==null?void 0:k.message)||"Unknown",network:((S=g.state.activeCaipNetwork)==null?void 0:S.caipNetworkId)||"",swapFromToken:((P=a.state.sourceToken)==null?void 0:P.symbol)||"",swapToToken:((v=a.state.toToken)==null?void 0:v.symbol)||"",swapFromAmount:a.state.sourceTokenAmount||"",swapToAmount:a.state.toTokenAmount||"",isSmartAccount:F(C.CHAIN.EVM)===L.ACCOUNT_TYPES.SMART_ACCOUNT}});return}},hasInsufficientToken(n,o){return b.isInsufficientSourceTokenForSwap(n,o,e.myTokensWithBalance)},setTransactionDetails(){const{toTokenAddress:n,toTokenDecimals:o}=a.getParams();!n||!o||(e.gasPriceInUSD=b.getGasPriceInUSD(e.networkPrice,BigInt(e.gasFee),BigInt(x)),e.priceImpact=b.getPriceImpact({sourceTokenAmount:e.sourceTokenAmount,sourceTokenPriceInUSD:e.sourceTokenPriceInUSD,toTokenPriceInUSD:e.toTokenPriceInUSD,toTokenAmount:e.toTokenAmount}),e.maxSlippage=b.getMaxSlippage(e.slippage,e.toTokenAmount),e.providerFee=b.getProviderFee(e.sourceTokenAmount))}},a=G(D);export{a as S};
1
+ import{N as T,j as G,R as I,S as f,k as B,E as M,l as F,W as L,C as g,B as N,b as W,m as E,A as O,n as z,d as _,g as R,o as H,e as V,i as q,p as $}from"./W3MFrameProviderSingleton-nlgW21N5.js";import{au as C}from"./NetworkUtil-xdrSr8Td.js";const b={getGasPriceInEther(n,o){const t=o*n;return Number(t)/1e18},getGasPriceInUSD(n,o,t){const s=b.getGasPriceInEther(o,t);return T.bigNumber(n).times(s).toNumber()},getPriceImpact({sourceTokenAmount:n,sourceTokenPriceInUSD:o,toTokenPriceInUSD:t,toTokenAmount:s}){const c=T.bigNumber(n).times(o),r=T.bigNumber(s).times(t);return c.minus(r).div(c).times(100).toNumber()},getMaxSlippage(n,o){const t=T.bigNumber(n).div(100);return T.multiply(o,t).toNumber()},getProviderFee(n,o=.0085){return T.bigNumber(n).times(o).toString()},isInsufficientNetworkTokenForGas(n,o){const t=o||"0";return T.bigNumber(n).eq(0)?!0:T.bigNumber(T.bigNumber(t)).gt(n)},isInsufficientSourceTokenForSwap(n,o,t){var r,d;const s=(d=(r=t==null?void 0:t.find(l=>l.address===o))==null?void 0:r.quantity)==null?void 0:d.numeric;return T.bigNumber(s||"0").lt(n)}},x=15e4,Q=6,m={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=$({...m}),D={state:e,subscribe(n){return q(e,()=>n(e))},subscribeKey(n,o){return V(e,n,o)},getParams(){var i,u,p,w,h,y,A,S,P;const n=g.state.activeChain,o=((i=g.getAccountData(n))==null?void 0:i.caipAddress)??g.state.activeCaipAddress,t=W.getPlainAddress(o),s=R(),c=H.getConnectorId(g.state.activeChain);if(!t)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=!((w=e.sourceToken)!=null&&w.address)||!((h=e.sourceToken)!=null&&h.decimals)||!T.bigNumber(e.sourceTokenAmount).gt(0),l=!e.sourceTokenAmount;return{networkAddress:s,fromAddress:t,fromCaipAddress:o,sourceTokenAddress:(y=e.sourceToken)==null?void 0:y.address,toTokenAddress:(A=e.toToken)==null?void 0:A.address,toTokenAmount:e.toTokenAmount,toTokenDecimals:(S=e.toToken)==null?void 0:S.decimals,sourceTokenAmount:e.sourceTokenAmount,sourceTokenDecimals:(P=e.sourceToken)==null?void 0:P.decimals,invalidToToken:r,invalidSourceToken:d,invalidSourceTokenAmount:l,availableToSwap:o&&!r&&!d&&!l,isAuthConnector:c===C.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,o){let t=e.tokensPriceMap[n]||0;t||(e.loadingPrices=!0,t=await a.getAddressPrice(n)),o==="sourceToken"?e.sourceTokenPriceInUSD=t:o==="toToken"&&(e.toTokenPriceInUSD=t),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,o=e.sourceToken?{...e.sourceToken}:void 0,t=n&&e.toTokenAmount===""?"1":e.toTokenAmount;a.setSourceTokenAmount(t),a.setToTokenAmount(""),await a.setSourceToken(n),await a.setToToken(o),e.switchingTokens=!1,a.swapTokens()}catch(n){throw e.switchingTokens=!1,n}}},resetState(){e.myTokensWithBalance=m.myTokensWithBalance,e.tokensPriceMap=m.tokensPriceMap,e.initialized=m.initialized,e.initializing=m.initializing,e.switchingTokens=m.switchingTokens,e.sourceToken=m.sourceToken,e.sourceTokenAmount=m.sourceTokenAmount,e.sourceTokenPriceInUSD=m.sourceTokenPriceInUSD,e.toToken=m.toToken,e.toTokenAmount=m.toTokenAmount,e.toTokenPriceInUSD=m.toTokenPriceInUSD,e.networkPrice=m.networkPrice,e.networkTokenSymbol=m.networkTokenSymbol,e.networkBalanceInUSD=m.networkBalanceInUSD,e.inputError=m.inputError},resetValues(){var t;const{networkAddress:n}=a.getParams(),o=(t=e.tokens)==null?void 0:t.find(s=>s.address===n);a.setSourceToken(o),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,f.showError("Failed to initialize swap"),I.goBack()}e.initializing=!1}},async fetchTokens(){var t;const{networkAddress:n}=a.getParams();await a.getNetworkTokenPrice(),await a.getMyTokensWithBalance();const o=(t=e.myTokensWithBalance)==null?void 0:t.find(s=>s.address===n);o&&(e.networkTokenSymbol=o.symbol,a.setSourceToken(o),a.setSourceTokenAmount("0"))},async getTokenList(){var o,t;const n=(o=g.state.activeCaipNetwork)==null?void 0:o.caipNetworkId;if(!(e.caipNetworkId===n&&e.tokens))try{e.tokensLoading=!0;const s=await E.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&&((t=_.SUGGESTED_TOKENS_BY_CHAIN)==null?void 0:t[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 o=e.tokensPriceMap[n];if(o)return o;const t=await N.fetchTokenPrice({addresses:[n]}),s=(t==null?void 0:t.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(),t=(c=(await N.fetchTokenPrice({addresses:[n]}).catch(()=>(f.showError("Failed to fetch network token price"),{fungibles:[]}))).fungibles)==null?void 0:c[0],s=(t==null?void 0:t.price.toString())||"0";e.tokensPriceMap[n]=parseFloat(s),e.networkTokenSymbol=(t==null?void 0:t.symbol)||"",e.networkPrice=s},async getMyTokensWithBalance(n){var s;const o=await z.getMyTokensWithBalance({forceUpdate:n,caipNetwork:g.state.activeCaipNetwork,address:(s=g.getAccountData())==null?void 0:s.address}),t=E.mapBalancesToSwapTokens(o);t&&(await a.getInitialGasPrice(),a.setBalances(t))},setBalances(n){const{networkAddress:o}=a.getParams(),t=g.state.activeCaipNetwork;if(!t)return;const s=n.find(c=>c.address===o);n.forEach(c=>{e.tokensPriceMap[c.address]=c.price||0}),e.myTokensWithBalance=n.filter(c=>c.address.startsWith(t.caipNetworkId)),e.networkBalanceInUSD=s?T.multiply(s.quantity.numeric,s.price).toString():"0"},async getInitialGasPrice(){var o,t;const n=await E.fetchGasPrice();if(!n)return{gasPrice:null,gasPriceInUSD:null};switch((t=(o=g.state)==null?void 0:o.activeCaipNetwork)==null?void 0:t.chainNamespace){case C.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 C.CHAIN.EVM:default:const s=n.standard??"0",c=BigInt(s),r=BigInt(x),d=b.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,o=e.sourceToken,t=e.toToken,s=T.bigNumber(e.sourceTokenAmount).gt(0);if(s||a.setToTokenAmount(""),!t||!o||e.loadingPrices||!s||!n)return;e.loadingQuote=!0;const c=T.bigNumber(e.sourceTokenAmount).times(10**o.decimals).round(0).toFixed(0);try{const i=await N.fetchSwapQuote({userAddress:n,from:o.address,to:t.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){O.open({displayMessage:"Incorrect amount",debugMessage:"Please enter a valid amount"},"error");return}const p=T.bigNumber(u).div(10**t.decimals).toString();a.setToTokenAmount(p),a.hasInsufficientToken(e.sourceTokenAmount,o.address)?e.inputError="Insufficient balance":(e.inputError=void 0,a.setTransactionDetails())}catch(i){const u=await E.handleSwapError(i);e.loadingQuote=!1,e.inputError=u||"Insufficient balance"}},async getTransaction(){const{fromCaipAddress:n,availableToSwap:o}=a.getParams(),t=e.sourceToken,s=e.toToken;if(!(!n||!o||!t||!s||e.loadingQuote))try{e.loadingBuildTransaction=!0;const c=await E.fetchSwapAllowance({userAddress:n,tokenAddress:t.address,sourceTokenAmount:e.sourceTokenAmount,sourceTokenDecimals:t.decimals});let r;return c?r=await a.createSwapTransaction():r=await a.createAllowanceTransaction(),e.loadingBuildTransaction=!1,e.fetchError=!1,r}catch{I.goBack(),f.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:o,toTokenAddress:t}=a.getParams();if(!(!n||!t)){if(!o)throw new Error("createAllowanceTransaction - No source token address found.");try{const s=await N.generateApproveCalldata({from:o,to:t,userAddress:n}),c=W.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{I.goBack(),f.showError("Failed to create approval transaction"),e.approvalTransaction=void 0,e.swapTransaction=void 0,e.fetchError=!0;return}}},async createSwapTransaction(){var d,l;const{networkAddress:n,fromCaipAddress:o,sourceTokenAmount:t}=a.getParams(),s=e.sourceToken,c=e.toToken;if(!o||!t||!s||!c)return;let r=(d=B.parseUnits(t,s.decimals))==null?void 0:d.toString();try{const i=s.address===n;let u=await N.generateSwapCalldata({userAddress:o,from:s.address,to:c.address,amount:r,disableEstimate:!0}),p=BigInt(u.tx.eip155.gas),w=BigInt(u.tx.eip155.gasPrice);if(i&&r){const A=(l=e.myTokensWithBalance)==null?void 0:l.find(S=>S.address===n);if(A){const S=parseInt(A.quantity.decimals,10),P=B.parseUnits(A.quantity.numeric,S)??0n,v=p*w;if(BigInt(r)+v>P){const k=P>v?P-v:0n;k>0n&&(u=await N.generateSwapCalldata({userAddress:o,from:s.address,to:c.address,amount:k.toString(),disableEstimate:!0}),r=k.toString(),p=BigInt(u.tx.eip155.gas),w=BigInt(u.tx.eip155.gasPrice))}}}const h=W.getPlainAddress(u.tx.to);if(!h)throw new Error("SwapController:createSwapTransaction - address is required");const y={data:u.tx.data,to:h,gas:p,gasPrice:w,value:BigInt(i?r??"0":"0"),toAmount:e.toTokenAmount};return e.gasPriceInUSD=b.getGasPriceInUSD(e.networkPrice,p,w),e.approvalTransaction=void 0,e.swapTransaction=y,y}catch{I.goBack(),f.showError("Failed to create transaction"),e.approvalTransaction=void 0,e.swapTransaction=void 0,e.fetchError=!0;return}},onEmbeddedWalletApprovalSuccess(){f.showLoading("Approve limit increase in your wallet"),I.replace("SwapPreview")},async sendTransactionForApproval(n){var c,r,d;const{fromAddress:o,isAuthConnector:t}=a.getParams();e.loadingApprovalTransaction=!0,t?I.pushTransactionStack({onSuccess:a.onEmbeddedWalletApprovalSuccess}):f.showLoading("Approve limit increase in your wallet");try{await B.sendTransaction({address:o,to:n.to,data:n.data,value:n.value,chainNamespace:C.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,f.showError((i==null?void 0:i.displayMessage)||"Transaction error"),M.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:F(C.CHAIN.EVM)===L.ACCOUNT_TYPES.SMART_ACCOUNT}})}},async sendTransactionForSwap(n){var d,l,i,u,p,w,h,y,A,S,P,v;if(!n)return;const{fromAddress:o,toTokenAmount:t,isAuthConnector:s}=a.getParams();e.loadingTransaction=!0;const c=`Swapping ${(d=e.sourceToken)==null?void 0:d.symbol} to ${T.formatNumberToLocalString(t,3)} ${(l=e.toToken)==null?void 0:l.symbol}`,r=`Swapped ${(i=e.sourceToken)==null?void 0:i.symbol} to ${T.formatNumberToLocalString(t,3)} ${(u=e.toToken)==null?void 0:u.symbol}`;s?I.pushTransactionStack({onSuccess(){I.replace("Account"),f.showLoading(c),D.resetState()}}):f.showLoading("Confirm transaction in your wallet");try{const U=[(p=e.sourceToken)==null?void 0:p.address,(w=e.toToken)==null?void 0:w.address].join(","),k=await B.sendTransaction({address:o,to:n.to,data:n.data,value:n.value,chainNamespace:C.CHAIN.EVM});return e.loadingTransaction=!1,f.showSuccess(r),M.sendEvent({type:"track",event:"SWAP_SUCCESS",properties:{network:((h=g.state.activeCaipNetwork)==null?void 0:h.caipNetworkId)||"",swapFromToken:((y=a.state.sourceToken)==null?void 0:y.symbol)||"",swapToToken:((A=a.state.toToken)==null?void 0:A.symbol)||"",swapFromAmount:a.state.sourceTokenAmount||"",swapToAmount:a.state.toTokenAmount||"",isSmartAccount:F(C.CHAIN.EVM)===L.ACCOUNT_TYPES.SMART_ACCOUNT}}),D.resetState(),s||I.replace("Account"),D.getMyTokensWithBalance(U),k}catch(U){const k=U;e.transactionError=k==null?void 0:k.displayMessage,e.loadingTransaction=!1,f.showError((k==null?void 0:k.displayMessage)||"Transaction error"),M.sendEvent({type:"track",event:"SWAP_ERROR",properties:{message:(k==null?void 0:k.displayMessage)||(k==null?void 0:k.message)||"Unknown",network:((S=g.state.activeCaipNetwork)==null?void 0:S.caipNetworkId)||"",swapFromToken:((P=a.state.sourceToken)==null?void 0:P.symbol)||"",swapToToken:((v=a.state.toToken)==null?void 0:v.symbol)||"",swapFromAmount:a.state.sourceTokenAmount||"",swapToAmount:a.state.toTokenAmount||"",isSmartAccount:F(C.CHAIN.EVM)===L.ACCOUNT_TYPES.SMART_ACCOUNT}});return}},hasInsufficientToken(n,o){return b.isInsufficientSourceTokenForSwap(n,o,e.myTokensWithBalance)},setTransactionDetails(){const{toTokenAddress:n,toTokenDecimals:o}=a.getParams();!n||!o||(e.gasPriceInUSD=b.getGasPriceInUSD(e.networkPrice,BigInt(e.gasFee),BigInt(x)),e.priceImpact=b.getPriceImpact({sourceTokenAmount:e.sourceTokenAmount,sourceTokenPriceInUSD:e.sourceTokenPriceInUSD,toTokenPriceInUSD:e.toTokenPriceInUSD,toTokenAmount:e.toTokenAmount}),e.maxSlippage=b.getMaxSlippage(e.slippage,e.toTokenAmount),e.providerFee=b.getProviderFee(e.sourceTokenAmount))}},a=G(D);export{a as S};
@@ -1,4 +1,4 @@
1
- import{r as e,j as c}from"./react-BXazHbBy.js";import{s as d,G as r}from"./index-N282EqWL.js";import{n as x}from"./emotion-CSxEP8yM.js";const h=d("span",x("block"))`
1
+ import{r as e,j as c}from"./react-BXazHbBy.js";import{s as d,G as r}from"./index-C3X5jLeD.js";import{n as x}from"./emotion-CSxEP8yM.js";const h=d("span",x("block"))`
2
2
  position: relative;
3
3
  display: ${({block:t})=>t?"flex":"inline-flex"};
4
4
  ${({block:t})=>t?"width: 100%;":""}
@@ -1 +1 @@
1
- var ve=Object.defineProperty;var xe=(r,t,e)=>t in r?ve(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var p=(r,t,e)=>xe(r,typeof t!="symbol"?t+"":t,e);import{W as ue,a as Q,C as ge,B as Ce,f as X}from"./ethers-BJDbBwOP.js";import{p as Ee,d as B}from"./dcl-schemas-BICTSpB5.js";import{c as ee}from"./react-BXazHbBy.js";import{aU as Re}from"./index-N282EqWL.js";import{a as te,g as re}from"./index-HN6Rk25C.js";import{c as q,e as Ie}from"./index-CO8EAj61.js";import{s as Pe}from"./sendMetaTransaction-CiO3jI6F.js";import"./sentry-CLqlZ0dX.js";import"./intl-CBcMB1D2.js";import"./events-DQ172AOg.js";async function be(r){const t=await de();if(t){const e=await new ue(t).getSigner().getChainId();if(r===e)return t}return q.createProvider(Ee.ProviderType.NETWORK,r)}async function de(){try{return await q.getProvider()}catch{try{const{provider:r}=await q.tryPreviousConnection();return r}catch{return null}}}function ne(r){return Math.floor(r/1e3)}function ae(r){switch(r.assetType){case B.TradeAssetType.ERC721:return r.tokenId;case B.TradeAssetType.COLLECTION_ITEM:return r.itemId;case B.TradeAssetType.ERC20:return r.amount;default:return console.error("Invalid asset type:",r),""}}function Ae(r){var t;return{checks:{uses:r.checks.uses,expiration:ne(r.checks.expiration),effective:ne(r.checks.effective),salt:Q(r.checks.salt,32),contractSignatureIndex:r.checks.contractSignatureIndex,signerSignatureIndex:r.checks.signerSignatureIndex,allowedRoot:Q(r.checks.allowedRoot,32),externalChecks:(t=r.checks.externalChecks)==null?void 0:t.map(e=>({contractAddress:e.contractAddress,selector:e.selector,value:e.value?e.value:"0x",required:e.required}))},sent:r.sent.map(e=>({assetType:e.assetType,contractAddress:e.contractAddress,value:ae(e),extra:e.extra?e.extra:"0x"})),received:r.received.map(e=>({assetType:e.assetType,contractAddress:e.contractAddress,value:ae(e),extra:e.extra?e.extra:"0x",beneficiary:e.beneficiary}))}}function se(r,t){const e=Ae(r);return{signer:r.signer,signature:r.signature,...e,checks:{...e.checks,allowedProof:[]},sent:e.sent.map(i=>({...i,beneficiary:t}))}}async function Se(r){const t=await r.request({method:"eth_chainId",params:[]});let e;return typeof t=="string"?e=parseInt(t,16):e=t,e}async function Fe(r){const t=await be(r);return new ue(t)}const S=new Ie.EventEmitter;var C;(function(r){r.ERROR="error",r.SUCCESS="success",r.PROMPT="prompt",r.ACCEPT="accept",r.REJECT="reject"})(C||(C={}));let Le="https://transactions-api.decentraland.org/v1";const Ue=()=>Le,ke=()=>new Promise((r,t)=>{const e=()=>{S.removeAllListeners(C.REJECT),r(!0)},i=()=>{S.removeAllListeners(C.ACCEPT),t(new Error("User rejected transaction"))};S.addListener(C.ACCEPT,e),S.addListener(C.REJECT,i)});async function oe(...r){const[t,e,...i]=r;try{const s=await de();if(!s)throw new Error("Provider not connected");const c=await Se(s),l=await Fe(t.chainId),I=new ge(t.address,t.abi,l),T=await(typeof e=="function"?e(I.populateTransaction):I.populateTransaction[e](...i));if(c===t.chainId){const v=l.getSigner();if(s.isMagic||s.isThirdweb){let k=Ce.from(0);try{const _=await v.getGasPrice(),U=await v.estimateGas(T);k=_.mul(U)}catch{}if(!k.isZero()){const _=ke(),U=await v.getBalance();S.emit(C.PROMPT,{transactionGasPrice:X(k),userBalance:X(U),chainId:t.chainId}),await _}}const b=await v.sendTransaction(T);return S.emit(C.SUCCESS,{txHash:b.hash}),b.hash}else{const v=await Pe(s,l,T.data,t,{serverURL:Ue()});return S.emit(C.SUCCESS,{txHash:v}),v}}catch(s){const c={type:C.ERROR,error:s};throw S.emit(C.ERROR,c),s}}var M={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */var _e=M.exports,ie;function Oe(){return ie||(ie=1,(function(r,t){(function(e){var i=t&&!t.nodeType&&t,s=r&&!r.nodeType&&r,c=typeof ee=="object"&&ee;(c.global===c||c.window===c||c.self===c)&&(e=c);var l,I=2147483647,T=36,v=1,b=26,k=38,_=700,U=72,G=128,J="-",he=/^xn--/,fe=/[^\x20-\x7E]/,pe=/[\x2E\u3002\uFF0E\uFF61]/g,ye={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},D=T-v,E=Math.floor,O=String.fromCharCode,N;function F(n){throw new RangeError(ye[n])}function $(n,a){for(var o=n.length,u=[];o--;)u[o]=a(n[o]);return u}function V(n,a){var o=n.split("@"),u="";o.length>1&&(u=o[0]+"@",n=o[1]),n=n.replace(pe,".");var d=n.split("."),y=$(d,a).join(".");return u+y}function H(n){for(var a=[],o=0,u=n.length,d,y;o<u;)d=n.charCodeAt(o++),d>=55296&&d<=56319&&o<u?(y=n.charCodeAt(o++),(y&64512)==56320?a.push(((d&1023)<<10)+(y&1023)+65536):(a.push(d),o--)):a.push(d);return a}function W(n){return $(n,function(a){var o="";return a>65535&&(a-=65536,o+=O(a>>>10&1023|55296),a=56320|a&1023),o+=O(a),o}).join("")}function Te(n){return n-48<10?n-22:n-65<26?n-65:n-97<26?n-97:T}function Y(n,a){return n+22+75*(n<26)-((a!=0)<<5)}function Z(n,a,o){var u=0;for(n=o?E(n/_):n>>1,n+=E(n/a);n>D*b>>1;u+=T)n=E(n/D);return E(u+(D+1)*n/(n+k))}function K(n){var a=[],o=n.length,u,d=0,y=G,h=U,w,x,R,P,f,m,g,A,L;for(w=n.lastIndexOf(J),w<0&&(w=0),x=0;x<w;++x)n.charCodeAt(x)>=128&&F("not-basic"),a.push(n.charCodeAt(x));for(R=w>0?w+1:0;R<o;){for(P=d,f=1,m=T;R>=o&&F("invalid-input"),g=Te(n.charCodeAt(R++)),(g>=T||g>E((I-d)/f))&&F("overflow"),d+=g*f,A=m<=h?v:m>=h+b?b:m-h,!(g<A);m+=T)L=T-A,f>E(I/L)&&F("overflow"),f*=L;u=a.length+1,h=Z(d-P,u,P==0),E(d/u)>I-y&&F("overflow"),y+=E(d/u),d%=u,a.splice(d++,0,y)}return W(a)}function z(n){var a,o,u,d,y,h,w,x,R,P,f,m=[],g,A,L,j;for(n=H(n),g=n.length,a=G,o=0,y=U,h=0;h<g;++h)f=n[h],f<128&&m.push(O(f));for(u=d=m.length,d&&m.push(J);u<g;){for(w=I,h=0;h<g;++h)f=n[h],f>=a&&f<w&&(w=f);for(A=u+1,w-a>E((I-o)/A)&&F("overflow"),o+=(w-a)*A,a=w,h=0;h<g;++h)if(f=n[h],f<a&&++o>I&&F("overflow"),f==a){for(x=o,R=T;P=R<=y?v:R>=y+b?b:R-y,!(x<P);R+=T)j=x-P,L=T-P,m.push(O(Y(P+j%L,0))),x=E(j/L);m.push(O(Y(x,0))),y=Z(o,A,u==d),o=0,++u}++o,++a}return m.join("")}function we(n){return V(n,function(a){return he.test(a)?K(a.slice(4).toLowerCase()):a})}function me(n){return V(n,function(a){return fe.test(a)?"xn--"+z(a):a})}if(l={version:"1.4.1",ucs2:{decode:H,encode:W},decode:K,encode:z,toASCII:me,toUnicode:we},i&&s)if(r.exports==i)s.exports=l;else for(N in l)l.hasOwnProperty(N)&&(i[N]=l[N]);else e.punycode=l})(_e)})(M,M.exports)),M.exports}Oe();var le=(function(r){function t(){var i=this||self;return delete r.prototype.__magic__,i}if(typeof globalThis=="object")return globalThis;if(this)return t();r.defineProperty(r.prototype,"__magic__",{configurable:!0,get:t});var e=__magic__;return e})(Object),Me=le.URL;le.URLSearchParams;var Ne={URL:Me};class ce extends Error{constructor(e,i,s){super(e);p(this,"status");p(this,"data");this.status=i,this.data=s}}const De=3,je=1e3,Be=[400,401,403,404,409,422],qe=(globalThis==null?void 0:globalThis.URL)??Ne.URL;class Ge{constructor(t,e){p(this,"baseUrl");p(this,"retries");p(this,"retryDelay");p(this,"nonRetryableStatuses");p(this,"identity");p(this,"sleep",t=>new Promise(e=>{setTimeout(e,t)}));p(this,"getIdentity",()=>this.identity instanceof Function?this.identity():this.identity);p(this,"rawFetch",(t,e)=>{const i=new qe(t,this.baseUrl),s=(e==null?void 0:e.identity)??this.getIdentity();return Re.signedFetchFactory()(i.toString(),{...e,identity:s})});p(this,"fetch",async(t,e)=>{for(let i=0;i<=this.retries;i++)try{let s,c;try{s=await this.rawFetch(t,e);const l=await s.text();l.length===0?c={ok:!0,data:null}:c=JSON.parse(l)}catch(l){throw new ce(l.message,void 0,null)}if(!s.ok||c.ok===!1){const l=c.message??c.error;throw new ce(l??`Request failed with status code ${s.status}`,s.status,c.data)}return c.ok===!0?c.data:c}catch(s){if(console.error(`[API] HTTP request failed: ${s.message||""}`,s),this.retries===i||s.status&&this.nonRetryableStatuses.includes(s.status))throw s;await this.sleep(this.retryDelay)}throw new Error("Unreachable code")});this.baseUrl=t,this.identity=e==null?void 0:e.identity,this.retries=(e==null?void 0:e.retries)??De,this.retryDelay=(e==null?void 0:e.retryDelay)??je,this.nonRetryableStatuses=(e==null?void 0:e.nonRetryableStatuses)??Be}}class Je extends Ge{constructor(e,i,s){super(i,s);p(this,"signer");p(this,"addTrade",async e=>this.fetch("/v1/trades",{method:"POST",body:JSON.stringify(e),metadata:{signer:this.signer,intent:"dcl:create-trade"},headers:{"Content-Type":"application/json"}}));p(this,"fetchTrade",async e=>this.fetch(`/v1/trades/${e}`,{method:"GET"}));this.signer=e}}class tt{constructor(t,e,i){p(this,"tradesAPI");this.tradesAPI=new Je(t,e,{identity:i,retries:0})}async addTrade(t){return this.tradesAPI.addTrade(t)}async fetchTrade(t){return this.tradesAPI.fetchTrade(t)}async accept(t,e){const i=te(t.contract),s=re(i,t.chainId),c=se(t,e);return oe(s,"accept",[c])}async cancel(t,e){const i=te(t.contract),s=re(i,t.chainId),c=se(t,e);return oe(s,"cancelSignature",[c])}}export{tt as TradeService};
1
+ var ve=Object.defineProperty;var xe=(r,t,e)=>t in r?ve(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var p=(r,t,e)=>xe(r,typeof t!="symbol"?t+"":t,e);import{W as ue,a as Q,C as ge,B as Ce,f as X}from"./ethers-BJDbBwOP.js";import{p as Ee,d as B}from"./dcl-schemas-BICTSpB5.js";import{c as ee}from"./react-BXazHbBy.js";import{aU as Re}from"./index-C3X5jLeD.js";import{a as te,g as re}from"./index-HN6Rk25C.js";import{c as q,e as Ie}from"./index-DY_9EV49.js";import{s as Pe}from"./sendMetaTransaction-CiO3jI6F.js";import"./sentry-CLqlZ0dX.js";import"./intl-CBcMB1D2.js";import"./events-DQ172AOg.js";async function be(r){const t=await de();if(t){const e=await new ue(t).getSigner().getChainId();if(r===e)return t}return q.createProvider(Ee.ProviderType.NETWORK,r)}async function de(){try{return await q.getProvider()}catch{try{const{provider:r}=await q.tryPreviousConnection();return r}catch{return null}}}function ne(r){return Math.floor(r/1e3)}function ae(r){switch(r.assetType){case B.TradeAssetType.ERC721:return r.tokenId;case B.TradeAssetType.COLLECTION_ITEM:return r.itemId;case B.TradeAssetType.ERC20:return r.amount;default:return console.error("Invalid asset type:",r),""}}function Ae(r){var t;return{checks:{uses:r.checks.uses,expiration:ne(r.checks.expiration),effective:ne(r.checks.effective),salt:Q(r.checks.salt,32),contractSignatureIndex:r.checks.contractSignatureIndex,signerSignatureIndex:r.checks.signerSignatureIndex,allowedRoot:Q(r.checks.allowedRoot,32),externalChecks:(t=r.checks.externalChecks)==null?void 0:t.map(e=>({contractAddress:e.contractAddress,selector:e.selector,value:e.value?e.value:"0x",required:e.required}))},sent:r.sent.map(e=>({assetType:e.assetType,contractAddress:e.contractAddress,value:ae(e),extra:e.extra?e.extra:"0x"})),received:r.received.map(e=>({assetType:e.assetType,contractAddress:e.contractAddress,value:ae(e),extra:e.extra?e.extra:"0x",beneficiary:e.beneficiary}))}}function se(r,t){const e=Ae(r);return{signer:r.signer,signature:r.signature,...e,checks:{...e.checks,allowedProof:[]},sent:e.sent.map(i=>({...i,beneficiary:t}))}}async function Se(r){const t=await r.request({method:"eth_chainId",params:[]});let e;return typeof t=="string"?e=parseInt(t,16):e=t,e}async function Fe(r){const t=await be(r);return new ue(t)}const S=new Ie.EventEmitter;var C;(function(r){r.ERROR="error",r.SUCCESS="success",r.PROMPT="prompt",r.ACCEPT="accept",r.REJECT="reject"})(C||(C={}));let Le="https://transactions-api.decentraland.org/v1";const Ue=()=>Le,ke=()=>new Promise((r,t)=>{const e=()=>{S.removeAllListeners(C.REJECT),r(!0)},i=()=>{S.removeAllListeners(C.ACCEPT),t(new Error("User rejected transaction"))};S.addListener(C.ACCEPT,e),S.addListener(C.REJECT,i)});async function oe(...r){const[t,e,...i]=r;try{const s=await de();if(!s)throw new Error("Provider not connected");const c=await Se(s),l=await Fe(t.chainId),I=new ge(t.address,t.abi,l),T=await(typeof e=="function"?e(I.populateTransaction):I.populateTransaction[e](...i));if(c===t.chainId){const v=l.getSigner();if(s.isMagic||s.isThirdweb){let k=Ce.from(0);try{const _=await v.getGasPrice(),U=await v.estimateGas(T);k=_.mul(U)}catch{}if(!k.isZero()){const _=ke(),U=await v.getBalance();S.emit(C.PROMPT,{transactionGasPrice:X(k),userBalance:X(U),chainId:t.chainId}),await _}}const b=await v.sendTransaction(T);return S.emit(C.SUCCESS,{txHash:b.hash}),b.hash}else{const v=await Pe(s,l,T.data,t,{serverURL:Ue()});return S.emit(C.SUCCESS,{txHash:v}),v}}catch(s){const c={type:C.ERROR,error:s};throw S.emit(C.ERROR,c),s}}var M={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */var _e=M.exports,ie;function Oe(){return ie||(ie=1,(function(r,t){(function(e){var i=t&&!t.nodeType&&t,s=r&&!r.nodeType&&r,c=typeof ee=="object"&&ee;(c.global===c||c.window===c||c.self===c)&&(e=c);var l,I=2147483647,T=36,v=1,b=26,k=38,_=700,U=72,G=128,J="-",he=/^xn--/,fe=/[^\x20-\x7E]/,pe=/[\x2E\u3002\uFF0E\uFF61]/g,ye={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},D=T-v,E=Math.floor,O=String.fromCharCode,N;function F(n){throw new RangeError(ye[n])}function $(n,a){for(var o=n.length,u=[];o--;)u[o]=a(n[o]);return u}function V(n,a){var o=n.split("@"),u="";o.length>1&&(u=o[0]+"@",n=o[1]),n=n.replace(pe,".");var d=n.split("."),y=$(d,a).join(".");return u+y}function H(n){for(var a=[],o=0,u=n.length,d,y;o<u;)d=n.charCodeAt(o++),d>=55296&&d<=56319&&o<u?(y=n.charCodeAt(o++),(y&64512)==56320?a.push(((d&1023)<<10)+(y&1023)+65536):(a.push(d),o--)):a.push(d);return a}function W(n){return $(n,function(a){var o="";return a>65535&&(a-=65536,o+=O(a>>>10&1023|55296),a=56320|a&1023),o+=O(a),o}).join("")}function Te(n){return n-48<10?n-22:n-65<26?n-65:n-97<26?n-97:T}function Y(n,a){return n+22+75*(n<26)-((a!=0)<<5)}function Z(n,a,o){var u=0;for(n=o?E(n/_):n>>1,n+=E(n/a);n>D*b>>1;u+=T)n=E(n/D);return E(u+(D+1)*n/(n+k))}function K(n){var a=[],o=n.length,u,d=0,y=G,h=U,w,x,R,P,f,m,g,A,L;for(w=n.lastIndexOf(J),w<0&&(w=0),x=0;x<w;++x)n.charCodeAt(x)>=128&&F("not-basic"),a.push(n.charCodeAt(x));for(R=w>0?w+1:0;R<o;){for(P=d,f=1,m=T;R>=o&&F("invalid-input"),g=Te(n.charCodeAt(R++)),(g>=T||g>E((I-d)/f))&&F("overflow"),d+=g*f,A=m<=h?v:m>=h+b?b:m-h,!(g<A);m+=T)L=T-A,f>E(I/L)&&F("overflow"),f*=L;u=a.length+1,h=Z(d-P,u,P==0),E(d/u)>I-y&&F("overflow"),y+=E(d/u),d%=u,a.splice(d++,0,y)}return W(a)}function z(n){var a,o,u,d,y,h,w,x,R,P,f,m=[],g,A,L,j;for(n=H(n),g=n.length,a=G,o=0,y=U,h=0;h<g;++h)f=n[h],f<128&&m.push(O(f));for(u=d=m.length,d&&m.push(J);u<g;){for(w=I,h=0;h<g;++h)f=n[h],f>=a&&f<w&&(w=f);for(A=u+1,w-a>E((I-o)/A)&&F("overflow"),o+=(w-a)*A,a=w,h=0;h<g;++h)if(f=n[h],f<a&&++o>I&&F("overflow"),f==a){for(x=o,R=T;P=R<=y?v:R>=y+b?b:R-y,!(x<P);R+=T)j=x-P,L=T-P,m.push(O(Y(P+j%L,0))),x=E(j/L);m.push(O(Y(x,0))),y=Z(o,A,u==d),o=0,++u}++o,++a}return m.join("")}function we(n){return V(n,function(a){return he.test(a)?K(a.slice(4).toLowerCase()):a})}function me(n){return V(n,function(a){return fe.test(a)?"xn--"+z(a):a})}if(l={version:"1.4.1",ucs2:{decode:H,encode:W},decode:K,encode:z,toASCII:me,toUnicode:we},i&&s)if(r.exports==i)s.exports=l;else for(N in l)l.hasOwnProperty(N)&&(i[N]=l[N]);else e.punycode=l})(_e)})(M,M.exports)),M.exports}Oe();var le=(function(r){function t(){var i=this||self;return delete r.prototype.__magic__,i}if(typeof globalThis=="object")return globalThis;if(this)return t();r.defineProperty(r.prototype,"__magic__",{configurable:!0,get:t});var e=__magic__;return e})(Object),Me=le.URL;le.URLSearchParams;var Ne={URL:Me};class ce extends Error{constructor(e,i,s){super(e);p(this,"status");p(this,"data");this.status=i,this.data=s}}const De=3,je=1e3,Be=[400,401,403,404,409,422],qe=(globalThis==null?void 0:globalThis.URL)??Ne.URL;class Ge{constructor(t,e){p(this,"baseUrl");p(this,"retries");p(this,"retryDelay");p(this,"nonRetryableStatuses");p(this,"identity");p(this,"sleep",t=>new Promise(e=>{setTimeout(e,t)}));p(this,"getIdentity",()=>this.identity instanceof Function?this.identity():this.identity);p(this,"rawFetch",(t,e)=>{const i=new qe(t,this.baseUrl),s=(e==null?void 0:e.identity)??this.getIdentity();return Re.signedFetchFactory()(i.toString(),{...e,identity:s})});p(this,"fetch",async(t,e)=>{for(let i=0;i<=this.retries;i++)try{let s,c;try{s=await this.rawFetch(t,e);const l=await s.text();l.length===0?c={ok:!0,data:null}:c=JSON.parse(l)}catch(l){throw new ce(l.message,void 0,null)}if(!s.ok||c.ok===!1){const l=c.message??c.error;throw new ce(l??`Request failed with status code ${s.status}`,s.status,c.data)}return c.ok===!0?c.data:c}catch(s){if(console.error(`[API] HTTP request failed: ${s.message||""}`,s),this.retries===i||s.status&&this.nonRetryableStatuses.includes(s.status))throw s;await this.sleep(this.retryDelay)}throw new Error("Unreachable code")});this.baseUrl=t,this.identity=e==null?void 0:e.identity,this.retries=(e==null?void 0:e.retries)??De,this.retryDelay=(e==null?void 0:e.retryDelay)??je,this.nonRetryableStatuses=(e==null?void 0:e.nonRetryableStatuses)??Be}}class Je extends Ge{constructor(e,i,s){super(i,s);p(this,"signer");p(this,"addTrade",async e=>this.fetch("/v1/trades",{method:"POST",body:JSON.stringify(e),metadata:{signer:this.signer,intent:"dcl:create-trade"},headers:{"Content-Type":"application/json"}}));p(this,"fetchTrade",async e=>this.fetch(`/v1/trades/${e}`,{method:"GET"}));this.signer=e}}class tt{constructor(t,e,i){p(this,"tradesAPI");this.tradesAPI=new Je(t,e,{identity:i,retries:0})}async addTrade(t){return this.tradesAPI.addTrade(t)}async fetchTrade(t){return this.tradesAPI.fetchTrade(t)}async accept(t,e){const i=te(t.contract),s=re(i,t.chainId),c=se(t,e);return oe(s,"accept",[c])}async cancel(t,e){const i=te(t.contract),s=re(i,t.chainId),c=se(t,e);return oe(s,"cancelSignature",[c])}}export{tt as TradeService};