@m0-foundation/swap-component 0.0.1
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.
- package/dist/m0-swap-component/ConstantsUtil-btJ3XIXu.js +28 -0
- package/dist/m0-swap-component/ConstantsUtil-btJ3XIXu.js.map +1 -0
- package/dist/m0-swap-component/HelpersUtil-5wkO4kIW.js +142 -0
- package/dist/m0-swap-component/HelpersUtil-5wkO4kIW.js.map +1 -0
- package/dist/m0-swap-component/PhArrowCircleDown-BiDIiYXi.js +76 -0
- package/dist/m0-swap-component/PhArrowCircleDown-BiDIiYXi.js.map +1 -0
- package/dist/m0-swap-component/PhArrowClockwise-BRnlxNUR.js +76 -0
- package/dist/m0-swap-component/PhArrowClockwise-BRnlxNUR.js.map +1 -0
- package/dist/m0-swap-component/PhArrowDown-Co2hyXIs.js +76 -0
- package/dist/m0-swap-component/PhArrowDown-Co2hyXIs.js.map +1 -0
- package/dist/m0-swap-component/PhArrowLeft-Cb8ijwK6.js +76 -0
- package/dist/m0-swap-component/PhArrowLeft-Cb8ijwK6.js.map +1 -0
- package/dist/m0-swap-component/PhArrowRight-B9t--Gmh.js +76 -0
- package/dist/m0-swap-component/PhArrowRight-B9t--Gmh.js.map +1 -0
- package/dist/m0-swap-component/PhArrowSquareOut-eGBMEr5T.js +76 -0
- package/dist/m0-swap-component/PhArrowSquareOut-eGBMEr5T.js.map +1 -0
- package/dist/m0-swap-component/PhArrowUp-CjSpT-xh.js +76 -0
- package/dist/m0-swap-component/PhArrowUp-CjSpT-xh.js.map +1 -0
- package/dist/m0-swap-component/PhArrowUpRight-B8u6wk-A.js +76 -0
- package/dist/m0-swap-component/PhArrowUpRight-B8u6wk-A.js.map +1 -0
- package/dist/m0-swap-component/PhArrowsClockwise-CBcfV6j6.js +76 -0
- package/dist/m0-swap-component/PhArrowsClockwise-CBcfV6j6.js.map +1 -0
- package/dist/m0-swap-component/PhArrowsDownUp-CMVR84b1.js +76 -0
- package/dist/m0-swap-component/PhArrowsDownUp-CMVR84b1.js.map +1 -0
- package/dist/m0-swap-component/PhArrowsLeftRight-CmXk8rs2.js +76 -0
- package/dist/m0-swap-component/PhArrowsLeftRight-CmXk8rs2.js.map +1 -0
- package/dist/m0-swap-component/PhBank-BigtjnS8.js +76 -0
- package/dist/m0-swap-component/PhBank-BigtjnS8.js.map +1 -0
- package/dist/m0-swap-component/PhBrowser-BOulLD8D.js +76 -0
- package/dist/m0-swap-component/PhBrowser-BOulLD8D.js.map +1 -0
- package/dist/m0-swap-component/PhCaretDown-BvvZ65ad.js +76 -0
- package/dist/m0-swap-component/PhCaretDown-BvvZ65ad.js.map +1 -0
- package/dist/m0-swap-component/PhCaretLeft-DtwjZbZ7.js +76 -0
- package/dist/m0-swap-component/PhCaretLeft-DtwjZbZ7.js.map +1 -0
- package/dist/m0-swap-component/PhCaretRight-C8LuSZkO.js +76 -0
- package/dist/m0-swap-component/PhCaretRight-C8LuSZkO.js.map +1 -0
- package/dist/m0-swap-component/PhCaretUp-B2lAObip.js +76 -0
- package/dist/m0-swap-component/PhCaretUp-B2lAObip.js.map +1 -0
- package/dist/m0-swap-component/PhCheck-DQtuVrQf.js +76 -0
- package/dist/m0-swap-component/PhCheck-DQtuVrQf.js.map +1 -0
- package/dist/m0-swap-component/PhCircleHalf-CXfZ0QZv.js +76 -0
- package/dist/m0-swap-component/PhCircleHalf-CXfZ0QZv.js.map +1 -0
- package/dist/m0-swap-component/PhClock-CXsmuc_a.js +76 -0
- package/dist/m0-swap-component/PhClock-CXsmuc_a.js.map +1 -0
- package/dist/m0-swap-component/PhCompass-Cg-qnMon.js +76 -0
- package/dist/m0-swap-component/PhCompass-Cg-qnMon.js.map +1 -0
- package/dist/m0-swap-component/PhCopy-kGRKcvb4.js +76 -0
- package/dist/m0-swap-component/PhCopy-kGRKcvb4.js.map +1 -0
- package/dist/m0-swap-component/PhCreditCard-jYFausLO.js +76 -0
- package/dist/m0-swap-component/PhCreditCard-jYFausLO.js.map +1 -0
- package/dist/m0-swap-component/PhCurrencyDollar-C8vSY3fy.js +76 -0
- package/dist/m0-swap-component/PhCurrencyDollar-C8vSY3fy.js.map +1 -0
- package/dist/m0-swap-component/PhDesktop-AczlBCho.js +76 -0
- package/dist/m0-swap-component/PhDesktop-AczlBCho.js.map +1 -0
- package/dist/m0-swap-component/PhDeviceMobile-3rFbdWLA.js +76 -0
- package/dist/m0-swap-component/PhDeviceMobile-3rFbdWLA.js.map +1 -0
- package/dist/m0-swap-component/PhDotsThree-cJsXXsvY.js +76 -0
- package/dist/m0-swap-component/PhDotsThree-cJsXXsvY.js.map +1 -0
- package/dist/m0-swap-component/PhEnvelope-C1bxHVXw.js +76 -0
- package/dist/m0-swap-component/PhEnvelope-C1bxHVXw.js.map +1 -0
- package/dist/m0-swap-component/PhFunnelSimple-DhqB9fsu.js +76 -0
- package/dist/m0-swap-component/PhFunnelSimple-DhqB9fsu.js.map +1 -0
- package/dist/m0-swap-component/PhGlobe-BFp6kx95.js +76 -0
- package/dist/m0-swap-component/PhGlobe-BFp6kx95.js.map +1 -0
- package/dist/m0-swap-component/PhIdentificationCard-BdYxckWB.js +76 -0
- package/dist/m0-swap-component/PhIdentificationCard-BdYxckWB.js.map +1 -0
- package/dist/m0-swap-component/PhImage-CXxX5oq3.js +76 -0
- package/dist/m0-swap-component/PhImage-CXxX5oq3.js.map +1 -0
- package/dist/m0-swap-component/PhInfo-BcuP36hY.js +76 -0
- package/dist/m0-swap-component/PhInfo-BcuP36hY.js.map +1 -0
- package/dist/m0-swap-component/PhLightbulb-DkWwRl94.js +76 -0
- package/dist/m0-swap-component/PhLightbulb-DkWwRl94.js.map +1 -0
- package/dist/m0-swap-component/PhMagnifyingGlass-B_fFjslY.js +76 -0
- package/dist/m0-swap-component/PhMagnifyingGlass-B_fFjslY.js.map +1 -0
- package/dist/m0-swap-component/PhPaperPlaneRight-BIzGG3QW.js +76 -0
- package/dist/m0-swap-component/PhPaperPlaneRight-BIzGG3QW.js.map +1 -0
- package/dist/m0-swap-component/PhPlus-BGosT2zu.js +76 -0
- package/dist/m0-swap-component/PhPlus-BGosT2zu.js.map +1 -0
- package/dist/m0-swap-component/PhPower-BMqDnP1n.js +76 -0
- package/dist/m0-swap-component/PhPower-BMqDnP1n.js.map +1 -0
- package/dist/m0-swap-component/PhPuzzlePiece-DNMpiJNU.js +76 -0
- package/dist/m0-swap-component/PhPuzzlePiece-DNMpiJNU.js.map +1 -0
- package/dist/m0-swap-component/PhQrCode-DrHkqrU4.js +76 -0
- package/dist/m0-swap-component/PhQrCode-DrHkqrU4.js.map +1 -0
- package/dist/m0-swap-component/PhQuestion-zTfvwqNz.js +76 -0
- package/dist/m0-swap-component/PhQuestion-zTfvwqNz.js.map +1 -0
- package/dist/m0-swap-component/PhQuestionMark-h3Nk1Yf1.js +76 -0
- package/dist/m0-swap-component/PhQuestionMark-h3Nk1Yf1.js.map +1 -0
- package/dist/m0-swap-component/PhSealCheck-DPPqSt6G.js +76 -0
- package/dist/m0-swap-component/PhSealCheck-DPPqSt6G.js.map +1 -0
- package/dist/m0-swap-component/PhSignOut-CJgnrE_v.js +76 -0
- package/dist/m0-swap-component/PhSignOut-CJgnrE_v.js.map +1 -0
- package/dist/m0-swap-component/PhSpinner-CMTEIWbw.js +76 -0
- package/dist/m0-swap-component/PhSpinner-CMTEIWbw.js.map +1 -0
- package/dist/m0-swap-component/PhTrash-CeDVW4am.js +76 -0
- package/dist/m0-swap-component/PhTrash-CeDVW4am.js.map +1 -0
- package/dist/m0-swap-component/PhUser-lQ9WUtAV.js +76 -0
- package/dist/m0-swap-component/PhUser-lQ9WUtAV.js.map +1 -0
- package/dist/m0-swap-component/PhVault-EnLnS_IQ.js +76 -0
- package/dist/m0-swap-component/PhVault-EnLnS_IQ.js.map +1 -0
- package/dist/m0-swap-component/PhWallet-CUeDZydd.js +76 -0
- package/dist/m0-swap-component/PhWallet-CUeDZydd.js.map +1 -0
- package/dist/m0-swap-component/PhWarning-CokeGZs2.js +76 -0
- package/dist/m0-swap-component/PhWarning-CokeGZs2.js.map +1 -0
- package/dist/m0-swap-component/PhWarningCircle-vWtA7S0R.js +76 -0
- package/dist/m0-swap-component/PhWarningCircle-vWtA7S0R.js.map +1 -0
- package/dist/m0-swap-component/PhX-DwCRIvoc.js +76 -0
- package/dist/m0-swap-component/PhX-DwCRIvoc.js.map +1 -0
- package/dist/m0-swap-component/data-capture-BmovBbKV.js +573 -0
- package/dist/m0-swap-component/data-capture-BmovBbKV.js.map +1 -0
- package/dist/m0-swap-component/email-B4niz3Ms.js +445 -0
- package/dist/m0-swap-component/email-B4niz3Ms.js.map +1 -0
- package/dist/m0-swap-component/embedded-wallet-D6bzjX_K.js +988 -0
- package/dist/m0-swap-component/embedded-wallet-D6bzjX_K.js.map +1 -0
- package/dist/m0-swap-component/features-EhJNVE-M.js +355 -0
- package/dist/m0-swap-component/features-EhJNVE-M.js.map +1 -0
- package/dist/m0-swap-component/if-defined-2CMpVr2R.js +12 -0
- package/dist/m0-swap-component/if-defined-2CMpVr2R.js.map +1 -0
- package/dist/m0-swap-component/index-B4xuj7uR.js +965 -0
- package/dist/m0-swap-component/index-B4xuj7uR.js.map +1 -0
- package/dist/m0-swap-component/index-BVZ66GYf.js +206 -0
- package/dist/m0-swap-component/index-BVZ66GYf.js.map +1 -0
- package/dist/m0-swap-component/index-BZXyMieH.js +150 -0
- package/dist/m0-swap-component/index-BZXyMieH.js.map +1 -0
- package/dist/m0-swap-component/index-Bj5sA_Ri.js +252 -0
- package/dist/m0-swap-component/index-Bj5sA_Ri.js.map +1 -0
- package/dist/m0-swap-component/index-Bs-pPJYj.js +129 -0
- package/dist/m0-swap-component/index-Bs-pPJYj.js.map +1 -0
- package/dist/m0-swap-component/index-CMS76VPf.js +474 -0
- package/dist/m0-swap-component/index-CMS76VPf.js.map +1 -0
- package/dist/m0-swap-component/index-CoMTkqee.js +95 -0
- package/dist/m0-swap-component/index-CoMTkqee.js.map +1 -0
- package/dist/m0-swap-component/index-DE0OtbL2.js +3566 -0
- package/dist/m0-swap-component/index-DE0OtbL2.js.map +1 -0
- package/dist/m0-swap-component/index-DEG-YczD.js +231 -0
- package/dist/m0-swap-component/index-DEG-YczD.js.map +1 -0
- package/dist/m0-swap-component/index-DY_Ijq_4.js +4345 -0
- package/dist/m0-swap-component/index-DY_Ijq_4.js.map +1 -0
- package/dist/m0-swap-component/index-IRpGhIhy.js +9394 -0
- package/dist/m0-swap-component/index-IRpGhIhy.js.map +1 -0
- package/dist/m0-swap-component/index-Z70nBYWG.js +113 -0
- package/dist/m0-swap-component/index-Z70nBYWG.js.map +1 -0
- package/dist/m0-swap-component/index-iNFotRMa.js +73 -0
- package/dist/m0-swap-component/index-iNFotRMa.js.map +1 -0
- package/dist/m0-swap-component/index-n1fooC-v.js +37757 -0
- package/dist/m0-swap-component/index-n1fooC-v.js.map +1 -0
- package/dist/m0-swap-component/index.esm.js +2 -0
- package/dist/m0-swap-component/index.esm.js.map +1 -0
- package/dist/m0-swap-component/loader.esm.js.map +1 -0
- package/dist/m0-swap-component/m0-swap-component.esm.js +48 -0
- package/dist/m0-swap-component/m0-swap-component.esm.js.map +1 -0
- package/dist/m0-swap-component/native-CPtqJIn7.js +18 -0
- package/dist/m0-swap-component/native-CPtqJIn7.js.map +1 -0
- package/dist/m0-swap-component/onramp-BppY2eDR.js +1003 -0
- package/dist/m0-swap-component/onramp-BppY2eDR.js.map +1 -0
- package/dist/m0-swap-component/pay-with-exchange-BJYQgTMB.js +639 -0
- package/dist/m0-swap-component/pay-with-exchange-BJYQgTMB.js.map +1 -0
- package/dist/m0-swap-component/property-BN-VaT99.js +625 -0
- package/dist/m0-swap-component/property-BN-VaT99.js.map +1 -0
- package/dist/m0-swap-component/receive-BptRM_5_.js +281 -0
- package/dist/m0-swap-component/receive-BptRM_5_.js.map +1 -0
- package/dist/m0-swap-component/ref-3xALOvo5.js +25 -0
- package/dist/m0-swap-component/ref-3xALOvo5.js.map +1 -0
- package/dist/m0-swap-component/send-BCyHM4Zr.js +1408 -0
- package/dist/m0-swap-component/send-BCyHM4Zr.js.map +1 -0
- package/dist/m0-swap-component/socials-BbajCSWV.js +824 -0
- package/dist/m0-swap-component/socials-BbajCSWV.js.map +1 -0
- package/dist/m0-swap-component/swap-module-5ZLM-vAV.js +140887 -0
- package/dist/m0-swap-component/swap-module-5ZLM-vAV.js.map +1 -0
- package/dist/m0-swap-component/swap-module.entry.esm.js.map +1 -0
- package/dist/m0-swap-component/swap-module.entry.js +15 -0
- package/dist/m0-swap-component/swaps-DyGe65DR.js +2121 -0
- package/dist/m0-swap-component/swaps-DyGe65DR.js.map +1 -0
- package/dist/m0-swap-component/transactions-BZ9l4zt5.js +60 -0
- package/dist/m0-swap-component/transactions-BZ9l4zt5.js.map +1 -0
- package/dist/m0-swap-component/utils-RCeZbvdb.js +95 -0
- package/dist/m0-swap-component/utils-RCeZbvdb.js.map +1 -0
- package/dist/m0-swap-component/w3m-modal-D0HWVPsj.js +2097 -0
- package/dist/m0-swap-component/w3m-modal-D0HWVPsj.js.map +1 -0
- package/dist/m0-swap-component/wui-button-BeTWD3Va.js +223 -0
- package/dist/m0-swap-component/wui-button-BeTWD3Va.js.map +1 -0
- package/dist/m0-swap-component/wui-email-input-CgnfUH0c.js +65 -0
- package/dist/m0-swap-component/wui-email-input-CgnfUH0c.js.map +1 -0
- package/dist/m0-swap-component/wui-icon-B0uTDhW-.js +4 -0
- package/dist/m0-swap-component/wui-icon-B0uTDhW-.js.map +1 -0
- package/dist/m0-swap-component/wui-icon-box-s87lODBB.js +4 -0
- package/dist/m0-swap-component/wui-icon-box-s87lODBB.js.map +1 -0
- package/dist/m0-swap-component/wui-icon-link-BFpV9kPE.js +127 -0
- package/dist/m0-swap-component/wui-icon-link-BFpV9kPE.js.map +1 -0
- package/dist/m0-swap-component/wui-image-BvjxoR51.js +4 -0
- package/dist/m0-swap-component/wui-image-BvjxoR51.js.map +1 -0
- package/dist/m0-swap-component/wui-input-amount-CWQfP3RO.js +182 -0
- package/dist/m0-swap-component/wui-input-amount-CWQfP3RO.js.map +1 -0
- package/dist/m0-swap-component/wui-input-text-g0sN4B2y.js +4 -0
- package/dist/m0-swap-component/wui-input-text-g0sN4B2y.js.map +1 -0
- package/dist/m0-swap-component/wui-link-VqM3wLny.js +123 -0
- package/dist/m0-swap-component/wui-link-VqM3wLny.js.map +1 -0
- package/dist/m0-swap-component/wui-list-item-BIijofqN.js +170 -0
- package/dist/m0-swap-component/wui-list-item-BIijofqN.js.map +1 -0
- package/dist/m0-swap-component/wui-list-social-C7GhkRc8.js +119 -0
- package/dist/m0-swap-component/wui-list-social-C7GhkRc8.js.map +1 -0
- package/dist/m0-swap-component/wui-list-token-C94lmAbT.js +134 -0
- package/dist/m0-swap-component/wui-list-token-C94lmAbT.js.map +1 -0
- package/dist/m0-swap-component/wui-list-wallet-C7fnQvCW.js +622 -0
- package/dist/m0-swap-component/wui-list-wallet-C7fnQvCW.js.map +1 -0
- package/dist/m0-swap-component/wui-loading-spinner-CW2_5SKA.js +4 -0
- package/dist/m0-swap-component/wui-loading-spinner-CW2_5SKA.js.map +1 -0
- package/dist/m0-swap-component/wui-loading-thumbnail-y3sGkT5j.js +337 -0
- package/dist/m0-swap-component/wui-loading-thumbnail-y3sGkT5j.js.map +1 -0
- package/dist/m0-swap-component/wui-qr-code-DekJTDGf.js +3412 -0
- package/dist/m0-swap-component/wui-qr-code-DekJTDGf.js.map +1 -0
- package/dist/m0-swap-component/wui-separator-DMZIL_Av.js +67 -0
- package/dist/m0-swap-component/wui-separator-DMZIL_Av.js.map +1 -0
- package/dist/m0-swap-component/wui-shimmer-CVFC8fMx.js +4 -0
- package/dist/m0-swap-component/wui-shimmer-CVFC8fMx.js.map +1 -0
- package/dist/m0-swap-component/wui-text-BS_lZKY4.js +1127 -0
- package/dist/m0-swap-component/wui-text-BS_lZKY4.js.map +1 -0
- package/dist/m0-swap-component/wui-token-button-CsOFoNJG.js +214 -0
- package/dist/m0-swap-component/wui-token-button-CsOFoNJG.js.map +1 -0
- package/dist/m0-swap-component/wui-visual-hU2Mkyrv.js +565 -0
- package/dist/m0-swap-component/wui-visual-hU2Mkyrv.js.map +1 -0
- package/dist/m0-swap-component/wui-wallet-switch-CWbdtfbN.js +459 -0
- package/dist/m0-swap-component/wui-wallet-switch-CWbdtfbN.js.map +1 -0
- package/dist/types/components/swap-module/balances.d.ts +16 -0
- package/dist/types/components/swap-module/chains.d.ts +16 -0
- package/dist/types/components/swap-module/store.d.ts +34 -0
- package/dist/types/components/swap-module/swap-module.d.ts +113 -0
- package/dist/types/components/swap-module/utils/constants.d.ts +7 -0
- package/dist/types/components/swap-module/utils/formatters.d.ts +23 -0
- package/dist/types/components/swap-module/utils/reown.d.ts +59 -0
- package/dist/types/components/swap-module/utils/wallet.d.ts +83 -0
- package/dist/types/components.d.ts +165 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/stencil-public-runtime.d.ts +1732 -0
- package/loader/cdn.js +1 -0
- package/loader/index.cjs.js +1 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +1 -0
- package/loader/index.js +2 -0
- package/package.json +60 -0
|
@@ -0,0 +1,3566 @@
|
|
|
1
|
+
import { d as css, a as i, b, r as resetStyles, e as elementStyles, c as customElement, n as CoreHelperUtil, h as ChainController, _ as ParseUtil, j as ConstantsUtil, m as ConnectionController, ad as ContractUtil, ae as ProviderController, af as FetchUtil, O as OptionsController, y as NumberUtil, ag as getNativeTokenAddress, Z as HelpersUtil, ah as proxy, D as AssetUtil, o as EventsController, p as SnackController, B as BalanceUtil, M as ModalController, ai as subscribeKey, aj as subscribe, C as ConnectorController, R as RouterController, L as vars, U as UiHelperUtil, i as i$1, z as MathUtil } from './swap-module-5ZLM-vAV.js';
|
|
2
|
+
import { n, r, e } from './wui-text-BS_lZKY4.js';
|
|
3
|
+
import { o } from './if-defined-2CMpVr2R.js';
|
|
4
|
+
import './wui-button-BeTWD3Va.js';
|
|
5
|
+
import './wui-icon-B0uTDhW-.js';
|
|
6
|
+
import './wui-icon-link-BFpV9kPE.js';
|
|
7
|
+
import './wui-image-BvjxoR51.js';
|
|
8
|
+
import './wui-list-item-BIijofqN.js';
|
|
9
|
+
import './wui-loading-spinner-CW2_5SKA.js';
|
|
10
|
+
import './wui-wallet-switch-CWbdtfbN.js';
|
|
11
|
+
import './wui-separator-DMZIL_Av.js';
|
|
12
|
+
import './utils-RCeZbvdb.js';
|
|
13
|
+
import './wui-shimmer-CVFC8fMx.js';
|
|
14
|
+
import './index-DY_Ijq_4.js';
|
|
15
|
+
import 'buffer';
|
|
16
|
+
import 'ox/BlockOverrides';
|
|
17
|
+
import 'ox/erc8010';
|
|
18
|
+
import 'ox/AbiConstructor';
|
|
19
|
+
import 'ox/AbiFunction';
|
|
20
|
+
import 'ox/erc6492';
|
|
21
|
+
import 'events';
|
|
22
|
+
import 'ox';
|
|
23
|
+
import 'ox/tempo';
|
|
24
|
+
import 'ox/Hex';
|
|
25
|
+
import 'ox/Secp256k1';
|
|
26
|
+
import 'ox/Signature';
|
|
27
|
+
import './index-CoMTkqee.js';
|
|
28
|
+
import './index-BZXyMieH.js';
|
|
29
|
+
import './index-Bs-pPJYj.js';
|
|
30
|
+
import './index-iNFotRMa.js';
|
|
31
|
+
|
|
32
|
+
var styles$9 = css `
|
|
33
|
+
:host {
|
|
34
|
+
position: relative;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
button {
|
|
38
|
+
display: flex;
|
|
39
|
+
justify-content: center;
|
|
40
|
+
align-items: center;
|
|
41
|
+
background-color: transparent;
|
|
42
|
+
padding: ${({ spacing }) => spacing[1]};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* -- Colors --------------------------------------------------- */
|
|
46
|
+
button[data-type='accent'] wui-icon {
|
|
47
|
+
color: ${({ tokens }) => tokens.core.iconAccentPrimary};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
button[data-type='neutral'][data-variant='primary'] wui-icon {
|
|
51
|
+
color: ${({ tokens }) => tokens.theme.iconInverse};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
button[data-type='neutral'][data-variant='secondary'] wui-icon {
|
|
55
|
+
color: ${({ tokens }) => tokens.theme.iconDefault};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
button[data-type='success'] wui-icon {
|
|
59
|
+
color: ${({ tokens }) => tokens.core.iconSuccess};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
button[data-type='error'] wui-icon {
|
|
63
|
+
color: ${({ tokens }) => tokens.core.iconError};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* -- Sizes --------------------------------------------------- */
|
|
67
|
+
button[data-size='xs'] {
|
|
68
|
+
width: 16px;
|
|
69
|
+
height: 16px;
|
|
70
|
+
|
|
71
|
+
border-radius: ${({ borderRadius }) => borderRadius[1]};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
button[data-size='sm'] {
|
|
75
|
+
width: 20px;
|
|
76
|
+
height: 20px;
|
|
77
|
+
border-radius: ${({ borderRadius }) => borderRadius[1]};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
button[data-size='md'] {
|
|
81
|
+
width: 24px;
|
|
82
|
+
height: 24px;
|
|
83
|
+
border-radius: ${({ borderRadius }) => borderRadius[2]};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
button[data-size='lg'] {
|
|
87
|
+
width: 28px;
|
|
88
|
+
height: 28px;
|
|
89
|
+
border-radius: ${({ borderRadius }) => borderRadius[2]};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
button[data-size='xs'] wui-icon {
|
|
93
|
+
width: 8px;
|
|
94
|
+
height: 8px;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
button[data-size='sm'] wui-icon {
|
|
98
|
+
width: 12px;
|
|
99
|
+
height: 12px;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
button[data-size='md'] wui-icon {
|
|
103
|
+
width: 16px;
|
|
104
|
+
height: 16px;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
button[data-size='lg'] wui-icon {
|
|
108
|
+
width: 20px;
|
|
109
|
+
height: 20px;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/* -- Hover --------------------------------------------------- */
|
|
113
|
+
@media (hover: hover) {
|
|
114
|
+
button[data-type='accent']:hover:enabled {
|
|
115
|
+
background-color: ${({ tokens }) => tokens.core.foregroundAccent010};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
button[data-variant='primary'][data-type='neutral']:hover:enabled {
|
|
119
|
+
background-color: ${({ tokens }) => tokens.theme.foregroundSecondary};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
button[data-variant='secondary'][data-type='neutral']:hover:enabled {
|
|
123
|
+
background-color: ${({ tokens }) => tokens.theme.foregroundSecondary};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
button[data-type='success']:hover:enabled {
|
|
127
|
+
background-color: ${({ tokens }) => tokens.core.backgroundSuccess};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
button[data-type='error']:hover:enabled {
|
|
131
|
+
background-color: ${({ tokens }) => tokens.core.backgroundError};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* -- Focus --------------------------------------------------- */
|
|
136
|
+
button:focus-visible {
|
|
137
|
+
box-shadow: 0 0 0 4px ${({ tokens }) => tokens.core.foregroundAccent020};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/* -- Properties --------------------------------------------------- */
|
|
141
|
+
button[data-full-width='true'] {
|
|
142
|
+
width: 100%;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
:host([fullWidth]) {
|
|
146
|
+
width: 100%;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
button[disabled] {
|
|
150
|
+
opacity: 0.5;
|
|
151
|
+
cursor: not-allowed;
|
|
152
|
+
}
|
|
153
|
+
`;
|
|
154
|
+
|
|
155
|
+
var __decorate$9 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
156
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
157
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
158
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
159
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
160
|
+
};
|
|
161
|
+
let WuiIconButton = class WuiIconButton extends i {
|
|
162
|
+
constructor() {
|
|
163
|
+
super(...arguments);
|
|
164
|
+
this.icon = 'card';
|
|
165
|
+
this.variant = 'primary';
|
|
166
|
+
this.type = 'accent';
|
|
167
|
+
this.size = 'md';
|
|
168
|
+
this.iconSize = undefined;
|
|
169
|
+
this.fullWidth = false;
|
|
170
|
+
this.disabled = false;
|
|
171
|
+
}
|
|
172
|
+
render() {
|
|
173
|
+
return b `<button
|
|
174
|
+
data-variant=${this.variant}
|
|
175
|
+
data-type=${this.type}
|
|
176
|
+
data-size=${this.size}
|
|
177
|
+
data-full-width=${this.fullWidth}
|
|
178
|
+
?disabled=${this.disabled}
|
|
179
|
+
>
|
|
180
|
+
<wui-icon color="inherit" name=${this.icon} size=${o(this.iconSize)}></wui-icon>
|
|
181
|
+
</button>`;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
WuiIconButton.styles = [resetStyles, elementStyles, styles$9];
|
|
185
|
+
__decorate$9([
|
|
186
|
+
n()
|
|
187
|
+
], WuiIconButton.prototype, "icon", void 0);
|
|
188
|
+
__decorate$9([
|
|
189
|
+
n()
|
|
190
|
+
], WuiIconButton.prototype, "variant", void 0);
|
|
191
|
+
__decorate$9([
|
|
192
|
+
n()
|
|
193
|
+
], WuiIconButton.prototype, "type", void 0);
|
|
194
|
+
__decorate$9([
|
|
195
|
+
n()
|
|
196
|
+
], WuiIconButton.prototype, "size", void 0);
|
|
197
|
+
__decorate$9([
|
|
198
|
+
n()
|
|
199
|
+
], WuiIconButton.prototype, "iconSize", void 0);
|
|
200
|
+
__decorate$9([
|
|
201
|
+
n({ type: Boolean })
|
|
202
|
+
], WuiIconButton.prototype, "fullWidth", void 0);
|
|
203
|
+
__decorate$9([
|
|
204
|
+
n({ type: Boolean })
|
|
205
|
+
], WuiIconButton.prototype, "disabled", void 0);
|
|
206
|
+
WuiIconButton = __decorate$9([
|
|
207
|
+
customElement('wui-icon-button')
|
|
208
|
+
], WuiIconButton);
|
|
209
|
+
|
|
210
|
+
const AppKitPayErrorCodes = {
|
|
211
|
+
INVALID_PAYMENT_CONFIG: 'INVALID_PAYMENT_CONFIG',
|
|
212
|
+
INVALID_RECIPIENT: 'INVALID_RECIPIENT',
|
|
213
|
+
INVALID_ASSET: 'INVALID_ASSET',
|
|
214
|
+
INVALID_AMOUNT: 'INVALID_AMOUNT',
|
|
215
|
+
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
|
|
216
|
+
UNABLE_TO_INITIATE_PAYMENT: 'UNABLE_TO_INITIATE_PAYMENT',
|
|
217
|
+
INVALID_CHAIN_NAMESPACE: 'INVALID_CHAIN_NAMESPACE',
|
|
218
|
+
GENERIC_PAYMENT_ERROR: 'GENERIC_PAYMENT_ERROR',
|
|
219
|
+
UNABLE_TO_GET_EXCHANGES: 'UNABLE_TO_GET_EXCHANGES',
|
|
220
|
+
ASSET_NOT_SUPPORTED: 'ASSET_NOT_SUPPORTED',
|
|
221
|
+
UNABLE_TO_GET_PAY_URL: 'UNABLE_TO_GET_PAY_URL',
|
|
222
|
+
UNABLE_TO_GET_BUY_STATUS: 'UNABLE_TO_GET_BUY_STATUS',
|
|
223
|
+
UNABLE_TO_GET_TOKEN_BALANCES: 'UNABLE_TO_GET_TOKEN_BALANCES',
|
|
224
|
+
UNABLE_TO_GET_QUOTE: 'UNABLE_TO_GET_QUOTE',
|
|
225
|
+
UNABLE_TO_GET_QUOTE_STATUS: 'UNABLE_TO_GET_QUOTE_STATUS',
|
|
226
|
+
INVALID_RECIPIENT_ADDRESS_FOR_ASSET: 'INVALID_RECIPIENT_ADDRESS_FOR_ASSET'
|
|
227
|
+
};
|
|
228
|
+
const AppKitPayErrorMessages = {
|
|
229
|
+
[AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG]: 'Invalid payment configuration',
|
|
230
|
+
[AppKitPayErrorCodes.INVALID_RECIPIENT]: 'Invalid recipient address',
|
|
231
|
+
[AppKitPayErrorCodes.INVALID_ASSET]: 'Invalid asset specified',
|
|
232
|
+
[AppKitPayErrorCodes.INVALID_AMOUNT]: 'Invalid payment amount',
|
|
233
|
+
[AppKitPayErrorCodes.INVALID_RECIPIENT_ADDRESS_FOR_ASSET]: 'Invalid recipient address for the asset selected',
|
|
234
|
+
[AppKitPayErrorCodes.UNKNOWN_ERROR]: 'Unknown payment error occurred',
|
|
235
|
+
[AppKitPayErrorCodes.UNABLE_TO_INITIATE_PAYMENT]: 'Unable to initiate payment',
|
|
236
|
+
[AppKitPayErrorCodes.INVALID_CHAIN_NAMESPACE]: 'Invalid chain namespace',
|
|
237
|
+
[AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR]: 'Unable to process payment',
|
|
238
|
+
[AppKitPayErrorCodes.UNABLE_TO_GET_EXCHANGES]: 'Unable to get exchanges',
|
|
239
|
+
[AppKitPayErrorCodes.ASSET_NOT_SUPPORTED]: 'Asset not supported by the selected exchange',
|
|
240
|
+
[AppKitPayErrorCodes.UNABLE_TO_GET_PAY_URL]: 'Unable to get payment URL',
|
|
241
|
+
[AppKitPayErrorCodes.UNABLE_TO_GET_BUY_STATUS]: 'Unable to get buy status',
|
|
242
|
+
[AppKitPayErrorCodes.UNABLE_TO_GET_TOKEN_BALANCES]: 'Unable to get token balances',
|
|
243
|
+
[AppKitPayErrorCodes.UNABLE_TO_GET_QUOTE]: 'Unable to get quote. Please choose a different token',
|
|
244
|
+
[AppKitPayErrorCodes.UNABLE_TO_GET_QUOTE_STATUS]: 'Unable to get quote status'
|
|
245
|
+
};
|
|
246
|
+
class AppKitPayError extends Error {
|
|
247
|
+
get message() {
|
|
248
|
+
return AppKitPayErrorMessages[this.code];
|
|
249
|
+
}
|
|
250
|
+
constructor(code, details) {
|
|
251
|
+
super(AppKitPayErrorMessages[code]);
|
|
252
|
+
this.name = 'AppKitPayError';
|
|
253
|
+
this.code = code;
|
|
254
|
+
this.details = details;
|
|
255
|
+
if (Error.captureStackTrace) {
|
|
256
|
+
Error.captureStackTrace(this, AppKitPayError);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function createAppKitPayError(code, details) {
|
|
261
|
+
const errorCode = code || AppKitPayErrorCodes.UNKNOWN_ERROR;
|
|
262
|
+
return new AppKitPayError(errorCode, details);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const API_URL = 'https://rpc.walletconnect.org/v1/json-rpc';
|
|
266
|
+
const REOWN_TEST_EXCHANGE_ID = 'reown_test';
|
|
267
|
+
|
|
268
|
+
async function ensureCorrectNetwork(options) {
|
|
269
|
+
const { paymentAssetNetwork, activeCaipNetwork, approvedCaipNetworkIds, requestedCaipNetworks } = options;
|
|
270
|
+
const sortedNetworks = CoreHelperUtil.sortRequestedNetworks(approvedCaipNetworkIds, requestedCaipNetworks);
|
|
271
|
+
const assetCaipNetwork = sortedNetworks.find(network => network.caipNetworkId === paymentAssetNetwork);
|
|
272
|
+
if (!assetCaipNetwork) {
|
|
273
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG);
|
|
274
|
+
}
|
|
275
|
+
if (assetCaipNetwork.caipNetworkId === activeCaipNetwork.caipNetworkId) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const isSupportingAllNetworks = ChainController.getNetworkProp('supportsAllNetworks', assetCaipNetwork.chainNamespace);
|
|
279
|
+
const isSwitchAllowed = approvedCaipNetworkIds?.includes(assetCaipNetwork.caipNetworkId) || isSupportingAllNetworks;
|
|
280
|
+
if (!isSwitchAllowed) {
|
|
281
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG);
|
|
282
|
+
}
|
|
283
|
+
try {
|
|
284
|
+
await ChainController.switchActiveNetwork(assetCaipNetwork);
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
throw new AppKitPayError(AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR, error);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function ensureCorrectAddress() {
|
|
291
|
+
const { chainNamespace } = ParseUtil.parseCaipNetworkId(PayController.state.paymentAsset.network);
|
|
292
|
+
const isAddress = CoreHelperUtil.isAddress(PayController.state.recipient, chainNamespace);
|
|
293
|
+
if (!isAddress) {
|
|
294
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_RECIPIENT_ADDRESS_FOR_ASSET, `Provide valid recipient address for namespace "${chainNamespace}"`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
async function processEvmNativePayment(paymentAsset, chainNamespace, params) {
|
|
298
|
+
if (chainNamespace !== ConstantsUtil.CHAIN.EVM) {
|
|
299
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_CHAIN_NAMESPACE);
|
|
300
|
+
}
|
|
301
|
+
if (!params.fromAddress) {
|
|
302
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG, 'fromAddress is required for native EVM payments.');
|
|
303
|
+
}
|
|
304
|
+
const amountValue = typeof params.amount === 'string' ? parseFloat(params.amount) : params.amount;
|
|
305
|
+
if (isNaN(amountValue)) {
|
|
306
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG);
|
|
307
|
+
}
|
|
308
|
+
const decimals = paymentAsset.metadata?.decimals ?? 18;
|
|
309
|
+
const amountBigInt = ConnectionController.parseUnits(amountValue.toString(), decimals);
|
|
310
|
+
if (typeof amountBigInt !== 'bigint') {
|
|
311
|
+
throw new AppKitPayError(AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR);
|
|
312
|
+
}
|
|
313
|
+
const txResponse = await ConnectionController.sendTransaction({
|
|
314
|
+
chainNamespace,
|
|
315
|
+
to: params.recipient,
|
|
316
|
+
address: params.fromAddress,
|
|
317
|
+
value: amountBigInt,
|
|
318
|
+
data: '0x'
|
|
319
|
+
});
|
|
320
|
+
return txResponse ?? undefined;
|
|
321
|
+
}
|
|
322
|
+
async function processEvmErc20Payment(paymentAsset, params) {
|
|
323
|
+
if (!params.fromAddress) {
|
|
324
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG, 'fromAddress is required for ERC20 EVM payments.');
|
|
325
|
+
}
|
|
326
|
+
const tokenAddress = paymentAsset.asset;
|
|
327
|
+
const recipientAddress = params.recipient;
|
|
328
|
+
const decimals = Number(paymentAsset.metadata.decimals);
|
|
329
|
+
const amountBigInt = ConnectionController.parseUnits(params.amount.toString(), decimals);
|
|
330
|
+
if (amountBigInt === undefined) {
|
|
331
|
+
throw new AppKitPayError(AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR);
|
|
332
|
+
}
|
|
333
|
+
const txResponse = await ConnectionController.writeContract({
|
|
334
|
+
fromAddress: params.fromAddress,
|
|
335
|
+
tokenAddress,
|
|
336
|
+
args: [recipientAddress, amountBigInt],
|
|
337
|
+
method: 'transfer',
|
|
338
|
+
abi: ContractUtil.getERC20Abi(tokenAddress),
|
|
339
|
+
chainNamespace: ConstantsUtil.CHAIN.EVM
|
|
340
|
+
});
|
|
341
|
+
return txResponse ?? undefined;
|
|
342
|
+
}
|
|
343
|
+
async function processSolanaPayment(chainNamespace, params) {
|
|
344
|
+
if (chainNamespace !== ConstantsUtil.CHAIN.SOLANA) {
|
|
345
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_CHAIN_NAMESPACE);
|
|
346
|
+
}
|
|
347
|
+
if (!params.fromAddress) {
|
|
348
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG, 'fromAddress is required for Solana payments.');
|
|
349
|
+
}
|
|
350
|
+
const amountValue = typeof params.amount === 'string' ? parseFloat(params.amount) : params.amount;
|
|
351
|
+
if (isNaN(amountValue) || amountValue <= 0) {
|
|
352
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG, 'Invalid payment amount.');
|
|
353
|
+
}
|
|
354
|
+
try {
|
|
355
|
+
const provider = ProviderController.getProvider(chainNamespace);
|
|
356
|
+
if (!provider) {
|
|
357
|
+
throw new AppKitPayError(AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR, 'No Solana provider available.');
|
|
358
|
+
}
|
|
359
|
+
const txResponse = await ConnectionController.sendTransaction({
|
|
360
|
+
chainNamespace: ConstantsUtil.CHAIN.SOLANA,
|
|
361
|
+
to: params.recipient,
|
|
362
|
+
value: amountValue,
|
|
363
|
+
tokenMint: params.tokenMint
|
|
364
|
+
});
|
|
365
|
+
if (!txResponse) {
|
|
366
|
+
throw new AppKitPayError(AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR, 'Transaction failed.');
|
|
367
|
+
}
|
|
368
|
+
return txResponse;
|
|
369
|
+
}
|
|
370
|
+
catch (error) {
|
|
371
|
+
if (error instanceof AppKitPayError) {
|
|
372
|
+
throw error;
|
|
373
|
+
}
|
|
374
|
+
throw new AppKitPayError(AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR, `Solana payment failed: ${error}`);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
async function getDirectTransferQuote({ sourceToken, toToken, amount, recipient }) {
|
|
378
|
+
const originalAmount = ConnectionController.parseUnits(amount, sourceToken.metadata.decimals);
|
|
379
|
+
const destinationAmount = ConnectionController.parseUnits(amount, toToken.metadata.decimals);
|
|
380
|
+
return Promise.resolve({
|
|
381
|
+
type: DIRECT_TRANSFER_REQUEST_ID,
|
|
382
|
+
origin: {
|
|
383
|
+
amount: originalAmount?.toString() ?? '0',
|
|
384
|
+
currency: sourceToken
|
|
385
|
+
},
|
|
386
|
+
destination: {
|
|
387
|
+
amount: destinationAmount?.toString() ?? '0',
|
|
388
|
+
currency: toToken
|
|
389
|
+
},
|
|
390
|
+
fees: [
|
|
391
|
+
{
|
|
392
|
+
id: 'service',
|
|
393
|
+
label: 'Service Fee',
|
|
394
|
+
amount: '0',
|
|
395
|
+
currency: toToken
|
|
396
|
+
}
|
|
397
|
+
],
|
|
398
|
+
steps: [
|
|
399
|
+
{
|
|
400
|
+
requestId: DIRECT_TRANSFER_REQUEST_ID,
|
|
401
|
+
type: 'deposit',
|
|
402
|
+
deposit: {
|
|
403
|
+
amount: originalAmount?.toString() ?? '0',
|
|
404
|
+
currency: sourceToken.asset,
|
|
405
|
+
receiver: recipient
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
],
|
|
409
|
+
timeInSeconds: 6
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
function getTransferStep(quote) {
|
|
413
|
+
if (!quote) {
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
const step = quote.steps[0];
|
|
417
|
+
if (!step || step.type !== DIRECT_TRANSFER_DEPOSIT_TYPE) {
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
return step;
|
|
421
|
+
}
|
|
422
|
+
function getTransactionsSteps(quote, completedTransactionsCount = 0) {
|
|
423
|
+
if (!quote) {
|
|
424
|
+
return [];
|
|
425
|
+
}
|
|
426
|
+
const steps = quote.steps.filter(step => step.type === DIRECT_TRANSFER_TRANSACTION_TYPE);
|
|
427
|
+
const stepsToShow = steps.filter((_, idx) => {
|
|
428
|
+
const incrementedIdx = idx + 1;
|
|
429
|
+
return incrementedIdx > completedTransactionsCount;
|
|
430
|
+
});
|
|
431
|
+
return steps.length > 0 && steps.length < 3 ? stepsToShow : [];
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
const api = new FetchUtil({ baseUrl: CoreHelperUtil.getApiUrl(), clientId: null });
|
|
435
|
+
class JsonRpcError extends Error {
|
|
436
|
+
}
|
|
437
|
+
function getApiUrl() {
|
|
438
|
+
const projectId = OptionsController.getSnapshot().projectId;
|
|
439
|
+
return `${API_URL}?projectId=${projectId}`;
|
|
440
|
+
}
|
|
441
|
+
function getSdkProperties() {
|
|
442
|
+
const { projectId, sdkType, sdkVersion } = OptionsController.state;
|
|
443
|
+
return {
|
|
444
|
+
projectId,
|
|
445
|
+
st: sdkType || 'appkit',
|
|
446
|
+
sv: sdkVersion || 'html-wagmi-4.2.2'
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
async function sendRequest(method, params) {
|
|
450
|
+
const url = getApiUrl();
|
|
451
|
+
const { sdkType: st, sdkVersion: sv, projectId } = OptionsController.getSnapshot();
|
|
452
|
+
const requestBody = {
|
|
453
|
+
jsonrpc: '2.0',
|
|
454
|
+
id: 1,
|
|
455
|
+
method,
|
|
456
|
+
params: {
|
|
457
|
+
...(params || {}),
|
|
458
|
+
st,
|
|
459
|
+
sv,
|
|
460
|
+
projectId
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
const response = await fetch(url, {
|
|
464
|
+
method: 'POST',
|
|
465
|
+
body: JSON.stringify(requestBody),
|
|
466
|
+
headers: { 'Content-Type': 'application/json' }
|
|
467
|
+
});
|
|
468
|
+
const json = await response.json();
|
|
469
|
+
if (json.error) {
|
|
470
|
+
throw new JsonRpcError(json.error.message);
|
|
471
|
+
}
|
|
472
|
+
return json;
|
|
473
|
+
}
|
|
474
|
+
async function getExchanges$1(params) {
|
|
475
|
+
const response = await sendRequest('reown_getExchanges', params);
|
|
476
|
+
return response.result;
|
|
477
|
+
}
|
|
478
|
+
async function getPayUrl$1(params) {
|
|
479
|
+
const response = await sendRequest('reown_getExchangePayUrl', params);
|
|
480
|
+
return response.result;
|
|
481
|
+
}
|
|
482
|
+
async function getBuyStatus(params) {
|
|
483
|
+
const response = await sendRequest('reown_getExchangeBuyStatus', params);
|
|
484
|
+
return response.result;
|
|
485
|
+
}
|
|
486
|
+
async function getTransfersQuote(params) {
|
|
487
|
+
const amount = NumberUtil.bigNumber(params.amount)
|
|
488
|
+
.times(10 ** params.toToken.metadata.decimals)
|
|
489
|
+
.toString();
|
|
490
|
+
const { chainId: originChainId, chainNamespace: originChainNamespace } = ParseUtil.parseCaipNetworkId(params.sourceToken.network);
|
|
491
|
+
const { chainId: destinationChainId, chainNamespace: destinationChainNamespace } = ParseUtil.parseCaipNetworkId(params.toToken.network);
|
|
492
|
+
const originCurrency = params.sourceToken.asset === 'native'
|
|
493
|
+
? getNativeTokenAddress(originChainNamespace)
|
|
494
|
+
: params.sourceToken.asset;
|
|
495
|
+
const destinationCurrency = params.toToken.asset === 'native'
|
|
496
|
+
? getNativeTokenAddress(destinationChainNamespace)
|
|
497
|
+
: params.toToken.asset;
|
|
498
|
+
const response = await api.post({
|
|
499
|
+
path: '/appkit/v1/transfers/quote',
|
|
500
|
+
body: {
|
|
501
|
+
user: params.address,
|
|
502
|
+
originChainId: originChainId.toString(),
|
|
503
|
+
originCurrency,
|
|
504
|
+
destinationChainId: destinationChainId.toString(),
|
|
505
|
+
destinationCurrency,
|
|
506
|
+
recipient: params.recipient,
|
|
507
|
+
amount
|
|
508
|
+
},
|
|
509
|
+
params: getSdkProperties()
|
|
510
|
+
});
|
|
511
|
+
return response;
|
|
512
|
+
}
|
|
513
|
+
async function getQuote(params) {
|
|
514
|
+
const isSameChain = HelpersUtil.isLowerCaseMatch(params.sourceToken.network, params.toToken.network);
|
|
515
|
+
const isSameAsset = HelpersUtil.isLowerCaseMatch(params.sourceToken.asset, params.toToken.asset);
|
|
516
|
+
if (isSameChain && isSameAsset) {
|
|
517
|
+
return getDirectTransferQuote(params);
|
|
518
|
+
}
|
|
519
|
+
return getTransfersQuote(params);
|
|
520
|
+
}
|
|
521
|
+
async function getQuoteStatus(params) {
|
|
522
|
+
const response = await api.get({
|
|
523
|
+
path: '/appkit/v1/transfers/status',
|
|
524
|
+
params: {
|
|
525
|
+
requestId: params.requestId,
|
|
526
|
+
...getSdkProperties()
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
return response;
|
|
530
|
+
}
|
|
531
|
+
async function getAssetsForExchange(exchangeId) {
|
|
532
|
+
const response = await api.get({
|
|
533
|
+
path: `/appkit/v1/transfers/assets/exchanges/${exchangeId}`,
|
|
534
|
+
params: getSdkProperties()
|
|
535
|
+
});
|
|
536
|
+
return response;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
const SUPPORT_PAY_WITH_WALLET_CHAIN_NAMESPACES = ['eip155', 'solana'];
|
|
540
|
+
const CHAIN_ASSET_INFO_MAP = {
|
|
541
|
+
eip155: {
|
|
542
|
+
native: { assetNamespace: 'slip44', assetReference: '60' },
|
|
543
|
+
defaultTokenNamespace: 'erc20'
|
|
544
|
+
},
|
|
545
|
+
solana: {
|
|
546
|
+
native: { assetNamespace: 'slip44', assetReference: '501' },
|
|
547
|
+
defaultTokenNamespace: 'token'
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
function formatCaip19Asset(caipNetworkId, asset) {
|
|
551
|
+
const { chainNamespace, chainId } = ParseUtil.parseCaipNetworkId(caipNetworkId);
|
|
552
|
+
const chainInfo = CHAIN_ASSET_INFO_MAP[chainNamespace];
|
|
553
|
+
if (!chainInfo) {
|
|
554
|
+
throw new Error(`Unsupported chain namespace for CAIP-19 formatting: ${chainNamespace}`);
|
|
555
|
+
}
|
|
556
|
+
let assetNamespace = chainInfo.native.assetNamespace;
|
|
557
|
+
let assetReference = chainInfo.native.assetReference;
|
|
558
|
+
if (asset !== 'native') {
|
|
559
|
+
assetNamespace = chainInfo.defaultTokenNamespace;
|
|
560
|
+
assetReference = asset;
|
|
561
|
+
}
|
|
562
|
+
const networkPart = `${chainNamespace}:${chainId}`;
|
|
563
|
+
return `${networkPart}/${assetNamespace}:${assetReference}`;
|
|
564
|
+
}
|
|
565
|
+
function isPayWithWalletSupported(networkId) {
|
|
566
|
+
const { chainNamespace } = ParseUtil.parseCaipNetworkId(networkId);
|
|
567
|
+
return SUPPORT_PAY_WITH_WALLET_CHAIN_NAMESPACES.includes(chainNamespace);
|
|
568
|
+
}
|
|
569
|
+
function formatBalanceToPaymentAsset(balance) {
|
|
570
|
+
const allNetworks = ChainController.getAllRequestedCaipNetworks();
|
|
571
|
+
const targetNetwork = allNetworks.find(net => net.caipNetworkId === balance.chainId);
|
|
572
|
+
let asset = balance.address;
|
|
573
|
+
if (!targetNetwork) {
|
|
574
|
+
throw new Error(`Target network not found for balance chainId "${balance.chainId}"`);
|
|
575
|
+
}
|
|
576
|
+
if (HelpersUtil.isLowerCaseMatch(balance.symbol, targetNetwork.nativeCurrency.symbol)) {
|
|
577
|
+
asset = 'native';
|
|
578
|
+
}
|
|
579
|
+
else if (CoreHelperUtil.isCaipAddress(asset)) {
|
|
580
|
+
const { address } = ParseUtil.parseCaipAddress(asset);
|
|
581
|
+
asset = address;
|
|
582
|
+
}
|
|
583
|
+
else if (!asset) {
|
|
584
|
+
throw new Error(`Balance address not found for balance symbol "${balance.symbol}"`);
|
|
585
|
+
}
|
|
586
|
+
return {
|
|
587
|
+
network: targetNetwork.caipNetworkId,
|
|
588
|
+
asset,
|
|
589
|
+
metadata: {
|
|
590
|
+
name: balance.name,
|
|
591
|
+
symbol: balance.symbol,
|
|
592
|
+
decimals: Number(balance.quantity.decimals),
|
|
593
|
+
logoURI: balance.iconUrl
|
|
594
|
+
},
|
|
595
|
+
amount: balance.quantity.numeric
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
function formatPaymentAssetToBalance(paymentAsset) {
|
|
599
|
+
return {
|
|
600
|
+
chainId: paymentAsset.network,
|
|
601
|
+
address: `${paymentAsset.network}:${paymentAsset.asset}`,
|
|
602
|
+
symbol: paymentAsset.metadata.symbol,
|
|
603
|
+
name: paymentAsset.metadata.name,
|
|
604
|
+
iconUrl: paymentAsset.metadata.logoURI || '',
|
|
605
|
+
price: 0,
|
|
606
|
+
quantity: {
|
|
607
|
+
numeric: '0',
|
|
608
|
+
decimals: paymentAsset.metadata.decimals.toString()
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
function formatAmount(amount) {
|
|
613
|
+
const num = NumberUtil.bigNumber(amount, { safe: true });
|
|
614
|
+
if (num.lt(0.001)) {
|
|
615
|
+
return '<0.001';
|
|
616
|
+
}
|
|
617
|
+
return num.round(4).toString();
|
|
618
|
+
}
|
|
619
|
+
function isTestnetAsset(paymentAsset) {
|
|
620
|
+
const allNetworks = ChainController.getAllRequestedCaipNetworks();
|
|
621
|
+
const targetNetwork = allNetworks.find(net => net.caipNetworkId === paymentAsset.network);
|
|
622
|
+
if (!targetNetwork) {
|
|
623
|
+
return false;
|
|
624
|
+
}
|
|
625
|
+
return Boolean(targetNetwork.testnet);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
const DEFAULT_PAGE = 0;
|
|
629
|
+
const DEFAULT_PAYMENT_ID = 'unknown';
|
|
630
|
+
const DIRECT_TRANSFER_REQUEST_ID = 'direct-transfer';
|
|
631
|
+
const DIRECT_TRANSFER_DEPOSIT_TYPE = 'deposit';
|
|
632
|
+
const DIRECT_TRANSFER_TRANSACTION_TYPE = 'transaction';
|
|
633
|
+
const state = proxy({
|
|
634
|
+
paymentAsset: {
|
|
635
|
+
network: 'eip155:1',
|
|
636
|
+
asset: '0x0',
|
|
637
|
+
metadata: {
|
|
638
|
+
name: '0x0',
|
|
639
|
+
symbol: '0x0',
|
|
640
|
+
decimals: 0
|
|
641
|
+
}
|
|
642
|
+
},
|
|
643
|
+
recipient: '0x0',
|
|
644
|
+
amount: 0,
|
|
645
|
+
isConfigured: false,
|
|
646
|
+
error: null,
|
|
647
|
+
isPaymentInProgress: false,
|
|
648
|
+
exchanges: [],
|
|
649
|
+
isLoading: false,
|
|
650
|
+
openInNewTab: true,
|
|
651
|
+
redirectUrl: undefined,
|
|
652
|
+
payWithExchange: undefined,
|
|
653
|
+
currentPayment: undefined,
|
|
654
|
+
analyticsSet: false,
|
|
655
|
+
paymentId: undefined,
|
|
656
|
+
choice: 'pay',
|
|
657
|
+
tokenBalances: {
|
|
658
|
+
[ConstantsUtil.CHAIN.EVM]: [],
|
|
659
|
+
[ConstantsUtil.CHAIN.SOLANA]: []
|
|
660
|
+
},
|
|
661
|
+
isFetchingTokenBalances: false,
|
|
662
|
+
selectedPaymentAsset: null,
|
|
663
|
+
quote: undefined,
|
|
664
|
+
quoteStatus: 'waiting',
|
|
665
|
+
quoteError: null,
|
|
666
|
+
isFetchingQuote: false,
|
|
667
|
+
selectedExchange: undefined,
|
|
668
|
+
exchangeUrlForQuote: undefined,
|
|
669
|
+
requestId: undefined
|
|
670
|
+
});
|
|
671
|
+
const PayController = {
|
|
672
|
+
state,
|
|
673
|
+
subscribe(callback) {
|
|
674
|
+
return subscribe(state, () => callback(state));
|
|
675
|
+
},
|
|
676
|
+
subscribeKey(key, callback) {
|
|
677
|
+
return subscribeKey(state, key, callback);
|
|
678
|
+
},
|
|
679
|
+
async handleOpenPay(options) {
|
|
680
|
+
this.resetState();
|
|
681
|
+
this.setPaymentConfig(options);
|
|
682
|
+
this.initializeAnalytics();
|
|
683
|
+
ensureCorrectAddress();
|
|
684
|
+
await this.prepareTokenLogo();
|
|
685
|
+
state.isConfigured = true;
|
|
686
|
+
EventsController.sendEvent({
|
|
687
|
+
type: 'track',
|
|
688
|
+
event: 'PAY_MODAL_OPEN',
|
|
689
|
+
properties: {
|
|
690
|
+
exchanges: state.exchanges,
|
|
691
|
+
configuration: {
|
|
692
|
+
network: state.paymentAsset.network,
|
|
693
|
+
asset: state.paymentAsset.asset,
|
|
694
|
+
recipient: state.recipient,
|
|
695
|
+
amount: state.amount
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
await ModalController.open({
|
|
700
|
+
view: 'Pay'
|
|
701
|
+
});
|
|
702
|
+
},
|
|
703
|
+
resetState() {
|
|
704
|
+
state.paymentAsset = {
|
|
705
|
+
network: 'eip155:1',
|
|
706
|
+
asset: '0x0',
|
|
707
|
+
metadata: { name: '0x0', symbol: '0x0', decimals: 0 }
|
|
708
|
+
};
|
|
709
|
+
state.recipient = '0x0';
|
|
710
|
+
state.amount = 0;
|
|
711
|
+
state.isConfigured = false;
|
|
712
|
+
state.error = null;
|
|
713
|
+
state.isPaymentInProgress = false;
|
|
714
|
+
state.isLoading = false;
|
|
715
|
+
state.currentPayment = undefined;
|
|
716
|
+
state.selectedExchange = undefined;
|
|
717
|
+
state.exchangeUrlForQuote = undefined;
|
|
718
|
+
state.requestId = undefined;
|
|
719
|
+
},
|
|
720
|
+
resetQuoteState() {
|
|
721
|
+
state.quote = undefined;
|
|
722
|
+
state.quoteStatus = 'waiting';
|
|
723
|
+
state.quoteError = null;
|
|
724
|
+
state.isFetchingQuote = false;
|
|
725
|
+
state.requestId = undefined;
|
|
726
|
+
},
|
|
727
|
+
setPaymentConfig(config) {
|
|
728
|
+
if (!config.paymentAsset) {
|
|
729
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG);
|
|
730
|
+
}
|
|
731
|
+
try {
|
|
732
|
+
state.choice = config.choice ?? 'pay';
|
|
733
|
+
state.paymentAsset = config.paymentAsset;
|
|
734
|
+
state.recipient = config.recipient;
|
|
735
|
+
state.amount = config.amount;
|
|
736
|
+
state.openInNewTab = config.openInNewTab ?? true;
|
|
737
|
+
state.redirectUrl = config.redirectUrl;
|
|
738
|
+
state.payWithExchange = config.payWithExchange;
|
|
739
|
+
state.error = null;
|
|
740
|
+
}
|
|
741
|
+
catch (error) {
|
|
742
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG, error.message);
|
|
743
|
+
}
|
|
744
|
+
},
|
|
745
|
+
setSelectedPaymentAsset(paymentAsset) {
|
|
746
|
+
state.selectedPaymentAsset = paymentAsset;
|
|
747
|
+
},
|
|
748
|
+
setSelectedExchange(exchange) {
|
|
749
|
+
state.selectedExchange = exchange;
|
|
750
|
+
},
|
|
751
|
+
setRequestId(requestId) {
|
|
752
|
+
state.requestId = requestId;
|
|
753
|
+
},
|
|
754
|
+
setPaymentInProgress(isPaymentInProgress) {
|
|
755
|
+
state.isPaymentInProgress = isPaymentInProgress;
|
|
756
|
+
},
|
|
757
|
+
getPaymentAsset() {
|
|
758
|
+
return state.paymentAsset;
|
|
759
|
+
},
|
|
760
|
+
getExchanges() {
|
|
761
|
+
return state.exchanges;
|
|
762
|
+
},
|
|
763
|
+
async fetchExchanges() {
|
|
764
|
+
try {
|
|
765
|
+
state.isLoading = true;
|
|
766
|
+
const response = await getExchanges$1({
|
|
767
|
+
page: DEFAULT_PAGE
|
|
768
|
+
});
|
|
769
|
+
state.exchanges = response.exchanges.slice(0, 2);
|
|
770
|
+
}
|
|
771
|
+
catch (error) {
|
|
772
|
+
SnackController.showError(AppKitPayErrorMessages.UNABLE_TO_GET_EXCHANGES);
|
|
773
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_EXCHANGES);
|
|
774
|
+
}
|
|
775
|
+
finally {
|
|
776
|
+
state.isLoading = false;
|
|
777
|
+
}
|
|
778
|
+
},
|
|
779
|
+
async getAvailableExchanges(params) {
|
|
780
|
+
try {
|
|
781
|
+
const asset = params?.asset && params?.network
|
|
782
|
+
? formatCaip19Asset(params.network, params.asset)
|
|
783
|
+
: undefined;
|
|
784
|
+
const response = await getExchanges$1({
|
|
785
|
+
page: params?.page ?? DEFAULT_PAGE,
|
|
786
|
+
asset,
|
|
787
|
+
amount: params?.amount?.toString()
|
|
788
|
+
});
|
|
789
|
+
return response;
|
|
790
|
+
}
|
|
791
|
+
catch (error) {
|
|
792
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_EXCHANGES);
|
|
793
|
+
}
|
|
794
|
+
},
|
|
795
|
+
async getPayUrl(exchangeId, params, headless = false) {
|
|
796
|
+
try {
|
|
797
|
+
const numericAmount = Number(params.amount);
|
|
798
|
+
const response = await getPayUrl$1({
|
|
799
|
+
exchangeId,
|
|
800
|
+
asset: formatCaip19Asset(params.network, params.asset),
|
|
801
|
+
amount: numericAmount.toString(),
|
|
802
|
+
recipient: `${params.network}:${params.recipient}`
|
|
803
|
+
});
|
|
804
|
+
EventsController.sendEvent({
|
|
805
|
+
type: 'track',
|
|
806
|
+
event: 'PAY_EXCHANGE_SELECTED',
|
|
807
|
+
properties: {
|
|
808
|
+
source: 'pay',
|
|
809
|
+
exchange: {
|
|
810
|
+
id: exchangeId
|
|
811
|
+
},
|
|
812
|
+
configuration: {
|
|
813
|
+
network: params.network,
|
|
814
|
+
asset: params.asset,
|
|
815
|
+
recipient: params.recipient,
|
|
816
|
+
amount: numericAmount
|
|
817
|
+
},
|
|
818
|
+
currentPayment: {
|
|
819
|
+
type: 'exchange',
|
|
820
|
+
exchangeId
|
|
821
|
+
},
|
|
822
|
+
headless
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
if (headless) {
|
|
826
|
+
this.initiatePayment();
|
|
827
|
+
EventsController.sendEvent({
|
|
828
|
+
type: 'track',
|
|
829
|
+
event: 'PAY_INITIATED',
|
|
830
|
+
properties: {
|
|
831
|
+
source: 'pay',
|
|
832
|
+
paymentId: state.paymentId || DEFAULT_PAYMENT_ID,
|
|
833
|
+
configuration: {
|
|
834
|
+
network: params.network,
|
|
835
|
+
asset: params.asset,
|
|
836
|
+
recipient: params.recipient,
|
|
837
|
+
amount: numericAmount
|
|
838
|
+
},
|
|
839
|
+
currentPayment: {
|
|
840
|
+
type: 'exchange',
|
|
841
|
+
exchangeId
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
return response;
|
|
847
|
+
}
|
|
848
|
+
catch (error) {
|
|
849
|
+
if (error instanceof Error && error.message.includes('is not supported')) {
|
|
850
|
+
throw new AppKitPayError(AppKitPayErrorCodes.ASSET_NOT_SUPPORTED);
|
|
851
|
+
}
|
|
852
|
+
throw new Error(error.message);
|
|
853
|
+
}
|
|
854
|
+
},
|
|
855
|
+
async generateExchangeUrlForQuote({ exchangeId, paymentAsset, amount, recipient }) {
|
|
856
|
+
const response = await getPayUrl$1({
|
|
857
|
+
exchangeId,
|
|
858
|
+
asset: formatCaip19Asset(paymentAsset.network, paymentAsset.asset),
|
|
859
|
+
amount: amount.toString(),
|
|
860
|
+
recipient
|
|
861
|
+
});
|
|
862
|
+
state.exchangeSessionId = response.sessionId;
|
|
863
|
+
state.exchangeUrlForQuote = response.url;
|
|
864
|
+
},
|
|
865
|
+
async openPayUrl(openParams, params, headless = false) {
|
|
866
|
+
try {
|
|
867
|
+
const payUrl = await this.getPayUrl(openParams.exchangeId, params, headless);
|
|
868
|
+
if (!payUrl) {
|
|
869
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_PAY_URL);
|
|
870
|
+
}
|
|
871
|
+
const shouldOpenInNewTab = openParams.openInNewTab ?? true;
|
|
872
|
+
const target = shouldOpenInNewTab ? '_blank' : '_self';
|
|
873
|
+
CoreHelperUtil.openHref(payUrl.url, target);
|
|
874
|
+
return payUrl;
|
|
875
|
+
}
|
|
876
|
+
catch (error) {
|
|
877
|
+
if (error instanceof AppKitPayError) {
|
|
878
|
+
state.error = error.message;
|
|
879
|
+
}
|
|
880
|
+
else {
|
|
881
|
+
state.error = AppKitPayErrorMessages.GENERIC_PAYMENT_ERROR;
|
|
882
|
+
}
|
|
883
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_PAY_URL);
|
|
884
|
+
}
|
|
885
|
+
},
|
|
886
|
+
async onTransfer({ chainNamespace, fromAddress, toAddress, amount, paymentAsset }) {
|
|
887
|
+
state.currentPayment = {
|
|
888
|
+
type: 'wallet',
|
|
889
|
+
status: 'IN_PROGRESS'
|
|
890
|
+
};
|
|
891
|
+
if (state.isPaymentInProgress) {
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
try {
|
|
895
|
+
this.initiatePayment();
|
|
896
|
+
const allNetworks = ChainController.getAllRequestedCaipNetworks();
|
|
897
|
+
const targetNetwork = allNetworks.find(net => net.caipNetworkId === paymentAsset.network);
|
|
898
|
+
if (!targetNetwork) {
|
|
899
|
+
throw new Error('Target network not found');
|
|
900
|
+
}
|
|
901
|
+
const caipNetwork = ChainController.state.activeCaipNetwork;
|
|
902
|
+
if (!HelpersUtil.isLowerCaseMatch(caipNetwork?.caipNetworkId, targetNetwork.caipNetworkId)) {
|
|
903
|
+
await ChainController.switchActiveNetwork(targetNetwork);
|
|
904
|
+
}
|
|
905
|
+
switch (chainNamespace) {
|
|
906
|
+
case ConstantsUtil.CHAIN.EVM:
|
|
907
|
+
if (paymentAsset.asset === 'native') {
|
|
908
|
+
state.currentPayment.result = await processEvmNativePayment(paymentAsset, chainNamespace, {
|
|
909
|
+
recipient: toAddress,
|
|
910
|
+
amount,
|
|
911
|
+
fromAddress: fromAddress
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
if (paymentAsset.asset.startsWith('0x')) {
|
|
915
|
+
state.currentPayment.result = await processEvmErc20Payment(paymentAsset, {
|
|
916
|
+
recipient: toAddress,
|
|
917
|
+
amount,
|
|
918
|
+
fromAddress: fromAddress
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
state.currentPayment.status = 'SUCCESS';
|
|
922
|
+
break;
|
|
923
|
+
case ConstantsUtil.CHAIN.SOLANA:
|
|
924
|
+
state.currentPayment.result = await processSolanaPayment(chainNamespace, {
|
|
925
|
+
recipient: toAddress,
|
|
926
|
+
amount,
|
|
927
|
+
fromAddress,
|
|
928
|
+
tokenMint: paymentAsset.asset === 'native' ? undefined : paymentAsset.asset
|
|
929
|
+
});
|
|
930
|
+
state.currentPayment.status = 'SUCCESS';
|
|
931
|
+
break;
|
|
932
|
+
default:
|
|
933
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_CHAIN_NAMESPACE);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
catch (error) {
|
|
937
|
+
if (error instanceof AppKitPayError) {
|
|
938
|
+
state.error = error.message;
|
|
939
|
+
}
|
|
940
|
+
else {
|
|
941
|
+
state.error = AppKitPayErrorMessages.GENERIC_PAYMENT_ERROR;
|
|
942
|
+
}
|
|
943
|
+
state.currentPayment.status = 'FAILED';
|
|
944
|
+
SnackController.showError(state.error);
|
|
945
|
+
throw error;
|
|
946
|
+
}
|
|
947
|
+
finally {
|
|
948
|
+
state.isPaymentInProgress = false;
|
|
949
|
+
}
|
|
950
|
+
},
|
|
951
|
+
async onSendTransaction(params) {
|
|
952
|
+
try {
|
|
953
|
+
const { namespace, transactionStep } = params;
|
|
954
|
+
PayController.initiatePayment();
|
|
955
|
+
const allNetworks = ChainController.getAllRequestedCaipNetworks();
|
|
956
|
+
const targetNetwork = allNetworks.find(net => net.caipNetworkId === state.paymentAsset?.network);
|
|
957
|
+
if (!targetNetwork) {
|
|
958
|
+
throw new Error('Target network not found');
|
|
959
|
+
}
|
|
960
|
+
const caipNetwork = ChainController.state.activeCaipNetwork;
|
|
961
|
+
if (!HelpersUtil.isLowerCaseMatch(caipNetwork?.caipNetworkId, targetNetwork.caipNetworkId)) {
|
|
962
|
+
await ChainController.switchActiveNetwork(targetNetwork);
|
|
963
|
+
}
|
|
964
|
+
if (namespace === ConstantsUtil.CHAIN.EVM) {
|
|
965
|
+
const { from, to, data, value } = transactionStep.transaction;
|
|
966
|
+
await ConnectionController.sendTransaction({
|
|
967
|
+
address: from,
|
|
968
|
+
to,
|
|
969
|
+
data,
|
|
970
|
+
value: BigInt(value),
|
|
971
|
+
chainNamespace: namespace
|
|
972
|
+
});
|
|
973
|
+
}
|
|
974
|
+
else if (namespace === ConstantsUtil.CHAIN.SOLANA) {
|
|
975
|
+
const { instructions } = transactionStep.transaction;
|
|
976
|
+
await ConnectionController.writeSolanaTransaction({
|
|
977
|
+
instructions
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
catch (error) {
|
|
982
|
+
if (error instanceof AppKitPayError) {
|
|
983
|
+
state.error = error.message;
|
|
984
|
+
}
|
|
985
|
+
else {
|
|
986
|
+
state.error = AppKitPayErrorMessages.GENERIC_PAYMENT_ERROR;
|
|
987
|
+
}
|
|
988
|
+
SnackController.showError(state.error);
|
|
989
|
+
throw error;
|
|
990
|
+
}
|
|
991
|
+
finally {
|
|
992
|
+
state.isPaymentInProgress = false;
|
|
993
|
+
}
|
|
994
|
+
},
|
|
995
|
+
getExchangeById(exchangeId) {
|
|
996
|
+
return state.exchanges.find(exchange => exchange.id === exchangeId);
|
|
997
|
+
},
|
|
998
|
+
validatePayConfig(config) {
|
|
999
|
+
const { paymentAsset, recipient, amount } = config;
|
|
1000
|
+
if (!paymentAsset) {
|
|
1001
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG);
|
|
1002
|
+
}
|
|
1003
|
+
if (!recipient) {
|
|
1004
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_RECIPIENT);
|
|
1005
|
+
}
|
|
1006
|
+
if (!paymentAsset.asset) {
|
|
1007
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_ASSET);
|
|
1008
|
+
}
|
|
1009
|
+
if (amount === undefined || amount === null || amount <= 0) {
|
|
1010
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_AMOUNT);
|
|
1011
|
+
}
|
|
1012
|
+
},
|
|
1013
|
+
async handlePayWithExchange(exchangeId) {
|
|
1014
|
+
try {
|
|
1015
|
+
state.currentPayment = {
|
|
1016
|
+
type: 'exchange',
|
|
1017
|
+
exchangeId
|
|
1018
|
+
};
|
|
1019
|
+
const { network, asset } = state.paymentAsset;
|
|
1020
|
+
const payUrlParams = {
|
|
1021
|
+
network,
|
|
1022
|
+
asset,
|
|
1023
|
+
amount: state.amount,
|
|
1024
|
+
recipient: state.recipient
|
|
1025
|
+
};
|
|
1026
|
+
const payUrl = await this.getPayUrl(exchangeId, payUrlParams);
|
|
1027
|
+
if (!payUrl) {
|
|
1028
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_INITIATE_PAYMENT);
|
|
1029
|
+
}
|
|
1030
|
+
state.currentPayment.sessionId = payUrl.sessionId;
|
|
1031
|
+
state.currentPayment.status = 'IN_PROGRESS';
|
|
1032
|
+
state.currentPayment.exchangeId = exchangeId;
|
|
1033
|
+
this.initiatePayment();
|
|
1034
|
+
return {
|
|
1035
|
+
url: payUrl.url,
|
|
1036
|
+
openInNewTab: state.openInNewTab
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
catch (error) {
|
|
1040
|
+
if (error instanceof AppKitPayError) {
|
|
1041
|
+
state.error = error.message;
|
|
1042
|
+
}
|
|
1043
|
+
else {
|
|
1044
|
+
state.error = AppKitPayErrorMessages.GENERIC_PAYMENT_ERROR;
|
|
1045
|
+
}
|
|
1046
|
+
state.isPaymentInProgress = false;
|
|
1047
|
+
SnackController.showError(state.error);
|
|
1048
|
+
return null;
|
|
1049
|
+
}
|
|
1050
|
+
},
|
|
1051
|
+
async getBuyStatus(exchangeId, sessionId) {
|
|
1052
|
+
try {
|
|
1053
|
+
const status = await getBuyStatus({ sessionId, exchangeId });
|
|
1054
|
+
if (status.status === 'SUCCESS' || status.status === 'FAILED') {
|
|
1055
|
+
EventsController.sendEvent({
|
|
1056
|
+
type: 'track',
|
|
1057
|
+
event: status.status === 'SUCCESS' ? 'PAY_SUCCESS' : 'PAY_ERROR',
|
|
1058
|
+
properties: {
|
|
1059
|
+
message: status.status === 'FAILED' ? CoreHelperUtil.parseError(state.error) : undefined,
|
|
1060
|
+
source: 'pay',
|
|
1061
|
+
paymentId: state.paymentId || DEFAULT_PAYMENT_ID,
|
|
1062
|
+
configuration: {
|
|
1063
|
+
network: state.paymentAsset.network,
|
|
1064
|
+
asset: state.paymentAsset.asset,
|
|
1065
|
+
recipient: state.recipient,
|
|
1066
|
+
amount: state.amount
|
|
1067
|
+
},
|
|
1068
|
+
currentPayment: {
|
|
1069
|
+
type: 'exchange',
|
|
1070
|
+
exchangeId: state.currentPayment?.exchangeId,
|
|
1071
|
+
sessionId: state.currentPayment?.sessionId,
|
|
1072
|
+
result: status.txHash
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
return status;
|
|
1078
|
+
}
|
|
1079
|
+
catch (error) {
|
|
1080
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_BUY_STATUS);
|
|
1081
|
+
}
|
|
1082
|
+
},
|
|
1083
|
+
async fetchTokensFromEOA({ caipAddress, caipNetwork, namespace }) {
|
|
1084
|
+
if (!caipAddress) {
|
|
1085
|
+
return [];
|
|
1086
|
+
}
|
|
1087
|
+
const { address } = ParseUtil.parseCaipAddress(caipAddress);
|
|
1088
|
+
let overideCaipNetwork = caipNetwork;
|
|
1089
|
+
if (namespace === ConstantsUtil.CHAIN.EVM) {
|
|
1090
|
+
overideCaipNetwork = undefined;
|
|
1091
|
+
}
|
|
1092
|
+
const balances = await BalanceUtil.getMyTokensWithBalance({
|
|
1093
|
+
address,
|
|
1094
|
+
caipNetwork: overideCaipNetwork
|
|
1095
|
+
});
|
|
1096
|
+
return balances;
|
|
1097
|
+
},
|
|
1098
|
+
async fetchTokensFromExchange() {
|
|
1099
|
+
if (!state.selectedExchange) {
|
|
1100
|
+
return [];
|
|
1101
|
+
}
|
|
1102
|
+
const assets = await getAssetsForExchange(state.selectedExchange.id);
|
|
1103
|
+
const allAssets = Object.values(assets.assets).flat();
|
|
1104
|
+
const balanceWithImages = await Promise.all(allAssets.map(async (token) => {
|
|
1105
|
+
const balance = formatPaymentAssetToBalance(token);
|
|
1106
|
+
const { chainNamespace } = ParseUtil.parseCaipNetworkId(balance.chainId);
|
|
1107
|
+
let address = balance.address;
|
|
1108
|
+
if (CoreHelperUtil.isCaipAddress(address)) {
|
|
1109
|
+
const { address: parsedAddress } = ParseUtil.parseCaipAddress(address);
|
|
1110
|
+
address = parsedAddress;
|
|
1111
|
+
}
|
|
1112
|
+
const image = await AssetUtil.getImageByToken(address ?? '', chainNamespace).catch(() => undefined);
|
|
1113
|
+
balance.iconUrl = image ?? '';
|
|
1114
|
+
return balance;
|
|
1115
|
+
}));
|
|
1116
|
+
return balanceWithImages;
|
|
1117
|
+
},
|
|
1118
|
+
async fetchTokens({ caipAddress, caipNetwork, namespace }) {
|
|
1119
|
+
try {
|
|
1120
|
+
state.isFetchingTokenBalances = true;
|
|
1121
|
+
const isUsingExchange = Boolean(state.selectedExchange);
|
|
1122
|
+
const balancesFnPromise = isUsingExchange
|
|
1123
|
+
? this.fetchTokensFromExchange()
|
|
1124
|
+
: this.fetchTokensFromEOA({ caipAddress, caipNetwork, namespace });
|
|
1125
|
+
const balances = await balancesFnPromise;
|
|
1126
|
+
state.tokenBalances = { ...state.tokenBalances, [namespace]: balances };
|
|
1127
|
+
}
|
|
1128
|
+
catch (err) {
|
|
1129
|
+
const message = err instanceof Error ? err.message : 'Unable to get token balances';
|
|
1130
|
+
SnackController.showError(message);
|
|
1131
|
+
}
|
|
1132
|
+
finally {
|
|
1133
|
+
state.isFetchingTokenBalances = false;
|
|
1134
|
+
}
|
|
1135
|
+
},
|
|
1136
|
+
async fetchQuote({ amount, address, sourceToken, toToken, recipient }) {
|
|
1137
|
+
try {
|
|
1138
|
+
PayController.resetQuoteState();
|
|
1139
|
+
state.isFetchingQuote = true;
|
|
1140
|
+
const quote = await getQuote({
|
|
1141
|
+
amount,
|
|
1142
|
+
address: state.selectedExchange ? undefined : address,
|
|
1143
|
+
sourceToken,
|
|
1144
|
+
toToken,
|
|
1145
|
+
recipient
|
|
1146
|
+
});
|
|
1147
|
+
if (state.selectedExchange) {
|
|
1148
|
+
const transferStep = getTransferStep(quote);
|
|
1149
|
+
if (transferStep) {
|
|
1150
|
+
const caipDepositAddress = `${sourceToken.network}:${transferStep.deposit.receiver}`;
|
|
1151
|
+
const depositAmount = NumberUtil.formatNumber(transferStep.deposit.amount, {
|
|
1152
|
+
decimals: sourceToken.metadata.decimals ?? 0,
|
|
1153
|
+
round: 8
|
|
1154
|
+
});
|
|
1155
|
+
await PayController.generateExchangeUrlForQuote({
|
|
1156
|
+
exchangeId: state.selectedExchange.id,
|
|
1157
|
+
paymentAsset: sourceToken,
|
|
1158
|
+
amount: depositAmount.toString(),
|
|
1159
|
+
recipient: caipDepositAddress
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
state.quote = quote;
|
|
1164
|
+
}
|
|
1165
|
+
catch (err) {
|
|
1166
|
+
let errMessage = AppKitPayErrorMessages.UNABLE_TO_GET_QUOTE;
|
|
1167
|
+
if (err instanceof Error && err.cause && err.cause instanceof Response) {
|
|
1168
|
+
try {
|
|
1169
|
+
const errorData = await err.cause.json();
|
|
1170
|
+
if (errorData.error && typeof errorData.error === 'string') {
|
|
1171
|
+
errMessage = errorData.error;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
catch {
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
state.quoteError = errMessage;
|
|
1178
|
+
SnackController.showError(errMessage);
|
|
1179
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_QUOTE);
|
|
1180
|
+
}
|
|
1181
|
+
finally {
|
|
1182
|
+
state.isFetchingQuote = false;
|
|
1183
|
+
}
|
|
1184
|
+
},
|
|
1185
|
+
async fetchQuoteStatus({ requestId }) {
|
|
1186
|
+
try {
|
|
1187
|
+
if (requestId === DIRECT_TRANSFER_REQUEST_ID) {
|
|
1188
|
+
const selectedExchange = state.selectedExchange;
|
|
1189
|
+
const sessionId = state.exchangeSessionId;
|
|
1190
|
+
if (selectedExchange && sessionId) {
|
|
1191
|
+
const status = await this.getBuyStatus(selectedExchange.id, sessionId);
|
|
1192
|
+
switch (status.status) {
|
|
1193
|
+
case 'IN_PROGRESS':
|
|
1194
|
+
state.quoteStatus = 'waiting';
|
|
1195
|
+
break;
|
|
1196
|
+
case 'SUCCESS':
|
|
1197
|
+
state.quoteStatus = 'success';
|
|
1198
|
+
state.isPaymentInProgress = false;
|
|
1199
|
+
break;
|
|
1200
|
+
case 'FAILED':
|
|
1201
|
+
state.quoteStatus = 'failure';
|
|
1202
|
+
state.isPaymentInProgress = false;
|
|
1203
|
+
break;
|
|
1204
|
+
case 'UNKNOWN':
|
|
1205
|
+
state.quoteStatus = 'waiting';
|
|
1206
|
+
break;
|
|
1207
|
+
default:
|
|
1208
|
+
state.quoteStatus = 'waiting';
|
|
1209
|
+
break;
|
|
1210
|
+
}
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
state.quoteStatus = 'success';
|
|
1214
|
+
return;
|
|
1215
|
+
}
|
|
1216
|
+
const { status } = await getQuoteStatus({ requestId });
|
|
1217
|
+
state.quoteStatus = status;
|
|
1218
|
+
}
|
|
1219
|
+
catch {
|
|
1220
|
+
state.quoteStatus = 'failure';
|
|
1221
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_QUOTE_STATUS);
|
|
1222
|
+
}
|
|
1223
|
+
},
|
|
1224
|
+
initiatePayment() {
|
|
1225
|
+
state.isPaymentInProgress = true;
|
|
1226
|
+
state.paymentId = crypto.randomUUID();
|
|
1227
|
+
},
|
|
1228
|
+
initializeAnalytics() {
|
|
1229
|
+
if (state.analyticsSet) {
|
|
1230
|
+
return;
|
|
1231
|
+
}
|
|
1232
|
+
state.analyticsSet = true;
|
|
1233
|
+
this.subscribeKey('isPaymentInProgress', _ => {
|
|
1234
|
+
if (state.currentPayment?.status && state.currentPayment.status !== 'UNKNOWN') {
|
|
1235
|
+
const eventType = {
|
|
1236
|
+
IN_PROGRESS: 'PAY_INITIATED',
|
|
1237
|
+
SUCCESS: 'PAY_SUCCESS',
|
|
1238
|
+
FAILED: 'PAY_ERROR'
|
|
1239
|
+
}[state.currentPayment.status];
|
|
1240
|
+
EventsController.sendEvent({
|
|
1241
|
+
type: 'track',
|
|
1242
|
+
event: eventType,
|
|
1243
|
+
properties: {
|
|
1244
|
+
message: state.currentPayment.status === 'FAILED'
|
|
1245
|
+
? CoreHelperUtil.parseError(state.error)
|
|
1246
|
+
: undefined,
|
|
1247
|
+
source: 'pay',
|
|
1248
|
+
paymentId: state.paymentId || DEFAULT_PAYMENT_ID,
|
|
1249
|
+
configuration: {
|
|
1250
|
+
network: state.paymentAsset.network,
|
|
1251
|
+
asset: state.paymentAsset.asset,
|
|
1252
|
+
recipient: state.recipient,
|
|
1253
|
+
amount: state.amount
|
|
1254
|
+
},
|
|
1255
|
+
currentPayment: {
|
|
1256
|
+
type: state.currentPayment.type,
|
|
1257
|
+
exchangeId: state.currentPayment.exchangeId,
|
|
1258
|
+
sessionId: state.currentPayment.sessionId,
|
|
1259
|
+
result: state.currentPayment.result
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
});
|
|
1265
|
+
},
|
|
1266
|
+
async prepareTokenLogo() {
|
|
1267
|
+
if (!state.paymentAsset.metadata.logoURI) {
|
|
1268
|
+
try {
|
|
1269
|
+
const { chainNamespace } = ParseUtil.parseCaipNetworkId(state.paymentAsset.network);
|
|
1270
|
+
const imageUrl = await AssetUtil.getImageByToken(state.paymentAsset.asset, chainNamespace);
|
|
1271
|
+
state.paymentAsset.metadata.logoURI = imageUrl;
|
|
1272
|
+
}
|
|
1273
|
+
catch {
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
|
|
1279
|
+
var styles$8 = css `
|
|
1280
|
+
wui-separator {
|
|
1281
|
+
margin: var(--apkt-spacing-3) calc(var(--apkt-spacing-3) * -1) var(--apkt-spacing-2)
|
|
1282
|
+
calc(var(--apkt-spacing-3) * -1);
|
|
1283
|
+
width: calc(100% + var(--apkt-spacing-3) * 2);
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
.token-display {
|
|
1287
|
+
padding: var(--apkt-spacing-3) var(--apkt-spacing-3);
|
|
1288
|
+
border-radius: var(--apkt-borderRadius-5);
|
|
1289
|
+
background-color: var(--apkt-tokens-theme-backgroundPrimary);
|
|
1290
|
+
margin-top: var(--apkt-spacing-3);
|
|
1291
|
+
margin-bottom: var(--apkt-spacing-3);
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
.token-display wui-text {
|
|
1295
|
+
text-transform: none;
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
wui-loading-spinner {
|
|
1299
|
+
padding: var(--apkt-spacing-2);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
.left-image-container {
|
|
1303
|
+
position: relative;
|
|
1304
|
+
justify-content: center;
|
|
1305
|
+
align-items: center;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
.token-image {
|
|
1309
|
+
border-radius: ${({ borderRadius }) => borderRadius.round};
|
|
1310
|
+
width: 40px;
|
|
1311
|
+
height: 40px;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
.chain-image {
|
|
1315
|
+
position: absolute;
|
|
1316
|
+
width: 20px;
|
|
1317
|
+
height: 20px;
|
|
1318
|
+
bottom: -3px;
|
|
1319
|
+
right: -5px;
|
|
1320
|
+
border-radius: ${({ borderRadius }) => borderRadius.round};
|
|
1321
|
+
border: 2px solid ${({ tokens }) => tokens.theme.backgroundPrimary};
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
.payment-methods-container {
|
|
1325
|
+
background-color: ${({ tokens }) => tokens.theme.foregroundPrimary};
|
|
1326
|
+
border-top-right-radius: ${({ borderRadius }) => borderRadius[8]};
|
|
1327
|
+
border-top-left-radius: ${({ borderRadius }) => borderRadius[8]};
|
|
1328
|
+
}
|
|
1329
|
+
`;
|
|
1330
|
+
|
|
1331
|
+
var __decorate$8 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
1332
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1333
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1334
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1335
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1336
|
+
};
|
|
1337
|
+
let W3mPayView = class W3mPayView extends i {
|
|
1338
|
+
constructor() {
|
|
1339
|
+
super();
|
|
1340
|
+
this.unsubscribe = [];
|
|
1341
|
+
this.amount = PayController.state.amount;
|
|
1342
|
+
this.namespace = undefined;
|
|
1343
|
+
this.paymentAsset = PayController.state.paymentAsset;
|
|
1344
|
+
this.activeConnectorIds = ConnectorController.state.activeConnectorIds;
|
|
1345
|
+
this.caipAddress = undefined;
|
|
1346
|
+
this.exchanges = PayController.state.exchanges;
|
|
1347
|
+
this.isLoading = PayController.state.isLoading;
|
|
1348
|
+
this.initializeNamespace();
|
|
1349
|
+
this.unsubscribe.push(PayController.subscribeKey('amount', val => (this.amount = val)));
|
|
1350
|
+
this.unsubscribe.push(ConnectorController.subscribeKey('activeConnectorIds', ids => (this.activeConnectorIds = ids)));
|
|
1351
|
+
this.unsubscribe.push(PayController.subscribeKey('exchanges', val => (this.exchanges = val)));
|
|
1352
|
+
this.unsubscribe.push(PayController.subscribeKey('isLoading', val => (this.isLoading = val)));
|
|
1353
|
+
PayController.fetchExchanges();
|
|
1354
|
+
PayController.setSelectedExchange(undefined);
|
|
1355
|
+
}
|
|
1356
|
+
disconnectedCallback() {
|
|
1357
|
+
this.unsubscribe.forEach(unsubscribe => unsubscribe());
|
|
1358
|
+
}
|
|
1359
|
+
render() {
|
|
1360
|
+
return b `
|
|
1361
|
+
<wui-flex flexDirection="column">
|
|
1362
|
+
${this.paymentDetailsTemplate()} ${this.paymentMethodsTemplate()}
|
|
1363
|
+
</wui-flex>
|
|
1364
|
+
`;
|
|
1365
|
+
}
|
|
1366
|
+
paymentMethodsTemplate() {
|
|
1367
|
+
return b `
|
|
1368
|
+
<wui-flex flexDirection="column" padding="3" gap="2" class="payment-methods-container">
|
|
1369
|
+
${this.payWithWalletTemplate()} ${this.templateSeparator()}
|
|
1370
|
+
${this.templateExchangeOptions()}
|
|
1371
|
+
</wui-flex>
|
|
1372
|
+
`;
|
|
1373
|
+
}
|
|
1374
|
+
initializeNamespace() {
|
|
1375
|
+
const namespace = ChainController.state.activeChain;
|
|
1376
|
+
this.namespace = namespace;
|
|
1377
|
+
this.caipAddress = ChainController.getAccountData(namespace)?.caipAddress;
|
|
1378
|
+
this.unsubscribe.push(ChainController.subscribeChainProp('accountState', accountState => {
|
|
1379
|
+
this.caipAddress = accountState?.caipAddress;
|
|
1380
|
+
}, namespace));
|
|
1381
|
+
}
|
|
1382
|
+
paymentDetailsTemplate() {
|
|
1383
|
+
const allNetworks = ChainController.getAllRequestedCaipNetworks();
|
|
1384
|
+
const targetNetwork = allNetworks.find(net => net.caipNetworkId === this.paymentAsset.network);
|
|
1385
|
+
return b `
|
|
1386
|
+
<wui-flex
|
|
1387
|
+
alignItems="center"
|
|
1388
|
+
justifyContent="space-between"
|
|
1389
|
+
.padding=${['6', '8', '6', '8']}
|
|
1390
|
+
gap="2"
|
|
1391
|
+
>
|
|
1392
|
+
<wui-flex alignItems="center" gap="1">
|
|
1393
|
+
<wui-text variant="h1-regular" color="primary">
|
|
1394
|
+
${formatAmount(this.amount || '0')}
|
|
1395
|
+
</wui-text>
|
|
1396
|
+
|
|
1397
|
+
<wui-flex flexDirection="column">
|
|
1398
|
+
<wui-text variant="h6-regular" color="secondary">
|
|
1399
|
+
${this.paymentAsset.metadata.symbol || 'Unknown'}
|
|
1400
|
+
</wui-text>
|
|
1401
|
+
<wui-text variant="md-medium" color="secondary"
|
|
1402
|
+
>on ${targetNetwork?.name || 'Unknown'}</wui-text
|
|
1403
|
+
>
|
|
1404
|
+
</wui-flex>
|
|
1405
|
+
</wui-flex>
|
|
1406
|
+
|
|
1407
|
+
<wui-flex class="left-image-container">
|
|
1408
|
+
<wui-image
|
|
1409
|
+
src=${o(this.paymentAsset.metadata.logoURI)}
|
|
1410
|
+
class="token-image"
|
|
1411
|
+
></wui-image>
|
|
1412
|
+
<wui-image
|
|
1413
|
+
src=${o(AssetUtil.getNetworkImage(targetNetwork))}
|
|
1414
|
+
class="chain-image"
|
|
1415
|
+
></wui-image>
|
|
1416
|
+
</wui-flex>
|
|
1417
|
+
</wui-flex>
|
|
1418
|
+
`;
|
|
1419
|
+
}
|
|
1420
|
+
payWithWalletTemplate() {
|
|
1421
|
+
if (!isPayWithWalletSupported(this.paymentAsset.network)) {
|
|
1422
|
+
return b ``;
|
|
1423
|
+
}
|
|
1424
|
+
return this.caipAddress ? this.connectedWalletTemplate() : this.disconnectedWalletTemplate();
|
|
1425
|
+
}
|
|
1426
|
+
connectedWalletTemplate() {
|
|
1427
|
+
const { name, image } = this.getWalletProperties({
|
|
1428
|
+
namespace: this.namespace
|
|
1429
|
+
});
|
|
1430
|
+
return b `
|
|
1431
|
+
<wui-flex flexDirection="column" gap="3">
|
|
1432
|
+
<wui-list-item
|
|
1433
|
+
type="secondary"
|
|
1434
|
+
boxColor="foregroundSecondary"
|
|
1435
|
+
@click=${this.onWalletPayment}
|
|
1436
|
+
.boxed=${false}
|
|
1437
|
+
?chevron=${true}
|
|
1438
|
+
?fullSize=${false}
|
|
1439
|
+
?rounded=${true}
|
|
1440
|
+
data-testid="wallet-payment-option"
|
|
1441
|
+
imageSrc=${o(image)}
|
|
1442
|
+
imageSize="3xl"
|
|
1443
|
+
>
|
|
1444
|
+
<wui-text variant="lg-regular" color="primary">Pay with ${name}</wui-text>
|
|
1445
|
+
</wui-list-item>
|
|
1446
|
+
|
|
1447
|
+
<wui-list-item
|
|
1448
|
+
type="secondary"
|
|
1449
|
+
icon="power"
|
|
1450
|
+
iconColor="error"
|
|
1451
|
+
@click=${this.onDisconnect}
|
|
1452
|
+
data-testid="disconnect-button"
|
|
1453
|
+
?chevron=${false}
|
|
1454
|
+
boxColor="foregroundSecondary"
|
|
1455
|
+
>
|
|
1456
|
+
<wui-text variant="lg-regular" color="secondary">Disconnect</wui-text>
|
|
1457
|
+
</wui-list-item>
|
|
1458
|
+
</wui-flex>
|
|
1459
|
+
`;
|
|
1460
|
+
}
|
|
1461
|
+
disconnectedWalletTemplate() {
|
|
1462
|
+
return b `<wui-list-item
|
|
1463
|
+
type="secondary"
|
|
1464
|
+
boxColor="foregroundSecondary"
|
|
1465
|
+
variant="icon"
|
|
1466
|
+
iconColor="default"
|
|
1467
|
+
iconVariant="overlay"
|
|
1468
|
+
icon="wallet"
|
|
1469
|
+
@click=${this.onWalletPayment}
|
|
1470
|
+
?chevron=${true}
|
|
1471
|
+
data-testid="wallet-payment-option"
|
|
1472
|
+
>
|
|
1473
|
+
<wui-text variant="lg-regular" color="primary">Pay with wallet</wui-text>
|
|
1474
|
+
</wui-list-item>`;
|
|
1475
|
+
}
|
|
1476
|
+
templateExchangeOptions() {
|
|
1477
|
+
if (this.isLoading) {
|
|
1478
|
+
return b `<wui-flex justifyContent="center" alignItems="center">
|
|
1479
|
+
<wui-loading-spinner size="md"></wui-loading-spinner>
|
|
1480
|
+
</wui-flex>`;
|
|
1481
|
+
}
|
|
1482
|
+
const exchangesToShow = this.exchanges.filter(exchange => {
|
|
1483
|
+
if (isTestnetAsset(this.paymentAsset)) {
|
|
1484
|
+
return exchange.id === REOWN_TEST_EXCHANGE_ID;
|
|
1485
|
+
}
|
|
1486
|
+
return exchange.id !== REOWN_TEST_EXCHANGE_ID;
|
|
1487
|
+
});
|
|
1488
|
+
if (exchangesToShow.length === 0) {
|
|
1489
|
+
return b `<wui-flex justifyContent="center" alignItems="center">
|
|
1490
|
+
<wui-text variant="md-medium" color="primary">No exchanges available</wui-text>
|
|
1491
|
+
</wui-flex>`;
|
|
1492
|
+
}
|
|
1493
|
+
return exchangesToShow.map(exchange => b `
|
|
1494
|
+
<wui-list-item
|
|
1495
|
+
type="secondary"
|
|
1496
|
+
boxColor="foregroundSecondary"
|
|
1497
|
+
@click=${() => this.onExchangePayment(exchange)}
|
|
1498
|
+
data-testid="exchange-option-${exchange.id}"
|
|
1499
|
+
?chevron=${true}
|
|
1500
|
+
imageSrc=${o(exchange.imageUrl)}
|
|
1501
|
+
>
|
|
1502
|
+
<wui-text flexGrow="1" variant="lg-regular" color="primary">
|
|
1503
|
+
Pay with ${exchange.name}
|
|
1504
|
+
</wui-text>
|
|
1505
|
+
</wui-list-item>
|
|
1506
|
+
`);
|
|
1507
|
+
}
|
|
1508
|
+
templateSeparator() {
|
|
1509
|
+
return b `<wui-separator text="or" bgColor="secondary"></wui-separator>`;
|
|
1510
|
+
}
|
|
1511
|
+
async onWalletPayment() {
|
|
1512
|
+
if (!this.namespace) {
|
|
1513
|
+
throw new Error('Namespace not found');
|
|
1514
|
+
}
|
|
1515
|
+
if (this.caipAddress) {
|
|
1516
|
+
RouterController.push('PayQuote');
|
|
1517
|
+
}
|
|
1518
|
+
else {
|
|
1519
|
+
await ConnectorController.connect();
|
|
1520
|
+
await ModalController.open({ view: 'PayQuote' });
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
onExchangePayment(exchange) {
|
|
1524
|
+
PayController.setSelectedExchange(exchange);
|
|
1525
|
+
RouterController.push('PayQuote');
|
|
1526
|
+
}
|
|
1527
|
+
async onDisconnect() {
|
|
1528
|
+
try {
|
|
1529
|
+
await ConnectionController.disconnect();
|
|
1530
|
+
await ModalController.open({ view: 'Pay' });
|
|
1531
|
+
}
|
|
1532
|
+
catch {
|
|
1533
|
+
console.error('Failed to disconnect');
|
|
1534
|
+
SnackController.showError('Failed to disconnect');
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
getWalletProperties({ namespace }) {
|
|
1538
|
+
if (!namespace) {
|
|
1539
|
+
return {
|
|
1540
|
+
name: undefined,
|
|
1541
|
+
image: undefined
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1544
|
+
const connectorId = this.activeConnectorIds[namespace];
|
|
1545
|
+
if (!connectorId) {
|
|
1546
|
+
return {
|
|
1547
|
+
name: undefined,
|
|
1548
|
+
image: undefined
|
|
1549
|
+
};
|
|
1550
|
+
}
|
|
1551
|
+
const connector = ConnectorController.getConnector({ id: connectorId, namespace });
|
|
1552
|
+
if (!connector) {
|
|
1553
|
+
return {
|
|
1554
|
+
name: undefined,
|
|
1555
|
+
image: undefined
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
const connectorImage = AssetUtil.getConnectorImage(connector);
|
|
1559
|
+
return {
|
|
1560
|
+
name: connector.name,
|
|
1561
|
+
image: connectorImage
|
|
1562
|
+
};
|
|
1563
|
+
}
|
|
1564
|
+
};
|
|
1565
|
+
W3mPayView.styles = styles$8;
|
|
1566
|
+
__decorate$8([
|
|
1567
|
+
r()
|
|
1568
|
+
], W3mPayView.prototype, "amount", void 0);
|
|
1569
|
+
__decorate$8([
|
|
1570
|
+
r()
|
|
1571
|
+
], W3mPayView.prototype, "namespace", void 0);
|
|
1572
|
+
__decorate$8([
|
|
1573
|
+
r()
|
|
1574
|
+
], W3mPayView.prototype, "paymentAsset", void 0);
|
|
1575
|
+
__decorate$8([
|
|
1576
|
+
r()
|
|
1577
|
+
], W3mPayView.prototype, "activeConnectorIds", void 0);
|
|
1578
|
+
__decorate$8([
|
|
1579
|
+
r()
|
|
1580
|
+
], W3mPayView.prototype, "caipAddress", void 0);
|
|
1581
|
+
__decorate$8([
|
|
1582
|
+
r()
|
|
1583
|
+
], W3mPayView.prototype, "exchanges", void 0);
|
|
1584
|
+
__decorate$8([
|
|
1585
|
+
r()
|
|
1586
|
+
], W3mPayView.prototype, "isLoading", void 0);
|
|
1587
|
+
W3mPayView = __decorate$8([
|
|
1588
|
+
customElement('w3m-pay-view')
|
|
1589
|
+
], W3mPayView);
|
|
1590
|
+
|
|
1591
|
+
var styles$7 = css `
|
|
1592
|
+
:host {
|
|
1593
|
+
display: inline-flex;
|
|
1594
|
+
align-items: center;
|
|
1595
|
+
justify-content: center;
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
.pulse-container {
|
|
1599
|
+
position: relative;
|
|
1600
|
+
width: var(--pulse-size);
|
|
1601
|
+
height: var(--pulse-size);
|
|
1602
|
+
display: flex;
|
|
1603
|
+
align-items: center;
|
|
1604
|
+
justify-content: center;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
.pulse-rings {
|
|
1608
|
+
position: absolute;
|
|
1609
|
+
inset: 0;
|
|
1610
|
+
pointer-events: none;
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
.pulse-ring {
|
|
1614
|
+
position: absolute;
|
|
1615
|
+
inset: 0;
|
|
1616
|
+
border-radius: 50%;
|
|
1617
|
+
border: 2px solid var(--pulse-color);
|
|
1618
|
+
opacity: 0;
|
|
1619
|
+
animation: pulse var(--pulse-duration, 2s) ease-out infinite;
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
.pulse-content {
|
|
1623
|
+
position: relative;
|
|
1624
|
+
z-index: 1;
|
|
1625
|
+
display: flex;
|
|
1626
|
+
align-items: center;
|
|
1627
|
+
justify-content: center;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
@keyframes pulse {
|
|
1631
|
+
0% {
|
|
1632
|
+
transform: scale(0.5);
|
|
1633
|
+
opacity: var(--pulse-opacity, 0.3);
|
|
1634
|
+
}
|
|
1635
|
+
50% {
|
|
1636
|
+
opacity: calc(var(--pulse-opacity, 0.3) * 0.5);
|
|
1637
|
+
}
|
|
1638
|
+
100% {
|
|
1639
|
+
transform: scale(1.2);
|
|
1640
|
+
opacity: 0;
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
`;
|
|
1644
|
+
|
|
1645
|
+
var __decorate$7 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
1646
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1647
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1648
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1649
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1650
|
+
};
|
|
1651
|
+
const DEFAULT_RINGS = 3;
|
|
1652
|
+
const DEFAULT_DURATION = 2;
|
|
1653
|
+
const DEFAULT_OPACITY = 0.3;
|
|
1654
|
+
const DEFAULT_SIZE = '200px';
|
|
1655
|
+
const COLOR_BY_VARIANT = {
|
|
1656
|
+
'accent-primary': vars.tokens.core.backgroundAccentPrimary
|
|
1657
|
+
};
|
|
1658
|
+
let WuiPulse = class WuiPulse extends i {
|
|
1659
|
+
constructor() {
|
|
1660
|
+
super(...arguments);
|
|
1661
|
+
this.rings = DEFAULT_RINGS;
|
|
1662
|
+
this.duration = DEFAULT_DURATION;
|
|
1663
|
+
this.opacity = DEFAULT_OPACITY;
|
|
1664
|
+
this.size = DEFAULT_SIZE;
|
|
1665
|
+
this.variant = 'accent-primary';
|
|
1666
|
+
}
|
|
1667
|
+
render() {
|
|
1668
|
+
const color = COLOR_BY_VARIANT[this.variant];
|
|
1669
|
+
this.style.cssText = `
|
|
1670
|
+
--pulse-size: ${this.size};
|
|
1671
|
+
--pulse-duration: ${this.duration}s;
|
|
1672
|
+
--pulse-color: ${color};
|
|
1673
|
+
--pulse-opacity: ${this.opacity};
|
|
1674
|
+
`;
|
|
1675
|
+
const ringElements = Array.from({ length: this.rings }, (_, i) => this.renderRing(i, this.rings));
|
|
1676
|
+
return b `
|
|
1677
|
+
<div class="pulse-container">
|
|
1678
|
+
<div class="pulse-rings">${ringElements}</div>
|
|
1679
|
+
<div class="pulse-content">
|
|
1680
|
+
<slot></slot>
|
|
1681
|
+
</div>
|
|
1682
|
+
</div>
|
|
1683
|
+
`;
|
|
1684
|
+
}
|
|
1685
|
+
renderRing(index, total) {
|
|
1686
|
+
const delay = (index / total) * this.duration;
|
|
1687
|
+
const style = `animation-delay: ${delay}s;`;
|
|
1688
|
+
return b `<div class="pulse-ring" style=${style}></div>`;
|
|
1689
|
+
}
|
|
1690
|
+
};
|
|
1691
|
+
WuiPulse.styles = [resetStyles, styles$7];
|
|
1692
|
+
__decorate$7([
|
|
1693
|
+
n({ type: Number })
|
|
1694
|
+
], WuiPulse.prototype, "rings", void 0);
|
|
1695
|
+
__decorate$7([
|
|
1696
|
+
n({ type: Number })
|
|
1697
|
+
], WuiPulse.prototype, "duration", void 0);
|
|
1698
|
+
__decorate$7([
|
|
1699
|
+
n({ type: Number })
|
|
1700
|
+
], WuiPulse.prototype, "opacity", void 0);
|
|
1701
|
+
__decorate$7([
|
|
1702
|
+
n()
|
|
1703
|
+
], WuiPulse.prototype, "size", void 0);
|
|
1704
|
+
__decorate$7([
|
|
1705
|
+
n()
|
|
1706
|
+
], WuiPulse.prototype, "variant", void 0);
|
|
1707
|
+
WuiPulse = __decorate$7([
|
|
1708
|
+
customElement('wui-pulse')
|
|
1709
|
+
], WuiPulse);
|
|
1710
|
+
|
|
1711
|
+
const STEPS = [
|
|
1712
|
+
{
|
|
1713
|
+
id: 'received',
|
|
1714
|
+
title: 'Receiving funds',
|
|
1715
|
+
icon: 'dollar'
|
|
1716
|
+
},
|
|
1717
|
+
{
|
|
1718
|
+
id: 'processing',
|
|
1719
|
+
title: 'Swapping asset',
|
|
1720
|
+
icon: 'recycleHorizontal'
|
|
1721
|
+
},
|
|
1722
|
+
{
|
|
1723
|
+
id: 'sending',
|
|
1724
|
+
title: 'Sending asset to the recipient address',
|
|
1725
|
+
icon: 'send'
|
|
1726
|
+
}
|
|
1727
|
+
];
|
|
1728
|
+
const TERMINAL_STATES = [
|
|
1729
|
+
'success',
|
|
1730
|
+
'submitted',
|
|
1731
|
+
'failure',
|
|
1732
|
+
'timeout',
|
|
1733
|
+
'refund'
|
|
1734
|
+
];
|
|
1735
|
+
|
|
1736
|
+
var styles$6 = css `
|
|
1737
|
+
:host {
|
|
1738
|
+
display: block;
|
|
1739
|
+
height: 100%;
|
|
1740
|
+
width: 100%;
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
wui-image {
|
|
1744
|
+
border-radius: ${({ borderRadius }) => borderRadius.round};
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
.token-badge-container {
|
|
1748
|
+
position: absolute;
|
|
1749
|
+
bottom: 6px;
|
|
1750
|
+
left: 50%;
|
|
1751
|
+
transform: translateX(-50%);
|
|
1752
|
+
border-radius: ${({ borderRadius }) => borderRadius[4]};
|
|
1753
|
+
z-index: 3;
|
|
1754
|
+
min-width: 105px;
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
.token-badge-container.loading {
|
|
1758
|
+
background-color: ${({ tokens }) => tokens.theme.backgroundPrimary};
|
|
1759
|
+
border: 3px solid ${({ tokens }) => tokens.theme.backgroundPrimary};
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
.token-badge-container.success {
|
|
1763
|
+
background-color: ${({ tokens }) => tokens.theme.backgroundPrimary};
|
|
1764
|
+
border: 3px solid ${({ tokens }) => tokens.theme.backgroundPrimary};
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
.token-image-container {
|
|
1768
|
+
position: relative;
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
.token-image {
|
|
1772
|
+
border-radius: ${({ borderRadius }) => borderRadius.round};
|
|
1773
|
+
width: 64px;
|
|
1774
|
+
height: 64px;
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
.token-image.success {
|
|
1778
|
+
background-color: ${({ tokens }) => tokens.theme.foregroundPrimary};
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
.token-image.error {
|
|
1782
|
+
background-color: ${({ tokens }) => tokens.theme.foregroundPrimary};
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
.token-image.loading {
|
|
1786
|
+
background: ${({ colors }) => colors.accent010};
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
.token-image wui-icon {
|
|
1790
|
+
width: 32px;
|
|
1791
|
+
height: 32px;
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
.token-badge {
|
|
1795
|
+
background-color: ${({ tokens }) => tokens.theme.foregroundPrimary};
|
|
1796
|
+
border: 1px solid ${({ tokens }) => tokens.theme.foregroundSecondary};
|
|
1797
|
+
border-radius: ${({ borderRadius }) => borderRadius[4]};
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
.token-badge wui-text {
|
|
1801
|
+
white-space: nowrap;
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
.payment-lifecycle-container {
|
|
1805
|
+
background-color: ${({ tokens }) => tokens.theme.foregroundPrimary};
|
|
1806
|
+
border-top-right-radius: ${({ borderRadius }) => borderRadius[6]};
|
|
1807
|
+
border-top-left-radius: ${({ borderRadius }) => borderRadius[6]};
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
.payment-step-badge {
|
|
1811
|
+
padding: ${({ spacing }) => spacing[1]} ${({ spacing }) => spacing[2]};
|
|
1812
|
+
border-radius: ${({ borderRadius }) => borderRadius[1]};
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
.payment-step-badge.loading {
|
|
1816
|
+
background-color: ${({ tokens }) => tokens.theme.foregroundSecondary};
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
.payment-step-badge.error {
|
|
1820
|
+
background-color: ${({ tokens }) => tokens.core.backgroundError};
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
.payment-step-badge.success {
|
|
1824
|
+
background-color: ${({ tokens }) => tokens.core.backgroundSuccess};
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
.step-icon-container {
|
|
1828
|
+
position: relative;
|
|
1829
|
+
height: 40px;
|
|
1830
|
+
width: 40px;
|
|
1831
|
+
border-radius: ${({ borderRadius }) => borderRadius.round};
|
|
1832
|
+
background-color: ${({ tokens }) => tokens.theme.foregroundSecondary};
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
.step-icon-box {
|
|
1836
|
+
position: absolute;
|
|
1837
|
+
right: -4px;
|
|
1838
|
+
bottom: -1px;
|
|
1839
|
+
padding: 2px;
|
|
1840
|
+
border-radius: ${({ borderRadius }) => borderRadius.round};
|
|
1841
|
+
border: 2px solid ${({ tokens }) => tokens.theme.backgroundPrimary};
|
|
1842
|
+
background-color: ${({ tokens }) => tokens.theme.foregroundPrimary};
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
.step-icon-box.success {
|
|
1846
|
+
background-color: ${({ tokens }) => tokens.core.backgroundSuccess};
|
|
1847
|
+
}
|
|
1848
|
+
`;
|
|
1849
|
+
|
|
1850
|
+
var __decorate$6 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
1851
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1852
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1853
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1854
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1855
|
+
};
|
|
1856
|
+
const STEP_COMPLETED_STATUSES = {
|
|
1857
|
+
received: ['pending', 'success', 'submitted'],
|
|
1858
|
+
processing: ['success', 'submitted'],
|
|
1859
|
+
sending: ['success', 'submitted']
|
|
1860
|
+
};
|
|
1861
|
+
const POLLING_INTERVAL_MS = 3000;
|
|
1862
|
+
let W3mPayLoadingView = class W3mPayLoadingView extends i {
|
|
1863
|
+
constructor() {
|
|
1864
|
+
super();
|
|
1865
|
+
this.unsubscribe = [];
|
|
1866
|
+
this.pollingInterval = null;
|
|
1867
|
+
this.paymentAsset = PayController.state.paymentAsset;
|
|
1868
|
+
this.quoteStatus = PayController.state.quoteStatus;
|
|
1869
|
+
this.quote = PayController.state.quote;
|
|
1870
|
+
this.amount = PayController.state.amount;
|
|
1871
|
+
this.namespace = undefined;
|
|
1872
|
+
this.caipAddress = undefined;
|
|
1873
|
+
this.profileName = null;
|
|
1874
|
+
this.activeConnectorIds = ConnectorController.state.activeConnectorIds;
|
|
1875
|
+
this.selectedExchange = PayController.state.selectedExchange;
|
|
1876
|
+
this.initializeNamespace();
|
|
1877
|
+
this.unsubscribe.push(...[
|
|
1878
|
+
PayController.subscribeKey('quoteStatus', val => (this.quoteStatus = val)),
|
|
1879
|
+
PayController.subscribeKey('quote', val => (this.quote = val)),
|
|
1880
|
+
ConnectorController.subscribeKey('activeConnectorIds', ids => (this.activeConnectorIds = ids)),
|
|
1881
|
+
PayController.subscribeKey('selectedExchange', val => (this.selectedExchange = val))
|
|
1882
|
+
]);
|
|
1883
|
+
}
|
|
1884
|
+
connectedCallback() {
|
|
1885
|
+
super.connectedCallback();
|
|
1886
|
+
this.startPolling();
|
|
1887
|
+
}
|
|
1888
|
+
disconnectedCallback() {
|
|
1889
|
+
super.disconnectedCallback();
|
|
1890
|
+
this.stopPolling();
|
|
1891
|
+
this.unsubscribe.forEach(unsubscribe => unsubscribe());
|
|
1892
|
+
}
|
|
1893
|
+
render() {
|
|
1894
|
+
return b `
|
|
1895
|
+
<wui-flex flexDirection="column" .padding=${['3', '0', '0', '0']} gap="2">
|
|
1896
|
+
${this.tokenTemplate()} ${this.paymentTemplate()} ${this.paymentLifecycleTemplate()}
|
|
1897
|
+
</wui-flex>
|
|
1898
|
+
`;
|
|
1899
|
+
}
|
|
1900
|
+
tokenTemplate() {
|
|
1901
|
+
const amount = formatAmount(this.amount || '0');
|
|
1902
|
+
const symbol = this.paymentAsset.metadata.symbol ?? 'Unknown';
|
|
1903
|
+
const allNetworks = ChainController.getAllRequestedCaipNetworks();
|
|
1904
|
+
const targetNetwork = allNetworks.find(net => net.caipNetworkId === this.paymentAsset.network);
|
|
1905
|
+
const hasTransactionFailed = this.quoteStatus === 'failure' ||
|
|
1906
|
+
this.quoteStatus === 'timeout' ||
|
|
1907
|
+
this.quoteStatus === 'refund';
|
|
1908
|
+
const hasTransactionSucceeded = this.quoteStatus === 'success' || this.quoteStatus === 'submitted';
|
|
1909
|
+
if (hasTransactionSucceeded) {
|
|
1910
|
+
return b `<wui-flex alignItems="center" justifyContent="center">
|
|
1911
|
+
<wui-flex justifyContent="center" alignItems="center" class="token-image success">
|
|
1912
|
+
<wui-icon name="checkmark" color="success" size="inherit"></wui-icon>
|
|
1913
|
+
</wui-flex>
|
|
1914
|
+
</wui-flex>`;
|
|
1915
|
+
}
|
|
1916
|
+
if (hasTransactionFailed) {
|
|
1917
|
+
return b `<wui-flex alignItems="center" justifyContent="center">
|
|
1918
|
+
<wui-flex justifyContent="center" alignItems="center" class="token-image error">
|
|
1919
|
+
<wui-icon name="close" color="error" size="inherit"></wui-icon>
|
|
1920
|
+
</wui-flex>
|
|
1921
|
+
</wui-flex>`;
|
|
1922
|
+
}
|
|
1923
|
+
return b `
|
|
1924
|
+
<wui-flex alignItems="center" justifyContent="center">
|
|
1925
|
+
<wui-flex class="token-image-container">
|
|
1926
|
+
<wui-pulse size="125px" rings="3" duration="4" opacity="0.5" variant="accent-primary">
|
|
1927
|
+
<wui-flex justifyContent="center" alignItems="center" class="token-image loading">
|
|
1928
|
+
<wui-icon name="paperPlaneTitle" color="accent-primary" size="inherit"></wui-icon>
|
|
1929
|
+
</wui-flex>
|
|
1930
|
+
</wui-pulse>
|
|
1931
|
+
|
|
1932
|
+
<wui-flex
|
|
1933
|
+
justifyContent="center"
|
|
1934
|
+
alignItems="center"
|
|
1935
|
+
class="token-badge-container loading"
|
|
1936
|
+
>
|
|
1937
|
+
<wui-flex
|
|
1938
|
+
alignItems="center"
|
|
1939
|
+
justifyContent="center"
|
|
1940
|
+
gap="01"
|
|
1941
|
+
padding="1"
|
|
1942
|
+
class="token-badge"
|
|
1943
|
+
>
|
|
1944
|
+
<wui-image
|
|
1945
|
+
src=${o(AssetUtil.getNetworkImage(targetNetwork))}
|
|
1946
|
+
class="chain-image"
|
|
1947
|
+
size="mdl"
|
|
1948
|
+
></wui-image>
|
|
1949
|
+
|
|
1950
|
+
<wui-text variant="lg-regular" color="primary">${amount} ${symbol}</wui-text>
|
|
1951
|
+
</wui-flex>
|
|
1952
|
+
</wui-flex>
|
|
1953
|
+
</wui-flex>
|
|
1954
|
+
</wui-flex>
|
|
1955
|
+
`;
|
|
1956
|
+
}
|
|
1957
|
+
paymentTemplate() {
|
|
1958
|
+
return b `
|
|
1959
|
+
<wui-flex flexDirection="column" gap="2" .padding=${['0', '6', '0', '6']}>
|
|
1960
|
+
${this.renderPayment()}
|
|
1961
|
+
<wui-separator></wui-separator>
|
|
1962
|
+
${this.renderWallet()}
|
|
1963
|
+
</wui-flex>
|
|
1964
|
+
`;
|
|
1965
|
+
}
|
|
1966
|
+
paymentLifecycleTemplate() {
|
|
1967
|
+
const stepsWithStatus = this.getStepsWithStatus();
|
|
1968
|
+
return b `
|
|
1969
|
+
<wui-flex flexDirection="column" padding="4" gap="2" class="payment-lifecycle-container">
|
|
1970
|
+
<wui-flex alignItems="center" justifyContent="space-between">
|
|
1971
|
+
<wui-text variant="md-regular" color="secondary">PAYMENT CYCLE</wui-text>
|
|
1972
|
+
|
|
1973
|
+
${this.renderPaymentCycleBadge()}
|
|
1974
|
+
</wui-flex>
|
|
1975
|
+
|
|
1976
|
+
<wui-flex flexDirection="column" gap="5" .padding=${['2', '0', '2', '0']}>
|
|
1977
|
+
${stepsWithStatus.map(step => this.renderStep(step))}
|
|
1978
|
+
</wui-flex>
|
|
1979
|
+
</wui-flex>
|
|
1980
|
+
`;
|
|
1981
|
+
}
|
|
1982
|
+
renderPaymentCycleBadge() {
|
|
1983
|
+
const hasTransactionFailed = this.quoteStatus === 'failure' ||
|
|
1984
|
+
this.quoteStatus === 'timeout' ||
|
|
1985
|
+
this.quoteStatus === 'refund';
|
|
1986
|
+
const hasTransactionSucceeded = this.quoteStatus === 'success' || this.quoteStatus === 'submitted';
|
|
1987
|
+
if (hasTransactionFailed) {
|
|
1988
|
+
return b `
|
|
1989
|
+
<wui-flex
|
|
1990
|
+
justifyContent="center"
|
|
1991
|
+
alignItems="center"
|
|
1992
|
+
class="payment-step-badge error"
|
|
1993
|
+
gap="1"
|
|
1994
|
+
>
|
|
1995
|
+
<wui-icon name="close" color="error" size="xs"></wui-icon>
|
|
1996
|
+
<wui-text variant="sm-regular" color="error">Failed</wui-text>
|
|
1997
|
+
</wui-flex>
|
|
1998
|
+
`;
|
|
1999
|
+
}
|
|
2000
|
+
if (hasTransactionSucceeded) {
|
|
2001
|
+
return b `
|
|
2002
|
+
<wui-flex
|
|
2003
|
+
justifyContent="center"
|
|
2004
|
+
alignItems="center"
|
|
2005
|
+
class="payment-step-badge success"
|
|
2006
|
+
gap="1"
|
|
2007
|
+
>
|
|
2008
|
+
<wui-icon name="checkmark" color="success" size="xs"></wui-icon>
|
|
2009
|
+
<wui-text variant="sm-regular" color="success">Completed</wui-text>
|
|
2010
|
+
</wui-flex>
|
|
2011
|
+
`;
|
|
2012
|
+
}
|
|
2013
|
+
const timeEstimate = this.quote?.timeInSeconds ?? 0;
|
|
2014
|
+
return b `
|
|
2015
|
+
<wui-flex alignItems="center" justifyContent="space-between" gap="3">
|
|
2016
|
+
<wui-flex
|
|
2017
|
+
justifyContent="center"
|
|
2018
|
+
alignItems="center"
|
|
2019
|
+
class="payment-step-badge loading"
|
|
2020
|
+
gap="1"
|
|
2021
|
+
>
|
|
2022
|
+
<wui-icon name="clock" color="default" size="xs"></wui-icon>
|
|
2023
|
+
<wui-text variant="sm-regular" color="primary">Est. ${timeEstimate} sec</wui-text>
|
|
2024
|
+
</wui-flex>
|
|
2025
|
+
|
|
2026
|
+
<wui-icon name="chevronBottom" color="default" size="xxs"></wui-icon>
|
|
2027
|
+
</wui-flex>
|
|
2028
|
+
`;
|
|
2029
|
+
}
|
|
2030
|
+
renderPayment() {
|
|
2031
|
+
const allNetworks = ChainController.getAllRequestedCaipNetworks();
|
|
2032
|
+
const targetNetwork = allNetworks.find(net => {
|
|
2033
|
+
const network = this.quote?.origin.currency.network;
|
|
2034
|
+
if (!network) {
|
|
2035
|
+
return false;
|
|
2036
|
+
}
|
|
2037
|
+
const { chainId } = ParseUtil.parseCaipNetworkId(network);
|
|
2038
|
+
return HelpersUtil.isLowerCaseMatch(net.id.toString(), chainId.toString());
|
|
2039
|
+
});
|
|
2040
|
+
const formatBigNumber = NumberUtil.formatNumber(this.quote?.origin.amount || '0', {
|
|
2041
|
+
decimals: this.quote?.origin.currency.metadata.decimals ?? 0
|
|
2042
|
+
}).toString();
|
|
2043
|
+
const formattedAmount = formatAmount(formatBigNumber);
|
|
2044
|
+
const symbol = this.quote?.origin.currency.metadata.symbol ?? 'Unknown';
|
|
2045
|
+
return b `
|
|
2046
|
+
<wui-flex
|
|
2047
|
+
alignItems="flex-start"
|
|
2048
|
+
justifyContent="space-between"
|
|
2049
|
+
.padding=${['3', '0', '3', '0']}
|
|
2050
|
+
>
|
|
2051
|
+
<wui-text variant="lg-regular" color="secondary">Payment Method</wui-text>
|
|
2052
|
+
|
|
2053
|
+
<wui-flex flexDirection="column" alignItems="flex-end" gap="1">
|
|
2054
|
+
<wui-flex alignItems="center" gap="01">
|
|
2055
|
+
<wui-text variant="lg-regular" color="primary">${formattedAmount}</wui-text>
|
|
2056
|
+
<wui-text variant="lg-regular" color="secondary">${symbol}</wui-text>
|
|
2057
|
+
</wui-flex>
|
|
2058
|
+
|
|
2059
|
+
<wui-flex alignItems="center" gap="1">
|
|
2060
|
+
<wui-text variant="md-regular" color="secondary">on</wui-text>
|
|
2061
|
+
<wui-image
|
|
2062
|
+
src=${o(AssetUtil.getNetworkImage(targetNetwork))}
|
|
2063
|
+
size="xs"
|
|
2064
|
+
></wui-image>
|
|
2065
|
+
<wui-text variant="md-regular" color="secondary">${targetNetwork?.name}</wui-text>
|
|
2066
|
+
</wui-flex>
|
|
2067
|
+
</wui-flex>
|
|
2068
|
+
</wui-flex>
|
|
2069
|
+
`;
|
|
2070
|
+
}
|
|
2071
|
+
renderWallet() {
|
|
2072
|
+
return b `
|
|
2073
|
+
<wui-flex
|
|
2074
|
+
alignItems="flex-start"
|
|
2075
|
+
justifyContent="space-between"
|
|
2076
|
+
.padding=${['3', '0', '3', '0']}
|
|
2077
|
+
>
|
|
2078
|
+
<wui-text variant="lg-regular" color="secondary">Wallet</wui-text>
|
|
2079
|
+
|
|
2080
|
+
${this.renderWalletText()}
|
|
2081
|
+
</wui-flex>
|
|
2082
|
+
`;
|
|
2083
|
+
}
|
|
2084
|
+
renderWalletText() {
|
|
2085
|
+
const { image } = this.getWalletProperties({ namespace: this.namespace });
|
|
2086
|
+
const { address } = this.caipAddress ? ParseUtil.parseCaipAddress(this.caipAddress) : {};
|
|
2087
|
+
const exchangeName = this.selectedExchange?.name;
|
|
2088
|
+
if (this.selectedExchange) {
|
|
2089
|
+
return b `
|
|
2090
|
+
<wui-flex alignItems="center" justifyContent="flex-end" gap="1">
|
|
2091
|
+
<wui-text variant="lg-regular" color="primary">${exchangeName}</wui-text>
|
|
2092
|
+
<wui-image src=${o(this.selectedExchange.imageUrl)} size="mdl"></wui-image>
|
|
2093
|
+
</wui-flex>
|
|
2094
|
+
`;
|
|
2095
|
+
}
|
|
2096
|
+
return b `
|
|
2097
|
+
<wui-flex alignItems="center" justifyContent="flex-end" gap="1">
|
|
2098
|
+
<wui-text variant="lg-regular" color="primary">
|
|
2099
|
+
${UiHelperUtil.getTruncateString({
|
|
2100
|
+
string: this.profileName || address || exchangeName || '',
|
|
2101
|
+
charsStart: this.profileName ? 16 : 4,
|
|
2102
|
+
charsEnd: this.profileName ? 0 : 6,
|
|
2103
|
+
truncate: this.profileName ? 'end' : 'middle'
|
|
2104
|
+
})}
|
|
2105
|
+
</wui-text>
|
|
2106
|
+
|
|
2107
|
+
<wui-image src=${o(image)} size="mdl"></wui-image>
|
|
2108
|
+
</wui-flex>
|
|
2109
|
+
`;
|
|
2110
|
+
}
|
|
2111
|
+
getStepsWithStatus() {
|
|
2112
|
+
const hasTransactionFailed = this.quoteStatus === 'failure' ||
|
|
2113
|
+
this.quoteStatus === 'timeout' ||
|
|
2114
|
+
this.quoteStatus === 'refund';
|
|
2115
|
+
if (hasTransactionFailed) {
|
|
2116
|
+
return STEPS.map(step => ({ ...step, status: 'failed' }));
|
|
2117
|
+
}
|
|
2118
|
+
return STEPS.map(step => {
|
|
2119
|
+
const completedStatuses = STEP_COMPLETED_STATUSES[step.id] ?? [];
|
|
2120
|
+
const status = completedStatuses.includes(this.quoteStatus) ? 'completed' : 'pending';
|
|
2121
|
+
return { ...step, status };
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
renderStep({ title, icon, status }) {
|
|
2125
|
+
const classes = {
|
|
2126
|
+
'step-icon-box': true,
|
|
2127
|
+
success: status === 'completed'
|
|
2128
|
+
};
|
|
2129
|
+
return b `
|
|
2130
|
+
<wui-flex alignItems="center" gap="3">
|
|
2131
|
+
<wui-flex justifyContent="center" alignItems="center" class="step-icon-container">
|
|
2132
|
+
<wui-icon name=${icon} color="default" size="mdl"></wui-icon>
|
|
2133
|
+
|
|
2134
|
+
<wui-flex alignItems="center" justifyContent="center" class=${e(classes)}>
|
|
2135
|
+
${this.renderStatusIndicator(status)}
|
|
2136
|
+
</wui-flex>
|
|
2137
|
+
</wui-flex>
|
|
2138
|
+
|
|
2139
|
+
<wui-text variant="md-regular" color="primary">${title}</wui-text>
|
|
2140
|
+
</wui-flex>
|
|
2141
|
+
`;
|
|
2142
|
+
}
|
|
2143
|
+
renderStatusIndicator(status) {
|
|
2144
|
+
if (status === 'completed') {
|
|
2145
|
+
return b `<wui-icon size="sm" color="success" name="checkmark"></wui-icon>`;
|
|
2146
|
+
}
|
|
2147
|
+
if (status === 'failed') {
|
|
2148
|
+
return b `<wui-icon size="sm" color="error" name="close"></wui-icon>`;
|
|
2149
|
+
}
|
|
2150
|
+
if (status === 'pending') {
|
|
2151
|
+
return b `<wui-loading-spinner color="accent-primary" size="sm"></wui-loading-spinner>`;
|
|
2152
|
+
}
|
|
2153
|
+
return null;
|
|
2154
|
+
}
|
|
2155
|
+
startPolling() {
|
|
2156
|
+
if (!this.pollingInterval) {
|
|
2157
|
+
this.fetchQuoteStatus();
|
|
2158
|
+
this.pollingInterval = setInterval(() => {
|
|
2159
|
+
this.fetchQuoteStatus();
|
|
2160
|
+
}, POLLING_INTERVAL_MS);
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
stopPolling() {
|
|
2164
|
+
if (this.pollingInterval) {
|
|
2165
|
+
clearInterval(this.pollingInterval);
|
|
2166
|
+
this.pollingInterval = null;
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
async fetchQuoteStatus() {
|
|
2170
|
+
const requestId = PayController.state.requestId;
|
|
2171
|
+
if (!requestId || TERMINAL_STATES.includes(this.quoteStatus)) {
|
|
2172
|
+
this.stopPolling();
|
|
2173
|
+
}
|
|
2174
|
+
else {
|
|
2175
|
+
try {
|
|
2176
|
+
await PayController.fetchQuoteStatus({ requestId });
|
|
2177
|
+
if (TERMINAL_STATES.includes(this.quoteStatus)) {
|
|
2178
|
+
this.stopPolling();
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
catch {
|
|
2182
|
+
this.stopPolling();
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
initializeNamespace() {
|
|
2187
|
+
const namespace = ChainController.state.activeChain;
|
|
2188
|
+
this.namespace = namespace;
|
|
2189
|
+
this.caipAddress = ChainController.getAccountData(namespace)?.caipAddress;
|
|
2190
|
+
this.profileName = ChainController.getAccountData(namespace)?.profileName ?? null;
|
|
2191
|
+
this.unsubscribe.push(ChainController.subscribeChainProp('accountState', accountState => {
|
|
2192
|
+
this.caipAddress = accountState?.caipAddress;
|
|
2193
|
+
this.profileName = accountState?.profileName ?? null;
|
|
2194
|
+
}, namespace));
|
|
2195
|
+
}
|
|
2196
|
+
getWalletProperties({ namespace }) {
|
|
2197
|
+
if (!namespace) {
|
|
2198
|
+
return {
|
|
2199
|
+
name: undefined,
|
|
2200
|
+
image: undefined
|
|
2201
|
+
};
|
|
2202
|
+
}
|
|
2203
|
+
const connectorId = this.activeConnectorIds[namespace];
|
|
2204
|
+
if (!connectorId) {
|
|
2205
|
+
return {
|
|
2206
|
+
name: undefined,
|
|
2207
|
+
image: undefined
|
|
2208
|
+
};
|
|
2209
|
+
}
|
|
2210
|
+
const connector = ConnectorController.getConnector({ id: connectorId, namespace });
|
|
2211
|
+
if (!connector) {
|
|
2212
|
+
return {
|
|
2213
|
+
name: undefined,
|
|
2214
|
+
image: undefined
|
|
2215
|
+
};
|
|
2216
|
+
}
|
|
2217
|
+
const connectorImage = AssetUtil.getConnectorImage(connector);
|
|
2218
|
+
return {
|
|
2219
|
+
name: connector.name,
|
|
2220
|
+
image: connectorImage
|
|
2221
|
+
};
|
|
2222
|
+
}
|
|
2223
|
+
};
|
|
2224
|
+
W3mPayLoadingView.styles = styles$6;
|
|
2225
|
+
__decorate$6([
|
|
2226
|
+
r()
|
|
2227
|
+
], W3mPayLoadingView.prototype, "paymentAsset", void 0);
|
|
2228
|
+
__decorate$6([
|
|
2229
|
+
r()
|
|
2230
|
+
], W3mPayLoadingView.prototype, "quoteStatus", void 0);
|
|
2231
|
+
__decorate$6([
|
|
2232
|
+
r()
|
|
2233
|
+
], W3mPayLoadingView.prototype, "quote", void 0);
|
|
2234
|
+
__decorate$6([
|
|
2235
|
+
r()
|
|
2236
|
+
], W3mPayLoadingView.prototype, "amount", void 0);
|
|
2237
|
+
__decorate$6([
|
|
2238
|
+
r()
|
|
2239
|
+
], W3mPayLoadingView.prototype, "namespace", void 0);
|
|
2240
|
+
__decorate$6([
|
|
2241
|
+
r()
|
|
2242
|
+
], W3mPayLoadingView.prototype, "caipAddress", void 0);
|
|
2243
|
+
__decorate$6([
|
|
2244
|
+
r()
|
|
2245
|
+
], W3mPayLoadingView.prototype, "profileName", void 0);
|
|
2246
|
+
__decorate$6([
|
|
2247
|
+
r()
|
|
2248
|
+
], W3mPayLoadingView.prototype, "activeConnectorIds", void 0);
|
|
2249
|
+
__decorate$6([
|
|
2250
|
+
r()
|
|
2251
|
+
], W3mPayLoadingView.prototype, "selectedExchange", void 0);
|
|
2252
|
+
W3mPayLoadingView = __decorate$6([
|
|
2253
|
+
customElement('w3m-pay-loading-view')
|
|
2254
|
+
], W3mPayLoadingView);
|
|
2255
|
+
|
|
2256
|
+
var styles$5 = i$1 `
|
|
2257
|
+
:host {
|
|
2258
|
+
display: block;
|
|
2259
|
+
}
|
|
2260
|
+
`;
|
|
2261
|
+
|
|
2262
|
+
var __decorate$5 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
2263
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2264
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2265
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2266
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2267
|
+
};
|
|
2268
|
+
let W3mPayFeesSkeleton = class W3mPayFeesSkeleton extends i {
|
|
2269
|
+
render() {
|
|
2270
|
+
return b `
|
|
2271
|
+
<wui-flex flexDirection="column" gap="4">
|
|
2272
|
+
<wui-flex alignItems="center" justifyContent="space-between">
|
|
2273
|
+
<wui-text variant="md-regular" color="secondary">Pay</wui-text>
|
|
2274
|
+
<wui-shimmer width="60px" height="16px" borderRadius="4xs" variant="light"></wui-shimmer>
|
|
2275
|
+
</wui-flex>
|
|
2276
|
+
|
|
2277
|
+
<wui-flex alignItems="center" justifyContent="space-between">
|
|
2278
|
+
<wui-text variant="md-regular" color="secondary">Network Fee</wui-text>
|
|
2279
|
+
|
|
2280
|
+
<wui-flex flexDirection="column" alignItems="flex-end" gap="2">
|
|
2281
|
+
<wui-shimmer
|
|
2282
|
+
width="75px"
|
|
2283
|
+
height="16px"
|
|
2284
|
+
borderRadius="4xs"
|
|
2285
|
+
variant="light"
|
|
2286
|
+
></wui-shimmer>
|
|
2287
|
+
|
|
2288
|
+
<wui-flex alignItems="center" gap="01">
|
|
2289
|
+
<wui-shimmer width="14px" height="14px" rounded variant="light"></wui-shimmer>
|
|
2290
|
+
<wui-shimmer
|
|
2291
|
+
width="49px"
|
|
2292
|
+
height="14px"
|
|
2293
|
+
borderRadius="4xs"
|
|
2294
|
+
variant="light"
|
|
2295
|
+
></wui-shimmer>
|
|
2296
|
+
</wui-flex>
|
|
2297
|
+
</wui-flex>
|
|
2298
|
+
</wui-flex>
|
|
2299
|
+
|
|
2300
|
+
<wui-flex alignItems="center" justifyContent="space-between">
|
|
2301
|
+
<wui-text variant="md-regular" color="secondary">Service Fee</wui-text>
|
|
2302
|
+
<wui-shimmer width="75px" height="16px" borderRadius="4xs" variant="light"></wui-shimmer>
|
|
2303
|
+
</wui-flex>
|
|
2304
|
+
</wui-flex>
|
|
2305
|
+
`;
|
|
2306
|
+
}
|
|
2307
|
+
};
|
|
2308
|
+
W3mPayFeesSkeleton.styles = [styles$5];
|
|
2309
|
+
W3mPayFeesSkeleton = __decorate$5([
|
|
2310
|
+
customElement('w3m-pay-fees-skeleton')
|
|
2311
|
+
], W3mPayFeesSkeleton);
|
|
2312
|
+
|
|
2313
|
+
var styles$4 = css `
|
|
2314
|
+
:host {
|
|
2315
|
+
display: block;
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2318
|
+
wui-image {
|
|
2319
|
+
border-radius: ${({ borderRadius }) => borderRadius.round};
|
|
2320
|
+
}
|
|
2321
|
+
`;
|
|
2322
|
+
|
|
2323
|
+
var __decorate$4 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
2324
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2325
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2326
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2327
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2328
|
+
};
|
|
2329
|
+
let W3mPayFees = class W3mPayFees extends i {
|
|
2330
|
+
constructor() {
|
|
2331
|
+
super();
|
|
2332
|
+
this.unsubscribe = [];
|
|
2333
|
+
this.quote = PayController.state.quote;
|
|
2334
|
+
this.unsubscribe.push(PayController.subscribeKey('quote', val => (this.quote = val)));
|
|
2335
|
+
}
|
|
2336
|
+
disconnectedCallback() {
|
|
2337
|
+
this.unsubscribe.forEach(unsubscribe => unsubscribe());
|
|
2338
|
+
}
|
|
2339
|
+
render() {
|
|
2340
|
+
const amount = NumberUtil.formatNumber(this.quote?.origin.amount || '0', {
|
|
2341
|
+
decimals: this.quote?.origin.currency.metadata.decimals ?? 0,
|
|
2342
|
+
round: 6
|
|
2343
|
+
}).toString();
|
|
2344
|
+
return b `
|
|
2345
|
+
<wui-flex flexDirection="column" gap="4">
|
|
2346
|
+
<wui-flex alignItems="center" justifyContent="space-between">
|
|
2347
|
+
<wui-text variant="md-regular" color="secondary">Pay</wui-text>
|
|
2348
|
+
<wui-text variant="md-regular" color="primary">
|
|
2349
|
+
${amount} ${this.quote?.origin.currency.metadata.symbol || 'Unknown'}
|
|
2350
|
+
</wui-text>
|
|
2351
|
+
</wui-flex>
|
|
2352
|
+
|
|
2353
|
+
${this.quote && this.quote.fees.length > 0
|
|
2354
|
+
? this.quote.fees.map(fee => this.renderFee(fee))
|
|
2355
|
+
: null}
|
|
2356
|
+
</wui-flex>
|
|
2357
|
+
`;
|
|
2358
|
+
}
|
|
2359
|
+
renderFee(fee) {
|
|
2360
|
+
const isNetworkFee = fee.id === 'network';
|
|
2361
|
+
const feeAmount = NumberUtil.formatNumber(fee.amount || '0', {
|
|
2362
|
+
decimals: fee.currency.metadata.decimals ?? 0,
|
|
2363
|
+
round: 6
|
|
2364
|
+
}).toString();
|
|
2365
|
+
if (isNetworkFee) {
|
|
2366
|
+
const allNetworks = ChainController.getAllRequestedCaipNetworks();
|
|
2367
|
+
const targetNetwork = allNetworks.find(net => HelpersUtil.isLowerCaseMatch(net.caipNetworkId, fee.currency.network));
|
|
2368
|
+
return b `
|
|
2369
|
+
<wui-flex alignItems="center" justifyContent="space-between">
|
|
2370
|
+
<wui-text variant="md-regular" color="secondary">${fee.label}</wui-text>
|
|
2371
|
+
|
|
2372
|
+
<wui-flex flexDirection="column" alignItems="flex-end" gap="2">
|
|
2373
|
+
<wui-text variant="md-regular" color="primary">
|
|
2374
|
+
${feeAmount} ${fee.currency.metadata.symbol || 'Unknown'}
|
|
2375
|
+
</wui-text>
|
|
2376
|
+
|
|
2377
|
+
<wui-flex alignItems="center" gap="01">
|
|
2378
|
+
<wui-image
|
|
2379
|
+
src=${o(AssetUtil.getNetworkImage(targetNetwork))}
|
|
2380
|
+
size="xs"
|
|
2381
|
+
></wui-image>
|
|
2382
|
+
<wui-text variant="sm-regular" color="secondary">
|
|
2383
|
+
${targetNetwork?.name || 'Unknown'}
|
|
2384
|
+
</wui-text>
|
|
2385
|
+
</wui-flex>
|
|
2386
|
+
</wui-flex>
|
|
2387
|
+
</wui-flex>
|
|
2388
|
+
`;
|
|
2389
|
+
}
|
|
2390
|
+
return b `
|
|
2391
|
+
<wui-flex alignItems="center" justifyContent="space-between">
|
|
2392
|
+
<wui-text variant="md-regular" color="secondary">${fee.label}</wui-text>
|
|
2393
|
+
<wui-text variant="md-regular" color="primary">
|
|
2394
|
+
${feeAmount} ${fee.currency.metadata.symbol || 'Unknown'}
|
|
2395
|
+
</wui-text>
|
|
2396
|
+
</wui-flex>
|
|
2397
|
+
`;
|
|
2398
|
+
}
|
|
2399
|
+
};
|
|
2400
|
+
W3mPayFees.styles = [styles$4];
|
|
2401
|
+
__decorate$4([
|
|
2402
|
+
r()
|
|
2403
|
+
], W3mPayFees.prototype, "quote", void 0);
|
|
2404
|
+
W3mPayFees = __decorate$4([
|
|
2405
|
+
customElement('w3m-pay-fees')
|
|
2406
|
+
], W3mPayFees);
|
|
2407
|
+
|
|
2408
|
+
var styles$3 = css `
|
|
2409
|
+
:host {
|
|
2410
|
+
display: block;
|
|
2411
|
+
width: 100%;
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2414
|
+
.disabled-container {
|
|
2415
|
+
padding: ${({ spacing }) => spacing[2]};
|
|
2416
|
+
min-height: 168px;
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
wui-icon {
|
|
2420
|
+
width: ${({ spacing }) => spacing[8]};
|
|
2421
|
+
height: ${({ spacing }) => spacing[8]};
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
wui-flex > wui-text {
|
|
2425
|
+
max-width: 273px;
|
|
2426
|
+
}
|
|
2427
|
+
`;
|
|
2428
|
+
|
|
2429
|
+
var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
2430
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2431
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2432
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2433
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2434
|
+
};
|
|
2435
|
+
let W3mPayOptionsEmpty = class W3mPayOptionsEmpty extends i {
|
|
2436
|
+
constructor() {
|
|
2437
|
+
super();
|
|
2438
|
+
this.unsubscribe = [];
|
|
2439
|
+
this.selectedExchange = PayController.state.selectedExchange;
|
|
2440
|
+
this.unsubscribe.push(PayController.subscribeKey('selectedExchange', val => (this.selectedExchange = val)));
|
|
2441
|
+
}
|
|
2442
|
+
disconnectedCallback() {
|
|
2443
|
+
this.unsubscribe.forEach(unsubscribe => unsubscribe());
|
|
2444
|
+
}
|
|
2445
|
+
render() {
|
|
2446
|
+
const isUsingExchange = Boolean(this.selectedExchange);
|
|
2447
|
+
return b `
|
|
2448
|
+
<wui-flex
|
|
2449
|
+
flexDirection="column"
|
|
2450
|
+
alignItems="center"
|
|
2451
|
+
justifyContent="center"
|
|
2452
|
+
gap="3"
|
|
2453
|
+
class="disabled-container"
|
|
2454
|
+
>
|
|
2455
|
+
<wui-icon name="coins" color="default" size="inherit"></wui-icon>
|
|
2456
|
+
|
|
2457
|
+
<wui-text variant="md-regular" color="primary" align="center">
|
|
2458
|
+
You don't have enough funds to complete this transaction
|
|
2459
|
+
</wui-text>
|
|
2460
|
+
|
|
2461
|
+
${isUsingExchange
|
|
2462
|
+
? null
|
|
2463
|
+
: b `<wui-button
|
|
2464
|
+
size="md"
|
|
2465
|
+
variant="neutral-secondary"
|
|
2466
|
+
@click=${this.dispatchConnectOtherWalletEvent.bind(this)}
|
|
2467
|
+
>Connect other wallet</wui-button
|
|
2468
|
+
>`}
|
|
2469
|
+
</wui-flex>
|
|
2470
|
+
`;
|
|
2471
|
+
}
|
|
2472
|
+
dispatchConnectOtherWalletEvent() {
|
|
2473
|
+
this.dispatchEvent(new CustomEvent('connectOtherWallet', {
|
|
2474
|
+
detail: true,
|
|
2475
|
+
bubbles: true,
|
|
2476
|
+
composed: true
|
|
2477
|
+
}));
|
|
2478
|
+
}
|
|
2479
|
+
};
|
|
2480
|
+
W3mPayOptionsEmpty.styles = [styles$3];
|
|
2481
|
+
__decorate$3([
|
|
2482
|
+
n({ type: Array })
|
|
2483
|
+
], W3mPayOptionsEmpty.prototype, "selectedExchange", void 0);
|
|
2484
|
+
W3mPayOptionsEmpty = __decorate$3([
|
|
2485
|
+
customElement('w3m-pay-options-empty')
|
|
2486
|
+
], W3mPayOptionsEmpty);
|
|
2487
|
+
|
|
2488
|
+
var styles$2 = css `
|
|
2489
|
+
:host {
|
|
2490
|
+
display: block;
|
|
2491
|
+
width: 100%;
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2494
|
+
.pay-options-container {
|
|
2495
|
+
max-height: 196px;
|
|
2496
|
+
overflow-y: auto;
|
|
2497
|
+
overflow-x: hidden;
|
|
2498
|
+
scrollbar-width: none;
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
.pay-options-container::-webkit-scrollbar {
|
|
2502
|
+
display: none;
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
.pay-option-container {
|
|
2506
|
+
border-radius: ${({ borderRadius }) => borderRadius[4]};
|
|
2507
|
+
padding: ${({ spacing }) => spacing[3]};
|
|
2508
|
+
min-height: 60px;
|
|
2509
|
+
}
|
|
2510
|
+
|
|
2511
|
+
.token-images-container {
|
|
2512
|
+
position: relative;
|
|
2513
|
+
justify-content: center;
|
|
2514
|
+
align-items: center;
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2517
|
+
.chain-image {
|
|
2518
|
+
position: absolute;
|
|
2519
|
+
bottom: -3px;
|
|
2520
|
+
right: -5px;
|
|
2521
|
+
border: 2px solid ${({ tokens }) => tokens.theme.foregroundSecondary};
|
|
2522
|
+
}
|
|
2523
|
+
`;
|
|
2524
|
+
|
|
2525
|
+
var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
2526
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2527
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2528
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2529
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2530
|
+
};
|
|
2531
|
+
let W3mPayOptionsSkeleton = class W3mPayOptionsSkeleton extends i {
|
|
2532
|
+
render() {
|
|
2533
|
+
return b `
|
|
2534
|
+
<wui-flex flexDirection="column" gap="2" class="pay-options-container">
|
|
2535
|
+
${this.renderOptionEntry()} ${this.renderOptionEntry()} ${this.renderOptionEntry()}
|
|
2536
|
+
</wui-flex>
|
|
2537
|
+
`;
|
|
2538
|
+
}
|
|
2539
|
+
renderOptionEntry() {
|
|
2540
|
+
return b `
|
|
2541
|
+
<wui-flex
|
|
2542
|
+
alignItems="center"
|
|
2543
|
+
justifyContent="space-between"
|
|
2544
|
+
gap="2"
|
|
2545
|
+
class="pay-option-container"
|
|
2546
|
+
>
|
|
2547
|
+
<wui-flex alignItems="center" gap="2">
|
|
2548
|
+
<wui-flex class="token-images-container">
|
|
2549
|
+
<wui-shimmer
|
|
2550
|
+
width="32px"
|
|
2551
|
+
height="32px"
|
|
2552
|
+
rounded
|
|
2553
|
+
variant="light"
|
|
2554
|
+
class="token-image"
|
|
2555
|
+
></wui-shimmer>
|
|
2556
|
+
<wui-shimmer
|
|
2557
|
+
width="16px"
|
|
2558
|
+
height="16px"
|
|
2559
|
+
rounded
|
|
2560
|
+
variant="light"
|
|
2561
|
+
class="chain-image"
|
|
2562
|
+
></wui-shimmer>
|
|
2563
|
+
</wui-flex>
|
|
2564
|
+
|
|
2565
|
+
<wui-flex flexDirection="column" gap="1">
|
|
2566
|
+
<wui-shimmer
|
|
2567
|
+
width="74px"
|
|
2568
|
+
height="16px"
|
|
2569
|
+
borderRadius="4xs"
|
|
2570
|
+
variant="light"
|
|
2571
|
+
></wui-shimmer>
|
|
2572
|
+
<wui-shimmer
|
|
2573
|
+
width="46px"
|
|
2574
|
+
height="14px"
|
|
2575
|
+
borderRadius="4xs"
|
|
2576
|
+
variant="light"
|
|
2577
|
+
></wui-shimmer>
|
|
2578
|
+
</wui-flex>
|
|
2579
|
+
</wui-flex>
|
|
2580
|
+
</wui-flex>
|
|
2581
|
+
`;
|
|
2582
|
+
}
|
|
2583
|
+
};
|
|
2584
|
+
W3mPayOptionsSkeleton.styles = [styles$2];
|
|
2585
|
+
W3mPayOptionsSkeleton = __decorate$2([
|
|
2586
|
+
customElement('w3m-pay-options-skeleton')
|
|
2587
|
+
], W3mPayOptionsSkeleton);
|
|
2588
|
+
|
|
2589
|
+
var styles$1 = css `
|
|
2590
|
+
:host {
|
|
2591
|
+
display: block;
|
|
2592
|
+
width: 100%;
|
|
2593
|
+
}
|
|
2594
|
+
|
|
2595
|
+
.pay-options-container {
|
|
2596
|
+
max-height: 196px;
|
|
2597
|
+
overflow-y: auto;
|
|
2598
|
+
overflow-x: hidden;
|
|
2599
|
+
scrollbar-width: none;
|
|
2600
|
+
mask-image: var(--options-mask-image);
|
|
2601
|
+
-webkit-mask-image: var(--options-mask-image);
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
.pay-options-container::-webkit-scrollbar {
|
|
2605
|
+
display: none;
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2608
|
+
.pay-option-container {
|
|
2609
|
+
cursor: pointer;
|
|
2610
|
+
border-radius: ${({ borderRadius }) => borderRadius[4]};
|
|
2611
|
+
padding: ${({ spacing }) => spacing[3]};
|
|
2612
|
+
transition: background-color ${({ durations }) => durations['lg']}
|
|
2613
|
+
${({ easings }) => easings['ease-out-power-1']};
|
|
2614
|
+
will-change: background-color;
|
|
2615
|
+
}
|
|
2616
|
+
|
|
2617
|
+
.token-images-container {
|
|
2618
|
+
position: relative;
|
|
2619
|
+
justify-content: center;
|
|
2620
|
+
align-items: center;
|
|
2621
|
+
}
|
|
2622
|
+
|
|
2623
|
+
.token-image {
|
|
2624
|
+
border-radius: ${({ borderRadius }) => borderRadius.round};
|
|
2625
|
+
width: 32px;
|
|
2626
|
+
height: 32px;
|
|
2627
|
+
}
|
|
2628
|
+
|
|
2629
|
+
.chain-image {
|
|
2630
|
+
position: absolute;
|
|
2631
|
+
width: 16px;
|
|
2632
|
+
height: 16px;
|
|
2633
|
+
bottom: -3px;
|
|
2634
|
+
right: -5px;
|
|
2635
|
+
border-radius: ${({ borderRadius }) => borderRadius.round};
|
|
2636
|
+
border: 2px solid ${({ tokens }) => tokens.theme.backgroundPrimary};
|
|
2637
|
+
}
|
|
2638
|
+
|
|
2639
|
+
@media (hover: hover) and (pointer: fine) {
|
|
2640
|
+
.pay-option-container:hover {
|
|
2641
|
+
background-color: ${({ tokens }) => tokens.theme.foregroundPrimary};
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
`;
|
|
2645
|
+
|
|
2646
|
+
var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
2647
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2648
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2649
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2650
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2651
|
+
};
|
|
2652
|
+
const SCROLL_THRESHOLD = 300;
|
|
2653
|
+
let W3mPayOptions = class W3mPayOptions extends i {
|
|
2654
|
+
constructor() {
|
|
2655
|
+
super();
|
|
2656
|
+
this.unsubscribe = [];
|
|
2657
|
+
this.options = [];
|
|
2658
|
+
this.selectedPaymentAsset = null;
|
|
2659
|
+
}
|
|
2660
|
+
disconnectedCallback() {
|
|
2661
|
+
this.unsubscribe.forEach(unsubscribe => unsubscribe());
|
|
2662
|
+
this.resizeObserver?.disconnect();
|
|
2663
|
+
const optionsEl = this.shadowRoot?.querySelector('.pay-options-container');
|
|
2664
|
+
optionsEl?.removeEventListener('scroll', this.handleOptionsListScroll.bind(this));
|
|
2665
|
+
}
|
|
2666
|
+
firstUpdated() {
|
|
2667
|
+
const optionsEl = this.shadowRoot?.querySelector('.pay-options-container');
|
|
2668
|
+
if (optionsEl) {
|
|
2669
|
+
requestAnimationFrame(this.handleOptionsListScroll.bind(this));
|
|
2670
|
+
optionsEl?.addEventListener('scroll', this.handleOptionsListScroll.bind(this));
|
|
2671
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
2672
|
+
this.handleOptionsListScroll();
|
|
2673
|
+
});
|
|
2674
|
+
this.resizeObserver?.observe(optionsEl);
|
|
2675
|
+
this.handleOptionsListScroll();
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
render() {
|
|
2679
|
+
return b `
|
|
2680
|
+
<wui-flex flexDirection="column" gap="2" class="pay-options-container">
|
|
2681
|
+
${this.options.map(option => this.payOptionTemplate(option))}
|
|
2682
|
+
</wui-flex>
|
|
2683
|
+
`;
|
|
2684
|
+
}
|
|
2685
|
+
payOptionTemplate(paymentAsset) {
|
|
2686
|
+
const { network, metadata, asset, amount = '0' } = paymentAsset;
|
|
2687
|
+
const allNetworks = ChainController.getAllRequestedCaipNetworks();
|
|
2688
|
+
const targetNetwork = allNetworks.find(net => net.caipNetworkId === network);
|
|
2689
|
+
const paymentCaipAddress = `${network}:${asset}`;
|
|
2690
|
+
const selectedPaymentCaipAddress = `${this.selectedPaymentAsset?.network}:${this.selectedPaymentAsset?.asset}`;
|
|
2691
|
+
const isSelected = paymentCaipAddress === selectedPaymentCaipAddress;
|
|
2692
|
+
const bigAmount = NumberUtil.bigNumber(amount, { safe: true });
|
|
2693
|
+
const hasEnoughBalance = bigAmount.gt(0);
|
|
2694
|
+
return b `
|
|
2695
|
+
<wui-flex
|
|
2696
|
+
alignItems="center"
|
|
2697
|
+
justifyContent="space-between"
|
|
2698
|
+
gap="2"
|
|
2699
|
+
@click=${() => this.onSelect?.(paymentAsset)}
|
|
2700
|
+
class="pay-option-container"
|
|
2701
|
+
>
|
|
2702
|
+
<wui-flex alignItems="center" gap="2">
|
|
2703
|
+
<wui-flex class="token-images-container">
|
|
2704
|
+
<wui-image
|
|
2705
|
+
src=${o(metadata.logoURI)}
|
|
2706
|
+
class="token-image"
|
|
2707
|
+
size="3xl"
|
|
2708
|
+
></wui-image>
|
|
2709
|
+
<wui-image
|
|
2710
|
+
src=${o(AssetUtil.getNetworkImage(targetNetwork))}
|
|
2711
|
+
class="chain-image"
|
|
2712
|
+
size="md"
|
|
2713
|
+
></wui-image>
|
|
2714
|
+
</wui-flex>
|
|
2715
|
+
|
|
2716
|
+
<wui-flex flexDirection="column" gap="1">
|
|
2717
|
+
<wui-text variant="lg-regular" color="primary">${metadata.symbol}</wui-text>
|
|
2718
|
+
${hasEnoughBalance
|
|
2719
|
+
? b `<wui-text variant="sm-regular" color="secondary">
|
|
2720
|
+
${bigAmount.round(6).toString()} ${metadata.symbol}
|
|
2721
|
+
</wui-text>`
|
|
2722
|
+
: null}
|
|
2723
|
+
</wui-flex>
|
|
2724
|
+
</wui-flex>
|
|
2725
|
+
|
|
2726
|
+
${isSelected
|
|
2727
|
+
? b `<wui-icon name="checkmark" size="md" color="success"></wui-icon>`
|
|
2728
|
+
: null}
|
|
2729
|
+
</wui-flex>
|
|
2730
|
+
`;
|
|
2731
|
+
}
|
|
2732
|
+
handleOptionsListScroll() {
|
|
2733
|
+
const optionsEl = this.shadowRoot?.querySelector('.pay-options-container');
|
|
2734
|
+
if (!optionsEl) {
|
|
2735
|
+
return;
|
|
2736
|
+
}
|
|
2737
|
+
const shouldApplyMask = optionsEl.scrollHeight > SCROLL_THRESHOLD;
|
|
2738
|
+
if (shouldApplyMask) {
|
|
2739
|
+
optionsEl.style.setProperty('--options-mask-image', `linear-gradient(
|
|
2740
|
+
to bottom,
|
|
2741
|
+
rgba(0, 0, 0, calc(1 - var(--options-scroll--top-opacity))) 0px,
|
|
2742
|
+
rgba(200, 200, 200, calc(1 - var(--options-scroll--top-opacity))) 1px,
|
|
2743
|
+
black 50px,
|
|
2744
|
+
black calc(100% - 50px),
|
|
2745
|
+
rgba(155, 155, 155, calc(1 - var(--options-scroll--bottom-opacity))) calc(100% - 1px),
|
|
2746
|
+
rgba(0, 0, 0, calc(1 - var(--options-scroll--bottom-opacity))) 100%
|
|
2747
|
+
)`);
|
|
2748
|
+
optionsEl.style.setProperty('--options-scroll--top-opacity', MathUtil.interpolate([0, 50], [0, 1], optionsEl.scrollTop).toString());
|
|
2749
|
+
optionsEl.style.setProperty('--options-scroll--bottom-opacity', MathUtil.interpolate([0, 50], [0, 1], optionsEl.scrollHeight - optionsEl.scrollTop - optionsEl.offsetHeight).toString());
|
|
2750
|
+
}
|
|
2751
|
+
else {
|
|
2752
|
+
optionsEl.style.setProperty('--options-mask-image', 'none');
|
|
2753
|
+
optionsEl.style.setProperty('--options-scroll--top-opacity', '0');
|
|
2754
|
+
optionsEl.style.setProperty('--options-scroll--bottom-opacity', '0');
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
};
|
|
2758
|
+
W3mPayOptions.styles = [styles$1];
|
|
2759
|
+
__decorate$1([
|
|
2760
|
+
n({ type: Array })
|
|
2761
|
+
], W3mPayOptions.prototype, "options", void 0);
|
|
2762
|
+
__decorate$1([
|
|
2763
|
+
n()
|
|
2764
|
+
], W3mPayOptions.prototype, "selectedPaymentAsset", void 0);
|
|
2765
|
+
__decorate$1([
|
|
2766
|
+
n()
|
|
2767
|
+
], W3mPayOptions.prototype, "onSelect", void 0);
|
|
2768
|
+
W3mPayOptions = __decorate$1([
|
|
2769
|
+
customElement('w3m-pay-options')
|
|
2770
|
+
], W3mPayOptions);
|
|
2771
|
+
|
|
2772
|
+
var styles = css `
|
|
2773
|
+
.payment-methods-container {
|
|
2774
|
+
background-color: ${({ tokens }) => tokens.theme.foregroundPrimary};
|
|
2775
|
+
border-top-right-radius: ${({ borderRadius }) => borderRadius[5]};
|
|
2776
|
+
border-top-left-radius: ${({ borderRadius }) => borderRadius[5]};
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2779
|
+
.pay-options-container {
|
|
2780
|
+
background-color: ${({ tokens }) => tokens.theme.foregroundSecondary};
|
|
2781
|
+
border-radius: ${({ borderRadius }) => borderRadius[5]};
|
|
2782
|
+
padding: ${({ spacing }) => spacing[1]};
|
|
2783
|
+
}
|
|
2784
|
+
|
|
2785
|
+
w3m-tooltip-trigger {
|
|
2786
|
+
display: flex;
|
|
2787
|
+
align-items: center;
|
|
2788
|
+
justify-content: center;
|
|
2789
|
+
max-width: fit-content;
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2792
|
+
wui-image {
|
|
2793
|
+
border-radius: ${({ borderRadius }) => borderRadius.round};
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
w3m-pay-options.disabled {
|
|
2797
|
+
opacity: 0.5;
|
|
2798
|
+
pointer-events: none;
|
|
2799
|
+
}
|
|
2800
|
+
`;
|
|
2801
|
+
|
|
2802
|
+
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
2803
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2804
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2805
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2806
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2807
|
+
};
|
|
2808
|
+
const NAMESPACE_ICONS = {
|
|
2809
|
+
eip155: 'ethereum',
|
|
2810
|
+
solana: 'solana',
|
|
2811
|
+
bip122: 'bitcoin',
|
|
2812
|
+
ton: 'ton'
|
|
2813
|
+
};
|
|
2814
|
+
const NAMESPACE_LABELS = {
|
|
2815
|
+
eip155: { icon: NAMESPACE_ICONS.eip155, label: 'EVM' },
|
|
2816
|
+
solana: { icon: NAMESPACE_ICONS.solana, label: 'Solana' },
|
|
2817
|
+
bip122: { icon: NAMESPACE_ICONS.bip122, label: 'Bitcoin' },
|
|
2818
|
+
ton: { icon: NAMESPACE_ICONS.ton, label: 'Ton' }
|
|
2819
|
+
};
|
|
2820
|
+
let W3mPayQuoteView = class W3mPayQuoteView extends i {
|
|
2821
|
+
constructor() {
|
|
2822
|
+
super();
|
|
2823
|
+
this.unsubscribe = [];
|
|
2824
|
+
this.profileName = null;
|
|
2825
|
+
this.paymentAsset = PayController.state.paymentAsset;
|
|
2826
|
+
this.namespace = undefined;
|
|
2827
|
+
this.caipAddress = undefined;
|
|
2828
|
+
this.amount = PayController.state.amount;
|
|
2829
|
+
this.recipient = PayController.state.recipient;
|
|
2830
|
+
this.activeConnectorIds = ConnectorController.state.activeConnectorIds;
|
|
2831
|
+
this.selectedPaymentAsset = PayController.state.selectedPaymentAsset;
|
|
2832
|
+
this.selectedExchange = PayController.state.selectedExchange;
|
|
2833
|
+
this.isFetchingQuote = PayController.state.isFetchingQuote;
|
|
2834
|
+
this.quoteError = PayController.state.quoteError;
|
|
2835
|
+
this.quote = PayController.state.quote;
|
|
2836
|
+
this.isFetchingTokenBalances = PayController.state.isFetchingTokenBalances;
|
|
2837
|
+
this.tokenBalances = PayController.state.tokenBalances;
|
|
2838
|
+
this.isPaymentInProgress = PayController.state.isPaymentInProgress;
|
|
2839
|
+
this.exchangeUrlForQuote = PayController.state.exchangeUrlForQuote;
|
|
2840
|
+
this.completedTransactionsCount = 0;
|
|
2841
|
+
this.unsubscribe.push(PayController.subscribeKey('paymentAsset', val => (this.paymentAsset = val)));
|
|
2842
|
+
this.unsubscribe.push(PayController.subscribeKey('tokenBalances', val => this.onTokenBalancesChanged(val)));
|
|
2843
|
+
this.unsubscribe.push(PayController.subscribeKey('isFetchingTokenBalances', val => (this.isFetchingTokenBalances = val)));
|
|
2844
|
+
this.unsubscribe.push(ConnectorController.subscribeKey('activeConnectorIds', newActiveConnectorIds => (this.activeConnectorIds = newActiveConnectorIds)));
|
|
2845
|
+
this.unsubscribe.push(PayController.subscribeKey('selectedPaymentAsset', val => (this.selectedPaymentAsset = val)));
|
|
2846
|
+
this.unsubscribe.push(PayController.subscribeKey('isFetchingQuote', val => (this.isFetchingQuote = val)));
|
|
2847
|
+
this.unsubscribe.push(PayController.subscribeKey('quoteError', val => (this.quoteError = val)));
|
|
2848
|
+
this.unsubscribe.push(PayController.subscribeKey('quote', val => (this.quote = val)));
|
|
2849
|
+
this.unsubscribe.push(PayController.subscribeKey('amount', val => (this.amount = val)));
|
|
2850
|
+
this.unsubscribe.push(PayController.subscribeKey('recipient', val => (this.recipient = val)));
|
|
2851
|
+
this.unsubscribe.push(PayController.subscribeKey('isPaymentInProgress', val => (this.isPaymentInProgress = val)));
|
|
2852
|
+
this.unsubscribe.push(PayController.subscribeKey('selectedExchange', val => (this.selectedExchange = val)));
|
|
2853
|
+
this.unsubscribe.push(PayController.subscribeKey('exchangeUrlForQuote', val => (this.exchangeUrlForQuote = val)));
|
|
2854
|
+
this.resetQuoteState();
|
|
2855
|
+
this.initializeNamespace();
|
|
2856
|
+
this.fetchTokens();
|
|
2857
|
+
}
|
|
2858
|
+
disconnectedCallback() {
|
|
2859
|
+
super.disconnectedCallback();
|
|
2860
|
+
this.resetAssetsState();
|
|
2861
|
+
this.unsubscribe.forEach(unsubscribe => unsubscribe());
|
|
2862
|
+
}
|
|
2863
|
+
updated(changedProperties) {
|
|
2864
|
+
super.updated(changedProperties);
|
|
2865
|
+
const shouldFetchQuote = changedProperties.has('selectedPaymentAsset');
|
|
2866
|
+
if (shouldFetchQuote) {
|
|
2867
|
+
this.fetchQuote();
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
render() {
|
|
2871
|
+
return b `
|
|
2872
|
+
<wui-flex flexDirection="column">
|
|
2873
|
+
${this.profileTemplate()}
|
|
2874
|
+
|
|
2875
|
+
<wui-flex
|
|
2876
|
+
flexDirection="column"
|
|
2877
|
+
gap="4"
|
|
2878
|
+
class="payment-methods-container"
|
|
2879
|
+
.padding=${['4', '4', '5', '4']}
|
|
2880
|
+
>
|
|
2881
|
+
${this.paymentOptionsViewTemplate()} ${this.amountWithFeeTemplate()}
|
|
2882
|
+
|
|
2883
|
+
<wui-flex
|
|
2884
|
+
alignItems="center"
|
|
2885
|
+
justifyContent="space-between"
|
|
2886
|
+
.padding=${['1', '0', '1', '0']}
|
|
2887
|
+
>
|
|
2888
|
+
<wui-separator></wui-separator>
|
|
2889
|
+
</wui-flex>
|
|
2890
|
+
|
|
2891
|
+
${this.paymentActionsTemplate()}
|
|
2892
|
+
</wui-flex>
|
|
2893
|
+
</wui-flex>
|
|
2894
|
+
`;
|
|
2895
|
+
}
|
|
2896
|
+
profileTemplate() {
|
|
2897
|
+
if (this.selectedExchange) {
|
|
2898
|
+
const amount = NumberUtil.formatNumber(this.quote?.origin.amount, {
|
|
2899
|
+
decimals: this.quote?.origin.currency.metadata.decimals ?? 0
|
|
2900
|
+
}).toString();
|
|
2901
|
+
return b `
|
|
2902
|
+
<wui-flex
|
|
2903
|
+
.padding=${['4', '3', '4', '3']}
|
|
2904
|
+
alignItems="center"
|
|
2905
|
+
justifyContent="space-between"
|
|
2906
|
+
gap="2"
|
|
2907
|
+
>
|
|
2908
|
+
<wui-text variant="lg-regular" color="secondary">Paying with</wui-text>
|
|
2909
|
+
|
|
2910
|
+
${this.quote
|
|
2911
|
+
? b `<wui-text variant="lg-regular" color="primary">
|
|
2912
|
+
${NumberUtil.bigNumber(amount, { safe: true }).round(6).toString()}
|
|
2913
|
+
${this.quote.origin.currency.metadata.symbol}
|
|
2914
|
+
</wui-text>`
|
|
2915
|
+
: b `<wui-shimmer width="80px" height="18px" variant="light"></wui-shimmer>`}
|
|
2916
|
+
</wui-flex>
|
|
2917
|
+
`;
|
|
2918
|
+
}
|
|
2919
|
+
const address = CoreHelperUtil.getPlainAddress(this.caipAddress) ?? '';
|
|
2920
|
+
const { name, image } = this.getWalletProperties({ namespace: this.namespace });
|
|
2921
|
+
const { icon: chainIcon, label: chainLabel } = NAMESPACE_LABELS[this.namespace] ?? {};
|
|
2922
|
+
return b `
|
|
2923
|
+
<wui-flex
|
|
2924
|
+
.padding=${['4', '3', '4', '3']}
|
|
2925
|
+
alignItems="center"
|
|
2926
|
+
justifyContent="space-between"
|
|
2927
|
+
gap="2"
|
|
2928
|
+
>
|
|
2929
|
+
<wui-wallet-switch
|
|
2930
|
+
profileName=${o(this.profileName)}
|
|
2931
|
+
address=${o(address)}
|
|
2932
|
+
imageSrc=${o(image)}
|
|
2933
|
+
alt=${o(name)}
|
|
2934
|
+
@click=${this.onConnectOtherWallet.bind(this)}
|
|
2935
|
+
data-testid="wui-wallet-switch"
|
|
2936
|
+
></wui-wallet-switch>
|
|
2937
|
+
|
|
2938
|
+
<wui-wallet-switch
|
|
2939
|
+
profileName=${o(chainLabel)}
|
|
2940
|
+
address=${o(address)}
|
|
2941
|
+
icon=${o(chainIcon)}
|
|
2942
|
+
iconSize="xs"
|
|
2943
|
+
.enableGreenCircle=${false}
|
|
2944
|
+
alt=${o(chainLabel)}
|
|
2945
|
+
@click=${this.onConnectOtherWallet.bind(this)}
|
|
2946
|
+
data-testid="wui-wallet-switch"
|
|
2947
|
+
></wui-wallet-switch>
|
|
2948
|
+
</wui-flex>
|
|
2949
|
+
`;
|
|
2950
|
+
}
|
|
2951
|
+
initializeNamespace() {
|
|
2952
|
+
const namespace = ChainController.state.activeChain;
|
|
2953
|
+
this.namespace = namespace;
|
|
2954
|
+
this.caipAddress = ChainController.getAccountData(namespace)?.caipAddress;
|
|
2955
|
+
this.profileName = ChainController.getAccountData(namespace)?.profileName ?? null;
|
|
2956
|
+
this.unsubscribe.push(ChainController.subscribeChainProp('accountState', accountState => this.onAccountStateChanged(accountState), namespace));
|
|
2957
|
+
}
|
|
2958
|
+
async fetchTokens() {
|
|
2959
|
+
if (this.namespace) {
|
|
2960
|
+
let caipNetwork = undefined;
|
|
2961
|
+
if (this.caipAddress) {
|
|
2962
|
+
const { chainId, chainNamespace } = ParseUtil.parseCaipAddress(this.caipAddress);
|
|
2963
|
+
const caipNetworkId = `${chainNamespace}:${chainId}`;
|
|
2964
|
+
const allNetworks = ChainController.getAllRequestedCaipNetworks();
|
|
2965
|
+
caipNetwork = allNetworks.find(net => net.caipNetworkId === caipNetworkId);
|
|
2966
|
+
}
|
|
2967
|
+
await PayController.fetchTokens({
|
|
2968
|
+
caipAddress: this.caipAddress,
|
|
2969
|
+
caipNetwork,
|
|
2970
|
+
namespace: this.namespace
|
|
2971
|
+
});
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
fetchQuote() {
|
|
2975
|
+
if (this.amount && this.recipient && this.selectedPaymentAsset && this.paymentAsset) {
|
|
2976
|
+
const { address } = this.caipAddress ? ParseUtil.parseCaipAddress(this.caipAddress) : {};
|
|
2977
|
+
PayController.fetchQuote({
|
|
2978
|
+
amount: this.amount.toString(),
|
|
2979
|
+
address,
|
|
2980
|
+
sourceToken: this.selectedPaymentAsset,
|
|
2981
|
+
toToken: this.paymentAsset,
|
|
2982
|
+
recipient: this.recipient
|
|
2983
|
+
});
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
getWalletProperties({ namespace }) {
|
|
2987
|
+
if (!namespace) {
|
|
2988
|
+
return {
|
|
2989
|
+
name: undefined,
|
|
2990
|
+
image: undefined
|
|
2991
|
+
};
|
|
2992
|
+
}
|
|
2993
|
+
const connectorId = this.activeConnectorIds[namespace];
|
|
2994
|
+
if (!connectorId) {
|
|
2995
|
+
return {
|
|
2996
|
+
name: undefined,
|
|
2997
|
+
image: undefined
|
|
2998
|
+
};
|
|
2999
|
+
}
|
|
3000
|
+
const connector = ConnectorController.getConnector({ id: connectorId, namespace });
|
|
3001
|
+
if (!connector) {
|
|
3002
|
+
return {
|
|
3003
|
+
name: undefined,
|
|
3004
|
+
image: undefined
|
|
3005
|
+
};
|
|
3006
|
+
}
|
|
3007
|
+
const connectorImage = AssetUtil.getConnectorImage(connector);
|
|
3008
|
+
return {
|
|
3009
|
+
name: connector.name,
|
|
3010
|
+
image: connectorImage
|
|
3011
|
+
};
|
|
3012
|
+
}
|
|
3013
|
+
paymentOptionsViewTemplate() {
|
|
3014
|
+
return b `
|
|
3015
|
+
<wui-flex flexDirection="column" gap="2">
|
|
3016
|
+
<wui-text variant="sm-regular" color="secondary">CHOOSE PAYMENT OPTION</wui-text>
|
|
3017
|
+
<wui-flex class="pay-options-container">${this.paymentOptionsTemplate()}</wui-flex>
|
|
3018
|
+
</wui-flex>
|
|
3019
|
+
`;
|
|
3020
|
+
}
|
|
3021
|
+
paymentOptionsTemplate() {
|
|
3022
|
+
const paymentAssets = this.getPaymentAssetFromTokenBalances();
|
|
3023
|
+
if (this.isFetchingTokenBalances) {
|
|
3024
|
+
return b `<w3m-pay-options-skeleton></w3m-pay-options-skeleton>`;
|
|
3025
|
+
}
|
|
3026
|
+
if (paymentAssets.length === 0) {
|
|
3027
|
+
return b `<w3m-pay-options-empty
|
|
3028
|
+
@connectOtherWallet=${this.onConnectOtherWallet.bind(this)}
|
|
3029
|
+
></w3m-pay-options-empty>`;
|
|
3030
|
+
}
|
|
3031
|
+
const classes = {
|
|
3032
|
+
disabled: this.isFetchingQuote
|
|
3033
|
+
};
|
|
3034
|
+
return b `<w3m-pay-options
|
|
3035
|
+
class=${e(classes)}
|
|
3036
|
+
.options=${paymentAssets}
|
|
3037
|
+
.selectedPaymentAsset=${o(this.selectedPaymentAsset)}
|
|
3038
|
+
.onSelect=${this.onSelectedPaymentAssetChanged.bind(this)}
|
|
3039
|
+
></w3m-pay-options>`;
|
|
3040
|
+
}
|
|
3041
|
+
amountWithFeeTemplate() {
|
|
3042
|
+
if (this.isFetchingQuote || !this.selectedPaymentAsset || this.quoteError) {
|
|
3043
|
+
return b `<w3m-pay-fees-skeleton></w3m-pay-fees-skeleton>`;
|
|
3044
|
+
}
|
|
3045
|
+
return b `<w3m-pay-fees></w3m-pay-fees>`;
|
|
3046
|
+
}
|
|
3047
|
+
paymentActionsTemplate() {
|
|
3048
|
+
const isLoading = this.isFetchingQuote || this.isFetchingTokenBalances;
|
|
3049
|
+
const isDisabled = this.isFetchingQuote ||
|
|
3050
|
+
this.isFetchingTokenBalances ||
|
|
3051
|
+
!this.selectedPaymentAsset ||
|
|
3052
|
+
Boolean(this.quoteError);
|
|
3053
|
+
const amount = NumberUtil.formatNumber(this.quote?.origin.amount ?? 0, {
|
|
3054
|
+
decimals: this.quote?.origin.currency.metadata.decimals ?? 0
|
|
3055
|
+
}).toString();
|
|
3056
|
+
if (this.selectedExchange) {
|
|
3057
|
+
if (isLoading || isDisabled) {
|
|
3058
|
+
return b `
|
|
3059
|
+
<wui-shimmer width="100%" height="48px" variant="light" ?rounded=${true}></wui-shimmer>
|
|
3060
|
+
`;
|
|
3061
|
+
}
|
|
3062
|
+
return b `<wui-button
|
|
3063
|
+
size="lg"
|
|
3064
|
+
fullWidth
|
|
3065
|
+
variant="accent-secondary"
|
|
3066
|
+
@click=${this.onPayWithExchange.bind(this)}
|
|
3067
|
+
>
|
|
3068
|
+
${`Continue in ${this.selectedExchange.name}`}
|
|
3069
|
+
|
|
3070
|
+
<wui-icon name="arrowRight" color="inherit" size="sm" slot="iconRight"></wui-icon>
|
|
3071
|
+
</wui-button>`;
|
|
3072
|
+
}
|
|
3073
|
+
return b `
|
|
3074
|
+
<wui-flex alignItems="center" justifyContent="space-between">
|
|
3075
|
+
<wui-flex flexDirection="column" gap="1">
|
|
3076
|
+
<wui-text variant="md-regular" color="secondary">Order Total</wui-text>
|
|
3077
|
+
|
|
3078
|
+
${isLoading || isDisabled
|
|
3079
|
+
? b `<wui-shimmer width="58px" height="32px" variant="light"></wui-shimmer>`
|
|
3080
|
+
: b `<wui-flex alignItems="center" gap="01">
|
|
3081
|
+
<wui-text variant="h4-regular" color="primary">${formatAmount(amount)}</wui-text>
|
|
3082
|
+
|
|
3083
|
+
<wui-text variant="lg-regular" color="secondary">
|
|
3084
|
+
${this.quote?.origin.currency.metadata.symbol || 'Unknown'}
|
|
3085
|
+
</wui-text>
|
|
3086
|
+
</wui-flex>`}
|
|
3087
|
+
</wui-flex>
|
|
3088
|
+
|
|
3089
|
+
${this.actionButtonTemplate({ isLoading, isDisabled })}
|
|
3090
|
+
</wui-flex>
|
|
3091
|
+
`;
|
|
3092
|
+
}
|
|
3093
|
+
actionButtonTemplate(params) {
|
|
3094
|
+
const allTransactionSteps = getTransactionsSteps(this.quote);
|
|
3095
|
+
const { isLoading, isDisabled } = params;
|
|
3096
|
+
let label = 'Pay';
|
|
3097
|
+
const isApprovalRequired = allTransactionSteps.length > 1 && this.completedTransactionsCount === 0;
|
|
3098
|
+
if (isApprovalRequired) {
|
|
3099
|
+
label = 'Approve';
|
|
3100
|
+
}
|
|
3101
|
+
return b `
|
|
3102
|
+
<wui-button
|
|
3103
|
+
size="lg"
|
|
3104
|
+
variant="accent-primary"
|
|
3105
|
+
?loading=${isLoading || this.isPaymentInProgress}
|
|
3106
|
+
?disabled=${isDisabled || this.isPaymentInProgress}
|
|
3107
|
+
@click=${() => {
|
|
3108
|
+
if (allTransactionSteps.length > 0) {
|
|
3109
|
+
this.onSendTransactions();
|
|
3110
|
+
}
|
|
3111
|
+
else {
|
|
3112
|
+
this.onTransfer();
|
|
3113
|
+
}
|
|
3114
|
+
}}
|
|
3115
|
+
>
|
|
3116
|
+
${label}
|
|
3117
|
+
${isLoading
|
|
3118
|
+
? null
|
|
3119
|
+
: b `<wui-icon
|
|
3120
|
+
name="arrowRight"
|
|
3121
|
+
color="inherit"
|
|
3122
|
+
size="sm"
|
|
3123
|
+
slot="iconRight"
|
|
3124
|
+
></wui-icon>`}
|
|
3125
|
+
</wui-button>
|
|
3126
|
+
`;
|
|
3127
|
+
}
|
|
3128
|
+
getPaymentAssetFromTokenBalances() {
|
|
3129
|
+
if (!this.namespace) {
|
|
3130
|
+
return [];
|
|
3131
|
+
}
|
|
3132
|
+
const balances = this.tokenBalances[this.namespace] ?? [];
|
|
3133
|
+
const paymentOptionsWithFormattedBalances = balances
|
|
3134
|
+
.map(balance => {
|
|
3135
|
+
try {
|
|
3136
|
+
return formatBalanceToPaymentAsset(balance);
|
|
3137
|
+
}
|
|
3138
|
+
catch (err) {
|
|
3139
|
+
return null;
|
|
3140
|
+
}
|
|
3141
|
+
})
|
|
3142
|
+
.filter((option) => Boolean(option));
|
|
3143
|
+
const paymentOptionsToShow = paymentOptionsWithFormattedBalances.filter(option => {
|
|
3144
|
+
const { chainId: optionChainId } = ParseUtil.parseCaipNetworkId(option.network);
|
|
3145
|
+
const { chainId: paymentAssetChainId } = ParseUtil.parseCaipNetworkId(this.paymentAsset.network);
|
|
3146
|
+
if (HelpersUtil.isLowerCaseMatch(option.asset, this.paymentAsset.asset)) {
|
|
3147
|
+
return true;
|
|
3148
|
+
}
|
|
3149
|
+
if (this.selectedExchange) {
|
|
3150
|
+
return !HelpersUtil.isLowerCaseMatch(optionChainId.toString(), paymentAssetChainId.toString());
|
|
3151
|
+
}
|
|
3152
|
+
return true;
|
|
3153
|
+
});
|
|
3154
|
+
return paymentOptionsToShow;
|
|
3155
|
+
}
|
|
3156
|
+
onTokenBalancesChanged(tokenBalances) {
|
|
3157
|
+
this.tokenBalances = tokenBalances;
|
|
3158
|
+
const [paymentAsset] = this.getPaymentAssetFromTokenBalances();
|
|
3159
|
+
if (paymentAsset) {
|
|
3160
|
+
PayController.setSelectedPaymentAsset(paymentAsset);
|
|
3161
|
+
}
|
|
3162
|
+
}
|
|
3163
|
+
async onConnectOtherWallet() {
|
|
3164
|
+
await ConnectorController.connect();
|
|
3165
|
+
await ModalController.open({ view: 'PayQuote' });
|
|
3166
|
+
}
|
|
3167
|
+
onAccountStateChanged(accountState) {
|
|
3168
|
+
const { address: oldAddress } = this.caipAddress
|
|
3169
|
+
? ParseUtil.parseCaipAddress(this.caipAddress)
|
|
3170
|
+
: {};
|
|
3171
|
+
this.caipAddress = accountState?.caipAddress;
|
|
3172
|
+
this.profileName = accountState?.profileName ?? null;
|
|
3173
|
+
if (oldAddress) {
|
|
3174
|
+
const { address: newAddress } = this.caipAddress
|
|
3175
|
+
? ParseUtil.parseCaipAddress(this.caipAddress)
|
|
3176
|
+
: {};
|
|
3177
|
+
if (!newAddress) {
|
|
3178
|
+
ModalController.close();
|
|
3179
|
+
}
|
|
3180
|
+
else if (!HelpersUtil.isLowerCaseMatch(newAddress, oldAddress)) {
|
|
3181
|
+
this.resetAssetsState();
|
|
3182
|
+
this.resetQuoteState();
|
|
3183
|
+
this.fetchTokens();
|
|
3184
|
+
}
|
|
3185
|
+
}
|
|
3186
|
+
}
|
|
3187
|
+
onSelectedPaymentAssetChanged(paymentAsset) {
|
|
3188
|
+
if (!this.isFetchingQuote) {
|
|
3189
|
+
PayController.setSelectedPaymentAsset(paymentAsset);
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
async onTransfer() {
|
|
3193
|
+
const transferStep = getTransferStep(this.quote);
|
|
3194
|
+
if (transferStep) {
|
|
3195
|
+
const isQuoteAssetSameAsSelectedPaymentAsset = HelpersUtil.isLowerCaseMatch(this.selectedPaymentAsset?.asset, transferStep.deposit.currency);
|
|
3196
|
+
if (!isQuoteAssetSameAsSelectedPaymentAsset) {
|
|
3197
|
+
throw new Error('Quote asset is not the same as the selected payment asset');
|
|
3198
|
+
}
|
|
3199
|
+
const currentAmount = this.selectedPaymentAsset?.amount ?? '0';
|
|
3200
|
+
const amountToTransfer = NumberUtil.formatNumber(transferStep.deposit.amount, {
|
|
3201
|
+
decimals: this.selectedPaymentAsset?.metadata.decimals ?? 0
|
|
3202
|
+
}).toString();
|
|
3203
|
+
const hasEnoughFunds = NumberUtil.bigNumber(currentAmount).gte(amountToTransfer);
|
|
3204
|
+
if (!hasEnoughFunds) {
|
|
3205
|
+
SnackController.showError('Insufficient funds');
|
|
3206
|
+
return;
|
|
3207
|
+
}
|
|
3208
|
+
if (this.quote && this.selectedPaymentAsset && this.caipAddress && this.namespace) {
|
|
3209
|
+
const { address: fromAddress } = ParseUtil.parseCaipAddress(this.caipAddress);
|
|
3210
|
+
await PayController.onTransfer({
|
|
3211
|
+
chainNamespace: this.namespace,
|
|
3212
|
+
fromAddress,
|
|
3213
|
+
toAddress: transferStep.deposit.receiver,
|
|
3214
|
+
amount: amountToTransfer,
|
|
3215
|
+
paymentAsset: this.selectedPaymentAsset
|
|
3216
|
+
});
|
|
3217
|
+
PayController.setRequestId(transferStep.requestId);
|
|
3218
|
+
RouterController.push('PayLoading');
|
|
3219
|
+
}
|
|
3220
|
+
}
|
|
3221
|
+
}
|
|
3222
|
+
async onSendTransactions() {
|
|
3223
|
+
const currentAmount = this.selectedPaymentAsset?.amount ?? '0';
|
|
3224
|
+
const amountToSwap = NumberUtil.formatNumber(this.quote?.origin.amount ?? 0, {
|
|
3225
|
+
decimals: this.selectedPaymentAsset?.metadata.decimals ?? 0
|
|
3226
|
+
}).toString();
|
|
3227
|
+
const hasEnoughFunds = NumberUtil.bigNumber(currentAmount).gte(amountToSwap);
|
|
3228
|
+
if (!hasEnoughFunds) {
|
|
3229
|
+
SnackController.showError('Insufficient funds');
|
|
3230
|
+
return;
|
|
3231
|
+
}
|
|
3232
|
+
const allTransactionSteps = getTransactionsSteps(this.quote);
|
|
3233
|
+
const [transactionStep] = getTransactionsSteps(this.quote, this.completedTransactionsCount);
|
|
3234
|
+
if (transactionStep && this.namespace) {
|
|
3235
|
+
await PayController.onSendTransaction({
|
|
3236
|
+
namespace: this.namespace,
|
|
3237
|
+
transactionStep
|
|
3238
|
+
});
|
|
3239
|
+
this.completedTransactionsCount += 1;
|
|
3240
|
+
const hasCompletedAllTransactions = this.completedTransactionsCount === allTransactionSteps.length;
|
|
3241
|
+
if (hasCompletedAllTransactions) {
|
|
3242
|
+
PayController.setRequestId(transactionStep.requestId);
|
|
3243
|
+
RouterController.push('PayLoading');
|
|
3244
|
+
}
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
onPayWithExchange() {
|
|
3248
|
+
if (this.exchangeUrlForQuote) {
|
|
3249
|
+
const popupWindow = CoreHelperUtil.returnOpenHref('', 'popupWindow', 'scrollbar=yes,width=480,height=720');
|
|
3250
|
+
if (!popupWindow) {
|
|
3251
|
+
throw new Error('Could not create popup window');
|
|
3252
|
+
}
|
|
3253
|
+
popupWindow.location.href = this.exchangeUrlForQuote;
|
|
3254
|
+
const transactionStep = getTransferStep(this.quote);
|
|
3255
|
+
if (transactionStep) {
|
|
3256
|
+
PayController.setRequestId(transactionStep.requestId);
|
|
3257
|
+
}
|
|
3258
|
+
PayController.initiatePayment();
|
|
3259
|
+
RouterController.push('PayLoading');
|
|
3260
|
+
}
|
|
3261
|
+
}
|
|
3262
|
+
resetAssetsState() {
|
|
3263
|
+
PayController.setSelectedPaymentAsset(null);
|
|
3264
|
+
}
|
|
3265
|
+
resetQuoteState() {
|
|
3266
|
+
PayController.resetQuoteState();
|
|
3267
|
+
}
|
|
3268
|
+
};
|
|
3269
|
+
W3mPayQuoteView.styles = styles;
|
|
3270
|
+
__decorate([
|
|
3271
|
+
r()
|
|
3272
|
+
], W3mPayQuoteView.prototype, "profileName", void 0);
|
|
3273
|
+
__decorate([
|
|
3274
|
+
r()
|
|
3275
|
+
], W3mPayQuoteView.prototype, "paymentAsset", void 0);
|
|
3276
|
+
__decorate([
|
|
3277
|
+
r()
|
|
3278
|
+
], W3mPayQuoteView.prototype, "namespace", void 0);
|
|
3279
|
+
__decorate([
|
|
3280
|
+
r()
|
|
3281
|
+
], W3mPayQuoteView.prototype, "caipAddress", void 0);
|
|
3282
|
+
__decorate([
|
|
3283
|
+
r()
|
|
3284
|
+
], W3mPayQuoteView.prototype, "amount", void 0);
|
|
3285
|
+
__decorate([
|
|
3286
|
+
r()
|
|
3287
|
+
], W3mPayQuoteView.prototype, "recipient", void 0);
|
|
3288
|
+
__decorate([
|
|
3289
|
+
r()
|
|
3290
|
+
], W3mPayQuoteView.prototype, "activeConnectorIds", void 0);
|
|
3291
|
+
__decorate([
|
|
3292
|
+
r()
|
|
3293
|
+
], W3mPayQuoteView.prototype, "selectedPaymentAsset", void 0);
|
|
3294
|
+
__decorate([
|
|
3295
|
+
r()
|
|
3296
|
+
], W3mPayQuoteView.prototype, "selectedExchange", void 0);
|
|
3297
|
+
__decorate([
|
|
3298
|
+
r()
|
|
3299
|
+
], W3mPayQuoteView.prototype, "isFetchingQuote", void 0);
|
|
3300
|
+
__decorate([
|
|
3301
|
+
r()
|
|
3302
|
+
], W3mPayQuoteView.prototype, "quoteError", void 0);
|
|
3303
|
+
__decorate([
|
|
3304
|
+
r()
|
|
3305
|
+
], W3mPayQuoteView.prototype, "quote", void 0);
|
|
3306
|
+
__decorate([
|
|
3307
|
+
r()
|
|
3308
|
+
], W3mPayQuoteView.prototype, "isFetchingTokenBalances", void 0);
|
|
3309
|
+
__decorate([
|
|
3310
|
+
r()
|
|
3311
|
+
], W3mPayQuoteView.prototype, "tokenBalances", void 0);
|
|
3312
|
+
__decorate([
|
|
3313
|
+
r()
|
|
3314
|
+
], W3mPayQuoteView.prototype, "isPaymentInProgress", void 0);
|
|
3315
|
+
__decorate([
|
|
3316
|
+
r()
|
|
3317
|
+
], W3mPayQuoteView.prototype, "exchangeUrlForQuote", void 0);
|
|
3318
|
+
__decorate([
|
|
3319
|
+
r()
|
|
3320
|
+
], W3mPayQuoteView.prototype, "completedTransactionsCount", void 0);
|
|
3321
|
+
W3mPayQuoteView = __decorate([
|
|
3322
|
+
customElement('w3m-pay-quote-view')
|
|
3323
|
+
], W3mPayQuoteView);
|
|
3324
|
+
|
|
3325
|
+
const PAYMENT_TIMEOUT_MS = 300000;
|
|
3326
|
+
async function openPay(options) {
|
|
3327
|
+
return PayController.handleOpenPay(options);
|
|
3328
|
+
}
|
|
3329
|
+
async function pay(options, timeoutMs = PAYMENT_TIMEOUT_MS) {
|
|
3330
|
+
if (timeoutMs <= 0) {
|
|
3331
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG, 'Timeout must be greater than 0');
|
|
3332
|
+
}
|
|
3333
|
+
try {
|
|
3334
|
+
await openPay(options);
|
|
3335
|
+
}
|
|
3336
|
+
catch (error) {
|
|
3337
|
+
if (error instanceof AppKitPayError) {
|
|
3338
|
+
throw error;
|
|
3339
|
+
}
|
|
3340
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_INITIATE_PAYMENT, error.message);
|
|
3341
|
+
}
|
|
3342
|
+
return new Promise((resolve, reject) => {
|
|
3343
|
+
let isSettled = false;
|
|
3344
|
+
const timeoutId = setTimeout(() => {
|
|
3345
|
+
if (isSettled) {
|
|
3346
|
+
return;
|
|
3347
|
+
}
|
|
3348
|
+
isSettled = true;
|
|
3349
|
+
cleanup();
|
|
3350
|
+
reject(new AppKitPayError(AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR, 'Payment timeout'));
|
|
3351
|
+
}, timeoutMs);
|
|
3352
|
+
function checkAndResolve() {
|
|
3353
|
+
if (isSettled) {
|
|
3354
|
+
return;
|
|
3355
|
+
}
|
|
3356
|
+
const currentPayment = PayController.state.currentPayment;
|
|
3357
|
+
const error = PayController.state.error;
|
|
3358
|
+
const isInProgress = PayController.state.isPaymentInProgress;
|
|
3359
|
+
if (currentPayment?.status === 'SUCCESS') {
|
|
3360
|
+
isSettled = true;
|
|
3361
|
+
cleanup();
|
|
3362
|
+
clearTimeout(timeoutId);
|
|
3363
|
+
resolve({
|
|
3364
|
+
success: true,
|
|
3365
|
+
result: currentPayment.result
|
|
3366
|
+
});
|
|
3367
|
+
return;
|
|
3368
|
+
}
|
|
3369
|
+
if (currentPayment?.status === 'FAILED') {
|
|
3370
|
+
isSettled = true;
|
|
3371
|
+
cleanup();
|
|
3372
|
+
clearTimeout(timeoutId);
|
|
3373
|
+
resolve({
|
|
3374
|
+
success: false,
|
|
3375
|
+
error: error || 'Payment failed'
|
|
3376
|
+
});
|
|
3377
|
+
return;
|
|
3378
|
+
}
|
|
3379
|
+
if (error && !isInProgress && !currentPayment) {
|
|
3380
|
+
isSettled = true;
|
|
3381
|
+
cleanup();
|
|
3382
|
+
clearTimeout(timeoutId);
|
|
3383
|
+
resolve({
|
|
3384
|
+
success: false,
|
|
3385
|
+
error
|
|
3386
|
+
});
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
const unsubscribePayment = subscribeStateKey('currentPayment', checkAndResolve);
|
|
3390
|
+
const unsubscribeError = subscribeStateKey('error', checkAndResolve);
|
|
3391
|
+
const unsubscribeProgress = subscribeStateKey('isPaymentInProgress', checkAndResolve);
|
|
3392
|
+
const cleanup = createCleanupHandler([
|
|
3393
|
+
unsubscribePayment,
|
|
3394
|
+
unsubscribeError,
|
|
3395
|
+
unsubscribeProgress
|
|
3396
|
+
]);
|
|
3397
|
+
checkAndResolve();
|
|
3398
|
+
});
|
|
3399
|
+
}
|
|
3400
|
+
function getAvailableExchanges(params) {
|
|
3401
|
+
return PayController.getAvailableExchanges(params);
|
|
3402
|
+
}
|
|
3403
|
+
function getPayUrl(exchangeId, params) {
|
|
3404
|
+
return PayController.getPayUrl(exchangeId, params, true);
|
|
3405
|
+
}
|
|
3406
|
+
function openPayUrl(exchangeId, params, openInNewTab) {
|
|
3407
|
+
return PayController.openPayUrl({ exchangeId, openInNewTab }, params, true);
|
|
3408
|
+
}
|
|
3409
|
+
function getExchanges() {
|
|
3410
|
+
return PayController.getExchanges();
|
|
3411
|
+
}
|
|
3412
|
+
function getPayResult() {
|
|
3413
|
+
return PayController.state.currentPayment?.result;
|
|
3414
|
+
}
|
|
3415
|
+
function getPayError() {
|
|
3416
|
+
return PayController.state.error;
|
|
3417
|
+
}
|
|
3418
|
+
function getIsPaymentInProgress() {
|
|
3419
|
+
return PayController.state.isPaymentInProgress;
|
|
3420
|
+
}
|
|
3421
|
+
function subscribeStateKey(key, callback) {
|
|
3422
|
+
return PayController.subscribeKey(key, callback);
|
|
3423
|
+
}
|
|
3424
|
+
function createCleanupHandler(unsubscribeFunctions) {
|
|
3425
|
+
return () => {
|
|
3426
|
+
unsubscribeFunctions.forEach(unsubscribe => {
|
|
3427
|
+
try {
|
|
3428
|
+
unsubscribe();
|
|
3429
|
+
}
|
|
3430
|
+
catch {
|
|
3431
|
+
}
|
|
3432
|
+
});
|
|
3433
|
+
};
|
|
3434
|
+
}
|
|
3435
|
+
|
|
3436
|
+
const baseETH = {
|
|
3437
|
+
network: 'eip155:8453',
|
|
3438
|
+
asset: 'native',
|
|
3439
|
+
metadata: {
|
|
3440
|
+
name: 'Ethereum',
|
|
3441
|
+
symbol: 'ETH',
|
|
3442
|
+
decimals: 18
|
|
3443
|
+
}
|
|
3444
|
+
};
|
|
3445
|
+
const baseUSDC = {
|
|
3446
|
+
network: 'eip155:8453',
|
|
3447
|
+
asset: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
|
|
3448
|
+
metadata: {
|
|
3449
|
+
name: 'USD Coin',
|
|
3450
|
+
symbol: 'USDC',
|
|
3451
|
+
decimals: 6
|
|
3452
|
+
}
|
|
3453
|
+
};
|
|
3454
|
+
const baseSepoliaETH = {
|
|
3455
|
+
network: 'eip155:84532',
|
|
3456
|
+
asset: 'native',
|
|
3457
|
+
metadata: {
|
|
3458
|
+
name: 'Ethereum',
|
|
3459
|
+
symbol: 'ETH',
|
|
3460
|
+
decimals: 18
|
|
3461
|
+
}
|
|
3462
|
+
};
|
|
3463
|
+
const ethereumUSDC = {
|
|
3464
|
+
network: 'eip155:1',
|
|
3465
|
+
asset: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
3466
|
+
metadata: {
|
|
3467
|
+
name: 'USD Coin',
|
|
3468
|
+
symbol: 'USDC',
|
|
3469
|
+
decimals: 6
|
|
3470
|
+
}
|
|
3471
|
+
};
|
|
3472
|
+
const optimismUSDC = {
|
|
3473
|
+
network: 'eip155:10',
|
|
3474
|
+
asset: '0x0b2c639c533813f4aa9d7837caf62653d097ff85',
|
|
3475
|
+
metadata: {
|
|
3476
|
+
name: 'USD Coin',
|
|
3477
|
+
symbol: 'USDC',
|
|
3478
|
+
decimals: 6
|
|
3479
|
+
}
|
|
3480
|
+
};
|
|
3481
|
+
const arbitrumUSDC = {
|
|
3482
|
+
network: 'eip155:42161',
|
|
3483
|
+
asset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
3484
|
+
metadata: {
|
|
3485
|
+
name: 'USD Coin',
|
|
3486
|
+
symbol: 'USDC',
|
|
3487
|
+
decimals: 6
|
|
3488
|
+
}
|
|
3489
|
+
};
|
|
3490
|
+
const polygonUSDC = {
|
|
3491
|
+
network: 'eip155:137',
|
|
3492
|
+
asset: '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359',
|
|
3493
|
+
metadata: {
|
|
3494
|
+
name: 'USD Coin',
|
|
3495
|
+
symbol: 'USDC',
|
|
3496
|
+
decimals: 6
|
|
3497
|
+
}
|
|
3498
|
+
};
|
|
3499
|
+
const solanaUSDC = {
|
|
3500
|
+
network: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
|
|
3501
|
+
asset: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
|
|
3502
|
+
metadata: {
|
|
3503
|
+
name: 'USD Coin',
|
|
3504
|
+
symbol: 'USDC',
|
|
3505
|
+
decimals: 6
|
|
3506
|
+
}
|
|
3507
|
+
};
|
|
3508
|
+
const ethereumUSDT = {
|
|
3509
|
+
network: 'eip155:1',
|
|
3510
|
+
asset: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
|
|
3511
|
+
metadata: {
|
|
3512
|
+
name: 'Tether USD',
|
|
3513
|
+
symbol: 'USDT',
|
|
3514
|
+
decimals: 6
|
|
3515
|
+
}
|
|
3516
|
+
};
|
|
3517
|
+
const optimismUSDT = {
|
|
3518
|
+
network: 'eip155:10',
|
|
3519
|
+
asset: '0x94b008aA00579c1307B0EF2c499aD98a8ce58e58',
|
|
3520
|
+
metadata: {
|
|
3521
|
+
name: 'Tether USD',
|
|
3522
|
+
symbol: 'USDT',
|
|
3523
|
+
decimals: 6
|
|
3524
|
+
}
|
|
3525
|
+
};
|
|
3526
|
+
const arbitrumUSDT = {
|
|
3527
|
+
network: 'eip155:42161',
|
|
3528
|
+
asset: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9',
|
|
3529
|
+
metadata: {
|
|
3530
|
+
name: 'Tether USD',
|
|
3531
|
+
symbol: 'USDT',
|
|
3532
|
+
decimals: 6
|
|
3533
|
+
}
|
|
3534
|
+
};
|
|
3535
|
+
const polygonUSDT = {
|
|
3536
|
+
network: 'eip155:137',
|
|
3537
|
+
asset: '0xc2132d05d31c914a87c6611c10748aeb04b58e8f',
|
|
3538
|
+
metadata: {
|
|
3539
|
+
name: 'Tether USD',
|
|
3540
|
+
symbol: 'USDT',
|
|
3541
|
+
decimals: 6
|
|
3542
|
+
}
|
|
3543
|
+
};
|
|
3544
|
+
const solanaUSDT = {
|
|
3545
|
+
network: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
|
|
3546
|
+
asset: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
|
|
3547
|
+
metadata: {
|
|
3548
|
+
name: 'Tether USD',
|
|
3549
|
+
symbol: 'USDT',
|
|
3550
|
+
decimals: 6
|
|
3551
|
+
}
|
|
3552
|
+
};
|
|
3553
|
+
const solanaSOL = {
|
|
3554
|
+
network: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
|
|
3555
|
+
asset: 'native',
|
|
3556
|
+
metadata: {
|
|
3557
|
+
name: 'Solana',
|
|
3558
|
+
symbol: 'SOL',
|
|
3559
|
+
decimals: 9
|
|
3560
|
+
}
|
|
3561
|
+
};
|
|
3562
|
+
|
|
3563
|
+
export { PayController, W3mPayLoadingView, W3mPayQuoteView, W3mPayView, arbitrumUSDC, arbitrumUSDT, baseETH, baseSepoliaETH, baseUSDC, ethereumUSDC, ethereumUSDT, getExchanges, getIsPaymentInProgress, getPayError, getPayResult, openPay, optimismUSDC, optimismUSDT, pay, polygonUSDC, polygonUSDT, solanaSOL, solanaUSDC, solanaUSDT };
|
|
3564
|
+
//# sourceMappingURL=index-DE0OtbL2.js.map
|
|
3565
|
+
|
|
3566
|
+
//# sourceMappingURL=index-DE0OtbL2.js.map
|