@reown/appkit-core-react-native 0.0.0-develop-20250728141602 → 0.0.0-develop-20251008155354

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 (291) hide show
  1. package/lib/commonjs/controllers/ApiController.js +157 -91
  2. package/lib/commonjs/controllers/ApiController.js.map +1 -1
  3. package/lib/commonjs/controllers/AssetController.js +0 -4
  4. package/lib/commonjs/controllers/AssetController.js.map +1 -1
  5. package/lib/commonjs/controllers/BlockchainApiController.js +180 -78
  6. package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
  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 +2 -0
  10. package/lib/commonjs/controllers/EnsController.js.map +1 -1
  11. package/lib/commonjs/controllers/EventsController.js +51 -1
  12. package/lib/commonjs/controllers/EventsController.js.map +1 -1
  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 +9 -7
  16. package/lib/commonjs/controllers/ModalController.js.map +1 -1
  17. package/lib/commonjs/controllers/OnRampController.js +47 -20
  18. package/lib/commonjs/controllers/OnRampController.js.map +1 -1
  19. package/lib/commonjs/controllers/OptionsController.js +28 -10
  20. package/lib/commonjs/controllers/OptionsController.js.map +1 -1
  21. package/lib/commonjs/controllers/PublicStateController.js.map +1 -1
  22. package/lib/commonjs/controllers/RouterController.js +7 -22
  23. package/lib/commonjs/controllers/RouterController.js.map +1 -1
  24. package/lib/commonjs/controllers/SendController.js +111 -95
  25. package/lib/commonjs/controllers/SendController.js.map +1 -1
  26. package/lib/commonjs/controllers/SnackController.js +29 -5
  27. package/lib/commonjs/controllers/SnackController.js.map +1 -1
  28. package/lib/commonjs/controllers/SwapController.js +162 -151
  29. package/lib/commonjs/controllers/SwapController.js.map +1 -1
  30. package/lib/commonjs/controllers/ThemeController.js +14 -1
  31. package/lib/commonjs/controllers/ThemeController.js.map +1 -1
  32. package/lib/commonjs/controllers/TransactionsController.js +24 -18
  33. package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
  34. package/lib/commonjs/controllers/WcController.js +73 -0
  35. package/lib/commonjs/controllers/WcController.js.map +1 -0
  36. package/lib/commonjs/features/reown-authentication/ReownAuthentication.js +272 -0
  37. package/lib/commonjs/features/reown-authentication/ReownAuthentication.js.map +1 -0
  38. package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js +48 -0
  39. package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
  40. package/lib/commonjs/features/reown-authentication/index.js +28 -0
  41. package/lib/commonjs/features/reown-authentication/index.js.map +1 -0
  42. package/lib/commonjs/index.js +33 -40
  43. package/lib/commonjs/index.js.map +1 -1
  44. package/lib/commonjs/package.json +1 -0
  45. package/lib/commonjs/utils/ApiUtil.js +1 -1
  46. package/lib/commonjs/utils/ApiUtil.js.map +1 -1
  47. package/lib/commonjs/utils/AssetUtil.js +8 -18
  48. package/lib/commonjs/utils/AssetUtil.js.map +1 -1
  49. package/lib/commonjs/utils/ConstantsUtil.js +117 -5
  50. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
  51. package/lib/commonjs/utils/CoreHelperUtil.js +32 -9
  52. package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
  53. package/lib/commonjs/utils/EventUtil.js.map +1 -1
  54. package/lib/commonjs/utils/FetchUtil.js +7 -2
  55. package/lib/commonjs/utils/FetchUtil.js.map +1 -1
  56. package/lib/commonjs/utils/LogUtils.js +131 -0
  57. package/lib/commonjs/utils/LogUtils.js.map +1 -0
  58. package/lib/commonjs/utils/StorageUtil.js +131 -150
  59. package/lib/commonjs/utils/StorageUtil.js.map +1 -1
  60. package/lib/commonjs/utils/SwapApiUtil.js +15 -21
  61. package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
  62. package/lib/commonjs/utils/SwapCalculationUtil.js.map +1 -1
  63. package/lib/commonjs/utils/WalletUtil.js +23 -0
  64. package/lib/commonjs/utils/WalletUtil.js.map +1 -0
  65. package/lib/module/controllers/ApiController.js +159 -91
  66. package/lib/module/controllers/ApiController.js.map +1 -1
  67. package/lib/module/controllers/AssetController.js +2 -4
  68. package/lib/module/controllers/AssetController.js.map +1 -1
  69. package/lib/module/controllers/BlockchainApiController.js +182 -78
  70. package/lib/module/controllers/BlockchainApiController.js.map +1 -1
  71. package/lib/module/controllers/ConnectionsController.js +422 -0
  72. package/lib/module/controllers/ConnectionsController.js.map +1 -0
  73. package/lib/module/controllers/EnsController.js +4 -0
  74. package/lib/module/controllers/EnsController.js.map +1 -1
  75. package/lib/module/controllers/EventsController.js +53 -1
  76. package/lib/module/controllers/EventsController.js.map +1 -1
  77. package/lib/module/controllers/LogController.js +185 -0
  78. package/lib/module/controllers/LogController.js.map +1 -0
  79. package/lib/module/controllers/ModalController.js +11 -7
  80. package/lib/module/controllers/ModalController.js.map +1 -1
  81. package/lib/module/controllers/OnRampController.js +45 -16
  82. package/lib/module/controllers/OnRampController.js.map +1 -1
  83. package/lib/module/controllers/OptionsController.js +30 -10
  84. package/lib/module/controllers/OptionsController.js.map +1 -1
  85. package/lib/module/controllers/PublicStateController.js +2 -0
  86. package/lib/module/controllers/PublicStateController.js.map +1 -1
  87. package/lib/module/controllers/RouterController.js +9 -22
  88. package/lib/module/controllers/RouterController.js.map +1 -1
  89. package/lib/module/controllers/SendController.js +113 -95
  90. package/lib/module/controllers/SendController.js.map +1 -1
  91. package/lib/module/controllers/SnackController.js +31 -5
  92. package/lib/module/controllers/SnackController.js.map +1 -1
  93. package/lib/module/controllers/SwapController.js +164 -151
  94. package/lib/module/controllers/SwapController.js.map +1 -1
  95. package/lib/module/controllers/ThemeController.js +16 -1
  96. package/lib/module/controllers/ThemeController.js.map +1 -1
  97. package/lib/module/controllers/TransactionsController.js +26 -18
  98. package/lib/module/controllers/TransactionsController.js.map +1 -1
  99. package/lib/module/controllers/WcController.js +70 -0
  100. package/lib/module/controllers/WcController.js.map +1 -0
  101. package/lib/module/features/reown-authentication/ReownAuthentication.js +268 -0
  102. package/lib/module/features/reown-authentication/ReownAuthentication.js.map +1 -0
  103. package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js +43 -0
  104. package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
  105. package/lib/module/features/reown-authentication/index.js +5 -0
  106. package/lib/module/features/reown-authentication/index.js.map +1 -0
  107. package/lib/module/index.js +13 -8
  108. package/lib/module/index.js.map +1 -1
  109. package/lib/module/utils/ApiUtil.js +3 -1
  110. package/lib/module/utils/ApiUtil.js.map +1 -1
  111. package/lib/module/utils/AssetUtil.js +10 -18
  112. package/lib/module/utils/AssetUtil.js.map +1 -1
  113. package/lib/module/utils/ConstantsUtil.js +119 -5
  114. package/lib/module/utils/ConstantsUtil.js.map +1 -1
  115. package/lib/module/utils/CoreHelperUtil.js +34 -7
  116. package/lib/module/utils/CoreHelperUtil.js.map +1 -1
  117. package/lib/module/utils/EventUtil.js +2 -0
  118. package/lib/module/utils/EventUtil.js.map +1 -1
  119. package/lib/module/utils/FetchUtil.js +10 -2
  120. package/lib/module/utils/FetchUtil.js.map +1 -1
  121. package/lib/module/utils/LogUtils.js +121 -0
  122. package/lib/module/utils/LogUtils.js.map +1 -0
  123. package/lib/module/utils/StorageUtil.js +134 -150
  124. package/lib/module/utils/StorageUtil.js.map +1 -1
  125. package/lib/module/utils/SwapApiUtil.js +17 -21
  126. package/lib/module/utils/SwapApiUtil.js.map +1 -1
  127. package/lib/module/utils/SwapCalculationUtil.js +3 -0
  128. package/lib/module/utils/SwapCalculationUtil.js.map +1 -1
  129. package/lib/module/utils/WalletUtil.js +19 -0
  130. package/lib/module/utils/WalletUtil.js.map +1 -0
  131. package/lib/typescript/controllers/ApiController.d.ts +9 -8
  132. package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
  133. package/lib/typescript/controllers/AssetController.d.ts +0 -2
  134. package/lib/typescript/controllers/AssetController.d.ts.map +1 -1
  135. package/lib/typescript/controllers/BlockchainApiController.d.ts +29 -11
  136. package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
  137. package/lib/typescript/controllers/ConnectionsController.d.ts +47 -0
  138. package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -0
  139. package/lib/typescript/controllers/EnsController.d.ts +1 -1
  140. package/lib/typescript/controllers/EnsController.d.ts.map +1 -1
  141. package/lib/typescript/controllers/EventsController.d.ts +13 -1
  142. package/lib/typescript/controllers/EventsController.d.ts.map +1 -1
  143. package/lib/typescript/controllers/LogController.d.ts +65 -0
  144. package/lib/typescript/controllers/LogController.d.ts.map +1 -0
  145. package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
  146. package/lib/typescript/controllers/OnRampController.d.ts +2 -2
  147. package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
  148. package/lib/typescript/controllers/OptionsController.d.ts +11 -6
  149. package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
  150. package/lib/typescript/controllers/PublicStateController.d.ts +1 -1
  151. package/lib/typescript/controllers/PublicStateController.d.ts.map +1 -1
  152. package/lib/typescript/controllers/RouterController.d.ts +6 -20
  153. package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
  154. package/lib/typescript/controllers/SendController.d.ts +5 -7
  155. package/lib/typescript/controllers/SendController.d.ts.map +1 -1
  156. package/lib/typescript/controllers/SnackController.d.ts +3 -3
  157. package/lib/typescript/controllers/SnackController.d.ts.map +1 -1
  158. package/lib/typescript/controllers/SwapController.d.ts +12 -12
  159. package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
  160. package/lib/typescript/controllers/ThemeController.d.ts +3 -1
  161. package/lib/typescript/controllers/ThemeController.d.ts.map +1 -1
  162. package/lib/typescript/controllers/TransactionsController.d.ts +3 -3
  163. package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -1
  164. package/lib/typescript/controllers/WcController.d.ts +27 -0
  165. package/lib/typescript/controllers/WcController.d.ts.map +1 -0
  166. package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts +174 -0
  167. package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts.map +1 -0
  168. package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts +16 -0
  169. package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts.map +1 -0
  170. package/lib/typescript/features/reown-authentication/index.d.ts +3 -0
  171. package/lib/typescript/features/reown-authentication/index.d.ts.map +1 -0
  172. package/lib/typescript/index.d.ts +7 -9
  173. package/lib/typescript/index.d.ts.map +1 -1
  174. package/lib/typescript/utils/ApiUtil.d.ts +1 -1
  175. package/lib/typescript/utils/AssetUtil.d.ts +3 -4
  176. package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
  177. package/lib/typescript/utils/ConstantsUtil.d.ts +11 -2
  178. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
  179. package/lib/typescript/utils/CoreHelperUtil.d.ts +8 -6
  180. package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
  181. package/lib/typescript/utils/EventUtil.d.ts +1 -1
  182. package/lib/typescript/utils/EventUtil.d.ts.map +1 -1
  183. package/lib/typescript/utils/FetchUtil.d.ts +4 -4
  184. package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
  185. package/lib/typescript/utils/LogUtils.d.ts +15 -0
  186. package/lib/typescript/utils/LogUtils.d.ts.map +1 -0
  187. package/lib/typescript/utils/StorageUtil.d.ts +15 -16
  188. package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
  189. package/lib/typescript/utils/SwapApiUtil.d.ts +3 -4
  190. package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
  191. package/lib/typescript/utils/SwapCalculationUtil.d.ts +1 -1
  192. package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +1 -1
  193. package/lib/typescript/utils/WalletUtil.d.ts +5 -0
  194. package/lib/typescript/utils/WalletUtil.d.ts.map +1 -0
  195. package/package.json +11 -24
  196. package/src/controllers/ApiController.ts +167 -84
  197. package/src/controllers/AssetController.ts +0 -6
  198. package/src/controllers/BlockchainApiController.ts +168 -66
  199. package/src/controllers/ConnectionsController.ts +575 -0
  200. package/src/controllers/EnsController.ts +3 -1
  201. package/src/controllers/EventsController.ts +73 -2
  202. package/src/controllers/LogController.ts +250 -0
  203. package/src/controllers/ModalController.ts +10 -7
  204. package/src/controllers/OnRampController.ts +54 -19
  205. package/src/controllers/OptionsController.ts +46 -18
  206. package/src/controllers/PublicStateController.ts +1 -1
  207. package/src/controllers/RouterController.ts +20 -57
  208. package/src/controllers/SendController.ts +147 -111
  209. package/src/controllers/SnackController.ts +31 -5
  210. package/src/controllers/SwapController.ts +185 -183
  211. package/src/controllers/ThemeController.ts +18 -2
  212. package/src/controllers/TransactionsController.ts +27 -19
  213. package/src/controllers/WcController.ts +93 -0
  214. package/src/features/reown-authentication/ReownAuthentication.ts +475 -0
  215. package/src/features/reown-authentication/ReownAuthenticationMessenger.ts +80 -0
  216. package/src/features/reown-authentication/index.ts +2 -0
  217. package/src/index.ts +17 -20
  218. package/src/utils/ApiUtil.ts +1 -1
  219. package/src/utils/AssetUtil.ts +9 -22
  220. package/src/utils/ConstantsUtil.ts +121 -6
  221. package/src/utils/CoreHelperUtil.ts +66 -10
  222. package/src/utils/EventUtil.ts +1 -1
  223. package/src/utils/FetchUtil.ts +14 -5
  224. package/src/utils/LogUtils.ts +179 -0
  225. package/src/utils/StorageUtil.ts +191 -176
  226. package/src/utils/SwapApiUtil.ts +30 -37
  227. package/src/utils/SwapCalculationUtil.ts +1 -2
  228. package/src/utils/WalletUtil.ts +14 -0
  229. package/lib/commonjs/controllers/AccountController.js +0 -93
  230. package/lib/commonjs/controllers/AccountController.js.map +0 -1
  231. package/lib/commonjs/controllers/ConnectionController.js +0 -126
  232. package/lib/commonjs/controllers/ConnectionController.js.map +0 -1
  233. package/lib/commonjs/controllers/ConnectorController.js +0 -49
  234. package/lib/commonjs/controllers/ConnectorController.js.map +0 -1
  235. package/lib/commonjs/controllers/NetworkController.js +0 -90
  236. package/lib/commonjs/controllers/NetworkController.js.map +0 -1
  237. package/lib/commonjs/controllers/WebviewController.js +0 -52
  238. package/lib/commonjs/controllers/WebviewController.js.map +0 -1
  239. package/lib/commonjs/utils/ConnectionUtil.js +0 -33
  240. package/lib/commonjs/utils/ConnectionUtil.js.map +0 -1
  241. package/lib/commonjs/utils/NetworkUtil.js +0 -46
  242. package/lib/commonjs/utils/NetworkUtil.js.map +0 -1
  243. package/lib/commonjs/utils/RouterUtil.js +0 -25
  244. package/lib/commonjs/utils/RouterUtil.js.map +0 -1
  245. package/lib/commonjs/utils/TypeUtil.js +0 -35
  246. package/lib/commonjs/utils/TypeUtil.js.map +0 -1
  247. package/lib/module/controllers/AccountController.js +0 -88
  248. package/lib/module/controllers/AccountController.js.map +0 -1
  249. package/lib/module/controllers/ConnectionController.js +0 -121
  250. package/lib/module/controllers/ConnectionController.js.map +0 -1
  251. package/lib/module/controllers/ConnectorController.js +0 -44
  252. package/lib/module/controllers/ConnectorController.js.map +0 -1
  253. package/lib/module/controllers/NetworkController.js +0 -85
  254. package/lib/module/controllers/NetworkController.js.map +0 -1
  255. package/lib/module/controllers/WebviewController.js +0 -47
  256. package/lib/module/controllers/WebviewController.js.map +0 -1
  257. package/lib/module/utils/ConnectionUtil.js +0 -27
  258. package/lib/module/utils/ConnectionUtil.js.map +0 -1
  259. package/lib/module/utils/NetworkUtil.js +0 -40
  260. package/lib/module/utils/NetworkUtil.js.map +0 -1
  261. package/lib/module/utils/RouterUtil.js +0 -19
  262. package/lib/module/utils/RouterUtil.js.map +0 -1
  263. package/lib/module/utils/TypeUtil.js +0 -28
  264. package/lib/module/utils/TypeUtil.js.map +0 -1
  265. package/lib/typescript/controllers/AccountController.d.ts +0 -33
  266. package/lib/typescript/controllers/AccountController.d.ts.map +0 -1
  267. package/lib/typescript/controllers/ConnectionController.d.ts +0 -66
  268. package/lib/typescript/controllers/ConnectionController.d.ts.map +0 -1
  269. package/lib/typescript/controllers/ConnectorController.d.ts +0 -18
  270. package/lib/typescript/controllers/ConnectorController.d.ts.map +0 -1
  271. package/lib/typescript/controllers/NetworkController.d.ts +0 -34
  272. package/lib/typescript/controllers/NetworkController.d.ts.map +0 -1
  273. package/lib/typescript/controllers/WebviewController.d.ts +0 -21
  274. package/lib/typescript/controllers/WebviewController.d.ts.map +0 -1
  275. package/lib/typescript/utils/ConnectionUtil.d.ts +0 -4
  276. package/lib/typescript/utils/ConnectionUtil.d.ts.map +0 -1
  277. package/lib/typescript/utils/NetworkUtil.d.ts +0 -8
  278. package/lib/typescript/utils/NetworkUtil.d.ts.map +0 -1
  279. package/lib/typescript/utils/RouterUtil.d.ts +0 -5
  280. package/lib/typescript/utils/RouterUtil.d.ts.map +0 -1
  281. package/lib/typescript/utils/TypeUtil.d.ts +0 -849
  282. package/lib/typescript/utils/TypeUtil.d.ts.map +0 -1
  283. package/src/controllers/AccountController.ts +0 -128
  284. package/src/controllers/ConnectionController.ts +0 -200
  285. package/src/controllers/ConnectorController.ts +0 -63
  286. package/src/controllers/NetworkController.ts +0 -120
  287. package/src/controllers/WebviewController.ts +0 -63
  288. package/src/utils/ConnectionUtil.ts +0 -27
  289. package/src/utils/NetworkUtil.ts +0 -33
  290. package/src/utils/RouterUtil.ts +0 -21
  291. package/src/utils/TypeUtil.ts +0 -1036
@@ -1,11 +1,11 @@
1
- import type { Transaction } from '@reown/appkit-common-react-native';
1
+ import type { CaipAddress, Transaction } from '@reown/appkit-common-react-native';
2
2
  import { proxy, subscribe as sub } from 'valtio';
3
3
  import { OptionsController } from './OptionsController';
4
4
  import { EventsController } from './EventsController';
5
5
  import { SnackController } from './SnackController';
6
- import { NetworkController } from './NetworkController';
7
6
  import { BlockchainApiController } from './BlockchainApiController';
8
- import { AccountController } from './AccountController';
7
+ import { ConnectionsController } from './ConnectionsController';
8
+ import { LogController } from './LogController';
9
9
 
10
10
  // -- Types --------------------------------------------- //
11
11
  type TransactionByMonthMap = Record<string, Transaction[]>;
@@ -34,22 +34,29 @@ export const TransactionsController = {
34
34
  return sub(state, () => callback(state));
35
35
  },
36
36
 
37
- async fetchTransactions(accountAddress?: string, reset?: boolean) {
38
- const { projectId } = OptionsController.state;
37
+ async fetchTransactions(accountAddress: CaipAddress, reset?: boolean) {
38
+ try {
39
+ const { projectId } = OptionsController.state;
39
40
 
40
- if (!projectId || !accountAddress) {
41
- throw new Error("Transactions can't be fetched without a projectId and an accountAddress");
42
- }
41
+ if (!projectId || !accountAddress) {
42
+ throw new Error("Transactions can't be fetched without a projectId and an accountAddress");
43
+ }
43
44
 
44
- state.loading = true;
45
+ state.loading = true;
45
46
 
46
- if (reset) {
47
- state.next = undefined;
48
- }
47
+ if (reset) {
48
+ state.next = undefined;
49
+ }
50
+
51
+ const [namespace, chain, address] = accountAddress?.split(':') ?? [];
52
+
53
+ if (!namespace || !chain || !address) {
54
+ throw new Error('Invalid address');
55
+ }
49
56
 
50
- try {
51
57
  const response = await BlockchainApiController.fetchTransactions({
52
- account: accountAddress,
58
+ account: address,
59
+ chainId: `${namespace}:${chain}`,
53
60
  projectId,
54
61
  cursor: state.next
55
62
  });
@@ -68,14 +75,15 @@ export const TransactionsController = {
68
75
  state.empty = nonSpamTransactions.length === 0;
69
76
  state.next = response?.next ? response.next : undefined;
70
77
  } catch (error) {
78
+ LogController.sendError(error, 'TransactionsController.ts', 'fetchTransactions');
71
79
  EventsController.sendEvent({
72
80
  type: 'track',
73
81
  event: 'ERROR_FETCH_TRANSACTIONS',
74
82
  properties: {
75
- address: accountAddress,
76
- projectId,
83
+ address: accountAddress ?? '',
84
+ projectId: OptionsController.state.projectId,
77
85
  cursor: state.next,
78
- isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount'
86
+ isSmartAccount: ConnectionsController.state.accountType === 'smartAccount'
79
87
  }
80
88
  });
81
89
  SnackController.showError('Failed to fetch transactions');
@@ -121,7 +129,7 @@ export const TransactionsController = {
121
129
  },
122
130
 
123
131
  filterByConnectedChain(transactions: Transaction[]) {
124
- const chainId = NetworkController.state.caipNetwork?.id;
132
+ const chainId = ConnectionsController.state.activeCaipNetworkId;
125
133
  const filteredTransactions = transactions.filter(
126
134
  transaction => transaction.metadata.chain === chainId
127
135
  );
@@ -133,7 +141,7 @@ export const TransactionsController = {
133
141
  state.next = undefined;
134
142
  },
135
143
 
136
- resetTransactions() {
144
+ resetState() {
137
145
  state.transactions = [];
138
146
  state.loading = false;
139
147
  state.empty = false;
@@ -0,0 +1,93 @@
1
+ import { proxy } from 'valtio';
2
+ import { subscribeKey as subKey } from 'valtio/utils';
3
+ import type { WalletDeepLink, WcWallet } from '@reown/appkit-common-react-native';
4
+ import { CoreHelperUtil } from '../utils/CoreHelperUtil';
5
+ import { StorageUtil } from '../utils/StorageUtil';
6
+
7
+ // -- Types --------------------------------------------- //
8
+ export interface WcControllerState {
9
+ wcUri?: string;
10
+ wcPromise?: Promise<void>;
11
+ wcPairingExpiry?: number;
12
+ wcLinking?: WalletDeepLink;
13
+ wcError?: boolean;
14
+ pressedWallet?: WcWallet;
15
+ recentWallets?: WcWallet[];
16
+ }
17
+
18
+ type StateKey = keyof WcControllerState;
19
+
20
+ // -- State --------------------------------------------- //
21
+ const state = proxy<WcControllerState>({
22
+ wcError: false
23
+ });
24
+
25
+ // -- Controller ---------------------------------------- //
26
+ export const WcController = {
27
+ state,
28
+
29
+ subscribeKey<K extends StateKey>(key: K, callback: (value: WcControllerState[K]) => void) {
30
+ return subKey(state, key, callback);
31
+ },
32
+
33
+ setWcLinking(wcLinking: WcControllerState['wcLinking']) {
34
+ state.wcLinking = wcLinking;
35
+ },
36
+
37
+ removeWcLinking() {
38
+ state.wcLinking = undefined;
39
+ },
40
+
41
+ setWcError(wcError: WcControllerState['wcError']) {
42
+ state.wcError = wcError;
43
+ },
44
+
45
+ setPressedWallet(wallet: WcControllerState['pressedWallet']) {
46
+ state.pressedWallet = wallet;
47
+ },
48
+
49
+ removePressedWallet() {
50
+ state.pressedWallet = undefined;
51
+ },
52
+
53
+ setWcPromise(wcPromise: WcControllerState['wcPromise']) {
54
+ state.wcPromise = wcPromise;
55
+ },
56
+
57
+ setWcUri(wcUri: WcControllerState['wcUri']) {
58
+ state.wcUri = wcUri;
59
+ state.wcPairingExpiry = CoreHelperUtil.getPairingExpiry();
60
+ },
61
+
62
+ setRecentWallets(wallets: WcControllerState['recentWallets']) {
63
+ state.recentWallets = wallets;
64
+ },
65
+
66
+ async addRecentWallet(wallet: WcWallet) {
67
+ const recentWallets = await StorageUtil.addRecentWallet(wallet);
68
+ if (recentWallets) {
69
+ WcController.setRecentWallets(recentWallets);
70
+ }
71
+ },
72
+
73
+ setConnectedWallet: async (wcLinking: WalletDeepLink, pressedWallet?: WcWallet) => {
74
+ StorageUtil.setWalletConnectDeepLink(wcLinking);
75
+
76
+ if (pressedWallet) {
77
+ WcController.addRecentWallet(pressedWallet);
78
+ }
79
+ },
80
+
81
+ clearUri() {
82
+ state.wcUri = undefined;
83
+ state.wcPairingExpiry = undefined;
84
+ state.wcPromise = undefined;
85
+ state.wcLinking = undefined;
86
+ },
87
+
88
+ resetState() {
89
+ this.clearUri();
90
+ state.pressedWallet = undefined;
91
+ StorageUtil.removeWalletConnectDeepLink();
92
+ }
93
+ };
@@ -0,0 +1,475 @@
1
+ import {
2
+ type CaipNetworkId,
3
+ type ChainNamespace,
4
+ type SafeStorageItems,
5
+ SafeStorageKeys,
6
+ type SIWXConfig,
7
+ type SIWXMessage,
8
+ type SIWXSession
9
+ } from '@reown/appkit-common-react-native';
10
+
11
+ import { ApiController } from '../../controllers/ApiController';
12
+ import { BlockchainApiController } from '../../controllers/BlockchainApiController';
13
+
14
+ import { ReownAuthenticationMessenger } from './ReownAuthenticationMessenger';
15
+ import { ConnectionsController } from '../../controllers/ConnectionsController';
16
+ import { CoreHelperUtil } from '../../utils/CoreHelperUtil';
17
+ import { OptionsController } from '../../controllers/OptionsController';
18
+ import { FetchUtil } from '../../utils/FetchUtil';
19
+ import { ApiUtil } from '../../utils/ApiUtil';
20
+ import { LogController } from '../../controllers/LogController';
21
+
22
+ /**
23
+ * This is the configuration for using SIWX with Reown Authentication service.
24
+ * It allows you to authenticate and capture user sessions through the Reown Dashboard.
25
+ */
26
+ export class ReownAuthentication implements SIWXConfig {
27
+ private readonly localAuthStorageKey: keyof SafeStorageItems;
28
+ private readonly localNonceStorageKey: keyof SafeStorageItems;
29
+ private readonly messenger: ReownAuthenticationMessenger;
30
+ private readonly fetchUtil = new FetchUtil({ baseUrl: CoreHelperUtil.getApiUrl() });
31
+ public readonly signOutOnDisconnect: boolean;
32
+
33
+ private required: boolean;
34
+
35
+ private listeners: ReownAuthentication.EventListeners = {
36
+ sessionChanged: []
37
+ };
38
+
39
+ constructor(params: ReownAuthentication.ConstructorParams = {}) {
40
+ this.localAuthStorageKey =
41
+ (params.localAuthStorageKey as keyof SafeStorageItems) || SafeStorageKeys.SIWX_AUTH_TOKEN;
42
+ this.localNonceStorageKey =
43
+ (params.localNonceStorageKey as keyof SafeStorageItems) || SafeStorageKeys.SIWX_NONCE_TOKEN;
44
+ this.required = params.required ?? true;
45
+
46
+ this.messenger = new ReownAuthenticationMessenger({
47
+ getNonce: this.getNonce.bind(this)
48
+ });
49
+
50
+ this.signOutOnDisconnect = params.signOutOnDisconnect ?? true;
51
+ }
52
+
53
+ async createMessage(input: SIWXMessage.Input): Promise<SIWXMessage> {
54
+ return this.messenger.createMessage(input);
55
+ }
56
+
57
+ async addSession(session: SIWXSession): Promise<void> {
58
+ const response = await this.request({
59
+ method: 'POST',
60
+ key: 'authenticate',
61
+ body: {
62
+ data: session.cacao ? undefined : session.data,
63
+ message: session.message,
64
+ signature: session.signature,
65
+ clientId: this.getClientId(),
66
+ walletInfo: this.getWalletInfo()
67
+ },
68
+ headers: ['nonce']
69
+ });
70
+
71
+ this.setStorageToken(response.token, this.localAuthStorageKey);
72
+
73
+ this.emit('sessionChanged', session);
74
+ }
75
+
76
+ async getSessions(chainId: CaipNetworkId, address: string): Promise<SIWXSession[]> {
77
+ try {
78
+ const sessions = await this.getStorageToken(this.localAuthStorageKey);
79
+ if (!sessions) {
80
+ return [];
81
+ }
82
+
83
+ const account = await this.request({
84
+ method: 'GET',
85
+ key: 'me',
86
+ query: {},
87
+ headers: ['auth']
88
+ });
89
+
90
+ if (!account) {
91
+ return [];
92
+ }
93
+
94
+ const isSameAddress = account.address.toLowerCase() === address.toLowerCase();
95
+ const isSameNetwork = account.caip2Network === chainId;
96
+
97
+ if (!isSameAddress || !isSameNetwork) {
98
+ return [];
99
+ }
100
+
101
+ const session: SIWXSession = {
102
+ data: {
103
+ accountAddress: account.address,
104
+ chainId: account.caip2Network
105
+ } as SIWXMessage.Data,
106
+ message: '',
107
+ signature: ''
108
+ };
109
+
110
+ this.emit('sessionChanged', session);
111
+
112
+ return [session];
113
+ } catch (error) {
114
+ LogController.sendError(error, 'ReownAuthentication.ts', 'getSessions');
115
+
116
+ return [];
117
+ }
118
+ }
119
+
120
+ async revokeSession(_chainId: CaipNetworkId, _address: string): Promise<void> {
121
+ return Promise.resolve(this.clearStorageTokens());
122
+ }
123
+
124
+ async setSessions(sessions: SIWXSession[]): Promise<void> {
125
+ if (sessions.length === 0) {
126
+ this.clearStorageTokens();
127
+ } else {
128
+ const session = (sessions.find(
129
+ s => s.data.chainId === ConnectionsController.state.activeCaipNetworkId
130
+ ) || sessions[0]) as SIWXSession;
131
+
132
+ await this.addSession(session);
133
+ }
134
+ }
135
+
136
+ getRequired() {
137
+ return this.required;
138
+ }
139
+
140
+ async getSessionAccount() {
141
+ const sessions = await this.getStorageToken(this.localAuthStorageKey);
142
+ if (!sessions) {
143
+ throw new Error('Not authenticated');
144
+ }
145
+
146
+ return this.request({
147
+ method: 'GET',
148
+ key: 'me',
149
+ body: undefined,
150
+ query: {
151
+ includeAppKitAccount: true
152
+ },
153
+ headers: ['auth']
154
+ });
155
+ }
156
+
157
+ async setSessionAccountMetadata(metadata: object | null = null) {
158
+ const sessions = await this.getStorageToken(this.localAuthStorageKey);
159
+ if (!sessions) {
160
+ throw new Error('Not authenticated');
161
+ }
162
+
163
+ return this.request({
164
+ method: 'PUT',
165
+ key: 'account-metadata',
166
+ body: { metadata },
167
+ headers: ['auth']
168
+ });
169
+ }
170
+
171
+ on<Event extends keyof ReownAuthentication.Events>(
172
+ event: Event,
173
+ callback: ReownAuthentication.Listener<Event>
174
+ ) {
175
+ this.listeners[event].push(callback);
176
+
177
+ return () => {
178
+ this.listeners[event] = this.listeners[event].filter(
179
+ cb => cb !== callback
180
+ ) as ReownAuthentication.EventListeners[Event];
181
+ };
182
+ }
183
+
184
+ removeAllListeners() {
185
+ const keys = Object.keys(this.listeners) as (keyof ReownAuthentication.Events)[];
186
+ keys.forEach(key => {
187
+ this.listeners[key] = [];
188
+ });
189
+ }
190
+
191
+ private async request<
192
+ Method extends ReownAuthentication.Methods,
193
+ Key extends ReownAuthentication.RequestKeys<Method>
194
+ >({
195
+ method,
196
+ key,
197
+ query,
198
+ body,
199
+ headers
200
+ }: ReownAuthentication.RequestParams<Key, Method>): Promise<
201
+ ReownAuthentication.RequestResponse<Method, Key>
202
+ > {
203
+ const { projectId, st, sv, domain } = this.getSDKProperties();
204
+
205
+ const url = this.fetchUtil.createUrl({
206
+ path: `/auth/v1/${String(key)}`,
207
+ params: { projectId, st, sv, domain, ...query }
208
+ });
209
+
210
+ const nonceJwt = await this.getStorageToken(this.localNonceStorageKey);
211
+ const auth = await this.getStorageToken(this.localAuthStorageKey);
212
+
213
+ const response = await fetch(url, {
214
+ method,
215
+ body: body ? JSON.stringify(body) : undefined,
216
+ headers: {
217
+ 'Content-Type': 'application/json',
218
+ ...(Array.isArray(headers)
219
+ ? headers.reduce((acc, header) => {
220
+ switch (header) {
221
+ case 'nonce':
222
+ acc['x-nonce-jwt'] = `Bearer ${nonceJwt}`;
223
+ break;
224
+ case 'auth':
225
+ acc['Authorization'] = `Bearer ${auth}`;
226
+ break;
227
+ default:
228
+ break;
229
+ }
230
+
231
+ return acc;
232
+ }, {})
233
+ : {})
234
+ }
235
+ });
236
+
237
+ if (!response.ok) {
238
+ throw new Error(await response.text());
239
+ }
240
+
241
+ if (response.headers.get('content-type')?.includes('application/json')) {
242
+ return response.json();
243
+ }
244
+
245
+ return null as ReownAuthentication.RequestResponse<Method, Key>;
246
+ }
247
+
248
+ private async getStorageToken(key: keyof SafeStorageItems): Promise<string | undefined> {
249
+ return OptionsController.getStorage().getItem(key);
250
+ }
251
+
252
+ private setStorageToken(token: string, key: keyof SafeStorageItems): void {
253
+ OptionsController.getStorage().setItem(key, token);
254
+ }
255
+
256
+ private clearStorageTokens(): void {
257
+ OptionsController.getStorage().removeItem(this.localAuthStorageKey);
258
+ OptionsController.getStorage().removeItem(this.localNonceStorageKey);
259
+ this.emit('sessionChanged', undefined);
260
+ }
261
+
262
+ private async getNonce(): Promise<string> {
263
+ const { nonce, token } = await this.request({
264
+ method: 'GET',
265
+ key: 'nonce'
266
+ });
267
+
268
+ this.setStorageToken(token, this.localNonceStorageKey);
269
+
270
+ return nonce;
271
+ }
272
+
273
+ private getClientId(): string | null {
274
+ return BlockchainApiController.state.clientId;
275
+ }
276
+
277
+ private getWalletInfo(): ReownAuthentication.WalletInfo | undefined {
278
+ const connectedWalletInfo = ConnectionsController.state.walletInfo;
279
+ const connectionProperties = ConnectionsController.state.connection?.properties;
280
+
281
+ if (!connectedWalletInfo || !connectionProperties) {
282
+ return undefined;
283
+ }
284
+
285
+ if (connectionProperties?.provider) {
286
+ const social = connectionProperties.provider;
287
+ const identifier = connectionProperties.email || 'unknown';
288
+
289
+ return { type: 'social', social, identifier };
290
+ }
291
+
292
+ let { name, icon, type } = connectedWalletInfo;
293
+
294
+ if (!type || type !== 'walletconnect') {
295
+ type = 'unknown';
296
+ }
297
+
298
+ return {
299
+ type,
300
+ name,
301
+ icon
302
+ };
303
+ }
304
+
305
+ private getSDKProperties(): { projectId: string; st: string; sv: string; domain: string } {
306
+ const { projectId, st, sv } = ApiController._getApiParams();
307
+ const domain = ApiUtil.getOrigin();
308
+
309
+ return {
310
+ projectId,
311
+ st,
312
+ sv,
313
+ domain
314
+ };
315
+ }
316
+
317
+ private emit<Event extends keyof ReownAuthentication.Events>(
318
+ event: Event,
319
+ data: ReownAuthentication.Events[Event]
320
+ ) {
321
+ this.listeners[event].forEach(listener => listener(data));
322
+ }
323
+ }
324
+
325
+ export namespace ReownAuthentication {
326
+ export type ConstructorParams = {
327
+ /**
328
+ * The key to use for storing the session token in local storage.
329
+ * @default '@appkit/siwx-auth-token'
330
+ */
331
+ localAuthStorageKey?: string;
332
+ /**
333
+ * The key to use for storing the nonce token in local storage.
334
+ * @default '@appkit/siwx-nonce-token'
335
+ */
336
+ localNonceStorageKey?: string;
337
+ /**
338
+ * If false the wallet stays connected when user denies the signature request.
339
+ * @default true
340
+ */
341
+ required?: boolean;
342
+ /**
343
+ * This flag determines whether the session should be cleared when the user disconnects.
344
+ *
345
+ * @default true
346
+ */
347
+ signOutOnDisconnect?: boolean;
348
+ };
349
+
350
+ export type AvailableRequestHeaders = {
351
+ nonce: {
352
+ 'x-nonce-jwt': string;
353
+ };
354
+ auth: {
355
+ Authorization: string;
356
+ };
357
+ origin: {
358
+ origin: string;
359
+ };
360
+ };
361
+
362
+ export type RequestParams<Key extends keyof Requests[Method], Method extends Methods> = {
363
+ method: Method;
364
+ key: Key;
365
+ // @ts-expect-error - This is matching correctly already
366
+ } & Pick<Requests[Method][Key], 'query' | 'body' | 'headers'>;
367
+
368
+ export type RequestResponse<
369
+ Method extends Methods,
370
+ Key extends RequestKeys<Method>
371
+ // @ts-expect-error - This is matching correctly already
372
+ > = Requests[Method][Key]['response'];
373
+
374
+ export type Request<
375
+ Body,
376
+ Response,
377
+ Query extends Record<string, unknown> | undefined = undefined,
378
+ Headers extends (keyof AvailableRequestHeaders)[] | undefined = undefined
379
+ > = (Response extends undefined
380
+ ? {
381
+ response?: never;
382
+ }
383
+ : {
384
+ response: Response;
385
+ }) &
386
+ (Body extends undefined ? { body?: never } : { body: Body }) &
387
+ (Query extends undefined ? { query?: never } : { query: Query }) &
388
+ (Headers extends undefined ? { headers?: never } : { headers: Headers });
389
+
390
+ export type Requests = {
391
+ GET: {
392
+ nonce: Request<undefined, { nonce: string; token: string }>;
393
+ me: Request<
394
+ undefined,
395
+ Omit<SessionAccount, 'appKitAccount'>,
396
+ { includeAppKitAccount?: boolean },
397
+ ['auth']
398
+ >;
399
+ };
400
+ POST: {
401
+ 'authenticate': Request<
402
+ {
403
+ data?: SIWXMessage.Data;
404
+ message: string;
405
+ signature: string;
406
+ clientId?: string | null;
407
+ walletInfo?: WalletInfo;
408
+ },
409
+ {
410
+ token: string;
411
+ },
412
+ undefined,
413
+ ['nonce']
414
+ >;
415
+ 'sign-out': Request<undefined, never, never, ['auth']>;
416
+ };
417
+ PUT: {
418
+ 'account-metadata': Request<{ metadata: object | null }, unknown, undefined, ['auth']>;
419
+ };
420
+ };
421
+
422
+ export type Methods = 'GET' | 'POST' | 'PUT';
423
+
424
+ export type RequestKeys<Method extends Methods> = keyof Requests[Method];
425
+
426
+ export type WalletInfo =
427
+ | {
428
+ type: 'walletconnect' | 'external' | 'unknown';
429
+ name: string | undefined;
430
+ icon: string | undefined;
431
+ }
432
+ | { type: 'social'; social: string; identifier: string };
433
+
434
+ export type Events = {
435
+ sessionChanged: SIWXSession | undefined;
436
+ };
437
+
438
+ export type Listener<Event extends keyof Events> = (event: Events[Event]) => void;
439
+
440
+ export type EventListeners = {
441
+ [Key in keyof Events]: Listener<Key>[];
442
+ };
443
+
444
+ export type SessionAccount = {
445
+ aud: string;
446
+ iss: string;
447
+ exp: number;
448
+ projectIdKey: string;
449
+ sub: string;
450
+ address: string;
451
+ chainId: number | string;
452
+ chainNamespace: ChainNamespace;
453
+ caip2Network: string;
454
+ uri: string;
455
+ domain: string;
456
+ projectUuid: string;
457
+ profileUuid: string;
458
+ nonce: string;
459
+ email?: string;
460
+ appKitAccount?: {
461
+ uuid: string;
462
+ caip2_chain: string;
463
+ address: string;
464
+ profile_uuid: string;
465
+ created_at: string;
466
+ is_main_account: boolean;
467
+ verification_status: null;
468
+ connection_method: object | null;
469
+ metadata: object;
470
+ last_signed_in_at: string;
471
+ signed_up_at: string;
472
+ updated_at: string;
473
+ };
474
+ };
475
+ }