@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
package/react-C43nEIqn.js
DELETED
|
@@ -1,3133 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
const index = require("./index-nigVQYBu.js");
|
|
4
|
-
const react = require("./react-DKUsVej7.js");
|
|
5
|
-
const viem = require("viem");
|
|
6
|
-
require("viem/chains");
|
|
7
|
-
const index$1 = require("./index-CWMcKi_X.js");
|
|
8
|
-
const ParseUtil = {
|
|
9
|
-
validateCaipAddress(address) {
|
|
10
|
-
var _a;
|
|
11
|
-
if (((_a = address.split(":")) == null ? void 0 : _a.length) !== 3) {
|
|
12
|
-
throw new Error("Invalid CAIP Address");
|
|
13
|
-
}
|
|
14
|
-
return address;
|
|
15
|
-
},
|
|
16
|
-
parseCaipAddress(caipAddress) {
|
|
17
|
-
const parts = caipAddress.split(":");
|
|
18
|
-
if (parts.length !== 3) {
|
|
19
|
-
throw new Error(`Invalid CAIP-10 address: ${caipAddress}`);
|
|
20
|
-
}
|
|
21
|
-
const [chainNamespace, chainId, address] = parts;
|
|
22
|
-
if (!chainNamespace || !chainId || !address) {
|
|
23
|
-
throw new Error(`Invalid CAIP-10 address: ${caipAddress}`);
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
chainNamespace,
|
|
27
|
-
chainId,
|
|
28
|
-
address
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
parseCaipNetworkId(caipNetworkId) {
|
|
32
|
-
const parts = caipNetworkId.split(":");
|
|
33
|
-
if (parts.length !== 2) {
|
|
34
|
-
throw new Error(`Invalid CAIP-2 network id: ${caipNetworkId}`);
|
|
35
|
-
}
|
|
36
|
-
const [chainNamespace, chainId] = parts;
|
|
37
|
-
if (!chainNamespace || !chainId) {
|
|
38
|
-
throw new Error(`Invalid CAIP-2 network id: ${caipNetworkId}`);
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
chainNamespace,
|
|
42
|
-
chainId
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
function shouldHandleEvent(eventKey, data = {}) {
|
|
47
|
-
var _a;
|
|
48
|
-
return typeof (data == null ? void 0 : data.type) === "string" && ((_a = data == null ? void 0 : data.type) == null ? void 0 : _a.includes(eventKey));
|
|
49
|
-
}
|
|
50
|
-
class W3mFrame {
|
|
51
|
-
constructor({ projectId, isAppClient = false, chainId = "eip155:1", enableLogger = true }) {
|
|
52
|
-
this.iframe = null;
|
|
53
|
-
this.rpcUrl = index.ConstantsUtil.BLOCKCHAIN_API_RPC_URL;
|
|
54
|
-
this.initFrame = () => {
|
|
55
|
-
const isFrameInitialized = document.getElementById("w3m-iframe");
|
|
56
|
-
if (this.iframe && !isFrameInitialized) {
|
|
57
|
-
document.body.appendChild(this.iframe);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
this.events = {
|
|
61
|
-
registerFrameEventHandler: (id, callback, signal) => {
|
|
62
|
-
function eventHandler({ data }) {
|
|
63
|
-
if (!shouldHandleEvent(index.W3mFrameConstants.FRAME_EVENT_KEY, data)) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const frameEvent = index.W3mFrameSchema.frameEvent.parse(data);
|
|
67
|
-
if (frameEvent.id === id) {
|
|
68
|
-
callback(frameEvent);
|
|
69
|
-
window.removeEventListener("message", eventHandler);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (index.W3mFrameHelpers.isClient) {
|
|
73
|
-
window.addEventListener("message", eventHandler);
|
|
74
|
-
signal.addEventListener("abort", () => {
|
|
75
|
-
window.removeEventListener("message", eventHandler);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
onFrameEvent: (callback) => {
|
|
80
|
-
if (index.W3mFrameHelpers.isClient) {
|
|
81
|
-
window.addEventListener("message", ({ data }) => {
|
|
82
|
-
if (!shouldHandleEvent(index.W3mFrameConstants.FRAME_EVENT_KEY, data)) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const frameEvent = index.W3mFrameSchema.frameEvent.parse(data);
|
|
86
|
-
callback(frameEvent);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
onAppEvent: (callback) => {
|
|
91
|
-
if (index.W3mFrameHelpers.isClient) {
|
|
92
|
-
window.addEventListener("message", ({ data }) => {
|
|
93
|
-
if (!shouldHandleEvent(index.W3mFrameConstants.APP_EVENT_KEY, data)) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const appEvent = index.W3mFrameSchema.appEvent.parse(data);
|
|
97
|
-
callback(appEvent);
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
postAppEvent: (event) => {
|
|
102
|
-
var _a;
|
|
103
|
-
if (index.W3mFrameHelpers.isClient) {
|
|
104
|
-
if (!((_a = this.iframe) == null ? void 0 : _a.contentWindow)) {
|
|
105
|
-
throw new Error("W3mFrame: iframe is not set");
|
|
106
|
-
}
|
|
107
|
-
index.W3mFrameSchema.appEvent.parse(event);
|
|
108
|
-
this.iframe.contentWindow.postMessage(event, "*");
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
postFrameEvent: (event) => {
|
|
112
|
-
if (index.W3mFrameHelpers.isClient) {
|
|
113
|
-
if (!parent) {
|
|
114
|
-
throw new Error("W3mFrame: parent is not set");
|
|
115
|
-
}
|
|
116
|
-
index.W3mFrameSchema.frameEvent.parse(event);
|
|
117
|
-
parent.postMessage(event, "*");
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
this.projectId = projectId;
|
|
122
|
-
this.frameLoadPromise = new Promise((resolve, reject) => {
|
|
123
|
-
this.frameLoadPromiseResolver = { resolve, reject };
|
|
124
|
-
});
|
|
125
|
-
if (isAppClient) {
|
|
126
|
-
this.frameLoadPromise = new Promise((resolve, reject) => {
|
|
127
|
-
this.frameLoadPromiseResolver = { resolve, reject };
|
|
128
|
-
});
|
|
129
|
-
if (index.W3mFrameHelpers.isClient) {
|
|
130
|
-
const iframe = document.createElement("iframe");
|
|
131
|
-
iframe.id = "w3m-iframe";
|
|
132
|
-
iframe.src = `${index.SECURE_SITE_SDK}?projectId=${projectId}&chainId=${chainId}&version=${index.SECURE_SITE_SDK_VERSION}&enableLogger=${enableLogger}`;
|
|
133
|
-
iframe.name = "w3m-secure-iframe";
|
|
134
|
-
iframe.style.position = "fixed";
|
|
135
|
-
iframe.style.zIndex = "999999";
|
|
136
|
-
iframe.style.display = "none";
|
|
137
|
-
iframe.style.animationDelay = "0s, 50ms";
|
|
138
|
-
iframe.style.borderBottomLeftRadius = `clamp(0px, var(--wui-border-radius-l), 44px)`;
|
|
139
|
-
iframe.style.borderBottomRightRadius = `clamp(0px, var(--wui-border-radius-l), 44px)`;
|
|
140
|
-
this.iframe = iframe;
|
|
141
|
-
this.iframe.onerror = () => {
|
|
142
|
-
var _a;
|
|
143
|
-
(_a = this.frameLoadPromiseResolver) == null ? void 0 : _a.reject("Unable to load email login dependency");
|
|
144
|
-
};
|
|
145
|
-
this.events.onFrameEvent((event) => {
|
|
146
|
-
var _a;
|
|
147
|
-
if (event.type === "@w3m-frame/READY") {
|
|
148
|
-
(_a = this.frameLoadPromiseResolver) == null ? void 0 : _a.resolve(void 0);
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
get networks() {
|
|
155
|
-
const data = [
|
|
156
|
-
"eip155:1",
|
|
157
|
-
"eip155:5",
|
|
158
|
-
"eip155:11155111",
|
|
159
|
-
"eip155:10",
|
|
160
|
-
"eip155:420",
|
|
161
|
-
"eip155:42161",
|
|
162
|
-
"eip155:421613",
|
|
163
|
-
"eip155:137",
|
|
164
|
-
"eip155:80001",
|
|
165
|
-
"eip155:42220",
|
|
166
|
-
"eip155:1313161554",
|
|
167
|
-
"eip155:1313161555",
|
|
168
|
-
"eip155:56",
|
|
169
|
-
"eip155:97",
|
|
170
|
-
"eip155:43114",
|
|
171
|
-
"eip155:43113",
|
|
172
|
-
"eip155:324",
|
|
173
|
-
"eip155:280",
|
|
174
|
-
"eip155:100",
|
|
175
|
-
"eip155:8453",
|
|
176
|
-
"eip155:84531",
|
|
177
|
-
"eip155:84532",
|
|
178
|
-
"eip155:7777777",
|
|
179
|
-
"eip155:999",
|
|
180
|
-
"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
181
|
-
"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z",
|
|
182
|
-
"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
183
|
-
].map((id) => ({
|
|
184
|
-
[id]: {
|
|
185
|
-
rpcUrl: `${this.rpcUrl}/v1/?chainId=${id}&projectId=${this.projectId}`,
|
|
186
|
-
chainId: id
|
|
187
|
-
}
|
|
188
|
-
}));
|
|
189
|
-
return Object.assign({}, ...data);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
class W3mFrameLogger {
|
|
193
|
-
constructor(projectId) {
|
|
194
|
-
var _a;
|
|
195
|
-
const loggerOptions = index.k({
|
|
196
|
-
level: index.DEFAULT_LOG_LEVEL
|
|
197
|
-
});
|
|
198
|
-
const { logger, chunkLoggerController } = index.A({
|
|
199
|
-
opts: loggerOptions
|
|
200
|
-
});
|
|
201
|
-
this.logger = index.E(logger, this.constructor.name);
|
|
202
|
-
this.chunkLoggerController = chunkLoggerController;
|
|
203
|
-
if (typeof window !== "undefined" && ((_a = this.chunkLoggerController) == null ? void 0 : _a.downloadLogsBlobInBrowser)) {
|
|
204
|
-
if (!window.downloadAppKitLogsBlob) {
|
|
205
|
-
window.downloadAppKitLogsBlob = {};
|
|
206
|
-
}
|
|
207
|
-
window.downloadAppKitLogsBlob["sdk"] = () => {
|
|
208
|
-
var _a2;
|
|
209
|
-
if ((_a2 = this.chunkLoggerController) == null ? void 0 : _a2.downloadLogsBlobInBrowser) {
|
|
210
|
-
this.chunkLoggerController.downloadLogsBlobInBrowser({
|
|
211
|
-
projectId
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
class W3mFrameProvider {
|
|
219
|
-
constructor({ projectId, chainId, enableLogger = true, onTimeout }) {
|
|
220
|
-
this.openRpcRequests = [];
|
|
221
|
-
if (enableLogger) {
|
|
222
|
-
this.w3mLogger = new W3mFrameLogger(projectId);
|
|
223
|
-
}
|
|
224
|
-
this.w3mFrame = new W3mFrame({ projectId, isAppClient: true, chainId, enableLogger });
|
|
225
|
-
this.onTimeout = onTimeout;
|
|
226
|
-
if (this.getLoginEmailUsed()) {
|
|
227
|
-
this.w3mFrame.initFrame();
|
|
228
|
-
}
|
|
229
|
-
this.w3mFrame.events.onFrameEvent((event) => {
|
|
230
|
-
if (event.type === index.W3mFrameConstants.FRAME_GET_USER_SUCCESS) {
|
|
231
|
-
this.user = event.payload;
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
this.initPromise = new Promise((resolve) => {
|
|
235
|
-
this.w3mFrame.events.onFrameEvent((event) => {
|
|
236
|
-
if (event.type === index.W3mFrameConstants.FRAME_READY) {
|
|
237
|
-
this.initPromise = void 0;
|
|
238
|
-
resolve();
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
async init() {
|
|
244
|
-
this.w3mFrame.initFrame();
|
|
245
|
-
if (this.initPromise) {
|
|
246
|
-
await this.initPromise;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
getLoginEmailUsed() {
|
|
250
|
-
return Boolean(index.W3mFrameStorage.get(index.W3mFrameConstants.EMAIL_LOGIN_USED_KEY));
|
|
251
|
-
}
|
|
252
|
-
getEmail() {
|
|
253
|
-
return index.W3mFrameStorage.get(index.W3mFrameConstants.EMAIL);
|
|
254
|
-
}
|
|
255
|
-
getUsername() {
|
|
256
|
-
return index.W3mFrameStorage.get(index.W3mFrameConstants.SOCIAL_USERNAME);
|
|
257
|
-
}
|
|
258
|
-
async reload() {
|
|
259
|
-
var _a;
|
|
260
|
-
try {
|
|
261
|
-
this.w3mFrame.initFrame();
|
|
262
|
-
await this.appEvent({
|
|
263
|
-
type: index.W3mFrameConstants.APP_RELOAD
|
|
264
|
-
});
|
|
265
|
-
} catch (error) {
|
|
266
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error reloading iframe");
|
|
267
|
-
throw error;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
async connectEmail(payload) {
|
|
271
|
-
var _a;
|
|
272
|
-
try {
|
|
273
|
-
index.W3mFrameHelpers.checkIfAllowedToTriggerEmail();
|
|
274
|
-
this.w3mFrame.initFrame();
|
|
275
|
-
const response = await this.appEvent({
|
|
276
|
-
type: index.W3mFrameConstants.APP_CONNECT_EMAIL,
|
|
277
|
-
payload
|
|
278
|
-
});
|
|
279
|
-
this.setNewLastEmailLoginTime();
|
|
280
|
-
return response;
|
|
281
|
-
} catch (error) {
|
|
282
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error connecting email");
|
|
283
|
-
throw error;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
async connectDevice() {
|
|
287
|
-
var _a;
|
|
288
|
-
try {
|
|
289
|
-
return this.appEvent({
|
|
290
|
-
type: index.W3mFrameConstants.APP_CONNECT_DEVICE
|
|
291
|
-
});
|
|
292
|
-
} catch (error) {
|
|
293
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error connecting device");
|
|
294
|
-
throw error;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
async connectOtp(payload) {
|
|
298
|
-
var _a;
|
|
299
|
-
try {
|
|
300
|
-
return this.appEvent({
|
|
301
|
-
type: index.W3mFrameConstants.APP_CONNECT_OTP,
|
|
302
|
-
payload
|
|
303
|
-
});
|
|
304
|
-
} catch (error) {
|
|
305
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error connecting otp");
|
|
306
|
-
throw error;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
async isConnected() {
|
|
310
|
-
var _a;
|
|
311
|
-
try {
|
|
312
|
-
if (!this.getLoginEmailUsed()) {
|
|
313
|
-
return { isConnected: false };
|
|
314
|
-
}
|
|
315
|
-
const response = await this.appEvent({
|
|
316
|
-
type: index.W3mFrameConstants.APP_IS_CONNECTED
|
|
317
|
-
});
|
|
318
|
-
if (!response.isConnected) {
|
|
319
|
-
this.deleteAuthLoginCache();
|
|
320
|
-
}
|
|
321
|
-
return response;
|
|
322
|
-
} catch (error) {
|
|
323
|
-
this.deleteAuthLoginCache();
|
|
324
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error checking connection");
|
|
325
|
-
throw error;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
async getChainId() {
|
|
329
|
-
var _a;
|
|
330
|
-
try {
|
|
331
|
-
const response = await this.appEvent({
|
|
332
|
-
type: index.W3mFrameConstants.APP_GET_CHAIN_ID
|
|
333
|
-
});
|
|
334
|
-
this.setLastUsedChainId(response.chainId);
|
|
335
|
-
return response;
|
|
336
|
-
} catch (error) {
|
|
337
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error getting chain id");
|
|
338
|
-
throw error;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
async getSocialRedirectUri(payload) {
|
|
342
|
-
var _a;
|
|
343
|
-
try {
|
|
344
|
-
this.w3mFrame.initFrame();
|
|
345
|
-
return this.appEvent({
|
|
346
|
-
type: index.W3mFrameConstants.APP_GET_SOCIAL_REDIRECT_URI,
|
|
347
|
-
payload
|
|
348
|
-
});
|
|
349
|
-
} catch (error) {
|
|
350
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error getting social redirect uri");
|
|
351
|
-
throw error;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
async updateEmail(payload) {
|
|
355
|
-
var _a;
|
|
356
|
-
try {
|
|
357
|
-
const response = await this.appEvent({
|
|
358
|
-
type: index.W3mFrameConstants.APP_UPDATE_EMAIL,
|
|
359
|
-
payload
|
|
360
|
-
});
|
|
361
|
-
this.setNewLastEmailLoginTime();
|
|
362
|
-
return response;
|
|
363
|
-
} catch (error) {
|
|
364
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error updating email");
|
|
365
|
-
throw error;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
async updateEmailPrimaryOtp(payload) {
|
|
369
|
-
var _a;
|
|
370
|
-
try {
|
|
371
|
-
return this.appEvent({
|
|
372
|
-
type: index.W3mFrameConstants.APP_UPDATE_EMAIL_PRIMARY_OTP,
|
|
373
|
-
payload
|
|
374
|
-
});
|
|
375
|
-
} catch (error) {
|
|
376
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error updating email primary otp");
|
|
377
|
-
throw error;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
async updateEmailSecondaryOtp(payload) {
|
|
381
|
-
var _a;
|
|
382
|
-
try {
|
|
383
|
-
const response = await this.appEvent({
|
|
384
|
-
type: index.W3mFrameConstants.APP_UPDATE_EMAIL_SECONDARY_OTP,
|
|
385
|
-
payload
|
|
386
|
-
});
|
|
387
|
-
this.setLoginSuccess(response.newEmail);
|
|
388
|
-
return response;
|
|
389
|
-
} catch (error) {
|
|
390
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error updating email secondary otp");
|
|
391
|
-
throw error;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
async syncTheme(payload) {
|
|
395
|
-
var _a;
|
|
396
|
-
try {
|
|
397
|
-
return this.appEvent({
|
|
398
|
-
type: index.W3mFrameConstants.APP_SYNC_THEME,
|
|
399
|
-
payload
|
|
400
|
-
});
|
|
401
|
-
} catch (error) {
|
|
402
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error syncing theme");
|
|
403
|
-
throw error;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
async syncDappData(payload) {
|
|
407
|
-
var _a;
|
|
408
|
-
try {
|
|
409
|
-
return this.appEvent({
|
|
410
|
-
type: index.W3mFrameConstants.APP_SYNC_DAPP_DATA,
|
|
411
|
-
payload
|
|
412
|
-
});
|
|
413
|
-
} catch (error) {
|
|
414
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error syncing dapp data");
|
|
415
|
-
throw error;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
async getSmartAccountEnabledNetworks() {
|
|
419
|
-
var _a;
|
|
420
|
-
try {
|
|
421
|
-
const response = await this.appEvent({
|
|
422
|
-
type: index.W3mFrameConstants.APP_GET_SMART_ACCOUNT_ENABLED_NETWORKS
|
|
423
|
-
});
|
|
424
|
-
this.persistSmartAccountEnabledNetworks(response.smartAccountEnabledNetworks);
|
|
425
|
-
return response;
|
|
426
|
-
} catch (error) {
|
|
427
|
-
this.persistSmartAccountEnabledNetworks([]);
|
|
428
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error getting smart account enabled networks");
|
|
429
|
-
throw error;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
async setPreferredAccount(type) {
|
|
433
|
-
var _a;
|
|
434
|
-
try {
|
|
435
|
-
return this.appEvent({
|
|
436
|
-
type: index.W3mFrameConstants.APP_SET_PREFERRED_ACCOUNT,
|
|
437
|
-
payload: { type }
|
|
438
|
-
});
|
|
439
|
-
} catch (error) {
|
|
440
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error setting preferred account");
|
|
441
|
-
throw error;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
async connect(payload) {
|
|
445
|
-
var _a;
|
|
446
|
-
try {
|
|
447
|
-
const chainId = (payload == null ? void 0 : payload.chainId) || this.getLastUsedChainId() || 1;
|
|
448
|
-
const response = await this.appEvent({
|
|
449
|
-
type: index.W3mFrameConstants.APP_GET_USER,
|
|
450
|
-
payload: { ...payload, chainId }
|
|
451
|
-
});
|
|
452
|
-
this.setLoginSuccess(response.email);
|
|
453
|
-
this.setLastUsedChainId(response.chainId);
|
|
454
|
-
return response;
|
|
455
|
-
} catch (error) {
|
|
456
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error connecting");
|
|
457
|
-
throw error;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
async getUser(payload) {
|
|
461
|
-
var _a;
|
|
462
|
-
try {
|
|
463
|
-
const chainId = (payload == null ? void 0 : payload.chainId) || this.getLastUsedChainId() || 1;
|
|
464
|
-
const response = await this.appEvent({
|
|
465
|
-
type: index.W3mFrameConstants.APP_GET_USER,
|
|
466
|
-
payload: { ...payload, chainId }
|
|
467
|
-
});
|
|
468
|
-
return response;
|
|
469
|
-
} catch (error) {
|
|
470
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error connecting");
|
|
471
|
-
throw error;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
async connectSocial(uri) {
|
|
475
|
-
var _a;
|
|
476
|
-
try {
|
|
477
|
-
this.w3mFrame.initFrame();
|
|
478
|
-
const response = await this.appEvent({
|
|
479
|
-
type: index.W3mFrameConstants.APP_CONNECT_SOCIAL,
|
|
480
|
-
payload: { uri }
|
|
481
|
-
});
|
|
482
|
-
if (response.userName) {
|
|
483
|
-
this.setSocialLoginSuccess(response.userName);
|
|
484
|
-
}
|
|
485
|
-
return response;
|
|
486
|
-
} catch (error) {
|
|
487
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error connecting social");
|
|
488
|
-
throw error;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
async getFarcasterUri() {
|
|
492
|
-
var _a;
|
|
493
|
-
try {
|
|
494
|
-
this.w3mFrame.initFrame();
|
|
495
|
-
const response = await this.appEvent({
|
|
496
|
-
type: index.W3mFrameConstants.APP_GET_FARCASTER_URI
|
|
497
|
-
});
|
|
498
|
-
return response;
|
|
499
|
-
} catch (error) {
|
|
500
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error getting farcaster uri");
|
|
501
|
-
throw error;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
async connectFarcaster() {
|
|
505
|
-
var _a;
|
|
506
|
-
try {
|
|
507
|
-
const response = await this.appEvent({
|
|
508
|
-
type: index.W3mFrameConstants.APP_CONNECT_FARCASTER
|
|
509
|
-
});
|
|
510
|
-
if (response.userName) {
|
|
511
|
-
this.setSocialLoginSuccess(response.userName);
|
|
512
|
-
}
|
|
513
|
-
return response;
|
|
514
|
-
} catch (error) {
|
|
515
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error connecting farcaster");
|
|
516
|
-
throw error;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
async switchNetwork(chainId) {
|
|
520
|
-
var _a;
|
|
521
|
-
try {
|
|
522
|
-
const response = await this.appEvent({
|
|
523
|
-
type: index.W3mFrameConstants.APP_SWITCH_NETWORK,
|
|
524
|
-
payload: { chainId }
|
|
525
|
-
});
|
|
526
|
-
this.setLastUsedChainId(response.chainId);
|
|
527
|
-
return response;
|
|
528
|
-
} catch (error) {
|
|
529
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error switching network");
|
|
530
|
-
throw error;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
async disconnect() {
|
|
534
|
-
var _a;
|
|
535
|
-
try {
|
|
536
|
-
const response = await this.appEvent({
|
|
537
|
-
type: index.W3mFrameConstants.APP_SIGN_OUT
|
|
538
|
-
});
|
|
539
|
-
this.deleteAuthLoginCache();
|
|
540
|
-
return response;
|
|
541
|
-
} catch (error) {
|
|
542
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error }, "Error disconnecting");
|
|
543
|
-
throw error;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
async request(req) {
|
|
547
|
-
var _a, _b, _c, _d;
|
|
548
|
-
try {
|
|
549
|
-
if (index.W3mFrameRpcConstants.GET_CHAIN_ID === req.method) {
|
|
550
|
-
return this.getLastUsedChainId();
|
|
551
|
-
}
|
|
552
|
-
(_a = this.rpcRequestHandler) == null ? void 0 : _a.call(this, req);
|
|
553
|
-
const response = await this.appEvent({
|
|
554
|
-
type: index.W3mFrameConstants.APP_RPC_REQUEST,
|
|
555
|
-
payload: req
|
|
556
|
-
});
|
|
557
|
-
(_b = this.rpcSuccessHandler) == null ? void 0 : _b.call(this, response, req);
|
|
558
|
-
return response;
|
|
559
|
-
} catch (error) {
|
|
560
|
-
(_c = this.rpcErrorHandler) == null ? void 0 : _c.call(this, error, req);
|
|
561
|
-
(_d = this.w3mLogger) == null ? void 0 : _d.logger.error({ error }, "Error requesting");
|
|
562
|
-
throw error;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
onRpcRequest(callback) {
|
|
566
|
-
this.rpcRequestHandler = callback;
|
|
567
|
-
}
|
|
568
|
-
onRpcSuccess(callback) {
|
|
569
|
-
this.rpcSuccessHandler = callback;
|
|
570
|
-
}
|
|
571
|
-
onRpcError(callback) {
|
|
572
|
-
this.rpcErrorHandler = callback;
|
|
573
|
-
}
|
|
574
|
-
onIsConnected(callback) {
|
|
575
|
-
this.w3mFrame.events.onFrameEvent((event) => {
|
|
576
|
-
if (event.type === index.W3mFrameConstants.FRAME_IS_CONNECTED_SUCCESS && event.payload.isConnected) {
|
|
577
|
-
callback();
|
|
578
|
-
}
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
|
-
onNotConnected(callback) {
|
|
582
|
-
this.w3mFrame.events.onFrameEvent((event) => {
|
|
583
|
-
if (event.type === index.W3mFrameConstants.FRAME_IS_CONNECTED_ERROR) {
|
|
584
|
-
callback();
|
|
585
|
-
}
|
|
586
|
-
if (event.type === index.W3mFrameConstants.FRAME_IS_CONNECTED_SUCCESS && !event.payload.isConnected) {
|
|
587
|
-
callback();
|
|
588
|
-
}
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
onConnect(callback) {
|
|
592
|
-
this.w3mFrame.events.onFrameEvent((event) => {
|
|
593
|
-
if (event.type === index.W3mFrameConstants.FRAME_GET_USER_SUCCESS) {
|
|
594
|
-
callback(event.payload);
|
|
595
|
-
}
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
onSocialConnected(callback) {
|
|
599
|
-
this.w3mFrame.events.onFrameEvent((event) => {
|
|
600
|
-
if (event.type === index.W3mFrameConstants.FRAME_CONNECT_SOCIAL_SUCCESS) {
|
|
601
|
-
callback(event.payload);
|
|
602
|
-
}
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
async getCapabilities() {
|
|
606
|
-
try {
|
|
607
|
-
const capabilities = await this.request({
|
|
608
|
-
method: "wallet_getCapabilities"
|
|
609
|
-
});
|
|
610
|
-
return capabilities || {};
|
|
611
|
-
} catch {
|
|
612
|
-
return {};
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
onSetPreferredAccount(callback) {
|
|
616
|
-
this.w3mFrame.events.onFrameEvent((event) => {
|
|
617
|
-
if (event.type === index.W3mFrameConstants.FRAME_SET_PREFERRED_ACCOUNT_SUCCESS) {
|
|
618
|
-
callback(event.payload);
|
|
619
|
-
} else if (event.type === index.W3mFrameConstants.FRAME_SET_PREFERRED_ACCOUNT_ERROR) {
|
|
620
|
-
callback({ type: index.W3mFrameRpcConstants.ACCOUNT_TYPES.EOA });
|
|
621
|
-
}
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
onGetSmartAccountEnabledNetworks(callback) {
|
|
625
|
-
this.w3mFrame.events.onFrameEvent((event) => {
|
|
626
|
-
if (event.type === index.W3mFrameConstants.FRAME_GET_SMART_ACCOUNT_ENABLED_NETWORKS_SUCCESS) {
|
|
627
|
-
callback(event.payload.smartAccountEnabledNetworks);
|
|
628
|
-
} else if (event.type === index.W3mFrameConstants.FRAME_GET_SMART_ACCOUNT_ENABLED_NETWORKS_ERROR) {
|
|
629
|
-
callback([]);
|
|
630
|
-
}
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
getAvailableChainIds() {
|
|
634
|
-
return Object.keys(this.w3mFrame.networks);
|
|
635
|
-
}
|
|
636
|
-
rejectRpcRequests() {
|
|
637
|
-
var _a;
|
|
638
|
-
try {
|
|
639
|
-
this.openRpcRequests.forEach(({ abortController, method }) => {
|
|
640
|
-
if (!index.W3mFrameRpcConstants.SAFE_RPC_METHODS.includes(method)) {
|
|
641
|
-
abortController.abort();
|
|
642
|
-
}
|
|
643
|
-
});
|
|
644
|
-
this.openRpcRequests = [];
|
|
645
|
-
} catch (e) {
|
|
646
|
-
(_a = this.w3mLogger) == null ? void 0 : _a.logger.error({ error: e }, "Error aborting RPC request");
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
async appEvent(event) {
|
|
650
|
-
await this.w3mFrame.frameLoadPromise;
|
|
651
|
-
let timer = void 0;
|
|
652
|
-
function replaceEventType(type2) {
|
|
653
|
-
return type2.replace("@w3m-app/", "");
|
|
654
|
-
}
|
|
655
|
-
const abortController = new AbortController();
|
|
656
|
-
const type = replaceEventType(event.type);
|
|
657
|
-
const shouldCheckForTimeout = [
|
|
658
|
-
index.W3mFrameConstants.APP_CONNECT_EMAIL,
|
|
659
|
-
index.W3mFrameConstants.APP_CONNECT_DEVICE,
|
|
660
|
-
index.W3mFrameConstants.APP_CONNECT_OTP,
|
|
661
|
-
index.W3mFrameConstants.APP_CONNECT_SOCIAL,
|
|
662
|
-
index.W3mFrameConstants.APP_GET_SOCIAL_REDIRECT_URI
|
|
663
|
-
].map(replaceEventType).includes(type);
|
|
664
|
-
if (shouldCheckForTimeout) {
|
|
665
|
-
timer = setTimeout(() => {
|
|
666
|
-
var _a;
|
|
667
|
-
(_a = this.onTimeout) == null ? void 0 : _a.call(this);
|
|
668
|
-
abortController.abort();
|
|
669
|
-
}, 3e4);
|
|
670
|
-
}
|
|
671
|
-
return new Promise((resolve, reject) => {
|
|
672
|
-
var _a, _b, _c;
|
|
673
|
-
const id = Math.random().toString(36).substring(7);
|
|
674
|
-
(_c = (_a = this.w3mLogger) == null ? void 0 : (_b = _a.logger).info) == null ? void 0 : _c.call(_b, { event, id }, "Sending app event");
|
|
675
|
-
this.w3mFrame.events.postAppEvent({ ...event, id });
|
|
676
|
-
if (type === "RPC_REQUEST") {
|
|
677
|
-
const rpcEvent = event;
|
|
678
|
-
this.openRpcRequests = [...this.openRpcRequests, { ...rpcEvent.payload, abortController }];
|
|
679
|
-
}
|
|
680
|
-
abortController.signal.addEventListener("abort", () => {
|
|
681
|
-
if (type === "RPC_REQUEST") {
|
|
682
|
-
reject(new Error("Request was aborted"));
|
|
683
|
-
} else if (type !== "GET_FARCASTER_URI") {
|
|
684
|
-
reject(new Error("Something went wrong"));
|
|
685
|
-
}
|
|
686
|
-
});
|
|
687
|
-
function handler(framEvent, logger) {
|
|
688
|
-
var _a2, _b2, _c2;
|
|
689
|
-
if (framEvent.id !== id) {
|
|
690
|
-
return;
|
|
691
|
-
}
|
|
692
|
-
(_b2 = logger == null ? void 0 : (_a2 = logger.logger).info) == null ? void 0 : _b2.call(_a2, { framEvent, id }, "Received frame response");
|
|
693
|
-
if (framEvent.type === `@w3m-frame/${type}_SUCCESS`) {
|
|
694
|
-
if (timer) {
|
|
695
|
-
clearTimeout(timer);
|
|
696
|
-
}
|
|
697
|
-
if ("payload" in framEvent) {
|
|
698
|
-
resolve(framEvent.payload);
|
|
699
|
-
}
|
|
700
|
-
resolve(void 0);
|
|
701
|
-
} else if (framEvent.type === `@w3m-frame/${type}_ERROR`) {
|
|
702
|
-
if (timer) {
|
|
703
|
-
clearTimeout(timer);
|
|
704
|
-
}
|
|
705
|
-
if ("payload" in framEvent) {
|
|
706
|
-
reject(new Error(((_c2 = framEvent.payload) == null ? void 0 : _c2.message) || "An error occurred"));
|
|
707
|
-
}
|
|
708
|
-
reject(new Error("An error occurred"));
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
this.w3mFrame.events.registerFrameEventHandler(id, (frameEvent) => handler(frameEvent, this.w3mLogger), abortController.signal);
|
|
712
|
-
});
|
|
713
|
-
}
|
|
714
|
-
setNewLastEmailLoginTime() {
|
|
715
|
-
index.W3mFrameStorage.set(index.W3mFrameConstants.LAST_EMAIL_LOGIN_TIME, Date.now().toString());
|
|
716
|
-
}
|
|
717
|
-
setSocialLoginSuccess(username) {
|
|
718
|
-
index.W3mFrameStorage.set(index.W3mFrameConstants.SOCIAL_USERNAME, username);
|
|
719
|
-
}
|
|
720
|
-
setLoginSuccess(email) {
|
|
721
|
-
if (email) {
|
|
722
|
-
index.W3mFrameStorage.set(index.W3mFrameConstants.EMAIL, email);
|
|
723
|
-
}
|
|
724
|
-
index.W3mFrameStorage.set(index.W3mFrameConstants.EMAIL_LOGIN_USED_KEY, "true");
|
|
725
|
-
index.W3mFrameStorage.delete(index.W3mFrameConstants.LAST_EMAIL_LOGIN_TIME);
|
|
726
|
-
}
|
|
727
|
-
deleteAuthLoginCache() {
|
|
728
|
-
index.W3mFrameStorage.delete(index.W3mFrameConstants.EMAIL_LOGIN_USED_KEY);
|
|
729
|
-
index.W3mFrameStorage.delete(index.W3mFrameConstants.EMAIL);
|
|
730
|
-
index.W3mFrameStorage.delete(index.W3mFrameConstants.LAST_USED_CHAIN_KEY);
|
|
731
|
-
index.W3mFrameStorage.delete(index.W3mFrameConstants.SOCIAL_USERNAME);
|
|
732
|
-
}
|
|
733
|
-
setLastUsedChainId(chainId) {
|
|
734
|
-
if (chainId) {
|
|
735
|
-
index.W3mFrameStorage.set(index.W3mFrameConstants.LAST_USED_CHAIN_KEY, String(chainId));
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
getLastUsedChainId() {
|
|
739
|
-
const chainId = index.W3mFrameStorage.get(index.W3mFrameConstants.LAST_USED_CHAIN_KEY) ?? void 0;
|
|
740
|
-
const numberChainId = Number(chainId);
|
|
741
|
-
return isNaN(numberChainId) ? chainId : numberChainId;
|
|
742
|
-
}
|
|
743
|
-
persistSmartAccountEnabledNetworks(networks) {
|
|
744
|
-
index.W3mFrameStorage.set(index.W3mFrameConstants.SMART_ACCOUNT_ENABLED_NETWORKS, networks.join(","));
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
const PresetsUtil = {
|
|
748
|
-
NetworkImageIds: {
|
|
749
|
-
1: "ba0ba0cd-17c6-4806-ad93-f9d174f17900",
|
|
750
|
-
42161: "3bff954d-5cb0-47a0-9a23-d20192e74600",
|
|
751
|
-
43114: "30c46e53-e989-45fb-4549-be3bd4eb3b00",
|
|
752
|
-
56: "93564157-2e8e-4ce7-81df-b264dbee9b00",
|
|
753
|
-
250: "06b26297-fe0c-4733-5d6b-ffa5498aac00",
|
|
754
|
-
10: "ab9c186a-c52f-464b-2906-ca59d760a400",
|
|
755
|
-
137: "41d04d42-da3b-4453-8506-668cc0727900",
|
|
756
|
-
5e3: "e86fae9b-b770-4eea-e520-150e12c81100",
|
|
757
|
-
295: "6a97d510-cac8-4e58-c7ce-e8681b044c00",
|
|
758
|
-
11155111: "e909ea0a-f92a-4512-c8fc-748044ea6800",
|
|
759
|
-
84532: "a18a7ecd-e307-4360-4746-283182228e00",
|
|
760
|
-
1301: "4eeea7ef-0014-4649-5d1d-07271a80f600",
|
|
761
|
-
130: "2257980a-3463-48c6-cbac-a42d2a956e00",
|
|
762
|
-
10143: "0a728e83-bacb-46db-7844-948f05434900",
|
|
763
|
-
100: "02b53f6a-e3d4-479e-1cb4-21178987d100",
|
|
764
|
-
9001: "f926ff41-260d-4028-635e-91913fc28e00",
|
|
765
|
-
324: "b310f07f-4ef7-49f3-7073-2a0a39685800",
|
|
766
|
-
314: "5a73b3dd-af74-424e-cae0-0de859ee9400",
|
|
767
|
-
4689: "34e68754-e536-40da-c153-6ef2e7188a00",
|
|
768
|
-
1088: "3897a66d-40b9-4833-162f-a2c90531c900",
|
|
769
|
-
1284: "161038da-44ae-4ec7-1208-0ea569454b00",
|
|
770
|
-
1285: "f1d73bb6-5450-4e18-38f7-fb6484264a00",
|
|
771
|
-
7777777: "845c60df-d429-4991-e687-91ae45791600",
|
|
772
|
-
42220: "ab781bbc-ccc6-418d-d32d-789b15da1f00",
|
|
773
|
-
8453: "7289c336-3981-4081-c5f4-efc26ac64a00",
|
|
774
|
-
1313161554: "3ff73439-a619-4894-9262-4470c773a100",
|
|
775
|
-
2020: "b8101fc0-9c19-4b6f-ec65-f6dfff106e00",
|
|
776
|
-
2021: "b8101fc0-9c19-4b6f-ec65-f6dfff106e00",
|
|
777
|
-
"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp": "a1b58899-f671-4276-6a5e-56ca5bd59700",
|
|
778
|
-
"4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z": "a1b58899-f671-4276-6a5e-56ca5bd59700",
|
|
779
|
-
EtWTRABZaYq6iMfeYKouRu166VU2xqa1: "a1b58899-f671-4276-6a5e-56ca5bd59700",
|
|
780
|
-
"000000000019d6689c085ae165831e93": "21c895fa-e105-4829-9434-378bb54fa600",
|
|
781
|
-
"000000000933ea01ad0ee984209779ba": "220bcb01-ba47-41d3-fe5b-e29bbc4a4b00"
|
|
782
|
-
},
|
|
783
|
-
ConnectorImageIds: {
|
|
784
|
-
[index.ConstantsUtil.CONNECTOR_ID.COINBASE]: "0c2840c3-5b04-4c44-9661-fbd4b49e1800",
|
|
785
|
-
[index.ConstantsUtil.CONNECTOR_ID.COINBASE_SDK]: "0c2840c3-5b04-4c44-9661-fbd4b49e1800",
|
|
786
|
-
[index.ConstantsUtil.CONNECTOR_ID.SAFE]: "461db637-8616-43ce-035a-d89b8a1d5800",
|
|
787
|
-
[index.ConstantsUtil.CONNECTOR_ID.LEDGER]: "54a1aa77-d202-4f8d-0fb2-5d2bb6db0300",
|
|
788
|
-
[index.ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT]: "ef1a1fcf-7fe8-4d69-bd6d-fda1345b4400",
|
|
789
|
-
[index.ConstantsUtil.CONNECTOR_ID.INJECTED]: "07ba87ed-43aa-4adf-4540-9e6a2b9cae00"
|
|
790
|
-
},
|
|
791
|
-
ConnectorNamesMap: {
|
|
792
|
-
[index.ConstantsUtil.CONNECTOR_ID.INJECTED]: "Browser Wallet",
|
|
793
|
-
[index.ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT]: "WalletConnect",
|
|
794
|
-
[index.ConstantsUtil.CONNECTOR_ID.COINBASE]: "Coinbase",
|
|
795
|
-
[index.ConstantsUtil.CONNECTOR_ID.COINBASE_SDK]: "Coinbase",
|
|
796
|
-
[index.ConstantsUtil.CONNECTOR_ID.LEDGER]: "Ledger",
|
|
797
|
-
[index.ConstantsUtil.CONNECTOR_ID.SAFE]: "Safe"
|
|
798
|
-
}
|
|
799
|
-
};
|
|
800
|
-
const HelpersUtil = {
|
|
801
|
-
getCaipTokens(tokens) {
|
|
802
|
-
if (!tokens) {
|
|
803
|
-
return void 0;
|
|
804
|
-
}
|
|
805
|
-
const caipTokens = {};
|
|
806
|
-
Object.entries(tokens).forEach(([id, token]) => {
|
|
807
|
-
caipTokens[`${index.ConstantsUtil$1.EIP155}:${id}`] = token;
|
|
808
|
-
});
|
|
809
|
-
return caipTokens;
|
|
810
|
-
},
|
|
811
|
-
isLowerCaseMatch(str1, str2) {
|
|
812
|
-
return (str1 == null ? void 0 : str1.toLowerCase()) === (str2 == null ? void 0 : str2.toLowerCase());
|
|
813
|
-
}
|
|
814
|
-
};
|
|
815
|
-
const ErrorUtil = {
|
|
816
|
-
UniversalProviderErrors: {
|
|
817
|
-
UNAUTHORIZED_DOMAIN_NOT_ALLOWED: {
|
|
818
|
-
message: "Unauthorized: origin not allowed",
|
|
819
|
-
alertErrorKey: "INVALID_APP_CONFIGURATION"
|
|
820
|
-
},
|
|
821
|
-
JWT_VALIDATION_ERROR: {
|
|
822
|
-
message: "JWT validation error: JWT Token is not yet valid",
|
|
823
|
-
alertErrorKey: "JWT_TOKEN_NOT_VALID"
|
|
824
|
-
},
|
|
825
|
-
INVALID_KEY: {
|
|
826
|
-
message: "Unauthorized: invalid key",
|
|
827
|
-
alertErrorKey: "INVALID_PROJECT_ID"
|
|
828
|
-
}
|
|
829
|
-
},
|
|
830
|
-
ALERT_ERRORS: {
|
|
831
|
-
SWITCH_NETWORK_NOT_FOUND: {
|
|
832
|
-
shortMessage: "Network Not Found",
|
|
833
|
-
longMessage: "Network not found - please make sure it is included in 'networks' array in createAppKit function"
|
|
834
|
-
},
|
|
835
|
-
INVALID_APP_CONFIGURATION: {
|
|
836
|
-
shortMessage: "Invalid App Configuration",
|
|
837
|
-
longMessage: () => `Origin ${isSafe() ? window.origin : "unknown"} not found on Allowlist - update configuration on cloud.reown.com`
|
|
838
|
-
},
|
|
839
|
-
SOCIALS_TIMEOUT: {
|
|
840
|
-
shortMessage: "Invalid App Configuration",
|
|
841
|
-
longMessage: () => "There was an issue loading the embedded wallet. Please verify that your domain is allowed at cloud.reown.com"
|
|
842
|
-
},
|
|
843
|
-
JWT_TOKEN_NOT_VALID: {
|
|
844
|
-
shortMessage: "Session Expired",
|
|
845
|
-
longMessage: "Invalid session found on UniversalProvider - please check your time settings and connect again"
|
|
846
|
-
},
|
|
847
|
-
INVALID_PROJECT_ID: {
|
|
848
|
-
shortMessage: "Invalid App Configuration",
|
|
849
|
-
longMessage: "Invalid Project ID - update configuration"
|
|
850
|
-
},
|
|
851
|
-
PROJECT_ID_NOT_CONFIGURED: {
|
|
852
|
-
shortMessage: "Project ID Not Configured",
|
|
853
|
-
longMessage: "Project ID Not Configured - update configuration on cloud.reown.com"
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
};
|
|
857
|
-
function isSafe() {
|
|
858
|
-
return typeof window !== "undefined";
|
|
859
|
-
}
|
|
860
|
-
const LoggerUtil = {
|
|
861
|
-
createLogger(onError, level = "error") {
|
|
862
|
-
const loggerOptions = index.k({
|
|
863
|
-
level
|
|
864
|
-
});
|
|
865
|
-
const { logger } = index.A({
|
|
866
|
-
opts: loggerOptions
|
|
867
|
-
});
|
|
868
|
-
logger.error = (...args) => {
|
|
869
|
-
for (const arg of args) {
|
|
870
|
-
if (arg instanceof Error) {
|
|
871
|
-
onError(arg, ...args);
|
|
872
|
-
return;
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
onError(void 0, ...args);
|
|
876
|
-
};
|
|
877
|
-
return logger;
|
|
878
|
-
}
|
|
879
|
-
};
|
|
880
|
-
const RPC_URL_HOST = "rpc.walletconnect.org";
|
|
881
|
-
function getBlockchainApiRpcUrl(caipNetworkId, projectId) {
|
|
882
|
-
const url = new URL("https://rpc.walletconnect.org/v1/");
|
|
883
|
-
url.searchParams.set("chainId", caipNetworkId);
|
|
884
|
-
url.searchParams.set("projectId", projectId);
|
|
885
|
-
return url.toString();
|
|
886
|
-
}
|
|
887
|
-
const WC_HTTP_RPC_SUPPORTED_CHAINS = [
|
|
888
|
-
"near:mainnet",
|
|
889
|
-
"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
890
|
-
"eip155:1101",
|
|
891
|
-
"eip155:56",
|
|
892
|
-
"eip155:42161",
|
|
893
|
-
"eip155:7777777",
|
|
894
|
-
"eip155:59144",
|
|
895
|
-
"eip155:324",
|
|
896
|
-
"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
|
|
897
|
-
"eip155:5000",
|
|
898
|
-
"solana:4sgjmw1sunhzsxgspuhpqldx6wiyjntz",
|
|
899
|
-
"eip155:80084",
|
|
900
|
-
"eip155:5003",
|
|
901
|
-
"eip155:100",
|
|
902
|
-
"eip155:8453",
|
|
903
|
-
"eip155:42220",
|
|
904
|
-
"eip155:1313161555",
|
|
905
|
-
"eip155:17000",
|
|
906
|
-
"eip155:1",
|
|
907
|
-
"eip155:300",
|
|
908
|
-
"eip155:1313161554",
|
|
909
|
-
"eip155:1329",
|
|
910
|
-
"eip155:84532",
|
|
911
|
-
"eip155:421614",
|
|
912
|
-
"eip155:11155111",
|
|
913
|
-
"eip155:8217",
|
|
914
|
-
"eip155:43114",
|
|
915
|
-
"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z",
|
|
916
|
-
"eip155:999999999",
|
|
917
|
-
"eip155:11155420",
|
|
918
|
-
"eip155:80002",
|
|
919
|
-
"eip155:97",
|
|
920
|
-
"eip155:43113",
|
|
921
|
-
"eip155:137",
|
|
922
|
-
"eip155:10",
|
|
923
|
-
"eip155:1301",
|
|
924
|
-
"bip122:000000000019d6689c085ae165831e93",
|
|
925
|
-
"bip122:000000000933ea01ad0ee984209779ba"
|
|
926
|
-
];
|
|
927
|
-
const CaipNetworksUtil = {
|
|
928
|
-
extendRpcUrlWithProjectId(rpcUrl, projectId) {
|
|
929
|
-
let isReownUrl = false;
|
|
930
|
-
try {
|
|
931
|
-
const url = new URL(rpcUrl);
|
|
932
|
-
isReownUrl = url.host === RPC_URL_HOST;
|
|
933
|
-
} catch (e) {
|
|
934
|
-
isReownUrl = false;
|
|
935
|
-
}
|
|
936
|
-
if (isReownUrl) {
|
|
937
|
-
const url = new URL(rpcUrl);
|
|
938
|
-
if (!url.searchParams.has("projectId")) {
|
|
939
|
-
url.searchParams.set("projectId", projectId);
|
|
940
|
-
}
|
|
941
|
-
return url.toString();
|
|
942
|
-
}
|
|
943
|
-
return rpcUrl;
|
|
944
|
-
},
|
|
945
|
-
isCaipNetwork(network) {
|
|
946
|
-
return "chainNamespace" in network && "caipNetworkId" in network;
|
|
947
|
-
},
|
|
948
|
-
getChainNamespace(network) {
|
|
949
|
-
if (this.isCaipNetwork(network)) {
|
|
950
|
-
return network.chainNamespace;
|
|
951
|
-
}
|
|
952
|
-
return index.ConstantsUtil.CHAIN.EVM;
|
|
953
|
-
},
|
|
954
|
-
getCaipNetworkId(network) {
|
|
955
|
-
if (this.isCaipNetwork(network)) {
|
|
956
|
-
return network.caipNetworkId;
|
|
957
|
-
}
|
|
958
|
-
return `${index.ConstantsUtil.CHAIN.EVM}:${network.id}`;
|
|
959
|
-
},
|
|
960
|
-
getDefaultRpcUrl(caipNetwork, caipNetworkId, projectId) {
|
|
961
|
-
var _a, _b, _c;
|
|
962
|
-
const defaultRpcUrl = (_c = (_b = (_a = caipNetwork.rpcUrls) == null ? void 0 : _a.default) == null ? void 0 : _b.http) == null ? void 0 : _c[0];
|
|
963
|
-
if (WC_HTTP_RPC_SUPPORTED_CHAINS.includes(caipNetworkId)) {
|
|
964
|
-
return getBlockchainApiRpcUrl(caipNetworkId, projectId);
|
|
965
|
-
}
|
|
966
|
-
return defaultRpcUrl || "";
|
|
967
|
-
},
|
|
968
|
-
extendCaipNetwork(caipNetwork, { customNetworkImageUrls, projectId, customRpc }) {
|
|
969
|
-
var _a, _b, _c, _d;
|
|
970
|
-
const caipNetworkId = this.getCaipNetworkId(caipNetwork);
|
|
971
|
-
const chainNamespace = this.getChainNamespace(caipNetwork);
|
|
972
|
-
const chainDefaultUrl = (_c = (_b = (_a = caipNetwork == null ? void 0 : caipNetwork.rpcUrls) == null ? void 0 : _a["chainDefault"]) == null ? void 0 : _b.http) == null ? void 0 : _c[0];
|
|
973
|
-
let rpcUrl = "";
|
|
974
|
-
if (customRpc) {
|
|
975
|
-
rpcUrl = ((_d = caipNetwork.rpcUrls.default.http) == null ? void 0 : _d[0]) || "";
|
|
976
|
-
} else {
|
|
977
|
-
rpcUrl = this.getDefaultRpcUrl(caipNetwork, caipNetworkId, projectId);
|
|
978
|
-
}
|
|
979
|
-
return {
|
|
980
|
-
...caipNetwork,
|
|
981
|
-
chainNamespace,
|
|
982
|
-
caipNetworkId,
|
|
983
|
-
assets: {
|
|
984
|
-
imageId: PresetsUtil.NetworkImageIds[caipNetwork.id],
|
|
985
|
-
imageUrl: customNetworkImageUrls == null ? void 0 : customNetworkImageUrls[caipNetwork.id]
|
|
986
|
-
},
|
|
987
|
-
rpcUrls: {
|
|
988
|
-
...caipNetwork.rpcUrls,
|
|
989
|
-
default: {
|
|
990
|
-
http: [rpcUrl]
|
|
991
|
-
},
|
|
992
|
-
chainDefault: {
|
|
993
|
-
http: [chainDefaultUrl || caipNetwork.rpcUrls.default.http[0] || ""]
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
};
|
|
997
|
-
},
|
|
998
|
-
extendCaipNetworks(caipNetworks, { customNetworkImageUrls, projectId, customRpcChainIds }) {
|
|
999
|
-
return caipNetworks.map((caipNetwork) => CaipNetworksUtil.extendCaipNetwork(caipNetwork, {
|
|
1000
|
-
customNetworkImageUrls,
|
|
1001
|
-
projectId,
|
|
1002
|
-
customRpc: customRpcChainIds == null ? void 0 : customRpcChainIds.includes(caipNetwork.id)
|
|
1003
|
-
}));
|
|
1004
|
-
},
|
|
1005
|
-
getViemTransport(caipNetwork) {
|
|
1006
|
-
var _a;
|
|
1007
|
-
const defaultRpcUrl = (_a = caipNetwork.rpcUrls.default.http) == null ? void 0 : _a[0];
|
|
1008
|
-
if (!WC_HTTP_RPC_SUPPORTED_CHAINS.includes(caipNetwork.caipNetworkId)) {
|
|
1009
|
-
return viem.http(defaultRpcUrl);
|
|
1010
|
-
}
|
|
1011
|
-
return viem.fallback([
|
|
1012
|
-
viem.http(defaultRpcUrl, {
|
|
1013
|
-
fetchOptions: {
|
|
1014
|
-
headers: {
|
|
1015
|
-
"Content-Type": "text/plain"
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
}),
|
|
1019
|
-
viem.http(defaultRpcUrl)
|
|
1020
|
-
]);
|
|
1021
|
-
}
|
|
1022
|
-
};
|
|
1023
|
-
class W3mFrameProviderSingleton {
|
|
1024
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function -- This is a singleton
|
|
1025
|
-
constructor() {
|
|
1026
|
-
}
|
|
1027
|
-
static getInstance({ projectId, chainId, enableLogger, onTimeout }) {
|
|
1028
|
-
if (!W3mFrameProviderSingleton.instance) {
|
|
1029
|
-
W3mFrameProviderSingleton.instance = new W3mFrameProvider({
|
|
1030
|
-
projectId,
|
|
1031
|
-
chainId,
|
|
1032
|
-
enableLogger,
|
|
1033
|
-
onTimeout
|
|
1034
|
-
});
|
|
1035
|
-
}
|
|
1036
|
-
return W3mFrameProviderSingleton.instance;
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
const WcConstantsUtil = {
|
|
1040
|
-
ERROR_CODE_UNRECOGNIZED_CHAIN_ID: 4902,
|
|
1041
|
-
ERROR_CODE_DEFAULT: 5e3,
|
|
1042
|
-
ERROR_INVALID_CHAIN_ID: 32603
|
|
1043
|
-
};
|
|
1044
|
-
const WcHelpersUtil = {
|
|
1045
|
-
getMethodsByChainNamespace(chainNamespace) {
|
|
1046
|
-
switch (chainNamespace) {
|
|
1047
|
-
case "solana":
|
|
1048
|
-
return [
|
|
1049
|
-
"solana_signMessage",
|
|
1050
|
-
"solana_signTransaction",
|
|
1051
|
-
"solana_requestAccounts",
|
|
1052
|
-
"solana_getAccounts",
|
|
1053
|
-
"solana_signAllTransactions",
|
|
1054
|
-
"solana_signAndSendTransaction"
|
|
1055
|
-
];
|
|
1056
|
-
case "eip155":
|
|
1057
|
-
return [
|
|
1058
|
-
"eth_accounts",
|
|
1059
|
-
"eth_requestAccounts",
|
|
1060
|
-
"eth_sendRawTransaction",
|
|
1061
|
-
"eth_sign",
|
|
1062
|
-
"eth_signTransaction",
|
|
1063
|
-
"eth_signTypedData",
|
|
1064
|
-
"eth_signTypedData_v3",
|
|
1065
|
-
"eth_signTypedData_v4",
|
|
1066
|
-
"eth_sendTransaction",
|
|
1067
|
-
"personal_sign",
|
|
1068
|
-
"wallet_switchEthereumChain",
|
|
1069
|
-
"wallet_addEthereumChain",
|
|
1070
|
-
"wallet_getPermissions",
|
|
1071
|
-
"wallet_requestPermissions",
|
|
1072
|
-
"wallet_registerOnboarding",
|
|
1073
|
-
"wallet_watchAsset",
|
|
1074
|
-
"wallet_scanQRCode",
|
|
1075
|
-
// EIP-5792
|
|
1076
|
-
"wallet_getCallsStatus",
|
|
1077
|
-
"wallet_showCallsStatus",
|
|
1078
|
-
"wallet_sendCalls",
|
|
1079
|
-
"wallet_getCapabilities",
|
|
1080
|
-
// EIP-7715
|
|
1081
|
-
"wallet_grantPermissions",
|
|
1082
|
-
"wallet_revokePermissions",
|
|
1083
|
-
//EIP-7811
|
|
1084
|
-
"wallet_getAssets"
|
|
1085
|
-
];
|
|
1086
|
-
case "bip122":
|
|
1087
|
-
return ["sendTransfer", "signMessage", "signPsbt", "getAccountAddresses"];
|
|
1088
|
-
default:
|
|
1089
|
-
return [];
|
|
1090
|
-
}
|
|
1091
|
-
},
|
|
1092
|
-
createNamespaces(caipNetworks) {
|
|
1093
|
-
return caipNetworks.reduce((acc, chain) => {
|
|
1094
|
-
const { id, chainNamespace, rpcUrls } = chain;
|
|
1095
|
-
const rpcUrl = rpcUrls.default.http[0];
|
|
1096
|
-
const methods = this.getMethodsByChainNamespace(chainNamespace);
|
|
1097
|
-
if (!acc[chainNamespace]) {
|
|
1098
|
-
acc[chainNamespace] = {
|
|
1099
|
-
methods,
|
|
1100
|
-
events: ["accountsChanged", "chainChanged"],
|
|
1101
|
-
chains: [],
|
|
1102
|
-
rpcMap: {}
|
|
1103
|
-
};
|
|
1104
|
-
}
|
|
1105
|
-
const caipNetworkId = `${chainNamespace}:${id}`;
|
|
1106
|
-
const namespace = acc[chainNamespace];
|
|
1107
|
-
namespace.chains.push(caipNetworkId);
|
|
1108
|
-
switch (caipNetworkId) {
|
|
1109
|
-
case index.solana.caipNetworkId:
|
|
1110
|
-
namespace.chains.push(index.solana.deprecatedCaipNetworkId);
|
|
1111
|
-
break;
|
|
1112
|
-
case index.solanaDevnet.caipNetworkId:
|
|
1113
|
-
namespace.chains.push(index.solanaDevnet.deprecatedCaipNetworkId);
|
|
1114
|
-
break;
|
|
1115
|
-
}
|
|
1116
|
-
if ((namespace == null ? void 0 : namespace.rpcMap) && rpcUrl) {
|
|
1117
|
-
namespace.rpcMap[id] = rpcUrl;
|
|
1118
|
-
}
|
|
1119
|
-
return acc;
|
|
1120
|
-
}, {});
|
|
1121
|
-
},
|
|
1122
|
-
resolveReownName: async (name) => {
|
|
1123
|
-
var _a;
|
|
1124
|
-
const wcNameAddress = await index.EnsController.resolveName(name);
|
|
1125
|
-
const networkNameAddresses = Object.values(wcNameAddress == null ? void 0 : wcNameAddress.addresses) || [];
|
|
1126
|
-
return ((_a = networkNameAddresses[0]) == null ? void 0 : _a.address) || false;
|
|
1127
|
-
},
|
|
1128
|
-
getChainsFromNamespaces(namespaces = {}) {
|
|
1129
|
-
return Object.values(namespaces).flatMap((namespace) => {
|
|
1130
|
-
const chains = namespace.chains || [];
|
|
1131
|
-
const accountsChains = namespace.accounts.map((account) => {
|
|
1132
|
-
const [chainNamespace, chainId] = account.split(":");
|
|
1133
|
-
return `${chainNamespace}:${chainId}`;
|
|
1134
|
-
});
|
|
1135
|
-
return Array.from(/* @__PURE__ */ new Set([...chains, ...accountsChains]));
|
|
1136
|
-
});
|
|
1137
|
-
},
|
|
1138
|
-
isSessionEventData(data) {
|
|
1139
|
-
return typeof data === "object" && data !== null && "id" in data && "topic" in data && "params" in data && typeof data.params === "object" && data.params !== null && "chainId" in data.params && "event" in data.params && typeof data.params.event === "object" && data.params.event !== null;
|
|
1140
|
-
}
|
|
1141
|
-
};
|
|
1142
|
-
class WalletConnectConnector {
|
|
1143
|
-
constructor({ provider, caipNetworks, namespace }) {
|
|
1144
|
-
this.id = index.ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT;
|
|
1145
|
-
this.name = PresetsUtil.ConnectorNamesMap[index.ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT];
|
|
1146
|
-
this.type = "WALLET_CONNECT";
|
|
1147
|
-
this.imageId = PresetsUtil.ConnectorImageIds[index.ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT];
|
|
1148
|
-
this.caipNetworks = caipNetworks;
|
|
1149
|
-
this.provider = provider;
|
|
1150
|
-
this.chain = namespace;
|
|
1151
|
-
}
|
|
1152
|
-
get chains() {
|
|
1153
|
-
return this.caipNetworks;
|
|
1154
|
-
}
|
|
1155
|
-
async connectWalletConnect() {
|
|
1156
|
-
const isAuthenticated = await this.authenticate();
|
|
1157
|
-
if (!isAuthenticated) {
|
|
1158
|
-
await this.provider.connect({
|
|
1159
|
-
optionalNamespaces: WcHelpersUtil.createNamespaces(this.caipNetworks)
|
|
1160
|
-
});
|
|
1161
|
-
}
|
|
1162
|
-
return {
|
|
1163
|
-
clientId: await this.provider.client.core.crypto.getClientId(),
|
|
1164
|
-
session: this.provider.session
|
|
1165
|
-
};
|
|
1166
|
-
}
|
|
1167
|
-
async disconnect() {
|
|
1168
|
-
await this.provider.disconnect();
|
|
1169
|
-
}
|
|
1170
|
-
async authenticate() {
|
|
1171
|
-
const chains = this.chains.map((network) => network.caipNetworkId);
|
|
1172
|
-
return index.SIWXUtil.universalProviderAuthenticate({
|
|
1173
|
-
universalProvider: this.provider,
|
|
1174
|
-
chains,
|
|
1175
|
-
methods: OPTIONAL_METHODS
|
|
1176
|
-
});
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
const OPTIONAL_METHODS = [
|
|
1180
|
-
"eth_accounts",
|
|
1181
|
-
"eth_requestAccounts",
|
|
1182
|
-
"eth_sendRawTransaction",
|
|
1183
|
-
"eth_sign",
|
|
1184
|
-
"eth_signTransaction",
|
|
1185
|
-
"eth_signTypedData",
|
|
1186
|
-
"eth_signTypedData_v3",
|
|
1187
|
-
"eth_signTypedData_v4",
|
|
1188
|
-
"eth_sendTransaction",
|
|
1189
|
-
"personal_sign",
|
|
1190
|
-
"wallet_switchEthereumChain",
|
|
1191
|
-
"wallet_addEthereumChain",
|
|
1192
|
-
"wallet_getPermissions",
|
|
1193
|
-
"wallet_requestPermissions",
|
|
1194
|
-
"wallet_registerOnboarding",
|
|
1195
|
-
"wallet_watchAsset",
|
|
1196
|
-
"wallet_scanQRCode",
|
|
1197
|
-
// EIP-5792
|
|
1198
|
-
"wallet_getCallsStatus",
|
|
1199
|
-
"wallet_sendCalls",
|
|
1200
|
-
"wallet_getCapabilities",
|
|
1201
|
-
// EIP-7715
|
|
1202
|
-
"wallet_grantPermissions",
|
|
1203
|
-
"wallet_revokePermissions",
|
|
1204
|
-
//EIP-7811
|
|
1205
|
-
"wallet_getAssets"
|
|
1206
|
-
];
|
|
1207
|
-
class AdapterBlueprint {
|
|
1208
|
-
/**
|
|
1209
|
-
* Creates an instance of AdapterBlueprint.
|
|
1210
|
-
* @param {AdapterBlueprint.Params} params - The parameters for initializing the adapter
|
|
1211
|
-
*/
|
|
1212
|
-
constructor(params) {
|
|
1213
|
-
this.availableConnectors = [];
|
|
1214
|
-
this.eventListeners = /* @__PURE__ */ new Map();
|
|
1215
|
-
if (params) {
|
|
1216
|
-
this.construct(params);
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
/**
|
|
1220
|
-
* Initializes the adapter with the given parameters.
|
|
1221
|
-
* @param {AdapterBlueprint.Params} params - The parameters for initializing the adapter
|
|
1222
|
-
*/
|
|
1223
|
-
construct(params) {
|
|
1224
|
-
this.caipNetworks = params.networks;
|
|
1225
|
-
this.projectId = params.projectId;
|
|
1226
|
-
this.namespace = params.namespace;
|
|
1227
|
-
}
|
|
1228
|
-
/**
|
|
1229
|
-
* Gets the available connectors.
|
|
1230
|
-
* @returns {Connector[]} An array of available connectors
|
|
1231
|
-
*/
|
|
1232
|
-
get connectors() {
|
|
1233
|
-
return this.availableConnectors;
|
|
1234
|
-
}
|
|
1235
|
-
/**
|
|
1236
|
-
* Gets the supported networks.
|
|
1237
|
-
* @returns {CaipNetwork[]} An array of supported networks
|
|
1238
|
-
*/
|
|
1239
|
-
get networks() {
|
|
1240
|
-
return this.caipNetworks || [];
|
|
1241
|
-
}
|
|
1242
|
-
/**
|
|
1243
|
-
* Sets the auth provider.
|
|
1244
|
-
* @param {W3mFrameProvider} authProvider - The auth provider instance
|
|
1245
|
-
*/
|
|
1246
|
-
setAuthProvider(authProvider) {
|
|
1247
|
-
this.addConnector({
|
|
1248
|
-
id: index.ConstantsUtil.CONNECTOR_ID.AUTH,
|
|
1249
|
-
type: "AUTH",
|
|
1250
|
-
name: index.ConstantsUtil.CONNECTOR_NAMES.AUTH,
|
|
1251
|
-
provider: authProvider,
|
|
1252
|
-
imageId: PresetsUtil.ConnectorImageIds[index.ConstantsUtil.CONNECTOR_ID.AUTH],
|
|
1253
|
-
chain: this.namespace,
|
|
1254
|
-
chains: []
|
|
1255
|
-
});
|
|
1256
|
-
}
|
|
1257
|
-
/**
|
|
1258
|
-
* Adds one or more connectors to the available connectors list.
|
|
1259
|
-
* @param {...Connector} connectors - The connectors to add
|
|
1260
|
-
*/
|
|
1261
|
-
addConnector(...connectors) {
|
|
1262
|
-
const connectorsAdded = /* @__PURE__ */ new Set();
|
|
1263
|
-
this.availableConnectors = [...connectors, ...this.availableConnectors].filter((connector) => {
|
|
1264
|
-
if (connectorsAdded.has(connector.id)) {
|
|
1265
|
-
return false;
|
|
1266
|
-
}
|
|
1267
|
-
connectorsAdded.add(connector.id);
|
|
1268
|
-
return true;
|
|
1269
|
-
});
|
|
1270
|
-
this.emit("connectors", this.availableConnectors);
|
|
1271
|
-
}
|
|
1272
|
-
setStatus(status, chainNamespace) {
|
|
1273
|
-
index.AccountController.setStatus(status, chainNamespace);
|
|
1274
|
-
}
|
|
1275
|
-
/**
|
|
1276
|
-
* Adds an event listener for a specific event.
|
|
1277
|
-
* @template T
|
|
1278
|
-
* @param {T} eventName - The name of the event
|
|
1279
|
-
* @param {EventCallback<T>} callback - The callback function to be called when the event is emitted
|
|
1280
|
-
*/
|
|
1281
|
-
on(eventName, callback) {
|
|
1282
|
-
var _a;
|
|
1283
|
-
if (!this.eventListeners.has(eventName)) {
|
|
1284
|
-
this.eventListeners.set(eventName, /* @__PURE__ */ new Set());
|
|
1285
|
-
}
|
|
1286
|
-
(_a = this.eventListeners.get(eventName)) == null ? void 0 : _a.add(callback);
|
|
1287
|
-
}
|
|
1288
|
-
/**
|
|
1289
|
-
* Removes an event listener for a specific event.
|
|
1290
|
-
* @template T
|
|
1291
|
-
* @param {T} eventName - The name of the event
|
|
1292
|
-
* @param {EventCallback<T>} callback - The callback function to be removed
|
|
1293
|
-
*/
|
|
1294
|
-
off(eventName, callback) {
|
|
1295
|
-
const listeners = this.eventListeners.get(eventName);
|
|
1296
|
-
if (listeners) {
|
|
1297
|
-
listeners.delete(callback);
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
/**
|
|
1301
|
-
* Removes all event listeners.
|
|
1302
|
-
*/
|
|
1303
|
-
removeAllEventListeners() {
|
|
1304
|
-
this.eventListeners.forEach((listeners) => {
|
|
1305
|
-
listeners.clear();
|
|
1306
|
-
});
|
|
1307
|
-
}
|
|
1308
|
-
/**
|
|
1309
|
-
* Emits an event with the given name and optional data.
|
|
1310
|
-
* @template T
|
|
1311
|
-
* @param {T} eventName - The name of the event to emit
|
|
1312
|
-
* @param {EventData[T]} [data] - The optional data to be passed to the event listeners
|
|
1313
|
-
*/
|
|
1314
|
-
emit(eventName, data) {
|
|
1315
|
-
const listeners = this.eventListeners.get(eventName);
|
|
1316
|
-
if (listeners) {
|
|
1317
|
-
listeners.forEach((callback) => callback(data));
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
/**
|
|
1321
|
-
* Connects to WalletConnect.
|
|
1322
|
-
* @param {number | string} [_chainId] - Optional chain ID to connect to
|
|
1323
|
-
*/
|
|
1324
|
-
async connectWalletConnect(_chainId) {
|
|
1325
|
-
const connector = this.getWalletConnectConnector();
|
|
1326
|
-
const result = await connector.connectWalletConnect();
|
|
1327
|
-
return { clientId: result.clientId };
|
|
1328
|
-
}
|
|
1329
|
-
/**
|
|
1330
|
-
* Switches the network.
|
|
1331
|
-
* @param {AdapterBlueprint.SwitchNetworkParams} params - Network switching parameters
|
|
1332
|
-
*/
|
|
1333
|
-
async switchNetwork(params) {
|
|
1334
|
-
const { caipNetwork, providerType } = params;
|
|
1335
|
-
if (!params.provider) {
|
|
1336
|
-
return;
|
|
1337
|
-
}
|
|
1338
|
-
const provider = "provider" in params.provider ? params.provider.provider : params.provider;
|
|
1339
|
-
if (providerType === "WALLET_CONNECT") {
|
|
1340
|
-
provider.setDefaultChain(caipNetwork.caipNetworkId);
|
|
1341
|
-
return;
|
|
1342
|
-
}
|
|
1343
|
-
if (provider && providerType === "AUTH") {
|
|
1344
|
-
const authProvider = provider;
|
|
1345
|
-
await authProvider.switchNetwork(caipNetwork.caipNetworkId);
|
|
1346
|
-
const user = await authProvider.getUser({
|
|
1347
|
-
chainId: caipNetwork.caipNetworkId,
|
|
1348
|
-
preferredAccountType: index.OptionsController.state.defaultAccountTypes[caipNetwork.chainNamespace]
|
|
1349
|
-
});
|
|
1350
|
-
this.emit("switchNetwork", user);
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
getWalletConnectConnector() {
|
|
1354
|
-
const connector = this.connectors.find((c) => c instanceof WalletConnectConnector);
|
|
1355
|
-
if (!connector) {
|
|
1356
|
-
throw new Error("WalletConnectConnector not found");
|
|
1357
|
-
}
|
|
1358
|
-
return connector;
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
class UniversalAdapter extends AdapterBlueprint {
|
|
1362
|
-
setUniversalProvider(universalProvider) {
|
|
1363
|
-
this.addConnector(new WalletConnectConnector({
|
|
1364
|
-
provider: universalProvider,
|
|
1365
|
-
caipNetworks: this.caipNetworks || [],
|
|
1366
|
-
namespace: this.namespace
|
|
1367
|
-
}));
|
|
1368
|
-
}
|
|
1369
|
-
async connect(params) {
|
|
1370
|
-
return Promise.resolve({
|
|
1371
|
-
id: "WALLET_CONNECT",
|
|
1372
|
-
type: "WALLET_CONNECT",
|
|
1373
|
-
chainId: Number(params.chainId),
|
|
1374
|
-
provider: this.provider,
|
|
1375
|
-
address: ""
|
|
1376
|
-
});
|
|
1377
|
-
}
|
|
1378
|
-
async disconnect() {
|
|
1379
|
-
try {
|
|
1380
|
-
const connector = this.getWalletConnectConnector();
|
|
1381
|
-
await connector.disconnect();
|
|
1382
|
-
} catch (error) {
|
|
1383
|
-
console.warn("UniversalAdapter:disconnect - error", error);
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
async getAccounts({ namespace }) {
|
|
1387
|
-
var _a, _b, _c, _d;
|
|
1388
|
-
const provider = this.provider;
|
|
1389
|
-
const addresses = ((_d = (_c = (_b = (_a = provider == null ? void 0 : provider.session) == null ? void 0 : _a.namespaces) == null ? void 0 : _b[namespace]) == null ? void 0 : _c.accounts) == null ? void 0 : _d.map((account) => {
|
|
1390
|
-
const [, , address] = account.split(":");
|
|
1391
|
-
return address;
|
|
1392
|
-
}).filter((address, index2, self) => self.indexOf(address) === index2)) || [];
|
|
1393
|
-
return Promise.resolve({
|
|
1394
|
-
accounts: addresses.map((address) => index.CoreHelperUtil.createAccount(namespace, address, namespace === "bip122" ? "payment" : "eoa"))
|
|
1395
|
-
});
|
|
1396
|
-
}
|
|
1397
|
-
async syncConnectors() {
|
|
1398
|
-
return Promise.resolve();
|
|
1399
|
-
}
|
|
1400
|
-
async getBalance(params) {
|
|
1401
|
-
var _a, _b, _c, _d, _e;
|
|
1402
|
-
const isBalanceSupported = params.caipNetwork && index.ConstantsUtil$2.BALANCE_SUPPORTED_CHAINS.includes((_a = params.caipNetwork) == null ? void 0 : _a.chainNamespace);
|
|
1403
|
-
if (!isBalanceSupported || ((_b = params.caipNetwork) == null ? void 0 : _b.testnet)) {
|
|
1404
|
-
return {
|
|
1405
|
-
balance: "0.00",
|
|
1406
|
-
symbol: ((_c = params.caipNetwork) == null ? void 0 : _c.nativeCurrency.symbol) || ""
|
|
1407
|
-
};
|
|
1408
|
-
}
|
|
1409
|
-
if (index.AccountController.state.balanceLoading && params.chainId === ((_d = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _d.id)) {
|
|
1410
|
-
return {
|
|
1411
|
-
balance: index.AccountController.state.balance || "0.00",
|
|
1412
|
-
symbol: index.AccountController.state.balanceSymbol || ""
|
|
1413
|
-
};
|
|
1414
|
-
}
|
|
1415
|
-
const balances = await index.AccountController.fetchTokenBalance();
|
|
1416
|
-
const balance = balances.find((b) => {
|
|
1417
|
-
var _a2, _b2;
|
|
1418
|
-
return b.chainId === `${(_a2 = params.caipNetwork) == null ? void 0 : _a2.chainNamespace}:${params.chainId}` && b.symbol === ((_b2 = params.caipNetwork) == null ? void 0 : _b2.nativeCurrency.symbol);
|
|
1419
|
-
});
|
|
1420
|
-
return {
|
|
1421
|
-
balance: (balance == null ? void 0 : balance.quantity.numeric) || "0.00",
|
|
1422
|
-
symbol: (balance == null ? void 0 : balance.symbol) || ((_e = params.caipNetwork) == null ? void 0 : _e.nativeCurrency.symbol) || ""
|
|
1423
|
-
};
|
|
1424
|
-
}
|
|
1425
|
-
async signMessage(params) {
|
|
1426
|
-
var _a, _b, _c;
|
|
1427
|
-
const { provider, message, address } = params;
|
|
1428
|
-
if (!provider) {
|
|
1429
|
-
throw new Error("UniversalAdapter:signMessage - provider is undefined");
|
|
1430
|
-
}
|
|
1431
|
-
let signature = "";
|
|
1432
|
-
if (((_a = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _a.chainNamespace) === index.ConstantsUtil.CHAIN.SOLANA) {
|
|
1433
|
-
const response = await provider.request({
|
|
1434
|
-
method: "solana_signMessage",
|
|
1435
|
-
params: {
|
|
1436
|
-
message: index.bs58.encode(new TextEncoder().encode(message)),
|
|
1437
|
-
pubkey: address
|
|
1438
|
-
}
|
|
1439
|
-
}, (_b = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _b.caipNetworkId);
|
|
1440
|
-
signature = response.signature;
|
|
1441
|
-
} else {
|
|
1442
|
-
signature = await provider.request({
|
|
1443
|
-
method: "personal_sign",
|
|
1444
|
-
params: [message, address]
|
|
1445
|
-
}, (_c = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _c.caipNetworkId);
|
|
1446
|
-
}
|
|
1447
|
-
return { signature };
|
|
1448
|
-
}
|
|
1449
|
-
// -- Transaction methods ---------------------------------------------------
|
|
1450
|
-
/**
|
|
1451
|
-
*
|
|
1452
|
-
* These methods are supported only on `wagmi` and `ethers` since the Solana SDK does not support them in the same way.
|
|
1453
|
-
* These function definition is to have a type parity between the clients. Currently not in use.
|
|
1454
|
-
*/
|
|
1455
|
-
async estimateGas() {
|
|
1456
|
-
return Promise.resolve({
|
|
1457
|
-
gas: BigInt(0)
|
|
1458
|
-
});
|
|
1459
|
-
}
|
|
1460
|
-
async getProfile() {
|
|
1461
|
-
return Promise.resolve({
|
|
1462
|
-
profileImage: "",
|
|
1463
|
-
profileName: ""
|
|
1464
|
-
});
|
|
1465
|
-
}
|
|
1466
|
-
async sendTransaction() {
|
|
1467
|
-
return Promise.resolve({
|
|
1468
|
-
hash: ""
|
|
1469
|
-
});
|
|
1470
|
-
}
|
|
1471
|
-
walletGetAssets(_params) {
|
|
1472
|
-
return Promise.resolve({});
|
|
1473
|
-
}
|
|
1474
|
-
async writeContract() {
|
|
1475
|
-
return Promise.resolve({
|
|
1476
|
-
hash: ""
|
|
1477
|
-
});
|
|
1478
|
-
}
|
|
1479
|
-
async getEnsAddress() {
|
|
1480
|
-
return Promise.resolve({
|
|
1481
|
-
address: false
|
|
1482
|
-
});
|
|
1483
|
-
}
|
|
1484
|
-
parseUnits() {
|
|
1485
|
-
return 0n;
|
|
1486
|
-
}
|
|
1487
|
-
formatUnits() {
|
|
1488
|
-
return "0";
|
|
1489
|
-
}
|
|
1490
|
-
async getCapabilities() {
|
|
1491
|
-
return Promise.resolve({});
|
|
1492
|
-
}
|
|
1493
|
-
async grantPermissions() {
|
|
1494
|
-
return Promise.resolve({});
|
|
1495
|
-
}
|
|
1496
|
-
async revokePermissions() {
|
|
1497
|
-
return Promise.resolve("0x");
|
|
1498
|
-
}
|
|
1499
|
-
async syncConnection() {
|
|
1500
|
-
return Promise.resolve({
|
|
1501
|
-
id: "WALLET_CONNECT",
|
|
1502
|
-
type: "WALLET_CONNECT",
|
|
1503
|
-
chainId: 1,
|
|
1504
|
-
provider: this.provider,
|
|
1505
|
-
address: ""
|
|
1506
|
-
});
|
|
1507
|
-
}
|
|
1508
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1509
|
-
async switchNetwork(params) {
|
|
1510
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1511
|
-
const { caipNetwork } = params;
|
|
1512
|
-
const connector = this.getWalletConnectConnector();
|
|
1513
|
-
if (caipNetwork.chainNamespace === index.ConstantsUtil.CHAIN.EVM) {
|
|
1514
|
-
try {
|
|
1515
|
-
await ((_a = connector.provider) == null ? void 0 : _a.request({
|
|
1516
|
-
method: "wallet_switchEthereumChain",
|
|
1517
|
-
params: [{ chainId: viem.toHex(caipNetwork.id) }]
|
|
1518
|
-
}));
|
|
1519
|
-
} catch (switchError) {
|
|
1520
|
-
if (switchError.code === WcConstantsUtil.ERROR_CODE_UNRECOGNIZED_CHAIN_ID || switchError.code === WcConstantsUtil.ERROR_INVALID_CHAIN_ID || switchError.code === WcConstantsUtil.ERROR_CODE_DEFAULT || ((_c = (_b = switchError == null ? void 0 : switchError.data) == null ? void 0 : _b.originalError) == null ? void 0 : _c.code) === WcConstantsUtil.ERROR_CODE_UNRECOGNIZED_CHAIN_ID) {
|
|
1521
|
-
try {
|
|
1522
|
-
await ((_f = connector.provider) == null ? void 0 : _f.request({
|
|
1523
|
-
method: "wallet_addEthereumChain",
|
|
1524
|
-
params: [
|
|
1525
|
-
{
|
|
1526
|
-
chainId: viem.toHex(caipNetwork.id),
|
|
1527
|
-
rpcUrls: [(_d = caipNetwork == null ? void 0 : caipNetwork.rpcUrls["chainDefault"]) == null ? void 0 : _d.http],
|
|
1528
|
-
chainName: caipNetwork.name,
|
|
1529
|
-
nativeCurrency: caipNetwork.nativeCurrency,
|
|
1530
|
-
blockExplorerUrls: [(_e = caipNetwork.blockExplorers) == null ? void 0 : _e.default.url]
|
|
1531
|
-
}
|
|
1532
|
-
]
|
|
1533
|
-
}));
|
|
1534
|
-
} catch (error) {
|
|
1535
|
-
throw new Error("Chain is not supported");
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
connector.provider.setDefaultChain(caipNetwork.caipNetworkId);
|
|
1541
|
-
}
|
|
1542
|
-
getWalletConnectProvider() {
|
|
1543
|
-
const connector = this.connectors.find((c) => c.type === "WALLET_CONNECT");
|
|
1544
|
-
const provider = connector == null ? void 0 : connector.provider;
|
|
1545
|
-
return provider;
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
let isInitialized = false;
|
|
1549
|
-
class AppKit {
|
|
1550
|
-
constructor(options) {
|
|
1551
|
-
var _a;
|
|
1552
|
-
this.chainNamespaces = [];
|
|
1553
|
-
this.initPromise = void 0;
|
|
1554
|
-
this.reportedAlertErrors = {};
|
|
1555
|
-
this.setStatus = (status, chain) => {
|
|
1556
|
-
index.StorageUtil.setConnectionStatus(status);
|
|
1557
|
-
index.AccountController.setStatus(status, chain);
|
|
1558
|
-
};
|
|
1559
|
-
this.getIsConnectedState = () => Boolean(index.ChainController.state.activeCaipAddress);
|
|
1560
|
-
this.setAllAccounts = (addresses, chain) => {
|
|
1561
|
-
index.AccountController.setAllAccounts(addresses, chain);
|
|
1562
|
-
index.OptionsController.setHasMultipleAddresses((addresses == null ? void 0 : addresses.length) > 1);
|
|
1563
|
-
};
|
|
1564
|
-
this.addAddressLabel = (address, label, chain) => {
|
|
1565
|
-
index.AccountController.addAddressLabel(address, label, chain);
|
|
1566
|
-
};
|
|
1567
|
-
this.removeAddressLabel = (address, chain) => {
|
|
1568
|
-
index.AccountController.removeAddressLabel(address, chain);
|
|
1569
|
-
};
|
|
1570
|
-
this.getCaipAddress = (chainNamespace) => {
|
|
1571
|
-
if (index.ChainController.state.activeChain === chainNamespace || !chainNamespace) {
|
|
1572
|
-
return index.ChainController.state.activeCaipAddress;
|
|
1573
|
-
}
|
|
1574
|
-
return index.ChainController.getAccountProp("caipAddress", chainNamespace);
|
|
1575
|
-
};
|
|
1576
|
-
this.getAddressByChainNamespace = (chainNamespace) => index.ChainController.getAccountProp("address", chainNamespace);
|
|
1577
|
-
this.getAddress = (chainNamespace) => {
|
|
1578
|
-
if (index.ChainController.state.activeChain === chainNamespace || !chainNamespace) {
|
|
1579
|
-
return index.AccountController.state.address;
|
|
1580
|
-
}
|
|
1581
|
-
return index.ChainController.getAccountProp("address", chainNamespace);
|
|
1582
|
-
};
|
|
1583
|
-
this.getProvider = (namespace) => index.ProviderUtil.getProvider(namespace);
|
|
1584
|
-
this.getProviderType = (namespace) => index.ProviderUtil.state.providerIds[namespace];
|
|
1585
|
-
this.getPreferredAccountType = () => index.AccountController.state.preferredAccountType;
|
|
1586
|
-
this.setCaipAddress = (caipAddress, chain) => {
|
|
1587
|
-
index.AccountController.setCaipAddress(caipAddress, chain);
|
|
1588
|
-
};
|
|
1589
|
-
this.setBalance = (balance, balanceSymbol, chain) => {
|
|
1590
|
-
index.AccountController.setBalance(balance, balanceSymbol, chain);
|
|
1591
|
-
};
|
|
1592
|
-
this.setProfileName = (profileName, chain) => {
|
|
1593
|
-
index.AccountController.setProfileName(profileName, chain);
|
|
1594
|
-
};
|
|
1595
|
-
this.setProfileImage = (profileImage, chain) => {
|
|
1596
|
-
index.AccountController.setProfileImage(profileImage, chain);
|
|
1597
|
-
};
|
|
1598
|
-
this.setUser = (user, chain) => {
|
|
1599
|
-
index.AccountController.setUser(user, chain);
|
|
1600
|
-
if (index.OptionsController.state.enableEmbedded) {
|
|
1601
|
-
index.ModalController.close();
|
|
1602
|
-
}
|
|
1603
|
-
};
|
|
1604
|
-
this.resetAccount = (chain) => {
|
|
1605
|
-
index.AccountController.resetAccount(chain);
|
|
1606
|
-
};
|
|
1607
|
-
this.setCaipNetwork = (caipNetwork) => {
|
|
1608
|
-
index.ChainController.setActiveCaipNetwork(caipNetwork);
|
|
1609
|
-
};
|
|
1610
|
-
this.getCaipNetwork = (chainNamespace) => {
|
|
1611
|
-
var _a2;
|
|
1612
|
-
if (chainNamespace) {
|
|
1613
|
-
return (_a2 = index.ChainController.getRequestedCaipNetworks(chainNamespace).filter((c) => c.chainNamespace === chainNamespace)) == null ? void 0 : _a2[0];
|
|
1614
|
-
}
|
|
1615
|
-
return index.ChainController.state.activeCaipNetwork || this.defaultCaipNetwork;
|
|
1616
|
-
};
|
|
1617
|
-
this.getCaipNetworkId = () => {
|
|
1618
|
-
const network = this.getCaipNetwork();
|
|
1619
|
-
if (network) {
|
|
1620
|
-
return network.id;
|
|
1621
|
-
}
|
|
1622
|
-
return void 0;
|
|
1623
|
-
};
|
|
1624
|
-
this.getCaipNetworks = (namespace) => index.ChainController.getRequestedCaipNetworks(namespace);
|
|
1625
|
-
this.getActiveChainNamespace = () => index.ChainController.state.activeChain;
|
|
1626
|
-
this.setRequestedCaipNetworks = (requestedCaipNetworks, chain) => {
|
|
1627
|
-
index.ChainController.setRequestedCaipNetworks(requestedCaipNetworks, chain);
|
|
1628
|
-
};
|
|
1629
|
-
this.getApprovedCaipNetworkIds = () => index.ChainController.getAllApprovedCaipNetworkIds();
|
|
1630
|
-
this.setApprovedCaipNetworksData = (namespace) => index.ChainController.setApprovedCaipNetworksData(namespace);
|
|
1631
|
-
this.resetNetwork = (namespace) => {
|
|
1632
|
-
index.ChainController.resetNetwork(namespace);
|
|
1633
|
-
};
|
|
1634
|
-
this.setConnectors = (connectors) => {
|
|
1635
|
-
const allConnectors = [...index.ConnectorController.getConnectors(), ...connectors];
|
|
1636
|
-
index.ConnectorController.setConnectors(allConnectors);
|
|
1637
|
-
};
|
|
1638
|
-
this.addConnector = (connector) => {
|
|
1639
|
-
index.ConnectorController.addConnector(connector);
|
|
1640
|
-
};
|
|
1641
|
-
this.getConnectors = () => index.ConnectorController.getConnectors();
|
|
1642
|
-
this.resetWcConnection = () => {
|
|
1643
|
-
index.ConnectionController.resetWcConnection();
|
|
1644
|
-
};
|
|
1645
|
-
this.fetchIdentity = (request) => index.BlockchainApiController.fetchIdentity(request);
|
|
1646
|
-
this.setAddressExplorerUrl = (addressExplorerUrl, chain) => {
|
|
1647
|
-
index.AccountController.setAddressExplorerUrl(addressExplorerUrl, chain);
|
|
1648
|
-
};
|
|
1649
|
-
this.setSmartAccountDeployed = (isDeployed, chain) => {
|
|
1650
|
-
index.AccountController.setSmartAccountDeployed(isDeployed, chain);
|
|
1651
|
-
};
|
|
1652
|
-
this.setConnectedWalletInfo = (connectedWalletInfo, chain) => {
|
|
1653
|
-
index.AccountController.setConnectedWalletInfo(connectedWalletInfo ? { type: index.ProviderUtil.getProviderId(chain), ...connectedWalletInfo } : void 0, chain);
|
|
1654
|
-
};
|
|
1655
|
-
this.setSmartAccountEnabledNetworks = (smartAccountEnabledNetworks, chain) => {
|
|
1656
|
-
index.ChainController.setSmartAccountEnabledNetworks(smartAccountEnabledNetworks, chain);
|
|
1657
|
-
};
|
|
1658
|
-
this.setPreferredAccountType = (preferredAccountType, chain) => {
|
|
1659
|
-
index.AccountController.setPreferredAccountType(preferredAccountType, chain);
|
|
1660
|
-
};
|
|
1661
|
-
this.getReownName = (address) => index.EnsController.getNamesForAddress(address);
|
|
1662
|
-
this.setEIP6963Enabled = (enabled) => {
|
|
1663
|
-
index.OptionsController.setEIP6963Enabled(enabled);
|
|
1664
|
-
};
|
|
1665
|
-
this.setClientId = (clientId) => {
|
|
1666
|
-
index.BlockchainApiController.setClientId(clientId);
|
|
1667
|
-
};
|
|
1668
|
-
this.getConnectorImage = (connector) => index.AssetUtil.getConnectorImage(connector);
|
|
1669
|
-
this.handleUnsafeRPCRequest = () => {
|
|
1670
|
-
if (this.isOpen()) {
|
|
1671
|
-
if (this.isTransactionStackEmpty()) {
|
|
1672
|
-
return;
|
|
1673
|
-
}
|
|
1674
|
-
this.redirect("ApproveTransaction");
|
|
1675
|
-
} else {
|
|
1676
|
-
this.open({ view: "ApproveTransaction" });
|
|
1677
|
-
}
|
|
1678
|
-
};
|
|
1679
|
-
this.options = options;
|
|
1680
|
-
this.version = options.sdkVersion;
|
|
1681
|
-
this.caipNetworks = this.extendCaipNetworks(options);
|
|
1682
|
-
this.chainNamespaces = [
|
|
1683
|
-
...new Set((_a = this.caipNetworks) == null ? void 0 : _a.map((caipNetwork) => caipNetwork.chainNamespace))
|
|
1684
|
-
];
|
|
1685
|
-
this.defaultCaipNetwork = this.extendDefaultCaipNetwork(options);
|
|
1686
|
-
this.chainAdapters = this.createAdapters(options.adapters);
|
|
1687
|
-
this.initialize(options);
|
|
1688
|
-
this.sendInitializeEvent(options);
|
|
1689
|
-
}
|
|
1690
|
-
static getInstance() {
|
|
1691
|
-
return this.instance;
|
|
1692
|
-
}
|
|
1693
|
-
async initialize(options) {
|
|
1694
|
-
this.initControllers(options);
|
|
1695
|
-
await this.initChainAdapters();
|
|
1696
|
-
await this.injectModalUi();
|
|
1697
|
-
await this.syncExistingConnection();
|
|
1698
|
-
index.PublicStateController.set({ initialized: true });
|
|
1699
|
-
}
|
|
1700
|
-
sendInitializeEvent(options) {
|
|
1701
|
-
var _a;
|
|
1702
|
-
const { ...optionsCopy } = options;
|
|
1703
|
-
delete optionsCopy.adapters;
|
|
1704
|
-
index.EventsController.sendEvent({
|
|
1705
|
-
type: "track",
|
|
1706
|
-
event: "INITIALIZE",
|
|
1707
|
-
properties: {
|
|
1708
|
-
...optionsCopy,
|
|
1709
|
-
networks: options.networks.map((n) => n.id),
|
|
1710
|
-
siweConfig: {
|
|
1711
|
-
options: ((_a = options.siweConfig) == null ? void 0 : _a.options) || {}
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
});
|
|
1715
|
-
}
|
|
1716
|
-
// -- Public -------------------------------------------------------------------
|
|
1717
|
-
async open(options) {
|
|
1718
|
-
await this.injectModalUi();
|
|
1719
|
-
if ((options == null ? void 0 : options.uri) && this.universalProvider) {
|
|
1720
|
-
index.ConnectionController.setUri(options.uri);
|
|
1721
|
-
}
|
|
1722
|
-
if (options == null ? void 0 : options.namespace) {
|
|
1723
|
-
index.ConnectorController.setFilterByNamespace(options.namespace);
|
|
1724
|
-
}
|
|
1725
|
-
await index.ModalController.open(options);
|
|
1726
|
-
}
|
|
1727
|
-
async close() {
|
|
1728
|
-
await this.injectModalUi();
|
|
1729
|
-
index.ModalController.close();
|
|
1730
|
-
}
|
|
1731
|
-
setLoading(loading) {
|
|
1732
|
-
index.ModalController.setLoading(loading);
|
|
1733
|
-
}
|
|
1734
|
-
// -- Adapter Methods ----------------------------------------------------------
|
|
1735
|
-
getError() {
|
|
1736
|
-
return "";
|
|
1737
|
-
}
|
|
1738
|
-
getChainId() {
|
|
1739
|
-
var _a;
|
|
1740
|
-
return (_a = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _a.id;
|
|
1741
|
-
}
|
|
1742
|
-
async switchNetwork(appKitNetwork) {
|
|
1743
|
-
var _a;
|
|
1744
|
-
const network = (_a = this.caipNetworks) == null ? void 0 : _a.find((n) => n.id === appKitNetwork.id);
|
|
1745
|
-
if (!network) {
|
|
1746
|
-
index.AlertController.open(ErrorUtil.ALERT_ERRORS.SWITCH_NETWORK_NOT_FOUND, "error");
|
|
1747
|
-
return;
|
|
1748
|
-
}
|
|
1749
|
-
await index.ChainController.switchActiveNetwork(network);
|
|
1750
|
-
}
|
|
1751
|
-
getWalletProvider() {
|
|
1752
|
-
return index.ChainController.state.activeChain ? index.ProviderUtil.state.providers[index.ChainController.state.activeChain] : null;
|
|
1753
|
-
}
|
|
1754
|
-
getWalletProviderType() {
|
|
1755
|
-
return index.ChainController.state.activeChain ? index.ProviderUtil.state.providerIds[index.ChainController.state.activeChain] : null;
|
|
1756
|
-
}
|
|
1757
|
-
subscribeProviders(callback) {
|
|
1758
|
-
return index.ProviderUtil.subscribeProviders(callback);
|
|
1759
|
-
}
|
|
1760
|
-
getThemeMode() {
|
|
1761
|
-
return index.ThemeController.state.themeMode;
|
|
1762
|
-
}
|
|
1763
|
-
getThemeVariables() {
|
|
1764
|
-
return index.ThemeController.state.themeVariables;
|
|
1765
|
-
}
|
|
1766
|
-
setThemeMode(themeMode) {
|
|
1767
|
-
index.ThemeController.setThemeMode(themeMode);
|
|
1768
|
-
index.setColorTheme(index.ThemeController.state.themeMode);
|
|
1769
|
-
}
|
|
1770
|
-
setTermsConditionsUrl(termsConditionsUrl) {
|
|
1771
|
-
index.OptionsController.setTermsConditionsUrl(termsConditionsUrl);
|
|
1772
|
-
}
|
|
1773
|
-
setPrivacyPolicyUrl(privacyPolicyUrl) {
|
|
1774
|
-
index.OptionsController.setPrivacyPolicyUrl(privacyPolicyUrl);
|
|
1775
|
-
}
|
|
1776
|
-
setThemeVariables(themeVariables) {
|
|
1777
|
-
index.ThemeController.setThemeVariables(themeVariables);
|
|
1778
|
-
index.setThemeVariables(index.ThemeController.state.themeVariables);
|
|
1779
|
-
}
|
|
1780
|
-
subscribeTheme(callback) {
|
|
1781
|
-
return index.ThemeController.subscribe(callback);
|
|
1782
|
-
}
|
|
1783
|
-
getWalletInfo() {
|
|
1784
|
-
return index.AccountController.state.connectedWalletInfo;
|
|
1785
|
-
}
|
|
1786
|
-
subscribeAccount(callback, namespace) {
|
|
1787
|
-
function updateVal() {
|
|
1788
|
-
const authConnector = index.ConnectorController.getAuthConnector(namespace);
|
|
1789
|
-
const accountState = index.ChainController.getAccountDataByChainNamespace(namespace);
|
|
1790
|
-
if (!accountState) {
|
|
1791
|
-
return;
|
|
1792
|
-
}
|
|
1793
|
-
callback({
|
|
1794
|
-
allAccounts: accountState.allAccounts,
|
|
1795
|
-
caipAddress: accountState.caipAddress,
|
|
1796
|
-
address: index.CoreHelperUtil.getPlainAddress(accountState.caipAddress),
|
|
1797
|
-
isConnected: Boolean(accountState.caipAddress),
|
|
1798
|
-
status: accountState.status,
|
|
1799
|
-
embeddedWalletInfo: authConnector ? {
|
|
1800
|
-
user: accountState.user,
|
|
1801
|
-
authProvider: accountState.socialProvider || "email",
|
|
1802
|
-
accountType: accountState.preferredAccountType,
|
|
1803
|
-
isSmartAccountDeployed: Boolean(accountState.smartAccountDeployed)
|
|
1804
|
-
} : void 0
|
|
1805
|
-
});
|
|
1806
|
-
}
|
|
1807
|
-
if (namespace) {
|
|
1808
|
-
index.ChainController.subscribeChainProp("accountState", updateVal, namespace);
|
|
1809
|
-
} else {
|
|
1810
|
-
index.ChainController.subscribe(updateVal);
|
|
1811
|
-
}
|
|
1812
|
-
index.ConnectorController.subscribe(updateVal);
|
|
1813
|
-
}
|
|
1814
|
-
subscribeNetwork(callback) {
|
|
1815
|
-
return index.ChainController.subscribe(({ activeCaipNetwork }) => {
|
|
1816
|
-
callback({
|
|
1817
|
-
caipNetwork: activeCaipNetwork,
|
|
1818
|
-
chainId: activeCaipNetwork == null ? void 0 : activeCaipNetwork.id,
|
|
1819
|
-
caipNetworkId: activeCaipNetwork == null ? void 0 : activeCaipNetwork.caipNetworkId
|
|
1820
|
-
});
|
|
1821
|
-
});
|
|
1822
|
-
}
|
|
1823
|
-
subscribeWalletInfo(callback) {
|
|
1824
|
-
return index.AccountController.subscribeKey("connectedWalletInfo", callback);
|
|
1825
|
-
}
|
|
1826
|
-
subscribeShouldUpdateToAddress(callback) {
|
|
1827
|
-
index.AccountController.subscribeKey("shouldUpdateToAddress", callback);
|
|
1828
|
-
}
|
|
1829
|
-
subscribeCaipNetworkChange(callback) {
|
|
1830
|
-
index.ChainController.subscribeKey("activeCaipNetwork", callback);
|
|
1831
|
-
}
|
|
1832
|
-
getState() {
|
|
1833
|
-
return index.PublicStateController.state;
|
|
1834
|
-
}
|
|
1835
|
-
subscribeState(callback) {
|
|
1836
|
-
return index.PublicStateController.subscribe(callback);
|
|
1837
|
-
}
|
|
1838
|
-
showErrorMessage(message) {
|
|
1839
|
-
index.SnackController.showError(message);
|
|
1840
|
-
}
|
|
1841
|
-
showSuccessMessage(message) {
|
|
1842
|
-
index.SnackController.showSuccess(message);
|
|
1843
|
-
}
|
|
1844
|
-
getEvent() {
|
|
1845
|
-
return { ...index.EventsController.state };
|
|
1846
|
-
}
|
|
1847
|
-
subscribeEvents(callback) {
|
|
1848
|
-
return index.EventsController.subscribe(callback);
|
|
1849
|
-
}
|
|
1850
|
-
replace(route) {
|
|
1851
|
-
index.RouterController.replace(route);
|
|
1852
|
-
}
|
|
1853
|
-
redirect(route) {
|
|
1854
|
-
index.RouterController.push(route);
|
|
1855
|
-
}
|
|
1856
|
-
popTransactionStack(cancel) {
|
|
1857
|
-
index.RouterController.popTransactionStack(cancel);
|
|
1858
|
-
}
|
|
1859
|
-
isOpen() {
|
|
1860
|
-
return index.ModalController.state.open;
|
|
1861
|
-
}
|
|
1862
|
-
isTransactionStackEmpty() {
|
|
1863
|
-
return index.RouterController.state.transactionStack.length === 0;
|
|
1864
|
-
}
|
|
1865
|
-
updateFeatures(newFeatures) {
|
|
1866
|
-
index.OptionsController.setFeatures(newFeatures);
|
|
1867
|
-
}
|
|
1868
|
-
updateOptions(newOptions) {
|
|
1869
|
-
const currentOptions = index.OptionsController.state || {};
|
|
1870
|
-
const updatedOptions = { ...currentOptions, ...newOptions };
|
|
1871
|
-
index.OptionsController.setOptions(updatedOptions);
|
|
1872
|
-
}
|
|
1873
|
-
setConnectMethodsOrder(connectMethodsOrder) {
|
|
1874
|
-
index.OptionsController.setConnectMethodsOrder(connectMethodsOrder);
|
|
1875
|
-
}
|
|
1876
|
-
setWalletFeaturesOrder(walletFeaturesOrder) {
|
|
1877
|
-
index.OptionsController.setWalletFeaturesOrder(walletFeaturesOrder);
|
|
1878
|
-
}
|
|
1879
|
-
setCollapseWallets(collapseWallets) {
|
|
1880
|
-
index.OptionsController.setCollapseWallets(collapseWallets);
|
|
1881
|
-
}
|
|
1882
|
-
setSocialsOrder(socialsOrder) {
|
|
1883
|
-
index.OptionsController.setSocialsOrder(socialsOrder);
|
|
1884
|
-
}
|
|
1885
|
-
async disconnect() {
|
|
1886
|
-
await index.ConnectionController.disconnect();
|
|
1887
|
-
}
|
|
1888
|
-
getConnectMethodsOrder() {
|
|
1889
|
-
return index.WalletUtil.getConnectOrderMethod(index.OptionsController.state.features, index.ConnectorController.getConnectors());
|
|
1890
|
-
}
|
|
1891
|
-
/**
|
|
1892
|
-
* Removes an adapter from the AppKit.
|
|
1893
|
-
* @param namespace - The namespace of the adapter to remove.
|
|
1894
|
-
*/
|
|
1895
|
-
removeAdapter(namespace) {
|
|
1896
|
-
var _a;
|
|
1897
|
-
const isConnected = this.getIsConnectedState();
|
|
1898
|
-
const adapter = this.getAdapter(namespace);
|
|
1899
|
-
if (!adapter || !this.chainAdapters || isConnected) {
|
|
1900
|
-
return;
|
|
1901
|
-
}
|
|
1902
|
-
const newCaipNetworks = (_a = this.caipNetworks) == null ? void 0 : _a.filter((network) => network.chainNamespace !== namespace);
|
|
1903
|
-
index.ChainController.removeAdapter(namespace);
|
|
1904
|
-
index.ConnectorController.removeAdapter(namespace);
|
|
1905
|
-
this.chainNamespaces = this.chainNamespaces.filter((n) => n !== namespace);
|
|
1906
|
-
this.caipNetworks = newCaipNetworks;
|
|
1907
|
-
adapter.removeAllEventListeners();
|
|
1908
|
-
Reflect.deleteProperty(this.chainAdapters, namespace);
|
|
1909
|
-
}
|
|
1910
|
-
/**
|
|
1911
|
-
* Adds an adapter to the AppKit.
|
|
1912
|
-
* @param adapter - The adapter instance.
|
|
1913
|
-
* @param networks - The list of networks that this adapter supports / uses.
|
|
1914
|
-
*/
|
|
1915
|
-
addAdapter(adapter, networks) {
|
|
1916
|
-
const namespace = adapter.namespace;
|
|
1917
|
-
if (!this.connectionControllerClient || !this.networkControllerClient) {
|
|
1918
|
-
return;
|
|
1919
|
-
}
|
|
1920
|
-
if (!this.chainAdapters || !namespace) {
|
|
1921
|
-
return;
|
|
1922
|
-
}
|
|
1923
|
-
const extendedAdapterNetworks = this.extendCaipNetworks({ ...this.options, networks });
|
|
1924
|
-
this.caipNetworks = [...this.caipNetworks || [], ...extendedAdapterNetworks];
|
|
1925
|
-
this.createAdapter(adapter);
|
|
1926
|
-
this.initChainAdapter(namespace);
|
|
1927
|
-
index.ChainController.addAdapter(adapter, {
|
|
1928
|
-
connectionControllerClient: this.connectionControllerClient,
|
|
1929
|
-
networkControllerClient: this.networkControllerClient
|
|
1930
|
-
}, extendedAdapterNetworks);
|
|
1931
|
-
}
|
|
1932
|
-
/**
|
|
1933
|
-
* Adds a network to an existing adapter in AppKit.
|
|
1934
|
-
* @param namespace - The chain namespace to add the network to (e.g. 'eip155', 'solana')
|
|
1935
|
-
* @param network - The network configuration to add
|
|
1936
|
-
* @throws Error if adapter for namespace doesn't exist
|
|
1937
|
-
*/
|
|
1938
|
-
addNetwork(namespace, network) {
|
|
1939
|
-
var _a;
|
|
1940
|
-
if (this.chainAdapters && !this.chainAdapters[namespace]) {
|
|
1941
|
-
throw new Error(`Adapter for namespace ${namespace} doesn't exist`);
|
|
1942
|
-
}
|
|
1943
|
-
const extendedNetwork = this.extendCaipNetwork(network, this.options);
|
|
1944
|
-
if (this.caipNetworks && !((_a = this.caipNetworks) == null ? void 0 : _a.find((n) => n.id === extendedNetwork.id))) {
|
|
1945
|
-
this.caipNetworks.push(extendedNetwork);
|
|
1946
|
-
index.ChainController.addNetwork(extendedNetwork);
|
|
1947
|
-
}
|
|
1948
|
-
}
|
|
1949
|
-
/**
|
|
1950
|
-
* Removes a network from an existing adapter in AppKit.
|
|
1951
|
-
* @param namespace - The chain namespace the network belongs to
|
|
1952
|
-
* @param networkId - The network ID to remove
|
|
1953
|
-
* @throws Error if adapter for namespace doesn't exist or if removing last network
|
|
1954
|
-
*/
|
|
1955
|
-
removeNetwork(namespace, networkId) {
|
|
1956
|
-
var _a;
|
|
1957
|
-
if (this.chainAdapters && !this.chainAdapters[namespace]) {
|
|
1958
|
-
throw new Error(`Adapter for namespace ${namespace} doesn't exist`);
|
|
1959
|
-
}
|
|
1960
|
-
const networkToRemove = (_a = this.caipNetworks) == null ? void 0 : _a.find((n) => n.id === networkId);
|
|
1961
|
-
if (!networkToRemove) {
|
|
1962
|
-
throw new Error(`Network with ID ${networkId} not found`);
|
|
1963
|
-
}
|
|
1964
|
-
if (!this.caipNetworks) {
|
|
1965
|
-
return;
|
|
1966
|
-
}
|
|
1967
|
-
const remainingAllNetworks = this.caipNetworks.filter((n) => n.id !== networkId);
|
|
1968
|
-
const remainingNamespaceNetworks = this.caipNetworks.filter((n) => n.id !== networkId && n.chainNamespace === namespace);
|
|
1969
|
-
if (!(remainingNamespaceNetworks == null ? void 0 : remainingNamespaceNetworks.length)) {
|
|
1970
|
-
throw new Error("Cannot remove last network for a namespace");
|
|
1971
|
-
}
|
|
1972
|
-
index.ChainController.removeNetwork(namespace, networkId);
|
|
1973
|
-
this.caipNetworks = [...remainingAllNetworks];
|
|
1974
|
-
}
|
|
1975
|
-
// -- Private ------------------------------------------------------------------
|
|
1976
|
-
initializeOptionsController(options) {
|
|
1977
|
-
var _a;
|
|
1978
|
-
index.OptionsController.setDebug(options.debug !== false);
|
|
1979
|
-
if (!options.projectId) {
|
|
1980
|
-
index.AlertController.open(ErrorUtil.ALERT_ERRORS.PROJECT_ID_NOT_CONFIGURED, "error");
|
|
1981
|
-
return;
|
|
1982
|
-
}
|
|
1983
|
-
index.OptionsController.setEnableWalletConnect(options.enableWalletConnect !== false);
|
|
1984
|
-
index.OptionsController.setEnableWalletGuide(options.enableWalletGuide !== false);
|
|
1985
|
-
index.OptionsController.setEnableWallets(options.enableWallets !== false);
|
|
1986
|
-
index.OptionsController.setEIP6963Enabled(options.enableEIP6963 !== false);
|
|
1987
|
-
index.OptionsController.setEnableAuthLogger(options.enableAuthLogger !== false);
|
|
1988
|
-
index.OptionsController.setSdkVersion(options.sdkVersion);
|
|
1989
|
-
index.OptionsController.setProjectId(options.projectId);
|
|
1990
|
-
index.OptionsController.setEnableEmbedded(options.enableEmbedded);
|
|
1991
|
-
index.OptionsController.setAllWallets(options.allWallets);
|
|
1992
|
-
index.OptionsController.setIncludeWalletIds(options.includeWalletIds);
|
|
1993
|
-
index.OptionsController.setExcludeWalletIds(options.excludeWalletIds);
|
|
1994
|
-
index.OptionsController.setFeaturedWalletIds(options.featuredWalletIds);
|
|
1995
|
-
index.OptionsController.setTokens(options.tokens);
|
|
1996
|
-
index.OptionsController.setTermsConditionsUrl(options.termsConditionsUrl);
|
|
1997
|
-
index.OptionsController.setPrivacyPolicyUrl(options.privacyPolicyUrl);
|
|
1998
|
-
index.OptionsController.setCustomWallets(options.customWallets);
|
|
1999
|
-
index.OptionsController.setFeatures(options.features);
|
|
2000
|
-
index.OptionsController.setAllowUnsupportedChain(options.allowUnsupportedChain);
|
|
2001
|
-
index.OptionsController.setDefaultAccountTypes(options.defaultAccountTypes);
|
|
2002
|
-
const defaultMetaData = this.getDefaultMetaData();
|
|
2003
|
-
if (!options.metadata && defaultMetaData) {
|
|
2004
|
-
options.metadata = defaultMetaData;
|
|
2005
|
-
}
|
|
2006
|
-
index.OptionsController.setMetadata(options.metadata);
|
|
2007
|
-
index.OptionsController.setDisableAppend(options.disableAppend);
|
|
2008
|
-
index.OptionsController.setEnableEmbedded(options.enableEmbedded);
|
|
2009
|
-
index.OptionsController.setSIWX(options.siwx);
|
|
2010
|
-
const evmAdapter = (_a = options.adapters) == null ? void 0 : _a.find((adapter) => adapter.namespace === index.ConstantsUtil.CHAIN.EVM);
|
|
2011
|
-
if (evmAdapter) {
|
|
2012
|
-
if (options.siweConfig) {
|
|
2013
|
-
if (options.siwx) {
|
|
2014
|
-
throw new Error("Cannot set both `siweConfig` and `siwx` options");
|
|
2015
|
-
}
|
|
2016
|
-
index.OptionsController.setSIWX(options.siweConfig.mapToSIWX());
|
|
2017
|
-
}
|
|
2018
|
-
}
|
|
2019
|
-
}
|
|
2020
|
-
initializeThemeController(options) {
|
|
2021
|
-
if (options.themeMode) {
|
|
2022
|
-
index.ThemeController.setThemeMode(options.themeMode);
|
|
2023
|
-
}
|
|
2024
|
-
if (options.themeVariables) {
|
|
2025
|
-
index.ThemeController.setThemeVariables(options.themeVariables);
|
|
2026
|
-
}
|
|
2027
|
-
}
|
|
2028
|
-
initializeChainController(options) {
|
|
2029
|
-
if (!this.connectionControllerClient || !this.networkControllerClient) {
|
|
2030
|
-
throw new Error("ConnectionControllerClient and NetworkControllerClient must be set");
|
|
2031
|
-
}
|
|
2032
|
-
index.ChainController.initialize(options.adapters ?? [], this.caipNetworks, {
|
|
2033
|
-
connectionControllerClient: this.connectionControllerClient,
|
|
2034
|
-
networkControllerClient: this.networkControllerClient
|
|
2035
|
-
});
|
|
2036
|
-
const network = this.getDefaultNetwork();
|
|
2037
|
-
if (network) {
|
|
2038
|
-
index.ChainController.setActiveCaipNetwork(network);
|
|
2039
|
-
}
|
|
2040
|
-
}
|
|
2041
|
-
async initializeBlockchainApiController() {
|
|
2042
|
-
await index.BlockchainApiController.getSupportedNetworks();
|
|
2043
|
-
}
|
|
2044
|
-
initControllers(options) {
|
|
2045
|
-
this.initializeOptionsController(options);
|
|
2046
|
-
this.initializeChainController(options);
|
|
2047
|
-
this.initializeThemeController(options);
|
|
2048
|
-
this.initializeBlockchainApiController();
|
|
2049
|
-
if (options.excludeWalletIds) {
|
|
2050
|
-
index.ApiController.initializeExcludedWalletRdns({ ids: options.excludeWalletIds });
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
getDefaultMetaData() {
|
|
2054
|
-
var _a, _b, _c, _d;
|
|
2055
|
-
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
2056
|
-
return {
|
|
2057
|
-
name: ((_b = (_a = document.getElementsByTagName("title")) == null ? void 0 : _a[0]) == null ? void 0 : _b.textContent) || "",
|
|
2058
|
-
description: ((_c = document.querySelector('meta[property="og:description"]')) == null ? void 0 : _c.content) || "",
|
|
2059
|
-
url: window.location.origin,
|
|
2060
|
-
icons: [((_d = document.querySelector('link[rel~="icon"]')) == null ? void 0 : _d.href) || ""]
|
|
2061
|
-
};
|
|
2062
|
-
}
|
|
2063
|
-
return null;
|
|
2064
|
-
}
|
|
2065
|
-
setUnsupportedNetwork(chainId) {
|
|
2066
|
-
const namespace = this.getActiveChainNamespace();
|
|
2067
|
-
if (namespace) {
|
|
2068
|
-
const unsupportedNetwork = this.getUnsupportedNetwork(`${namespace}:${chainId}`);
|
|
2069
|
-
index.ChainController.setActiveCaipNetwork(unsupportedNetwork);
|
|
2070
|
-
}
|
|
2071
|
-
}
|
|
2072
|
-
extendCaipNetwork(network, options) {
|
|
2073
|
-
const extendedNetwork = CaipNetworksUtil.extendCaipNetwork(network, {
|
|
2074
|
-
customNetworkImageUrls: options.chainImages,
|
|
2075
|
-
projectId: options.projectId
|
|
2076
|
-
});
|
|
2077
|
-
return extendedNetwork;
|
|
2078
|
-
}
|
|
2079
|
-
extendCaipNetworks(options) {
|
|
2080
|
-
const extendedNetworks = CaipNetworksUtil.extendCaipNetworks(options.networks, {
|
|
2081
|
-
customNetworkImageUrls: options.chainImages,
|
|
2082
|
-
projectId: options.projectId
|
|
2083
|
-
});
|
|
2084
|
-
return extendedNetworks;
|
|
2085
|
-
}
|
|
2086
|
-
extendDefaultCaipNetwork(options) {
|
|
2087
|
-
const defaultNetwork = options.networks.find((n) => {
|
|
2088
|
-
var _a;
|
|
2089
|
-
return n.id === ((_a = options.defaultNetwork) == null ? void 0 : _a.id);
|
|
2090
|
-
});
|
|
2091
|
-
const extendedNetwork = defaultNetwork ? CaipNetworksUtil.extendCaipNetwork(defaultNetwork, {
|
|
2092
|
-
customNetworkImageUrls: options.chainImages,
|
|
2093
|
-
projectId: options.projectId
|
|
2094
|
-
}) : void 0;
|
|
2095
|
-
return extendedNetwork;
|
|
2096
|
-
}
|
|
2097
|
-
createClients() {
|
|
2098
|
-
this.connectionControllerClient = {
|
|
2099
|
-
connectWalletConnect: async () => {
|
|
2100
|
-
var _a;
|
|
2101
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2102
|
-
if (!adapter) {
|
|
2103
|
-
throw new Error("Adapter not found");
|
|
2104
|
-
}
|
|
2105
|
-
const result = await adapter.connectWalletConnect((_a = this.getCaipNetwork()) == null ? void 0 : _a.id);
|
|
2106
|
-
this.close();
|
|
2107
|
-
this.setClientId((result == null ? void 0 : result.clientId) || null);
|
|
2108
|
-
index.StorageUtil.setConnectedNamespaces([...index.ChainController.state.chains.keys()]);
|
|
2109
|
-
await this.syncWalletConnectAccount();
|
|
2110
|
-
},
|
|
2111
|
-
connectExternal: async ({ id, info, type, provider, chain, caipNetwork }) => {
|
|
2112
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2113
|
-
const activeChain = index.ChainController.state.activeChain;
|
|
2114
|
-
const chainToUse = chain || activeChain;
|
|
2115
|
-
const adapter = this.getAdapter(chainToUse);
|
|
2116
|
-
if (chain && chain !== activeChain && !caipNetwork) {
|
|
2117
|
-
const toConnectNetwork = (_a = this.caipNetworks) == null ? void 0 : _a.find((network) => network.chainNamespace === chain);
|
|
2118
|
-
if (toConnectNetwork) {
|
|
2119
|
-
this.setCaipNetwork(toConnectNetwork);
|
|
2120
|
-
}
|
|
2121
|
-
}
|
|
2122
|
-
if (!adapter) {
|
|
2123
|
-
throw new Error("Adapter not found");
|
|
2124
|
-
}
|
|
2125
|
-
const res = await adapter.connect({
|
|
2126
|
-
id,
|
|
2127
|
-
info,
|
|
2128
|
-
type,
|
|
2129
|
-
provider,
|
|
2130
|
-
chainId: (caipNetwork == null ? void 0 : caipNetwork.id) || ((_b = this.getCaipNetwork()) == null ? void 0 : _b.id),
|
|
2131
|
-
rpcUrl: ((_e = (_d = (_c = caipNetwork == null ? void 0 : caipNetwork.rpcUrls) == null ? void 0 : _c.default) == null ? void 0 : _d.http) == null ? void 0 : _e[0]) || ((_i = (_h = (_g = (_f = this.getCaipNetwork()) == null ? void 0 : _f.rpcUrls) == null ? void 0 : _g.default) == null ? void 0 : _h.http) == null ? void 0 : _i[0])
|
|
2132
|
-
});
|
|
2133
|
-
if (!res) {
|
|
2134
|
-
return;
|
|
2135
|
-
}
|
|
2136
|
-
index.StorageUtil.addConnectedNamespace(chainToUse);
|
|
2137
|
-
this.syncProvider({ ...res, chainNamespace: chainToUse });
|
|
2138
|
-
await this.syncAccount({ ...res, chainNamespace: chainToUse });
|
|
2139
|
-
const { accounts } = await adapter.getAccounts({ namespace: chainToUse, id });
|
|
2140
|
-
this.setAllAccounts(accounts, chainToUse);
|
|
2141
|
-
},
|
|
2142
|
-
reconnectExternal: async ({ id, info, type, provider }) => {
|
|
2143
|
-
var _a;
|
|
2144
|
-
const namespace = index.ChainController.state.activeChain;
|
|
2145
|
-
const adapter = this.getAdapter(namespace);
|
|
2146
|
-
if (adapter == null ? void 0 : adapter.reconnect) {
|
|
2147
|
-
await (adapter == null ? void 0 : adapter.reconnect({ id, info, type, provider, chainId: (_a = this.getCaipNetwork()) == null ? void 0 : _a.id }));
|
|
2148
|
-
index.StorageUtil.addConnectedNamespace(namespace);
|
|
2149
|
-
}
|
|
2150
|
-
},
|
|
2151
|
-
disconnect: async () => {
|
|
2152
|
-
const namespace = index.ChainController.state.activeChain;
|
|
2153
|
-
const adapter = this.getAdapter(namespace);
|
|
2154
|
-
const provider = index.ProviderUtil.getProvider(namespace);
|
|
2155
|
-
const providerType = index.ProviderUtil.state.providerIds[namespace];
|
|
2156
|
-
await (adapter == null ? void 0 : adapter.disconnect({ provider, providerType }));
|
|
2157
|
-
index.StorageUtil.removeConnectedNamespace(namespace);
|
|
2158
|
-
index.ProviderUtil.resetChain(namespace);
|
|
2159
|
-
this.setUser(void 0, namespace);
|
|
2160
|
-
this.setStatus("disconnected", namespace);
|
|
2161
|
-
},
|
|
2162
|
-
checkInstalled: (ids) => {
|
|
2163
|
-
if (!ids) {
|
|
2164
|
-
return Boolean(window.ethereum);
|
|
2165
|
-
}
|
|
2166
|
-
return ids.some((id) => {
|
|
2167
|
-
var _a;
|
|
2168
|
-
return Boolean((_a = window.ethereum) == null ? void 0 : _a[String(id)]);
|
|
2169
|
-
});
|
|
2170
|
-
},
|
|
2171
|
-
signMessage: async (message) => {
|
|
2172
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2173
|
-
const result = await (adapter == null ? void 0 : adapter.signMessage({
|
|
2174
|
-
message,
|
|
2175
|
-
address: index.AccountController.state.address,
|
|
2176
|
-
provider: index.ProviderUtil.getProvider(index.ChainController.state.activeChain)
|
|
2177
|
-
}));
|
|
2178
|
-
return (result == null ? void 0 : result.signature) || "";
|
|
2179
|
-
},
|
|
2180
|
-
sendTransaction: async (args) => {
|
|
2181
|
-
if (args.chainNamespace === index.ConstantsUtil.CHAIN.EVM) {
|
|
2182
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2183
|
-
const provider = index.ProviderUtil.getProvider(index.ChainController.state.activeChain);
|
|
2184
|
-
const result = await (adapter == null ? void 0 : adapter.sendTransaction({ ...args, provider }));
|
|
2185
|
-
return (result == null ? void 0 : result.hash) || "";
|
|
2186
|
-
}
|
|
2187
|
-
return "";
|
|
2188
|
-
},
|
|
2189
|
-
estimateGas: async (args) => {
|
|
2190
|
-
if (args.chainNamespace === index.ConstantsUtil.CHAIN.EVM) {
|
|
2191
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2192
|
-
const provider = index.ProviderUtil.getProvider(index.ChainController.state.activeChain);
|
|
2193
|
-
const caipNetwork = this.getCaipNetwork();
|
|
2194
|
-
if (!caipNetwork) {
|
|
2195
|
-
throw new Error("CaipNetwork is undefined");
|
|
2196
|
-
}
|
|
2197
|
-
const result = await (adapter == null ? void 0 : adapter.estimateGas({
|
|
2198
|
-
...args,
|
|
2199
|
-
provider,
|
|
2200
|
-
caipNetwork
|
|
2201
|
-
}));
|
|
2202
|
-
return (result == null ? void 0 : result.gas) || 0n;
|
|
2203
|
-
}
|
|
2204
|
-
return 0n;
|
|
2205
|
-
},
|
|
2206
|
-
getEnsAvatar: async () => {
|
|
2207
|
-
var _a;
|
|
2208
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2209
|
-
const result = await (adapter == null ? void 0 : adapter.getProfile({
|
|
2210
|
-
address: index.AccountController.state.address,
|
|
2211
|
-
chainId: Number((_a = this.getCaipNetwork()) == null ? void 0 : _a.id)
|
|
2212
|
-
}));
|
|
2213
|
-
return (result == null ? void 0 : result.profileImage) || false;
|
|
2214
|
-
},
|
|
2215
|
-
getEnsAddress: async (name) => {
|
|
2216
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2217
|
-
const caipNetwork = this.getCaipNetwork();
|
|
2218
|
-
if (!caipNetwork) {
|
|
2219
|
-
return false;
|
|
2220
|
-
}
|
|
2221
|
-
const result = await (adapter == null ? void 0 : adapter.getEnsAddress({
|
|
2222
|
-
name,
|
|
2223
|
-
caipNetwork
|
|
2224
|
-
}));
|
|
2225
|
-
return (result == null ? void 0 : result.address) || false;
|
|
2226
|
-
},
|
|
2227
|
-
writeContract: async (args) => {
|
|
2228
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2229
|
-
const caipNetwork = this.getCaipNetwork();
|
|
2230
|
-
const caipAddress = this.getCaipAddress();
|
|
2231
|
-
const provider = index.ProviderUtil.getProvider(index.ChainController.state.activeChain);
|
|
2232
|
-
if (!caipNetwork || !caipAddress) {
|
|
2233
|
-
throw new Error("CaipNetwork or CaipAddress is undefined");
|
|
2234
|
-
}
|
|
2235
|
-
const result = await (adapter == null ? void 0 : adapter.writeContract({ ...args, caipNetwork, provider, caipAddress }));
|
|
2236
|
-
return result == null ? void 0 : result.hash;
|
|
2237
|
-
},
|
|
2238
|
-
parseUnits: (value, decimals) => {
|
|
2239
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2240
|
-
return (adapter == null ? void 0 : adapter.parseUnits({ value, decimals })) ?? 0n;
|
|
2241
|
-
},
|
|
2242
|
-
formatUnits: (value, decimals) => {
|
|
2243
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2244
|
-
return (adapter == null ? void 0 : adapter.formatUnits({ value, decimals })) ?? "0";
|
|
2245
|
-
},
|
|
2246
|
-
getCapabilities: async (params) => {
|
|
2247
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2248
|
-
return await (adapter == null ? void 0 : adapter.getCapabilities(params));
|
|
2249
|
-
},
|
|
2250
|
-
grantPermissions: async (params) => {
|
|
2251
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2252
|
-
return await (adapter == null ? void 0 : adapter.grantPermissions(params));
|
|
2253
|
-
},
|
|
2254
|
-
revokePermissions: async (params) => {
|
|
2255
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2256
|
-
if (adapter == null ? void 0 : adapter.revokePermissions) {
|
|
2257
|
-
return await adapter.revokePermissions(params);
|
|
2258
|
-
}
|
|
2259
|
-
return "0x";
|
|
2260
|
-
},
|
|
2261
|
-
walletGetAssets: async (params) => {
|
|
2262
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2263
|
-
return await (adapter == null ? void 0 : adapter.walletGetAssets(params)) ?? {};
|
|
2264
|
-
}
|
|
2265
|
-
};
|
|
2266
|
-
this.networkControllerClient = {
|
|
2267
|
-
switchCaipNetwork: async (caipNetwork) => {
|
|
2268
|
-
var _a, _b;
|
|
2269
|
-
if (!caipNetwork) {
|
|
2270
|
-
return;
|
|
2271
|
-
}
|
|
2272
|
-
if (index.AccountController.state.address && caipNetwork.chainNamespace === index.ChainController.state.activeChain) {
|
|
2273
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2274
|
-
const provider = index.ProviderUtil.getProvider(index.ChainController.state.activeChain);
|
|
2275
|
-
const providerType = index.ProviderUtil.state.providerIds[index.ChainController.state.activeChain];
|
|
2276
|
-
await (adapter == null ? void 0 : adapter.switchNetwork({ caipNetwork, provider, providerType }));
|
|
2277
|
-
this.setCaipNetwork(caipNetwork);
|
|
2278
|
-
await this.syncAccount({
|
|
2279
|
-
address: index.AccountController.state.address,
|
|
2280
|
-
chainId: caipNetwork.id,
|
|
2281
|
-
chainNamespace: caipNetwork.chainNamespace
|
|
2282
|
-
});
|
|
2283
|
-
} else if (index.AccountController.state.address) {
|
|
2284
|
-
const providerType = index.ProviderUtil.state.providerIds[index.ChainController.state.activeChain];
|
|
2285
|
-
if (providerType === index.ConstantsUtil$1.CONNECTOR_TYPE_AUTH) {
|
|
2286
|
-
try {
|
|
2287
|
-
index.ChainController.state.activeChain = caipNetwork.chainNamespace;
|
|
2288
|
-
await ((_b = (_a = this.connectionControllerClient) == null ? void 0 : _a.connectExternal) == null ? void 0 : _b.call(_a, {
|
|
2289
|
-
id: index.ConstantsUtil.CONNECTOR_ID.AUTH,
|
|
2290
|
-
provider: this.authProvider,
|
|
2291
|
-
chain: caipNetwork.chainNamespace,
|
|
2292
|
-
chainId: caipNetwork.id,
|
|
2293
|
-
type: index.ConstantsUtil$1.CONNECTOR_TYPE_AUTH,
|
|
2294
|
-
caipNetwork
|
|
2295
|
-
}));
|
|
2296
|
-
this.setCaipNetwork(caipNetwork);
|
|
2297
|
-
} catch (error) {
|
|
2298
|
-
const adapter = this.getAdapter(caipNetwork.chainNamespace);
|
|
2299
|
-
await (adapter == null ? void 0 : adapter.switchNetwork({
|
|
2300
|
-
caipNetwork,
|
|
2301
|
-
provider: this.authProvider,
|
|
2302
|
-
providerType
|
|
2303
|
-
}));
|
|
2304
|
-
}
|
|
2305
|
-
} else if (providerType === "WALLET_CONNECT") {
|
|
2306
|
-
this.setCaipNetwork(caipNetwork);
|
|
2307
|
-
this.syncWalletConnectAccount();
|
|
2308
|
-
} else {
|
|
2309
|
-
this.setCaipNetwork(caipNetwork);
|
|
2310
|
-
const address = this.getAddressByChainNamespace(caipNetwork.chainNamespace);
|
|
2311
|
-
if (address) {
|
|
2312
|
-
this.syncAccount({
|
|
2313
|
-
address,
|
|
2314
|
-
chainId: caipNetwork.id,
|
|
2315
|
-
chainNamespace: caipNetwork.chainNamespace
|
|
2316
|
-
});
|
|
2317
|
-
}
|
|
2318
|
-
}
|
|
2319
|
-
} else {
|
|
2320
|
-
this.setCaipNetwork(caipNetwork);
|
|
2321
|
-
}
|
|
2322
|
-
},
|
|
2323
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2324
|
-
getApprovedCaipNetworksData: async () => {
|
|
2325
|
-
var _a, _b, _c, _d, _e;
|
|
2326
|
-
const providerType = index.ProviderUtil.state.providerIds[index.ChainController.state.activeChain];
|
|
2327
|
-
if (providerType === index.ConstantsUtil$1.CONNECTOR_TYPE_WALLET_CONNECT) {
|
|
2328
|
-
const namespaces = (_b = (_a = this.universalProvider) == null ? void 0 : _a.session) == null ? void 0 : _b.namespaces;
|
|
2329
|
-
return {
|
|
2330
|
-
/*
|
|
2331
|
-
* MetaMask Wallet only returns 1 namespace in the session object. This makes it imposible
|
|
2332
|
-
* to switch to other networks. Setting supportsAllNetworks to true for MetaMask Wallet
|
|
2333
|
-
* will make it possible to switch to other networks.
|
|
2334
|
-
*/
|
|
2335
|
-
supportsAllNetworks: ((_e = (_d = (_c = this.universalProvider) == null ? void 0 : _c.session) == null ? void 0 : _d.peer) == null ? void 0 : _e.metadata.name) === "MetaMask Wallet",
|
|
2336
|
-
approvedCaipNetworkIds: this.getChainsFromNamespaces(namespaces)
|
|
2337
|
-
};
|
|
2338
|
-
}
|
|
2339
|
-
return { supportsAllNetworks: true, approvedCaipNetworkIds: [] };
|
|
2340
|
-
}
|
|
2341
|
-
};
|
|
2342
|
-
index.ConnectionController.setClient(this.connectionControllerClient);
|
|
2343
|
-
}
|
|
2344
|
-
setupAuthConnectorListeners(provider) {
|
|
2345
|
-
provider.onRpcRequest((request) => {
|
|
2346
|
-
if (index.W3mFrameHelpers.checkIfRequestExists(request)) {
|
|
2347
|
-
if (!index.W3mFrameHelpers.checkIfRequestIsSafe(request)) {
|
|
2348
|
-
this.handleUnsafeRPCRequest();
|
|
2349
|
-
}
|
|
2350
|
-
} else {
|
|
2351
|
-
this.open();
|
|
2352
|
-
console.error(index.W3mFrameRpcConstants.RPC_METHOD_NOT_ALLOWED_MESSAGE, {
|
|
2353
|
-
method: request.method
|
|
2354
|
-
});
|
|
2355
|
-
setTimeout(() => {
|
|
2356
|
-
this.showErrorMessage(index.W3mFrameRpcConstants.RPC_METHOD_NOT_ALLOWED_UI_MESSAGE);
|
|
2357
|
-
}, 300);
|
|
2358
|
-
provider.rejectRpcRequests();
|
|
2359
|
-
}
|
|
2360
|
-
});
|
|
2361
|
-
provider.onRpcError(() => {
|
|
2362
|
-
const isModalOpen = this.isOpen();
|
|
2363
|
-
if (isModalOpen) {
|
|
2364
|
-
if (this.isTransactionStackEmpty()) {
|
|
2365
|
-
this.close();
|
|
2366
|
-
} else {
|
|
2367
|
-
this.popTransactionStack(true);
|
|
2368
|
-
}
|
|
2369
|
-
}
|
|
2370
|
-
});
|
|
2371
|
-
provider.onRpcSuccess((_, request) => {
|
|
2372
|
-
var _a;
|
|
2373
|
-
const isSafeRequest = index.W3mFrameHelpers.checkIfRequestIsSafe(request);
|
|
2374
|
-
if (isSafeRequest) {
|
|
2375
|
-
return;
|
|
2376
|
-
}
|
|
2377
|
-
if (index.AccountController.state.address && ((_a = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _a.id)) {
|
|
2378
|
-
this.updateNativeBalance();
|
|
2379
|
-
}
|
|
2380
|
-
if (this.isTransactionStackEmpty()) {
|
|
2381
|
-
this.close();
|
|
2382
|
-
} else {
|
|
2383
|
-
this.popTransactionStack();
|
|
2384
|
-
}
|
|
2385
|
-
});
|
|
2386
|
-
provider.onNotConnected(() => {
|
|
2387
|
-
const namespace = index.ChainController.state.activeChain;
|
|
2388
|
-
const connectorId = index.StorageUtil.getConnectedConnectorId(namespace);
|
|
2389
|
-
const isConnectedWithAuth = connectorId === index.ConstantsUtil.CONNECTOR_ID.AUTH;
|
|
2390
|
-
if (isConnectedWithAuth) {
|
|
2391
|
-
this.setCaipAddress(void 0, namespace);
|
|
2392
|
-
this.setLoading(false);
|
|
2393
|
-
}
|
|
2394
|
-
});
|
|
2395
|
-
provider.onConnect(async (user) => {
|
|
2396
|
-
var _a;
|
|
2397
|
-
const namespace = index.ChainController.state.activeChain;
|
|
2398
|
-
const caipAddress = namespace === index.ConstantsUtil.CHAIN.EVM ? `eip155:${user.chainId}:${user.address}` : `${user.chainId}:${user.address}`;
|
|
2399
|
-
this.setSmartAccountDeployed(Boolean(user.smartAccountDeployed), namespace);
|
|
2400
|
-
if (!HelpersUtil.isLowerCaseMatch(user.address, index.AccountController.state.address)) {
|
|
2401
|
-
this.syncIdentity({
|
|
2402
|
-
address: user.address,
|
|
2403
|
-
chainId: user.chainId,
|
|
2404
|
-
chainNamespace: namespace
|
|
2405
|
-
});
|
|
2406
|
-
}
|
|
2407
|
-
this.setCaipAddress(caipAddress, namespace);
|
|
2408
|
-
this.setUser({ ...index.AccountController.state.user || {}, email: user.email }, namespace);
|
|
2409
|
-
const preferredAccountType = user.preferredAccountType || index.OptionsController.state.defaultAccountTypes[namespace];
|
|
2410
|
-
this.setPreferredAccountType(preferredAccountType, namespace);
|
|
2411
|
-
const userAccounts = (_a = user.accounts) == null ? void 0 : _a.map((account) => index.CoreHelperUtil.createAccount(namespace, account.address, account.type || index.OptionsController.state.defaultAccountTypes[namespace]));
|
|
2412
|
-
this.setAllAccounts(userAccounts || [
|
|
2413
|
-
index.CoreHelperUtil.createAccount(namespace, user.address, preferredAccountType)
|
|
2414
|
-
], namespace);
|
|
2415
|
-
await provider.getSmartAccountEnabledNetworks();
|
|
2416
|
-
this.setLoading(false);
|
|
2417
|
-
});
|
|
2418
|
-
provider.onSocialConnected(({ userName }) => {
|
|
2419
|
-
this.setUser({ ...index.AccountController.state.user || {}, username: userName }, index.ChainController.state.activeChain);
|
|
2420
|
-
});
|
|
2421
|
-
provider.onGetSmartAccountEnabledNetworks((networks) => {
|
|
2422
|
-
this.setSmartAccountEnabledNetworks(networks, index.ChainController.state.activeChain);
|
|
2423
|
-
});
|
|
2424
|
-
provider.onSetPreferredAccount(({ address, type }) => {
|
|
2425
|
-
if (!address) {
|
|
2426
|
-
return;
|
|
2427
|
-
}
|
|
2428
|
-
this.setPreferredAccountType(type, index.ChainController.state.activeChain);
|
|
2429
|
-
});
|
|
2430
|
-
}
|
|
2431
|
-
async syncAuthConnector(provider) {
|
|
2432
|
-
var _a, _b, _c, _d;
|
|
2433
|
-
this.setLoading(true);
|
|
2434
|
-
const isLoginEmailUsed = provider.getLoginEmailUsed();
|
|
2435
|
-
this.setLoading(isLoginEmailUsed);
|
|
2436
|
-
if (isLoginEmailUsed) {
|
|
2437
|
-
this.setStatus("connecting", index.ChainController.state.activeChain);
|
|
2438
|
-
}
|
|
2439
|
-
const email = provider.getEmail();
|
|
2440
|
-
const username = provider.getUsername();
|
|
2441
|
-
this.setUser({ ...((_a = index.AccountController.state) == null ? void 0 : _a.user) || {}, username, email }, index.ChainController.state.activeChain);
|
|
2442
|
-
this.setupAuthConnectorListeners(provider);
|
|
2443
|
-
const { isConnected } = await provider.isConnected();
|
|
2444
|
-
const theme = index.ThemeController.getSnapshot();
|
|
2445
|
-
const options = index.OptionsController.getSnapshot();
|
|
2446
|
-
provider.syncDappData({
|
|
2447
|
-
metadata: options.metadata,
|
|
2448
|
-
sdkVersion: options.sdkVersion,
|
|
2449
|
-
projectId: options.projectId,
|
|
2450
|
-
sdkType: options.sdkType
|
|
2451
|
-
});
|
|
2452
|
-
provider.syncTheme({
|
|
2453
|
-
themeMode: theme.themeMode,
|
|
2454
|
-
themeVariables: theme.themeVariables,
|
|
2455
|
-
w3mThemeVariables: index.getW3mThemeVariables(theme.themeVariables, theme.themeMode)
|
|
2456
|
-
});
|
|
2457
|
-
const namespace = index.StorageUtil.getActiveNamespace();
|
|
2458
|
-
if (namespace) {
|
|
2459
|
-
if (isConnected && ((_b = this.connectionControllerClient) == null ? void 0 : _b.connectExternal)) {
|
|
2460
|
-
await ((_d = this.connectionControllerClient) == null ? void 0 : _d.connectExternal({
|
|
2461
|
-
id: index.ConstantsUtil.CONNECTOR_ID.AUTH,
|
|
2462
|
-
info: { name: index.ConstantsUtil.CONNECTOR_ID.AUTH },
|
|
2463
|
-
type: index.ConstantsUtil$1.CONNECTOR_TYPE_AUTH,
|
|
2464
|
-
provider,
|
|
2465
|
-
chainId: (_c = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _c.id,
|
|
2466
|
-
chain: namespace
|
|
2467
|
-
}));
|
|
2468
|
-
this.setStatus("connected", namespace);
|
|
2469
|
-
} else if (index.StorageUtil.getConnectedConnectorId(namespace) === index.ConstantsUtil.CONNECTOR_ID.AUTH) {
|
|
2470
|
-
this.setStatus("disconnected", namespace);
|
|
2471
|
-
index.StorageUtil.removeConnectedNamespace(namespace);
|
|
2472
|
-
}
|
|
2473
|
-
}
|
|
2474
|
-
this.setLoading(false);
|
|
2475
|
-
}
|
|
2476
|
-
listenWalletConnect() {
|
|
2477
|
-
if (this.universalProvider) {
|
|
2478
|
-
this.universalProvider.on("display_uri", (uri) => {
|
|
2479
|
-
index.ConnectionController.setUri(uri);
|
|
2480
|
-
});
|
|
2481
|
-
this.universalProvider.on("disconnect", () => {
|
|
2482
|
-
this.chainNamespaces.forEach((namespace) => {
|
|
2483
|
-
this.resetAccount(namespace);
|
|
2484
|
-
});
|
|
2485
|
-
index.ConnectionController.resetWcConnection();
|
|
2486
|
-
});
|
|
2487
|
-
this.universalProvider.on("chainChanged", (chainId) => {
|
|
2488
|
-
var _a;
|
|
2489
|
-
const caipNetwork = (_a = this.caipNetworks) == null ? void 0 : _a.find((c) => c.id == chainId);
|
|
2490
|
-
const currentCaipNetwork = this.getCaipNetwork();
|
|
2491
|
-
if (!caipNetwork) {
|
|
2492
|
-
this.setUnsupportedNetwork(chainId);
|
|
2493
|
-
return;
|
|
2494
|
-
}
|
|
2495
|
-
if ((currentCaipNetwork == null ? void 0 : currentCaipNetwork.id) !== (caipNetwork == null ? void 0 : caipNetwork.id)) {
|
|
2496
|
-
this.setCaipNetwork(caipNetwork);
|
|
2497
|
-
}
|
|
2498
|
-
});
|
|
2499
|
-
this.universalProvider.on("session_event", (callbackData) => {
|
|
2500
|
-
if (WcHelpersUtil.isSessionEventData(callbackData)) {
|
|
2501
|
-
const { name, data } = callbackData.params.event;
|
|
2502
|
-
if (name === "accountsChanged" && Array.isArray(data) && index.CoreHelperUtil.isCaipAddress(data[0])) {
|
|
2503
|
-
this.syncAccount(ParseUtil.parseCaipAddress(data[0]));
|
|
2504
|
-
}
|
|
2505
|
-
}
|
|
2506
|
-
});
|
|
2507
|
-
}
|
|
2508
|
-
}
|
|
2509
|
-
listenAdapter(chainNamespace) {
|
|
2510
|
-
const adapter = this.getAdapter(chainNamespace);
|
|
2511
|
-
if (!adapter) {
|
|
2512
|
-
return;
|
|
2513
|
-
}
|
|
2514
|
-
const connectionStatus = index.StorageUtil.getConnectionStatus();
|
|
2515
|
-
if (connectionStatus === "connected") {
|
|
2516
|
-
this.setStatus("connecting", chainNamespace);
|
|
2517
|
-
} else if (connectionStatus === "disconnected") {
|
|
2518
|
-
index.StorageUtil.clearAddressCache();
|
|
2519
|
-
this.setStatus(connectionStatus, chainNamespace);
|
|
2520
|
-
} else {
|
|
2521
|
-
this.setStatus(connectionStatus, chainNamespace);
|
|
2522
|
-
}
|
|
2523
|
-
adapter.on("switchNetwork", ({ address, chainId }) => {
|
|
2524
|
-
var _a;
|
|
2525
|
-
if (chainId && ((_a = this.caipNetworks) == null ? void 0 : _a.find((n) => n.id === chainId || n.caipNetworkId === chainId))) {
|
|
2526
|
-
if (index.ChainController.state.activeChain === chainNamespace && address) {
|
|
2527
|
-
this.syncAccount({ address, chainId, chainNamespace });
|
|
2528
|
-
} else if (index.ChainController.state.activeChain === chainNamespace && index.AccountController.state.address) {
|
|
2529
|
-
this.syncAccount({
|
|
2530
|
-
address: index.AccountController.state.address,
|
|
2531
|
-
chainId,
|
|
2532
|
-
chainNamespace
|
|
2533
|
-
});
|
|
2534
|
-
}
|
|
2535
|
-
} else {
|
|
2536
|
-
this.setUnsupportedNetwork(chainId);
|
|
2537
|
-
}
|
|
2538
|
-
});
|
|
2539
|
-
adapter.on("disconnect", this.disconnect.bind(this));
|
|
2540
|
-
adapter.on("pendingTransactions", () => {
|
|
2541
|
-
const address = index.AccountController.state.address;
|
|
2542
|
-
const activeCaipNetwork = index.ChainController.state.activeCaipNetwork;
|
|
2543
|
-
if (!address || !(activeCaipNetwork == null ? void 0 : activeCaipNetwork.id)) {
|
|
2544
|
-
return;
|
|
2545
|
-
}
|
|
2546
|
-
this.updateNativeBalance();
|
|
2547
|
-
});
|
|
2548
|
-
adapter.on("accountChanged", ({ address, chainId }) => {
|
|
2549
|
-
var _a, _b;
|
|
2550
|
-
if (index.ChainController.state.activeChain === chainNamespace && chainId) {
|
|
2551
|
-
this.syncAccount({
|
|
2552
|
-
address,
|
|
2553
|
-
chainId,
|
|
2554
|
-
chainNamespace
|
|
2555
|
-
});
|
|
2556
|
-
} else if (index.ChainController.state.activeChain === chainNamespace && ((_a = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _a.id)) {
|
|
2557
|
-
this.syncAccount({
|
|
2558
|
-
address,
|
|
2559
|
-
chainId: (_b = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _b.id,
|
|
2560
|
-
chainNamespace
|
|
2561
|
-
});
|
|
2562
|
-
}
|
|
2563
|
-
});
|
|
2564
|
-
}
|
|
2565
|
-
async updateNativeBalance() {
|
|
2566
|
-
var _a;
|
|
2567
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2568
|
-
if (adapter && index.ChainController.state.activeChain && index.AccountController.state.address) {
|
|
2569
|
-
const balance = await adapter.getBalance({
|
|
2570
|
-
address: index.AccountController.state.address,
|
|
2571
|
-
chainId: (_a = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _a.id,
|
|
2572
|
-
caipNetwork: this.getCaipNetwork(),
|
|
2573
|
-
tokens: this.options.tokens
|
|
2574
|
-
});
|
|
2575
|
-
this.setBalance(balance.balance, balance.symbol, index.ChainController.state.activeChain);
|
|
2576
|
-
}
|
|
2577
|
-
}
|
|
2578
|
-
getChainsFromNamespaces(namespaces = {}) {
|
|
2579
|
-
return Object.values(namespaces).flatMap((namespace) => {
|
|
2580
|
-
const chains = namespace.chains || [];
|
|
2581
|
-
const accountsChains = namespace.accounts.map((account) => {
|
|
2582
|
-
const { chainId, chainNamespace } = ParseUtil.parseCaipAddress(account);
|
|
2583
|
-
return `${chainNamespace}:${chainId}`;
|
|
2584
|
-
});
|
|
2585
|
-
return Array.from(/* @__PURE__ */ new Set([...chains, ...accountsChains]));
|
|
2586
|
-
});
|
|
2587
|
-
}
|
|
2588
|
-
async syncWalletConnectAccount() {
|
|
2589
|
-
const adapter = this.getAdapter(index.ChainController.state.activeChain);
|
|
2590
|
-
this.chainNamespaces.forEach(async (chainNamespace) => {
|
|
2591
|
-
var _a, _b, _c, _d, _e;
|
|
2592
|
-
const namespaceAccounts = ((_d = (_c = (_b = (_a = this.universalProvider) == null ? void 0 : _a.session) == null ? void 0 : _b.namespaces) == null ? void 0 : _c[chainNamespace]) == null ? void 0 : _d.accounts) || [];
|
|
2593
|
-
const activeChainId = (_e = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _e.id;
|
|
2594
|
-
const sessionAddress = namespaceAccounts.find((account) => {
|
|
2595
|
-
const { chainId } = ParseUtil.parseCaipAddress(account);
|
|
2596
|
-
return chainId === (activeChainId == null ? void 0 : activeChainId.toString());
|
|
2597
|
-
}) || namespaceAccounts[0];
|
|
2598
|
-
if (sessionAddress) {
|
|
2599
|
-
const caipAddress = ParseUtil.validateCaipAddress(sessionAddress);
|
|
2600
|
-
const { chainId, address } = ParseUtil.parseCaipAddress(caipAddress);
|
|
2601
|
-
index.ProviderUtil.setProviderId(chainNamespace, index.ConstantsUtil$1.CONNECTOR_TYPE_WALLET_CONNECT);
|
|
2602
|
-
if (this.caipNetworks && index.ChainController.state.activeCaipNetwork && (adapter == null ? void 0 : adapter.namespace) !== index.ConstantsUtil.CHAIN.EVM) {
|
|
2603
|
-
const provider = adapter == null ? void 0 : adapter.getWalletConnectProvider({
|
|
2604
|
-
caipNetworks: this.caipNetworks,
|
|
2605
|
-
provider: this.universalProvider,
|
|
2606
|
-
activeCaipNetwork: index.ChainController.state.activeCaipNetwork
|
|
2607
|
-
});
|
|
2608
|
-
index.ProviderUtil.setProvider(chainNamespace, provider);
|
|
2609
|
-
} else {
|
|
2610
|
-
index.ProviderUtil.setProvider(chainNamespace, this.universalProvider);
|
|
2611
|
-
}
|
|
2612
|
-
index.StorageUtil.setConnectedConnectorId(chainNamespace, index.ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT);
|
|
2613
|
-
index.StorageUtil.addConnectedNamespace(chainNamespace);
|
|
2614
|
-
this.syncWalletConnectAccounts(chainNamespace);
|
|
2615
|
-
await this.syncAccount({
|
|
2616
|
-
address,
|
|
2617
|
-
chainId,
|
|
2618
|
-
chainNamespace
|
|
2619
|
-
});
|
|
2620
|
-
}
|
|
2621
|
-
});
|
|
2622
|
-
await index.ChainController.setApprovedCaipNetworksData(index.ChainController.state.activeChain);
|
|
2623
|
-
}
|
|
2624
|
-
syncWalletConnectAccounts(chainNamespace) {
|
|
2625
|
-
var _a, _b, _c, _d, _e;
|
|
2626
|
-
const addresses = (_e = (_d = (_c = (_b = (_a = this.universalProvider) == null ? void 0 : _a.session) == null ? void 0 : _b.namespaces) == null ? void 0 : _c[chainNamespace]) == null ? void 0 : _d.accounts) == null ? void 0 : _e.map((account) => {
|
|
2627
|
-
const { address } = ParseUtil.parseCaipAddress(account);
|
|
2628
|
-
return address;
|
|
2629
|
-
}).filter((address, index2, self) => self.indexOf(address) === index2);
|
|
2630
|
-
if (addresses) {
|
|
2631
|
-
this.setAllAccounts(addresses.map((address) => index.CoreHelperUtil.createAccount(chainNamespace, address, chainNamespace === "bip122" ? "payment" : "eoa")), chainNamespace);
|
|
2632
|
-
}
|
|
2633
|
-
}
|
|
2634
|
-
syncProvider({ type, provider, id, chainNamespace }) {
|
|
2635
|
-
index.ProviderUtil.setProviderId(chainNamespace, type);
|
|
2636
|
-
index.ProviderUtil.setProvider(chainNamespace, provider);
|
|
2637
|
-
index.StorageUtil.setConnectedConnectorId(chainNamespace, id);
|
|
2638
|
-
}
|
|
2639
|
-
async syncAccount(params) {
|
|
2640
|
-
var _a, _b, _c, _d, _e, _f;
|
|
2641
|
-
const { address, chainId, chainNamespace } = params;
|
|
2642
|
-
const { chainId: activeChainId } = index.StorageUtil.getActiveNetworkProps();
|
|
2643
|
-
const chainIdToUse = chainId || activeChainId;
|
|
2644
|
-
const isUnsupportedNetwork = ((_a = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _a.name) === index.ConstantsUtil.UNSUPPORTED_NETWORK_NAME;
|
|
2645
|
-
const shouldSupportAllNetworks = index.ChainController.getNetworkProp("supportsAllNetworks", chainNamespace);
|
|
2646
|
-
this.setStatus("connected", chainNamespace);
|
|
2647
|
-
if (isUnsupportedNetwork && !shouldSupportAllNetworks) {
|
|
2648
|
-
return;
|
|
2649
|
-
}
|
|
2650
|
-
if (chainIdToUse) {
|
|
2651
|
-
let caipNetwork = (_b = this.caipNetworks) == null ? void 0 : _b.find((n) => n.id.toString() === chainIdToUse.toString());
|
|
2652
|
-
let fallbackCaipNetwork = (_c = this.caipNetworks) == null ? void 0 : _c.find((n) => n.chainNamespace === chainNamespace);
|
|
2653
|
-
if (!shouldSupportAllNetworks && !caipNetwork && !fallbackCaipNetwork) {
|
|
2654
|
-
const caipNetworkIds = this.getApprovedCaipNetworkIds() || [];
|
|
2655
|
-
const caipNetworkId = caipNetworkIds.find((id) => {
|
|
2656
|
-
var _a2;
|
|
2657
|
-
return ((_a2 = ParseUtil.parseCaipNetworkId(id)) == null ? void 0 : _a2.chainId) === chainIdToUse.toString();
|
|
2658
|
-
});
|
|
2659
|
-
const fallBackCaipNetworkId = caipNetworkIds.find((id) => {
|
|
2660
|
-
var _a2;
|
|
2661
|
-
return ((_a2 = ParseUtil.parseCaipNetworkId(id)) == null ? void 0 : _a2.chainNamespace) === chainNamespace;
|
|
2662
|
-
});
|
|
2663
|
-
caipNetwork = (_d = this.caipNetworks) == null ? void 0 : _d.find((n) => n.caipNetworkId === caipNetworkId);
|
|
2664
|
-
fallbackCaipNetwork = (_e = this.caipNetworks) == null ? void 0 : _e.find((n) => n.caipNetworkId === fallBackCaipNetworkId || // This is a workaround used in Solana network to support deprecated caipNetworkId
|
|
2665
|
-
"deprecatedCaipNetworkId" in n && n.deprecatedCaipNetworkId === fallBackCaipNetworkId);
|
|
2666
|
-
}
|
|
2667
|
-
const network = caipNetwork || fallbackCaipNetwork;
|
|
2668
|
-
if ((network == null ? void 0 : network.chainNamespace) === index.ChainController.state.activeChain) {
|
|
2669
|
-
if (!index.OptionsController.state.allowUnsupportedChain && ((_f = index.ChainController.state.activeCaipNetwork) == null ? void 0 : _f.name) === index.ConstantsUtil.UNSUPPORTED_NETWORK_NAME) {
|
|
2670
|
-
index.ChainController.showUnsupportedChainUI();
|
|
2671
|
-
} else {
|
|
2672
|
-
this.setCaipNetwork(network);
|
|
2673
|
-
}
|
|
2674
|
-
}
|
|
2675
|
-
this.syncConnectedWalletInfo(chainNamespace);
|
|
2676
|
-
if (!HelpersUtil.isLowerCaseMatch(address, index.AccountController.state.address)) {
|
|
2677
|
-
this.setCaipAddress(`${chainNamespace}:${network == null ? void 0 : network.id}:${address}`, chainNamespace);
|
|
2678
|
-
await this.syncIdentity({
|
|
2679
|
-
address,
|
|
2680
|
-
chainId: network == null ? void 0 : network.id,
|
|
2681
|
-
chainNamespace
|
|
2682
|
-
});
|
|
2683
|
-
}
|
|
2684
|
-
await this.syncBalance({ address, chainId: network == null ? void 0 : network.id, chainNamespace });
|
|
2685
|
-
}
|
|
2686
|
-
}
|
|
2687
|
-
async syncBalance(params) {
|
|
2688
|
-
const caipNetwork = index.NetworkUtil.getNetworksByNamespace(this.caipNetworks, params.chainNamespace).find((n) => {
|
|
2689
|
-
var _a;
|
|
2690
|
-
return n.id.toString() === ((_a = params.chainId) == null ? void 0 : _a.toString());
|
|
2691
|
-
});
|
|
2692
|
-
if (!caipNetwork) {
|
|
2693
|
-
return;
|
|
2694
|
-
}
|
|
2695
|
-
await this.updateNativeBalance();
|
|
2696
|
-
}
|
|
2697
|
-
syncConnectedWalletInfo(chainNamespace) {
|
|
2698
|
-
var _a;
|
|
2699
|
-
const connectorId = index.StorageUtil.getConnectedConnectorId(chainNamespace);
|
|
2700
|
-
const providerType = index.ProviderUtil.getProviderId(chainNamespace);
|
|
2701
|
-
if (providerType === index.ConstantsUtil$1.CONNECTOR_TYPE_ANNOUNCED || providerType === index.ConstantsUtil$1.CONNECTOR_TYPE_INJECTED) {
|
|
2702
|
-
if (connectorId) {
|
|
2703
|
-
const connector = this.getConnectors().find((c) => c.id === connectorId);
|
|
2704
|
-
if (connector) {
|
|
2705
|
-
const { info, name, imageUrl } = connector;
|
|
2706
|
-
const icon = imageUrl || this.getConnectorImage(connector);
|
|
2707
|
-
this.setConnectedWalletInfo({ name, icon, ...info }, chainNamespace);
|
|
2708
|
-
}
|
|
2709
|
-
}
|
|
2710
|
-
} else if (providerType === index.ConstantsUtil$1.CONNECTOR_TYPE_WALLET_CONNECT) {
|
|
2711
|
-
const provider = index.ProviderUtil.getProvider(chainNamespace);
|
|
2712
|
-
if (provider == null ? void 0 : provider.session) {
|
|
2713
|
-
this.setConnectedWalletInfo({
|
|
2714
|
-
...provider.session.peer.metadata,
|
|
2715
|
-
name: provider.session.peer.metadata.name,
|
|
2716
|
-
icon: (_a = provider.session.peer.metadata.icons) == null ? void 0 : _a[0]
|
|
2717
|
-
}, chainNamespace);
|
|
2718
|
-
}
|
|
2719
|
-
} else if (providerType === index.ConstantsUtil$1.CONNECTOR_TYPE_AUTH) {
|
|
2720
|
-
const provider = this.authProvider;
|
|
2721
|
-
if (provider) {
|
|
2722
|
-
const social = index.StorageUtil.getConnectedSocialProvider() ?? "email";
|
|
2723
|
-
const identifier = provider.getEmail() ?? provider.getUsername();
|
|
2724
|
-
this.setConnectedWalletInfo({ name: providerType, identifier, social }, chainNamespace);
|
|
2725
|
-
}
|
|
2726
|
-
} else if (connectorId) {
|
|
2727
|
-
if (connectorId === index.ConstantsUtil.CONNECTOR_ID.COINBASE) {
|
|
2728
|
-
const connector = this.getConnectors().find((c) => c.id === index.ConstantsUtil.CONNECTOR_ID.COINBASE);
|
|
2729
|
-
this.setConnectedWalletInfo({ name: "Coinbase Wallet", icon: this.getConnectorImage(connector) }, chainNamespace);
|
|
2730
|
-
}
|
|
2731
|
-
this.setConnectedWalletInfo({ name: connectorId }, chainNamespace);
|
|
2732
|
-
}
|
|
2733
|
-
}
|
|
2734
|
-
async syncIdentity({ address, chainId, chainNamespace }) {
|
|
2735
|
-
var _a;
|
|
2736
|
-
const caipNetworkId = `${chainNamespace}:${chainId}`;
|
|
2737
|
-
const activeCaipNetwork = (_a = this.caipNetworks) == null ? void 0 : _a.find((n) => n.caipNetworkId === caipNetworkId);
|
|
2738
|
-
if (chainNamespace !== index.ConstantsUtil.CHAIN.EVM || (activeCaipNetwork == null ? void 0 : activeCaipNetwork.testnet)) {
|
|
2739
|
-
return;
|
|
2740
|
-
}
|
|
2741
|
-
try {
|
|
2742
|
-
const { name, avatar } = await this.fetchIdentity({
|
|
2743
|
-
address,
|
|
2744
|
-
caipNetworkId
|
|
2745
|
-
});
|
|
2746
|
-
this.setProfileName(name, chainNamespace);
|
|
2747
|
-
this.setProfileImage(avatar, chainNamespace);
|
|
2748
|
-
if (!name) {
|
|
2749
|
-
await this.syncReownName(address, chainNamespace);
|
|
2750
|
-
const adapter = this.getAdapter(chainNamespace);
|
|
2751
|
-
const result = await (adapter == null ? void 0 : adapter.getProfile({
|
|
2752
|
-
address,
|
|
2753
|
-
chainId: Number(chainId)
|
|
2754
|
-
}));
|
|
2755
|
-
if (result == null ? void 0 : result.profileName) {
|
|
2756
|
-
this.setProfileName(result.profileName, chainNamespace);
|
|
2757
|
-
if (result.profileImage) {
|
|
2758
|
-
this.setProfileImage(result.profileImage, chainNamespace);
|
|
2759
|
-
}
|
|
2760
|
-
} else {
|
|
2761
|
-
await this.syncReownName(address, chainNamespace);
|
|
2762
|
-
this.setProfileImage(null, chainNamespace);
|
|
2763
|
-
}
|
|
2764
|
-
}
|
|
2765
|
-
} catch {
|
|
2766
|
-
if (chainId === 1) {
|
|
2767
|
-
await this.syncReownName(address, chainNamespace);
|
|
2768
|
-
} else {
|
|
2769
|
-
await this.syncReownName(address, chainNamespace);
|
|
2770
|
-
this.setProfileImage(null, chainNamespace);
|
|
2771
|
-
}
|
|
2772
|
-
}
|
|
2773
|
-
}
|
|
2774
|
-
async syncReownName(address, chainNamespace) {
|
|
2775
|
-
try {
|
|
2776
|
-
const registeredWcNames = await this.getReownName(address);
|
|
2777
|
-
if (registeredWcNames[0]) {
|
|
2778
|
-
const wcName = registeredWcNames[0];
|
|
2779
|
-
this.setProfileName(wcName.name, chainNamespace);
|
|
2780
|
-
} else {
|
|
2781
|
-
this.setProfileName(null, chainNamespace);
|
|
2782
|
-
}
|
|
2783
|
-
} catch {
|
|
2784
|
-
this.setProfileName(null, chainNamespace);
|
|
2785
|
-
}
|
|
2786
|
-
}
|
|
2787
|
-
async syncAdapterConnection(namespace) {
|
|
2788
|
-
var _a, _b, _c;
|
|
2789
|
-
const adapter = this.getAdapter(namespace);
|
|
2790
|
-
const connectorId = index.StorageUtil.getConnectedConnectorId(namespace);
|
|
2791
|
-
const caipNetwork = this.getCaipNetwork();
|
|
2792
|
-
try {
|
|
2793
|
-
if (!adapter || !connectorId) {
|
|
2794
|
-
throw new Error(`Adapter or connectorId not found for namespace ${namespace}`);
|
|
2795
|
-
}
|
|
2796
|
-
const connection = await (adapter == null ? void 0 : adapter.syncConnection({
|
|
2797
|
-
namespace,
|
|
2798
|
-
id: connectorId,
|
|
2799
|
-
chainId: caipNetwork == null ? void 0 : caipNetwork.id,
|
|
2800
|
-
rpcUrl: (_c = (_b = (_a = caipNetwork == null ? void 0 : caipNetwork.rpcUrls) == null ? void 0 : _a.default) == null ? void 0 : _b.http) == null ? void 0 : _c[0]
|
|
2801
|
-
}));
|
|
2802
|
-
if (connection) {
|
|
2803
|
-
const accounts = await (adapter == null ? void 0 : adapter.getAccounts({
|
|
2804
|
-
namespace,
|
|
2805
|
-
id: connectorId
|
|
2806
|
-
}));
|
|
2807
|
-
if (accounts && accounts.accounts.length > 0) {
|
|
2808
|
-
this.setAllAccounts(accounts.accounts, namespace);
|
|
2809
|
-
} else {
|
|
2810
|
-
this.setAllAccounts([index.CoreHelperUtil.createAccount(namespace, connection.address, "eoa")], namespace);
|
|
2811
|
-
}
|
|
2812
|
-
this.syncProvider({ ...connection, chainNamespace: namespace });
|
|
2813
|
-
await this.syncAccount({ ...connection, chainNamespace: namespace });
|
|
2814
|
-
this.setStatus("connected", namespace);
|
|
2815
|
-
} else {
|
|
2816
|
-
this.setStatus("disconnected", namespace);
|
|
2817
|
-
}
|
|
2818
|
-
} catch (e) {
|
|
2819
|
-
index.StorageUtil.deleteConnectedConnectorId(namespace);
|
|
2820
|
-
this.setStatus("disconnected", namespace);
|
|
2821
|
-
}
|
|
2822
|
-
}
|
|
2823
|
-
async syncNamespaceConnection(namespace) {
|
|
2824
|
-
var _a;
|
|
2825
|
-
try {
|
|
2826
|
-
const connectorId = index.StorageUtil.getConnectedConnectorId(namespace);
|
|
2827
|
-
const isEmailUsed = (_a = this.authProvider) == null ? void 0 : _a.getLoginEmailUsed();
|
|
2828
|
-
if (isEmailUsed) {
|
|
2829
|
-
return;
|
|
2830
|
-
}
|
|
2831
|
-
this.setStatus("connecting", namespace);
|
|
2832
|
-
switch (connectorId) {
|
|
2833
|
-
case index.ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT:
|
|
2834
|
-
await this.syncWalletConnectAccount();
|
|
2835
|
-
break;
|
|
2836
|
-
case index.ConstantsUtil.CONNECTOR_ID.AUTH:
|
|
2837
|
-
break;
|
|
2838
|
-
default:
|
|
2839
|
-
await this.syncAdapterConnection(namespace);
|
|
2840
|
-
}
|
|
2841
|
-
} catch (err) {
|
|
2842
|
-
console.warn("AppKit couldn't sync existing connection", err);
|
|
2843
|
-
index.StorageUtil.deleteConnectedConnectorId(namespace);
|
|
2844
|
-
this.setStatus("disconnected", namespace);
|
|
2845
|
-
}
|
|
2846
|
-
}
|
|
2847
|
-
async syncExistingConnection() {
|
|
2848
|
-
await Promise.allSettled(this.chainNamespaces.map((namespace) => this.syncNamespaceConnection(namespace)));
|
|
2849
|
-
}
|
|
2850
|
-
getAdapter(namespace) {
|
|
2851
|
-
var _a;
|
|
2852
|
-
if (!namespace) {
|
|
2853
|
-
return void 0;
|
|
2854
|
-
}
|
|
2855
|
-
return (_a = this.chainAdapters) == null ? void 0 : _a[namespace];
|
|
2856
|
-
}
|
|
2857
|
-
createUniversalProvider() {
|
|
2858
|
-
var _a;
|
|
2859
|
-
if (!this.universalProviderInitPromise && index.CoreHelperUtil.isClient() && ((_a = this.options) == null ? void 0 : _a.projectId)) {
|
|
2860
|
-
this.universalProviderInitPromise = this.initializeUniversalAdapter();
|
|
2861
|
-
}
|
|
2862
|
-
return this.universalProviderInitPromise;
|
|
2863
|
-
}
|
|
2864
|
-
handleAlertError(error) {
|
|
2865
|
-
const matchedUniversalProviderError = Object.entries(ErrorUtil.UniversalProviderErrors).find(([, { message: message2 }]) => error.message.includes(message2));
|
|
2866
|
-
const [errorKey, errorValue] = matchedUniversalProviderError ?? [];
|
|
2867
|
-
const { message, alertErrorKey } = errorValue ?? {};
|
|
2868
|
-
if (errorKey && message && !this.reportedAlertErrors[errorKey]) {
|
|
2869
|
-
const alertError = ErrorUtil.ALERT_ERRORS[alertErrorKey];
|
|
2870
|
-
if (alertError) {
|
|
2871
|
-
index.AlertController.open(alertError, "error");
|
|
2872
|
-
this.reportedAlertErrors[errorKey] = true;
|
|
2873
|
-
}
|
|
2874
|
-
}
|
|
2875
|
-
}
|
|
2876
|
-
async initializeUniversalAdapter() {
|
|
2877
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2878
|
-
const logger = LoggerUtil.createLogger((error, ...args) => {
|
|
2879
|
-
if (error) {
|
|
2880
|
-
this.handleAlertError(error);
|
|
2881
|
-
}
|
|
2882
|
-
console.error(...args);
|
|
2883
|
-
});
|
|
2884
|
-
const universalProviderOptions = {
|
|
2885
|
-
projectId: (_a = this.options) == null ? void 0 : _a.projectId,
|
|
2886
|
-
metadata: {
|
|
2887
|
-
name: ((_b = this.options) == null ? void 0 : _b.metadata) ? (_c = this.options) == null ? void 0 : _c.metadata.name : "",
|
|
2888
|
-
description: ((_d = this.options) == null ? void 0 : _d.metadata) ? (_e = this.options) == null ? void 0 : _e.metadata.description : "",
|
|
2889
|
-
url: ((_f = this.options) == null ? void 0 : _f.metadata) ? (_g = this.options) == null ? void 0 : _g.metadata.url : "",
|
|
2890
|
-
icons: ((_h = this.options) == null ? void 0 : _h.metadata) ? (_i = this.options) == null ? void 0 : _i.metadata.icons : [""]
|
|
2891
|
-
},
|
|
2892
|
-
logger
|
|
2893
|
-
};
|
|
2894
|
-
index.OptionsController.setUsingInjectedUniversalProvider(Boolean((_j = this.options) == null ? void 0 : _j.universalProvider));
|
|
2895
|
-
this.universalProvider = this.options.universalProvider ?? await index.M.init(universalProviderOptions);
|
|
2896
|
-
this.listenWalletConnect();
|
|
2897
|
-
}
|
|
2898
|
-
async getUniversalProvider() {
|
|
2899
|
-
if (!this.universalProvider) {
|
|
2900
|
-
try {
|
|
2901
|
-
await this.createUniversalProvider();
|
|
2902
|
-
} catch (error) {
|
|
2903
|
-
throw new Error("AppKit:getUniversalProvider - Cannot create provider");
|
|
2904
|
-
}
|
|
2905
|
-
}
|
|
2906
|
-
return this.universalProvider;
|
|
2907
|
-
}
|
|
2908
|
-
createAuthProvider() {
|
|
2909
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2910
|
-
const isEmailEnabled = ((_b = (_a = this.options) == null ? void 0 : _a.features) == null ? void 0 : _b.email) === void 0 ? index.ConstantsUtil$2.DEFAULT_FEATURES.email : (_d = (_c = this.options) == null ? void 0 : _c.features) == null ? void 0 : _d.email;
|
|
2911
|
-
const isSocialsEnabled = ((_f = (_e = this.options) == null ? void 0 : _e.features) == null ? void 0 : _f.socials) ? ((_i = (_h = (_g = this.options) == null ? void 0 : _g.features) == null ? void 0 : _h.socials) == null ? void 0 : _i.length) > 0 : index.ConstantsUtil$2.DEFAULT_FEATURES.socials;
|
|
2912
|
-
const isAuthEnabled = isEmailEnabled || isSocialsEnabled;
|
|
2913
|
-
if (!this.authProvider && ((_j = this.options) == null ? void 0 : _j.projectId) && isAuthEnabled) {
|
|
2914
|
-
this.authProvider = W3mFrameProviderSingleton.getInstance({
|
|
2915
|
-
projectId: this.options.projectId,
|
|
2916
|
-
enableLogger: this.options.enableAuthLogger,
|
|
2917
|
-
chainId: (_k = this.getCaipNetwork()) == null ? void 0 : _k.caipNetworkId,
|
|
2918
|
-
onTimeout: () => {
|
|
2919
|
-
index.AlertController.open(ErrorUtil.ALERT_ERRORS.SOCIALS_TIMEOUT, "error");
|
|
2920
|
-
}
|
|
2921
|
-
});
|
|
2922
|
-
this.subscribeState((val) => {
|
|
2923
|
-
var _a2;
|
|
2924
|
-
if (!val.open) {
|
|
2925
|
-
(_a2 = this.authProvider) == null ? void 0 : _a2.rejectRpcRequests();
|
|
2926
|
-
}
|
|
2927
|
-
});
|
|
2928
|
-
this.syncAuthConnector(this.authProvider);
|
|
2929
|
-
this.checkExistingSocialConnection();
|
|
2930
|
-
}
|
|
2931
|
-
}
|
|
2932
|
-
async createUniversalProviderForAdapter(chainNamespace) {
|
|
2933
|
-
var _a, _b, _c;
|
|
2934
|
-
await this.getUniversalProvider();
|
|
2935
|
-
if (this.universalProvider) {
|
|
2936
|
-
(_c = (_b = (_a = this.chainAdapters) == null ? void 0 : _a[chainNamespace]) == null ? void 0 : _b.setUniversalProvider) == null ? void 0 : _c.call(_b, this.universalProvider);
|
|
2937
|
-
}
|
|
2938
|
-
}
|
|
2939
|
-
createAuthProviderForAdapter(chainNamespace) {
|
|
2940
|
-
var _a, _b, _c;
|
|
2941
|
-
this.createAuthProvider();
|
|
2942
|
-
if (this.authProvider) {
|
|
2943
|
-
(_c = (_b = (_a = this.chainAdapters) == null ? void 0 : _a[chainNamespace]) == null ? void 0 : _b.setAuthProvider) == null ? void 0 : _c.call(_b, this.authProvider);
|
|
2944
|
-
}
|
|
2945
|
-
}
|
|
2946
|
-
createAdapter(blueprint) {
|
|
2947
|
-
var _a;
|
|
2948
|
-
if (!blueprint) {
|
|
2949
|
-
return;
|
|
2950
|
-
}
|
|
2951
|
-
const namespace = blueprint.namespace;
|
|
2952
|
-
if (!namespace) {
|
|
2953
|
-
return;
|
|
2954
|
-
}
|
|
2955
|
-
this.createClients();
|
|
2956
|
-
const adapterBlueprint = blueprint;
|
|
2957
|
-
adapterBlueprint.namespace = namespace;
|
|
2958
|
-
adapterBlueprint.construct({
|
|
2959
|
-
namespace,
|
|
2960
|
-
projectId: (_a = this.options) == null ? void 0 : _a.projectId,
|
|
2961
|
-
networks: this.caipNetworks
|
|
2962
|
-
});
|
|
2963
|
-
if (!this.chainNamespaces.includes(namespace)) {
|
|
2964
|
-
this.chainNamespaces.push(namespace);
|
|
2965
|
-
}
|
|
2966
|
-
if (this.chainAdapters) {
|
|
2967
|
-
this.chainAdapters[namespace] = adapterBlueprint;
|
|
2968
|
-
}
|
|
2969
|
-
}
|
|
2970
|
-
createAdapters(blueprints) {
|
|
2971
|
-
this.createClients();
|
|
2972
|
-
return this.chainNamespaces.reduce((adapters, namespace) => {
|
|
2973
|
-
var _a;
|
|
2974
|
-
const blueprint = blueprints == null ? void 0 : blueprints.find((b) => b.namespace === namespace);
|
|
2975
|
-
if (blueprint) {
|
|
2976
|
-
adapters[namespace] = blueprint;
|
|
2977
|
-
adapters[namespace].namespace = namespace;
|
|
2978
|
-
adapters[namespace].construct({
|
|
2979
|
-
namespace,
|
|
2980
|
-
projectId: (_a = this.options) == null ? void 0 : _a.projectId,
|
|
2981
|
-
networks: this.caipNetworks
|
|
2982
|
-
});
|
|
2983
|
-
} else {
|
|
2984
|
-
adapters[namespace] = new UniversalAdapter({
|
|
2985
|
-
namespace,
|
|
2986
|
-
networks: this.caipNetworks
|
|
2987
|
-
});
|
|
2988
|
-
}
|
|
2989
|
-
return adapters;
|
|
2990
|
-
}, {});
|
|
2991
|
-
}
|
|
2992
|
-
onConnectors(chainNamespace) {
|
|
2993
|
-
const adapter = this.getAdapter(chainNamespace);
|
|
2994
|
-
adapter == null ? void 0 : adapter.on("connectors", this.setConnectors.bind(this));
|
|
2995
|
-
}
|
|
2996
|
-
async initChainAdapter(namespace) {
|
|
2997
|
-
var _a;
|
|
2998
|
-
this.onConnectors(namespace);
|
|
2999
|
-
this.listenAdapter(namespace);
|
|
3000
|
-
(_a = this.chainAdapters) == null ? void 0 : _a[namespace].syncConnectors(this.options, this);
|
|
3001
|
-
await this.createUniversalProviderForAdapter(namespace);
|
|
3002
|
-
this.createAuthProviderForAdapter(namespace);
|
|
3003
|
-
}
|
|
3004
|
-
async initChainAdapters() {
|
|
3005
|
-
await Promise.all(this.chainNamespaces.map(async (namespace) => {
|
|
3006
|
-
await this.initChainAdapter(namespace);
|
|
3007
|
-
}));
|
|
3008
|
-
}
|
|
3009
|
-
getUnsupportedNetwork(caipNetworkId) {
|
|
3010
|
-
return {
|
|
3011
|
-
id: caipNetworkId.split(":")[1],
|
|
3012
|
-
caipNetworkId,
|
|
3013
|
-
name: index.ConstantsUtil.UNSUPPORTED_NETWORK_NAME,
|
|
3014
|
-
chainNamespace: caipNetworkId.split(":")[0],
|
|
3015
|
-
nativeCurrency: {
|
|
3016
|
-
name: "",
|
|
3017
|
-
decimals: 0,
|
|
3018
|
-
symbol: ""
|
|
3019
|
-
},
|
|
3020
|
-
rpcUrls: {
|
|
3021
|
-
default: {
|
|
3022
|
-
http: []
|
|
3023
|
-
}
|
|
3024
|
-
}
|
|
3025
|
-
};
|
|
3026
|
-
}
|
|
3027
|
-
getDefaultNetwork() {
|
|
3028
|
-
var _a, _b;
|
|
3029
|
-
const caipNetworkIdFromStorage = index.StorageUtil.getActiveCaipNetworkId();
|
|
3030
|
-
if (caipNetworkIdFromStorage) {
|
|
3031
|
-
const caipNetwork = (_a = this.caipNetworks) == null ? void 0 : _a.find((n) => n.caipNetworkId === caipNetworkIdFromStorage);
|
|
3032
|
-
if (caipNetwork) {
|
|
3033
|
-
return caipNetwork;
|
|
3034
|
-
}
|
|
3035
|
-
if (this.defaultCaipNetwork) {
|
|
3036
|
-
return this.defaultCaipNetwork;
|
|
3037
|
-
}
|
|
3038
|
-
return this.getUnsupportedNetwork(caipNetworkIdFromStorage);
|
|
3039
|
-
}
|
|
3040
|
-
if (this.defaultCaipNetwork) {
|
|
3041
|
-
return this.defaultCaipNetwork;
|
|
3042
|
-
}
|
|
3043
|
-
return (_b = this.caipNetworks) == null ? void 0 : _b[0];
|
|
3044
|
-
}
|
|
3045
|
-
async injectModalUi() {
|
|
3046
|
-
if (!this.initPromise && !isInitialized && index.CoreHelperUtil.isClient()) {
|
|
3047
|
-
isInitialized = true;
|
|
3048
|
-
this.initPromise = new Promise(async (resolve) => {
|
|
3049
|
-
await Promise.all([
|
|
3050
|
-
Promise.resolve().then(() => require("./index-C4WV9nam.js")),
|
|
3051
|
-
Promise.resolve().then(() => require("./w3m-modal-DLyg7Voy.js"))
|
|
3052
|
-
]);
|
|
3053
|
-
const modal2 = document.createElement("w3m-modal");
|
|
3054
|
-
if (!index.OptionsController.state.disableAppend && !index.OptionsController.state.enableEmbedded) {
|
|
3055
|
-
document.body.insertAdjacentElement("beforeend", modal2);
|
|
3056
|
-
}
|
|
3057
|
-
resolve();
|
|
3058
|
-
});
|
|
3059
|
-
}
|
|
3060
|
-
return this.initPromise;
|
|
3061
|
-
}
|
|
3062
|
-
async checkExistingSocialConnection() {
|
|
3063
|
-
var _a;
|
|
3064
|
-
try {
|
|
3065
|
-
if (!index.CoreHelperUtil.isTelegram()) {
|
|
3066
|
-
return;
|
|
3067
|
-
}
|
|
3068
|
-
const socialProviderToConnect = index.SafeLocalStorage.getItem(index.SafeLocalStorageKeys.SOCIAL_PROVIDER);
|
|
3069
|
-
if (!socialProviderToConnect) {
|
|
3070
|
-
return;
|
|
3071
|
-
}
|
|
3072
|
-
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
3073
|
-
return;
|
|
3074
|
-
}
|
|
3075
|
-
const url = new URL(window.location.href);
|
|
3076
|
-
const resultUri = url.searchParams.get("result_uri");
|
|
3077
|
-
if (!resultUri) {
|
|
3078
|
-
return;
|
|
3079
|
-
}
|
|
3080
|
-
index.AccountController.setSocialProvider(socialProviderToConnect, index.ChainController.state.activeChain);
|
|
3081
|
-
await ((_a = this.authProvider) == null ? void 0 : _a.init());
|
|
3082
|
-
const authConnector = index.ConnectorController.getAuthConnector();
|
|
3083
|
-
if (socialProviderToConnect && authConnector) {
|
|
3084
|
-
this.setLoading(true);
|
|
3085
|
-
await authConnector.provider.connectSocial(resultUri);
|
|
3086
|
-
await index.ConnectionController.connectExternal(authConnector, authConnector.chain);
|
|
3087
|
-
index.StorageUtil.setConnectedSocialProvider(socialProviderToConnect);
|
|
3088
|
-
index.SafeLocalStorage.removeItem(index.SafeLocalStorageKeys.SOCIAL_PROVIDER);
|
|
3089
|
-
index.EventsController.sendEvent({
|
|
3090
|
-
type: "track",
|
|
3091
|
-
event: "SOCIAL_LOGIN_SUCCESS",
|
|
3092
|
-
properties: { provider: socialProviderToConnect }
|
|
3093
|
-
});
|
|
3094
|
-
}
|
|
3095
|
-
} catch (error) {
|
|
3096
|
-
this.setLoading(false);
|
|
3097
|
-
console.error("checkExistingSocialConnection error", error);
|
|
3098
|
-
}
|
|
3099
|
-
try {
|
|
3100
|
-
const url = new URL(window.location.href);
|
|
3101
|
-
url.searchParams.delete("result_uri");
|
|
3102
|
-
window.history.replaceState({}, document.title, url.toString());
|
|
3103
|
-
} catch (error) {
|
|
3104
|
-
console.error("tma social login failed", error);
|
|
3105
|
-
}
|
|
3106
|
-
}
|
|
3107
|
-
}
|
|
3108
|
-
const PACKAGE_VERSION = "1.6.9";
|
|
3109
|
-
let modal = void 0;
|
|
3110
|
-
function createAppKit(options) {
|
|
3111
|
-
if (!modal) {
|
|
3112
|
-
modal = new AppKit({
|
|
3113
|
-
...options,
|
|
3114
|
-
sdkVersion: index.CoreHelperUtil.generateSdkVersion(options.adapters ?? [], "react", PACKAGE_VERSION)
|
|
3115
|
-
});
|
|
3116
|
-
index$1.getAppKit(modal);
|
|
3117
|
-
}
|
|
3118
|
-
return modal;
|
|
3119
|
-
}
|
|
3120
|
-
function useAppKitNetwork() {
|
|
3121
|
-
const { caipNetwork, caipNetworkId, chainId } = react.useAppKitNetworkCore();
|
|
3122
|
-
function switchNetwork(network) {
|
|
3123
|
-
modal == null ? void 0 : modal.switchNetwork(network);
|
|
3124
|
-
}
|
|
3125
|
-
return {
|
|
3126
|
-
caipNetwork,
|
|
3127
|
-
caipNetworkId,
|
|
3128
|
-
chainId,
|
|
3129
|
-
switchNetwork
|
|
3130
|
-
};
|
|
3131
|
-
}
|
|
3132
|
-
exports.createAppKit = createAppKit;
|
|
3133
|
-
exports.useAppKitNetwork = useAppKitNetwork;
|