@reown/appkit-core-react-native 0.0.0-accounts-canary.1-20251023174733

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 (234) hide show
  1. package/lib/commonjs/controllers/ApiController.js +410 -0
  2. package/lib/commonjs/controllers/ApiController.js.map +1 -0
  3. package/lib/commonjs/controllers/AssetController.js +30 -0
  4. package/lib/commonjs/controllers/AssetController.js.map +1 -0
  5. package/lib/commonjs/controllers/BlockchainApiController.js +384 -0
  6. package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -0
  7. package/lib/commonjs/controllers/ConnectionsController.js +425 -0
  8. package/lib/commonjs/controllers/ConnectionsController.js.map +1 -0
  9. package/lib/commonjs/controllers/EnsController.js +37 -0
  10. package/lib/commonjs/controllers/EnsController.js.map +1 -0
  11. package/lib/commonjs/controllers/EventsController.js +122 -0
  12. package/lib/commonjs/controllers/EventsController.js.map +1 -0
  13. package/lib/commonjs/controllers/LogController.js +188 -0
  14. package/lib/commonjs/controllers/LogController.js.map +1 -0
  15. package/lib/commonjs/controllers/ModalController.js +68 -0
  16. package/lib/commonjs/controllers/ModalController.js.map +1 -0
  17. package/lib/commonjs/controllers/OnRampController.js +502 -0
  18. package/lib/commonjs/controllers/OnRampController.js.map +1 -0
  19. package/lib/commonjs/controllers/OptionsController.js +96 -0
  20. package/lib/commonjs/controllers/OptionsController.js.map +1 -0
  21. package/lib/commonjs/controllers/PublicStateController.js +33 -0
  22. package/lib/commonjs/controllers/PublicStateController.js.map +1 -0
  23. package/lib/commonjs/controllers/RouterController.js +63 -0
  24. package/lib/commonjs/controllers/RouterController.js.map +1 -0
  25. package/lib/commonjs/controllers/SendController.js +192 -0
  26. package/lib/commonjs/controllers/SendController.js.map +1 -0
  27. package/lib/commonjs/controllers/SnackController.js +83 -0
  28. package/lib/commonjs/controllers/SnackController.js.map +1 -0
  29. package/lib/commonjs/controllers/SwapController.js +674 -0
  30. package/lib/commonjs/controllers/SwapController.js.map +1 -0
  31. package/lib/commonjs/controllers/ThemeController.js +45 -0
  32. package/lib/commonjs/controllers/ThemeController.js.map +1 -0
  33. package/lib/commonjs/controllers/TransactionsController.js +118 -0
  34. package/lib/commonjs/controllers/TransactionsController.js.map +1 -0
  35. package/lib/commonjs/controllers/WcController.js +73 -0
  36. package/lib/commonjs/controllers/WcController.js.map +1 -0
  37. package/lib/commonjs/features/reown-authentication/ReownAuthentication.js +272 -0
  38. package/lib/commonjs/features/reown-authentication/ReownAuthentication.js.map +1 -0
  39. package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js +48 -0
  40. package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
  41. package/lib/commonjs/features/reown-authentication/index.js +28 -0
  42. package/lib/commonjs/features/reown-authentication/index.js.map +1 -0
  43. package/lib/commonjs/index.js +202 -0
  44. package/lib/commonjs/index.js.map +1 -0
  45. package/lib/commonjs/package.json +1 -0
  46. package/lib/commonjs/utils/ApiUtil.js +43 -0
  47. package/lib/commonjs/utils/ApiUtil.js.map +1 -0
  48. package/lib/commonjs/utils/AssetUtil.js +27 -0
  49. package/lib/commonjs/utils/AssetUtil.js.map +1 -0
  50. package/lib/commonjs/utils/ConstantsUtil.js +226 -0
  51. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -0
  52. package/lib/commonjs/utils/CoreHelperUtil.js +298 -0
  53. package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -0
  54. package/lib/commonjs/utils/EventUtil.js +25 -0
  55. package/lib/commonjs/utils/EventUtil.js.map +1 -0
  56. package/lib/commonjs/utils/FetchUtil.js +158 -0
  57. package/lib/commonjs/utils/FetchUtil.js.map +1 -0
  58. package/lib/commonjs/utils/LogUtils.js +131 -0
  59. package/lib/commonjs/utils/LogUtils.js.map +1 -0
  60. package/lib/commonjs/utils/StorageUtil.js +319 -0
  61. package/lib/commonjs/utils/StorageUtil.js.map +1 -0
  62. package/lib/commonjs/utils/SwapApiUtil.js +75 -0
  63. package/lib/commonjs/utils/SwapApiUtil.js.map +1 -0
  64. package/lib/commonjs/utils/SwapCalculationUtil.js +97 -0
  65. package/lib/commonjs/utils/SwapCalculationUtil.js.map +1 -0
  66. package/lib/commonjs/utils/WalletUtil.js +23 -0
  67. package/lib/commonjs/utils/WalletUtil.js.map +1 -0
  68. package/lib/module/controllers/ApiController.js +407 -0
  69. package/lib/module/controllers/ApiController.js.map +1 -0
  70. package/lib/module/controllers/AssetController.js +27 -0
  71. package/lib/module/controllers/AssetController.js.map +1 -0
  72. package/lib/module/controllers/BlockchainApiController.js +381 -0
  73. package/lib/module/controllers/BlockchainApiController.js.map +1 -0
  74. package/lib/module/controllers/ConnectionsController.js +422 -0
  75. package/lib/module/controllers/ConnectionsController.js.map +1 -0
  76. package/lib/module/controllers/EnsController.js +34 -0
  77. package/lib/module/controllers/EnsController.js.map +1 -0
  78. package/lib/module/controllers/EventsController.js +118 -0
  79. package/lib/module/controllers/EventsController.js.map +1 -0
  80. package/lib/module/controllers/LogController.js +185 -0
  81. package/lib/module/controllers/LogController.js.map +1 -0
  82. package/lib/module/controllers/ModalController.js +65 -0
  83. package/lib/module/controllers/ModalController.js.map +1 -0
  84. package/lib/module/controllers/OnRampController.js +499 -0
  85. package/lib/module/controllers/OnRampController.js.map +1 -0
  86. package/lib/module/controllers/OptionsController.js +93 -0
  87. package/lib/module/controllers/OptionsController.js.map +1 -0
  88. package/lib/module/controllers/PublicStateController.js +30 -0
  89. package/lib/module/controllers/PublicStateController.js.map +1 -0
  90. package/lib/module/controllers/RouterController.js +60 -0
  91. package/lib/module/controllers/RouterController.js.map +1 -0
  92. package/lib/module/controllers/SendController.js +189 -0
  93. package/lib/module/controllers/SendController.js.map +1 -0
  94. package/lib/module/controllers/SnackController.js +80 -0
  95. package/lib/module/controllers/SnackController.js.map +1 -0
  96. package/lib/module/controllers/SwapController.js +671 -0
  97. package/lib/module/controllers/SwapController.js.map +1 -0
  98. package/lib/module/controllers/ThemeController.js +42 -0
  99. package/lib/module/controllers/ThemeController.js.map +1 -0
  100. package/lib/module/controllers/TransactionsController.js +115 -0
  101. package/lib/module/controllers/TransactionsController.js.map +1 -0
  102. package/lib/module/controllers/WcController.js +70 -0
  103. package/lib/module/controllers/WcController.js.map +1 -0
  104. package/lib/module/features/reown-authentication/ReownAuthentication.js +268 -0
  105. package/lib/module/features/reown-authentication/ReownAuthentication.js.map +1 -0
  106. package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js +43 -0
  107. package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
  108. package/lib/module/features/reown-authentication/index.js +5 -0
  109. package/lib/module/features/reown-authentication/index.js.map +1 -0
  110. package/lib/module/index.js +38 -0
  111. package/lib/module/index.js.map +1 -0
  112. package/lib/module/utils/ApiUtil.js +39 -0
  113. package/lib/module/utils/ApiUtil.js.map +1 -0
  114. package/lib/module/utils/AssetUtil.js +23 -0
  115. package/lib/module/utils/AssetUtil.js.map +1 -0
  116. package/lib/module/utils/ConstantsUtil.js +222 -0
  117. package/lib/module/utils/ConstantsUtil.js.map +1 -0
  118. package/lib/module/utils/CoreHelperUtil.js +294 -0
  119. package/lib/module/utils/CoreHelperUtil.js.map +1 -0
  120. package/lib/module/utils/EventUtil.js +21 -0
  121. package/lib/module/utils/EventUtil.js.map +1 -0
  122. package/lib/module/utils/FetchUtil.js +154 -0
  123. package/lib/module/utils/FetchUtil.js.map +1 -0
  124. package/lib/module/utils/LogUtils.js +121 -0
  125. package/lib/module/utils/LogUtils.js.map +1 -0
  126. package/lib/module/utils/StorageUtil.js +315 -0
  127. package/lib/module/utils/StorageUtil.js.map +1 -0
  128. package/lib/module/utils/SwapApiUtil.js +71 -0
  129. package/lib/module/utils/SwapApiUtil.js.map +1 -0
  130. package/lib/module/utils/SwapCalculationUtil.js +94 -0
  131. package/lib/module/utils/SwapCalculationUtil.js.map +1 -0
  132. package/lib/module/utils/WalletUtil.js +19 -0
  133. package/lib/module/utils/WalletUtil.js.map +1 -0
  134. package/lib/typescript/controllers/ApiController.d.ts +40 -0
  135. package/lib/typescript/controllers/ApiController.d.ts.map +1 -0
  136. package/lib/typescript/controllers/AssetController.d.ts +12 -0
  137. package/lib/typescript/controllers/AssetController.d.ts.map +1 -0
  138. package/lib/typescript/controllers/BlockchainApiController.d.ts +55 -0
  139. package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -0
  140. package/lib/typescript/controllers/ConnectionsController.d.ts +47 -0
  141. package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -0
  142. package/lib/typescript/controllers/EnsController.d.ts +10 -0
  143. package/lib/typescript/controllers/EnsController.d.ts.map +1 -0
  144. package/lib/typescript/controllers/EventsController.d.ts +25 -0
  145. package/lib/typescript/controllers/EventsController.d.ts.map +1 -0
  146. package/lib/typescript/controllers/LogController.d.ts +65 -0
  147. package/lib/typescript/controllers/LogController.d.ts.map +1 -0
  148. package/lib/typescript/controllers/ModalController.d.ts +17 -0
  149. package/lib/typescript/controllers/ModalController.d.ts.map +1 -0
  150. package/lib/typescript/controllers/OnRampController.d.ts +55 -0
  151. package/lib/typescript/controllers/OnRampController.d.ts.map +1 -0
  152. package/lib/typescript/controllers/OptionsController.d.ts +46 -0
  153. package/lib/typescript/controllers/OptionsController.d.ts.map +1 -0
  154. package/lib/typescript/controllers/PublicStateController.d.ts +12 -0
  155. package/lib/typescript/controllers/PublicStateController.d.ts.map +1 -0
  156. package/lib/typescript/controllers/RouterController.d.ts +21 -0
  157. package/lib/typescript/controllers/RouterController.d.ts.map +1 -0
  158. package/lib/typescript/controllers/SendController.d.ts +39 -0
  159. package/lib/typescript/controllers/SendController.d.ts.map +1 -0
  160. package/lib/typescript/controllers/SnackController.d.ts +20 -0
  161. package/lib/typescript/controllers/SnackController.d.ts.map +1 -0
  162. package/lib/typescript/controllers/SwapController.d.ts +116 -0
  163. package/lib/typescript/controllers/SwapController.d.ts.map +1 -0
  164. package/lib/typescript/controllers/ThemeController.d.ts +14 -0
  165. package/lib/typescript/controllers/ThemeController.d.ts.map +1 -0
  166. package/lib/typescript/controllers/TransactionsController.d.ts +21 -0
  167. package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -0
  168. package/lib/typescript/controllers/WcController.d.ts +27 -0
  169. package/lib/typescript/controllers/WcController.d.ts.map +1 -0
  170. package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts +174 -0
  171. package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts.map +1 -0
  172. package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts +16 -0
  173. package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts.map +1 -0
  174. package/lib/typescript/features/reown-authentication/index.d.ts +3 -0
  175. package/lib/typescript/features/reown-authentication/index.d.ts.map +1 -0
  176. package/lib/typescript/index.d.ts +29 -0
  177. package/lib/typescript/index.d.ts.map +1 -0
  178. package/lib/typescript/utils/ApiUtil.d.ts +7 -0
  179. package/lib/typescript/utils/ApiUtil.d.ts.map +1 -0
  180. package/lib/typescript/utils/AssetUtil.d.ts +6 -0
  181. package/lib/typescript/utils/AssetUtil.d.ts.map +1 -0
  182. package/lib/typescript/utils/ConstantsUtil.d.ts +79 -0
  183. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -0
  184. package/lib/typescript/utils/CoreHelperUtil.d.ts +43 -0
  185. package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -0
  186. package/lib/typescript/utils/EventUtil.d.ts +5 -0
  187. package/lib/typescript/utils/EventUtil.d.ts.map +1 -0
  188. package/lib/typescript/utils/FetchUtil.d.ts +29 -0
  189. package/lib/typescript/utils/FetchUtil.d.ts.map +1 -0
  190. package/lib/typescript/utils/LogUtils.d.ts +15 -0
  191. package/lib/typescript/utils/LogUtils.d.ts.map +1 -0
  192. package/lib/typescript/utils/StorageUtil.d.ts +36 -0
  193. package/lib/typescript/utils/StorageUtil.d.ts.map +1 -0
  194. package/lib/typescript/utils/SwapApiUtil.d.ts +11 -0
  195. package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -0
  196. package/lib/typescript/utils/SwapCalculationUtil.d.ts +24 -0
  197. package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +1 -0
  198. package/lib/typescript/utils/WalletUtil.d.ts +5 -0
  199. package/lib/typescript/utils/WalletUtil.d.ts.map +1 -0
  200. package/package.json +57 -0
  201. package/readme.md +9 -0
  202. package/src/controllers/ApiController.ts +454 -0
  203. package/src/controllers/AssetController.ts +32 -0
  204. package/src/controllers/BlockchainApiController.ts +418 -0
  205. package/src/controllers/ConnectionsController.ts +575 -0
  206. package/src/controllers/EnsController.ts +41 -0
  207. package/src/controllers/EventsController.ts +146 -0
  208. package/src/controllers/LogController.ts +250 -0
  209. package/src/controllers/ModalController.ts +68 -0
  210. package/src/controllers/OnRampController.ts +698 -0
  211. package/src/controllers/OptionsController.ts +143 -0
  212. package/src/controllers/PublicStateController.ts +37 -0
  213. package/src/controllers/RouterController.ts +112 -0
  214. package/src/controllers/SendController.ts +270 -0
  215. package/src/controllers/SnackController.ts +95 -0
  216. package/src/controllers/SwapController.ts +863 -0
  217. package/src/controllers/ThemeController.ts +47 -0
  218. package/src/controllers/TransactionsController.ts +150 -0
  219. package/src/controllers/WcController.ts +93 -0
  220. package/src/features/reown-authentication/ReownAuthentication.ts +475 -0
  221. package/src/features/reown-authentication/ReownAuthenticationMessenger.ts +80 -0
  222. package/src/features/reown-authentication/index.ts +2 -0
  223. package/src/index.ts +70 -0
  224. package/src/utils/ApiUtil.ts +50 -0
  225. package/src/utils/AssetUtil.ts +27 -0
  226. package/src/utils/ConstantsUtil.ts +303 -0
  227. package/src/utils/CoreHelperUtil.ts +377 -0
  228. package/src/utils/EventUtil.ts +22 -0
  229. package/src/utils/FetchUtil.ts +164 -0
  230. package/src/utils/LogUtils.ts +179 -0
  231. package/src/utils/StorageUtil.ts +405 -0
  232. package/src/utils/SwapApiUtil.ts +101 -0
  233. package/src/utils/SwapCalculationUtil.ts +145 -0
  234. package/src/utils/WalletUtil.ts +14 -0
@@ -0,0 +1,146 @@
1
+ import { proxy, subscribe as sub } from 'valtio';
2
+ import { ApiController } from './ApiController';
3
+ import { OptionsController } from './OptionsController';
4
+ import { CoreHelperUtil } from '../utils/CoreHelperUtil';
5
+ import { FetchUtil } from '../utils/FetchUtil';
6
+ import type {
7
+ Event,
8
+ EventName,
9
+ WalletImpressionItem,
10
+ WcWallet
11
+ } from '@reown/appkit-common-react-native';
12
+
13
+ // -- Helpers ------------------------------------------- //
14
+ const baseUrl = CoreHelperUtil.getAnalyticsUrl();
15
+ const api = new FetchUtil({ baseUrl });
16
+ const excluded = ['MODAL_CREATED'];
17
+ const IMPRESSION_TIMEOUT = 3000;
18
+
19
+ // -- Types --------------------------------------------- //
20
+ export interface EventsControllerState {
21
+ timestamp: number;
22
+ data: Event;
23
+ pendingWalletImpressions: WalletImpressionItem[];
24
+ pendingImpressionTimeout?: NodeJS.Timeout;
25
+ }
26
+
27
+ // -- State --------------------------------------------- //
28
+ const state = proxy<EventsControllerState>({
29
+ timestamp: Date.now(),
30
+ data: {
31
+ type: 'track',
32
+ event: 'MODAL_CREATED' // just for init purposes
33
+ },
34
+ pendingWalletImpressions: [],
35
+ pendingImpressionTimeout: undefined
36
+ });
37
+
38
+ // -- Controller ---------------------------------------- //
39
+ export const EventsController = {
40
+ state,
41
+
42
+ subscribe(callback: (newState: EventsControllerState) => void) {
43
+ return sub(state, () => callback(state));
44
+ },
45
+
46
+ subscribeEvent(event: EventName, callback: (newEvent: EventsControllerState) => void) {
47
+ return sub(state, () => {
48
+ if (state.data.event === event) {
49
+ callback(state);
50
+ }
51
+ });
52
+ },
53
+
54
+ trackWalletImpression(props: {
55
+ wallet: WcWallet;
56
+ view: 'Connect' | 'AllWallets';
57
+ displayIndex: number;
58
+ query?: string;
59
+ installed?: boolean;
60
+ }) {
61
+ state.pendingWalletImpressions.push({
62
+ name: props.wallet.name ?? 'Unknown',
63
+ walletRank: props.wallet.order,
64
+ explorerId: props.wallet.id,
65
+ certified: props.wallet.badge_type === 'certified',
66
+ displayIndex: props.displayIndex,
67
+ view: props.view,
68
+ query: props.query,
69
+ installed: props.installed
70
+ });
71
+
72
+ if (state.pendingImpressionTimeout) {
73
+ clearTimeout(state.pendingImpressionTimeout);
74
+ }
75
+
76
+ state.pendingImpressionTimeout = setTimeout(() => {
77
+ EventsController.sendWalletImpressions();
78
+ }, IMPRESSION_TIMEOUT);
79
+ },
80
+
81
+ sendWalletImpressions() {
82
+ if (state.pendingImpressionTimeout) {
83
+ clearTimeout(state.pendingImpressionTimeout);
84
+ state.pendingImpressionTimeout = undefined;
85
+ }
86
+
87
+ const impressions = state.pendingWalletImpressions;
88
+
89
+ if (impressions.length === 0) {
90
+ return;
91
+ }
92
+
93
+ state.pendingWalletImpressions = [];
94
+ EventsController.sendEvent({
95
+ type: 'track',
96
+ event: 'WALLET_IMPRESSION',
97
+ items: impressions
98
+ });
99
+ },
100
+
101
+ async _sendAnalyticsEvent(data: EventsControllerState['data'], timestamp: number) {
102
+ if (excluded.includes(data.event)) {
103
+ return;
104
+ }
105
+
106
+ try {
107
+ await api.post({
108
+ path: '/e',
109
+ headers: ApiController._getApiHeaders(),
110
+ params: ApiController._getApiParams(),
111
+ body: {
112
+ eventId: CoreHelperUtil.getUUID(),
113
+ bundleId: CoreHelperUtil.getBundleId(),
114
+ timestamp,
115
+ props: data
116
+ }
117
+ });
118
+ } catch {
119
+ // Catch silently
120
+ }
121
+ },
122
+
123
+ async sendEvent(data: EventsControllerState['data']) {
124
+ const timestamp = Date.now();
125
+ state.timestamp = timestamp;
126
+ state.data = data;
127
+ await ApiController.state.prefetchPromise;
128
+
129
+ if (OptionsController.state.enableAnalytics) {
130
+ EventsController._sendAnalyticsEvent(data, timestamp);
131
+ }
132
+ },
133
+
134
+ resetState() {
135
+ if (state.pendingImpressionTimeout) {
136
+ clearTimeout(state.pendingImpressionTimeout);
137
+ state.pendingImpressionTimeout = undefined;
138
+ }
139
+ state.pendingWalletImpressions = [];
140
+ state.data = {
141
+ type: 'track',
142
+ event: 'MODAL_CREATED'
143
+ };
144
+ state.timestamp = Date.now();
145
+ }
146
+ };
@@ -0,0 +1,250 @@
1
+ import { proxy } from 'valtio';
2
+ import { OptionsController } from './OptionsController';
3
+ import { sanitizeString, sanitizeStackTrace, sanitizeValue, sanitizeData } from '../utils/LogUtils';
4
+ import { CoreHelperUtil } from '../utils/CoreHelperUtil';
5
+
6
+ // -- Types --------------------------------------------- //
7
+ export type LogLevel = 'info' | 'warn' | 'error' | 'debug';
8
+
9
+ export interface LogEntry {
10
+ id: string;
11
+ timestamp: number;
12
+ level: LogLevel;
13
+ message: string;
14
+ fileName?: string;
15
+ functionName?: string;
16
+ data?: Record<string, unknown>;
17
+ }
18
+
19
+ export interface LogControllerState {
20
+ logs: LogEntry[];
21
+ }
22
+
23
+ // -- Constants ----------------------------------------- //
24
+ const MAX_LOGS_COUNT = 300; // Prevent memory issues
25
+
26
+ // -- State --------------------------------------------- //
27
+ const state = proxy<LogControllerState>({
28
+ logs: []
29
+ });
30
+
31
+ const generateLogId = (): string => {
32
+ return CoreHelperUtil.getUUID();
33
+ };
34
+
35
+ const logToConsole = (entry: LogEntry) => {
36
+ const { debug } = OptionsController.state;
37
+
38
+ if (!debug) {
39
+ return;
40
+ }
41
+
42
+ const location =
43
+ entry.fileName && entry.functionName
44
+ ? `[${entry.fileName}:${entry.functionName}]`
45
+ : entry.fileName
46
+ ? `[${entry.fileName}]`
47
+ : '';
48
+
49
+ const logMessage = `[AppKit] ${location} ${entry.message}`;
50
+
51
+ switch (entry.level) {
52
+ case 'error':
53
+ // eslint-disable-next-line no-console
54
+ console.error(logMessage);
55
+ break;
56
+ case 'warn':
57
+ console.warn(logMessage);
58
+ break;
59
+ case 'debug':
60
+ // eslint-disable-next-line no-console
61
+ console.debug(logMessage);
62
+ break;
63
+ case 'info':
64
+ default:
65
+ // eslint-disable-next-line no-console
66
+ console.log(logMessage);
67
+ break;
68
+ }
69
+ };
70
+
71
+ // -- Controller ---------------------------------------- //
72
+ export const LogController = {
73
+ state,
74
+
75
+ /**
76
+ * Destroy the LogController (cleanup resources)
77
+ */
78
+ destroy() {
79
+ // Clear all logs
80
+ state.logs = [];
81
+ },
82
+
83
+ /**
84
+ * Send a general log entry
85
+ */
86
+ sendLog(
87
+ level: LogLevel,
88
+ message: string,
89
+ fileName?: string,
90
+ functionName?: string,
91
+ data?: Record<string, unknown>
92
+ ) {
93
+ if (!OptionsController.state.debug) {
94
+ return;
95
+ }
96
+ const entry: LogEntry = {
97
+ id: generateLogId(),
98
+ timestamp: Date.now(),
99
+ level,
100
+ message: sanitizeString(message),
101
+ fileName,
102
+ functionName,
103
+ data: sanitizeData(data)
104
+ };
105
+
106
+ state.logs.push(entry);
107
+
108
+ // Enforce maximum log count
109
+ if (state.logs.length > MAX_LOGS_COUNT) {
110
+ state.logs = state.logs.slice(-MAX_LOGS_COUNT);
111
+ }
112
+
113
+ logToConsole(entry);
114
+ },
115
+
116
+ /**
117
+ * Send an error log entry - convenience method for try/catch blocks
118
+ */
119
+ sendError(
120
+ error: Error | string | unknown,
121
+ fileName?: string,
122
+ functionName?: string,
123
+ additionalData?: Record<string, unknown>
124
+ ) {
125
+ let message: string;
126
+ let data: Record<string, unknown> = sanitizeData(additionalData) || {};
127
+
128
+ if (error instanceof Error) {
129
+ message = error.message || 'Error occurred';
130
+ // Sanitize stack trace to remove sensitive file paths
131
+ data['stack'] = error.stack ? sanitizeStackTrace(error.stack) : undefined;
132
+ data['name'] = error.name;
133
+
134
+ // Sanitize any additional properties on the error object
135
+ const errorProps: Record<string, unknown> = {};
136
+ Object.getOwnPropertyNames(error).forEach(prop => {
137
+ if (prop !== 'message' && prop !== 'stack' && prop !== 'name') {
138
+ errorProps[prop] = (error as any)[prop];
139
+ }
140
+ });
141
+
142
+ if (Object.keys(errorProps).length > 0) {
143
+ Object.assign(data, sanitizeValue(errorProps) as Record<string, unknown>);
144
+ }
145
+ } else if (typeof error === 'string') {
146
+ message = error;
147
+ } else if (error && typeof error === 'object' && 'message' in error) {
148
+ // Handle error-like objects (e.g., RPC errors, custom error objects)
149
+ message = String((error as any).message) || 'Error occurred';
150
+ // Include all properties of the error object
151
+ Object.assign(data, sanitizeValue(error) as Record<string, unknown>);
152
+ } else {
153
+ message = 'Unknown error occurred';
154
+ // Sanitize the original error object
155
+ data['originalError'] = sanitizeValue(error);
156
+ }
157
+
158
+ // Note: sanitization happens in sendLog method
159
+ this.sendLog('error', message, fileName, functionName, data);
160
+ },
161
+
162
+ /**
163
+ * Send an info log entry
164
+ */
165
+ sendInfo(
166
+ message: string,
167
+ fileName?: string,
168
+ functionName?: string,
169
+ data?: Record<string, unknown>
170
+ ) {
171
+ this.sendLog('info', message, fileName, functionName, data);
172
+ },
173
+
174
+ /**
175
+ * Send a warning log entry
176
+ */
177
+ sendWarn(
178
+ message: string,
179
+ fileName?: string,
180
+ functionName?: string,
181
+ data?: Record<string, unknown>
182
+ ) {
183
+ this.sendLog('warn', message, fileName, functionName, data);
184
+ },
185
+
186
+ /**
187
+ * Send a debug log entry
188
+ */
189
+ sendDebug(
190
+ message: string,
191
+ fileName?: string,
192
+ functionName?: string,
193
+ data?: Record<string, unknown>
194
+ ) {
195
+ this.sendLog('debug', message, fileName, functionName, data);
196
+ },
197
+
198
+ /**
199
+ * Get all logs
200
+ */
201
+ getLogs(): LogEntry[] {
202
+ return [...state.logs];
203
+ },
204
+
205
+ /**
206
+ * Get logs by level
207
+ */
208
+ getLogsByLevel(level: LogLevel): LogEntry[] {
209
+ return state.logs.filter(log => log.level === level);
210
+ },
211
+
212
+ /**
213
+ * Get recent logs (last N entries)
214
+ */
215
+ getRecentLogs(count: number = 100): LogEntry[] {
216
+ return state.logs.slice(-count);
217
+ },
218
+
219
+ /**
220
+ * Clear all logs
221
+ */
222
+ clearLogs() {
223
+ state.logs = [];
224
+ },
225
+
226
+ /**
227
+ * Export logs as JSON string for debugging
228
+ */
229
+ exportLogs(): string {
230
+ return JSON.stringify(state.logs, null, 2);
231
+ },
232
+
233
+ /**
234
+ * Get logs count by level
235
+ */
236
+ getLogsStats(): Record<LogLevel, number> {
237
+ const stats: Record<LogLevel, number> = {
238
+ info: 0,
239
+ warn: 0,
240
+ error: 0,
241
+ debug: 0
242
+ };
243
+
244
+ state.logs.forEach(log => {
245
+ stats[log.level]++;
246
+ });
247
+
248
+ return stats;
249
+ }
250
+ };
@@ -0,0 +1,68 @@
1
+ import { proxy } from 'valtio';
2
+ import { RouterController, type RouterControllerState } from './RouterController';
3
+ import { PublicStateController } from './PublicStateController';
4
+ import { EventsController } from './EventsController';
5
+ import { ApiController } from './ApiController';
6
+ import { ConnectionsController } from './ConnectionsController';
7
+
8
+ // -- Types --------------------------------------------- //
9
+ export interface ModalControllerState {
10
+ open: boolean;
11
+ loading: boolean;
12
+ }
13
+
14
+ export interface ModalControllerArguments {
15
+ open: {
16
+ view?: RouterControllerState['view'];
17
+ };
18
+ }
19
+
20
+ // -- State --------------------------------------------- //
21
+ const state = proxy<ModalControllerState>({
22
+ open: false,
23
+ loading: false
24
+ });
25
+
26
+ // -- Controller ---------------------------------------- //
27
+ export const ModalController = {
28
+ state,
29
+
30
+ async open(options?: ModalControllerArguments['open']) {
31
+ await ApiController.state.prefetchPromise;
32
+ const isConnected = ConnectionsController.state.isConnected;
33
+ const isUniversalWallet = !!ConnectionsController.state.connection?.properties?.provider;
34
+ if (options?.view) {
35
+ if (options.view === 'Account' && !isUniversalWallet) {
36
+ options.view = 'AccountDefault';
37
+ }
38
+
39
+ RouterController.reset(options.view);
40
+ } else if (isConnected) {
41
+ RouterController.reset(isUniversalWallet ? 'Account' : 'AccountDefault');
42
+ } else {
43
+ RouterController.reset('Connect');
44
+ }
45
+ state.open = true;
46
+ PublicStateController.set({ open: true });
47
+ EventsController.sendEvent({
48
+ type: 'track',
49
+ event: 'MODAL_OPEN',
50
+ properties: { connected: isConnected }
51
+ });
52
+ },
53
+
54
+ close() {
55
+ const connected = ConnectionsController.state.isConnected;
56
+ state.open = false;
57
+ PublicStateController.set({ open: false });
58
+ EventsController.sendEvent({
59
+ type: 'track',
60
+ event: 'MODAL_CLOSE',
61
+ properties: { connected }
62
+ });
63
+ },
64
+
65
+ setLoading(loading: ModalControllerState['loading']) {
66
+ state.loading = loading;
67
+ }
68
+ };