@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,1069 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
+
const bitcoin = require("./bitcoin-DAvQGpeP.js");
|
|
5
|
+
const ifDefined = require("./if-defined-CJ5EZLw2.js");
|
|
6
|
+
require("./index-BXkamf-I.js");
|
|
7
|
+
require("./index-r6Kre1rx.js");
|
|
8
|
+
require("./index-BxSUTfaY.js");
|
|
9
|
+
require("./index-CtFcWwAd.js");
|
|
10
|
+
require("./index-Ba0tVdql.js");
|
|
11
|
+
require("./index-dnFzVpGy.js");
|
|
12
|
+
require("./index-miQwZPmn.js");
|
|
13
|
+
const react = require("./react-BzZcQig5.js");
|
|
14
|
+
const index = require("./index--Vg7VI9t.js");
|
|
15
|
+
require("./index-Daok2ZKn.js");
|
|
16
|
+
const AppKitPayErrorCodes = {
|
|
17
|
+
INVALID_PAYMENT_CONFIG: "INVALID_PAYMENT_CONFIG",
|
|
18
|
+
INVALID_RECIPIENT: "INVALID_RECIPIENT",
|
|
19
|
+
INVALID_ASSET: "INVALID_ASSET",
|
|
20
|
+
INVALID_AMOUNT: "INVALID_AMOUNT",
|
|
21
|
+
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
22
|
+
UNABLE_TO_INITIATE_PAYMENT: "UNABLE_TO_INITIATE_PAYMENT",
|
|
23
|
+
INVALID_CHAIN_NAMESPACE: "INVALID_CHAIN_NAMESPACE",
|
|
24
|
+
GENERIC_PAYMENT_ERROR: "GENERIC_PAYMENT_ERROR",
|
|
25
|
+
UNABLE_TO_GET_EXCHANGES: "UNABLE_TO_GET_EXCHANGES",
|
|
26
|
+
ASSET_NOT_SUPPORTED: "ASSET_NOT_SUPPORTED",
|
|
27
|
+
UNABLE_TO_GET_PAY_URL: "UNABLE_TO_GET_PAY_URL",
|
|
28
|
+
UNABLE_TO_GET_BUY_STATUS: "UNABLE_TO_GET_BUY_STATUS"
|
|
29
|
+
};
|
|
30
|
+
const AppKitPayErrorMessages = {
|
|
31
|
+
[AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG]: "Invalid payment configuration",
|
|
32
|
+
[AppKitPayErrorCodes.INVALID_RECIPIENT]: "Invalid recipient address",
|
|
33
|
+
[AppKitPayErrorCodes.INVALID_ASSET]: "Invalid asset specified",
|
|
34
|
+
[AppKitPayErrorCodes.INVALID_AMOUNT]: "Invalid payment amount",
|
|
35
|
+
[AppKitPayErrorCodes.UNKNOWN_ERROR]: "Unknown payment error occurred",
|
|
36
|
+
[AppKitPayErrorCodes.UNABLE_TO_INITIATE_PAYMENT]: "Unable to initiate payment",
|
|
37
|
+
[AppKitPayErrorCodes.INVALID_CHAIN_NAMESPACE]: "Invalid chain namespace",
|
|
38
|
+
[AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR]: "Unable to process payment",
|
|
39
|
+
[AppKitPayErrorCodes.UNABLE_TO_GET_EXCHANGES]: "Unable to get exchanges",
|
|
40
|
+
[AppKitPayErrorCodes.ASSET_NOT_SUPPORTED]: "Asset not supported by the selected exchange",
|
|
41
|
+
[AppKitPayErrorCodes.UNABLE_TO_GET_PAY_URL]: "Unable to get payment URL",
|
|
42
|
+
[AppKitPayErrorCodes.UNABLE_TO_GET_BUY_STATUS]: "Unable to get buy status"
|
|
43
|
+
};
|
|
44
|
+
class AppKitPayError extends Error {
|
|
45
|
+
get message() {
|
|
46
|
+
return AppKitPayErrorMessages[this.code];
|
|
47
|
+
}
|
|
48
|
+
constructor(code, details) {
|
|
49
|
+
super(AppKitPayErrorMessages[code]);
|
|
50
|
+
this.name = "AppKitPayError";
|
|
51
|
+
this.code = code;
|
|
52
|
+
this.details = details;
|
|
53
|
+
if (Error.captureStackTrace) {
|
|
54
|
+
Error.captureStackTrace(this, AppKitPayError);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const API_URL = "https://rpc.walletconnect.org/v1/json-rpc";
|
|
59
|
+
class JsonRpcError extends Error {
|
|
60
|
+
}
|
|
61
|
+
function getApiUrl() {
|
|
62
|
+
const projectId = react.OptionsController.getSnapshot().projectId;
|
|
63
|
+
return `${API_URL}?projectId=${projectId}`;
|
|
64
|
+
}
|
|
65
|
+
async function sendRequest(method, params) {
|
|
66
|
+
const url = getApiUrl();
|
|
67
|
+
const requestBody = {
|
|
68
|
+
jsonrpc: "2.0",
|
|
69
|
+
id: 1,
|
|
70
|
+
method,
|
|
71
|
+
params
|
|
72
|
+
};
|
|
73
|
+
const response = await fetch(url, {
|
|
74
|
+
method: "POST",
|
|
75
|
+
body: JSON.stringify(requestBody),
|
|
76
|
+
headers: { "Content-Type": "application/json" }
|
|
77
|
+
});
|
|
78
|
+
const json = await response.json();
|
|
79
|
+
if (json.error) {
|
|
80
|
+
throw new JsonRpcError(json.error.message);
|
|
81
|
+
}
|
|
82
|
+
return json;
|
|
83
|
+
}
|
|
84
|
+
async function getExchanges$1(params) {
|
|
85
|
+
const response = await sendRequest("reown_getExchanges", params);
|
|
86
|
+
return response.result;
|
|
87
|
+
}
|
|
88
|
+
async function getPayUrl(params) {
|
|
89
|
+
const response = await sendRequest("reown_getExchangePayUrl", params);
|
|
90
|
+
return response.result;
|
|
91
|
+
}
|
|
92
|
+
async function getBuyStatus(params) {
|
|
93
|
+
const response = await sendRequest("reown_getExchangeBuyStatus", params);
|
|
94
|
+
return response.result;
|
|
95
|
+
}
|
|
96
|
+
const SUPPORT_PAY_WITH_WALLET_CHAIN_NAMESPACES = ["eip155"];
|
|
97
|
+
const CHAIN_ASSET_INFO_MAP = {
|
|
98
|
+
eip155: {
|
|
99
|
+
native: { assetNamespace: "slip44", assetReference: "60" },
|
|
100
|
+
defaultTokenNamespace: "erc20"
|
|
101
|
+
},
|
|
102
|
+
solana: {
|
|
103
|
+
native: { assetNamespace: "slip44", assetReference: "501" },
|
|
104
|
+
defaultTokenNamespace: "token"
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
function formatCaip19Asset(caipNetworkId, asset) {
|
|
108
|
+
const { chainNamespace, chainId } = react.ParseUtil.parseCaipNetworkId(caipNetworkId);
|
|
109
|
+
const chainInfo = CHAIN_ASSET_INFO_MAP[chainNamespace];
|
|
110
|
+
if (!chainInfo) {
|
|
111
|
+
throw new Error(`Unsupported chain namespace for CAIP-19 formatting: ${chainNamespace}`);
|
|
112
|
+
}
|
|
113
|
+
let assetNamespace = chainInfo.native.assetNamespace;
|
|
114
|
+
let assetReference = chainInfo.native.assetReference;
|
|
115
|
+
if (asset !== "native") {
|
|
116
|
+
assetNamespace = chainInfo.defaultTokenNamespace;
|
|
117
|
+
assetReference = asset;
|
|
118
|
+
}
|
|
119
|
+
const networkPart = `${chainNamespace}:${chainId}`;
|
|
120
|
+
return `${networkPart}/${assetNamespace}:${assetReference}`;
|
|
121
|
+
}
|
|
122
|
+
function isPayWithWalletSupported(networkId) {
|
|
123
|
+
const { chainNamespace } = react.ParseUtil.parseCaipNetworkId(networkId);
|
|
124
|
+
return SUPPORT_PAY_WITH_WALLET_CHAIN_NAMESPACES.includes(chainNamespace);
|
|
125
|
+
}
|
|
126
|
+
async function ensureCorrectNetwork(options) {
|
|
127
|
+
const { paymentAssetNetwork, activeCaipNetwork, approvedCaipNetworkIds, requestedCaipNetworks } = options;
|
|
128
|
+
const sortedNetworks = react.CoreHelperUtil.sortRequestedNetworks(approvedCaipNetworkIds, requestedCaipNetworks);
|
|
129
|
+
const assetCaipNetwork = sortedNetworks.find((network) => network.caipNetworkId === paymentAssetNetwork);
|
|
130
|
+
if (!assetCaipNetwork) {
|
|
131
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG);
|
|
132
|
+
}
|
|
133
|
+
if (assetCaipNetwork.caipNetworkId === activeCaipNetwork.caipNetworkId) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const isSupportingAllNetworks = react.ChainController.getNetworkProp("supportsAllNetworks", assetCaipNetwork.chainNamespace);
|
|
137
|
+
const isSwitchAllowed = (approvedCaipNetworkIds == null ? void 0 : approvedCaipNetworkIds.includes(assetCaipNetwork.caipNetworkId)) || isSupportingAllNetworks;
|
|
138
|
+
if (!isSwitchAllowed) {
|
|
139
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG);
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
await react.ChainController.switchActiveNetwork(assetCaipNetwork);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
throw new AppKitPayError(AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR, error);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async function processEvmNativePayment(paymentAsset, chainNamespace, params) {
|
|
148
|
+
var _a;
|
|
149
|
+
if (chainNamespace !== react.ConstantsUtil$1.CHAIN.EVM) {
|
|
150
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_CHAIN_NAMESPACE);
|
|
151
|
+
}
|
|
152
|
+
if (!params.fromAddress) {
|
|
153
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG, "fromAddress is required for native EVM payments.");
|
|
154
|
+
}
|
|
155
|
+
const amountValue = typeof params.amount === "string" ? parseFloat(params.amount) : params.amount;
|
|
156
|
+
if (isNaN(amountValue)) {
|
|
157
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG);
|
|
158
|
+
}
|
|
159
|
+
const decimals = ((_a = paymentAsset.metadata) == null ? void 0 : _a.decimals) ?? 18;
|
|
160
|
+
const amountBigInt = react.ConnectionController.parseUnits(amountValue.toString(), decimals);
|
|
161
|
+
if (typeof amountBigInt !== "bigint") {
|
|
162
|
+
throw new AppKitPayError(AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR);
|
|
163
|
+
}
|
|
164
|
+
const txResponse = await react.ConnectionController.sendTransaction({
|
|
165
|
+
chainNamespace,
|
|
166
|
+
to: params.recipient,
|
|
167
|
+
address: params.fromAddress,
|
|
168
|
+
value: amountBigInt,
|
|
169
|
+
data: "0x"
|
|
170
|
+
});
|
|
171
|
+
return txResponse ?? void 0;
|
|
172
|
+
}
|
|
173
|
+
async function processEvmErc20Payment(paymentAsset, params) {
|
|
174
|
+
if (!params.fromAddress) {
|
|
175
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG, "fromAddress is required for ERC20 EVM payments.");
|
|
176
|
+
}
|
|
177
|
+
const tokenAddress = paymentAsset.asset;
|
|
178
|
+
const recipientAddress = params.recipient;
|
|
179
|
+
const decimals = Number(paymentAsset.metadata.decimals);
|
|
180
|
+
const amountBigInt = react.ConnectionController.parseUnits(params.amount.toString(), decimals);
|
|
181
|
+
if (amountBigInt === void 0) {
|
|
182
|
+
throw new AppKitPayError(AppKitPayErrorCodes.GENERIC_PAYMENT_ERROR);
|
|
183
|
+
}
|
|
184
|
+
const txResponse = await react.ConnectionController.writeContract({
|
|
185
|
+
fromAddress: params.fromAddress,
|
|
186
|
+
tokenAddress,
|
|
187
|
+
args: [recipientAddress, amountBigInt],
|
|
188
|
+
method: "transfer",
|
|
189
|
+
abi: react.ContractUtil.getERC20Abi(tokenAddress),
|
|
190
|
+
chainNamespace: react.ConstantsUtil$1.CHAIN.EVM
|
|
191
|
+
});
|
|
192
|
+
return txResponse ?? void 0;
|
|
193
|
+
}
|
|
194
|
+
const DEFAULT_PAGE = 0;
|
|
195
|
+
const DEFAULT_PAYMENT_ID = "unknown";
|
|
196
|
+
const state = bitcoin.proxy({
|
|
197
|
+
paymentAsset: {
|
|
198
|
+
network: "eip155:1",
|
|
199
|
+
asset: "0x0",
|
|
200
|
+
metadata: {
|
|
201
|
+
name: "0x0",
|
|
202
|
+
symbol: "0x0",
|
|
203
|
+
decimals: 0
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
recipient: "0x0",
|
|
207
|
+
amount: 0,
|
|
208
|
+
isConfigured: false,
|
|
209
|
+
error: null,
|
|
210
|
+
isPaymentInProgress: false,
|
|
211
|
+
exchanges: [],
|
|
212
|
+
isLoading: false,
|
|
213
|
+
openInNewTab: true,
|
|
214
|
+
redirectUrl: void 0,
|
|
215
|
+
payWithExchange: void 0,
|
|
216
|
+
currentPayment: void 0,
|
|
217
|
+
analyticsSet: false,
|
|
218
|
+
paymentId: void 0
|
|
219
|
+
});
|
|
220
|
+
const PayController = {
|
|
221
|
+
state,
|
|
222
|
+
subscribe(callback) {
|
|
223
|
+
return bitcoin.subscribe(state, () => callback(state));
|
|
224
|
+
},
|
|
225
|
+
subscribeKey(key, callback) {
|
|
226
|
+
return bitcoin.subscribeKey(state, key, callback);
|
|
227
|
+
},
|
|
228
|
+
async handleOpenPay(options) {
|
|
229
|
+
this.resetState();
|
|
230
|
+
this.setPaymentConfig(options);
|
|
231
|
+
this.subscribeEvents();
|
|
232
|
+
this.initializeAnalytics();
|
|
233
|
+
state.isConfigured = true;
|
|
234
|
+
react.EventsController.sendEvent({
|
|
235
|
+
type: "track",
|
|
236
|
+
event: "PAY_MODAL_OPEN",
|
|
237
|
+
properties: {
|
|
238
|
+
exchanges: state.exchanges,
|
|
239
|
+
configuration: {
|
|
240
|
+
network: state.paymentAsset.network,
|
|
241
|
+
asset: state.paymentAsset.asset,
|
|
242
|
+
recipient: state.recipient,
|
|
243
|
+
amount: state.amount
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
await react.ModalController.open({
|
|
248
|
+
view: "Pay"
|
|
249
|
+
});
|
|
250
|
+
},
|
|
251
|
+
resetState() {
|
|
252
|
+
state.paymentAsset = {
|
|
253
|
+
network: "eip155:1",
|
|
254
|
+
asset: "0x0",
|
|
255
|
+
metadata: { name: "0x0", symbol: "0x0", decimals: 0 }
|
|
256
|
+
};
|
|
257
|
+
state.recipient = "0x0";
|
|
258
|
+
state.amount = 0;
|
|
259
|
+
state.isConfigured = false;
|
|
260
|
+
state.error = null;
|
|
261
|
+
state.isPaymentInProgress = false;
|
|
262
|
+
state.isLoading = false;
|
|
263
|
+
state.currentPayment = void 0;
|
|
264
|
+
},
|
|
265
|
+
setPaymentConfig(config) {
|
|
266
|
+
if (!config.paymentAsset) {
|
|
267
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG);
|
|
268
|
+
}
|
|
269
|
+
try {
|
|
270
|
+
state.paymentAsset = config.paymentAsset;
|
|
271
|
+
state.recipient = config.recipient;
|
|
272
|
+
state.amount = config.amount;
|
|
273
|
+
state.openInNewTab = config.openInNewTab ?? true;
|
|
274
|
+
state.redirectUrl = config.redirectUrl;
|
|
275
|
+
state.payWithExchange = config.payWithExchange;
|
|
276
|
+
state.error = null;
|
|
277
|
+
} catch (error) {
|
|
278
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG, error.message);
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
getPaymentAsset() {
|
|
282
|
+
return state.paymentAsset;
|
|
283
|
+
},
|
|
284
|
+
getExchanges() {
|
|
285
|
+
return state.exchanges;
|
|
286
|
+
},
|
|
287
|
+
async fetchExchanges() {
|
|
288
|
+
try {
|
|
289
|
+
state.isLoading = true;
|
|
290
|
+
const response = await getExchanges$1({
|
|
291
|
+
page: DEFAULT_PAGE,
|
|
292
|
+
asset: formatCaip19Asset(state.paymentAsset.network, state.paymentAsset.asset),
|
|
293
|
+
amount: state.amount.toString()
|
|
294
|
+
});
|
|
295
|
+
state.exchanges = response.exchanges.slice(0, 2);
|
|
296
|
+
} catch (error) {
|
|
297
|
+
react.SnackController.showError(AppKitPayErrorMessages.UNABLE_TO_GET_EXCHANGES);
|
|
298
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_EXCHANGES);
|
|
299
|
+
} finally {
|
|
300
|
+
state.isLoading = false;
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
async getAvailableExchanges(params) {
|
|
304
|
+
var _a;
|
|
305
|
+
try {
|
|
306
|
+
const asset = (params == null ? void 0 : params.asset) && (params == null ? void 0 : params.network) ? formatCaip19Asset(params.network, params.asset) : void 0;
|
|
307
|
+
const response = await getExchanges$1({
|
|
308
|
+
page: (params == null ? void 0 : params.page) ?? DEFAULT_PAGE,
|
|
309
|
+
asset,
|
|
310
|
+
amount: (_a = params == null ? void 0 : params.amount) == null ? void 0 : _a.toString()
|
|
311
|
+
});
|
|
312
|
+
return response;
|
|
313
|
+
} catch (error) {
|
|
314
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_EXCHANGES);
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
async getPayUrl(exchangeId, params, headless = false) {
|
|
318
|
+
try {
|
|
319
|
+
const numericAmount = Number(params.amount);
|
|
320
|
+
const response = await getPayUrl({
|
|
321
|
+
exchangeId,
|
|
322
|
+
asset: formatCaip19Asset(params.network, params.asset),
|
|
323
|
+
amount: numericAmount.toString(),
|
|
324
|
+
recipient: `${params.network}:${params.recipient}`
|
|
325
|
+
});
|
|
326
|
+
react.EventsController.sendEvent({
|
|
327
|
+
type: "track",
|
|
328
|
+
event: "PAY_EXCHANGE_SELECTED",
|
|
329
|
+
properties: {
|
|
330
|
+
exchange: {
|
|
331
|
+
id: exchangeId
|
|
332
|
+
},
|
|
333
|
+
configuration: {
|
|
334
|
+
network: params.network,
|
|
335
|
+
asset: params.asset,
|
|
336
|
+
recipient: params.recipient,
|
|
337
|
+
amount: numericAmount
|
|
338
|
+
},
|
|
339
|
+
currentPayment: {
|
|
340
|
+
type: "exchange",
|
|
341
|
+
exchangeId
|
|
342
|
+
},
|
|
343
|
+
headless
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
if (headless) {
|
|
347
|
+
this.initiatePayment();
|
|
348
|
+
react.EventsController.sendEvent({
|
|
349
|
+
type: "track",
|
|
350
|
+
event: "PAY_INITIATED",
|
|
351
|
+
properties: {
|
|
352
|
+
paymentId: state.paymentId || DEFAULT_PAYMENT_ID,
|
|
353
|
+
configuration: {
|
|
354
|
+
network: params.network,
|
|
355
|
+
asset: params.asset,
|
|
356
|
+
recipient: params.recipient,
|
|
357
|
+
amount: numericAmount
|
|
358
|
+
},
|
|
359
|
+
currentPayment: {
|
|
360
|
+
type: "exchange",
|
|
361
|
+
exchangeId
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
return response;
|
|
367
|
+
} catch (error) {
|
|
368
|
+
if (error instanceof Error && error.message.includes("is not supported")) {
|
|
369
|
+
throw new AppKitPayError(AppKitPayErrorCodes.ASSET_NOT_SUPPORTED);
|
|
370
|
+
}
|
|
371
|
+
throw new Error(error.message);
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
async openPayUrl(openParams, params, headless = false) {
|
|
375
|
+
try {
|
|
376
|
+
const payUrl = await this.getPayUrl(openParams.exchangeId, params, headless);
|
|
377
|
+
if (!payUrl) {
|
|
378
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_PAY_URL);
|
|
379
|
+
}
|
|
380
|
+
const shouldOpenInNewTab = openParams.openInNewTab ?? true;
|
|
381
|
+
const target = shouldOpenInNewTab ? "_blank" : "_self";
|
|
382
|
+
react.CoreHelperUtil.openHref(payUrl.url, target);
|
|
383
|
+
return payUrl;
|
|
384
|
+
} catch (error) {
|
|
385
|
+
if (error instanceof AppKitPayError) {
|
|
386
|
+
state.error = error.message;
|
|
387
|
+
} else {
|
|
388
|
+
state.error = AppKitPayErrorMessages.GENERIC_PAYMENT_ERROR;
|
|
389
|
+
}
|
|
390
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_PAY_URL);
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
subscribeEvents() {
|
|
394
|
+
if (state.isConfigured) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
index.ProviderUtil.subscribeProviders(async (_) => {
|
|
398
|
+
const chainNamespace = react.ChainController.state.activeChain;
|
|
399
|
+
const provider = index.ProviderUtil.getProvider(chainNamespace);
|
|
400
|
+
if (!provider) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
await this.handlePayment();
|
|
404
|
+
});
|
|
405
|
+
react.AccountController.subscribeKey("caipAddress", async (caipAddress) => {
|
|
406
|
+
if (!caipAddress) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
await this.handlePayment();
|
|
410
|
+
});
|
|
411
|
+
},
|
|
412
|
+
async handlePayment() {
|
|
413
|
+
state.currentPayment = {
|
|
414
|
+
type: "wallet",
|
|
415
|
+
status: "IN_PROGRESS"
|
|
416
|
+
};
|
|
417
|
+
const caipAddress = react.AccountController.state.caipAddress;
|
|
418
|
+
if (!caipAddress) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const { chainId, address } = react.ParseUtil.parseCaipAddress(caipAddress);
|
|
422
|
+
const chainNamespace = react.ChainController.state.activeChain;
|
|
423
|
+
if (!address || !chainId || !chainNamespace) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const provider = index.ProviderUtil.getProvider(chainNamespace);
|
|
427
|
+
if (!provider) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
const caipNetwork = react.ChainController.state.activeCaipNetwork;
|
|
431
|
+
if (!caipNetwork) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
if (state.isPaymentInProgress) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
try {
|
|
438
|
+
this.initiatePayment();
|
|
439
|
+
const requestedCaipNetworks = react.ChainController.getAllRequestedCaipNetworks();
|
|
440
|
+
const approvedCaipNetworkIds = react.ChainController.getAllApprovedCaipNetworkIds();
|
|
441
|
+
await ensureCorrectNetwork({
|
|
442
|
+
paymentAssetNetwork: state.paymentAsset.network,
|
|
443
|
+
activeCaipNetwork: caipNetwork,
|
|
444
|
+
approvedCaipNetworkIds,
|
|
445
|
+
requestedCaipNetworks
|
|
446
|
+
});
|
|
447
|
+
await react.ModalController.open({
|
|
448
|
+
view: "PayLoading"
|
|
449
|
+
});
|
|
450
|
+
switch (chainNamespace) {
|
|
451
|
+
case react.ConstantsUtil$1.CHAIN.EVM:
|
|
452
|
+
if (state.paymentAsset.asset === "native") {
|
|
453
|
+
state.currentPayment.result = await processEvmNativePayment(state.paymentAsset, chainNamespace, {
|
|
454
|
+
recipient: state.recipient,
|
|
455
|
+
amount: state.amount,
|
|
456
|
+
fromAddress: address
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
if (state.paymentAsset.asset.startsWith("0x")) {
|
|
460
|
+
state.currentPayment.result = await processEvmErc20Payment(state.paymentAsset, {
|
|
461
|
+
recipient: state.recipient,
|
|
462
|
+
amount: state.amount,
|
|
463
|
+
fromAddress: address
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
state.currentPayment.status = "SUCCESS";
|
|
467
|
+
break;
|
|
468
|
+
default:
|
|
469
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_CHAIN_NAMESPACE);
|
|
470
|
+
}
|
|
471
|
+
} catch (error) {
|
|
472
|
+
if (error instanceof AppKitPayError) {
|
|
473
|
+
state.error = error.message;
|
|
474
|
+
} else {
|
|
475
|
+
state.error = AppKitPayErrorMessages.GENERIC_PAYMENT_ERROR;
|
|
476
|
+
}
|
|
477
|
+
state.currentPayment.status = "FAILED";
|
|
478
|
+
react.SnackController.showError(state.error);
|
|
479
|
+
} finally {
|
|
480
|
+
state.isPaymentInProgress = false;
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
getExchangeById(exchangeId) {
|
|
484
|
+
return state.exchanges.find((exchange) => exchange.id === exchangeId);
|
|
485
|
+
},
|
|
486
|
+
validatePayConfig(config) {
|
|
487
|
+
const { paymentAsset, recipient, amount } = config;
|
|
488
|
+
if (!paymentAsset) {
|
|
489
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_PAYMENT_CONFIG);
|
|
490
|
+
}
|
|
491
|
+
if (!recipient) {
|
|
492
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_RECIPIENT);
|
|
493
|
+
}
|
|
494
|
+
if (!paymentAsset.asset) {
|
|
495
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_ASSET);
|
|
496
|
+
}
|
|
497
|
+
if (amount === void 0 || amount === null || amount <= 0) {
|
|
498
|
+
throw new AppKitPayError(AppKitPayErrorCodes.INVALID_AMOUNT);
|
|
499
|
+
}
|
|
500
|
+
},
|
|
501
|
+
handlePayWithWallet() {
|
|
502
|
+
const caipAddress = react.AccountController.state.caipAddress;
|
|
503
|
+
if (!caipAddress) {
|
|
504
|
+
react.RouterController.push("Connect");
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
const { chainId, address } = react.ParseUtil.parseCaipAddress(caipAddress);
|
|
508
|
+
const chainNamespace = react.ChainController.state.activeChain;
|
|
509
|
+
if (!address || !chainId || !chainNamespace) {
|
|
510
|
+
react.RouterController.push("Connect");
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
this.handlePayment();
|
|
514
|
+
},
|
|
515
|
+
async handlePayWithExchange(exchangeId) {
|
|
516
|
+
try {
|
|
517
|
+
state.currentPayment = {
|
|
518
|
+
type: "exchange",
|
|
519
|
+
exchangeId
|
|
520
|
+
};
|
|
521
|
+
const { network, asset } = state.paymentAsset;
|
|
522
|
+
const payUrlParams = {
|
|
523
|
+
network,
|
|
524
|
+
asset,
|
|
525
|
+
amount: state.amount,
|
|
526
|
+
recipient: state.recipient
|
|
527
|
+
};
|
|
528
|
+
const payUrl = await this.getPayUrl(exchangeId, payUrlParams);
|
|
529
|
+
if (!payUrl) {
|
|
530
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_INITIATE_PAYMENT);
|
|
531
|
+
}
|
|
532
|
+
state.currentPayment.sessionId = payUrl.sessionId;
|
|
533
|
+
state.currentPayment.status = "IN_PROGRESS";
|
|
534
|
+
state.currentPayment.exchangeId = exchangeId;
|
|
535
|
+
this.initiatePayment();
|
|
536
|
+
return {
|
|
537
|
+
url: payUrl.url,
|
|
538
|
+
openInNewTab: state.openInNewTab
|
|
539
|
+
};
|
|
540
|
+
} catch (error) {
|
|
541
|
+
if (error instanceof AppKitPayError) {
|
|
542
|
+
state.error = error.message;
|
|
543
|
+
} else {
|
|
544
|
+
state.error = AppKitPayErrorMessages.GENERIC_PAYMENT_ERROR;
|
|
545
|
+
}
|
|
546
|
+
state.isPaymentInProgress = false;
|
|
547
|
+
react.SnackController.showError(state.error);
|
|
548
|
+
return null;
|
|
549
|
+
}
|
|
550
|
+
},
|
|
551
|
+
async getBuyStatus(exchangeId, sessionId) {
|
|
552
|
+
var _a, _b;
|
|
553
|
+
try {
|
|
554
|
+
const status = await getBuyStatus({ sessionId, exchangeId });
|
|
555
|
+
if (status.status === "SUCCESS" || status.status === "FAILED") {
|
|
556
|
+
react.EventsController.sendEvent({
|
|
557
|
+
type: "track",
|
|
558
|
+
event: status.status === "SUCCESS" ? "PAY_SUCCESS" : "PAY_ERROR",
|
|
559
|
+
properties: {
|
|
560
|
+
paymentId: state.paymentId || DEFAULT_PAYMENT_ID,
|
|
561
|
+
configuration: {
|
|
562
|
+
network: state.paymentAsset.network,
|
|
563
|
+
asset: state.paymentAsset.asset,
|
|
564
|
+
recipient: state.recipient,
|
|
565
|
+
amount: state.amount
|
|
566
|
+
},
|
|
567
|
+
currentPayment: {
|
|
568
|
+
type: "exchange",
|
|
569
|
+
exchangeId: (_a = state.currentPayment) == null ? void 0 : _a.exchangeId,
|
|
570
|
+
sessionId: (_b = state.currentPayment) == null ? void 0 : _b.sessionId,
|
|
571
|
+
result: status.txHash
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
return status;
|
|
577
|
+
} catch (error) {
|
|
578
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_BUY_STATUS);
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
async updateBuyStatus(exchangeId, sessionId) {
|
|
582
|
+
try {
|
|
583
|
+
const status = await this.getBuyStatus(exchangeId, sessionId);
|
|
584
|
+
if (state.currentPayment) {
|
|
585
|
+
state.currentPayment.status = status.status;
|
|
586
|
+
state.currentPayment.result = status.txHash;
|
|
587
|
+
}
|
|
588
|
+
if (status.status === "SUCCESS" || status.status === "FAILED") {
|
|
589
|
+
state.isPaymentInProgress = false;
|
|
590
|
+
}
|
|
591
|
+
} catch (error) {
|
|
592
|
+
throw new AppKitPayError(AppKitPayErrorCodes.UNABLE_TO_GET_BUY_STATUS);
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
initiatePayment() {
|
|
596
|
+
state.isPaymentInProgress = true;
|
|
597
|
+
state.paymentId = crypto.randomUUID();
|
|
598
|
+
},
|
|
599
|
+
initializeAnalytics() {
|
|
600
|
+
if (state.analyticsSet) {
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
state.analyticsSet = true;
|
|
604
|
+
this.subscribeKey("isPaymentInProgress", (_) => {
|
|
605
|
+
var _a;
|
|
606
|
+
if (((_a = state.currentPayment) == null ? void 0 : _a.status) && state.currentPayment.status !== "UNKNOWN") {
|
|
607
|
+
const eventType = {
|
|
608
|
+
IN_PROGRESS: "PAY_INITIATED",
|
|
609
|
+
SUCCESS: "PAY_SUCCESS",
|
|
610
|
+
FAILED: "PAY_ERROR"
|
|
611
|
+
}[state.currentPayment.status];
|
|
612
|
+
react.EventsController.sendEvent({
|
|
613
|
+
type: "track",
|
|
614
|
+
event: eventType,
|
|
615
|
+
properties: {
|
|
616
|
+
paymentId: state.paymentId || DEFAULT_PAYMENT_ID,
|
|
617
|
+
configuration: {
|
|
618
|
+
network: state.paymentAsset.network,
|
|
619
|
+
asset: state.paymentAsset.asset,
|
|
620
|
+
recipient: state.recipient,
|
|
621
|
+
amount: state.amount
|
|
622
|
+
},
|
|
623
|
+
currentPayment: {
|
|
624
|
+
type: state.currentPayment.type,
|
|
625
|
+
exchangeId: state.currentPayment.exchangeId,
|
|
626
|
+
sessionId: state.currentPayment.sessionId,
|
|
627
|
+
result: state.currentPayment.result
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
const styles$1 = bitcoin.i`
|
|
636
|
+
wui-separator {
|
|
637
|
+
margin: var(--wui-spacing-m) calc(var(--wui-spacing-m) * -1) var(--wui-spacing-xs)
|
|
638
|
+
calc(var(--wui-spacing-m) * -1);
|
|
639
|
+
width: calc(100% + var(--wui-spacing-s) * 2);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
.token-display {
|
|
643
|
+
padding: var(--wui-spacing-s) var(--wui-spacing-m);
|
|
644
|
+
border-radius: var(--wui-border-radius-s);
|
|
645
|
+
background-color: var(--wui-color-bg-125);
|
|
646
|
+
margin-top: var(--wui-spacing-s);
|
|
647
|
+
margin-bottom: var(--wui-spacing-s);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
.token-display wui-text {
|
|
651
|
+
text-transform: none;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
wui-loading-spinner {
|
|
655
|
+
padding: var(--wui-spacing-xs);
|
|
656
|
+
}
|
|
657
|
+
`;
|
|
658
|
+
var __decorate$1 = function(decorators, target, key, desc) {
|
|
659
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
660
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
661
|
+
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;
|
|
662
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
663
|
+
};
|
|
664
|
+
exports.W3mPayView = class W3mPayView extends bitcoin.i$1 {
|
|
665
|
+
constructor() {
|
|
666
|
+
super();
|
|
667
|
+
this.unsubscribe = [];
|
|
668
|
+
this.amount = "";
|
|
669
|
+
this.tokenSymbol = "";
|
|
670
|
+
this.networkName = "";
|
|
671
|
+
this.exchanges = PayController.state.exchanges;
|
|
672
|
+
this.isLoading = PayController.state.isLoading;
|
|
673
|
+
this.loadingExchangeId = null;
|
|
674
|
+
this.connectedWalletInfo = react.AccountController.state.connectedWalletInfo;
|
|
675
|
+
this.initializePaymentDetails();
|
|
676
|
+
this.unsubscribe.push(PayController.subscribeKey("exchanges", (val) => this.exchanges = val));
|
|
677
|
+
this.unsubscribe.push(PayController.subscribeKey("isLoading", (val) => this.isLoading = val));
|
|
678
|
+
this.unsubscribe.push(react.AccountController.subscribe((newState) => this.connectedWalletInfo = newState.connectedWalletInfo));
|
|
679
|
+
PayController.fetchExchanges();
|
|
680
|
+
}
|
|
681
|
+
get isWalletConnected() {
|
|
682
|
+
return react.AccountController.state.status === "connected";
|
|
683
|
+
}
|
|
684
|
+
render() {
|
|
685
|
+
return bitcoin.x`
|
|
686
|
+
<wui-flex flexDirection="column">
|
|
687
|
+
<wui-flex flexDirection="column" .padding=${["0", "l", "l", "l"]} gap="s">
|
|
688
|
+
${this.renderPaymentHeader()}
|
|
689
|
+
|
|
690
|
+
<wui-flex flexDirection="column" gap="s">
|
|
691
|
+
${this.renderPayWithWallet()} ${this.renderExchangeOptions()}
|
|
692
|
+
</wui-flex>
|
|
693
|
+
</wui-flex>
|
|
694
|
+
</wui-flex>
|
|
695
|
+
`;
|
|
696
|
+
}
|
|
697
|
+
initializePaymentDetails() {
|
|
698
|
+
const paymentAsset = PayController.getPaymentAsset();
|
|
699
|
+
this.networkName = paymentAsset.network;
|
|
700
|
+
this.tokenSymbol = paymentAsset.metadata.symbol;
|
|
701
|
+
this.amount = PayController.state.amount.toString();
|
|
702
|
+
}
|
|
703
|
+
renderPayWithWallet() {
|
|
704
|
+
if (!isPayWithWalletSupported(this.networkName)) {
|
|
705
|
+
return bitcoin.x``;
|
|
706
|
+
}
|
|
707
|
+
return bitcoin.x`<wui-flex flexDirection="column" gap="s">
|
|
708
|
+
${this.isWalletConnected ? this.renderConnectedView() : this.renderDisconnectedView()}
|
|
709
|
+
</wui-flex>
|
|
710
|
+
<wui-separator text="or"></wui-separator>`;
|
|
711
|
+
}
|
|
712
|
+
renderPaymentHeader() {
|
|
713
|
+
let displayNetworkName = this.networkName;
|
|
714
|
+
if (this.networkName) {
|
|
715
|
+
const allNetworks = react.ChainController.getAllRequestedCaipNetworks();
|
|
716
|
+
const targetNetwork = allNetworks.find((net) => net.caipNetworkId === this.networkName);
|
|
717
|
+
if (targetNetwork) {
|
|
718
|
+
displayNetworkName = targetNetwork.name;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
return bitcoin.x`
|
|
722
|
+
<wui-flex flexDirection="column" alignItems="center">
|
|
723
|
+
<wui-flex alignItems="center" gap="xs">
|
|
724
|
+
<wui-text variant="large-700" color="fg-100">${this.amount || "0.0000"}</wui-text>
|
|
725
|
+
<wui-flex class="token-display" alignItems="center" gap="xxs">
|
|
726
|
+
<wui-text variant="paragraph-600" color="fg-100">
|
|
727
|
+
${this.tokenSymbol || "Unknown Asset"}
|
|
728
|
+
</wui-text>
|
|
729
|
+
${displayNetworkName ? bitcoin.x`
|
|
730
|
+
<wui-text variant="small-500" color="fg-200"> on ${displayNetworkName} </wui-text>
|
|
731
|
+
` : ""}
|
|
732
|
+
</wui-flex>
|
|
733
|
+
</wui-flex>
|
|
734
|
+
</wui-flex>
|
|
735
|
+
`;
|
|
736
|
+
}
|
|
737
|
+
renderConnectedView() {
|
|
738
|
+
var _a, _b, _c;
|
|
739
|
+
const walletName = ((_a = this.connectedWalletInfo) == null ? void 0 : _a.name) || "connected wallet";
|
|
740
|
+
return bitcoin.x`
|
|
741
|
+
<wui-list-item
|
|
742
|
+
@click=${this.onWalletPayment}
|
|
743
|
+
?chevron=${true}
|
|
744
|
+
data-testid="wallet-payment-option"
|
|
745
|
+
>
|
|
746
|
+
<wui-flex alignItems="center" gap="s">
|
|
747
|
+
<wui-wallet-image
|
|
748
|
+
size="sm"
|
|
749
|
+
imageSrc=${ifDefined.o((_b = this.connectedWalletInfo) == null ? void 0 : _b.icon)}
|
|
750
|
+
name=${ifDefined.o((_c = this.connectedWalletInfo) == null ? void 0 : _c.name)}
|
|
751
|
+
></wui-wallet-image>
|
|
752
|
+
<wui-text variant="paragraph-500" color="inherit">Pay with ${walletName}</wui-text>
|
|
753
|
+
</wui-flex>
|
|
754
|
+
</wui-list-item>
|
|
755
|
+
|
|
756
|
+
<wui-list-item
|
|
757
|
+
variant="icon"
|
|
758
|
+
iconVariant="overlay"
|
|
759
|
+
icon="disconnect"
|
|
760
|
+
@click=${this.onDisconnect}
|
|
761
|
+
data-testid="disconnect-button"
|
|
762
|
+
?chevron=${false}
|
|
763
|
+
>
|
|
764
|
+
<wui-text variant="paragraph-500" color="fg-200">Disconnect</wui-text>
|
|
765
|
+
</wui-list-item>
|
|
766
|
+
`;
|
|
767
|
+
}
|
|
768
|
+
renderDisconnectedView() {
|
|
769
|
+
return bitcoin.x`<wui-list-item
|
|
770
|
+
variant="icon"
|
|
771
|
+
iconVariant="overlay"
|
|
772
|
+
icon="walletPlaceholder"
|
|
773
|
+
@click=${this.onWalletPayment}
|
|
774
|
+
?chevron=${true}
|
|
775
|
+
data-testid="wallet-payment-option"
|
|
776
|
+
>
|
|
777
|
+
<wui-text variant="paragraph-500" color="inherit">Pay from wallet</wui-text>
|
|
778
|
+
</wui-list-item>`;
|
|
779
|
+
}
|
|
780
|
+
renderExchangeOptions() {
|
|
781
|
+
if (this.isLoading) {
|
|
782
|
+
return bitcoin.x`<wui-flex justifyContent="center" alignItems="center">
|
|
783
|
+
<wui-spinner size="md"></wui-spinner>
|
|
784
|
+
</wui-flex>`;
|
|
785
|
+
}
|
|
786
|
+
if (this.exchanges.length === 0) {
|
|
787
|
+
return bitcoin.x`<wui-flex justifyContent="center" alignItems="center">
|
|
788
|
+
<wui-text variant="paragraph-500" color="fg-100">No exchanges available</wui-text>
|
|
789
|
+
</wui-flex>`;
|
|
790
|
+
}
|
|
791
|
+
return this.exchanges.map((exchange) => bitcoin.x`
|
|
792
|
+
<wui-list-item
|
|
793
|
+
@click=${() => this.onExchangePayment(exchange.id)}
|
|
794
|
+
data-testid="exchange-option-${exchange.id}"
|
|
795
|
+
?chevron=${true}
|
|
796
|
+
?disabled=${this.loadingExchangeId !== null}
|
|
797
|
+
>
|
|
798
|
+
<wui-flex alignItems="center" gap="s">
|
|
799
|
+
${this.loadingExchangeId === exchange.id ? bitcoin.x`<wui-loading-spinner color="accent-100" size="md"></wui-loading-spinner>` : bitcoin.x`<wui-wallet-image
|
|
800
|
+
size="sm"
|
|
801
|
+
imageSrc=${ifDefined.o(exchange.imageUrl)}
|
|
802
|
+
name=${exchange.name}
|
|
803
|
+
></wui-wallet-image>`}
|
|
804
|
+
<wui-text flexGrow="1" variant="paragraph-500" color="inherit"
|
|
805
|
+
>Pay with ${exchange.name} <wui-spinner size="sm" color="fg-200"></wui-spinner
|
|
806
|
+
></wui-text>
|
|
807
|
+
</wui-flex>
|
|
808
|
+
</wui-list-item>
|
|
809
|
+
`);
|
|
810
|
+
}
|
|
811
|
+
onWalletPayment() {
|
|
812
|
+
PayController.handlePayWithWallet();
|
|
813
|
+
}
|
|
814
|
+
async onExchangePayment(exchangeId) {
|
|
815
|
+
try {
|
|
816
|
+
this.loadingExchangeId = exchangeId;
|
|
817
|
+
const result = await PayController.handlePayWithExchange(exchangeId);
|
|
818
|
+
if (result) {
|
|
819
|
+
await react.ModalController.open({
|
|
820
|
+
view: "PayLoading"
|
|
821
|
+
});
|
|
822
|
+
react.CoreHelperUtil.openHref(result.url, result.openInNewTab ? "_blank" : "_self");
|
|
823
|
+
}
|
|
824
|
+
} catch (error) {
|
|
825
|
+
console.error("Failed to pay with exchange", error);
|
|
826
|
+
react.SnackController.showError("Failed to pay with exchange");
|
|
827
|
+
} finally {
|
|
828
|
+
this.loadingExchangeId = null;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
async onDisconnect(e) {
|
|
832
|
+
e.stopPropagation();
|
|
833
|
+
try {
|
|
834
|
+
await react.ConnectionController.disconnect();
|
|
835
|
+
react.ModalController.close();
|
|
836
|
+
} catch {
|
|
837
|
+
console.error("Failed to disconnect");
|
|
838
|
+
react.SnackController.showError("Failed to disconnect");
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
disconnectedCallback() {
|
|
842
|
+
this.unsubscribe.forEach((unsubscribe) => unsubscribe());
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
exports.W3mPayView.styles = styles$1;
|
|
846
|
+
__decorate$1([
|
|
847
|
+
ifDefined.r()
|
|
848
|
+
], exports.W3mPayView.prototype, "amount", void 0);
|
|
849
|
+
__decorate$1([
|
|
850
|
+
ifDefined.r()
|
|
851
|
+
], exports.W3mPayView.prototype, "tokenSymbol", void 0);
|
|
852
|
+
__decorate$1([
|
|
853
|
+
ifDefined.r()
|
|
854
|
+
], exports.W3mPayView.prototype, "networkName", void 0);
|
|
855
|
+
__decorate$1([
|
|
856
|
+
ifDefined.r()
|
|
857
|
+
], exports.W3mPayView.prototype, "exchanges", void 0);
|
|
858
|
+
__decorate$1([
|
|
859
|
+
ifDefined.r()
|
|
860
|
+
], exports.W3mPayView.prototype, "isLoading", void 0);
|
|
861
|
+
__decorate$1([
|
|
862
|
+
ifDefined.r()
|
|
863
|
+
], exports.W3mPayView.prototype, "loadingExchangeId", void 0);
|
|
864
|
+
__decorate$1([
|
|
865
|
+
ifDefined.r()
|
|
866
|
+
], exports.W3mPayView.prototype, "connectedWalletInfo", void 0);
|
|
867
|
+
exports.W3mPayView = __decorate$1([
|
|
868
|
+
ifDefined.customElement("w3m-pay-view")
|
|
869
|
+
], exports.W3mPayView);
|
|
870
|
+
const styles = bitcoin.i`
|
|
871
|
+
:host {
|
|
872
|
+
display: block;
|
|
873
|
+
height: 100%;
|
|
874
|
+
width: 100%;
|
|
875
|
+
}
|
|
876
|
+
`;
|
|
877
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
878
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
879
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
880
|
+
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;
|
|
881
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
882
|
+
};
|
|
883
|
+
const EXCHANGE_STATUS_CHECK_INTERVAL = 4e3;
|
|
884
|
+
exports.W3mPayLoadingView = class W3mPayLoadingView extends bitcoin.i$1 {
|
|
885
|
+
constructor() {
|
|
886
|
+
super();
|
|
887
|
+
this.loadingMessage = "";
|
|
888
|
+
this.subMessage = "";
|
|
889
|
+
this.paymentState = "in-progress";
|
|
890
|
+
this.paymentState = PayController.state.isPaymentInProgress ? "in-progress" : "completed";
|
|
891
|
+
this.updateMessages();
|
|
892
|
+
this.setupSubscription();
|
|
893
|
+
this.setupExchangeSubscription();
|
|
894
|
+
}
|
|
895
|
+
disconnectedCallback() {
|
|
896
|
+
clearInterval(this.exchangeSubscription);
|
|
897
|
+
}
|
|
898
|
+
render() {
|
|
899
|
+
return bitcoin.x`
|
|
900
|
+
<wui-flex
|
|
901
|
+
flexDirection="column"
|
|
902
|
+
alignItems="center"
|
|
903
|
+
.padding=${["xl", "xl", "xl", "xl"]}
|
|
904
|
+
gap="xl"
|
|
905
|
+
>
|
|
906
|
+
<wui-flex justifyContent="center" alignItems="center"> ${this.getStateIcon()} </wui-flex>
|
|
907
|
+
<wui-flex flexDirection="column" alignItems="center" gap="xs">
|
|
908
|
+
<wui-text align="center" variant="paragraph-500" color="fg-100">
|
|
909
|
+
${this.loadingMessage}
|
|
910
|
+
</wui-text>
|
|
911
|
+
<wui-text align="center" variant="small-400" color="fg-200">
|
|
912
|
+
${this.subMessage}
|
|
913
|
+
</wui-text>
|
|
914
|
+
</wui-flex>
|
|
915
|
+
</wui-flex>
|
|
916
|
+
`;
|
|
917
|
+
}
|
|
918
|
+
updateMessages() {
|
|
919
|
+
var _a;
|
|
920
|
+
switch (this.paymentState) {
|
|
921
|
+
case "completed":
|
|
922
|
+
this.loadingMessage = "Payment completed";
|
|
923
|
+
this.subMessage = "Your transaction has been successfully processed";
|
|
924
|
+
break;
|
|
925
|
+
case "error":
|
|
926
|
+
this.loadingMessage = "Payment failed";
|
|
927
|
+
this.subMessage = "There was an error processing your transaction";
|
|
928
|
+
break;
|
|
929
|
+
case "in-progress":
|
|
930
|
+
default:
|
|
931
|
+
if (((_a = PayController.state.currentPayment) == null ? void 0 : _a.type) === "exchange") {
|
|
932
|
+
this.loadingMessage = "Payment initiated";
|
|
933
|
+
this.subMessage = `Please complete the payment on the exchange`;
|
|
934
|
+
} else {
|
|
935
|
+
this.loadingMessage = "Awaiting payment confirmation";
|
|
936
|
+
this.subMessage = "Please confirm the payment transaction in your wallet";
|
|
937
|
+
}
|
|
938
|
+
break;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
getStateIcon() {
|
|
942
|
+
switch (this.paymentState) {
|
|
943
|
+
case "completed":
|
|
944
|
+
return this.successTemplate();
|
|
945
|
+
case "error":
|
|
946
|
+
return this.errorTemplate();
|
|
947
|
+
case "in-progress":
|
|
948
|
+
default:
|
|
949
|
+
return this.loaderTemplate();
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
setupExchangeSubscription() {
|
|
953
|
+
var _a;
|
|
954
|
+
if (((_a = PayController.state.currentPayment) == null ? void 0 : _a.type) !== "exchange") {
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
this.exchangeSubscription = setInterval(async () => {
|
|
958
|
+
var _a2, _b, _c;
|
|
959
|
+
const exchangeId = (_a2 = PayController.state.currentPayment) == null ? void 0 : _a2.exchangeId;
|
|
960
|
+
const sessionId = (_b = PayController.state.currentPayment) == null ? void 0 : _b.sessionId;
|
|
961
|
+
if (exchangeId && sessionId) {
|
|
962
|
+
await PayController.updateBuyStatus(exchangeId, sessionId);
|
|
963
|
+
if (((_c = PayController.state.currentPayment) == null ? void 0 : _c.status) === "SUCCESS") {
|
|
964
|
+
clearInterval(this.exchangeSubscription);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
}, EXCHANGE_STATUS_CHECK_INTERVAL);
|
|
968
|
+
}
|
|
969
|
+
setupSubscription() {
|
|
970
|
+
PayController.subscribeKey("isPaymentInProgress", (inProgress) => {
|
|
971
|
+
var _a;
|
|
972
|
+
if (!inProgress && this.paymentState === "in-progress") {
|
|
973
|
+
if (PayController.state.error || !((_a = PayController.state.currentPayment) == null ? void 0 : _a.result)) {
|
|
974
|
+
this.paymentState = "error";
|
|
975
|
+
} else {
|
|
976
|
+
this.paymentState = "completed";
|
|
977
|
+
}
|
|
978
|
+
this.updateMessages();
|
|
979
|
+
setTimeout(() => {
|
|
980
|
+
if (react.ConnectionController.state.status === "disconnected") {
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
react.ModalController.close();
|
|
984
|
+
}, 3e3);
|
|
985
|
+
}
|
|
986
|
+
});
|
|
987
|
+
PayController.subscribeKey("error", (error) => {
|
|
988
|
+
if (error && this.paymentState === "in-progress") {
|
|
989
|
+
this.paymentState = "error";
|
|
990
|
+
this.updateMessages();
|
|
991
|
+
}
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
loaderTemplate() {
|
|
995
|
+
const borderRadiusMaster = react.ThemeController.state.themeVariables["--w3m-border-radius-master"];
|
|
996
|
+
const radius = borderRadiusMaster ? parseInt(borderRadiusMaster.replace("px", ""), 10) : 4;
|
|
997
|
+
return bitcoin.x`<wui-loading-thumbnail radius=${radius * 9}></wui-loading-thumbnail>`;
|
|
998
|
+
}
|
|
999
|
+
successTemplate() {
|
|
1000
|
+
return bitcoin.x`<wui-icon size="xl" color="success-100" name="checkmark"></wui-icon>`;
|
|
1001
|
+
}
|
|
1002
|
+
errorTemplate() {
|
|
1003
|
+
return bitcoin.x`<wui-icon size="xl" color="error-100" name="close"></wui-icon>`;
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
exports.W3mPayLoadingView.styles = styles;
|
|
1007
|
+
__decorate([
|
|
1008
|
+
ifDefined.r()
|
|
1009
|
+
], exports.W3mPayLoadingView.prototype, "loadingMessage", void 0);
|
|
1010
|
+
__decorate([
|
|
1011
|
+
ifDefined.r()
|
|
1012
|
+
], exports.W3mPayLoadingView.prototype, "subMessage", void 0);
|
|
1013
|
+
__decorate([
|
|
1014
|
+
ifDefined.r()
|
|
1015
|
+
], exports.W3mPayLoadingView.prototype, "paymentState", void 0);
|
|
1016
|
+
exports.W3mPayLoadingView = __decorate([
|
|
1017
|
+
ifDefined.customElement("w3m-pay-loading-view")
|
|
1018
|
+
], exports.W3mPayLoadingView);
|
|
1019
|
+
async function openPay(options) {
|
|
1020
|
+
return PayController.handleOpenPay(options);
|
|
1021
|
+
}
|
|
1022
|
+
function getExchanges() {
|
|
1023
|
+
return PayController.getExchanges();
|
|
1024
|
+
}
|
|
1025
|
+
function getPayResult() {
|
|
1026
|
+
var _a;
|
|
1027
|
+
return (_a = PayController.state.currentPayment) == null ? void 0 : _a.result;
|
|
1028
|
+
}
|
|
1029
|
+
function getPayError() {
|
|
1030
|
+
return PayController.state.error;
|
|
1031
|
+
}
|
|
1032
|
+
function getIsPaymentInProgress() {
|
|
1033
|
+
return PayController.state.isPaymentInProgress;
|
|
1034
|
+
}
|
|
1035
|
+
const baseETH = {
|
|
1036
|
+
network: "eip155:8453",
|
|
1037
|
+
asset: "native",
|
|
1038
|
+
metadata: {
|
|
1039
|
+
name: "Ethereum",
|
|
1040
|
+
symbol: "ETH",
|
|
1041
|
+
decimals: 18
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
const baseUSDC = {
|
|
1045
|
+
network: "eip155:8453",
|
|
1046
|
+
asset: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
|
|
1047
|
+
metadata: {
|
|
1048
|
+
name: "USD Coin",
|
|
1049
|
+
symbol: "USDC",
|
|
1050
|
+
decimals: 6
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
const baseSepoliaETH = {
|
|
1054
|
+
network: "eip155:84532",
|
|
1055
|
+
asset: "native",
|
|
1056
|
+
metadata: {
|
|
1057
|
+
name: "Ethereum",
|
|
1058
|
+
symbol: "ETH",
|
|
1059
|
+
decimals: 18
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
exports.baseETH = baseETH;
|
|
1063
|
+
exports.baseSepoliaETH = baseSepoliaETH;
|
|
1064
|
+
exports.baseUSDC = baseUSDC;
|
|
1065
|
+
exports.getExchanges = getExchanges;
|
|
1066
|
+
exports.getIsPaymentInProgress = getIsPaymentInProgress;
|
|
1067
|
+
exports.getPayError = getPayError;
|
|
1068
|
+
exports.getPayResult = getPayResult;
|
|
1069
|
+
exports.openPay = openPay;
|