@reown/appkit-core-react-native 2.0.0 → 2.0.1

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 (282) hide show
  1. package/lib/commonjs/controllers/ApiController.js +148 -82
  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 +127 -134
  6. package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
  7. package/lib/commonjs/controllers/ConnectionsController.js +280 -60
  8. package/lib/commonjs/controllers/ConnectionsController.js.map +1 -1
  9. package/lib/commonjs/controllers/EnsController.js +6 -4
  10. package/lib/commonjs/controllers/EnsController.js.map +1 -1
  11. package/lib/commonjs/controllers/EventsController.js +55 -5
  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 +134 -53
  18. package/lib/commonjs/controllers/OnRampController.js.map +1 -1
  19. package/lib/commonjs/controllers/OptionsController.js +20 -7
  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 +115 -99
  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 +119 -119
  29. package/lib/commonjs/controllers/SwapController.js.map +1 -1
  30. package/lib/commonjs/controllers/ThemeController.js +5 -0
  31. package/lib/commonjs/controllers/ThemeController.js.map +1 -1
  32. package/lib/commonjs/controllers/TransactionsController.js +25 -19
  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 +30 -37
  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 -17
  48. package/lib/commonjs/utils/AssetUtil.js.map +1 -1
  49. package/lib/commonjs/utils/ConstantsUtil.js +14 -431
  50. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
  51. package/lib/commonjs/utils/CoreHelperUtil.js +33 -10
  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 +41 -12
  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 +119 -172
  59. package/lib/commonjs/utils/StorageUtil.js.map +1 -1
  60. package/lib/commonjs/utils/SwapApiUtil.js +2 -17
  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 +150 -82
  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 +128 -133
  70. package/lib/module/controllers/BlockchainApiController.js.map +1 -1
  71. package/lib/module/controllers/ConnectionsController.js +282 -60
  72. package/lib/module/controllers/ConnectionsController.js.map +1 -1
  73. package/lib/module/controllers/EnsController.js +6 -2
  74. package/lib/module/controllers/EnsController.js.map +1 -1
  75. package/lib/module/controllers/EventsController.js +54 -2
  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 +135 -52
  82. package/lib/module/controllers/OnRampController.js.map +1 -1
  83. package/lib/module/controllers/OptionsController.js +22 -7
  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 +114 -96
  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 +121 -119
  94. package/lib/module/controllers/SwapController.js.map +1 -1
  95. package/lib/module/controllers/ThemeController.js +7 -0
  96. package/lib/module/controllers/ThemeController.js.map +1 -1
  97. package/lib/module/controllers/TransactionsController.js +25 -17
  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 +12 -7
  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 -17
  112. package/lib/module/utils/AssetUtil.js.map +1 -1
  113. package/lib/module/utils/ConstantsUtil.js +16 -431
  114. package/lib/module/utils/ConstantsUtil.js.map +1 -1
  115. package/lib/module/utils/CoreHelperUtil.js +35 -8
  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 +44 -12
  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 +122 -172
  124. package/lib/module/utils/StorageUtil.js.map +1 -1
  125. package/lib/module/utils/SwapApiUtil.js +4 -17
  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 +8 -7
  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 +21 -13
  136. package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
  137. package/lib/typescript/controllers/ConnectionsController.d.ts +22 -18
  138. package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -1
  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 +1 -1
  146. package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
  147. package/lib/typescript/controllers/OnRampController.d.ts +4 -3
  148. package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
  149. package/lib/typescript/controllers/OptionsController.d.ts +8 -6
  150. package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
  151. package/lib/typescript/controllers/RouterController.d.ts +6 -21
  152. package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
  153. package/lib/typescript/controllers/SendController.d.ts +5 -7
  154. package/lib/typescript/controllers/SendController.d.ts.map +1 -1
  155. package/lib/typescript/controllers/SnackController.d.ts +3 -3
  156. package/lib/typescript/controllers/SnackController.d.ts.map +1 -1
  157. package/lib/typescript/controllers/SwapController.d.ts +11 -11
  158. package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
  159. package/lib/typescript/controllers/ThemeController.d.ts +2 -0
  160. package/lib/typescript/controllers/ThemeController.d.ts.map +1 -1
  161. package/lib/typescript/controllers/TransactionsController.d.ts +3 -3
  162. package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -1
  163. package/lib/typescript/controllers/WcController.d.ts +27 -0
  164. package/lib/typescript/controllers/WcController.d.ts.map +1 -0
  165. package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts +174 -0
  166. package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts.map +1 -0
  167. package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts +16 -0
  168. package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts.map +1 -0
  169. package/lib/typescript/features/reown-authentication/index.d.ts +3 -0
  170. package/lib/typescript/features/reown-authentication/index.d.ts.map +1 -0
  171. package/lib/typescript/index.d.ts +6 -8
  172. package/lib/typescript/index.d.ts.map +1 -1
  173. package/lib/typescript/utils/ApiUtil.d.ts +1 -1
  174. package/lib/typescript/utils/AssetUtil.d.ts +3 -4
  175. package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
  176. package/lib/typescript/utils/ConstantsUtil.d.ts +7 -416
  177. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
  178. package/lib/typescript/utils/CoreHelperUtil.d.ts +8 -6
  179. package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
  180. package/lib/typescript/utils/EventUtil.d.ts +1 -1
  181. package/lib/typescript/utils/EventUtil.d.ts.map +1 -1
  182. package/lib/typescript/utils/FetchUtil.d.ts +3 -3
  183. package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
  184. package/lib/typescript/utils/LogUtils.d.ts +15 -0
  185. package/lib/typescript/utils/LogUtils.d.ts.map +1 -0
  186. package/lib/typescript/utils/StorageUtil.d.ts +8 -19
  187. package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
  188. package/lib/typescript/utils/SwapApiUtil.d.ts +3 -4
  189. package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
  190. package/lib/typescript/utils/SwapCalculationUtil.d.ts +1 -1
  191. package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +1 -1
  192. package/lib/typescript/utils/WalletUtil.d.ts +5 -0
  193. package/lib/typescript/utils/WalletUtil.d.ts.map +1 -0
  194. package/package.json +12 -25
  195. package/src/controllers/ApiController.ts +158 -80
  196. package/src/controllers/AssetController.ts +0 -6
  197. package/src/controllers/BlockchainApiController.ts +109 -144
  198. package/src/controllers/ConnectionsController.ts +372 -88
  199. package/src/controllers/EnsController.ts +5 -3
  200. package/src/controllers/EventsController.ts +74 -3
  201. package/src/controllers/LogController.ts +250 -0
  202. package/src/controllers/ModalController.ts +11 -9
  203. package/src/controllers/OnRampController.ts +195 -82
  204. package/src/controllers/OptionsController.ts +40 -13
  205. package/src/controllers/RouterController.ts +20 -58
  206. package/src/controllers/SendController.ts +148 -112
  207. package/src/controllers/SnackController.ts +31 -5
  208. package/src/controllers/SwapController.ts +140 -148
  209. package/src/controllers/ThemeController.ts +7 -0
  210. package/src/controllers/TransactionsController.ts +26 -18
  211. package/src/controllers/WcController.ts +93 -0
  212. package/src/features/reown-authentication/ReownAuthentication.ts +475 -0
  213. package/src/features/reown-authentication/ReownAuthenticationMessenger.ts +80 -0
  214. package/src/features/reown-authentication/index.ts +2 -0
  215. package/src/index.ts +15 -22
  216. package/src/utils/ApiUtil.ts +1 -1
  217. package/src/utils/AssetUtil.ts +9 -20
  218. package/src/utils/ConstantsUtil.ts +16 -435
  219. package/src/utils/CoreHelperUtil.ts +62 -11
  220. package/src/utils/EventUtil.ts +1 -1
  221. package/src/utils/FetchUtil.ts +50 -14
  222. package/src/utils/LogUtils.ts +179 -0
  223. package/src/utils/StorageUtil.ts +171 -199
  224. package/src/utils/SwapApiUtil.ts +18 -37
  225. package/src/utils/SwapCalculationUtil.ts +1 -2
  226. package/src/utils/WalletUtil.ts +14 -0
  227. package/lib/commonjs/controllers/AccountController.js +0 -93
  228. package/lib/commonjs/controllers/AccountController.js.map +0 -1
  229. package/lib/commonjs/controllers/ConnectionController.js +0 -132
  230. package/lib/commonjs/controllers/ConnectionController.js.map +0 -1
  231. package/lib/commonjs/controllers/ConnectorController.js +0 -50
  232. package/lib/commonjs/controllers/ConnectorController.js.map +0 -1
  233. package/lib/commonjs/controllers/NetworkController.js +0 -90
  234. package/lib/commonjs/controllers/NetworkController.js.map +0 -1
  235. package/lib/commonjs/controllers/WebviewController.js +0 -52
  236. package/lib/commonjs/controllers/WebviewController.js.map +0 -1
  237. package/lib/commonjs/utils/NetworkUtil.js +0 -46
  238. package/lib/commonjs/utils/NetworkUtil.js.map +0 -1
  239. package/lib/commonjs/utils/RouterUtil.js +0 -25
  240. package/lib/commonjs/utils/RouterUtil.js.map +0 -1
  241. package/lib/commonjs/utils/TypeUtil.js +0 -6
  242. package/lib/commonjs/utils/TypeUtil.js.map +0 -1
  243. package/lib/module/controllers/AccountController.js +0 -88
  244. package/lib/module/controllers/AccountController.js.map +0 -1
  245. package/lib/module/controllers/ConnectionController.js +0 -127
  246. package/lib/module/controllers/ConnectionController.js.map +0 -1
  247. package/lib/module/controllers/ConnectorController.js +0 -45
  248. package/lib/module/controllers/ConnectorController.js.map +0 -1
  249. package/lib/module/controllers/NetworkController.js +0 -85
  250. package/lib/module/controllers/NetworkController.js.map +0 -1
  251. package/lib/module/controllers/WebviewController.js +0 -47
  252. package/lib/module/controllers/WebviewController.js.map +0 -1
  253. package/lib/module/utils/NetworkUtil.js +0 -40
  254. package/lib/module/utils/NetworkUtil.js.map +0 -1
  255. package/lib/module/utils/RouterUtil.js +0 -19
  256. package/lib/module/utils/RouterUtil.js.map +0 -1
  257. package/lib/module/utils/TypeUtil.js +0 -2
  258. package/lib/module/utils/TypeUtil.js.map +0 -1
  259. package/lib/typescript/controllers/AccountController.d.ts +0 -33
  260. package/lib/typescript/controllers/AccountController.d.ts.map +0 -1
  261. package/lib/typescript/controllers/ConnectionController.d.ts +0 -68
  262. package/lib/typescript/controllers/ConnectionController.d.ts.map +0 -1
  263. package/lib/typescript/controllers/ConnectorController.d.ts +0 -18
  264. package/lib/typescript/controllers/ConnectorController.d.ts.map +0 -1
  265. package/lib/typescript/controllers/NetworkController.d.ts +0 -34
  266. package/lib/typescript/controllers/NetworkController.d.ts.map +0 -1
  267. package/lib/typescript/controllers/WebviewController.d.ts +0 -21
  268. package/lib/typescript/controllers/WebviewController.d.ts.map +0 -1
  269. package/lib/typescript/utils/NetworkUtil.d.ts +0 -8
  270. package/lib/typescript/utils/NetworkUtil.d.ts.map +0 -1
  271. package/lib/typescript/utils/RouterUtil.d.ts +0 -5
  272. package/lib/typescript/utils/RouterUtil.d.ts.map +0 -1
  273. package/lib/typescript/utils/TypeUtil.d.ts +0 -817
  274. package/lib/typescript/utils/TypeUtil.d.ts.map +0 -1
  275. package/src/controllers/AccountController.ts +0 -128
  276. package/src/controllers/ConnectionController.ts +0 -208
  277. package/src/controllers/ConnectorController.ts +0 -64
  278. package/src/controllers/NetworkController.ts +0 -120
  279. package/src/controllers/WebviewController.ts +0 -63
  280. package/src/utils/NetworkUtil.ts +0 -33
  281. package/src/utils/RouterUtil.ts +0 -21
  282. package/src/utils/TypeUtil.ts +0 -995
@@ -1,23 +1,12 @@
1
1
  import { proxy } from 'valtio';
2
- import type { CaipNetwork } from '@reown/appkit-common-react-native';
3
-
4
2
  import type {
3
+ AppKitNetwork,
4
+ SocialProvider,
5
5
  WcWallet,
6
- Connector,
7
- SwapInputTarget,
8
6
  OnRampTransactionResult
9
- } from '../utils/TypeUtil';
7
+ } from '@reown/appkit-common-react-native';
10
8
 
11
9
  // -- Types --------------------------------------------- //
12
- type TransactionAction = {
13
- goBack: boolean;
14
- view: RouterControllerState['view'] | null;
15
- close?: boolean;
16
- replace?: boolean;
17
- onSuccess?: () => void;
18
- onCancel?: () => void;
19
- };
20
-
21
10
  export interface RouterControllerState {
22
11
  view:
23
12
  | 'Account'
@@ -26,13 +15,7 @@ export interface RouterControllerState {
26
15
  | 'Connect'
27
16
  | 'ConnectSocials'
28
17
  | 'ConnectingExternal'
29
- | 'ConnectingSiwe'
30
18
  | 'ConnectingSocial'
31
- | 'ConnectingFarcaster'
32
- | 'ConnectingWalletConnect'
33
- | 'Create'
34
- | 'EmailVerifyDevice'
35
- | 'EmailVerifyOtp'
36
19
  | 'GetWallet'
37
20
  | 'Networks'
38
21
  | 'OnRamp'
@@ -40,18 +23,15 @@ export interface RouterControllerState {
40
23
  | 'OnRampLoading'
41
24
  | 'OnRampSettings'
42
25
  | 'OnRampTransaction'
43
- | 'SwitchNetwork'
26
+ | 'SIWXSignMessage'
44
27
  | 'Swap'
45
- | 'SwapSelectToken'
46
28
  | 'SwapPreview'
29
+ | 'SwitchNetwork'
47
30
  | 'Transactions'
48
31
  | 'UnsupportedChain'
49
- | 'UpdateEmailPrimaryOtp'
50
- | 'UpdateEmailSecondaryOtp'
51
- | 'UpdateEmailWallet'
52
32
  | 'UpgradeEmailWallet'
53
- | 'UpgradeToSmartAccount'
54
33
  | 'WalletCompatibleNetworks'
34
+ | 'WalletConnect'
55
35
  | 'WalletReceive'
56
36
  | 'WalletSend'
57
37
  | 'WalletSendPreview'
@@ -59,62 +39,41 @@ export interface RouterControllerState {
59
39
  | 'WhatIsANetwork'
60
40
  | 'WhatIsAWallet';
61
41
  history: RouterControllerState['view'][];
42
+ navigationDirection: 'forward' | 'backward' | 'none';
62
43
  data?: {
63
- connector?: Connector;
64
44
  wallet?: WcWallet;
65
- network?: CaipNetwork;
66
- email?: string;
67
- newEmail?: string;
68
- swapTarget?: SwapInputTarget;
45
+ network?: AppKitNetwork;
69
46
  onrampResult?: OnRampTransactionResult;
47
+ socialProvider?: SocialProvider;
70
48
  };
71
- transactionStack: TransactionAction[];
72
49
  }
73
50
 
74
51
  // -- State --------------------------------------------- //
75
52
  const state = proxy<RouterControllerState>({
76
53
  view: 'Connect',
77
54
  history: ['Connect'],
78
- transactionStack: []
55
+ navigationDirection: 'none'
79
56
  });
80
57
 
81
58
  // -- Controller ---------------------------------------- //
82
59
  export const RouterController = {
83
60
  state,
84
61
 
85
- push(view: RouterControllerState['view'], data?: RouterControllerState['data']) {
62
+ push(
63
+ view: RouterControllerState['view'],
64
+ data?: RouterControllerState['data'],
65
+ direction: 'forward' | 'backward' = 'forward'
66
+ ) {
86
67
  if (view !== state.view) {
68
+ state.navigationDirection = direction;
87
69
  state.view = view;
88
70
  state.history = [...state.history, view];
89
71
  state.data = data;
90
72
  }
91
73
  },
92
74
 
93
- pushTransactionStack(action: TransactionAction) {
94
- state.transactionStack = [...state.transactionStack, action];
95
- },
96
-
97
- popTransactionStack(cancel?: boolean) {
98
- const action = state.transactionStack.pop();
99
-
100
- if (!action) {
101
- return;
102
- }
103
-
104
- if (cancel) {
105
- this.goBack();
106
- action?.onCancel?.();
107
- } else {
108
- if (action.goBack) {
109
- this.goBack();
110
- } else if (action.view) {
111
- this.reset(action.view);
112
- }
113
- action?.onSuccess?.();
114
- }
115
- },
116
-
117
75
  reset(view: RouterControllerState['view'], data?: RouterControllerState['data']) {
76
+ state.navigationDirection = 'none';
118
77
  state.view = view;
119
78
  state.history = [view];
120
79
  state.data = data;
@@ -122,6 +81,7 @@ export const RouterController = {
122
81
 
123
82
  replace(view: RouterControllerState['view'], data?: RouterControllerState['data']) {
124
83
  if (state.history.length >= 1 && state.history.at(-1) !== view) {
84
+ state.navigationDirection = 'none';
125
85
  state.view = view;
126
86
  state.history[state.history.length - 1] = view;
127
87
  state.data = data;
@@ -133,6 +93,7 @@ export const RouterController = {
133
93
  state.history.pop();
134
94
  const [last] = state.history.slice(-1);
135
95
  if (last) {
96
+ state.navigationDirection = 'backward';
136
97
  state.view = last;
137
98
  }
138
99
  }
@@ -143,6 +104,7 @@ export const RouterController = {
143
104
  state.history = state.history.slice(0, historyIndex + 1);
144
105
  const [last] = state.history.slice(-1);
145
106
  if (last) {
107
+ state.navigationDirection = 'backward';
146
108
  state.view = last;
147
109
  }
148
110
  }
@@ -1,19 +1,20 @@
1
- import { subscribeKey as subKey } from 'valtio/vanilla/utils';
2
- import { proxy, ref, subscribe as sub } from 'valtio/vanilla';
1
+ import { subscribeKey as subKey } from 'valtio/utils';
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
8
  import { RouterController } from './RouterController';
10
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: ConnectionsController.state.activeNetwork?.caipNetworkId || ''
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: ConnectionsController.state.activeNetwork?.caipNetworkId || ''
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: ConnectionsController.state.activeNetwork?.caipNetworkId || ''
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: ConnectionsController.state.activeNetwork?.caipNetworkId || ''
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
  };