@reown/appkit-core-react-native 0.0.0-develop-20250728153935 → 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 -850
  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 -1039
@@ -1,22 +1,12 @@
1
1
  import { proxy } from 'valtio';
2
2
  import type {
3
+ AppKitNetwork,
4
+ SocialProvider,
3
5
  WcWallet,
4
- CaipNetwork,
5
- Connector,
6
- SwapInputTarget,
7
6
  OnRampTransactionResult
8
- } from '../utils/TypeUtil';
7
+ } from '@reown/appkit-common-react-native';
9
8
 
10
9
  // -- Types --------------------------------------------- //
11
- type TransactionAction = {
12
- goBack: boolean;
13
- view: RouterControllerState['view'] | null;
14
- close?: boolean;
15
- replace?: boolean;
16
- onSuccess?: () => void;
17
- onCancel?: () => void;
18
- };
19
-
20
10
  export interface RouterControllerState {
21
11
  view:
22
12
  | 'Account'
@@ -25,13 +15,7 @@ export interface RouterControllerState {
25
15
  | 'Connect'
26
16
  | 'ConnectSocials'
27
17
  | 'ConnectingExternal'
28
- | 'ConnectingSiwe'
29
18
  | 'ConnectingSocial'
30
- | 'ConnectingFarcaster'
31
- | 'ConnectingWalletConnect'
32
- | 'Create'
33
- | 'EmailVerifyDevice'
34
- | 'EmailVerifyOtp'
35
19
  | 'GetWallet'
36
20
  | 'Networks'
37
21
  | 'OnRamp'
@@ -39,18 +23,15 @@ export interface RouterControllerState {
39
23
  | 'OnRampLoading'
40
24
  | 'OnRampSettings'
41
25
  | 'OnRampTransaction'
42
- | 'SwitchNetwork'
26
+ | 'SIWXSignMessage'
43
27
  | 'Swap'
44
- | 'SwapSelectToken'
45
28
  | 'SwapPreview'
29
+ | 'SwitchNetwork'
46
30
  | 'Transactions'
47
31
  | 'UnsupportedChain'
48
- | 'UpdateEmailPrimaryOtp'
49
- | 'UpdateEmailSecondaryOtp'
50
- | 'UpdateEmailWallet'
51
32
  | 'UpgradeEmailWallet'
52
- | 'UpgradeToSmartAccount'
53
33
  | 'WalletCompatibleNetworks'
34
+ | 'WalletConnect'
54
35
  | 'WalletReceive'
55
36
  | 'WalletSend'
56
37
  | 'WalletSendPreview'
@@ -58,62 +39,41 @@ export interface RouterControllerState {
58
39
  | 'WhatIsANetwork'
59
40
  | 'WhatIsAWallet';
60
41
  history: RouterControllerState['view'][];
42
+ navigationDirection: 'forward' | 'backward' | 'none';
61
43
  data?: {
62
- connector?: Connector;
63
44
  wallet?: WcWallet;
64
- network?: CaipNetwork;
65
- email?: string;
66
- newEmail?: string;
67
- swapTarget?: SwapInputTarget;
45
+ network?: AppKitNetwork;
68
46
  onrampResult?: OnRampTransactionResult;
47
+ socialProvider?: SocialProvider;
69
48
  };
70
- transactionStack: TransactionAction[];
71
49
  }
72
50
 
73
51
  // -- State --------------------------------------------- //
74
52
  const state = proxy<RouterControllerState>({
75
53
  view: 'Connect',
76
54
  history: ['Connect'],
77
- transactionStack: []
55
+ navigationDirection: 'none'
78
56
  });
79
57
 
80
58
  // -- Controller ---------------------------------------- //
81
59
  export const RouterController = {
82
60
  state,
83
61
 
84
- push(view: RouterControllerState['view'], data?: RouterControllerState['data']) {
62
+ push(
63
+ view: RouterControllerState['view'],
64
+ data?: RouterControllerState['data'],
65
+ direction: 'forward' | 'backward' = 'forward'
66
+ ) {
85
67
  if (view !== state.view) {
68
+ state.navigationDirection = direction;
86
69
  state.view = view;
87
70
  state.history = [...state.history, view];
88
71
  state.data = data;
89
72
  }
90
73
  },
91
74
 
92
- pushTransactionStack(action: TransactionAction) {
93
- state.transactionStack = [...state.transactionStack, action];
94
- },
95
-
96
- popTransactionStack(cancel?: boolean) {
97
- const action = state.transactionStack.pop();
98
-
99
- if (!action) {
100
- return;
101
- }
102
-
103
- if (cancel) {
104
- this.goBack();
105
- action?.onCancel?.();
106
- } else {
107
- if (action.goBack) {
108
- this.goBack();
109
- } else if (action.view) {
110
- this.reset(action.view);
111
- }
112
- action?.onSuccess?.();
113
- }
114
- },
115
-
116
75
  reset(view: RouterControllerState['view'], data?: RouterControllerState['data']) {
76
+ state.navigationDirection = 'none';
117
77
  state.view = view;
118
78
  state.history = [view];
119
79
  state.data = data;
@@ -121,6 +81,7 @@ export const RouterController = {
121
81
 
122
82
  replace(view: RouterControllerState['view'], data?: RouterControllerState['data']) {
123
83
  if (state.history.length >= 1 && state.history.at(-1) !== view) {
84
+ state.navigationDirection = 'none';
124
85
  state.view = view;
125
86
  state.history[state.history.length - 1] = view;
126
87
  state.data = data;
@@ -132,6 +93,7 @@ export const RouterController = {
132
93
  state.history.pop();
133
94
  const [last] = state.history.slice(-1);
134
95
  if (last) {
96
+ state.navigationDirection = 'backward';
135
97
  state.view = last;
136
98
  }
137
99
  }
@@ -142,6 +104,7 @@ export const RouterController = {
142
104
  state.history = state.history.slice(0, historyIndex + 1);
143
105
  const [last] = state.history.slice(-1);
144
106
  if (last) {
107
+ state.navigationDirection = 'backward';
145
108
  state.view = last;
146
109
  }
147
110
  }
@@ -1,19 +1,20 @@
1
1
  import { subscribeKey as subKey } from 'valtio/utils';
2
2
  import { proxy, ref, subscribe as sub } from 'valtio';
3
3
  import { ContractUtil, type Balance } from '@reown/appkit-common-react-native';
4
- import { AccountController } from './AccountController';
5
- import { ConnectionController } from './ConnectionController';
4
+
6
5
  import { SnackController } from './SnackController';
7
6
  import { CoreHelperUtil } from '../utils/CoreHelperUtil';
8
7
  import { EventsController } from './EventsController';
9
- import { NetworkController } from './NetworkController';
10
8
  import { RouterController } from './RouterController';
9
+ import { ConnectionsController } from './ConnectionsController';
10
+ import { SwapController } from './SwapController';
11
+ import { ConstantsUtil as CoreConstantsUtil } from '../utils/ConstantsUtil';
12
+ import { LogController } from './LogController';
11
13
 
12
14
  // -- Types --------------------------------------------- //
13
15
  export interface TxParams {
14
16
  receiverAddress: string;
15
17
  sendTokenAmount: number;
16
- gasPrice: bigint;
17
18
  decimals: string;
18
19
  }
19
20
 
@@ -30,8 +31,6 @@ export interface SendControllerState {
30
31
  receiverAddress?: string;
31
32
  receiverProfileName?: string;
32
33
  receiverProfileImageUrl?: string;
33
- gasPrice?: bigint;
34
- gasPriceInUSD?: number;
35
34
  loading: boolean;
36
35
  }
37
36
 
@@ -78,152 +77,189 @@ export const SendController = {
78
77
  state.receiverProfileName = receiverProfileName;
79
78
  },
80
79
 
81
- setGasPrice(gasPrice: SendControllerState['gasPrice']) {
82
- state.gasPrice = gasPrice;
83
- },
84
-
85
- setGasPriceInUsd(gasPriceInUSD: SendControllerState['gasPriceInUSD']) {
86
- state.gasPriceInUSD = gasPriceInUSD;
87
- },
88
-
89
80
  setLoading(loading: SendControllerState['loading']) {
90
81
  state.loading = loading;
91
82
  },
92
83
 
93
- sendToken() {
94
- if (this.state.token?.address && this.state.sendTokenAmount && this.state.receiverAddress) {
95
- state.loading = true;
84
+ async sendToken() {
85
+ const isAuth = !!ConnectionsController.state.connection?.properties?.provider;
86
+ const eventProperties = {
87
+ isSmartAccount: ConnectionsController.state.accountType === 'smartAccount',
88
+ token: this.state.token?.address ?? this.state.token?.symbol ?? '',
89
+ amount: this.state.sendTokenAmount || 0,
90
+ network: ConnectionsController.state.activeNetwork?.caipNetworkId
91
+ };
92
+
93
+ try {
94
+ this.state.loading = true;
95
+
96
96
  EventsController.sendEvent({
97
97
  type: 'track',
98
98
  event: 'SEND_INITIATED',
99
- properties: {
100
- isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount',
101
- token: this.state.token.address,
102
- amount: this.state.sendTokenAmount,
103
- network: NetworkController.state.caipNetwork?.id || ''
104
- }
99
+ properties: eventProperties
100
+ });
101
+
102
+ switch (ConnectionsController.state.activeNamespace) {
103
+ case 'eip155':
104
+ await SendController.sendEvmToken();
105
+
106
+ break;
107
+ case 'solana':
108
+ await SendController.sendSolanaToken();
109
+
110
+ break;
111
+ default:
112
+ throw new Error('Unsupported chain');
113
+ }
114
+
115
+ SnackController.showSuccess('Transaction started');
116
+ EventsController.sendEvent({
117
+ type: 'track',
118
+ event: 'SEND_SUCCESS',
119
+ properties: eventProperties
105
120
  });
106
- this.sendERC20Token({
121
+ RouterController.reset(isAuth ? 'Account' : 'AccountDefault');
122
+ this.resetState();
123
+ } catch (error: any) {
124
+ LogController.sendError(error, 'SendController.ts', 'sendToken');
125
+ EventsController.sendEvent({
126
+ type: 'track',
127
+ event: 'SEND_ERROR',
128
+ properties: eventProperties
129
+ });
130
+
131
+ if (
132
+ error?.message &&
133
+ (error?.message.includes('user rejected') || error?.message.includes('canceled'))
134
+ ) {
135
+ SnackController.showError('Transaction cancelled');
136
+ } else {
137
+ SnackController.showError('Something went wrong');
138
+ }
139
+ } finally {
140
+ this.state.loading = false;
141
+ }
142
+ },
143
+
144
+ async sendEvmToken() {
145
+ if (this.state.token?.address && this.state.sendTokenAmount && this.state.receiverAddress) {
146
+ await this.sendERC20Token({
107
147
  receiverAddress: this.state.receiverAddress,
108
148
  tokenAddress: this.state.token.address,
109
149
  sendTokenAmount: this.state.sendTokenAmount,
110
- decimals: this.state.token.quantity.decimals
150
+ decimals: this.state.token.quantity?.decimals || '0'
111
151
  });
112
152
  } else if (
113
153
  this.state.receiverAddress &&
114
154
  this.state.sendTokenAmount &&
115
- this.state.gasPrice &&
116
- this.state.token?.quantity.decimals
155
+ this.state.token?.quantity?.decimals
117
156
  ) {
118
- state.loading = true;
119
- EventsController.sendEvent({
120
- type: 'track',
121
- event: 'SEND_INITIATED',
122
- properties: {
123
- isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount',
124
- token: this.state.token?.symbol,
125
- amount: this.state.sendTokenAmount,
126
- network: NetworkController.state.caipNetwork?.id || ''
127
- }
128
- });
129
- this.sendNativeToken({
157
+ await this.sendNativeToken({
130
158
  receiverAddress: this.state.receiverAddress,
131
159
  sendTokenAmount: this.state.sendTokenAmount,
132
- gasPrice: this.state.gasPrice,
133
160
  decimals: this.state.token.quantity.decimals
134
161
  });
135
162
  }
136
163
  },
137
164
 
138
165
  async sendNativeToken(params: TxParams) {
139
- RouterController.pushTransactionStack({
140
- view: 'Account',
141
- goBack: false
142
- });
143
-
144
166
  const to = params.receiverAddress as `0x${string}`;
145
- const address = AccountController.state.address as `0x${string}`;
146
- const value = ConnectionController.parseUnits(
167
+ const network = ConnectionsController.state.activeNetwork;
168
+ const address = CoreHelperUtil.getPlainAddress(
169
+ ConnectionsController.state.activeAddress
170
+ ) as `0x${string}`;
171
+ if (!address) {
172
+ throw new Error('Invalid address');
173
+ }
174
+
175
+ const value = ConnectionsController.parseUnits(
147
176
  params.sendTokenAmount.toString(),
148
177
  Number(params.decimals)
149
178
  );
150
179
  const data = '0x';
151
180
 
152
- try {
153
- await ConnectionController.sendTransaction({
154
- to,
155
- address,
156
- data,
157
- value,
158
- gasPrice: params.gasPrice
159
- });
160
- SnackController.showSuccess('Transaction started');
161
- EventsController.sendEvent({
162
- type: 'track',
163
- event: 'SEND_SUCCESS',
164
- properties: {
165
- isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount',
166
- token: this.state.token?.symbol || '',
167
- amount: params.sendTokenAmount,
168
- network: NetworkController.state.caipNetwork?.id || ''
169
- }
170
- });
171
- this.resetSend();
172
- } catch (error) {
173
- state.loading = false;
174
- EventsController.sendEvent({
175
- type: 'track',
176
- event: 'SEND_ERROR',
177
- properties: {
178
- isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount',
179
- token: this.state.token?.symbol || '',
180
- amount: params.sendTokenAmount,
181
- network: NetworkController.state.caipNetwork?.id || ''
182
- }
183
- });
184
- SnackController.showError('Something went wrong');
185
- }
181
+ await ConnectionsController.sendTransaction({
182
+ to,
183
+ address,
184
+ data,
185
+ value,
186
+ network
187
+ });
186
188
  },
187
189
 
188
190
  async sendERC20Token(params: ContractWriteParams) {
189
- RouterController.pushTransactionStack({
190
- view: 'Account',
191
- goBack: false
192
- });
193
-
194
- const amount = ConnectionController.parseUnits(
191
+ const network = ConnectionsController.state.activeNetwork;
192
+ const amount = ConnectionsController.parseUnits(
195
193
  params.sendTokenAmount.toString(),
196
194
  Number(params.decimals)
197
195
  );
198
196
 
199
- try {
200
- if (
201
- AccountController.state.address &&
202
- params.sendTokenAmount &&
203
- params.receiverAddress &&
204
- params.tokenAddress
205
- ) {
206
- const tokenAddress = CoreHelperUtil.getPlainAddress(
207
- params.tokenAddress as `${string}:${string}:${string}`
208
- ) as `0x${string}`;
209
- await ConnectionController.writeContract({
210
- fromAddress: AccountController.state.address as `0x${string}`,
211
- tokenAddress,
212
- receiverAddress: params.receiverAddress as `0x${string}`,
213
- tokenAmount: amount,
214
- method: 'transfer',
215
- abi: ContractUtil.getERC20Abi(tokenAddress)
216
- });
217
- SnackController.showSuccess('Transaction started');
218
- this.resetSend();
197
+ if (
198
+ ConnectionsController.state.activeAddress &&
199
+ params.sendTokenAmount &&
200
+ params.receiverAddress &&
201
+ params.tokenAddress
202
+ ) {
203
+ const tokenAddress = CoreHelperUtil.getPlainAddress(
204
+ params.tokenAddress as `${string}:${string}:${string}`
205
+ ) as `0x${string}`;
206
+
207
+ const fromAddress = CoreHelperUtil.getPlainAddress(
208
+ ConnectionsController.state.activeAddress
209
+ ) as `0x${string}`;
210
+ if (!fromAddress) {
211
+ throw new Error('Invalid address');
219
212
  }
220
- } catch (error) {
221
- state.loading = false;
222
- SnackController.showError('Something went wrong');
213
+
214
+ await ConnectionsController.writeContract({
215
+ fromAddress,
216
+ tokenAddress,
217
+ receiverAddress: params.receiverAddress as `0x${string}`,
218
+ tokenAmount: amount,
219
+ method: 'transfer',
220
+ abi: ContractUtil.getERC20Abi(tokenAddress),
221
+ network
222
+ });
223
+ }
224
+ },
225
+
226
+ async sendSolanaToken() {
227
+ if (!this.state.sendTokenAmount || !this.state.receiverAddress) {
228
+ throw new Error('An amount and receiver address are required');
229
+ }
230
+
231
+ const plainAddress = CoreHelperUtil.getPlainAddress(ConnectionsController.state.activeAddress);
232
+ if (!plainAddress) {
233
+ throw new Error('Invalid address');
223
234
  }
235
+
236
+ let tokenMint: string | undefined;
237
+
238
+ if (
239
+ SendController.state.token &&
240
+ SendController.state.token.address !== CoreConstantsUtil.NATIVE_TOKEN_ADDRESS.solana
241
+ ) {
242
+ if (CoreHelperUtil.isCaipAddress(SendController.state.token.address)) {
243
+ tokenMint = CoreHelperUtil.getPlainAddress(SendController.state.token.address);
244
+ } else {
245
+ tokenMint = SendController.state.token.address;
246
+ }
247
+ }
248
+
249
+ await ConnectionsController.sendTransaction({
250
+ tokenMint,
251
+ fromAddress: plainAddress,
252
+ toAddress: this.state.receiverAddress,
253
+ amount: this.state.sendTokenAmount,
254
+ network: ConnectionsController.state.activeNetwork
255
+ });
256
+ },
257
+
258
+ async fetchNetworkPrice() {
259
+ await SwapController.getNetworkTokenPrice();
224
260
  },
225
261
 
226
- resetSend() {
262
+ resetState() {
227
263
  state.token = undefined;
228
264
  state.sendTokenAmount = undefined;
229
265
  state.receiverAddress = undefined;
@@ -22,26 +22,52 @@ const state = proxy<SnackControllerState>({
22
22
  long: false
23
23
  });
24
24
 
25
+ // -- Private Variables --------------------------------- //
26
+ let hideTimeout: NodeJS.Timeout | null = null;
27
+
28
+ // -- Private Functions --------------------------------- //
29
+ const clearHideTimeout = () => {
30
+ if (hideTimeout) {
31
+ clearTimeout(hideTimeout);
32
+ hideTimeout = null;
33
+ }
34
+ };
35
+
36
+ const scheduleAutoHide = (long: boolean) => {
37
+ clearHideTimeout();
38
+
39
+ const duration = long ? 15000 : 2200;
40
+ hideTimeout = setTimeout(() => {
41
+ SnackController.hide();
42
+ }, duration);
43
+ };
44
+
25
45
  // -- Controller ---------------------------------------- //
26
46
  export const SnackController = {
27
47
  state,
28
48
 
29
- showSuccess(message: SnackControllerState['message']) {
49
+ showSuccess(message: SnackControllerState['message'], long = false) {
30
50
  state.message = message;
31
51
  state.variant = 'success';
32
52
  state.open = true;
53
+ state.long = long;
54
+ scheduleAutoHide(long);
33
55
  },
34
56
 
35
- showError(message: SnackControllerState['message']) {
57
+ showError(message: SnackControllerState['message'], long = false) {
36
58
  state.message = message;
37
59
  state.variant = 'error';
38
60
  state.open = true;
61
+ state.long = long;
62
+ scheduleAutoHide(long);
39
63
  },
40
64
 
41
- showLoading(message: SnackControllerState['message']) {
65
+ showLoading(message: SnackControllerState['message'], long = false) {
42
66
  state.message = message;
43
67
  state.variant = 'loading';
44
68
  state.open = true;
69
+ state.long = long;
70
+ scheduleAutoHide(long);
45
71
  },
46
72
 
47
73
  showInternalError(error: Message) {
@@ -52,6 +78,7 @@ export const SnackController = {
52
78
  state.variant = 'error';
53
79
  state.open = true;
54
80
  state.long = true;
81
+ scheduleAutoHide(true);
55
82
  }
56
83
 
57
84
  if (error.longMessage) {
@@ -61,9 +88,8 @@ export const SnackController = {
61
88
  },
62
89
 
63
90
  hide() {
91
+ clearHideTimeout();
64
92
  state.open = false;
65
93
  state.long = false;
66
- state.message = '';
67
- state.variant = 'success';
68
94
  }
69
95
  };