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