cppay-sdk 0.0.2-beta.25 → 0.0.2-beta.27

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.
Files changed (141) hide show
  1. package/dist/cppay-sdk.css +1 -1
  2. package/dist/index.cjs +1 -1
  3. package/dist/polygon-1pLQCNfb.js +3952 -0
  4. package/dist/polygon-zw79IkW8.cjs +15 -0
  5. package/dist/react.cjs +6 -1
  6. package/dist/react.js +422 -303
  7. package/dist/vue.cjs +1 -1
  8. package/dist/vue.js +174 -235
  9. package/package.json +40 -24
  10. package/dist/AlertController-BPGQ5PgH.js +0 -12787
  11. package/dist/AlertController-CjTbf-Vd.cjs +0 -10
  12. package/dist/ApiController-Crww70p3.js +0 -5652
  13. package/dist/ApiController-DB43iwF1.cjs +0 -4
  14. package/dist/CaipNetworkUtil-Bd4HeTLY.js +0 -204
  15. package/dist/CaipNetworkUtil-Bg22uavB.cjs +0 -1
  16. package/dist/HelpersUtil-CeTmhhZv.js +0 -1415
  17. package/dist/HelpersUtil-L0eeYoE2.cjs +0 -225
  18. package/dist/PhArrowCircleDown-BBy_VuPx.js +0 -46
  19. package/dist/PhArrowCircleDown-BU4QSsA3.cjs +0 -14
  20. package/dist/PhArrowClockwise-D8C24T6J.js +0 -46
  21. package/dist/PhArrowClockwise-DWqhijc2.cjs +0 -14
  22. package/dist/PhArrowDown-Qm1T2ueY.cjs +0 -14
  23. package/dist/PhArrowDown-p9Tekztm.js +0 -46
  24. package/dist/PhArrowLeft-CEtyMFdq.cjs +0 -14
  25. package/dist/PhArrowLeft-CgSKs9Xe.js +0 -46
  26. package/dist/PhArrowRight-ZatyoD6R.cjs +0 -14
  27. package/dist/PhArrowRight-dMdzUgrx.js +0 -46
  28. package/dist/PhArrowSquareOut-CbP71Gny.js +0 -46
  29. package/dist/PhArrowSquareOut-HyssV9za.cjs +0 -14
  30. package/dist/PhArrowUp-Cz127u8b.cjs +0 -14
  31. package/dist/PhArrowUp-DNn-RQ7v.js +0 -46
  32. package/dist/PhArrowUpRight-BX6LlOL0.cjs +0 -14
  33. package/dist/PhArrowUpRight-OyGUhoGi.js +0 -46
  34. package/dist/PhArrowsClockwise-B6w_d2Gy.cjs +0 -14
  35. package/dist/PhArrowsClockwise-BWITTwAP.js +0 -46
  36. package/dist/PhArrowsDownUp-CHHtczH8.js +0 -46
  37. package/dist/PhArrowsDownUp-WYzjhvmQ.cjs +0 -14
  38. package/dist/PhArrowsLeftRight-BA0fjcLn.js +0 -46
  39. package/dist/PhArrowsLeftRight-bgyrYWLt.cjs +0 -14
  40. package/dist/PhBank-BInxTxLw.js +0 -46
  41. package/dist/PhBank-CZ_uTsAN.cjs +0 -14
  42. package/dist/PhBrowser--6CxS13p.js +0 -46
  43. package/dist/PhBrowser-BzOw0W8k.cjs +0 -14
  44. package/dist/PhCaretDown-D-zrPZN9.js +0 -46
  45. package/dist/PhCaretDown-DvF3M2iu.cjs +0 -14
  46. package/dist/PhCaretLeft-DND0SNkF.cjs +0 -14
  47. package/dist/PhCaretLeft-Dm6NsnIS.js +0 -46
  48. package/dist/PhCaretRight-BkRzbZ5m.js +0 -46
  49. package/dist/PhCaretRight-xQkT3bmO.cjs +0 -14
  50. package/dist/PhCaretUp-BEk_5jnn.cjs +0 -14
  51. package/dist/PhCaretUp-DZRZQ-T1.js +0 -46
  52. package/dist/PhCheck-BmwCUZuW.js +0 -46
  53. package/dist/PhCheck-C-u2QP3y.cjs +0 -14
  54. package/dist/PhCircleHalf--TfGDEAT.js +0 -46
  55. package/dist/PhCircleHalf-keQfI7pU.cjs +0 -14
  56. package/dist/PhClock-BvmbjmRx.cjs +0 -14
  57. package/dist/PhClock-DNCf5CVD.js +0 -46
  58. package/dist/PhCompass-B6tcbOFZ.js +0 -46
  59. package/dist/PhCompass-rWCQ_cR8.cjs +0 -14
  60. package/dist/PhCopy-CzC1olDO.cjs +0 -14
  61. package/dist/PhCopy-rbBTM6ME.js +0 -46
  62. package/dist/PhCreditCard-DOpOB0Pl.js +0 -46
  63. package/dist/PhCreditCard-D_qRVKuY.cjs +0 -14
  64. package/dist/PhCurrencyDollar-4EASQkjs.js +0 -46
  65. package/dist/PhCurrencyDollar-RVJJ6bQ3.cjs +0 -14
  66. package/dist/PhDesktop-CPaC-lRj.cjs +0 -14
  67. package/dist/PhDesktop-DZPux6RD.js +0 -46
  68. package/dist/PhDeviceMobile-BnXs4f3Q.cjs +0 -14
  69. package/dist/PhDeviceMobile-CcdKzyah.js +0 -46
  70. package/dist/PhDotsThree-19bbXQaM.js +0 -46
  71. package/dist/PhDotsThree-DSmFeW6i.cjs +0 -14
  72. package/dist/PhEnvelope-F7RF6h58.js +0 -46
  73. package/dist/PhEnvelope-QuTMQbE9.cjs +0 -14
  74. package/dist/PhFunnelSimple-B_FRP21W.js +0 -46
  75. package/dist/PhFunnelSimple-D4Ztu4ri.cjs +0 -14
  76. package/dist/PhGlobe-B8GrTk4S.cjs +0 -14
  77. package/dist/PhGlobe-BSPoRqTV.js +0 -46
  78. package/dist/PhIdentificationCard-fGDBGII0.cjs +0 -14
  79. package/dist/PhIdentificationCard-giQnti3K.js +0 -46
  80. package/dist/PhImage-BpUk8j27.cjs +0 -14
  81. package/dist/PhImage-PtBaftbW.js +0 -46
  82. package/dist/PhInfo-DQEDS02h.js +0 -46
  83. package/dist/PhInfo-V5wKJJoK.cjs +0 -14
  84. package/dist/PhLightbulb-Cisg0Myw.js +0 -46
  85. package/dist/PhLightbulb-xP9kaUlD.cjs +0 -14
  86. package/dist/PhMagnifyingGlass-C1cVSYf2.cjs +0 -14
  87. package/dist/PhMagnifyingGlass-DlkOfQXn.js +0 -46
  88. package/dist/PhPaperPlaneRight-C7Jp2jl_.js +0 -46
  89. package/dist/PhPaperPlaneRight-Kh3uxxIy.cjs +0 -14
  90. package/dist/PhPlus-BgHn57eW.js +0 -46
  91. package/dist/PhPlus-hJ6DZNjc.cjs +0 -14
  92. package/dist/PhPower-C369g1jk.js +0 -46
  93. package/dist/PhPower-DZ-SpUrD.cjs +0 -14
  94. package/dist/PhPuzzlePiece-B0oABcWl.js +0 -46
  95. package/dist/PhPuzzlePiece-DLtOLrcw.cjs +0 -14
  96. package/dist/PhQrCode-BT_hyeEa.js +0 -46
  97. package/dist/PhQrCode-yI6bLoYY.cjs +0 -14
  98. package/dist/PhQuestion-B1UeE96D.js +0 -46
  99. package/dist/PhQuestion-icSeWABx.cjs +0 -14
  100. package/dist/PhQuestionMark-CBVW9Awo.js +0 -46
  101. package/dist/PhQuestionMark-Cmhqu81E.cjs +0 -14
  102. package/dist/PhSealCheck-DTKS5QAx.cjs +0 -14
  103. package/dist/PhSealCheck-Dm2I2X7k.js +0 -46
  104. package/dist/PhSignOut-25xp33w2.cjs +0 -14
  105. package/dist/PhSignOut-BTTDADPY.js +0 -46
  106. package/dist/PhSpinner-Dbua7p0Y.js +0 -46
  107. package/dist/PhSpinner-DtpwblyA.cjs +0 -14
  108. package/dist/PhTrash-B3wUg10m.cjs +0 -14
  109. package/dist/PhTrash-gZghJkGX.js +0 -46
  110. package/dist/PhUser-Bvcv05IM.js +0 -46
  111. package/dist/PhUser-COPP3N-M.cjs +0 -14
  112. package/dist/PhVault-CFa5lrPU.cjs +0 -14
  113. package/dist/PhVault-DvlBF0VI.js +0 -46
  114. package/dist/PhWallet-CzJcybaO.cjs +0 -14
  115. package/dist/PhWallet-Do_lf9BX.js +0 -46
  116. package/dist/PhWarning-BrbSc7gQ.cjs +0 -14
  117. package/dist/PhWarning-DiIpJVsx.js +0 -46
  118. package/dist/PhWarningCircle-DE9BlEIc.js +0 -46
  119. package/dist/PhWarningCircle-F5Piypme.cjs +0 -14
  120. package/dist/PhX-BK3VZT8X.cjs +0 -14
  121. package/dist/PhX-CNlXuiat.js +0 -46
  122. package/dist/basic-C16-Uba1.js +0 -3796
  123. package/dist/basic-ChiCOE6E.cjs +0 -1329
  124. package/dist/chunk-2qRSBEuq.js +0 -18
  125. package/dist/chunk-DT80SxnK.cjs +0 -1
  126. package/dist/core-DKXmyfMB.js +0 -2337
  127. package/dist/core-PuDBroil.cjs +0 -1
  128. package/dist/dijkstra-CNhLvnjU.cjs +0 -1
  129. package/dist/dijkstra-kFl0HtsI.js +0 -56
  130. package/dist/features-BYfQH2hG.cjs +0 -2
  131. package/dist/features-_5Pi-gXV.js +0 -245
  132. package/dist/index.es-DDV8bPq_.js +0 -8311
  133. package/dist/index.es-fgFnvPDP.cjs +0 -19
  134. package/dist/property-Dil4gG0H.cjs +0 -3
  135. package/dist/property-JsW5AM1M.js +0 -578
  136. package/dist/w3m-modal-BBvmkTyb.cjs +0 -2416
  137. package/dist/w3m-modal-CFhImDZN.js +0 -5286
  138. package/dist/walletconnect-B0zXLUON.cjs +0 -17
  139. package/dist/walletconnect-Bb4rv9-G.js +0 -11314
  140. package/dist/wui-list-item-BGvfYb1W.cjs +0 -1452
  141. package/dist/wui-list-item-C4wJpGBn.js +0 -2123
@@ -1,2337 +0,0 @@
1
- import { P as esm_default, _ as Ge, y as Ue } from "./index.es-DDV8bPq_.js";
2
- import { C as SnackController, F as ONRAMP_PROVIDERS, I as subscribeKey, J as ConstantsUtil, L as proxy, M as StorageUtil, N as ConstantsUtil$1, O as withErrorBoundary, P as MELD_PUBLIC_KEY, R as subscribe, S as BlockchainApiController, T as AssetUtil, U as UserRejectedRequestError, V as isSafe, W as ParseUtil, _ as PublicStateController, a as ProviderController, b as ConnectorUtil, c as ConnectionController, g as ModalController, h as ThemeController, j as CoreHelperUtil, k as OptionsController, l as ConnectionControllerUtil, m as ConnectorController, n as ChainController, o as AdapterController, p as getPreferredAccountType, q as NetworkUtil, r as SendController, t as ApiController, v as EventsController, x as WalletUtil, y as RouterController } from "./ApiController-Crww70p3.js";
3
- import { c as setColorTheme, l as setThemeVariables, n as ConstantsUtil$2, t as HelpersUtil } from "./HelpersUtil-CeTmhhZv.js";
4
- import { n as SIWXUtil, r as N, t as AlertController } from "./AlertController-BPGQ5PgH.js";
5
- import { t as CaipNetworksUtil } from "./CaipNetworkUtil-Bd4HeTLY.js";
6
- import { toHex } from "viem";
7
- const USDC_CURRENCY_DEFAULT = {
8
- id: "2b92315d-eab7-5bef-84fa-089a131333f5",
9
- name: "USD Coin",
10
- symbol: "USDC",
11
- networks: [{
12
- name: "ethereum-mainnet",
13
- display_name: "Ethereum",
14
- chain_id: "1",
15
- contract_address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
16
- }, {
17
- name: "polygon-mainnet",
18
- display_name: "Polygon",
19
- chain_id: "137",
20
- contract_address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"
21
- }]
22
- }, USD_CURRENCY_DEFAULT = {
23
- id: "USD",
24
- payment_method_limits: [{
25
- id: "card",
26
- min: "10.00",
27
- max: "7500.00"
28
- }, {
29
- id: "ach_bank_account",
30
- min: "10.00",
31
- max: "25000.00"
32
- }]
33
- };
34
- var state$1 = proxy({
35
- providers: ONRAMP_PROVIDERS,
36
- selectedProvider: null,
37
- error: null,
38
- purchaseCurrency: USDC_CURRENCY_DEFAULT,
39
- paymentCurrency: USD_CURRENCY_DEFAULT,
40
- purchaseCurrencies: [USDC_CURRENCY_DEFAULT],
41
- paymentCurrencies: [],
42
- quotesLoading: !1
43
- });
44
- const OnRampController = withErrorBoundary({
45
- state: state$1,
46
- subscribe(f) {
47
- return subscribe(state$1, () => f(state$1));
48
- },
49
- subscribeKey(f, V) {
50
- return subscribeKey(state$1, f, V);
51
- },
52
- setSelectedProvider(f) {
53
- if (f && f.name === "meld") {
54
- let V = ChainController.state.activeChain, H = V === ConstantsUtil.CHAIN.SOLANA ? "SOL" : "USDC", U = V ? ChainController.state.chains.get(V)?.accountState?.address ?? "" : "", W = new URL(f.url);
55
- W.searchParams.append("publicKey", MELD_PUBLIC_KEY), W.searchParams.append("destinationCurrencyCode", H), W.searchParams.append("walletAddress", U), W.searchParams.append("externalCustomerId", OptionsController.state.projectId), state$1.selectedProvider = {
56
- ...f,
57
- url: W.toString()
58
- };
59
- } else state$1.selectedProvider = f;
60
- },
61
- setOnrampProviders(f) {
62
- if (Array.isArray(f) && f.every((f) => typeof f == "string")) {
63
- let V = f;
64
- state$1.providers = ONRAMP_PROVIDERS.filter((f) => V.includes(f.name));
65
- } else state$1.providers = [];
66
- },
67
- setPurchaseCurrency(f) {
68
- state$1.purchaseCurrency = f;
69
- },
70
- setPaymentCurrency(f) {
71
- state$1.paymentCurrency = f;
72
- },
73
- setPurchaseAmount(f) {
74
- OnRampController.state.purchaseAmount = f;
75
- },
76
- setPaymentAmount(f) {
77
- OnRampController.state.paymentAmount = f;
78
- },
79
- async getAvailableCurrencies() {
80
- let f = await BlockchainApiController.getOnrampOptions();
81
- state$1.purchaseCurrencies = f.purchaseCurrencies, state$1.paymentCurrencies = f.paymentCurrencies, state$1.paymentCurrency = f.paymentCurrencies[0] || USD_CURRENCY_DEFAULT, state$1.purchaseCurrency = f.purchaseCurrencies[0] || USDC_CURRENCY_DEFAULT, await ApiController.fetchCurrencyImages(f.paymentCurrencies.map((f) => f.id)), await ApiController.fetchTokenImages(f.purchaseCurrencies.map((f) => f.symbol));
82
- },
83
- async getQuote() {
84
- state$1.quotesLoading = !0;
85
- try {
86
- let f = await BlockchainApiController.getOnrampQuote({
87
- purchaseCurrency: state$1.purchaseCurrency,
88
- paymentCurrency: state$1.paymentCurrency,
89
- amount: state$1.paymentAmount?.toString() || "0",
90
- network: state$1.purchaseCurrency?.symbol
91
- });
92
- return state$1.quotesLoading = !1, state$1.purchaseAmount = Number(f?.purchaseAmount.amount), f;
93
- } catch (f) {
94
- return state$1.error = f.message, state$1.quotesLoading = !1, null;
95
- } finally {
96
- state$1.quotesLoading = !1;
97
- }
98
- },
99
- resetState() {
100
- state$1.selectedProvider = null, state$1.error = null, state$1.purchaseCurrency = USDC_CURRENCY_DEFAULT, state$1.paymentCurrency = USD_CURRENCY_DEFAULT, state$1.purchaseCurrencies = [USDC_CURRENCY_DEFAULT], state$1.paymentCurrencies = [], state$1.paymentAmount = void 0, state$1.purchaseAmount = void 0, state$1.quotesLoading = !1;
101
- }
102
- });
103
- var SLIP44_MSB = 2147483648;
104
- const EnsUtil = { convertEVMChainIdToCoinType(f) {
105
- if (f >= SLIP44_MSB) throw Error("Invalid chainId");
106
- return (SLIP44_MSB | f) >>> 0;
107
- } };
108
- var state = proxy({
109
- suggestions: [],
110
- loading: !1
111
- });
112
- const EnsController = withErrorBoundary({
113
- state,
114
- subscribe(f) {
115
- return subscribe(state, () => f(state));
116
- },
117
- subscribeKey(f, V) {
118
- return subscribeKey(state, f, V);
119
- },
120
- async resolveName(f) {
121
- try {
122
- return await BlockchainApiController.lookupEnsName(f);
123
- } catch (f) {
124
- let V = f;
125
- throw Error(V?.reasons?.[0]?.description || "Error resolving name");
126
- }
127
- },
128
- async isNameRegistered(f) {
129
- try {
130
- return await BlockchainApiController.lookupEnsName(f), !0;
131
- } catch {
132
- return !1;
133
- }
134
- },
135
- async getSuggestions(f) {
136
- try {
137
- return state.loading = !0, state.suggestions = [], state.suggestions = (await BlockchainApiController.getEnsNameSuggestions(f)).suggestions || [], state.suggestions;
138
- } catch (f) {
139
- let V = EnsController.parseEnsApiError(f, "Error fetching name suggestions");
140
- throw Error(V);
141
- } finally {
142
- state.loading = !1;
143
- }
144
- },
145
- async getNamesForAddress(f) {
146
- try {
147
- if (!ChainController.state.activeCaipNetwork) return [];
148
- let V = StorageUtil.getEnsFromCacheForAddress(f);
149
- if (V) return V;
150
- let H = await BlockchainApiController.reverseLookupEnsName({ address: f });
151
- return StorageUtil.updateEnsCache({
152
- address: f,
153
- ens: H,
154
- timestamp: Date.now()
155
- }), H;
156
- } catch (f) {
157
- let V = EnsController.parseEnsApiError(f, "Error fetching names for address");
158
- throw Error(V);
159
- }
160
- },
161
- async registerName(f) {
162
- let V = ChainController.state.activeCaipNetwork, H = ChainController.getAccountData(V?.chainNamespace)?.address, U = ConnectorController.getAuthConnector();
163
- if (!V) throw Error("Network not found");
164
- if (!H || !U) throw Error("Address or auth connector not found");
165
- state.loading = !0;
166
- try {
167
- let U = JSON.stringify({
168
- name: f,
169
- attributes: {},
170
- timestamp: Math.floor(Date.now() / 1e3)
171
- });
172
- RouterController.pushTransactionStack({ onCancel() {
173
- RouterController.replace("RegisterAccountName");
174
- } });
175
- let W = await ConnectionController.signMessage(U);
176
- state.loading = !1;
177
- let G = V.id;
178
- if (!G) throw Error("Network not found");
179
- let K = EnsUtil.convertEVMChainIdToCoinType(Number(G));
180
- await BlockchainApiController.registerEnsName({
181
- coinType: K,
182
- address: H,
183
- signature: W,
184
- message: U
185
- }), ChainController.setAccountProp("profileName", f, V.chainNamespace), StorageUtil.updateEnsCache({
186
- address: H,
187
- ens: [{
188
- name: f,
189
- registered_at: (/* @__PURE__ */ new Date()).toISOString(),
190
- updated_at: void 0,
191
- addresses: {},
192
- attributes: []
193
- }],
194
- timestamp: Date.now()
195
- }), RouterController.replace("RegisterAccountNameSuccess");
196
- } catch (V) {
197
- let H = EnsController.parseEnsApiError(V, `Error registering name ${f}`);
198
- throw RouterController.replace("RegisterAccountName"), Error(H);
199
- } finally {
200
- state.loading = !1;
201
- }
202
- },
203
- validateName(f) {
204
- return /^[a-zA-Z0-9-]{4,}$/u.test(f);
205
- },
206
- parseEnsApiError(f, V) {
207
- return f?.reasons?.[0]?.description || V;
208
- }
209
- });
210
- function parseUrl(f) {
211
- try {
212
- return new URL(f);
213
- } catch {
214
- return null;
215
- }
216
- }
217
- function parseSchemelessHostPort(f) {
218
- let V = f.split("/"), H = V.length > 0 && V[0] !== void 0 ? V[0] : "", U = H.lastIndexOf(":");
219
- return U === -1 ? { host: H } : {
220
- host: H.slice(0, U),
221
- port: H.slice(U + 1)
222
- };
223
- }
224
- function parseOriginRaw(f) {
225
- let V = f.indexOf("://");
226
- if (V === -1) return null;
227
- let H = f.slice(0, V), U = V + 3, W = f.indexOf("/", U);
228
- W === -1 && (W = f.length);
229
- let G = f.slice(U, W), K = G.lastIndexOf(":");
230
- return K === -1 ? {
231
- scheme: H,
232
- host: G
233
- } : {
234
- scheme: H,
235
- host: G.slice(0, K),
236
- port: G.slice(K + 1)
237
- };
238
- }
239
- function matchNonWildcardPattern(f, V) {
240
- if (V.includes("://")) {
241
- let H = parseUrl(V);
242
- return H ? H.origin === f : !1;
243
- }
244
- let { host: H, port: U } = parseSchemelessHostPort(V), W = f.indexOf("://");
245
- if (W !== -1) {
246
- let V = W + 3, G = f.indexOf("/", V);
247
- G === -1 && (G = f.length);
248
- let K = f.slice(V, G);
249
- return U === void 0 ? H === K.split(":")[0] : `${H}:${U}` === K;
250
- }
251
- let G = parseUrl(f);
252
- return G ? U === void 0 ? H === G.hostname : H === G.hostname && U === (G.port || void 0) : !1;
253
- }
254
- function matchWildcardPattern(f, V, H) {
255
- let U = H, W, G = U.indexOf("://");
256
- G !== -1 && (W = U.slice(0, G), U = U.slice(G + 3));
257
- let K = U.indexOf("/");
258
- K !== -1 && (U = U.slice(0, K));
259
- let q = U, J, Y = q.lastIndexOf(":");
260
- Y !== -1 && (J = q.slice(Y + 1), q = q.slice(0, Y));
261
- let X = q.split(".");
262
- for (let f of X) if (f.includes("*") && f !== "*") return !1;
263
- let Z = f.protocol.replace(/:$/u, "");
264
- if (W && W !== Z || J !== void 0 && J !== "*" && J !== f.port) return !1;
265
- let Q = parseOriginRaw(V), $ = (Q ? Q.host : f.hostname).split(".");
266
- if (X.length !== $.length) return !1;
267
- for (let f = X.length - 1; f >= 0; --f) {
268
- let V = X[f], H = $[f];
269
- if (V !== "*" && V !== H) return !1;
270
- }
271
- return !0;
272
- }
273
- const DEFAULT_METHODS = {
274
- ton: ["ton_sendMessage", "ton_signData"],
275
- solana: [
276
- "solana_signMessage",
277
- "solana_signTransaction",
278
- "solana_requestAccounts",
279
- "solana_getAccounts",
280
- "solana_signAllTransactions",
281
- "solana_signAndSendTransaction"
282
- ],
283
- eip155: [
284
- "eth_accounts",
285
- "eth_requestAccounts",
286
- "eth_sendRawTransaction",
287
- "eth_sign",
288
- "eth_signTransaction",
289
- "eth_signTypedData",
290
- "eth_signTypedData_v3",
291
- "eth_signTypedData_v4",
292
- "eth_sendTransaction",
293
- "personal_sign",
294
- "wallet_switchEthereumChain",
295
- "wallet_addEthereumChain",
296
- "wallet_getPermissions",
297
- "wallet_requestPermissions",
298
- "wallet_registerOnboarding",
299
- "wallet_watchAsset",
300
- "wallet_scanQRCode",
301
- "wallet_getCallsStatus",
302
- "wallet_showCallsStatus",
303
- "wallet_sendCalls",
304
- "wallet_getCapabilities",
305
- "wallet_grantPermissions",
306
- "wallet_revokePermissions",
307
- "wallet_getAssets"
308
- ],
309
- bip122: [
310
- "sendTransfer",
311
- "signMessage",
312
- "signPsbt",
313
- "getAccountAddresses"
314
- ]
315
- }, WcHelpersUtil = {
316
- RPC_ERROR_CODE: {
317
- USER_REJECTED: 5e3,
318
- USER_REJECTED_METHODS: 5002
319
- },
320
- getMethodsByChainNamespace(f) {
321
- return DEFAULT_METHODS[f] || [];
322
- },
323
- createDefaultNamespace(f) {
324
- return {
325
- methods: this.getMethodsByChainNamespace(f),
326
- events: ["accountsChanged", "chainChanged"],
327
- chains: [],
328
- rpcMap: {}
329
- };
330
- },
331
- applyNamespaceOverrides(f, V) {
332
- if (!V) return { ...f };
333
- let H = { ...f }, U = /* @__PURE__ */ new Set();
334
- if (V.methods && Object.keys(V.methods).forEach((f) => U.add(f)), V.chains && Object.keys(V.chains).forEach((f) => U.add(f)), V.events && Object.keys(V.events).forEach((f) => U.add(f)), V.rpcMap && Object.keys(V.rpcMap).forEach((f) => {
335
- let [V] = f.split(":");
336
- V && U.add(V);
337
- }), U.forEach((f) => {
338
- H[f] || (H[f] = this.createDefaultNamespace(f));
339
- }), V.methods && Object.entries(V.methods).forEach(([f, V]) => {
340
- H[f] && (H[f].methods = V);
341
- }), V.chains && Object.entries(V.chains).forEach(([f, V]) => {
342
- H[f] && (H[f].chains = V);
343
- }), V.events && Object.entries(V.events).forEach(([f, V]) => {
344
- H[f] && (H[f].events = V);
345
- }), V.rpcMap) {
346
- let f = /* @__PURE__ */ new Set();
347
- Object.entries(V.rpcMap).forEach(([V, U]) => {
348
- let [W, G] = V.split(":");
349
- !W || !G || !H[W] || (H[W].rpcMap || (H[W].rpcMap = {}), f.has(W) || (H[W].rpcMap = {}, f.add(W)), H[W].rpcMap[G] = U);
350
- });
351
- }
352
- return H;
353
- },
354
- createNamespaces(f, V) {
355
- let H = f.reduce((f, V) => {
356
- let { id: H, chainNamespace: U, rpcUrls: W } = V, G = W.default.http[0];
357
- f[U] || (f[U] = this.createDefaultNamespace(U));
358
- let K = `${U}:${H}`, q = f[U];
359
- switch (q.chains.push(K), K) {
360
- case "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp":
361
- q.chains.push("solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ");
362
- break;
363
- case "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1":
364
- q.chains.push("solana:8E9rvCKLFQia2Y35HXjjpWzj8weVo44K");
365
- break;
366
- default:
367
- }
368
- return q?.rpcMap && G && (q.rpcMap[H] = G), f;
369
- }, {});
370
- return this.applyNamespaceOverrides(H, V);
371
- },
372
- resolveReownName: async (f) => {
373
- let V = await EnsController.resolveName(f);
374
- return (V?.addresses ? Object.values(V.addresses) : [])[0]?.address || !1;
375
- },
376
- getChainsFromNamespaces(f = {}) {
377
- return Object.values(f).flatMap((f) => {
378
- let V = f.chains || [], H = f.accounts.map((f) => {
379
- let [V, H] = f.split(":");
380
- return `${V}:${H}`;
381
- });
382
- return Array.from(new Set([...V, ...H]));
383
- });
384
- },
385
- isSessionEventData(f) {
386
- return typeof f == "object" && !!f && "id" in f && "topic" in f && "params" in f && typeof f.params == "object" && f.params !== null && "chainId" in f.params && "event" in f.params && typeof f.params.event == "object" && f.params.event !== null;
387
- },
388
- isUserRejectedRequestError(f) {
389
- try {
390
- if (typeof f == "object" && f) {
391
- let V = f, H = typeof V.code == "number", U = H && V.code === WcHelpersUtil.RPC_ERROR_CODE.USER_REJECTED_METHODS, W = H && V.code === WcHelpersUtil.RPC_ERROR_CODE.USER_REJECTED;
392
- return U || W;
393
- }
394
- return !1;
395
- } catch {
396
- return !1;
397
- }
398
- },
399
- isOriginAllowed(f, V, H) {
400
- let U = [...V, ...H];
401
- if (V.length === 0) return !0;
402
- let W = parseUrl(f);
403
- if (!W) return U.some((V) => !V.includes("*") && V === f);
404
- if (W.hostname === "localhost" || W.hostname === "127.0.0.1") return !0;
405
- for (let V of U) if (V.includes("*")) {
406
- if (matchWildcardPattern(W, f, V)) return !0;
407
- } else if (matchNonWildcardPattern(f, V)) return !0;
408
- return !1;
409
- },
410
- listenWcProvider({ universalProvider: f, namespace: V, onConnect: H, onDisconnect: U, onAccountsChanged: W, onChainChanged: G, onDisplayUri: K }) {
411
- H && f.on("connect", () => {
412
- H(WcHelpersUtil.getWalletConnectAccounts(f, V));
413
- }), U && f.on("disconnect", () => {
414
- U();
415
- }), W && f.on("accountsChanged", (H) => {
416
- try {
417
- let U = f.session?.namespaces?.[V]?.accounts || [], G = f.rpcProviders?.[V]?.getDefaultChain(), K = H.map((f) => {
418
- let H = U.find((H) => H.includes(`${V}:${G}:${f}`));
419
- if (!H) return;
420
- let { chainId: W, chainNamespace: K } = ParseUtil.parseCaipAddress(H);
421
- return {
422
- address: f,
423
- chainId: W,
424
- chainNamespace: K
425
- };
426
- }).filter((f) => f !== void 0);
427
- K.length > 0 && W(K);
428
- } catch (f) {
429
- console.warn("Failed to parse accounts for namespace on accountsChanged event", V, H, f);
430
- }
431
- }), G && f.on("chainChanged", (f) => {
432
- G(f);
433
- }), K && f.on("display_uri", (f) => {
434
- K(f);
435
- });
436
- },
437
- getWalletConnectAccounts(f, V) {
438
- let H = /* @__PURE__ */ new Set(), U = f?.session?.namespaces?.[V]?.accounts?.map((f) => ParseUtil.parseCaipAddress(f)).filter(({ address: f }) => H.has(f.toLowerCase()) ? !1 : (H.add(f.toLowerCase()), !0));
439
- return U && U.length > 0 ? U : [];
440
- }
441
- };
442
- var IGNORED_CONNECTOR_IDS_FOR_LISTENER = [ConstantsUtil.CONNECTOR_ID.AUTH, ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT], AdapterBlueprint = class {
443
- constructor(f) {
444
- this.availableConnectors = [], this.availableConnections = [], this.providerHandlers = {}, this.eventListeners = /* @__PURE__ */ new Map(), this.getCaipNetworks = (f) => ChainController.getCaipNetworks(f), this.getConnectorId = (f) => ConnectorController.getConnectorId(f), f && this.construct(f);
445
- }
446
- construct(f) {
447
- this.projectId = f.projectId, this.namespace = f.namespace, this.adapterType = f.adapterType;
448
- }
449
- get connectors() {
450
- return this.availableConnectors;
451
- }
452
- get connections() {
453
- return this.availableConnections;
454
- }
455
- get networks() {
456
- return this.getCaipNetworks(this.namespace);
457
- }
458
- onAuthConnected({ accounts: f, chainId: V }) {
459
- let H = this.getCaipNetworks().filter((f) => f.chainNamespace === this.namespace).find((f) => f.id.toString() === V?.toString());
460
- f && H && this.addConnection({
461
- connectorId: ConstantsUtil.CONNECTOR_ID.AUTH,
462
- accounts: f,
463
- caipNetwork: H
464
- });
465
- }
466
- setAuthProvider(f) {
467
- f.onConnect(this.onAuthConnected.bind(this)), f.onSocialConnected(this.onAuthConnected.bind(this)), this.addConnector({
468
- id: ConstantsUtil.CONNECTOR_ID.AUTH,
469
- type: "AUTH",
470
- name: ConstantsUtil.CONNECTOR_NAMES.AUTH,
471
- provider: f,
472
- imageId: void 0,
473
- chain: this.namespace,
474
- chains: []
475
- });
476
- }
477
- addConnector(...f) {
478
- let V = /* @__PURE__ */ new Set();
479
- this.availableConnectors = [...f, ...this.availableConnectors].filter((f) => V.has(f.id) ? !1 : (V.add(f.id), !0)), this.emit("connectors", this.availableConnectors);
480
- }
481
- addConnection(...f) {
482
- let V = /* @__PURE__ */ new Set();
483
- this.availableConnections = [...f, ...this.availableConnections].filter((f) => V.has(f.connectorId.toLowerCase()) ? !1 : (V.add(f.connectorId.toLowerCase()), !0)), this.emit("connections", this.availableConnections);
484
- }
485
- deleteConnection(f) {
486
- this.availableConnections = this.availableConnections.filter((V) => V.connectorId.toLowerCase() !== f.toLowerCase()), this.emit("connections", this.availableConnections);
487
- }
488
- clearConnections(f = !1) {
489
- this.availableConnections = [], f && this.emit("connections", this.availableConnections);
490
- }
491
- setStatus(f, V) {
492
- ChainController.setAccountProp("status", f, V);
493
- }
494
- on(f, V) {
495
- this.eventListeners.has(f) || this.eventListeners.set(f, /* @__PURE__ */ new Set()), this.eventListeners.get(f)?.add(V);
496
- }
497
- off(f, V) {
498
- let H = this.eventListeners.get(f);
499
- H && H.delete(V);
500
- }
501
- removeAllEventListeners() {
502
- this.eventListeners.forEach((f) => {
503
- f.clear();
504
- });
505
- }
506
- emit(f, V) {
507
- let H = this.eventListeners.get(f);
508
- H && H.forEach((f) => f(V));
509
- }
510
- async connectWalletConnect(f) {
511
- try {
512
- return { clientId: (await this.getWalletConnectConnector().connectWalletConnect()).clientId };
513
- } catch (f) {
514
- throw WcHelpersUtil.isUserRejectedRequestError(f) ? new UserRejectedRequestError(f) : f;
515
- }
516
- }
517
- async switchNetwork(f) {
518
- let { caipNetwork: V } = f, H = ProviderController.getProviderId(V.chainNamespace), U = ProviderController.getProvider(V.chainNamespace);
519
- if (!U) throw Error("Provider not found");
520
- if (H === "WALLET_CONNECT") {
521
- U.setDefaultChain(V.caipNetworkId);
522
- return;
523
- }
524
- if (H === "AUTH") {
525
- let f = ConnectorController.getAuthConnector()?.provider;
526
- if (!f) throw Error("Auth provider not found");
527
- let H = getPreferredAccountType(V.chainNamespace);
528
- await f.switchNetwork({ chainId: V.caipNetworkId });
529
- let U = await f.getUser({
530
- chainId: V.caipNetworkId,
531
- preferredAccountType: H
532
- });
533
- this.emit("switchNetwork", U);
534
- }
535
- }
536
- getWalletConnectConnector() {
537
- let f = this.connectors.find((f) => f.id === "walletConnect");
538
- if (!f) throw Error("WalletConnectConnector not found");
539
- return f;
540
- }
541
- onConnect(f, V) {
542
- if (f.length > 0) {
543
- let { address: H, chainId: U } = CoreHelperUtil.getAccount(f[0]), W = this.getCaipNetworks().filter((f) => f.chainNamespace === this.namespace).find((f) => f.id.toString() === U?.toString()), G = this.connectors.find((f) => f.id === V);
544
- H && (this.emit("accountChanged", {
545
- address: H,
546
- chainId: U,
547
- connector: G
548
- }), this.addConnection({
549
- connectorId: V,
550
- accounts: f.map((f) => {
551
- let { address: V } = CoreHelperUtil.getAccount(f);
552
- return { address: V };
553
- }),
554
- caipNetwork: W
555
- }));
556
- }
557
- }
558
- onAccountsChanged(f, V, H = !0) {
559
- if (f.length > 0) {
560
- let { address: H } = CoreHelperUtil.getAccount(f[0]), U = this.getConnection({
561
- connectorId: V,
562
- connections: this.connections,
563
- connectors: this.connectors
564
- });
565
- H && this.getConnectorId(ConstantsUtil.CHAIN.EVM)?.toLowerCase() === V.toLowerCase() && this.emit("accountChanged", {
566
- address: H,
567
- chainId: U?.caipNetwork?.id,
568
- connector: U?.connector
569
- }), this.addConnection({
570
- connectorId: V,
571
- accounts: f.map((f) => {
572
- let { address: V } = CoreHelperUtil.getAccount(f);
573
- return { address: V };
574
- }),
575
- caipNetwork: U?.caipNetwork
576
- });
577
- } else H && this.onDisconnect(V);
578
- }
579
- onDisconnect(f) {
580
- this.removeProviderListeners(f), this.deleteConnection(f), this.getConnectorId(ConstantsUtil.CHAIN.EVM)?.toLowerCase() === f.toLowerCase() && this.emitFirstAvailableConnection(), this.connections.length === 0 && this.emit("disconnect");
581
- }
582
- onChainChanged(f, V) {
583
- let H = typeof f == "string" && f.startsWith("0x") ? parseInt(f, 16).toString() : f.toString(), U = this.getConnection({
584
- connectorId: V,
585
- connections: this.connections,
586
- connectors: this.connectors
587
- }), W = this.getCaipNetworks().filter((f) => f.chainNamespace === this.namespace).find((f) => f.id.toString() === H);
588
- U && this.addConnection({
589
- connectorId: V,
590
- accounts: U.accounts,
591
- caipNetwork: W
592
- }), this.getConnectorId(ConstantsUtil.CHAIN.EVM)?.toLowerCase() === V.toLowerCase() && this.emit("switchNetwork", { chainId: H });
593
- }
594
- listenProviderEvents(f, V) {
595
- if (IGNORED_CONNECTOR_IDS_FOR_LISTENER.includes(f)) return;
596
- let H = (V) => this.onAccountsChanged(V, f), U = (V) => this.onChainChanged(V, f), W = () => this.onDisconnect(f);
597
- this.providerHandlers[f] || (V.on("disconnect", W), V.on("accountsChanged", H), V.on("chainChanged", U), this.providerHandlers[f] = {
598
- provider: V,
599
- disconnect: W,
600
- accountsChanged: H,
601
- chainChanged: U
602
- });
603
- }
604
- removeProviderListeners(f) {
605
- if (this.providerHandlers[f]) {
606
- let { provider: V, disconnect: H, accountsChanged: U, chainChanged: W } = this.providerHandlers[f];
607
- V.removeListener("disconnect", H), V.removeListener("accountsChanged", U), V.removeListener("chainChanged", W), this.providerHandlers[f] = null;
608
- }
609
- }
610
- emitFirstAvailableConnection() {
611
- let f = this.getConnection({
612
- connections: this.connections,
613
- connectors: this.connectors
614
- });
615
- if (f) {
616
- let [V] = f.accounts;
617
- this.emit("accountChanged", {
618
- address: V?.address,
619
- chainId: f.caipNetwork?.id,
620
- connector: f.connector
621
- });
622
- }
623
- }
624
- getConnection({ address: f, connectorId: V, connections: H, connectors: U }) {
625
- if (V) {
626
- let W = H.find((f) => f.connectorId.toLowerCase() === V.toLowerCase());
627
- if (!W) return null;
628
- let G = U.find((f) => f.id.toLowerCase() === W.connectorId.toLowerCase()), K = f ? W.accounts.find((V) => V.address.toLowerCase() === f.toLowerCase()) : W.accounts[0];
629
- return {
630
- ...W,
631
- account: K,
632
- connector: G
633
- };
634
- }
635
- let W = H.find((f) => f.accounts.length > 0 && U.some((V) => V.id.toLowerCase() === f.connectorId.toLowerCase()));
636
- if (W) {
637
- let [f] = W.accounts, V = U.find((f) => f.id.toLowerCase() === W.connectorId.toLowerCase());
638
- return {
639
- ...W,
640
- account: f,
641
- connector: V
642
- };
643
- }
644
- return null;
645
- }
646
- }, WalletConnectConnector = class {
647
- constructor({ provider: f, namespace: V }) {
648
- this.id = ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT, this.name = "WalletConnect", this.type = "WALLET_CONNECT", this.imageId = "ef1a1fcf-7fe8-4d69-bd6d-fda1345b4400", this.getCaipNetworks = ChainController.getCaipNetworks.bind(ChainController), this.caipNetworks = this.getCaipNetworks(), this.provider = f, this.chain = V;
649
- }
650
- get chains() {
651
- return this.getCaipNetworks();
652
- }
653
- async connectWalletConnect() {
654
- if (!await this.authenticate()) {
655
- let f = this.getCaipNetworks(), V = OptionsController.state.universalProviderConfigOverride, H = WcHelpersUtil.createNamespaces(f, V);
656
- await this.provider.connect({ optionalNamespaces: H });
657
- }
658
- return {
659
- clientId: await this.provider.client.core.crypto.getClientId(),
660
- session: this.provider.session
661
- };
662
- }
663
- async disconnect() {
664
- await this.provider.disconnect();
665
- }
666
- async authenticate() {
667
- let f = this.chains.map((f) => f.caipNetworkId);
668
- return SIWXUtil.universalProviderAuthenticate({
669
- universalProvider: this.provider,
670
- chains: f,
671
- methods: OPTIONAL_METHODS
672
- });
673
- }
674
- }, OPTIONAL_METHODS = [
675
- "eth_accounts",
676
- "eth_requestAccounts",
677
- "eth_sendRawTransaction",
678
- "eth_sign",
679
- "eth_signTransaction",
680
- "eth_signTypedData",
681
- "eth_signTypedData_v3",
682
- "eth_signTypedData_v4",
683
- "eth_sendTransaction",
684
- "personal_sign",
685
- "wallet_switchEthereumChain",
686
- "wallet_addEthereumChain",
687
- "wallet_getPermissions",
688
- "wallet_requestPermissions",
689
- "wallet_registerOnboarding",
690
- "wallet_watchAsset",
691
- "wallet_scanQRCode",
692
- "wallet_getCallsStatus",
693
- "wallet_sendCalls",
694
- "wallet_getCapabilities",
695
- "wallet_grantPermissions",
696
- "wallet_revokePermissions",
697
- "wallet_getAssets"
698
- ];
699
- const baseUSDC = {
700
- network: "eip155:8453",
701
- asset: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
702
- metadata: {
703
- name: "USD Coin",
704
- symbol: "USDC",
705
- decimals: 6
706
- }
707
- }, baseSepoliaUSDC = {
708
- network: "eip155:84532",
709
- asset: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
710
- metadata: {
711
- name: "USD Coin",
712
- symbol: "USDC",
713
- decimals: 6
714
- }
715
- }, ErrorUtil = {
716
- EmbeddedWalletAbortController: new AbortController(),
717
- UniversalProviderErrors: {
718
- UNAUTHORIZED_DOMAIN_NOT_ALLOWED: {
719
- message: "Unauthorized: origin not allowed",
720
- alertErrorKey: "ORIGIN_NOT_ALLOWED"
721
- },
722
- JWT_VALIDATION_ERROR: {
723
- message: "JWT validation error: JWT Token is not yet valid",
724
- alertErrorKey: "JWT_TOKEN_NOT_VALID"
725
- },
726
- INVALID_KEY: {
727
- message: "Unauthorized: invalid key",
728
- alertErrorKey: "INVALID_PROJECT_ID"
729
- }
730
- },
731
- ALERT_ERRORS: {
732
- SWITCH_NETWORK_NOT_FOUND: {
733
- code: "APKT001",
734
- displayMessage: "Network Not Found",
735
- debugMessage: "The specified network is not recognized. Please ensure it is included in the `networks` array of your `createAppKit` configuration."
736
- },
737
- ORIGIN_NOT_ALLOWED: {
738
- code: "APKT002",
739
- displayMessage: "Invalid App Configuration",
740
- debugMessage: () => `The origin ${isSafe() ? window.origin : "unknown"} is not in your allow list. Please update your allowed domains at https://dashboard.reown.com. [PID: ${OptionsController.state.projectId}]`
741
- },
742
- IFRAME_LOAD_FAILED: {
743
- code: "APKT003",
744
- displayMessage: "Network Error: Wallet Load Failed",
745
- debugMessage: () => "Failed to load the embedded wallet. This may be due to network issues or server downtime. Please check your network connection and try again shortly. Contact support if the issue persists."
746
- },
747
- IFRAME_REQUEST_TIMEOUT: {
748
- code: "APKT004",
749
- displayMessage: "Wallet Request Timeout",
750
- debugMessage: () => "The request to the embedded wallet timed out. Please check your network connection and try again shortly. Contact support if the issue persists."
751
- },
752
- UNVERIFIED_DOMAIN: {
753
- code: "APKT005",
754
- displayMessage: "Unverified Domain",
755
- debugMessage: () => "Embedded wallet load failed. Ensure your domain is verified in https://dashboard.reown.com."
756
- },
757
- JWT_TOKEN_NOT_VALID: {
758
- code: "APKT006",
759
- displayMessage: "Session Expired",
760
- debugMessage: "Your session is invalid or expired. Please check your system’s date and time settings, then reconnect."
761
- },
762
- INVALID_PROJECT_ID: {
763
- code: "APKT007",
764
- displayMessage: "Invalid Project ID",
765
- debugMessage: "The specified project ID is invalid. Please visit https://dashboard.reown.com to obtain a valid project ID."
766
- },
767
- PROJECT_ID_NOT_CONFIGURED: {
768
- code: "APKT008",
769
- displayMessage: "Project ID Missing",
770
- debugMessage: "No project ID is configured. You can create and configure a project ID at https://dashboard.reown.com."
771
- },
772
- SERVER_ERROR_APP_CONFIGURATION: {
773
- code: "APKT009",
774
- displayMessage: "Server Error",
775
- debugMessage: (f) => `Unable to fetch App Configuration. ${f}. Please check your network connection and try again shortly. Contact support if the issue persists.`
776
- },
777
- RATE_LIMITED_APP_CONFIGURATION: {
778
- code: "APKT010",
779
- displayMessage: "Rate Limited",
780
- debugMessage: "You have been rate limited while retrieving App Configuration. Please wait a few minutes and try again. Contact support if the issue persists."
781
- }
782
- },
783
- ALERT_WARNINGS: {
784
- LOCAL_CONFIGURATION_IGNORED: { debugMessage: (f) => `[Reown Config Notice] ${f}` },
785
- INACTIVE_NAMESPACE_NOT_CONNECTED: {
786
- code: "APKTW001",
787
- displayMessage: "Inactive Namespace Not Connected",
788
- debugMessage: (f, V) => `An error occurred while connecting an inactive namespace ${f}: "${V}"`
789
- },
790
- INVALID_EMAIL: {
791
- code: "APKTW002",
792
- displayMessage: "Invalid Email Address",
793
- debugMessage: "Please enter a valid email address"
794
- }
795
- }
796
- }, TokenUtil = {
797
- TOKEN_ADDRESSES_BY_SYMBOL: { USDC: {
798
- 8453: baseUSDC.asset,
799
- 84532: baseSepoliaUSDC.asset
800
- } },
801
- getTokenSymbolByAddress(f) {
802
- if (!f) return;
803
- let [V] = Object.entries(TokenUtil.TOKEN_ADDRESSES_BY_SYMBOL).find(([V, H]) => Object.values(H).includes(f)) ?? [];
804
- return V;
805
- }
806
- }, LoggerUtil = { createLogger(f, U = "error") {
807
- let { logger: W } = Ue({ opts: Ge({ level: U }) });
808
- return W.error = (...V) => {
809
- for (let H of V) if (H instanceof Error) {
810
- f(H, ...V);
811
- return;
812
- }
813
- f(void 0, ...V);
814
- }, W;
815
- } }, WcConstantsUtil = {
816
- ERROR_CODE_UNRECOGNIZED_CHAIN_ID: 4902,
817
- ERROR_CODE_DEFAULT: 5e3,
818
- ERROR_INVALID_CHAIN_ID: 32603
819
- };
820
- var UniversalAdapter = class extends AdapterBlueprint {
821
- async setUniversalProvider(f) {
822
- if (!this.namespace) throw Error("UniversalAdapter:setUniversalProvider - namespace is required");
823
- return this.addConnector(new WalletConnectConnector({
824
- provider: f,
825
- caipNetworks: this.getCaipNetworks(),
826
- namespace: this.namespace
827
- })), Promise.resolve();
828
- }
829
- async connect(f) {
830
- return Promise.resolve({
831
- id: "WALLET_CONNECT",
832
- type: "WALLET_CONNECT",
833
- chainId: Number(f.chainId),
834
- provider: this.provider,
835
- address: ""
836
- });
837
- }
838
- async disconnect() {
839
- try {
840
- await this.getWalletConnectConnector().disconnect(), this.emit("disconnect");
841
- } catch (f) {
842
- console.warn("UniversalAdapter:disconnect - error", f);
843
- }
844
- return { connections: [] };
845
- }
846
- syncConnections() {
847
- return Promise.resolve();
848
- }
849
- async writeSolanaTransaction() {
850
- return Promise.resolve({ hash: "" });
851
- }
852
- async getAccounts({ namespace: f }) {
853
- let V = this.provider?.session?.namespaces?.[f]?.accounts?.map((f) => {
854
- let [, , V] = f.split(":");
855
- return V;
856
- }).filter((f, V, H) => H.indexOf(f) === V) || [];
857
- return Promise.resolve({ accounts: V.map((V) => CoreHelperUtil.createAccount(f, V, f === "bip122" ? "payment" : "eoa")) });
858
- }
859
- async syncConnectors() {
860
- return Promise.resolve();
861
- }
862
- async getBalance(f) {
863
- if (!(f.caipNetwork && ConstantsUtil$1.BALANCE_SUPPORTED_CHAINS.includes(f.caipNetwork?.chainNamespace)) || f.caipNetwork?.testnet) return {
864
- balance: "0.00",
865
- symbol: f.caipNetwork?.nativeCurrency.symbol || ""
866
- };
867
- let V = ChainController.getAccountData();
868
- if (V?.balanceLoading && f.chainId === ChainController.state.activeCaipNetwork?.id) return {
869
- balance: V?.balance || "0.00",
870
- symbol: V?.balanceSymbol || ""
871
- };
872
- let H = (await ChainController.fetchTokenBalance()).find((V) => V.chainId === `${f.caipNetwork?.chainNamespace}:${f.chainId}` && V.symbol === f.caipNetwork?.nativeCurrency.symbol);
873
- return {
874
- balance: H?.quantity.numeric || "0.00",
875
- symbol: H?.symbol || f.caipNetwork?.nativeCurrency.symbol || ""
876
- };
877
- }
878
- async signMessage(V) {
879
- let { provider: H, message: U, address: W } = V;
880
- if (!H) throw Error("UniversalAdapter:signMessage - provider is undefined");
881
- let G = "";
882
- return G = ChainController.state.activeCaipNetwork?.chainNamespace === ConstantsUtil.CHAIN.SOLANA ? (await H.request({
883
- method: "solana_signMessage",
884
- params: {
885
- message: esm_default.encode(new TextEncoder().encode(U)),
886
- pubkey: W
887
- }
888
- }, ChainController.state.activeCaipNetwork?.caipNetworkId)).signature : await H.request({
889
- method: "personal_sign",
890
- params: [U, W]
891
- }, ChainController.state.activeCaipNetwork?.caipNetworkId), { signature: G };
892
- }
893
- async estimateGas() {
894
- return Promise.resolve({ gas: BigInt(0) });
895
- }
896
- async sendTransaction() {
897
- return Promise.resolve({ hash: "" });
898
- }
899
- walletGetAssets(f) {
900
- return Promise.resolve({});
901
- }
902
- async writeContract() {
903
- return Promise.resolve({ hash: "" });
904
- }
905
- emitFirstAvailableConnection() {}
906
- parseUnits() {
907
- return 0n;
908
- }
909
- formatUnits() {
910
- return "0";
911
- }
912
- async getCapabilities() {
913
- return Promise.resolve({});
914
- }
915
- async grantPermissions() {
916
- return Promise.resolve({});
917
- }
918
- async revokePermissions() {
919
- return Promise.resolve("0x");
920
- }
921
- async syncConnection() {
922
- return Promise.resolve({
923
- id: "WALLET_CONNECT",
924
- type: "WALLET_CONNECT",
925
- chainId: 1,
926
- provider: this.provider,
927
- address: ""
928
- });
929
- }
930
- async switchNetwork(f) {
931
- let { caipNetwork: V } = f, H = this.getWalletConnectConnector();
932
- if (V.chainNamespace === ConstantsUtil.CHAIN.EVM) try {
933
- await H.provider?.request({
934
- method: "wallet_switchEthereumChain",
935
- params: [{ chainId: toHex(V.id) }]
936
- });
937
- } catch (f) {
938
- if (f.code === WcConstantsUtil.ERROR_CODE_UNRECOGNIZED_CHAIN_ID || f.code === WcConstantsUtil.ERROR_INVALID_CHAIN_ID || f.code === WcConstantsUtil.ERROR_CODE_DEFAULT || f?.data?.originalError?.code === WcConstantsUtil.ERROR_CODE_UNRECOGNIZED_CHAIN_ID) try {
939
- await H.provider?.request({
940
- method: "wallet_addEthereumChain",
941
- params: [{
942
- chainId: toHex(V.id),
943
- rpcUrls: [V?.rpcUrls.chainDefault?.http],
944
- chainName: V.name,
945
- nativeCurrency: V.nativeCurrency,
946
- blockExplorerUrls: [V.blockExplorers?.default.url]
947
- }]
948
- });
949
- } catch {
950
- throw Error("Chain is not supported");
951
- }
952
- }
953
- H.provider.setDefaultChain(V.caipNetworkId);
954
- }
955
- getWalletConnectProvider() {
956
- return this.connectors.find((f) => f.type === "WALLET_CONNECT")?.provider;
957
- }
958
- }, FEATURE_KEYS = [
959
- "email",
960
- "socials",
961
- "swaps",
962
- "onramp",
963
- "activity",
964
- "reownBranding",
965
- "multiWallet",
966
- "emailCapture",
967
- "payWithExchange",
968
- "payments",
969
- "reownAuthentication",
970
- "headless"
971
- ], featureConfig = {
972
- email: {
973
- apiFeatureName: "social_login",
974
- localFeatureName: "email",
975
- returnType: !1,
976
- isLegacy: !1,
977
- isAvailableOnBasic: !1,
978
- processApi: (f) => {
979
- if (!f?.config) return !1;
980
- let V = f.config;
981
- return !!f.isEnabled && V.includes("email");
982
- },
983
- processFallback: (f) => f === void 0 ? ConstantsUtil$1.DEFAULT_REMOTE_FEATURES.email : !!f
984
- },
985
- socials: {
986
- apiFeatureName: "social_login",
987
- localFeatureName: "socials",
988
- returnType: !1,
989
- isLegacy: !1,
990
- isAvailableOnBasic: !1,
991
- processApi: (f) => {
992
- if (!f?.config) return !1;
993
- let V = f.config;
994
- return f.isEnabled && V.length > 0 ? V.filter((f) => f !== "email") : !1;
995
- },
996
- processFallback: (f) => f === void 0 ? ConstantsUtil$1.DEFAULT_REMOTE_FEATURES.socials : typeof f == "boolean" ? f ? ConstantsUtil$1.DEFAULT_REMOTE_FEATURES.socials : !1 : f
997
- },
998
- swaps: {
999
- apiFeatureName: "swap",
1000
- localFeatureName: "swaps",
1001
- returnType: !1,
1002
- isLegacy: !1,
1003
- isAvailableOnBasic: !1,
1004
- processApi: (f) => {
1005
- if (!f?.config) return !1;
1006
- let V = f.config;
1007
- return f.isEnabled && V.length > 0 ? V : !1;
1008
- },
1009
- processFallback: (f) => f === void 0 ? ConstantsUtil$1.DEFAULT_REMOTE_FEATURES.swaps : typeof f == "boolean" ? f ? ConstantsUtil$1.DEFAULT_REMOTE_FEATURES.swaps : !1 : f
1010
- },
1011
- onramp: {
1012
- apiFeatureName: "onramp",
1013
- localFeatureName: "onramp",
1014
- returnType: !1,
1015
- isLegacy: !1,
1016
- isAvailableOnBasic: !1,
1017
- processApi: (f) => {
1018
- if (!f?.config) return !1;
1019
- let V = f.config;
1020
- return f.isEnabled && V.length > 0 ? V : !1;
1021
- },
1022
- processFallback: (f) => f === void 0 ? ConstantsUtil$1.DEFAULT_REMOTE_FEATURES.onramp : typeof f == "boolean" ? f ? ConstantsUtil$1.DEFAULT_REMOTE_FEATURES.onramp : !1 : f
1023
- },
1024
- activity: {
1025
- apiFeatureName: "activity",
1026
- localFeatureName: "history",
1027
- returnType: !1,
1028
- isLegacy: !0,
1029
- isAvailableOnBasic: !1,
1030
- processApi: (f) => !!f.isEnabled,
1031
- processFallback: (f) => f === void 0 ? ConstantsUtil$1.DEFAULT_REMOTE_FEATURES.activity : !!f
1032
- },
1033
- reownBranding: {
1034
- apiFeatureName: "reown_branding",
1035
- localFeatureName: "reownBranding",
1036
- returnType: !1,
1037
- isLegacy: !1,
1038
- isAvailableOnBasic: !1,
1039
- processApi: (f) => !!f.isEnabled,
1040
- processFallback: (f) => f === void 0 ? ConstantsUtil$1.DEFAULT_REMOTE_FEATURES.reownBranding : !!f
1041
- },
1042
- emailCapture: {
1043
- apiFeatureName: "email_capture",
1044
- localFeatureName: "emailCapture",
1045
- returnType: !1,
1046
- isLegacy: !1,
1047
- isAvailableOnBasic: !1,
1048
- processApi: (f) => f.isEnabled && (f.config ?? []),
1049
- processFallback: (f) => !1
1050
- },
1051
- multiWallet: {
1052
- apiFeatureName: "multi_wallet",
1053
- localFeatureName: "multiWallet",
1054
- returnType: !1,
1055
- isLegacy: !1,
1056
- isAvailableOnBasic: !1,
1057
- processApi: (f) => !!f.isEnabled,
1058
- processFallback: () => ConstantsUtil$1.DEFAULT_REMOTE_FEATURES.multiWallet
1059
- },
1060
- payWithExchange: {
1061
- apiFeatureName: "fund_from_exchange",
1062
- localFeatureName: "payWithExchange",
1063
- returnType: !1,
1064
- isLegacy: !1,
1065
- isAvailableOnBasic: !1,
1066
- processApi: (f) => !!f.isEnabled,
1067
- processFallback: () => ConstantsUtil$1.DEFAULT_REMOTE_FEATURES.payWithExchange
1068
- },
1069
- payments: {
1070
- apiFeatureName: "payments",
1071
- localFeatureName: "payments",
1072
- returnType: !1,
1073
- isLegacy: !1,
1074
- isAvailableOnBasic: !1,
1075
- processApi: (f) => !!f.isEnabled,
1076
- processFallback: () => ConstantsUtil$1.DEFAULT_REMOTE_FEATURES.payments
1077
- },
1078
- reownAuthentication: {
1079
- apiFeatureName: "reown_authentication",
1080
- localFeatureName: "reownAuthentication",
1081
- returnType: !1,
1082
- isLegacy: !1,
1083
- isAvailableOnBasic: !1,
1084
- processApi: (f) => !!f.isEnabled,
1085
- processFallback: (f) => f === void 0 ? ConstantsUtil$1.DEFAULT_REMOTE_FEATURES.reownAuthentication : !!f
1086
- },
1087
- headless: {
1088
- apiFeatureName: "headless",
1089
- localFeatureName: "headless",
1090
- returnType: !1,
1091
- isLegacy: !1,
1092
- isAvailableOnBasic: !1,
1093
- processApi: (f) => !!f.isEnabled,
1094
- processFallback: () => ConstantsUtil$1.DEFAULT_REMOTE_FEATURES.headless
1095
- }
1096
- };
1097
- const ConfigUtil = {
1098
- localSettingsOverridden: /* @__PURE__ */ new Set(),
1099
- getApiConfig(f, V) {
1100
- return V?.find((V) => V.id === f);
1101
- },
1102
- addWarning(f, V) {
1103
- if (f !== void 0) {
1104
- let f = featureConfig[V], H = f.isLegacy ? `"features.${f.localFeatureName}" (now "${V}")` : `"features.${V}"`;
1105
- this.localSettingsOverridden.add(H);
1106
- }
1107
- },
1108
- processFeature(f, V, H, U, W) {
1109
- let G = featureConfig[f], K = V[G.localFeatureName];
1110
- if (W && !G.isAvailableOnBasic) return !1;
1111
- if (U) {
1112
- let V = this.getApiConfig(G.apiFeatureName, H);
1113
- return V?.config === null ? this.processFallbackFeature(f, K) : V?.config ? (K !== void 0 && this.addWarning(K, f), this.processApiFeature(f, V)) : !1;
1114
- }
1115
- return this.processFallbackFeature(f, K);
1116
- },
1117
- processApiFeature(f, V) {
1118
- return featureConfig[f].processApi(V);
1119
- },
1120
- processFallbackFeature(f, V) {
1121
- return featureConfig[f].processFallback(V);
1122
- },
1123
- async fetchRemoteFeatures(f) {
1124
- let V = f.basic ?? !1, H = f.features || {};
1125
- this.localSettingsOverridden.clear();
1126
- let U = null, W = !1;
1127
- try {
1128
- U = await ApiController.fetchProjectConfig(), W = U != null;
1129
- } catch (f) {
1130
- console.warn("[Reown Config] Failed to fetch remote project configuration. Using local/default values.", f);
1131
- }
1132
- let G = W && !V ? ConstantsUtil$1.DEFAULT_REMOTE_FEATURES : ConstantsUtil$1.DEFAULT_REMOTE_FEATURES_DISABLED;
1133
- try {
1134
- for (let f of FEATURE_KEYS) {
1135
- let K = this.processFeature(f, H, U, W, V);
1136
- Object.assign(G, { [f]: K });
1137
- }
1138
- } catch (f) {
1139
- return console.warn("[Reown Config] Failed to process the configuration from Cloud. Using default values.", f), ConstantsUtil$1.DEFAULT_REMOTE_FEATURES;
1140
- }
1141
- if (W && this.localSettingsOverridden.size > 0) {
1142
- let f = `Your local configuration for ${Array.from(this.localSettingsOverridden).join(", ")} was ignored because a remote configuration was successfully fetched. Please manage these features via your project dashboard on dashboard.reown.com.`;
1143
- AlertController.open({ debugMessage: ErrorUtil.ALERT_WARNINGS.LOCAL_CONFIGURATION_IGNORED.debugMessage(f) }, "warning");
1144
- }
1145
- return G;
1146
- }
1147
- };
1148
- var AppKitBaseClient = class {
1149
- constructor(f) {
1150
- this.chainNamespaces = [], this.features = {}, this.remoteFeatures = {}, this.reportedAlertErrors = {}, this.getCaipNetwork = (f, V) => f ? ChainController.getCaipNetworks(f)?.find((f) => f.id === V) || ChainController.getNetworkData(f)?.caipNetwork || ChainController.getRequestedCaipNetworks(f).filter((V) => V.chainNamespace === f)?.[0] : ChainController.state.activeCaipNetwork || this.defaultCaipNetwork, this.getCaipNetworkId = () => {
1151
- let f = this.getCaipNetwork();
1152
- if (f) return f.id;
1153
- }, this.getCaipNetworks = (f) => ChainController.getCaipNetworks(f), this.getActiveChainNamespace = () => ChainController.state.activeChain, this.setRequestedCaipNetworks = (f, V) => {
1154
- ChainController.setRequestedCaipNetworks(f, V);
1155
- }, this.getApprovedCaipNetworkIds = () => ChainController.getAllApprovedCaipNetworkIds(), this.getCaipAddress = (f) => ChainController.state.activeChain === f || !f ? ChainController.state.activeCaipAddress : ChainController.state.chains.get(f)?.accountState?.caipAddress, this.setClientId = (f) => {
1156
- BlockchainApiController.setClientId(f);
1157
- }, this.getProvider = (f) => ProviderController.getProvider(f), this.getProviderType = (f) => ProviderController.getProviderId(f), this.getPreferredAccountType = (f) => getPreferredAccountType(f), this.setCaipAddress = (f, V, H = !1) => {
1158
- ChainController.setAccountProp("caipAddress", f, V, H), ChainController.setAccountProp("address", CoreHelperUtil.getPlainAddress(f), V, H);
1159
- }, this.setBalance = (f, V, H) => {
1160
- ChainController.setAccountProp("balance", f, H), ChainController.setAccountProp("balanceSymbol", V, H);
1161
- }, this.setProfileName = (f, V) => {
1162
- ChainController.setAccountProp("profileName", f, V);
1163
- }, this.setProfileImage = (f, V) => {
1164
- ChainController.setAccountProp("profileImage", f, V);
1165
- }, this.setUser = (f, V) => {
1166
- ChainController.setAccountProp("user", f, V);
1167
- }, this.resetAccount = (f) => {
1168
- ChainController.resetAccount(f);
1169
- }, this.setCaipNetwork = (f) => {
1170
- ChainController.setActiveCaipNetwork(f);
1171
- }, this.setCaipNetworkOfNamespace = (f, V) => {
1172
- ChainController.setChainNetworkData(V, { caipNetwork: f });
1173
- }, this.setStatus = (f, V) => {
1174
- ChainController.setAccountProp("status", f, V), ConnectorController.isConnected() ? StorageUtil.setConnectionStatus("connected") : StorageUtil.setConnectionStatus("disconnected");
1175
- }, this.getAddressByChainNamespace = (f) => ChainController.getAccountData(f)?.address, this.setConnectors = (f) => {
1176
- let V = [...ConnectorController.state.allConnectors, ...f];
1177
- ConnectorController.setConnectors(V);
1178
- }, this.setConnections = (f, V) => {
1179
- StorageUtil.setConnections(f, V), ConnectionController.setConnections(f, V);
1180
- }, this.fetchIdentity = (f) => BlockchainApiController.fetchIdentity(f), this.getReownName = (f) => EnsController.getNamesForAddress(f), this.getConnectors = () => ConnectorController.getConnectors(), this.getConnectorImage = (f) => AssetUtil.getConnectorImage(f), this.getConnections = (f) => this.remoteFeatures.multiWallet ? ConnectionControllerUtil.getConnectionsData(f).connections : (AlertController.open(ConstantsUtil.REMOTE_FEATURES_ALERTS.MULTI_WALLET_NOT_ENABLED.DEFAULT, "info"), []), this.getRecentConnections = (f) => this.remoteFeatures.multiWallet ? ConnectionControllerUtil.getConnectionsData(f).recentConnections : (AlertController.open(ConstantsUtil.REMOTE_FEATURES_ALERTS.MULTI_WALLET_NOT_ENABLED.DEFAULT, "info"), []), this.switchConnection = async (f) => {
1181
- if (!this.remoteFeatures.multiWallet) {
1182
- AlertController.open(ConstantsUtil.REMOTE_FEATURES_ALERTS.MULTI_WALLET_NOT_ENABLED.DEFAULT, "info");
1183
- return;
1184
- }
1185
- await ConnectionController.switchConnection(f);
1186
- }, this.deleteConnection = (f) => {
1187
- if (!this.remoteFeatures.multiWallet) {
1188
- AlertController.open(ConstantsUtil.REMOTE_FEATURES_ALERTS.MULTI_WALLET_NOT_ENABLED.DEFAULT, "info");
1189
- return;
1190
- }
1191
- StorageUtil.deleteAddressFromConnection(f), ConnectionController.syncStorageConnections();
1192
- }, this.setConnectedWalletInfo = (f, V) => {
1193
- let H = ProviderController.getProviderId(V), U = f ? {
1194
- ...f,
1195
- type: H
1196
- } : void 0;
1197
- ChainController.setAccountProp("connectedWalletInfo", U, V);
1198
- }, this.getIsConnectedState = () => !!ChainController.state.activeCaipAddress, this.addAddressLabel = (f, V, H) => {
1199
- let U = ChainController.getAccountData(H)?.addressLabels || {};
1200
- ChainController.setAccountProp("addressLabels", {
1201
- ...U,
1202
- [f]: V
1203
- }, H);
1204
- }, this.removeAddressLabel = (f, V) => {
1205
- let H = ChainController.getAccountData(V)?.addressLabels || {};
1206
- ChainController.setAccountProp("addressLabels", {
1207
- ...H,
1208
- [f]: void 0
1209
- }, V);
1210
- }, this.getAddress = (f) => {
1211
- let V = f || ChainController.state.activeChain;
1212
- return ChainController.getAccountData(V)?.address;
1213
- }, this.resetNetwork = (f) => {
1214
- ChainController.resetNetwork(f);
1215
- }, this.addConnector = (f) => {
1216
- ConnectorController.addConnector(f);
1217
- }, this.resetWcConnection = () => {
1218
- ConnectionController.resetWcConnection();
1219
- }, this.setAddressExplorerUrl = (f, V) => {
1220
- ChainController.setAccountProp("addressExplorerUrl", f, V);
1221
- }, this.setSmartAccountDeployed = (f, V) => {
1222
- ChainController.setAccountProp("smartAccountDeployed", f, V);
1223
- }, this.setPreferredAccountType = (f, V) => {
1224
- ChainController.setAccountProp("preferredAccountType", f, V);
1225
- }, this.setEIP6963Enabled = (f) => {
1226
- OptionsController.setEIP6963Enabled(f);
1227
- }, this.handleUnsafeRPCRequest = () => {
1228
- if (this.isOpen()) {
1229
- if (this.isTransactionStackEmpty()) return;
1230
- this.redirect("ApproveTransaction");
1231
- } else this.open({ view: "ApproveTransaction" });
1232
- }, this.options = f, this.version = f.sdkVersion, this.caipNetworks = this.extendCaipNetworks(f), this.chainNamespaces = this.getChainNamespacesSet(f.adapters, this.caipNetworks), this.defaultCaipNetwork = this.extendDefaultCaipNetwork(f), this.chainAdapters = this.createAdapters(f.adapters), this.readyPromise = this.initialize(f);
1233
- }
1234
- getChainNamespacesSet(f, V) {
1235
- let H = f?.map((f) => f.namespace).filter((f) => !!f);
1236
- if (H?.length) return [...new Set(H)];
1237
- let U = V?.map((f) => f.chainNamespace);
1238
- return [...new Set(U)];
1239
- }
1240
- async initialize(f) {
1241
- if (this.initializeProjectSettings(f), this.initControllers(f), await this.initChainAdapters(), this.sendInitializeEvent(f), f.features?.headless && !ConnectorUtil.hasInjectedConnectors() && ApiController.prefetch({
1242
- fetchNetworkImages: !1,
1243
- fetchConnectorImages: !1,
1244
- fetchWalletRanks: !1,
1245
- fetchRecommendedWallets: !0
1246
- }), OptionsController.state.enableReconnect ? (await this.syncExistingConnection(), await this.syncAdapterConnections()) : await this.unSyncExistingConnection(), !f.basic && !f.manualWCControl && (this.remoteFeatures = await ConfigUtil.fetchRemoteFeatures(f)), await ApiController.fetchUsage(), OptionsController.setRemoteFeatures(this.remoteFeatures), this.remoteFeatures.onramp && OnRampController.setOnrampProviders(this.remoteFeatures.onramp), (OptionsController.state.remoteFeatures?.email || Array.isArray(OptionsController.state.remoteFeatures?.socials) && OptionsController.state.remoteFeatures?.socials.length > 0) && await this.checkAllowedOrigins(), OptionsController.state.features?.reownAuthentication || OptionsController.state.remoteFeatures?.reownAuthentication) {
1247
- let { ReownAuthentication: f } = await import("./features-_5Pi-gXV.js"), V = OptionsController.state.siwx;
1248
- V instanceof f || (V && console.warn("ReownAuthentication option is enabled, SIWX configuration will be overridden."), OptionsController.setSIWX(new f()));
1249
- }
1250
- }
1251
- async openSend(f) {
1252
- let V = f.namespace || ChainController.state.activeChain, H = this.getCaipAddress(V), U = this.getCaipNetwork(V)?.id;
1253
- if (!H) throw Error("openSend: caipAddress not found");
1254
- if (U?.toString() !== f.chainId.toString()) {
1255
- let H = ChainController.getCaipNetworkById(f.chainId, V);
1256
- if (!H) throw Error(`openSend: caipNetwork with chainId ${f.chainId} not found`);
1257
- await this.switchNetwork(H, { throwOnFailure: !0 });
1258
- }
1259
- try {
1260
- let V = TokenUtil.getTokenSymbolByAddress(f.assetAddress);
1261
- V && await ApiController.fetchTokenImages([V]);
1262
- } catch {}
1263
- return await ModalController.open({
1264
- view: "WalletSend",
1265
- data: { send: f }
1266
- }), new Promise((f, V) => {
1267
- let H = SendController.subscribeKey("hash", (V) => {
1268
- V && (W(), f({ hash: V }));
1269
- }), U = ModalController.subscribe((f) => {
1270
- f.open || (W(), V(/* @__PURE__ */ Error("Modal closed")));
1271
- }), W = this.createCleanupHandler([H, U]);
1272
- });
1273
- }
1274
- toModalOptions() {
1275
- function f(f) {
1276
- return f?.view === "Swap";
1277
- }
1278
- function V(f) {
1279
- return f?.view === "WalletSend";
1280
- }
1281
- return {
1282
- isSwap: f,
1283
- isSend: V
1284
- };
1285
- }
1286
- async checkAllowedOrigins() {
1287
- try {
1288
- let f = await ApiController.fetchAllowedOrigins();
1289
- if (!CoreHelperUtil.isClient()) return;
1290
- let V = window.location.origin;
1291
- WcHelpersUtil.isOriginAllowed(V, f, ConstantsUtil.DEFAULT_ALLOWED_ANCESTORS) || AlertController.open(ErrorUtil.ALERT_ERRORS.ORIGIN_NOT_ALLOWED, "error");
1292
- } catch (f) {
1293
- if (!(f instanceof Error)) return;
1294
- switch (f.message) {
1295
- case "RATE_LIMITED":
1296
- AlertController.open(ErrorUtil.ALERT_ERRORS.RATE_LIMITED_APP_CONFIGURATION, "error");
1297
- break;
1298
- case "SERVER_ERROR": {
1299
- let V = f.cause instanceof Error ? f.cause : f;
1300
- AlertController.open({
1301
- displayMessage: ErrorUtil.ALERT_ERRORS.SERVER_ERROR_APP_CONFIGURATION.displayMessage,
1302
- debugMessage: ErrorUtil.ALERT_ERRORS.SERVER_ERROR_APP_CONFIGURATION.debugMessage(V.message)
1303
- }, "error");
1304
- break;
1305
- }
1306
- default: break;
1307
- }
1308
- }
1309
- }
1310
- createCleanupHandler(f) {
1311
- return () => {
1312
- f.forEach((f) => {
1313
- try {
1314
- f();
1315
- } catch {}
1316
- });
1317
- };
1318
- }
1319
- sendInitializeEvent(f) {
1320
- let { ...V } = f;
1321
- delete V.adapters, delete V.universalProvider, EventsController.sendEvent({
1322
- type: "track",
1323
- event: "INITIALIZE",
1324
- properties: {
1325
- ...V,
1326
- networks: f.networks.map((f) => f.id),
1327
- siweConfig: { options: f.siweConfig?.options || {} }
1328
- }
1329
- });
1330
- }
1331
- initControllers(f) {
1332
- this.initializeOptionsController(f), this.initializeChainController(f), this.initializeThemeController(f), this.initializeConnectionController(f), this.initializeConnectorController();
1333
- }
1334
- initAdapterController() {
1335
- AdapterController.initialize(this.chainAdapters);
1336
- }
1337
- initializeThemeController(f) {
1338
- f.themeMode && ThemeController.setThemeMode(f.themeMode), f.themeVariables && ThemeController.setThemeVariables(f.themeVariables);
1339
- }
1340
- initializeChainController(f) {
1341
- if (!this.connectionControllerClient) throw Error("ConnectionControllerClient must be set");
1342
- ChainController.initialize(f.adapters ?? [], this.caipNetworks, { connectionControllerClient: this.connectionControllerClient });
1343
- let V = this.getDefaultNetwork();
1344
- V && ChainController.setActiveCaipNetwork(V);
1345
- }
1346
- initializeConnectionController(f) {
1347
- ConnectionController.initialize(f.adapters ?? []), ConnectionController.setWcBasic(f.basic ?? !1);
1348
- }
1349
- initializeConnectorController() {
1350
- ConnectorController.initialize(this.chainNamespaces);
1351
- }
1352
- initializeProjectSettings(f) {
1353
- OptionsController.setProjectId(f.projectId), OptionsController.setSdkVersion(f.sdkVersion);
1354
- }
1355
- initializeOptionsController(f) {
1356
- OptionsController.setDebug(f.debug !== !1), OptionsController.setEnableWalletGuide(f.enableWalletGuide !== !1), OptionsController.setEnableWallets(f.enableWallets !== !1), OptionsController.setEIP6963Enabled(f.enableEIP6963 !== !1), OptionsController.setEnableNetworkSwitch(f.enableNetworkSwitch !== !1), OptionsController.setEnableReconnect(f.enableReconnect !== !1), OptionsController.setEnableMobileFullScreen(f.enableMobileFullScreen === !0), OptionsController.setCoinbasePreference(f.coinbasePreference), OptionsController.setEnableAuthLogger(f.enableAuthLogger !== !1), OptionsController.setCustomRpcUrls(f.customRpcUrls), OptionsController.setEnableEmbedded(f.enableEmbedded), OptionsController.setAllWallets(f.allWallets), OptionsController.setIncludeWalletIds(f.includeWalletIds), OptionsController.setExcludeWalletIds(f.excludeWalletIds), OptionsController.setFeaturedWalletIds(f.featuredWalletIds), OptionsController.setTokens(f.tokens), OptionsController.setTermsConditionsUrl(f.termsConditionsUrl), OptionsController.setPrivacyPolicyUrl(f.privacyPolicyUrl), OptionsController.setCustomWallets(f.customWallets), OptionsController.setFeatures(f.features), OptionsController.setAllowUnsupportedChain(f.allowUnsupportedChain), OptionsController.setUniversalProviderConfigOverride(f.universalProviderConfigOverride), OptionsController.setPreferUniversalLinks(f.experimental_preferUniversalLinks), OptionsController.setDefaultAccountTypes(f.defaultAccountTypes);
1357
- let V = this.getDefaultMetaData();
1358
- if (!f.metadata && V && (f.metadata = V), OptionsController.setMetadata(f.metadata), OptionsController.setDisableAppend(f.disableAppend), OptionsController.setEnableEmbedded(f.enableEmbedded), OptionsController.setSIWX(f.siwx), this.features = OptionsController.state.features ?? {}, !f.projectId) {
1359
- AlertController.open(ErrorUtil.ALERT_ERRORS.PROJECT_ID_NOT_CONFIGURED, "error");
1360
- return;
1361
- }
1362
- if (f.adapters?.find((f) => f.namespace === ConstantsUtil.CHAIN.EVM) && f.siweConfig) {
1363
- if (f.siwx) throw Error("Cannot set both `siweConfig` and `siwx` options");
1364
- OptionsController.setSIWX(f.siweConfig.mapToSIWX());
1365
- }
1366
- }
1367
- getDefaultMetaData() {
1368
- return CoreHelperUtil.isClient() ? {
1369
- name: document.getElementsByTagName("title")?.[0]?.textContent || "",
1370
- description: document.querySelector("meta[property=\"og:description\"]")?.content || "",
1371
- url: window.location.origin,
1372
- icons: [document.querySelector("link[rel~=\"icon\"]")?.href || ""]
1373
- } : null;
1374
- }
1375
- setUnsupportedNetwork(f) {
1376
- let V = this.getActiveChainNamespace();
1377
- if (V) {
1378
- let H = CaipNetworksUtil.getUnsupportedNetwork(`${V}:${f}`);
1379
- ChainController.setActiveCaipNetwork(H);
1380
- }
1381
- }
1382
- getDefaultNetwork() {
1383
- return CaipNetworksUtil.getCaipNetworkFromStorage(this.defaultCaipNetwork);
1384
- }
1385
- extendCaipNetwork(f, V) {
1386
- return CaipNetworksUtil.extendCaipNetwork(f, {
1387
- customNetworkImageUrls: V.chainImages,
1388
- projectId: V.projectId
1389
- });
1390
- }
1391
- extendCaipNetworks(f) {
1392
- return CaipNetworksUtil.extendCaipNetworks(f.networks, {
1393
- customNetworkImageUrls: f.chainImages,
1394
- customRpcUrls: f.customRpcUrls,
1395
- projectId: f.projectId
1396
- });
1397
- }
1398
- extendDefaultCaipNetwork(f) {
1399
- let V = f.networks.find((V) => V.id === f.defaultNetwork?.id);
1400
- return V ? CaipNetworksUtil.extendCaipNetwork(V, {
1401
- customNetworkImageUrls: f.chainImages,
1402
- customRpcUrls: f.customRpcUrls,
1403
- projectId: f.projectId
1404
- }) : void 0;
1405
- }
1406
- async disconnectConnector(f, V) {
1407
- try {
1408
- this.setLoading(!0, f);
1409
- let H = { connections: [] }, U = this.getAdapter(f);
1410
- return (ChainController.state.chains.get(f)?.accountState?.caipAddress || !OptionsController.state.enableReconnect) && U?.disconnect && (H = await U.disconnect({ id: V })), this.setLoading(!1, f), H;
1411
- } catch (V) {
1412
- throw this.setLoading(!1, f), Error(`Failed to disconnect chains: ${V.message}`);
1413
- }
1414
- }
1415
- createClients() {
1416
- this.connectionControllerClient = {
1417
- connectWalletConnect: async () => {
1418
- let f = ChainController.state.activeChain, V = this.getAdapter(f), H = this.getCaipNetwork(f)?.id, U = ConnectionController.getConnections(f), W = this.remoteFeatures.multiWallet, G = U.length > 0;
1419
- if (!V) throw Error("Adapter not found");
1420
- let K = await V.connectWalletConnect(H);
1421
- (!G || !W) && this.close(), this.setClientId(K?.clientId || null), StorageUtil.setConnectedNamespaces([...ChainController.state.chains.keys()]), await this.syncWalletConnectAccount(), await SIWXUtil.initializeIfEnabled();
1422
- },
1423
- connectExternal: async (f) => {
1424
- let V = await this.onConnectExternal(f);
1425
- return await this.connectInactiveNamespaces(f, V), V ? { address: V.address } : void 0;
1426
- },
1427
- reconnectExternal: async ({ id: f, info: V, type: H, provider: U }) => {
1428
- let W = ChainController.state.activeChain, G = this.getAdapter(W);
1429
- if (!W) throw Error("reconnectExternal: namespace not found");
1430
- if (!G) throw Error("reconnectExternal: adapter not found");
1431
- G?.reconnect && (await G?.reconnect({
1432
- id: f,
1433
- info: V,
1434
- type: H,
1435
- provider: U,
1436
- chainId: this.getCaipNetwork()?.id
1437
- }), StorageUtil.addConnectedNamespace(W), this.syncConnectedWalletInfo(W));
1438
- },
1439
- disconnectConnector: async (f) => {
1440
- await this.disconnectConnector(f.namespace, f.id);
1441
- },
1442
- disconnect: async (f) => {
1443
- let { id: V, chainNamespace: H, initialDisconnect: U } = f || {}, W = H || ChainController.state.activeChain, G = ConnectorController.getConnectorId(W), q = V === ConstantsUtil.CONNECTOR_ID.AUTH || G === ConstantsUtil.CONNECTOR_ID.AUTH, Y = V === ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT || G === ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT;
1444
- try {
1445
- let f = Array.from(ChainController.state.chains.keys()), W = H ? [H] : f;
1446
- (Y || q) && (W = f);
1447
- let G = W.map(async (f) => {
1448
- let H = ConnectorController.getConnectorId(f), W = V || H, G = await this.disconnectConnector(f, W);
1449
- G && (q && StorageUtil.deleteConnectedSocialProvider(), G.connections.forEach((V) => {
1450
- StorageUtil.addDisconnectedConnectorId(V.connectorId, f);
1451
- })), U && this.onDisconnectNamespace({
1452
- chainNamespace: f,
1453
- closeModal: !1
1454
- });
1455
- }), K = await Promise.allSettled(G);
1456
- SendController.resetSend(), ConnectionController.resetWcConnection(), SIWXUtil.getSIWX()?.signOutOnDisconnect && await SIWXUtil.clearSessions(), ConnectorController.setFilterByNamespace(void 0), ConnectionController.syncStorageConnections();
1457
- let X = K.filter((f) => f.status === "rejected");
1458
- if (X.length > 0) throw Error(X.map((f) => f.reason.message).join(", "));
1459
- EventsController.sendEvent({
1460
- type: "track",
1461
- event: "DISCONNECT_SUCCESS",
1462
- properties: { namespace: H || "all" }
1463
- });
1464
- } catch (f) {
1465
- throw Error(`Failed to disconnect chains: ${f.message}`);
1466
- }
1467
- },
1468
- checkInstalled: (f) => f ? f.some((f) => !!window.ethereum?.[String(f)]) : !!window.ethereum,
1469
- signMessage: async (f) => {
1470
- let V = ChainController.state.activeChain, H = this.getAdapter(ChainController.state.activeChain);
1471
- if (!V) throw Error("signMessage: namespace not found");
1472
- if (!H) throw Error("signMessage: adapter not found");
1473
- let U = this.getAddress(V);
1474
- if (!U) throw Error("signMessage: address not found");
1475
- return (await H?.signMessage({
1476
- message: f,
1477
- address: U,
1478
- provider: ProviderController.getProvider(V)
1479
- }))?.signature || "";
1480
- },
1481
- sendTransaction: async (f) => {
1482
- let V = f.chainNamespace;
1483
- if (!V) throw Error("sendTransaction: namespace not found");
1484
- if (ConstantsUtil$1.SEND_SUPPORTED_NAMESPACES.includes(V)) {
1485
- let H = this.getAdapter(V);
1486
- if (!H) throw Error("sendTransaction: adapter not found");
1487
- let U = ProviderController.getProvider(V);
1488
- return (await H?.sendTransaction({
1489
- ...f,
1490
- caipNetwork: this.getCaipNetwork(),
1491
- provider: U
1492
- }))?.hash || "";
1493
- }
1494
- return "";
1495
- },
1496
- estimateGas: async (f) => {
1497
- let V = f.chainNamespace;
1498
- if (V === ConstantsUtil.CHAIN.EVM) {
1499
- let H = this.getAdapter(V);
1500
- if (!H) throw Error("estimateGas: adapter is required but got undefined");
1501
- let U = ProviderController.getProvider(V), W = this.getCaipNetwork();
1502
- if (!W) throw Error("estimateGas: caipNetwork is required but got undefined");
1503
- return (await H?.estimateGas({
1504
- ...f,
1505
- provider: U,
1506
- caipNetwork: W
1507
- }))?.gas || 0n;
1508
- }
1509
- return 0n;
1510
- },
1511
- getEnsAvatar: async () => {
1512
- let f = ChainController.state.activeChain;
1513
- if (!f) throw Error("getEnsAvatar: namespace is required but got undefined");
1514
- let V = this.getAddress(f);
1515
- if (!V) throw Error("getEnsAvatar: address not found");
1516
- return await this.syncIdentity({
1517
- address: V,
1518
- chainId: Number(this.getCaipNetwork()?.id),
1519
- chainNamespace: f
1520
- }), ChainController.getAccountData()?.profileImage || !1;
1521
- },
1522
- getEnsAddress: async (f) => await WcHelpersUtil.resolveReownName(f),
1523
- writeContract: async (f) => {
1524
- let V = ChainController.state.activeChain, H = this.getAdapter(V);
1525
- if (!V) throw Error("writeContract: namespace is required but got undefined");
1526
- if (!H) throw Error("writeContract: adapter is required but got undefined");
1527
- let U = this.getCaipNetwork(), W = this.getCaipAddress(), G = ProviderController.getProvider(V);
1528
- if (!U || !W) throw Error("writeContract: caipNetwork or caipAddress is required but got undefined");
1529
- return (await H?.writeContract({
1530
- ...f,
1531
- caipNetwork: U,
1532
- provider: G,
1533
- caipAddress: W
1534
- }))?.hash;
1535
- },
1536
- writeSolanaTransaction: async (f) => {
1537
- let V = ChainController.state.activeChain, H = this.getAdapter(V);
1538
- if (!V) throw Error("writeContract: namespace is required but got undefined");
1539
- if (!H) throw Error("writeContract: adapter is required but got undefined");
1540
- let U = this.getCaipNetwork(), W = this.getCaipAddress(), G = ProviderController.getProvider(V);
1541
- if (!U || !W) throw Error("writeContract: caipNetwork or caipAddress is required but got undefined");
1542
- return (await H?.writeSolanaTransaction({
1543
- ...f,
1544
- caipNetwork: U,
1545
- provider: G,
1546
- caipAddress: W
1547
- }))?.hash;
1548
- },
1549
- parseUnits: (f, V) => {
1550
- let H = this.getAdapter(ChainController.state.activeChain);
1551
- if (!H) throw Error("parseUnits: adapter is required but got undefined");
1552
- return H?.parseUnits({
1553
- value: f,
1554
- decimals: V
1555
- }) ?? 0n;
1556
- },
1557
- formatUnits: (f, V) => {
1558
- let H = this.getAdapter(ChainController.state.activeChain);
1559
- if (!H) throw Error("formatUnits: adapter is required but got undefined");
1560
- return H?.formatUnits({
1561
- value: f,
1562
- decimals: V
1563
- }) ?? "0";
1564
- },
1565
- getCapabilities: async (f) => {
1566
- let V = this.getAdapter(ChainController.state.activeChain);
1567
- if (!V) throw Error("getCapabilities: adapter is required but got undefined");
1568
- return await V?.getCapabilities(f);
1569
- },
1570
- grantPermissions: async (f) => {
1571
- let V = this.getAdapter(ChainController.state.activeChain);
1572
- if (!V) throw Error("grantPermissions: adapter is required but got undefined");
1573
- return await V?.grantPermissions(f);
1574
- },
1575
- revokePermissions: async (f) => {
1576
- let V = this.getAdapter(ChainController.state.activeChain);
1577
- if (!V) throw Error("revokePermissions: adapter is required but got undefined");
1578
- return V?.revokePermissions ? await V.revokePermissions(f) : "0x";
1579
- },
1580
- walletGetAssets: async (f) => {
1581
- let V = this.getAdapter(ChainController.state.activeChain);
1582
- if (!V) throw Error("walletGetAssets: adapter is required but got undefined");
1583
- return await V?.walletGetAssets(f) ?? {};
1584
- },
1585
- updateBalance: (f) => {
1586
- let V = this.getAddress(f), H = this.getCaipNetwork(f);
1587
- !H || !V || this.updateNativeBalance(V, H?.id, f);
1588
- }
1589
- }, ConnectionController.setClient(this.connectionControllerClient);
1590
- }
1591
- async onConnectExternal(f) {
1592
- let V = ChainController.state.activeChain, H = f.chain || V, U = this.getAdapter(H), W = !0;
1593
- if (f.type === ConstantsUtil$2.CONNECTOR_TYPE_AUTH && ConstantsUtil.AUTH_CONNECTOR_SUPPORTED_CHAINS.some((f) => ConnectorController.getConnectorId(f) === ConstantsUtil.CONNECTOR_ID.AUTH) && f.chain !== V && (W = !1), f.chain && f.chain !== V && !f.caipNetwork) {
1594
- let V = this.getCaipNetworks().find((V) => V.chainNamespace === f.chain);
1595
- V && W && this.setCaipNetwork(V);
1596
- }
1597
- if (!H) throw Error("connectExternal: namespace not found");
1598
- if (!U) throw Error("connectExternal: adapter not found");
1599
- let G = this.getCaipNetwork(H), q = f.caipNetwork || G, Y = await U.connect({
1600
- id: f.id,
1601
- address: f.address,
1602
- info: f.info,
1603
- type: f.type,
1604
- provider: f.provider,
1605
- socialUri: f.socialUri,
1606
- chainId: f.caipNetwork?.id || G?.id,
1607
- rpcUrl: f.caipNetwork?.rpcUrls?.default?.http?.[0] || G?.rpcUrls?.default?.http?.[0]
1608
- });
1609
- if (Y) return StorageUtil.addConnectedNamespace(H), this.syncProvider({
1610
- ...Y,
1611
- chainNamespace: H
1612
- }), this.setStatus("connected", H), this.syncConnectedWalletInfo(H), StorageUtil.removeDisconnectedConnectorId(f.id, H), {
1613
- address: Y.address,
1614
- connectedCaipNetwork: q
1615
- };
1616
- }
1617
- async connectInactiveNamespaces(f, V) {
1618
- let H = f.type === ConstantsUtil$2.CONNECTOR_TYPE_AUTH, U = HelpersUtil.getOtherAuthNamespaces(V?.connectedCaipNetwork?.chainNamespace), W = ChainController.state.activeCaipNetwork, G = this.getAdapter(W?.chainNamespace);
1619
- H && (await Promise.all(U.map(async (V) => {
1620
- try {
1621
- let H = ProviderController.getProvider(V), U = this.getCaipNetwork(V);
1622
- await this.getAdapter(V)?.connect({
1623
- ...f,
1624
- provider: H,
1625
- socialUri: void 0,
1626
- chainId: U?.id,
1627
- rpcUrl: U?.rpcUrls?.default?.http?.[0]
1628
- }) && (StorageUtil.addConnectedNamespace(V), StorageUtil.removeDisconnectedConnectorId(f.id, V), this.setStatus("connected", V), this.syncConnectedWalletInfo(V));
1629
- } catch (f) {
1630
- AlertController.warn(ErrorUtil.ALERT_WARNINGS.INACTIVE_NAMESPACE_NOT_CONNECTED.displayMessage, ErrorUtil.ALERT_WARNINGS.INACTIVE_NAMESPACE_NOT_CONNECTED.debugMessage(V, f instanceof Error ? f.message : void 0), ErrorUtil.ALERT_WARNINGS.INACTIVE_NAMESPACE_NOT_CONNECTED.code);
1631
- }
1632
- })), W && await G?.switchNetwork({ caipNetwork: W }));
1633
- }
1634
- getApprovedCaipNetworksData() {
1635
- if (ProviderController.getProviderId(ChainController.state.activeChain) === ConstantsUtil$2.CONNECTOR_TYPE_WALLET_CONNECT) {
1636
- let f = this.universalProvider?.session?.namespaces;
1637
- return {
1638
- supportsAllNetworks: this.universalProvider?.session?.peer?.metadata.name === "MetaMask Wallet",
1639
- approvedCaipNetworkIds: this.getChainsFromNamespaces(f)
1640
- };
1641
- }
1642
- return {
1643
- supportsAllNetworks: !0,
1644
- approvedCaipNetworkIds: []
1645
- };
1646
- }
1647
- async switchCaipNetwork(f) {
1648
- let V = f.chainNamespace;
1649
- if (this.getAddressByChainNamespace(f.chainNamespace)) {
1650
- let H = ProviderController.getProviderId(V);
1651
- if (f.chainNamespace === ChainController.state.activeChain) await this.getAdapter(V)?.switchNetwork({ caipNetwork: f });
1652
- else if (this.setCaipNetwork(f), H === ConstantsUtil$2.CONNECTOR_TYPE_WALLET_CONNECT) this.syncWalletConnectAccount();
1653
- else {
1654
- let H = this.getAddressByChainNamespace(V);
1655
- H && this.syncAccount({
1656
- address: H,
1657
- chainId: f.id,
1658
- chainNamespace: V
1659
- });
1660
- }
1661
- } else this.setCaipNetwork(f);
1662
- }
1663
- getChainsFromNamespaces(f = {}) {
1664
- return Object.values(f).flatMap((f) => {
1665
- let V = f.chains || [], H = f.accounts.map((f) => {
1666
- let { chainId: V, chainNamespace: H } = ParseUtil.parseCaipAddress(f);
1667
- return `${H}:${V}`;
1668
- });
1669
- return Array.from(new Set([...V, ...H]));
1670
- });
1671
- }
1672
- createAdapters(f) {
1673
- return this.createClients(), this.chainNamespaces.reduce((V, H) => {
1674
- let U = f?.find((f) => f.namespace === H);
1675
- return U ? (U.construct({
1676
- namespace: H,
1677
- projectId: this.options?.projectId,
1678
- networks: this.caipNetworks?.filter(({ chainNamespace: f }) => f === H)
1679
- }), V[H] = U) : V[H] = new UniversalAdapter({
1680
- namespace: H,
1681
- networks: this.getCaipNetworks()
1682
- }), V;
1683
- }, {});
1684
- }
1685
- async initChainAdapter(f) {
1686
- this.onConnectors(f), this.listenAdapter(f);
1687
- let V = this.getAdapter(f);
1688
- if (!V) throw Error("adapter not found");
1689
- await V.syncConnectors(), await this.createUniversalProviderForAdapter(f);
1690
- }
1691
- async initChainAdapters() {
1692
- await Promise.all(this.chainNamespaces.map(async (f) => {
1693
- await this.initChainAdapter(f);
1694
- })), this.initAdapterController();
1695
- }
1696
- onConnectors(f) {
1697
- this.getAdapter(f)?.on("connectors", this.setConnectors.bind(this));
1698
- }
1699
- listenAdapter(f) {
1700
- let V = this.getAdapter(f);
1701
- if (!V) return;
1702
- let H = StorageUtil.getConnectionStatus();
1703
- OptionsController.state.enableReconnect === !1 ? this.setStatus("disconnected", f) : H === "connected" ? this.setStatus("connecting", f) : (H === "disconnected" && StorageUtil.clearAddressCache(), this.setStatus(H, f)), V.on("switchNetwork", ({ address: V, chainId: H }) => {
1704
- let U = this.getCaipNetworks().find((f) => f.id.toString() === H.toString() || f.caipNetworkId.toString() === H.toString()), W = ChainController.state.activeChain === f, G = ChainController.state.chains.get(f)?.accountState?.address;
1705
- if (U) {
1706
- let H = W && V ? V : G;
1707
- H && this.syncAccount({
1708
- address: H,
1709
- chainId: U.id,
1710
- chainNamespace: f
1711
- });
1712
- } else this.setUnsupportedNetwork(H);
1713
- }), V.on("disconnect", () => {
1714
- let V = this.remoteFeatures.multiWallet, H = Array.from(ConnectionController.state.connections.values()).flat();
1715
- this.onDisconnectNamespace({
1716
- chainNamespace: f,
1717
- closeModal: !V || H.length === 0
1718
- });
1719
- }), V.on("connections", (V) => {
1720
- this.setConnections(V, f);
1721
- }), V.on("pendingTransactions", () => {
1722
- let V = this.getAddress(f), H = ChainController.state.activeCaipNetwork;
1723
- !V || !H?.id || this.updateNativeBalance(V, H.id, H.chainNamespace);
1724
- }), V.on("accountChanged", ({ address: V, chainId: H, connector: U }) => {
1725
- this.handlePreviousConnectorConnection(U);
1726
- let W = ChainController.state.activeChain === f;
1727
- U?.provider && (this.syncProvider({
1728
- id: U.id,
1729
- type: U.type,
1730
- provider: U?.provider,
1731
- chainNamespace: f
1732
- }), this.syncConnectedWalletInfo(f));
1733
- let G = ChainController.getNetworkData(f)?.caipNetwork?.id, K = H || G;
1734
- W && K ? this.syncAccount({
1735
- address: V,
1736
- chainId: K,
1737
- chainNamespace: f
1738
- }) : !W && K ? (this.syncAccountInfo(V, K, f), this.syncBalance({
1739
- address: V,
1740
- chainId: K,
1741
- chainNamespace: f
1742
- })) : this.syncAccountInfo(V, H, f), StorageUtil.addConnectedNamespace(f);
1743
- });
1744
- }
1745
- async handlePreviousConnectorConnection(f) {
1746
- let V = f?.chain, H = f?.id, U = ConnectorController.getConnectorId(V), W = OptionsController.state.remoteFeatures?.multiWallet, G = V && H && U && U !== H && !W;
1747
- try {
1748
- G && await ConnectionController.disconnect({
1749
- id: U,
1750
- namespace: V
1751
- });
1752
- } catch (f) {
1753
- console.warn("Error disconnecting previous connector", f);
1754
- }
1755
- }
1756
- async createUniversalProviderForAdapter(f) {
1757
- await this.getUniversalProvider(), this.universalProvider && await this.chainAdapters?.[f]?.setUniversalProvider?.(this.universalProvider);
1758
- }
1759
- async syncExistingConnection() {
1760
- await Promise.allSettled(this.chainNamespaces.map((f) => this.syncNamespaceConnection(f)));
1761
- }
1762
- async unSyncExistingConnection() {
1763
- try {
1764
- await Promise.allSettled(this.chainNamespaces.map((f) => ConnectionController.disconnect({
1765
- namespace: f,
1766
- initialDisconnect: !0
1767
- })));
1768
- } catch (f) {
1769
- console.error("Error disconnecting existing connections:", f);
1770
- }
1771
- }
1772
- async reconnectWalletConnect() {
1773
- await this.syncWalletConnectAccount();
1774
- let f = this.getAddress();
1775
- this.getCaipAddress() || StorageUtil.deleteRecentWallet();
1776
- let V = StorageUtil.getRecentWallet();
1777
- EventsController.sendEvent({
1778
- type: "track",
1779
- event: "CONNECT_SUCCESS",
1780
- address: f,
1781
- properties: {
1782
- method: CoreHelperUtil.isMobile() ? "mobile" : "qrcode",
1783
- name: V?.name || "Unknown",
1784
- reconnect: !0,
1785
- view: RouterController.state.view,
1786
- walletRank: V?.order
1787
- }
1788
- });
1789
- }
1790
- async syncNamespaceConnection(f) {
1791
- try {
1792
- f === ConstantsUtil.CHAIN.EVM && CoreHelperUtil.isSafeApp() && ConnectorController.setConnectorId(ConstantsUtil.CONNECTOR_ID.SAFE, f);
1793
- let V = ConnectorController.getConnectorId(f);
1794
- switch (this.setStatus("connecting", f), V) {
1795
- case ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT:
1796
- await this.reconnectWalletConnect();
1797
- break;
1798
- case ConstantsUtil.CONNECTOR_ID.AUTH: break;
1799
- default: await this.syncAdapterConnection(f);
1800
- }
1801
- } catch (V) {
1802
- console.warn("AppKit couldn't sync existing connection", V), this.setStatus("disconnected", f);
1803
- }
1804
- }
1805
- onDisconnectNamespace(f) {
1806
- let { chainNamespace: V, closeModal: H } = f || {};
1807
- ChainController.resetAccount(V), ChainController.resetNetwork(V), StorageUtil.removeConnectedNamespace(V);
1808
- let U = Array.from(ChainController.state.chains.keys());
1809
- (V ? [V] : U).forEach((f) => StorageUtil.addDisconnectedConnectorId(ConnectorController.getConnectorId(f) || "", f)), ConnectorController.removeConnectorId(V), ProviderController.resetChain(V), this.setUser(null, V), this.setStatus("disconnected", V), this.setConnectedWalletInfo(null, V), H !== !1 && ModalController.close();
1810
- }
1811
- async syncAdapterConnections() {
1812
- await Promise.allSettled(this.chainNamespaces.map((f) => {
1813
- let V = this.getAdapter(f), H = this.getCaipAddress(f), U = this.getCaipNetwork(f);
1814
- return V?.syncConnections({
1815
- connectToFirstConnector: !H,
1816
- caipNetwork: U
1817
- });
1818
- }));
1819
- }
1820
- async syncAdapterConnection(f) {
1821
- let V = this.getAdapter(f), H = this.getCaipNetwork(f), U = ConnectorController.getConnectorId(f), W = ConnectorController.getConnectors(f).find((f) => f.id === U);
1822
- try {
1823
- if (!V || !W) throw Error(`Adapter or connector not found for namespace ${f}`);
1824
- if (!H?.id) throw Error("CaipNetwork not found");
1825
- let U = await V?.syncConnection({
1826
- namespace: f,
1827
- id: W.id,
1828
- chainId: H.id,
1829
- rpcUrl: H?.rpcUrls?.default?.http?.[0]
1830
- });
1831
- U ? (this.syncProvider({
1832
- ...U,
1833
- chainNamespace: f
1834
- }), await this.syncAccount({
1835
- ...U,
1836
- chainNamespace: f
1837
- }), this.setStatus("connected", f), EventsController.sendEvent({
1838
- type: "track",
1839
- event: "CONNECT_SUCCESS",
1840
- address: U.address,
1841
- properties: {
1842
- method: "browser",
1843
- name: W.info?.name || W.name || "Unknown",
1844
- reconnect: !0,
1845
- view: RouterController.state.view,
1846
- walletRank: W?.explorerWallet?.order
1847
- }
1848
- })) : this.setStatus("disconnected", f);
1849
- } catch {
1850
- this.onDisconnectNamespace({
1851
- chainNamespace: f,
1852
- closeModal: !1
1853
- });
1854
- }
1855
- }
1856
- async syncWalletConnectAccount() {
1857
- let f = Object.keys(this.universalProvider?.session?.namespaces || {}), V = this.chainNamespaces.map(async (V) => {
1858
- let H = this.getAdapter(V);
1859
- if (!H) return;
1860
- let U = this.universalProvider?.session?.namespaces?.[V]?.accounts || [], W = ChainController.state.activeCaipNetwork?.id, G = U.find((f) => {
1861
- let { chainId: V } = ParseUtil.parseCaipAddress(f);
1862
- return V === W?.toString();
1863
- }) || U[0];
1864
- if (G) {
1865
- let f = ParseUtil.validateCaipAddress(G), { chainId: U, address: W } = ParseUtil.parseCaipAddress(f);
1866
- if (ProviderController.setProviderId(V, ConstantsUtil$2.CONNECTOR_TYPE_WALLET_CONNECT), this.caipNetworks && ChainController.state.activeCaipNetwork && H.namespace !== ConstantsUtil.CHAIN.EVM) {
1867
- let f = H.getWalletConnectProvider({
1868
- caipNetworks: this.getCaipNetworks(),
1869
- provider: this.universalProvider,
1870
- activeCaipNetwork: ChainController.state.activeCaipNetwork
1871
- });
1872
- ProviderController.setProvider(V, f);
1873
- } else ProviderController.setProvider(V, this.universalProvider);
1874
- ConnectorController.setConnectorId(ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT, V), StorageUtil.addConnectedNamespace(V), await this.syncAccount({
1875
- address: W,
1876
- chainId: U,
1877
- chainNamespace: V
1878
- });
1879
- } else f.includes(V) && this.setStatus("disconnected", V);
1880
- let q = this.getApprovedCaipNetworksData();
1881
- this.syncConnectedWalletInfo(V), ChainController.setApprovedCaipNetworksData(V, {
1882
- approvedCaipNetworkIds: q.approvedCaipNetworkIds,
1883
- supportsAllNetworks: q.supportsAllNetworks
1884
- });
1885
- });
1886
- await Promise.all(V);
1887
- }
1888
- syncProvider({ type: f, provider: V, id: H, chainNamespace: U }) {
1889
- ProviderController.setProviderId(U, f), ProviderController.setProvider(U, V), ConnectorController.setConnectorId(H, U);
1890
- }
1891
- async syncAccount(f) {
1892
- let V = f.chainNamespace === ChainController.state.activeChain, H = ChainController.getCaipNetworkByNamespace(f.chainNamespace, f.chainId), { address: U, chainId: W, chainNamespace: G } = f, { chainId: q } = StorageUtil.getActiveNetworkProps(), Y = H?.id || q, X = ChainController.state.activeCaipNetwork?.name === ConstantsUtil.UNSUPPORTED_NETWORK_NAME, Z = ChainController.getNetworkProp("supportsAllNetworks", G);
1893
- if (this.setStatus("connected", G), !(X && !Z) && Y) {
1894
- let f = this.getCaipNetworks().find((f) => f.id.toString() === Y.toString()), q = this.getCaipNetworks().find((f) => f.chainNamespace === G);
1895
- if (!Z && !f && !q) {
1896
- let V = this.getApprovedCaipNetworkIds() || [], H = V.find((f) => ParseUtil.parseCaipNetworkId(f)?.chainId === Y.toString()), U = V.find((f) => ParseUtil.parseCaipNetworkId(f)?.chainNamespace === G);
1897
- f = this.getCaipNetworks().find((f) => f.caipNetworkId === H), q = this.getCaipNetworks().find((f) => f.caipNetworkId === U || "deprecatedCaipNetworkId" in f && f.deprecatedCaipNetworkId === U);
1898
- }
1899
- let J = f || q;
1900
- J?.chainNamespace === ChainController.state.activeChain ? OptionsController.state.enableNetworkSwitch && !OptionsController.state.allowUnsupportedChain && ChainController.state.activeCaipNetwork?.name === ConstantsUtil.UNSUPPORTED_NETWORK_NAME ? ChainController.showUnsupportedChainUI() : this.setCaipNetwork(J) : V || H && this.setCaipNetworkOfNamespace(H, G), this.syncConnectedWalletInfo(G);
1901
- let X = this.getAddress(G);
1902
- HelpersUtil.isLowerCaseMatch(U, X) || this.syncAccountInfo(U, J?.id, G), V ? await this.syncBalance({
1903
- address: U,
1904
- chainId: J?.id,
1905
- chainNamespace: G
1906
- }) : await this.syncBalance({
1907
- address: U,
1908
- chainId: H?.id,
1909
- chainNamespace: G
1910
- }), this.syncIdentity({
1911
- address: U,
1912
- chainId: W,
1913
- chainNamespace: G
1914
- });
1915
- }
1916
- }
1917
- async syncAccountInfo(f, V, H) {
1918
- let U = this.getCaipAddress(H), W = V || U?.split(":")[1];
1919
- if (!W) return;
1920
- let G = `${H}:${W}:${f}`;
1921
- this.setCaipAddress(G, H, !0), await this.syncIdentity({
1922
- address: f,
1923
- chainId: W,
1924
- chainNamespace: H
1925
- });
1926
- }
1927
- async syncReownName(f, V) {
1928
- try {
1929
- let H = await this.getReownName(f);
1930
- if (H[0]) {
1931
- let f = H[0];
1932
- this.setProfileName(f.name, V);
1933
- } else this.setProfileName(null, V);
1934
- } catch {
1935
- this.setProfileName(null, V);
1936
- }
1937
- }
1938
- syncConnectedWalletInfo(f) {
1939
- let V = ConnectorController.getConnectorId(f), H = ProviderController.getProviderId(f);
1940
- if (H === ConstantsUtil$2.CONNECTOR_TYPE_ANNOUNCED || H === ConstantsUtil$2.CONNECTOR_TYPE_INJECTED) {
1941
- if (V) {
1942
- let H = this.getConnectors().find((f) => {
1943
- let H = f.id === V, U = f.info?.rdns === V, W = f.connectors?.some((f) => f.id === V || f.info?.rdns === V);
1944
- return H || U || !!W;
1945
- });
1946
- if (H) {
1947
- let { info: V, name: U, imageUrl: W } = H, G = W || this.getConnectorImage(H);
1948
- this.setConnectedWalletInfo({
1949
- name: U,
1950
- icon: G,
1951
- ...V
1952
- }, f);
1953
- }
1954
- }
1955
- } else if (H === ConstantsUtil$2.CONNECTOR_TYPE_WALLET_CONNECT) {
1956
- let V = ProviderController.getProvider(f);
1957
- V?.session && this.setConnectedWalletInfo({
1958
- ...V.session.peer.metadata,
1959
- name: V.session.peer.metadata.name,
1960
- icon: V.session.peer.metadata.icons?.[0]
1961
- }, f);
1962
- } else if (V && (V === ConstantsUtil.CONNECTOR_ID.COINBASE_SDK || V === ConstantsUtil.CONNECTOR_ID.COINBASE)) {
1963
- let H = this.getConnectors().find((f) => f.id === V), U = H?.name || "Coinbase Wallet", W = H?.imageUrl || this.getConnectorImage(H), G = H?.info;
1964
- this.setConnectedWalletInfo({
1965
- ...G,
1966
- name: U,
1967
- icon: W
1968
- }, f);
1969
- }
1970
- }
1971
- async syncBalance(f) {
1972
- !NetworkUtil.getNetworksByNamespace(this.getCaipNetworks(), f.chainNamespace).find((V) => V.id.toString() === f.chainId?.toString()) || !f.chainId || await this.updateNativeBalance(f.address, f.chainId, f.chainNamespace);
1973
- }
1974
- async ready() {
1975
- await this.readyPromise;
1976
- }
1977
- async updateNativeBalance(f, V, H) {
1978
- let U = this.getAdapter(H), W = ChainController.getCaipNetworkByNamespace(H, V);
1979
- if (U) {
1980
- let G = await U.getBalance({
1981
- address: f,
1982
- chainId: V,
1983
- caipNetwork: W,
1984
- tokens: this.options.tokens
1985
- });
1986
- return this.setBalance(G.balance, G.symbol, H), G;
1987
- }
1988
- }
1989
- async initializeUniversalAdapter() {
1990
- let f = LoggerUtil.createLogger((f, ...V) => {
1991
- f && this.handleAlertError(f), console.error(...V);
1992
- }), V = {
1993
- projectId: this.options?.projectId,
1994
- metadata: {
1995
- name: this.options?.metadata ? this.options?.metadata.name : "",
1996
- description: this.options?.metadata ? this.options?.metadata.description : "",
1997
- url: this.options?.metadata ? this.options?.metadata.url : "",
1998
- icons: this.options?.metadata ? this.options?.metadata.icons : [""]
1999
- },
2000
- logger: f
2001
- };
2002
- OptionsController.setManualWCControl(!!this.options?.manualWCControl), this.universalProvider = this.options.universalProvider ?? await N.init(V);
2003
- let H = this.universalProvider.disconnect.bind(this.universalProvider);
2004
- this.universalProvider.disconnect = async () => {
2005
- try {
2006
- return await H();
2007
- } catch (f) {
2008
- if (f instanceof Error && f.message.includes("Missing or invalid. Record was recently deleted")) return;
2009
- throw f;
2010
- }
2011
- }, OptionsController.state.enableReconnect === !1 && this.universalProvider.session && await this.universalProvider.disconnect(), this.listenWalletConnect();
2012
- }
2013
- listenWalletConnect() {
2014
- this.universalProvider && this.chainNamespaces.forEach((f) => {
2015
- WcHelpersUtil.listenWcProvider({
2016
- universalProvider: this.universalProvider,
2017
- namespace: f,
2018
- onDisplayUri: (f) => {
2019
- ConnectionController.setUri(f);
2020
- },
2021
- onConnect: (f) => {
2022
- let { address: V } = CoreHelperUtil.getAccount(f[0]);
2023
- for (let f of this.chainNamespaces) StorageUtil.removeDisconnectedConnectorId(ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT, f);
2024
- ConnectionController.finalizeWcConnection(V);
2025
- },
2026
- onDisconnect: () => {
2027
- ChainController.state.noAdapters && this.resetAccount(f), ConnectionController.resetWcConnection();
2028
- },
2029
- onChainChanged: (V) => {
2030
- let H = ChainController.state.activeChain, U = H && ConnectorController.state.activeConnectorIds[H] === ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT;
2031
- if (H === f && (ChainController.state.noAdapters || U)) {
2032
- let f = this.getCaipNetworks().find((f) => f.id.toString() === V.toString() || f.caipNetworkId.toString() === V.toString()), H = this.getCaipNetwork();
2033
- if (!f) {
2034
- this.setUnsupportedNetwork(V);
2035
- return;
2036
- }
2037
- H?.id.toString() !== f?.id.toString() && H?.chainNamespace === f?.chainNamespace && this.setCaipNetwork(f);
2038
- }
2039
- },
2040
- onAccountsChanged: (V) => {
2041
- let H = ChainController.state.activeChain, U = H && ConnectorController.state.activeConnectorIds[H] === ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT;
2042
- if (H === f && (ChainController.state.noAdapters || U)) {
2043
- let f = V?.[0];
2044
- f && this.syncAccount({
2045
- address: f.address,
2046
- chainId: f.chainId,
2047
- chainNamespace: f.chainNamespace
2048
- });
2049
- }
2050
- }
2051
- });
2052
- });
2053
- }
2054
- createUniversalProvider() {
2055
- return !this.universalProviderInitPromise && CoreHelperUtil.isClient() && this.options?.projectId && (this.universalProviderInitPromise = this.initializeUniversalAdapter()), this.universalProviderInitPromise;
2056
- }
2057
- async getUniversalProvider() {
2058
- if (!this.universalProvider) try {
2059
- await this.createUniversalProvider();
2060
- } catch (f) {
2061
- EventsController.sendEvent({
2062
- type: "error",
2063
- event: "INTERNAL_SDK_ERROR",
2064
- properties: {
2065
- errorType: "UniversalProviderInitError",
2066
- errorMessage: f instanceof Error ? f.message : "Unknown",
2067
- uncaught: !1
2068
- }
2069
- }), console.error("AppKit:getUniversalProvider - Cannot create provider", f);
2070
- }
2071
- return this.universalProvider;
2072
- }
2073
- getDisabledCaipNetworks() {
2074
- let f = ChainController.getAllApprovedCaipNetworkIds(), V = ChainController.getAllRequestedCaipNetworks();
2075
- return CoreHelperUtil.sortRequestedNetworks(f, V).filter((f) => ChainController.isCaipNetworkDisabled(f));
2076
- }
2077
- handleAlertError(f) {
2078
- let [V, H] = Object.entries(ErrorUtil.UniversalProviderErrors).find(([, { message: V }]) => f.message.includes(V)) ?? [], { message: U, alertErrorKey: W } = H ?? {};
2079
- if (V && U && !this.reportedAlertErrors[V]) {
2080
- let f = ErrorUtil.ALERT_ERRORS[W];
2081
- f && (AlertController.open(f, "error"), this.reportedAlertErrors[V] = !0);
2082
- }
2083
- }
2084
- getAdapter(f) {
2085
- if (f) return this.chainAdapters?.[f];
2086
- }
2087
- createAdapter(f) {
2088
- if (!f) return;
2089
- let V = f.namespace;
2090
- if (!V) return;
2091
- this.createClients();
2092
- let H = f;
2093
- H.namespace = V, H.construct({
2094
- namespace: V,
2095
- projectId: this.options?.projectId,
2096
- networks: this.caipNetworks?.filter(({ chainNamespace: f }) => f === V)
2097
- }), this.chainNamespaces.includes(V) || this.chainNamespaces.push(V), this.chainAdapters && (this.chainAdapters[V] = H);
2098
- }
2099
- async open(f) {
2100
- await this.injectModalUi(), f?.uri && ConnectionController.setUri(f.uri);
2101
- let { isSwap: V, isSend: H } = this.toModalOptions();
2102
- return V(f) ? ModalController.open({
2103
- ...f,
2104
- data: { swap: f.arguments }
2105
- }) : H(f) && f.arguments ? this.openSend(f.arguments) : ModalController.open(f);
2106
- }
2107
- async close() {
2108
- await this.injectModalUi(), ModalController.close();
2109
- }
2110
- setLoading(f, V) {
2111
- ModalController.setLoading(f, V);
2112
- }
2113
- async disconnect(f) {
2114
- await ConnectionController.disconnect({ namespace: f });
2115
- }
2116
- getSIWX() {
2117
- return OptionsController.state.siwx;
2118
- }
2119
- getError() {
2120
- return "";
2121
- }
2122
- getChainId() {
2123
- return ChainController.state.activeCaipNetwork?.id;
2124
- }
2125
- async switchNetwork(f, { throwOnFailure: V = !1 } = {}) {
2126
- let H = this.getCaipNetworks().find((V) => V.id === f.id);
2127
- if (!H) {
2128
- AlertController.open(ErrorUtil.ALERT_ERRORS.SWITCH_NETWORK_NOT_FOUND, "error");
2129
- return;
2130
- }
2131
- await ChainController.switchActiveNetwork(H, { throwOnFailure: V });
2132
- }
2133
- getWalletProvider() {
2134
- return ChainController.state.activeChain ? ProviderController.state.providers[ChainController.state.activeChain] : null;
2135
- }
2136
- getWalletProviderType() {
2137
- return ProviderController.getProviderId(ChainController.state.activeChain);
2138
- }
2139
- subscribeProviders(f) {
2140
- return ProviderController.subscribeProviders(f);
2141
- }
2142
- getThemeMode() {
2143
- return ThemeController.state.themeMode;
2144
- }
2145
- getThemeVariables() {
2146
- return ThemeController.state.themeVariables;
2147
- }
2148
- setThemeMode(f) {
2149
- ThemeController.setThemeMode(f), setColorTheme(ThemeController.state.themeMode);
2150
- }
2151
- setTermsConditionsUrl(f) {
2152
- OptionsController.setTermsConditionsUrl(f);
2153
- }
2154
- setPrivacyPolicyUrl(f) {
2155
- OptionsController.setPrivacyPolicyUrl(f);
2156
- }
2157
- setThemeVariables(f) {
2158
- ThemeController.setThemeVariables(f), setThemeVariables(ThemeController.state.themeVariables);
2159
- }
2160
- subscribeTheme(f) {
2161
- return ThemeController.subscribe(f);
2162
- }
2163
- subscribeConnections(f) {
2164
- return this.remoteFeatures.multiWallet ? ConnectionController.subscribe(f) : (AlertController.open(ConstantsUtil.REMOTE_FEATURES_ALERTS.MULTI_WALLET_NOT_ENABLED.DEFAULT, "info"), () => void 0);
2165
- }
2166
- getWalletInfo(f) {
2167
- return f ? ChainController.state.chains.get(f)?.accountState?.connectedWalletInfo : ChainController.getAccountData()?.connectedWalletInfo;
2168
- }
2169
- getAccount(f) {
2170
- let V = f || ChainController.state.activeChain, H = ConnectorController.getAuthConnector(V), U = ChainController.getAccountData(V), W = StorageUtil.getConnectedConnectorId(ChainController.state.activeChain), G = ConnectionController.getConnections(V);
2171
- if (!V) throw Error("AppKit:getAccount - namespace is required");
2172
- let q = G.flatMap((f) => f.accounts.map(({ address: f, type: H, publicKey: U }) => CoreHelperUtil.createAccount(V, f, H || "eoa", U)));
2173
- if (U) return {
2174
- allAccounts: q,
2175
- caipAddress: U.caipAddress,
2176
- address: CoreHelperUtil.getPlainAddress(U.caipAddress),
2177
- isConnected: !!U.caipAddress,
2178
- status: U.status,
2179
- embeddedWalletInfo: H && W === ConstantsUtil.CONNECTOR_ID.AUTH ? {
2180
- user: U.user ? {
2181
- ...U.user,
2182
- username: StorageUtil.getConnectedSocialUsername()
2183
- } : void 0,
2184
- authProvider: U.socialProvider || "email",
2185
- accountType: getPreferredAccountType(V),
2186
- isSmartAccountDeployed: !!U.smartAccountDeployed
2187
- } : void 0
2188
- };
2189
- }
2190
- subscribeAccount(f, V) {
2191
- let H = [], U = () => {
2192
- let H = this.getAccount(V);
2193
- H && f(H);
2194
- };
2195
- if (V) {
2196
- let f = ChainController.subscribeChainProp("accountState", U, V);
2197
- H.push(f);
2198
- } else {
2199
- let f = ChainController.subscribe(U);
2200
- H.push(f);
2201
- }
2202
- let W = ConnectorController.subscribe(U);
2203
- return H.push(W), () => {
2204
- H.forEach((f) => f());
2205
- };
2206
- }
2207
- subscribeNetwork(f) {
2208
- return ChainController.subscribe(({ activeCaipNetwork: V }) => {
2209
- f({
2210
- caipNetwork: V,
2211
- chainId: V?.id,
2212
- caipNetworkId: V?.caipNetworkId
2213
- });
2214
- });
2215
- }
2216
- subscribeWalletInfo(f, V) {
2217
- return V ? ChainController.subscribeChainProp("accountState", (V) => f(V?.connectedWalletInfo), V) : ChainController.subscribeChainProp("accountState", (V) => f(V?.connectedWalletInfo));
2218
- }
2219
- subscribeShouldUpdateToAddress(f) {
2220
- return ChainController.subscribeChainProp("accountState", (V) => f(V?.shouldUpdateToAddress));
2221
- }
2222
- subscribeCaipNetworkChange(f) {
2223
- return ChainController.subscribeKey("activeCaipNetwork", f);
2224
- }
2225
- getState() {
2226
- return PublicStateController.state;
2227
- }
2228
- getRemoteFeatures() {
2229
- return OptionsController.state.remoteFeatures;
2230
- }
2231
- subscribeState(f) {
2232
- return PublicStateController.subscribe(f);
2233
- }
2234
- subscribeRemoteFeatures(f) {
2235
- return OptionsController.subscribeKey("remoteFeatures", f);
2236
- }
2237
- showErrorMessage(f) {
2238
- SnackController.showError(f);
2239
- }
2240
- showSuccessMessage(f) {
2241
- SnackController.showSuccess(f);
2242
- }
2243
- getEvent() {
2244
- return { ...EventsController.state };
2245
- }
2246
- subscribeEvents(f) {
2247
- return EventsController.subscribe(f);
2248
- }
2249
- replace(f) {
2250
- RouterController.replace(f);
2251
- }
2252
- redirect(f) {
2253
- RouterController.push(f);
2254
- }
2255
- popTransactionStack(f) {
2256
- RouterController.popTransactionStack(f);
2257
- }
2258
- isOpen() {
2259
- return ModalController.state.open;
2260
- }
2261
- isTransactionStackEmpty() {
2262
- return RouterController.state.transactionStack.length === 0;
2263
- }
2264
- static getInstance() {
2265
- return this.instance;
2266
- }
2267
- updateFeatures(f) {
2268
- OptionsController.setFeatures(f);
2269
- }
2270
- updateRemoteFeatures(f) {
2271
- OptionsController.setRemoteFeatures(f);
2272
- }
2273
- updateOptions(f) {
2274
- let V = {
2275
- ...OptionsController.state || {},
2276
- ...f
2277
- };
2278
- OptionsController.setOptions(V);
2279
- }
2280
- setConnectMethodsOrder(f) {
2281
- OptionsController.setConnectMethodsOrder(f);
2282
- }
2283
- setWalletFeaturesOrder(f) {
2284
- OptionsController.setWalletFeaturesOrder(f);
2285
- }
2286
- setCollapseWallets(f) {
2287
- OptionsController.setCollapseWallets(f);
2288
- }
2289
- setSocialsOrder(f) {
2290
- OptionsController.setSocialsOrder(f);
2291
- }
2292
- getConnectMethodsOrder() {
2293
- return WalletUtil.getConnectOrderMethod(OptionsController.state.features, ConnectorController.getConnectors());
2294
- }
2295
- addNetwork(f, V) {
2296
- if (this.chainAdapters && !this.chainAdapters[f]) throw Error(`Adapter for namespace ${f} doesn't exist`);
2297
- let H = this.extendCaipNetwork(V, this.options);
2298
- this.getCaipNetworks().find((f) => f.id === H.id) || ChainController.addNetwork(H);
2299
- }
2300
- removeNetwork(f, V) {
2301
- if (this.chainAdapters && !this.chainAdapters[f]) throw Error(`Adapter for namespace ${f} doesn't exist`);
2302
- this.getCaipNetworks().find((f) => f.id === V) && ChainController.removeNetwork(f, V);
2303
- }
2304
- }, isInitialized = !1, AppKit = class extends AppKitBaseClient {
2305
- async open(f) {
2306
- ConnectorController.isConnected() || await super.open(f);
2307
- }
2308
- async close() {
2309
- if (await super.close(), this.options.manualWCControl) {
2310
- let f = ChainController.getAccountData(this.activeChainNamespace)?.address;
2311
- ConnectionController.finalizeWcConnection(f);
2312
- }
2313
- }
2314
- async syncIdentity(f) {
2315
- return Promise.resolve();
2316
- }
2317
- async syncBalance(f) {
2318
- return Promise.resolve();
2319
- }
2320
- async injectModalUi() {
2321
- if (!isInitialized && CoreHelperUtil.isClient()) {
2322
- if (await import("./basic-C16-Uba1.js"), await import("./w3m-modal-CFhImDZN.js"), !document.querySelector("w3m-modal")) {
2323
- let f = document.createElement("w3m-modal");
2324
- !OptionsController.state.disableAppend && !OptionsController.state.enableEmbedded && document.body.insertAdjacentElement("beforeend", f);
2325
- }
2326
- isInitialized = !0;
2327
- }
2328
- }
2329
- };
2330
- function createAppKit(f) {
2331
- return new AppKit({
2332
- ...f,
2333
- basic: !0,
2334
- sdkVersion: "html-core-1.8.17-wc-circular-dependencies-fix.0"
2335
- });
2336
- }
2337
- export { createAppKit };