@multiversx/sdk-dapp-liquidity 1.0.12 → 1.0.14
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/ConstantsUtil-BinYIDR2.mjs +8 -0
- package/ConstantsUtil-CbnVdQ5P.js +8 -0
- package/add-D-ECcdUh.mjs +19 -0
- package/add-Diz8heiY.js +20 -0
- package/all-wallets-_iOQf3bl.js +11 -0
- package/all-wallets-puIIQy3Y.mjs +10 -0
- package/app-store-BGTKFL27.js +22 -0
- package/app-store-Bsf7w3pv.mjs +21 -0
- package/apple-Cw8e8IGH.mjs +22 -0
- package/apple-DF7n_Yzl.js +23 -0
- package/arrow-bottom-Cp2C4fQv.mjs +12 -0
- package/arrow-bottom-DTvIR3s3.js +13 -0
- package/arrow-bottom-circle-CN6i5mHz.mjs +15 -0
- package/arrow-bottom-circle-CzPwiwWH.js +16 -0
- package/arrow-left-9VFYHQSW.js +13 -0
- package/arrow-left-BDQHoEvX.mjs +12 -0
- package/arrow-right-BxkuSpWU.mjs +12 -0
- package/arrow-right-DBLQ6w92.js +13 -0
- package/arrow-top-BiQd5Aey.js +13 -0
- package/arrow-top-BrLVX4Rj.mjs +12 -0
- package/bank-B7EC6Kdz.mjs +18 -0
- package/bank-CvPn9sfV.js +19 -0
- package/{bignumber-CKZkoo0g.mjs → bignumber-2Z7uapuD.mjs} +6 -6
- package/{bignumber-B8vjg9qn.js → bignumber-D1Wl54dL.js} +6 -6
- package/bin-BXO1kNZh.js +9 -0
- package/bin-CwiYVJ1L.mjs +8 -0
- package/bitcoin-C3kBVar_.mjs +17 -0
- package/bitcoin-DAvQGpeP.js +3251 -0
- package/bitcoin-dNBGbS2B.mjs +3251 -0
- package/bitcoin-k6bvmzMA.js +18 -0
- package/browser-ShRLuKKz.mjs +18 -0
- package/browser-t7nfT7HL.js +19 -0
- package/card-BJg5bdoM.mjs +18 -0
- package/card-hxUDXttT.js +19 -0
- package/checkmark-BpR0Yy93.mjs +15 -0
- package/checkmark-D9AVWgl5.js +16 -0
- package/checkmark-bold-D3Xcby1U.mjs +12 -0
- package/checkmark-bold-De02hde8.js +13 -0
- package/chevron-bottom-DcBf7T5F.js +13 -0
- package/chevron-bottom-DfGpWIz7.mjs +12 -0
- package/chevron-left-BKvYVnUo.js +13 -0
- package/chevron-left-DGSG9WJQ.mjs +12 -0
- package/chevron-right-BLgYIEeO.js +13 -0
- package/chevron-right-C2nsTx_Y.mjs +12 -0
- package/chevron-top-CwFOEFy8.js +13 -0
- package/chevron-top-vk-9DvUU.mjs +12 -0
- package/chrome-store-4H_ie3vA.mjs +65 -0
- package/chrome-store-BWarxVMl.js +66 -0
- package/circle-BtqWJU0_.mjs +8 -0
- package/circle-DYjG6o7-.js +9 -0
- package/clock-Ba5SM-pl.mjs +12 -0
- package/clock-DPzNREdU.js +13 -0
- package/close-CJHKFOyp.mjs +12 -0
- package/close-DDWnJdJe.js +13 -0
- package/coinPlaceholder-Cbba3D1H.mjs +12 -0
- package/coinPlaceholder-DdxQIc2D.js +13 -0
- package/compass-CugCxeSC.js +13 -0
- package/compass-DbN5DkTl.mjs +12 -0
- package/copy-CHSZprYJ.mjs +19 -0
- package/copy-En5h5Uhu.js +20 -0
- package/cursor-DCRkvEhr.mjs +7 -0
- package/cursor-DnEQtrUK.js +8 -0
- package/cursor-transparent-CU8lk-xg.js +17 -0
- package/cursor-transparent-CliETg4d.mjs +16 -0
- package/desktop-BgD7aypB.js +14 -0
- package/desktop-Cg5I32-p.mjs +13 -0
- package/disconnect-CCyMbAdw.js +13 -0
- package/disconnect-Cp2vRWB2.mjs +12 -0
- package/discord-B1d-qeSk.mjs +21 -0
- package/discord-BEB5klec.js +22 -0
- package/email-CorlePKz.js +873 -0
- package/email-Znno7H8_.mjs +878 -0
- package/embedded-wallet-B9ro9Tel.js +549 -0
- package/embedded-wallet-CnTWeseG.mjs +552 -0
- package/ethereum-BRcsRjUU.mjs +14 -0
- package/ethereum-CZ_xe09e.js +15 -0
- package/etherscan-BZKGpKp8.mjs +10 -0
- package/etherscan-DtLi-C3z.js +11 -0
- package/exclamation-triangle-BLNnBLEc.js +9 -0
- package/exclamation-triangle-CFThXxRT.mjs +8 -0
- package/extension-CwUepr-W.mjs +12 -0
- package/extension-DOD67G1k.js +13 -0
- package/external-link-CZkQS5XK.js +13 -0
- package/external-link-ClYNKSPt.mjs +12 -0
- package/facebook-CFjrd4my.mjs +30 -0
- package/facebook-CbE6K6AK.js +31 -0
- package/farcaster-Ba7_C-Vm.js +17 -0
- package/farcaster-DyVJtVS9.mjs +16 -0
- package/filters-CpHaFNjT.mjs +12 -0
- package/filters-w5LC-r6e.js +13 -0
- package/github-CeO70C3E.mjs +22 -0
- package/github-uLFBWAa5.js +23 -0
- package/google-CyOdUlbw.mjs +22 -0
- package/google-ILGK-opP.js +23 -0
- package/help-circle-Dh3dRNoB.mjs +16 -0
- package/help-circle-HUMbz_KN.js +17 -0
- package/id-Cy3Qkrvb.js +17 -0
- package/id-D-Q0uPFM.mjs +16 -0
- package/if-defined-CJ5EZLw2.js +815 -0
- package/if-defined-DjC5UMfF.mjs +815 -0
- package/image-BTGOf8bb.mjs +8 -0
- package/image-WFQO5bWa.js +9 -0
- package/index--O5ypTeK.mjs +70 -0
- package/index--Vg7VI9t.js +173 -0
- package/index-2iRSO1sa.mjs +9964 -0
- package/index-42Rpweo5.mjs +95 -0
- package/index-70kjE43k.mjs +90 -0
- package/index-8VyNYS01.js +273 -0
- package/index-B-dx8l0g.mjs +82 -0
- package/index-BB0nW9RB.mjs +198 -0
- package/index-BBwuv2SS.js +97 -0
- package/index-BIe-kofv.mjs +273 -0
- package/index-BQf6VHil.js +278 -0
- package/index-BWIZXhFv.mjs +630 -0
- package/index-BXkamf-I.js +337 -0
- package/index-BYTxCmKH.js +64 -0
- package/index-BYoOxo0S.js +218 -0
- package/index-Ba0tVdql.js +200 -0
- package/index-BdOAPWyt.mjs +210 -0
- package/index-BirWzf8c.mjs +71 -0
- package/index-BnCJUHtW.mjs +346 -0
- package/index-BuL2FC61.mjs +216 -0
- package/index-BxSUTfaY.js +88 -0
- package/index-C49C5Rxf.js +743 -0
- package/index-CNMDBpW7.js +346 -0
- package/index-CP0CGjqQ.mjs +263 -0
- package/index-CQaHcTZM.mjs +86 -0
- package/index-CRGXQei1.js +178 -0
- package/index-CSykUIfV.mjs +176 -0
- package/index-CWIHaLkQ.mjs +101 -0
- package/index-CZSDJd0P.mjs +1070 -0
- package/index-CZaV8JgR.mjs +49 -0
- package/index-CZjdy6QP.js +101 -0
- package/index-C_lIGGlC.js +632 -0
- package/index-CcgeRPs2.mjs +57 -0
- package/index-CeY_DRuc.js +566 -0
- package/index-ChFNkSxT.js +92 -0
- package/index-CkjZc20w.js +677 -0
- package/index-CtFcWwAd.js +72 -0
- package/index-D0mOfznC.mjs +362 -0
- package/index-DAtWLY21.js +84 -0
- package/index-DEs8H3w2.js +262 -0
- package/index-DLnxotbC.mjs +566 -0
- package/index-DN4fGDgg.mjs +743 -0
- package/index-DT_mc1hV.mjs +335 -0
- package/index-DZEwxUMS.js +59 -0
- package/index-DaRH_4bD.js +9939 -0
- package/index-Daok2ZKn.js +73 -0
- package/index-DomzHmwk.js +210 -0
- package/index-Dx7NyDyv.mjs +101 -0
- package/index-DyGir6_2.mjs +675 -0
- package/index-GglJmM2C.js +2237 -0
- package/index-H5b7UTeJ.mjs +173 -0
- package/index-NNZ1lNuc.mjs +168 -0
- package/index-RJd-gQcv.mjs +2235 -0
- package/index-dnFzVpGy.js +103 -0
- package/index-kwVLu8EV.js +168 -0
- package/index-miQwZPmn.js +51 -0
- package/index-oCj_SpOa.mjs +62 -0
- package/index-pNK-h_x9.js +1069 -0
- package/index-r6Kre1rx.js +362 -0
- package/index-xBD0nXoB.mjs +276 -0
- package/index.js +3 -3
- package/index.mjs +3 -3
- package/info-BKNAiN0k.js +8 -0
- package/info-DQE0s-A4.mjs +7 -0
- package/info-circle-C3uTocjH.js +17 -0
- package/info-circle-CIn6yeQo.mjs +16 -0
- package/lightbulb-CB-BmIop.js +8 -0
- package/lightbulb-Gv7IbnzO.mjs +7 -0
- package/mail-CFYm95wn.mjs +12 -0
- package/mail-GEwk-Fzr.js +13 -0
- package/mobile-CZ7ZBfa5.js +14 -0
- package/mobile-OIbnpFsU.mjs +13 -0
- package/more-C8N_RV55.mjs +15 -0
- package/more-CiQpPZwq.js +16 -0
- package/network-placeholder-CxEcczEx.mjs +18 -0
- package/network-placeholder-DwR8E8hP.js +19 -0
- package/nftPlaceholder-BFexVcGX.js +13 -0
- package/nftPlaceholder-MiYL110I.mjs +12 -0
- package/off-BNiMlpUU.mjs +8 -0
- package/off-iJHSK3Z7.js +9 -0
- package/onramp-Bs8HHFFY.js +1474 -0
- package/onramp-C6fuQfX7.mjs +1480 -0
- package/package.json +11 -11
- package/play-store-B4ssIYUA.js +37 -0
- package/play-store-D6nmQXhX.mjs +36 -0
- package/plus-Bh7z7Oc0.js +18 -0
- package/plus-C8ioZuCD.mjs +17 -0
- package/qr-code-CSVwaBLf.mjs +10 -0
- package/qr-code-YgtXPokK.js +11 -0
- package/react-BWxe90Ar.mjs +6342 -0
- package/react-BzZcQig5.js +6342 -0
- package/react-C_wTMVq_.js +23003 -0
- package/react-M-DnxvZl.mjs +23003 -0
- package/reactjs/components/BridgeForm/BridgeForm.js +2 -1
- package/reactjs/components/BridgeForm/BridgeForm.mjs +2 -1
- package/reactjs/components/Connect/BridgeAccountDisplay.js +3 -2
- package/reactjs/components/Connect/BridgeAccountDisplay.mjs +3 -2
- package/reactjs/components/Connect/CustomConnectButton.js +3 -2
- package/reactjs/components/Connect/CustomConnectButton.mjs +3 -2
- package/reactjs/components/Connect/SwitchChainButton.js +4 -3
- package/reactjs/components/Connect/SwitchChainButton.mjs +4 -3
- package/reactjs/components/DisplayAmount/DisplayAmount.js +1 -1
- package/reactjs/components/DisplayAmount/DisplayAmount.mjs +1 -1
- package/reactjs/components/TokenSelector/components/TokenItem.js +1 -1
- package/reactjs/components/TokenSelector/components/TokenItem.mjs +1 -1
- package/reactjs/hooks/useAccount.d.ts +4 -4
- package/reactjs/hooks/useAccount.js +3 -2
- package/reactjs/hooks/useAccount.mjs +3 -2
- package/reactjs/hooks/useGetChainId.js +1 -1
- package/reactjs/hooks/useGetChainId.mjs +1 -1
- package/reactjs/index.js +3 -3
- package/reactjs/index.mjs +3 -3
- package/reactjs/init/init.js +4 -3
- package/reactjs/init/init.mjs +4 -3
- package/reactjs/init/tests/init.spec.js +2 -2
- package/reactjs/init/tests/init.spec.mjs +2 -2
- package/reactjs/queries/useGetEvmTokensBalances.query.js +3 -2
- package/reactjs/queries/useGetEvmTokensBalances.query.mjs +3 -2
- package/reactjs/reexports.js +3 -3
- package/reactjs/reexports.mjs +3 -3
- package/reactjs/utils/getCleanStringAmount.js +1 -1
- package/reactjs/utils/getCleanStringAmount.mjs +1 -1
- package/reactjs/utils/hasEnoughFunds.js +1 -1
- package/reactjs/utils/hasEnoughFunds.mjs +1 -1
- package/reactjs/utils/isStringFloat.js +1 -1
- package/reactjs/utils/isStringFloat.mjs +1 -1
- package/reactjs/utils/roundAmount.js +1 -1
- package/reactjs/utils/roundAmount.mjs +1 -1
- package/receive-CK0hRQPr.js +212 -0
- package/receive-CQcD6bZf.mjs +212 -0
- package/recycle-horizontal--x5cMoTE.js +14 -0
- package/recycle-horizontal-QI0xtDHK.mjs +13 -0
- package/ref-CqxfRkBm.mjs +41 -0
- package/ref-FGI2cUQB.js +41 -0
- package/refresh-CFNHjhDi.js +13 -0
- package/refresh-CSOC1NUY.mjs +12 -0
- package/reown-logo-BfU5xFX5.js +17 -0
- package/reown-logo-CZAEp1jU.mjs +16 -0
- package/search-Do_rb-9-.mjs +12 -0
- package/search-V9CGMHkm.js +13 -0
- package/send-D-5G7tDL.mjs +1204 -0
- package/send-D4yYsIHV.mjs +19 -0
- package/send-DoiSHLsX.js +1202 -0
- package/send-_jfNFrys.js +20 -0
- package/socials-BL7-97fT.mjs +758 -0
- package/socials-DF0CK9cN.js +756 -0
- package/solana-BQ0Jh8lh.js +18 -0
- package/solana-YAkDp6j_.mjs +17 -0
- package/swapHorizontal-DOIo-Ccx.mjs +12 -0
- package/swapHorizontal-OHKtz4Gu.js +13 -0
- package/swapHorizontalBold-D7QmFj-c.js +13 -0
- package/swapHorizontalBold-DDroA0Af.mjs +12 -0
- package/swapHorizontalMedium-CU_v0kFz.mjs +20 -0
- package/swapHorizontalMedium-D-yMmtml.js +21 -0
- package/swapHorizontalRoundedBold-CHvbmnjw.js +13 -0
- package/swapHorizontalRoundedBold-DXMH0sgK.mjs +12 -0
- package/swapVertical-CH7fTK6w.js +13 -0
- package/swapVertical-HJZ6rFcr.mjs +12 -0
- package/swaps-CETflhdU.js +1952 -0
- package/swaps-DRUV6d3p.mjs +1954 -0
- package/telegram-CsCauOwj.mjs +20 -0
- package/telegram-DKEcF_Tq.js +21 -0
- package/three-dots-B-7hr8Nl.js +10 -0
- package/three-dots-LNZ_fjP7.mjs +9 -0
- package/transactions-BTTsGV2W.mjs +37 -0
- package/transactions-mpNNlClw.js +37 -0
- package/twitch-CCWVT2ij.js +23 -0
- package/twitch-Dg1CCQvd.mjs +22 -0
- package/twitterIcon-BjR09Cj9.mjs +10 -0
- package/twitterIcon-CeEs0iDJ.js +11 -0
- package/verify-B8WZq7kt.mjs +12 -0
- package/verify-filled-BeqC1imk.mjs +12 -0
- package/verify-filled-C-mv3ApD.js +13 -0
- package/verify-yATdPqt-.js +13 -0
- package/w3m-modal-3GziKj7h.js +1254 -0
- package/w3m-modal-81Z5PngE.mjs +1255 -0
- package/wallet-BMXEH23x.js +13 -0
- package/wallet-CNAVQCfm.mjs +12 -0
- package/wallet-placeholder-CQ-7CmVN.mjs +18 -0
- package/wallet-placeholder-CdoQy2e6.js +19 -0
- package/walletconnect-ACr-R1QZ.mjs +38 -0
- package/walletconnect-BWSkiS2F.js +39 -0
- package/warning-circle-CYnuYwpt.js +17 -0
- package/warning-circle-HV2lOiCj.mjs +16 -0
- package/x-CW5dozRj.js +17 -0
- package/x-Cgm2OFpL.mjs +16 -0
- package/x-mark-CR8SpZvu.js +8 -0
- package/x-mark-u0KJjUJ1.mjs +7 -0
- package/index-B4Eq5P3w.mjs +0 -91
- package/index-C4WV9nam.js +0 -329
- package/index-CWMcKi_X.js +0 -107
- package/index-D8E0O3qL.mjs +0 -68744
- package/index-DJ8CdHSw.mjs +0 -107
- package/index-nigVQYBu.js +0 -68665
- package/react-C43nEIqn.js +0 -3133
- package/react-DKUsVej7.js +0 -50
- package/react-Dp0H8q2z.mjs +0 -50
- package/react-wMhOUFOm.mjs +0 -3133
- package/w3m-modal-DLyg7Voy.js +0 -356
- package/w3m-modal-hC-B8qZP.mjs +0 -356
|
@@ -0,0 +1,1070 @@
|
|
|
1
|
+
import { p as proxy, a as subscribeKey, s as subscribe, i, f as i$1, x } from "./bitcoin-dNBGbS2B.mjs";
|
|
2
|
+
import { o, r, c as customElement } from "./if-defined-DjC5UMfF.mjs";
|
|
3
|
+
import "./index-DT_mc1hV.mjs";
|
|
4
|
+
import "./index-D0mOfznC.mjs";
|
|
5
|
+
import "./index-CQaHcTZM.mjs";
|
|
6
|
+
import "./index--O5ypTeK.mjs";
|
|
7
|
+
import "./index-BB0nW9RB.mjs";
|
|
8
|
+
import "./index-Dx7NyDyv.mjs";
|
|
9
|
+
import "./index-CZaV8JgR.mjs";
|
|
10
|
+
import { O as OptionsController, P as ParseUtil, d as CoreHelperUtil, c as ChainController, l as ConstantsUtil, C as ConnectionController, p as ContractUtil, E as EventsController, S as SnackController, A as AccountController, R as RouterController, M as ModalController, T as ThemeController } from "./react-BWxe90Ar.mjs";
|
|
11
|
+
import { P as ProviderUtil } from "./index-H5b7UTeJ.mjs";
|
|
12
|
+
import "./index-BirWzf8c.mjs";
|
|
13
|
+
const AppKitPayErrorCodes = {
|
|
14
|
+
INVALID_PAYMENT_CONFIG: "INVALID_PAYMENT_CONFIG",
|
|
15
|
+
INVALID_RECIPIENT: "INVALID_RECIPIENT",
|
|
16
|
+
INVALID_ASSET: "INVALID_ASSET",
|
|
17
|
+
INVALID_AMOUNT: "INVALID_AMOUNT",
|
|
18
|
+
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
19
|
+
UNABLE_TO_INITIATE_PAYMENT: "UNABLE_TO_INITIATE_PAYMENT",
|
|
20
|
+
INVALID_CHAIN_NAMESPACE: "INVALID_CHAIN_NAMESPACE",
|
|
21
|
+
GENERIC_PAYMENT_ERROR: "GENERIC_PAYMENT_ERROR",
|
|
22
|
+
UNABLE_TO_GET_EXCHANGES: "UNABLE_TO_GET_EXCHANGES",
|
|
23
|
+
ASSET_NOT_SUPPORTED: "ASSET_NOT_SUPPORTED",
|
|
24
|
+
UNABLE_TO_GET_PAY_URL: "UNABLE_TO_GET_PAY_URL",
|
|
25
|
+
UNABLE_TO_GET_BUY_STATUS: "UNABLE_TO_GET_BUY_STATUS"
|
|
26
|
+
};
|
|
27
|
+
const AppKitPayErrorMessages = {
|
|
28
|
+
[AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG]: "Invalid payment configuration",
|
|
29
|
+
[AppKitPayErrorCodes.INVALID_RECIPIENT]: "Invalid recipient address",
|
|
30
|
+
[AppKitPayErrorCodes.INVALID_ASSET]: "Invalid asset specified",
|
|
31
|
+
[AppKitPayErrorCodes.INVALID_AMOUNT]: "Invalid payment amount",
|
|
32
|
+
[AppKitPayErrorCodes.UNKNOWN_ERROR]: "Unknown payment error occurred",
|
|
33
|
+
[AppKitPayErrorCodes.UNABLE_TO_INITIATE_PAYMENT]: "Unable to initiate payment",
|
|
34
|
+
[AppKitPayErrorCodes.INVALID_CHAIN_NAMESPACE]: "Invalid chain namespace",
|
|
35
|
+
[AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR]: "Unable to process payment",
|
|
36
|
+
[AppKitPayErrorCodes.UNABLE_TO_GET_EXCHANGES]: "Unable to get exchanges",
|
|
37
|
+
[AppKitPayErrorCodes.ASSET_NOT_SUPPORTED]: "Asset not supported by the selected exchange",
|
|
38
|
+
[AppKitPayErrorCodes.UNABLE_TO_GET_PAY_URL]: "Unable to get payment URL",
|
|
39
|
+
[AppKitPayErrorCodes.UNABLE_TO_GET_BUY_STATUS]: "Unable to get buy status"
|
|
40
|
+
};
|
|
41
|
+
class AppKitPayError extends Error {
|
|
42
|
+
get message() {
|
|
43
|
+
return AppKitPayErrorMessages[this.code];
|
|
44
|
+
}
|
|
45
|
+
constructor(code, details) {
|
|
46
|
+
super(AppKitPayErrorMessages[code]);
|
|
47
|
+
this.name = "AppKitPayError";
|
|
48
|
+
this.code = code;
|
|
49
|
+
this.details = details;
|
|
50
|
+
if (Error.captureStackTrace) {
|
|
51
|
+
Error.captureStackTrace(this, AppKitPayError);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const API_URL = "https://rpc.walletconnect.org/v1/json-rpc";
|
|
56
|
+
class JsonRpcError extends Error {
|
|
57
|
+
}
|
|
58
|
+
function getApiUrl() {
|
|
59
|
+
const projectId = OptionsController.getSnapshot().projectId;
|
|
60
|
+
return `${API_URL}?projectId=${projectId}`;
|
|
61
|
+
}
|
|
62
|
+
async function sendRequest(method, params) {
|
|
63
|
+
const url = getApiUrl();
|
|
64
|
+
const requestBody = {
|
|
65
|
+
jsonrpc: "2.0",
|
|
66
|
+
id: 1,
|
|
67
|
+
method,
|
|
68
|
+
params
|
|
69
|
+
};
|
|
70
|
+
const response = await fetch(url, {
|
|
71
|
+
method: "POST",
|
|
72
|
+
body: JSON.stringify(requestBody),
|
|
73
|
+
headers: { "Content-Type": "application/json" }
|
|
74
|
+
});
|
|
75
|
+
const json = await response.json();
|
|
76
|
+
if (json.error) {
|
|
77
|
+
throw new JsonRpcError(json.error.message);
|
|
78
|
+
}
|
|
79
|
+
return json;
|
|
80
|
+
}
|
|
81
|
+
async function getExchanges$1(params) {
|
|
82
|
+
const response = await sendRequest("reown_getExchanges", params);
|
|
83
|
+
return response.result;
|
|
84
|
+
}
|
|
85
|
+
async function getPayUrl(params) {
|
|
86
|
+
const response = await sendRequest("reown_getExchangePayUrl", params);
|
|
87
|
+
return response.result;
|
|
88
|
+
}
|
|
89
|
+
async function getBuyStatus(params) {
|
|
90
|
+
const response = await sendRequest("reown_getExchangeBuyStatus", params);
|
|
91
|
+
return response.result;
|
|
92
|
+
}
|
|
93
|
+
const SUPPORT_PAY_WITH_WALLET_CHAIN_NAMESPACES = ["eip155"];
|
|
94
|
+
const CHAIN_ASSET_INFO_MAP = {
|
|
95
|
+
eip155: {
|
|
96
|
+
native: { assetNamespace: "slip44", assetReference: "60" },
|
|
97
|
+
defaultTokenNamespace: "erc20"
|
|
98
|
+
},
|
|
99
|
+
solana: {
|
|
100
|
+
native: { assetNamespace: "slip44", assetReference: "501" },
|
|
101
|
+
defaultTokenNamespace: "token"
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
function formatCaip19Asset(caipNetworkId, asset) {
|
|
105
|
+
const { chainNamespace, chainId } = ParseUtil.parseCaipNetworkId(caipNetworkId);
|
|
106
|
+
const chainInfo = CHAIN_ASSET_INFO_MAP[chainNamespace];
|
|
107
|
+
if (!chainInfo) {
|
|
108
|
+
throw new Error(`Unsupported chain namespace for CAIP-19 formatting: ${chainNamespace}`);
|
|
109
|
+
}
|
|
110
|
+
let assetNamespace = chainInfo.native.assetNamespace;
|
|
111
|
+
let assetReference = chainInfo.native.assetReference;
|
|
112
|
+
if (asset !== "native") {
|
|
113
|
+
assetNamespace = chainInfo.defaultTokenNamespace;
|
|
114
|
+
assetReference = asset;
|
|
115
|
+
}
|
|
116
|
+
const networkPart = `${chainNamespace}:${chainId}`;
|
|
117
|
+
return `${networkPart}/${assetNamespace}:${assetReference}`;
|
|
118
|
+
}
|
|
119
|
+
function isPayWithWalletSupported(networkId) {
|
|
120
|
+
const { chainNamespace } = ParseUtil.parseCaipNetworkId(networkId);
|
|
121
|
+
return SUPPORT_PAY_WITH_WALLET_CHAIN_NAMESPACES.includes(chainNamespace);
|
|
122
|
+
}
|
|
123
|
+
async function ensureCorrectNetwork(options) {
|
|
124
|
+
const { paymentAssetNetwork, activeCaipNetwork, approvedCaipNetworkIds, requestedCaipNetworks } = options;
|
|
125
|
+
const sortedNetworks = CoreHelperUtil.sortRequestedNetworks(approvedCaipNetworkIds, requestedCaipNetworks);
|
|
126
|
+
const assetCaipNetwork = sortedNetworks.find((network) => network.caipNetworkId === paymentAssetNetwork);
|
|
127
|
+
if (!assetCaipNetwork) {
|
|
128
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG);
|
|
129
|
+
}
|
|
130
|
+
if (assetCaipNetwork.caipNetworkId === activeCaipNetwork.caipNetworkId) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const isSupportingAllNetworks = ChainController.getNetworkProp("supportsAllNetworks", assetCaipNetwork.chainNamespace);
|
|
134
|
+
const isSwitchAllowed = (approvedCaipNetworkIds == null ? void 0 : approvedCaipNetworkIds.includes(assetCaipNetwork.caipNetworkId)) || isSupportingAllNetworks;
|
|
135
|
+
if (!isSwitchAllowed) {
|
|
136
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG);
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
await ChainController.switchActiveNetwork(assetCaipNetwork);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
throw new AppKitPayError(AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR, error);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async function processEvmNativePayment(paymentAsset, chainNamespace, params) {
|
|
145
|
+
var _a;
|
|
146
|
+
if (chainNamespace !== ConstantsUtil.CHAIN.EVM) {
|
|
147
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_CHAIN_NAMESPACE);
|
|
148
|
+
}
|
|
149
|
+
if (!params.fromAddress) {
|
|
150
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG, "fromAddress is required for native EVM payments.");
|
|
151
|
+
}
|
|
152
|
+
const amountValue = typeof params.amount === "string" ? parseFloat(params.amount) : params.amount;
|
|
153
|
+
if (isNaN(amountValue)) {
|
|
154
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG);
|
|
155
|
+
}
|
|
156
|
+
const decimals = ((_a = paymentAsset.metadata) == null ? void 0 : _a.decimals) ?? 18;
|
|
157
|
+
const amountBigInt = ConnectionController.parseUnits(amountValue.toString(), decimals);
|
|
158
|
+
if (typeof amountBigInt !== "bigint") {
|
|
159
|
+
throw new AppKitPayError(AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR);
|
|
160
|
+
}
|
|
161
|
+
const txResponse = await ConnectionController.sendTransaction({
|
|
162
|
+
chainNamespace,
|
|
163
|
+
to: params.recipient,
|
|
164
|
+
address: params.fromAddress,
|
|
165
|
+
value: amountBigInt,
|
|
166
|
+
data: "0x"
|
|
167
|
+
});
|
|
168
|
+
return txResponse ?? void 0;
|
|
169
|
+
}
|
|
170
|
+
async function processEvmErc20Payment(paymentAsset, params) {
|
|
171
|
+
if (!params.fromAddress) {
|
|
172
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG, "fromAddress is required for ERC20 EVM payments.");
|
|
173
|
+
}
|
|
174
|
+
const tokenAddress = paymentAsset.asset;
|
|
175
|
+
const recipientAddress = params.recipient;
|
|
176
|
+
const decimals = Number(paymentAsset.metadata.decimals);
|
|
177
|
+
const amountBigInt = ConnectionController.parseUnits(params.amount.toString(), decimals);
|
|
178
|
+
if (amountBigInt === void 0) {
|
|
179
|
+
throw new AppKitPayError(AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR);
|
|
180
|
+
}
|
|
181
|
+
const txResponse = await ConnectionController.writeContract({
|
|
182
|
+
fromAddress: params.fromAddress,
|
|
183
|
+
tokenAddress,
|
|
184
|
+
args: [recipientAddress, amountBigInt],
|
|
185
|
+
method: "transfer",
|
|
186
|
+
abi: ContractUtil.getERC20Abi(tokenAddress),
|
|
187
|
+
chainNamespace: ConstantsUtil.CHAIN.EVM
|
|
188
|
+
});
|
|
189
|
+
return txResponse ?? void 0;
|
|
190
|
+
}
|
|
191
|
+
const DEFAULT_PAGE = 0;
|
|
192
|
+
const DEFAULT_PAYMENT_ID = "unknown";
|
|
193
|
+
const state = proxy({
|
|
194
|
+
paymentAsset: {
|
|
195
|
+
network: "eip155:1",
|
|
196
|
+
asset: "0x0",
|
|
197
|
+
metadata: {
|
|
198
|
+
name: "0x0",
|
|
199
|
+
symbol: "0x0",
|
|
200
|
+
decimals: 0
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
recipient: "0x0",
|
|
204
|
+
amount: 0,
|
|
205
|
+
isConfigured: false,
|
|
206
|
+
error: null,
|
|
207
|
+
isPaymentInProgress: false,
|
|
208
|
+
exchanges: [],
|
|
209
|
+
isLoading: false,
|
|
210
|
+
openInNewTab: true,
|
|
211
|
+
redirectUrl: void 0,
|
|
212
|
+
payWithExchange: void 0,
|
|
213
|
+
currentPayment: void 0,
|
|
214
|
+
analyticsSet: false,
|
|
215
|
+
paymentId: void 0
|
|
216
|
+
});
|
|
217
|
+
const PayController = {
|
|
218
|
+
state,
|
|
219
|
+
subscribe(callback) {
|
|
220
|
+
return subscribe(state, () => callback(state));
|
|
221
|
+
},
|
|
222
|
+
subscribeKey(key, callback) {
|
|
223
|
+
return subscribeKey(state, key, callback);
|
|
224
|
+
},
|
|
225
|
+
async handleOpenPay(options) {
|
|
226
|
+
this.resetState();
|
|
227
|
+
this.setPaymentConfig(options);
|
|
228
|
+
this.subscribeEvents();
|
|
229
|
+
this.initializeAnalytics();
|
|
230
|
+
state.isConfigured = true;
|
|
231
|
+
EventsController.sendEvent({
|
|
232
|
+
type: "track",
|
|
233
|
+
event: "PAY_MODAL_OPEN",
|
|
234
|
+
properties: {
|
|
235
|
+
exchanges: state.exchanges,
|
|
236
|
+
configuration: {
|
|
237
|
+
network: state.paymentAsset.network,
|
|
238
|
+
asset: state.paymentAsset.asset,
|
|
239
|
+
recipient: state.recipient,
|
|
240
|
+
amount: state.amount
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
await ModalController.open({
|
|
245
|
+
view: "Pay"
|
|
246
|
+
});
|
|
247
|
+
},
|
|
248
|
+
resetState() {
|
|
249
|
+
state.paymentAsset = {
|
|
250
|
+
network: "eip155:1",
|
|
251
|
+
asset: "0x0",
|
|
252
|
+
metadata: { name: "0x0", symbol: "0x0", decimals: 0 }
|
|
253
|
+
};
|
|
254
|
+
state.recipient = "0x0";
|
|
255
|
+
state.amount = 0;
|
|
256
|
+
state.isConfigured = false;
|
|
257
|
+
state.error = null;
|
|
258
|
+
state.isPaymentInProgress = false;
|
|
259
|
+
state.isLoading = false;
|
|
260
|
+
state.currentPayment = void 0;
|
|
261
|
+
},
|
|
262
|
+
setPaymentConfig(config) {
|
|
263
|
+
if (!config.paymentAsset) {
|
|
264
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG);
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
state.paymentAsset = config.paymentAsset;
|
|
268
|
+
state.recipient = config.recipient;
|
|
269
|
+
state.amount = config.amount;
|
|
270
|
+
state.openInNewTab = config.openInNewTab ?? true;
|
|
271
|
+
state.redirectUrl = config.redirectUrl;
|
|
272
|
+
state.payWithExchange = config.payWithExchange;
|
|
273
|
+
state.error = null;
|
|
274
|
+
} catch (error) {
|
|
275
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG, error.message);
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
getPaymentAsset() {
|
|
279
|
+
return state.paymentAsset;
|
|
280
|
+
},
|
|
281
|
+
getExchanges() {
|
|
282
|
+
return state.exchanges;
|
|
283
|
+
},
|
|
284
|
+
async fetchExchanges() {
|
|
285
|
+
try {
|
|
286
|
+
state.isLoading = true;
|
|
287
|
+
const response = await getExchanges$1({
|
|
288
|
+
page: DEFAULT_PAGE,
|
|
289
|
+
asset: formatCaip19Asset(state.paymentAsset.network, state.paymentAsset.asset),
|
|
290
|
+
amount: state.amount.toString()
|
|
291
|
+
});
|
|
292
|
+
state.exchanges = response.exchanges.slice(0, 2);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
SnackController.showError(AppKitPayErrorMessages.UNABLE_TO_GET_EXCHANGES);
|
|
295
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_EXCHANGES);
|
|
296
|
+
} finally {
|
|
297
|
+
state.isLoading = false;
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
async getAvailableExchanges(params) {
|
|
301
|
+
var _a;
|
|
302
|
+
try {
|
|
303
|
+
const asset = (params == null ? void 0 : params.asset) && (params == null ? void 0 : params.network) ? formatCaip19Asset(params.network, params.asset) : void 0;
|
|
304
|
+
const response = await getExchanges$1({
|
|
305
|
+
page: (params == null ? void 0 : params.page) ?? DEFAULT_PAGE,
|
|
306
|
+
asset,
|
|
307
|
+
amount: (_a = params == null ? void 0 : params.amount) == null ? void 0 : _a.toString()
|
|
308
|
+
});
|
|
309
|
+
return response;
|
|
310
|
+
} catch (error) {
|
|
311
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_EXCHANGES);
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
async getPayUrl(exchangeId, params, headless = false) {
|
|
315
|
+
try {
|
|
316
|
+
const numericAmount = Number(params.amount);
|
|
317
|
+
const response = await getPayUrl({
|
|
318
|
+
exchangeId,
|
|
319
|
+
asset: formatCaip19Asset(params.network, params.asset),
|
|
320
|
+
amount: numericAmount.toString(),
|
|
321
|
+
recipient: `${params.network}:${params.recipient}`
|
|
322
|
+
});
|
|
323
|
+
EventsController.sendEvent({
|
|
324
|
+
type: "track",
|
|
325
|
+
event: "PAY_EXCHANGE_SELECTED",
|
|
326
|
+
properties: {
|
|
327
|
+
exchange: {
|
|
328
|
+
id: exchangeId
|
|
329
|
+
},
|
|
330
|
+
configuration: {
|
|
331
|
+
network: params.network,
|
|
332
|
+
asset: params.asset,
|
|
333
|
+
recipient: params.recipient,
|
|
334
|
+
amount: numericAmount
|
|
335
|
+
},
|
|
336
|
+
currentPayment: {
|
|
337
|
+
type: "exchange",
|
|
338
|
+
exchangeId
|
|
339
|
+
},
|
|
340
|
+
headless
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
if (headless) {
|
|
344
|
+
this.initiatePayment();
|
|
345
|
+
EventsController.sendEvent({
|
|
346
|
+
type: "track",
|
|
347
|
+
event: "PAY_INITIATED",
|
|
348
|
+
properties: {
|
|
349
|
+
paymentId: state.paymentId || DEFAULT_PAYMENT_ID,
|
|
350
|
+
configuration: {
|
|
351
|
+
network: params.network,
|
|
352
|
+
asset: params.asset,
|
|
353
|
+
recipient: params.recipient,
|
|
354
|
+
amount: numericAmount
|
|
355
|
+
},
|
|
356
|
+
currentPayment: {
|
|
357
|
+
type: "exchange",
|
|
358
|
+
exchangeId
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
return response;
|
|
364
|
+
} catch (error) {
|
|
365
|
+
if (error instanceof Error && error.message.includes("is not supported")) {
|
|
366
|
+
throw new AppKitPayError(AppKitPayErrorCodes.ASSET_NOT_SUPPORTED);
|
|
367
|
+
}
|
|
368
|
+
throw new Error(error.message);
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
async openPayUrl(openParams, params, headless = false) {
|
|
372
|
+
try {
|
|
373
|
+
const payUrl = await this.getPayUrl(openParams.exchangeId, params, headless);
|
|
374
|
+
if (!payUrl) {
|
|
375
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_PAY_URL);
|
|
376
|
+
}
|
|
377
|
+
const shouldOpenInNewTab = openParams.openInNewTab ?? true;
|
|
378
|
+
const target = shouldOpenInNewTab ? "_blank" : "_self";
|
|
379
|
+
CoreHelperUtil.openHref(payUrl.url, target);
|
|
380
|
+
return payUrl;
|
|
381
|
+
} catch (error) {
|
|
382
|
+
if (error instanceof AppKitPayError) {
|
|
383
|
+
state.error = error.message;
|
|
384
|
+
} else {
|
|
385
|
+
state.error = AppKitPayErrorMessages.GENERIC_PAYMENT_ERROR;
|
|
386
|
+
}
|
|
387
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_PAY_URL);
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
subscribeEvents() {
|
|
391
|
+
if (state.isConfigured) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
ProviderUtil.subscribeProviders(async (_) => {
|
|
395
|
+
const chainNamespace = ChainController.state.activeChain;
|
|
396
|
+
const provider = ProviderUtil.getProvider(chainNamespace);
|
|
397
|
+
if (!provider) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
await this.handlePayment();
|
|
401
|
+
});
|
|
402
|
+
AccountController.subscribeKey("caipAddress", async (caipAddress) => {
|
|
403
|
+
if (!caipAddress) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
await this.handlePayment();
|
|
407
|
+
});
|
|
408
|
+
},
|
|
409
|
+
async handlePayment() {
|
|
410
|
+
state.currentPayment = {
|
|
411
|
+
type: "wallet",
|
|
412
|
+
status: "IN_PROGRESS"
|
|
413
|
+
};
|
|
414
|
+
const caipAddress = AccountController.state.caipAddress;
|
|
415
|
+
if (!caipAddress) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const { chainId, address } = ParseUtil.parseCaipAddress(caipAddress);
|
|
419
|
+
const chainNamespace = ChainController.state.activeChain;
|
|
420
|
+
if (!address || !chainId || !chainNamespace) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
const provider = ProviderUtil.getProvider(chainNamespace);
|
|
424
|
+
if (!provider) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const caipNetwork = ChainController.state.activeCaipNetwork;
|
|
428
|
+
if (!caipNetwork) {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
if (state.isPaymentInProgress) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
try {
|
|
435
|
+
this.initiatePayment();
|
|
436
|
+
const requestedCaipNetworks = ChainController.getAllRequestedCaipNetworks();
|
|
437
|
+
const approvedCaipNetworkIds = ChainController.getAllApprovedCaipNetworkIds();
|
|
438
|
+
await ensureCorrectNetwork({
|
|
439
|
+
paymentAssetNetwork: state.paymentAsset.network,
|
|
440
|
+
activeCaipNetwork: caipNetwork,
|
|
441
|
+
approvedCaipNetworkIds,
|
|
442
|
+
requestedCaipNetworks
|
|
443
|
+
});
|
|
444
|
+
await ModalController.open({
|
|
445
|
+
view: "PayLoading"
|
|
446
|
+
});
|
|
447
|
+
switch (chainNamespace) {
|
|
448
|
+
case ConstantsUtil.CHAIN.EVM:
|
|
449
|
+
if (state.paymentAsset.asset === "native") {
|
|
450
|
+
state.currentPayment.result = await processEvmNativePayment(state.paymentAsset, chainNamespace, {
|
|
451
|
+
recipient: state.recipient,
|
|
452
|
+
amount: state.amount,
|
|
453
|
+
fromAddress: address
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
if (state.paymentAsset.asset.startsWith("0x")) {
|
|
457
|
+
state.currentPayment.result = await processEvmErc20Payment(state.paymentAsset, {
|
|
458
|
+
recipient: state.recipient,
|
|
459
|
+
amount: state.amount,
|
|
460
|
+
fromAddress: address
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
state.currentPayment.status = "SUCCESS";
|
|
464
|
+
break;
|
|
465
|
+
default:
|
|
466
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_CHAIN_NAMESPACE);
|
|
467
|
+
}
|
|
468
|
+
} catch (error) {
|
|
469
|
+
if (error instanceof AppKitPayError) {
|
|
470
|
+
state.error = error.message;
|
|
471
|
+
} else {
|
|
472
|
+
state.error = AppKitPayErrorMessages.GENERIC_PAYMENT_ERROR;
|
|
473
|
+
}
|
|
474
|
+
state.currentPayment.status = "FAILED";
|
|
475
|
+
SnackController.showError(state.error);
|
|
476
|
+
} finally {
|
|
477
|
+
state.isPaymentInProgress = false;
|
|
478
|
+
}
|
|
479
|
+
},
|
|
480
|
+
getExchangeById(exchangeId) {
|
|
481
|
+
return state.exchanges.find((exchange) => exchange.id === exchangeId);
|
|
482
|
+
},
|
|
483
|
+
validatePayConfig(config) {
|
|
484
|
+
const { paymentAsset, recipient, amount } = config;
|
|
485
|
+
if (!paymentAsset) {
|
|
486
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG);
|
|
487
|
+
}
|
|
488
|
+
if (!recipient) {
|
|
489
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_RECIPIENT);
|
|
490
|
+
}
|
|
491
|
+
if (!paymentAsset.asset) {
|
|
492
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_ASSET);
|
|
493
|
+
}
|
|
494
|
+
if (amount === void 0 || amount === null || amount <= 0) {
|
|
495
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_AMOUNT);
|
|
496
|
+
}
|
|
497
|
+
},
|
|
498
|
+
handlePayWithWallet() {
|
|
499
|
+
const caipAddress = AccountController.state.caipAddress;
|
|
500
|
+
if (!caipAddress) {
|
|
501
|
+
RouterController.push("Connect");
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
const { chainId, address } = ParseUtil.parseCaipAddress(caipAddress);
|
|
505
|
+
const chainNamespace = ChainController.state.activeChain;
|
|
506
|
+
if (!address || !chainId || !chainNamespace) {
|
|
507
|
+
RouterController.push("Connect");
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
this.handlePayment();
|
|
511
|
+
},
|
|
512
|
+
async handlePayWithExchange(exchangeId) {
|
|
513
|
+
try {
|
|
514
|
+
state.currentPayment = {
|
|
515
|
+
type: "exchange",
|
|
516
|
+
exchangeId
|
|
517
|
+
};
|
|
518
|
+
const { network, asset } = state.paymentAsset;
|
|
519
|
+
const payUrlParams = {
|
|
520
|
+
network,
|
|
521
|
+
asset,
|
|
522
|
+
amount: state.amount,
|
|
523
|
+
recipient: state.recipient
|
|
524
|
+
};
|
|
525
|
+
const payUrl = await this.getPayUrl(exchangeId, payUrlParams);
|
|
526
|
+
if (!payUrl) {
|
|
527
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_INITIATE_PAYMENT);
|
|
528
|
+
}
|
|
529
|
+
state.currentPayment.sessionId = payUrl.sessionId;
|
|
530
|
+
state.currentPayment.status = "IN_PROGRESS";
|
|
531
|
+
state.currentPayment.exchangeId = exchangeId;
|
|
532
|
+
this.initiatePayment();
|
|
533
|
+
return {
|
|
534
|
+
url: payUrl.url,
|
|
535
|
+
openInNewTab: state.openInNewTab
|
|
536
|
+
};
|
|
537
|
+
} catch (error) {
|
|
538
|
+
if (error instanceof AppKitPayError) {
|
|
539
|
+
state.error = error.message;
|
|
540
|
+
} else {
|
|
541
|
+
state.error = AppKitPayErrorMessages.GENERIC_PAYMENT_ERROR;
|
|
542
|
+
}
|
|
543
|
+
state.isPaymentInProgress = false;
|
|
544
|
+
SnackController.showError(state.error);
|
|
545
|
+
return null;
|
|
546
|
+
}
|
|
547
|
+
},
|
|
548
|
+
async getBuyStatus(exchangeId, sessionId) {
|
|
549
|
+
var _a, _b;
|
|
550
|
+
try {
|
|
551
|
+
const status = await getBuyStatus({ sessionId, exchangeId });
|
|
552
|
+
if (status.status === "SUCCESS" || status.status === "FAILED") {
|
|
553
|
+
EventsController.sendEvent({
|
|
554
|
+
type: "track",
|
|
555
|
+
event: status.status === "SUCCESS" ? "PAY_SUCCESS" : "PAY_ERROR",
|
|
556
|
+
properties: {
|
|
557
|
+
paymentId: state.paymentId || DEFAULT_PAYMENT_ID,
|
|
558
|
+
configuration: {
|
|
559
|
+
network: state.paymentAsset.network,
|
|
560
|
+
asset: state.paymentAsset.asset,
|
|
561
|
+
recipient: state.recipient,
|
|
562
|
+
amount: state.amount
|
|
563
|
+
},
|
|
564
|
+
currentPayment: {
|
|
565
|
+
type: "exchange",
|
|
566
|
+
exchangeId: (_a = state.currentPayment) == null ? void 0 : _a.exchangeId,
|
|
567
|
+
sessionId: (_b = state.currentPayment) == null ? void 0 : _b.sessionId,
|
|
568
|
+
result: status.txHash
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
return status;
|
|
574
|
+
} catch (error) {
|
|
575
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_BUY_STATUS);
|
|
576
|
+
}
|
|
577
|
+
},
|
|
578
|
+
async updateBuyStatus(exchangeId, sessionId) {
|
|
579
|
+
try {
|
|
580
|
+
const status = await this.getBuyStatus(exchangeId, sessionId);
|
|
581
|
+
if (state.currentPayment) {
|
|
582
|
+
state.currentPayment.status = status.status;
|
|
583
|
+
state.currentPayment.result = status.txHash;
|
|
584
|
+
}
|
|
585
|
+
if (status.status === "SUCCESS" || status.status === "FAILED") {
|
|
586
|
+
state.isPaymentInProgress = false;
|
|
587
|
+
}
|
|
588
|
+
} catch (error) {
|
|
589
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_BUY_STATUS);
|
|
590
|
+
}
|
|
591
|
+
},
|
|
592
|
+
initiatePayment() {
|
|
593
|
+
state.isPaymentInProgress = true;
|
|
594
|
+
state.paymentId = crypto.randomUUID();
|
|
595
|
+
},
|
|
596
|
+
initializeAnalytics() {
|
|
597
|
+
if (state.analyticsSet) {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
state.analyticsSet = true;
|
|
601
|
+
this.subscribeKey("isPaymentInProgress", (_) => {
|
|
602
|
+
var _a;
|
|
603
|
+
if (((_a = state.currentPayment) == null ? void 0 : _a.status) && state.currentPayment.status !== "UNKNOWN") {
|
|
604
|
+
const eventType = {
|
|
605
|
+
IN_PROGRESS: "PAY_INITIATED",
|
|
606
|
+
SUCCESS: "PAY_SUCCESS",
|
|
607
|
+
FAILED: "PAY_ERROR"
|
|
608
|
+
}[state.currentPayment.status];
|
|
609
|
+
EventsController.sendEvent({
|
|
610
|
+
type: "track",
|
|
611
|
+
event: eventType,
|
|
612
|
+
properties: {
|
|
613
|
+
paymentId: state.paymentId || DEFAULT_PAYMENT_ID,
|
|
614
|
+
configuration: {
|
|
615
|
+
network: state.paymentAsset.network,
|
|
616
|
+
asset: state.paymentAsset.asset,
|
|
617
|
+
recipient: state.recipient,
|
|
618
|
+
amount: state.amount
|
|
619
|
+
},
|
|
620
|
+
currentPayment: {
|
|
621
|
+
type: state.currentPayment.type,
|
|
622
|
+
exchangeId: state.currentPayment.exchangeId,
|
|
623
|
+
sessionId: state.currentPayment.sessionId,
|
|
624
|
+
result: state.currentPayment.result
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
const styles$1 = i`
|
|
633
|
+
wui-separator {
|
|
634
|
+
margin: var(--wui-spacing-m) calc(var(--wui-spacing-m) * -1) var(--wui-spacing-xs)
|
|
635
|
+
calc(var(--wui-spacing-m) * -1);
|
|
636
|
+
width: calc(100% + var(--wui-spacing-s) * 2);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
.token-display {
|
|
640
|
+
padding: var(--wui-spacing-s) var(--wui-spacing-m);
|
|
641
|
+
border-radius: var(--wui-border-radius-s);
|
|
642
|
+
background-color: var(--wui-color-bg-125);
|
|
643
|
+
margin-top: var(--wui-spacing-s);
|
|
644
|
+
margin-bottom: var(--wui-spacing-s);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
.token-display wui-text {
|
|
648
|
+
text-transform: none;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
wui-loading-spinner {
|
|
652
|
+
padding: var(--wui-spacing-xs);
|
|
653
|
+
}
|
|
654
|
+
`;
|
|
655
|
+
var __decorate$1 = function(decorators, target, key, desc) {
|
|
656
|
+
var c = arguments.length, r2 = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
657
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
658
|
+
else for (var i2 = decorators.length - 1; i2 >= 0; i2--) if (d = decorators[i2]) r2 = (c < 3 ? d(r2) : c > 3 ? d(target, key, r2) : d(target, key)) || r2;
|
|
659
|
+
return c > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
660
|
+
};
|
|
661
|
+
let W3mPayView = class W3mPayView2 extends i$1 {
|
|
662
|
+
constructor() {
|
|
663
|
+
super();
|
|
664
|
+
this.unsubscribe = [];
|
|
665
|
+
this.amount = "";
|
|
666
|
+
this.tokenSymbol = "";
|
|
667
|
+
this.networkName = "";
|
|
668
|
+
this.exchanges = PayController.state.exchanges;
|
|
669
|
+
this.isLoading = PayController.state.isLoading;
|
|
670
|
+
this.loadingExchangeId = null;
|
|
671
|
+
this.connectedWalletInfo = AccountController.state.connectedWalletInfo;
|
|
672
|
+
this.initializePaymentDetails();
|
|
673
|
+
this.unsubscribe.push(PayController.subscribeKey("exchanges", (val) => this.exchanges = val));
|
|
674
|
+
this.unsubscribe.push(PayController.subscribeKey("isLoading", (val) => this.isLoading = val));
|
|
675
|
+
this.unsubscribe.push(AccountController.subscribe((newState) => this.connectedWalletInfo = newState.connectedWalletInfo));
|
|
676
|
+
PayController.fetchExchanges();
|
|
677
|
+
}
|
|
678
|
+
get isWalletConnected() {
|
|
679
|
+
return AccountController.state.status === "connected";
|
|
680
|
+
}
|
|
681
|
+
render() {
|
|
682
|
+
return x`
|
|
683
|
+
<wui-flex flexDirection="column">
|
|
684
|
+
<wui-flex flexDirection="column" .padding=${["0", "l", "l", "l"]} gap="s">
|
|
685
|
+
${this.renderPaymentHeader()}
|
|
686
|
+
|
|
687
|
+
<wui-flex flexDirection="column" gap="s">
|
|
688
|
+
${this.renderPayWithWallet()} ${this.renderExchangeOptions()}
|
|
689
|
+
</wui-flex>
|
|
690
|
+
</wui-flex>
|
|
691
|
+
</wui-flex>
|
|
692
|
+
`;
|
|
693
|
+
}
|
|
694
|
+
initializePaymentDetails() {
|
|
695
|
+
const paymentAsset = PayController.getPaymentAsset();
|
|
696
|
+
this.networkName = paymentAsset.network;
|
|
697
|
+
this.tokenSymbol = paymentAsset.metadata.symbol;
|
|
698
|
+
this.amount = PayController.state.amount.toString();
|
|
699
|
+
}
|
|
700
|
+
renderPayWithWallet() {
|
|
701
|
+
if (!isPayWithWalletSupported(this.networkName)) {
|
|
702
|
+
return x``;
|
|
703
|
+
}
|
|
704
|
+
return x`<wui-flex flexDirection="column" gap="s">
|
|
705
|
+
${this.isWalletConnected ? this.renderConnectedView() : this.renderDisconnectedView()}
|
|
706
|
+
</wui-flex>
|
|
707
|
+
<wui-separator text="or"></wui-separator>`;
|
|
708
|
+
}
|
|
709
|
+
renderPaymentHeader() {
|
|
710
|
+
let displayNetworkName = this.networkName;
|
|
711
|
+
if (this.networkName) {
|
|
712
|
+
const allNetworks = ChainController.getAllRequestedCaipNetworks();
|
|
713
|
+
const targetNetwork = allNetworks.find((net) => net.caipNetworkId === this.networkName);
|
|
714
|
+
if (targetNetwork) {
|
|
715
|
+
displayNetworkName = targetNetwork.name;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
return x`
|
|
719
|
+
<wui-flex flexDirection="column" alignItems="center">
|
|
720
|
+
<wui-flex alignItems="center" gap="xs">
|
|
721
|
+
<wui-text variant="large-700" color="fg-100">${this.amount || "0.0000"}</wui-text>
|
|
722
|
+
<wui-flex class="token-display" alignItems="center" gap="xxs">
|
|
723
|
+
<wui-text variant="paragraph-600" color="fg-100">
|
|
724
|
+
${this.tokenSymbol || "Unknown Asset"}
|
|
725
|
+
</wui-text>
|
|
726
|
+
${displayNetworkName ? x`
|
|
727
|
+
<wui-text variant="small-500" color="fg-200"> on ${displayNetworkName} </wui-text>
|
|
728
|
+
` : ""}
|
|
729
|
+
</wui-flex>
|
|
730
|
+
</wui-flex>
|
|
731
|
+
</wui-flex>
|
|
732
|
+
`;
|
|
733
|
+
}
|
|
734
|
+
renderConnectedView() {
|
|
735
|
+
var _a, _b, _c;
|
|
736
|
+
const walletName = ((_a = this.connectedWalletInfo) == null ? void 0 : _a.name) || "connected wallet";
|
|
737
|
+
return x`
|
|
738
|
+
<wui-list-item
|
|
739
|
+
@click=${this.onWalletPayment}
|
|
740
|
+
?chevron=${true}
|
|
741
|
+
data-testid="wallet-payment-option"
|
|
742
|
+
>
|
|
743
|
+
<wui-flex alignItems="center" gap="s">
|
|
744
|
+
<wui-wallet-image
|
|
745
|
+
size="sm"
|
|
746
|
+
imageSrc=${o((_b = this.connectedWalletInfo) == null ? void 0 : _b.icon)}
|
|
747
|
+
name=${o((_c = this.connectedWalletInfo) == null ? void 0 : _c.name)}
|
|
748
|
+
></wui-wallet-image>
|
|
749
|
+
<wui-text variant="paragraph-500" color="inherit">Pay with ${walletName}</wui-text>
|
|
750
|
+
</wui-flex>
|
|
751
|
+
</wui-list-item>
|
|
752
|
+
|
|
753
|
+
<wui-list-item
|
|
754
|
+
variant="icon"
|
|
755
|
+
iconVariant="overlay"
|
|
756
|
+
icon="disconnect"
|
|
757
|
+
@click=${this.onDisconnect}
|
|
758
|
+
data-testid="disconnect-button"
|
|
759
|
+
?chevron=${false}
|
|
760
|
+
>
|
|
761
|
+
<wui-text variant="paragraph-500" color="fg-200">Disconnect</wui-text>
|
|
762
|
+
</wui-list-item>
|
|
763
|
+
`;
|
|
764
|
+
}
|
|
765
|
+
renderDisconnectedView() {
|
|
766
|
+
return x`<wui-list-item
|
|
767
|
+
variant="icon"
|
|
768
|
+
iconVariant="overlay"
|
|
769
|
+
icon="walletPlaceholder"
|
|
770
|
+
@click=${this.onWalletPayment}
|
|
771
|
+
?chevron=${true}
|
|
772
|
+
data-testid="wallet-payment-option"
|
|
773
|
+
>
|
|
774
|
+
<wui-text variant="paragraph-500" color="inherit">Pay from wallet</wui-text>
|
|
775
|
+
</wui-list-item>`;
|
|
776
|
+
}
|
|
777
|
+
renderExchangeOptions() {
|
|
778
|
+
if (this.isLoading) {
|
|
779
|
+
return x`<wui-flex justifyContent="center" alignItems="center">
|
|
780
|
+
<wui-spinner size="md"></wui-spinner>
|
|
781
|
+
</wui-flex>`;
|
|
782
|
+
}
|
|
783
|
+
if (this.exchanges.length === 0) {
|
|
784
|
+
return x`<wui-flex justifyContent="center" alignItems="center">
|
|
785
|
+
<wui-text variant="paragraph-500" color="fg-100">No exchanges available</wui-text>
|
|
786
|
+
</wui-flex>`;
|
|
787
|
+
}
|
|
788
|
+
return this.exchanges.map((exchange) => x`
|
|
789
|
+
<wui-list-item
|
|
790
|
+
@click=${() => this.onExchangePayment(exchange.id)}
|
|
791
|
+
data-testid="exchange-option-${exchange.id}"
|
|
792
|
+
?chevron=${true}
|
|
793
|
+
?disabled=${this.loadingExchangeId !== null}
|
|
794
|
+
>
|
|
795
|
+
<wui-flex alignItems="center" gap="s">
|
|
796
|
+
${this.loadingExchangeId === exchange.id ? x`<wui-loading-spinner color="accent-100" size="md"></wui-loading-spinner>` : x`<wui-wallet-image
|
|
797
|
+
size="sm"
|
|
798
|
+
imageSrc=${o(exchange.imageUrl)}
|
|
799
|
+
name=${exchange.name}
|
|
800
|
+
></wui-wallet-image>`}
|
|
801
|
+
<wui-text flexGrow="1" variant="paragraph-500" color="inherit"
|
|
802
|
+
>Pay with ${exchange.name} <wui-spinner size="sm" color="fg-200"></wui-spinner
|
|
803
|
+
></wui-text>
|
|
804
|
+
</wui-flex>
|
|
805
|
+
</wui-list-item>
|
|
806
|
+
`);
|
|
807
|
+
}
|
|
808
|
+
onWalletPayment() {
|
|
809
|
+
PayController.handlePayWithWallet();
|
|
810
|
+
}
|
|
811
|
+
async onExchangePayment(exchangeId) {
|
|
812
|
+
try {
|
|
813
|
+
this.loadingExchangeId = exchangeId;
|
|
814
|
+
const result = await PayController.handlePayWithExchange(exchangeId);
|
|
815
|
+
if (result) {
|
|
816
|
+
await ModalController.open({
|
|
817
|
+
view: "PayLoading"
|
|
818
|
+
});
|
|
819
|
+
CoreHelperUtil.openHref(result.url, result.openInNewTab ? "_blank" : "_self");
|
|
820
|
+
}
|
|
821
|
+
} catch (error) {
|
|
822
|
+
console.error("Failed to pay with exchange", error);
|
|
823
|
+
SnackController.showError("Failed to pay with exchange");
|
|
824
|
+
} finally {
|
|
825
|
+
this.loadingExchangeId = null;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
async onDisconnect(e) {
|
|
829
|
+
e.stopPropagation();
|
|
830
|
+
try {
|
|
831
|
+
await ConnectionController.disconnect();
|
|
832
|
+
ModalController.close();
|
|
833
|
+
} catch {
|
|
834
|
+
console.error("Failed to disconnect");
|
|
835
|
+
SnackController.showError("Failed to disconnect");
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
disconnectedCallback() {
|
|
839
|
+
this.unsubscribe.forEach((unsubscribe) => unsubscribe());
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
W3mPayView.styles = styles$1;
|
|
843
|
+
__decorate$1([
|
|
844
|
+
r()
|
|
845
|
+
], W3mPayView.prototype, "amount", void 0);
|
|
846
|
+
__decorate$1([
|
|
847
|
+
r()
|
|
848
|
+
], W3mPayView.prototype, "tokenSymbol", void 0);
|
|
849
|
+
__decorate$1([
|
|
850
|
+
r()
|
|
851
|
+
], W3mPayView.prototype, "networkName", void 0);
|
|
852
|
+
__decorate$1([
|
|
853
|
+
r()
|
|
854
|
+
], W3mPayView.prototype, "exchanges", void 0);
|
|
855
|
+
__decorate$1([
|
|
856
|
+
r()
|
|
857
|
+
], W3mPayView.prototype, "isLoading", void 0);
|
|
858
|
+
__decorate$1([
|
|
859
|
+
r()
|
|
860
|
+
], W3mPayView.prototype, "loadingExchangeId", void 0);
|
|
861
|
+
__decorate$1([
|
|
862
|
+
r()
|
|
863
|
+
], W3mPayView.prototype, "connectedWalletInfo", void 0);
|
|
864
|
+
W3mPayView = __decorate$1([
|
|
865
|
+
customElement("w3m-pay-view")
|
|
866
|
+
], W3mPayView);
|
|
867
|
+
const styles = i`
|
|
868
|
+
:host {
|
|
869
|
+
display: block;
|
|
870
|
+
height: 100%;
|
|
871
|
+
width: 100%;
|
|
872
|
+
}
|
|
873
|
+
`;
|
|
874
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
875
|
+
var c = arguments.length, r2 = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
876
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
877
|
+
else for (var i2 = decorators.length - 1; i2 >= 0; i2--) if (d = decorators[i2]) r2 = (c < 3 ? d(r2) : c > 3 ? d(target, key, r2) : d(target, key)) || r2;
|
|
878
|
+
return c > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
879
|
+
};
|
|
880
|
+
const EXCHANGE_STATUS_CHECK_INTERVAL = 4e3;
|
|
881
|
+
let W3mPayLoadingView = class W3mPayLoadingView2 extends i$1 {
|
|
882
|
+
constructor() {
|
|
883
|
+
super();
|
|
884
|
+
this.loadingMessage = "";
|
|
885
|
+
this.subMessage = "";
|
|
886
|
+
this.paymentState = "in-progress";
|
|
887
|
+
this.paymentState = PayController.state.isPaymentInProgress ? "in-progress" : "completed";
|
|
888
|
+
this.updateMessages();
|
|
889
|
+
this.setupSubscription();
|
|
890
|
+
this.setupExchangeSubscription();
|
|
891
|
+
}
|
|
892
|
+
disconnectedCallback() {
|
|
893
|
+
clearInterval(this.exchangeSubscription);
|
|
894
|
+
}
|
|
895
|
+
render() {
|
|
896
|
+
return x`
|
|
897
|
+
<wui-flex
|
|
898
|
+
flexDirection="column"
|
|
899
|
+
alignItems="center"
|
|
900
|
+
.padding=${["xl", "xl", "xl", "xl"]}
|
|
901
|
+
gap="xl"
|
|
902
|
+
>
|
|
903
|
+
<wui-flex justifyContent="center" alignItems="center"> ${this.getStateIcon()} </wui-flex>
|
|
904
|
+
<wui-flex flexDirection="column" alignItems="center" gap="xs">
|
|
905
|
+
<wui-text align="center" variant="paragraph-500" color="fg-100">
|
|
906
|
+
${this.loadingMessage}
|
|
907
|
+
</wui-text>
|
|
908
|
+
<wui-text align="center" variant="small-400" color="fg-200">
|
|
909
|
+
${this.subMessage}
|
|
910
|
+
</wui-text>
|
|
911
|
+
</wui-flex>
|
|
912
|
+
</wui-flex>
|
|
913
|
+
`;
|
|
914
|
+
}
|
|
915
|
+
updateMessages() {
|
|
916
|
+
var _a;
|
|
917
|
+
switch (this.paymentState) {
|
|
918
|
+
case "completed":
|
|
919
|
+
this.loadingMessage = "Payment completed";
|
|
920
|
+
this.subMessage = "Your transaction has been successfully processed";
|
|
921
|
+
break;
|
|
922
|
+
case "error":
|
|
923
|
+
this.loadingMessage = "Payment failed";
|
|
924
|
+
this.subMessage = "There was an error processing your transaction";
|
|
925
|
+
break;
|
|
926
|
+
case "in-progress":
|
|
927
|
+
default:
|
|
928
|
+
if (((_a = PayController.state.currentPayment) == null ? void 0 : _a.type) === "exchange") {
|
|
929
|
+
this.loadingMessage = "Payment initiated";
|
|
930
|
+
this.subMessage = `Please complete the payment on the exchange`;
|
|
931
|
+
} else {
|
|
932
|
+
this.loadingMessage = "Awaiting payment confirmation";
|
|
933
|
+
this.subMessage = "Please confirm the payment transaction in your wallet";
|
|
934
|
+
}
|
|
935
|
+
break;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
getStateIcon() {
|
|
939
|
+
switch (this.paymentState) {
|
|
940
|
+
case "completed":
|
|
941
|
+
return this.successTemplate();
|
|
942
|
+
case "error":
|
|
943
|
+
return this.errorTemplate();
|
|
944
|
+
case "in-progress":
|
|
945
|
+
default:
|
|
946
|
+
return this.loaderTemplate();
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
setupExchangeSubscription() {
|
|
950
|
+
var _a;
|
|
951
|
+
if (((_a = PayController.state.currentPayment) == null ? void 0 : _a.type) !== "exchange") {
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
this.exchangeSubscription = setInterval(async () => {
|
|
955
|
+
var _a2, _b, _c;
|
|
956
|
+
const exchangeId = (_a2 = PayController.state.currentPayment) == null ? void 0 : _a2.exchangeId;
|
|
957
|
+
const sessionId = (_b = PayController.state.currentPayment) == null ? void 0 : _b.sessionId;
|
|
958
|
+
if (exchangeId && sessionId) {
|
|
959
|
+
await PayController.updateBuyStatus(exchangeId, sessionId);
|
|
960
|
+
if (((_c = PayController.state.currentPayment) == null ? void 0 : _c.status) === "SUCCESS") {
|
|
961
|
+
clearInterval(this.exchangeSubscription);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
}, EXCHANGE_STATUS_CHECK_INTERVAL);
|
|
965
|
+
}
|
|
966
|
+
setupSubscription() {
|
|
967
|
+
PayController.subscribeKey("isPaymentInProgress", (inProgress) => {
|
|
968
|
+
var _a;
|
|
969
|
+
if (!inProgress && this.paymentState === "in-progress") {
|
|
970
|
+
if (PayController.state.error || !((_a = PayController.state.currentPayment) == null ? void 0 : _a.result)) {
|
|
971
|
+
this.paymentState = "error";
|
|
972
|
+
} else {
|
|
973
|
+
this.paymentState = "completed";
|
|
974
|
+
}
|
|
975
|
+
this.updateMessages();
|
|
976
|
+
setTimeout(() => {
|
|
977
|
+
if (ConnectionController.state.status === "disconnected") {
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
ModalController.close();
|
|
981
|
+
}, 3e3);
|
|
982
|
+
}
|
|
983
|
+
});
|
|
984
|
+
PayController.subscribeKey("error", (error) => {
|
|
985
|
+
if (error && this.paymentState === "in-progress") {
|
|
986
|
+
this.paymentState = "error";
|
|
987
|
+
this.updateMessages();
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
loaderTemplate() {
|
|
992
|
+
const borderRadiusMaster = ThemeController.state.themeVariables["--w3m-border-radius-master"];
|
|
993
|
+
const radius = borderRadiusMaster ? parseInt(borderRadiusMaster.replace("px", ""), 10) : 4;
|
|
994
|
+
return x`<wui-loading-thumbnail radius=${radius * 9}></wui-loading-thumbnail>`;
|
|
995
|
+
}
|
|
996
|
+
successTemplate() {
|
|
997
|
+
return x`<wui-icon size="xl" color="success-100" name="checkmark"></wui-icon>`;
|
|
998
|
+
}
|
|
999
|
+
errorTemplate() {
|
|
1000
|
+
return x`<wui-icon size="xl" color="error-100" name="close"></wui-icon>`;
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
W3mPayLoadingView.styles = styles;
|
|
1004
|
+
__decorate([
|
|
1005
|
+
r()
|
|
1006
|
+
], W3mPayLoadingView.prototype, "loadingMessage", void 0);
|
|
1007
|
+
__decorate([
|
|
1008
|
+
r()
|
|
1009
|
+
], W3mPayLoadingView.prototype, "subMessage", void 0);
|
|
1010
|
+
__decorate([
|
|
1011
|
+
r()
|
|
1012
|
+
], W3mPayLoadingView.prototype, "paymentState", void 0);
|
|
1013
|
+
W3mPayLoadingView = __decorate([
|
|
1014
|
+
customElement("w3m-pay-loading-view")
|
|
1015
|
+
], W3mPayLoadingView);
|
|
1016
|
+
async function openPay(options) {
|
|
1017
|
+
return PayController.handleOpenPay(options);
|
|
1018
|
+
}
|
|
1019
|
+
function getExchanges() {
|
|
1020
|
+
return PayController.getExchanges();
|
|
1021
|
+
}
|
|
1022
|
+
function getPayResult() {
|
|
1023
|
+
var _a;
|
|
1024
|
+
return (_a = PayController.state.currentPayment) == null ? void 0 : _a.result;
|
|
1025
|
+
}
|
|
1026
|
+
function getPayError() {
|
|
1027
|
+
return PayController.state.error;
|
|
1028
|
+
}
|
|
1029
|
+
function getIsPaymentInProgress() {
|
|
1030
|
+
return PayController.state.isPaymentInProgress;
|
|
1031
|
+
}
|
|
1032
|
+
const baseETH = {
|
|
1033
|
+
network: "eip155:8453",
|
|
1034
|
+
asset: "native",
|
|
1035
|
+
metadata: {
|
|
1036
|
+
name: "Ethereum",
|
|
1037
|
+
symbol: "ETH",
|
|
1038
|
+
decimals: 18
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
const baseUSDC = {
|
|
1042
|
+
network: "eip155:8453",
|
|
1043
|
+
asset: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
|
|
1044
|
+
metadata: {
|
|
1045
|
+
name: "USD Coin",
|
|
1046
|
+
symbol: "USDC",
|
|
1047
|
+
decimals: 6
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
const baseSepoliaETH = {
|
|
1051
|
+
network: "eip155:84532",
|
|
1052
|
+
asset: "native",
|
|
1053
|
+
metadata: {
|
|
1054
|
+
name: "Ethereum",
|
|
1055
|
+
symbol: "ETH",
|
|
1056
|
+
decimals: 18
|
|
1057
|
+
}
|
|
1058
|
+
};
|
|
1059
|
+
export {
|
|
1060
|
+
W3mPayLoadingView,
|
|
1061
|
+
W3mPayView,
|
|
1062
|
+
baseETH,
|
|
1063
|
+
baseSepoliaETH,
|
|
1064
|
+
baseUSDC,
|
|
1065
|
+
getExchanges,
|
|
1066
|
+
getIsPaymentInProgress,
|
|
1067
|
+
getPayError,
|
|
1068
|
+
getPayResult,
|
|
1069
|
+
openPay
|
|
1070
|
+
};
|