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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/lib/commonjs/controllers/ApiController.js +410 -0
  2. package/lib/commonjs/controllers/ApiController.js.map +1 -0
  3. package/lib/commonjs/controllers/AssetController.js +30 -0
  4. package/lib/commonjs/controllers/AssetController.js.map +1 -0
  5. package/lib/commonjs/controllers/BlockchainApiController.js +384 -0
  6. package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -0
  7. package/lib/commonjs/controllers/ConnectionsController.js +425 -0
  8. package/lib/commonjs/controllers/ConnectionsController.js.map +1 -0
  9. package/lib/commonjs/controllers/EnsController.js +37 -0
  10. package/lib/commonjs/controllers/EnsController.js.map +1 -0
  11. package/lib/commonjs/controllers/EventsController.js +122 -0
  12. package/lib/commonjs/controllers/EventsController.js.map +1 -0
  13. package/lib/commonjs/controllers/LogController.js +188 -0
  14. package/lib/commonjs/controllers/LogController.js.map +1 -0
  15. package/lib/commonjs/controllers/ModalController.js +68 -0
  16. package/lib/commonjs/controllers/ModalController.js.map +1 -0
  17. package/lib/commonjs/controllers/OnRampController.js +502 -0
  18. package/lib/commonjs/controllers/OnRampController.js.map +1 -0
  19. package/lib/commonjs/controllers/OptionsController.js +96 -0
  20. package/lib/commonjs/controllers/OptionsController.js.map +1 -0
  21. package/lib/commonjs/controllers/PublicStateController.js +33 -0
  22. package/lib/commonjs/controllers/PublicStateController.js.map +1 -0
  23. package/lib/commonjs/controllers/RouterController.js +63 -0
  24. package/lib/commonjs/controllers/RouterController.js.map +1 -0
  25. package/lib/commonjs/controllers/SendController.js +192 -0
  26. package/lib/commonjs/controllers/SendController.js.map +1 -0
  27. package/lib/commonjs/controllers/SnackController.js +83 -0
  28. package/lib/commonjs/controllers/SnackController.js.map +1 -0
  29. package/lib/commonjs/controllers/SwapController.js +674 -0
  30. package/lib/commonjs/controllers/SwapController.js.map +1 -0
  31. package/lib/commonjs/controllers/ThemeController.js +45 -0
  32. package/lib/commonjs/controllers/ThemeController.js.map +1 -0
  33. package/lib/commonjs/controllers/TransactionsController.js +118 -0
  34. package/lib/commonjs/controllers/TransactionsController.js.map +1 -0
  35. package/lib/commonjs/controllers/WcController.js +73 -0
  36. package/lib/commonjs/controllers/WcController.js.map +1 -0
  37. package/lib/commonjs/features/reown-authentication/ReownAuthentication.js +272 -0
  38. package/lib/commonjs/features/reown-authentication/ReownAuthentication.js.map +1 -0
  39. package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js +48 -0
  40. package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
  41. package/lib/commonjs/features/reown-authentication/index.js +28 -0
  42. package/lib/commonjs/features/reown-authentication/index.js.map +1 -0
  43. package/lib/commonjs/index.js +202 -0
  44. package/lib/commonjs/index.js.map +1 -0
  45. package/lib/commonjs/package.json +1 -0
  46. package/lib/commonjs/utils/ApiUtil.js +43 -0
  47. package/lib/commonjs/utils/ApiUtil.js.map +1 -0
  48. package/lib/commonjs/utils/AssetUtil.js +27 -0
  49. package/lib/commonjs/utils/AssetUtil.js.map +1 -0
  50. package/lib/commonjs/utils/ConstantsUtil.js +226 -0
  51. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -0
  52. package/lib/commonjs/utils/CoreHelperUtil.js +298 -0
  53. package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -0
  54. package/lib/commonjs/utils/EventUtil.js +25 -0
  55. package/lib/commonjs/utils/EventUtil.js.map +1 -0
  56. package/lib/commonjs/utils/FetchUtil.js +158 -0
  57. package/lib/commonjs/utils/FetchUtil.js.map +1 -0
  58. package/lib/commonjs/utils/LogUtils.js +131 -0
  59. package/lib/commonjs/utils/LogUtils.js.map +1 -0
  60. package/lib/commonjs/utils/StorageUtil.js +319 -0
  61. package/lib/commonjs/utils/StorageUtil.js.map +1 -0
  62. package/lib/commonjs/utils/SwapApiUtil.js +75 -0
  63. package/lib/commonjs/utils/SwapApiUtil.js.map +1 -0
  64. package/lib/commonjs/utils/SwapCalculationUtil.js +97 -0
  65. package/lib/commonjs/utils/SwapCalculationUtil.js.map +1 -0
  66. package/lib/commonjs/utils/WalletUtil.js +23 -0
  67. package/lib/commonjs/utils/WalletUtil.js.map +1 -0
  68. package/lib/module/controllers/ApiController.js +407 -0
  69. package/lib/module/controllers/ApiController.js.map +1 -0
  70. package/lib/module/controllers/AssetController.js +27 -0
  71. package/lib/module/controllers/AssetController.js.map +1 -0
  72. package/lib/module/controllers/BlockchainApiController.js +381 -0
  73. package/lib/module/controllers/BlockchainApiController.js.map +1 -0
  74. package/lib/module/controllers/ConnectionsController.js +422 -0
  75. package/lib/module/controllers/ConnectionsController.js.map +1 -0
  76. package/lib/module/controllers/EnsController.js +34 -0
  77. package/lib/module/controllers/EnsController.js.map +1 -0
  78. package/lib/module/controllers/EventsController.js +118 -0
  79. package/lib/module/controllers/EventsController.js.map +1 -0
  80. package/lib/module/controllers/LogController.js +185 -0
  81. package/lib/module/controllers/LogController.js.map +1 -0
  82. package/lib/module/controllers/ModalController.js +65 -0
  83. package/lib/module/controllers/ModalController.js.map +1 -0
  84. package/lib/module/controllers/OnRampController.js +499 -0
  85. package/lib/module/controllers/OnRampController.js.map +1 -0
  86. package/lib/module/controllers/OptionsController.js +93 -0
  87. package/lib/module/controllers/OptionsController.js.map +1 -0
  88. package/lib/module/controllers/PublicStateController.js +30 -0
  89. package/lib/module/controllers/PublicStateController.js.map +1 -0
  90. package/lib/module/controllers/RouterController.js +60 -0
  91. package/lib/module/controllers/RouterController.js.map +1 -0
  92. package/lib/module/controllers/SendController.js +189 -0
  93. package/lib/module/controllers/SendController.js.map +1 -0
  94. package/lib/module/controllers/SnackController.js +80 -0
  95. package/lib/module/controllers/SnackController.js.map +1 -0
  96. package/lib/module/controllers/SwapController.js +671 -0
  97. package/lib/module/controllers/SwapController.js.map +1 -0
  98. package/lib/module/controllers/ThemeController.js +42 -0
  99. package/lib/module/controllers/ThemeController.js.map +1 -0
  100. package/lib/module/controllers/TransactionsController.js +115 -0
  101. package/lib/module/controllers/TransactionsController.js.map +1 -0
  102. package/lib/module/controllers/WcController.js +70 -0
  103. package/lib/module/controllers/WcController.js.map +1 -0
  104. package/lib/module/features/reown-authentication/ReownAuthentication.js +268 -0
  105. package/lib/module/features/reown-authentication/ReownAuthentication.js.map +1 -0
  106. package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js +43 -0
  107. package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
  108. package/lib/module/features/reown-authentication/index.js +5 -0
  109. package/lib/module/features/reown-authentication/index.js.map +1 -0
  110. package/lib/module/index.js +38 -0
  111. package/lib/module/index.js.map +1 -0
  112. package/lib/module/utils/ApiUtil.js +39 -0
  113. package/lib/module/utils/ApiUtil.js.map +1 -0
  114. package/lib/module/utils/AssetUtil.js +23 -0
  115. package/lib/module/utils/AssetUtil.js.map +1 -0
  116. package/lib/module/utils/ConstantsUtil.js +222 -0
  117. package/lib/module/utils/ConstantsUtil.js.map +1 -0
  118. package/lib/module/utils/CoreHelperUtil.js +294 -0
  119. package/lib/module/utils/CoreHelperUtil.js.map +1 -0
  120. package/lib/module/utils/EventUtil.js +21 -0
  121. package/lib/module/utils/EventUtil.js.map +1 -0
  122. package/lib/module/utils/FetchUtil.js +154 -0
  123. package/lib/module/utils/FetchUtil.js.map +1 -0
  124. package/lib/module/utils/LogUtils.js +121 -0
  125. package/lib/module/utils/LogUtils.js.map +1 -0
  126. package/lib/module/utils/StorageUtil.js +315 -0
  127. package/lib/module/utils/StorageUtil.js.map +1 -0
  128. package/lib/module/utils/SwapApiUtil.js +71 -0
  129. package/lib/module/utils/SwapApiUtil.js.map +1 -0
  130. package/lib/module/utils/SwapCalculationUtil.js +94 -0
  131. package/lib/module/utils/SwapCalculationUtil.js.map +1 -0
  132. package/lib/module/utils/WalletUtil.js +19 -0
  133. package/lib/module/utils/WalletUtil.js.map +1 -0
  134. package/lib/typescript/controllers/ApiController.d.ts +40 -0
  135. package/lib/typescript/controllers/ApiController.d.ts.map +1 -0
  136. package/lib/typescript/controllers/AssetController.d.ts +12 -0
  137. package/lib/typescript/controllers/AssetController.d.ts.map +1 -0
  138. package/lib/typescript/controllers/BlockchainApiController.d.ts +55 -0
  139. package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -0
  140. package/lib/typescript/controllers/ConnectionsController.d.ts +47 -0
  141. package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -0
  142. package/lib/typescript/controllers/EnsController.d.ts +10 -0
  143. package/lib/typescript/controllers/EnsController.d.ts.map +1 -0
  144. package/lib/typescript/controllers/EventsController.d.ts +25 -0
  145. package/lib/typescript/controllers/EventsController.d.ts.map +1 -0
  146. package/lib/typescript/controllers/LogController.d.ts +65 -0
  147. package/lib/typescript/controllers/LogController.d.ts.map +1 -0
  148. package/lib/typescript/controllers/ModalController.d.ts +17 -0
  149. package/lib/typescript/controllers/ModalController.d.ts.map +1 -0
  150. package/lib/typescript/controllers/OnRampController.d.ts +55 -0
  151. package/lib/typescript/controllers/OnRampController.d.ts.map +1 -0
  152. package/lib/typescript/controllers/OptionsController.d.ts +46 -0
  153. package/lib/typescript/controllers/OptionsController.d.ts.map +1 -0
  154. package/lib/typescript/controllers/PublicStateController.d.ts +12 -0
  155. package/lib/typescript/controllers/PublicStateController.d.ts.map +1 -0
  156. package/lib/typescript/controllers/RouterController.d.ts +21 -0
  157. package/lib/typescript/controllers/RouterController.d.ts.map +1 -0
  158. package/lib/typescript/controllers/SendController.d.ts +39 -0
  159. package/lib/typescript/controllers/SendController.d.ts.map +1 -0
  160. package/lib/typescript/controllers/SnackController.d.ts +20 -0
  161. package/lib/typescript/controllers/SnackController.d.ts.map +1 -0
  162. package/lib/typescript/controllers/SwapController.d.ts +116 -0
  163. package/lib/typescript/controllers/SwapController.d.ts.map +1 -0
  164. package/lib/typescript/controllers/ThemeController.d.ts +14 -0
  165. package/lib/typescript/controllers/ThemeController.d.ts.map +1 -0
  166. package/lib/typescript/controllers/TransactionsController.d.ts +21 -0
  167. package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -0
  168. package/lib/typescript/controllers/WcController.d.ts +27 -0
  169. package/lib/typescript/controllers/WcController.d.ts.map +1 -0
  170. package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts +174 -0
  171. package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts.map +1 -0
  172. package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts +16 -0
  173. package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts.map +1 -0
  174. package/lib/typescript/features/reown-authentication/index.d.ts +3 -0
  175. package/lib/typescript/features/reown-authentication/index.d.ts.map +1 -0
  176. package/lib/typescript/index.d.ts +29 -0
  177. package/lib/typescript/index.d.ts.map +1 -0
  178. package/lib/typescript/utils/ApiUtil.d.ts +7 -0
  179. package/lib/typescript/utils/ApiUtil.d.ts.map +1 -0
  180. package/lib/typescript/utils/AssetUtil.d.ts +6 -0
  181. package/lib/typescript/utils/AssetUtil.d.ts.map +1 -0
  182. package/lib/typescript/utils/ConstantsUtil.d.ts +79 -0
  183. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -0
  184. package/lib/typescript/utils/CoreHelperUtil.d.ts +43 -0
  185. package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -0
  186. package/lib/typescript/utils/EventUtil.d.ts +5 -0
  187. package/lib/typescript/utils/EventUtil.d.ts.map +1 -0
  188. package/lib/typescript/utils/FetchUtil.d.ts +29 -0
  189. package/lib/typescript/utils/FetchUtil.d.ts.map +1 -0
  190. package/lib/typescript/utils/LogUtils.d.ts +15 -0
  191. package/lib/typescript/utils/LogUtils.d.ts.map +1 -0
  192. package/lib/typescript/utils/StorageUtil.d.ts +36 -0
  193. package/lib/typescript/utils/StorageUtil.d.ts.map +1 -0
  194. package/lib/typescript/utils/SwapApiUtil.d.ts +11 -0
  195. package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -0
  196. package/lib/typescript/utils/SwapCalculationUtil.d.ts +24 -0
  197. package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +1 -0
  198. package/lib/typescript/utils/WalletUtil.d.ts +5 -0
  199. package/lib/typescript/utils/WalletUtil.d.ts.map +1 -0
  200. package/package.json +57 -0
  201. package/readme.md +9 -0
  202. package/src/controllers/ApiController.ts +454 -0
  203. package/src/controllers/AssetController.ts +32 -0
  204. package/src/controllers/BlockchainApiController.ts +418 -0
  205. package/src/controllers/ConnectionsController.ts +575 -0
  206. package/src/controllers/EnsController.ts +41 -0
  207. package/src/controllers/EventsController.ts +146 -0
  208. package/src/controllers/LogController.ts +250 -0
  209. package/src/controllers/ModalController.ts +68 -0
  210. package/src/controllers/OnRampController.ts +698 -0
  211. package/src/controllers/OptionsController.ts +143 -0
  212. package/src/controllers/PublicStateController.ts +37 -0
  213. package/src/controllers/RouterController.ts +112 -0
  214. package/src/controllers/SendController.ts +270 -0
  215. package/src/controllers/SnackController.ts +95 -0
  216. package/src/controllers/SwapController.ts +863 -0
  217. package/src/controllers/ThemeController.ts +47 -0
  218. package/src/controllers/TransactionsController.ts +150 -0
  219. package/src/controllers/WcController.ts +93 -0
  220. package/src/features/reown-authentication/ReownAuthentication.ts +475 -0
  221. package/src/features/reown-authentication/ReownAuthenticationMessenger.ts +80 -0
  222. package/src/features/reown-authentication/index.ts +2 -0
  223. package/src/index.ts +70 -0
  224. package/src/utils/ApiUtil.ts +50 -0
  225. package/src/utils/AssetUtil.ts +27 -0
  226. package/src/utils/ConstantsUtil.ts +303 -0
  227. package/src/utils/CoreHelperUtil.ts +377 -0
  228. package/src/utils/EventUtil.ts +22 -0
  229. package/src/utils/FetchUtil.ts +164 -0
  230. package/src/utils/LogUtils.ts +179 -0
  231. package/src/utils/StorageUtil.ts +405 -0
  232. package/src/utils/SwapApiUtil.ts +101 -0
  233. package/src/utils/SwapCalculationUtil.ts +145 -0
  234. package/src/utils/WalletUtil.ts +14 -0
@@ -0,0 +1,143 @@
1
+ import { proxy, ref } from 'valtio';
2
+ import type {
3
+ Storage,
4
+ Metadata,
5
+ AppKitNetwork,
6
+ CustomWallet,
7
+ Features,
8
+ ProjectId,
9
+ SdkType,
10
+ SdkVersion,
11
+ SIWXConfig
12
+ } from '@reown/appkit-common-react-native';
13
+
14
+ import { ConstantsUtil } from '../utils/ConstantsUtil';
15
+
16
+ // -- Types --------------------------------------------- //
17
+ export interface ClipboardClient {
18
+ setString: (value: string) => Promise<void>;
19
+ }
20
+
21
+ export interface OptionsControllerState {
22
+ projectId: ProjectId;
23
+ clipboardClient?: ClipboardClient;
24
+ storage?: Storage;
25
+ includeWalletIds?: string[];
26
+ excludeWalletIds?: string[];
27
+ featuredWalletIds?: string[];
28
+ customWallets?: CustomWallet[];
29
+ enableAnalytics?: boolean;
30
+ sdkType: SdkType;
31
+ sdkVersion: SdkVersion;
32
+ metadata?: Metadata;
33
+ siwx?: SIWXConfig;
34
+ isOnRampEnabled?: boolean;
35
+ features?: Features;
36
+ debug?: boolean;
37
+ defaultNetwork?: AppKitNetwork;
38
+ requestedNetworks?: AppKitNetwork[];
39
+ }
40
+
41
+ // -- State --------------------------------------------- //
42
+ const state = proxy<OptionsControllerState>({
43
+ projectId: '',
44
+ sdkType: 'appkit',
45
+ sdkVersion: 'react-native-undefined-undefined',
46
+ features: ConstantsUtil.DEFAULT_FEATURES,
47
+ customWallets: [],
48
+ debug: false
49
+ });
50
+
51
+ // -- Controller ---------------------------------------- //
52
+ export const OptionsController = {
53
+ state,
54
+
55
+ setClipboardClient(client: ClipboardClient) {
56
+ state.clipboardClient = ref(client);
57
+ },
58
+
59
+ setProjectId(projectId: OptionsControllerState['projectId']) {
60
+ state.projectId = projectId;
61
+ },
62
+
63
+ setIncludeWalletIds(includeWalletIds: OptionsControllerState['includeWalletIds']) {
64
+ state.includeWalletIds = includeWalletIds;
65
+ },
66
+
67
+ setExcludeWalletIds(excludeWalletIds: OptionsControllerState['excludeWalletIds']) {
68
+ state.excludeWalletIds = excludeWalletIds;
69
+ },
70
+
71
+ setFeaturedWalletIds(featuredWalletIds: OptionsControllerState['featuredWalletIds']) {
72
+ state.featuredWalletIds = featuredWalletIds;
73
+ },
74
+
75
+ setCustomWallets(customWallets: OptionsControllerState['customWallets']) {
76
+ state.customWallets = customWallets;
77
+ },
78
+
79
+ setEnableAnalytics(enableAnalytics: OptionsControllerState['enableAnalytics']) {
80
+ state.enableAnalytics = enableAnalytics;
81
+ },
82
+
83
+ setSdkVersion(sdkVersion: OptionsControllerState['sdkVersion']) {
84
+ state.sdkVersion = sdkVersion;
85
+ },
86
+
87
+ setMetadata(metadata: OptionsControllerState['metadata']) {
88
+ state.metadata = metadata;
89
+ },
90
+
91
+ setFeatures(features: OptionsControllerState['features']) {
92
+ state.features = { ...ConstantsUtil.DEFAULT_FEATURES, ...features };
93
+ },
94
+
95
+ setDebug(debug: OptionsControllerState['debug']) {
96
+ state.debug = debug;
97
+ },
98
+
99
+ setIsOnRampEnabled(isOnRampEnabled: OptionsControllerState['isOnRampEnabled']) {
100
+ state.isOnRampEnabled = isOnRampEnabled;
101
+ },
102
+
103
+ setStorage(storage?: OptionsControllerState['storage']) {
104
+ if (storage) {
105
+ state.storage = ref(storage);
106
+ }
107
+ },
108
+
109
+ setDefaultNetwork(defaultNetwork?: OptionsControllerState['defaultNetwork']) {
110
+ state.defaultNetwork = defaultNetwork;
111
+ },
112
+
113
+ setRequestedNetworks(requestedNetworks?: OptionsControllerState['requestedNetworks']) {
114
+ state.requestedNetworks = requestedNetworks;
115
+ },
116
+
117
+ setSiwx(siwx?: OptionsControllerState['siwx']) {
118
+ if (siwx && (siwx?.signOutOnDisconnect === undefined || siwx?.signOutOnDisconnect === null)) {
119
+ siwx.signOutOnDisconnect = true;
120
+ }
121
+
122
+ state.siwx = siwx;
123
+ },
124
+
125
+ isClipboardAvailable() {
126
+ return !!state.clipboardClient;
127
+ },
128
+
129
+ getStorage() {
130
+ if (!state.storage) {
131
+ throw new Error('AppKit: Storage is not set');
132
+ }
133
+
134
+ return state.storage;
135
+ },
136
+
137
+ copyToClipboard(value: string) {
138
+ const client = state.clipboardClient;
139
+ if (client) {
140
+ client?.setString(value);
141
+ }
142
+ }
143
+ };
@@ -0,0 +1,37 @@
1
+ import { proxy, subscribe as sub } from 'valtio';
2
+ import { subscribeKey as subKey } from 'valtio/utils';
3
+ import type { CaipNetworkId } from '@reown/appkit-common-react-native';
4
+
5
+ // -- Types --------------------------------------------- //
6
+ export interface PublicStateControllerState {
7
+ open: boolean;
8
+ selectedNetworkId?: CaipNetworkId;
9
+ }
10
+
11
+ type StateKey = keyof PublicStateControllerState;
12
+
13
+ // -- State --------------------------------------------- //
14
+ const state = proxy<PublicStateControllerState>({
15
+ open: false,
16
+ selectedNetworkId: undefined
17
+ });
18
+
19
+ // -- Controller ---------------------------------------- //
20
+ export const PublicStateController = {
21
+ state,
22
+
23
+ subscribe(callback: (newState: PublicStateControllerState) => void) {
24
+ return sub(state, () => callback(state));
25
+ },
26
+
27
+ subscribeKey<K extends StateKey>(
28
+ key: K,
29
+ callback: (value: PublicStateControllerState[K]) => void
30
+ ) {
31
+ return subKey(state, key, callback);
32
+ },
33
+
34
+ set(newState: Partial<PublicStateControllerState>) {
35
+ Object.assign(state, { ...state, ...newState });
36
+ }
37
+ };
@@ -0,0 +1,112 @@
1
+ import { proxy } from 'valtio';
2
+ import type {
3
+ AppKitNetwork,
4
+ SocialProvider,
5
+ WcWallet,
6
+ OnRampTransactionResult
7
+ } from '@reown/appkit-common-react-native';
8
+
9
+ // -- Types --------------------------------------------- //
10
+ export interface RouterControllerState {
11
+ view:
12
+ | 'Account'
13
+ | 'AccountDefault'
14
+ | 'AllWallets'
15
+ | 'Connect'
16
+ | 'ConnectSocials'
17
+ | 'ConnectingExternal'
18
+ | 'ConnectingSocial'
19
+ | 'GetWallet'
20
+ | 'Networks'
21
+ | 'OnRamp'
22
+ | 'OnRampCheckout'
23
+ | 'OnRampLoading'
24
+ | 'OnRampSettings'
25
+ | 'OnRampTransaction'
26
+ | 'SIWXSignMessage'
27
+ | 'Swap'
28
+ | 'SwapPreview'
29
+ | 'SwitchNetwork'
30
+ | 'Transactions'
31
+ | 'UnsupportedChain'
32
+ | 'UpgradeEmailWallet'
33
+ | 'WalletCompatibleNetworks'
34
+ | 'WalletConnect'
35
+ | 'WalletReceive'
36
+ | 'WalletSend'
37
+ | 'WalletSendPreview'
38
+ | 'WalletSendSelectToken'
39
+ | 'WhatIsANetwork'
40
+ | 'WhatIsAWallet';
41
+ history: RouterControllerState['view'][];
42
+ navigationDirection: 'forward' | 'backward' | 'none';
43
+ data?: {
44
+ wallet?: WcWallet;
45
+ network?: AppKitNetwork;
46
+ onrampResult?: OnRampTransactionResult;
47
+ socialProvider?: SocialProvider;
48
+ };
49
+ }
50
+
51
+ // -- State --------------------------------------------- //
52
+ const state = proxy<RouterControllerState>({
53
+ view: 'Connect',
54
+ history: ['Connect'],
55
+ navigationDirection: 'none'
56
+ });
57
+
58
+ // -- Controller ---------------------------------------- //
59
+ export const RouterController = {
60
+ state,
61
+
62
+ push(
63
+ view: RouterControllerState['view'],
64
+ data?: RouterControllerState['data'],
65
+ direction: 'forward' | 'backward' = 'forward'
66
+ ) {
67
+ if (view !== state.view) {
68
+ state.navigationDirection = direction;
69
+ state.view = view;
70
+ state.history = [...state.history, view];
71
+ state.data = data;
72
+ }
73
+ },
74
+
75
+ reset(view: RouterControllerState['view'], data?: RouterControllerState['data']) {
76
+ state.navigationDirection = 'none';
77
+ state.view = view;
78
+ state.history = [view];
79
+ state.data = data;
80
+ },
81
+
82
+ replace(view: RouterControllerState['view'], data?: RouterControllerState['data']) {
83
+ if (state.history.length >= 1 && state.history.at(-1) !== view) {
84
+ state.navigationDirection = 'none';
85
+ state.view = view;
86
+ state.history[state.history.length - 1] = view;
87
+ state.data = data;
88
+ }
89
+ },
90
+
91
+ goBack() {
92
+ if (state.history.length > 1) {
93
+ state.history.pop();
94
+ const [last] = state.history.slice(-1);
95
+ if (last) {
96
+ state.navigationDirection = 'backward';
97
+ state.view = last;
98
+ }
99
+ }
100
+ },
101
+
102
+ goBackToIndex(historyIndex: number) {
103
+ if (state.history.length > 1) {
104
+ state.history = state.history.slice(0, historyIndex + 1);
105
+ const [last] = state.history.slice(-1);
106
+ if (last) {
107
+ state.navigationDirection = 'backward';
108
+ state.view = last;
109
+ }
110
+ }
111
+ }
112
+ };
@@ -0,0 +1,270 @@
1
+ import { subscribeKey as subKey } from 'valtio/utils';
2
+ import { proxy, ref, subscribe as sub } from 'valtio';
3
+ import { ContractUtil, type Balance } from '@reown/appkit-common-react-native';
4
+
5
+ import { SnackController } from './SnackController';
6
+ import { CoreHelperUtil } from '../utils/CoreHelperUtil';
7
+ import { EventsController } from './EventsController';
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';
13
+
14
+ // -- Types --------------------------------------------- //
15
+ export interface TxParams {
16
+ receiverAddress: string;
17
+ sendTokenAmount: number;
18
+ decimals: string;
19
+ }
20
+
21
+ export interface ContractWriteParams {
22
+ receiverAddress: string;
23
+ tokenAddress: string;
24
+ sendTokenAmount: number;
25
+ decimals: string;
26
+ }
27
+
28
+ export interface SendControllerState {
29
+ token?: Balance;
30
+ sendTokenAmount?: number;
31
+ receiverAddress?: string;
32
+ receiverProfileName?: string;
33
+ receiverProfileImageUrl?: string;
34
+ loading: boolean;
35
+ }
36
+
37
+ type StateKey = keyof SendControllerState;
38
+
39
+ // -- State --------------------------------------------- //
40
+ const state = proxy<SendControllerState>({
41
+ loading: false
42
+ });
43
+
44
+ // -- Controller ---------------------------------------- //
45
+ export const SendController = {
46
+ state,
47
+
48
+ subscribe(callback: (newState: SendControllerState) => void) {
49
+ return sub(state, () => callback(state));
50
+ },
51
+
52
+ subscribeKey<K extends StateKey>(key: K, callback: (value: SendControllerState[K]) => void) {
53
+ return subKey(state, key, callback);
54
+ },
55
+
56
+ setToken(token: SendControllerState['token']) {
57
+ if (token) {
58
+ state.token = ref(token);
59
+ }
60
+ },
61
+
62
+ setTokenAmount(sendTokenAmount: SendControllerState['sendTokenAmount']) {
63
+ state.sendTokenAmount = sendTokenAmount;
64
+ },
65
+
66
+ setReceiverAddress(receiverAddress: SendControllerState['receiverAddress']) {
67
+ state.receiverAddress = receiverAddress;
68
+ },
69
+
70
+ setReceiverProfileImageUrl(
71
+ receiverProfileImageUrl: SendControllerState['receiverProfileImageUrl']
72
+ ) {
73
+ state.receiverProfileImageUrl = receiverProfileImageUrl;
74
+ },
75
+
76
+ setReceiverProfileName(receiverProfileName: SendControllerState['receiverProfileName']) {
77
+ state.receiverProfileName = receiverProfileName;
78
+ },
79
+
80
+ setLoading(loading: SendControllerState['loading']) {
81
+ state.loading = loading;
82
+ },
83
+
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
+ EventsController.sendEvent({
97
+ type: 'track',
98
+ event: 'SEND_INITIATED',
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
120
+ });
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({
147
+ receiverAddress: this.state.receiverAddress,
148
+ tokenAddress: this.state.token.address,
149
+ sendTokenAmount: this.state.sendTokenAmount,
150
+ decimals: this.state.token.quantity?.decimals || '0'
151
+ });
152
+ } else if (
153
+ this.state.receiverAddress &&
154
+ this.state.sendTokenAmount &&
155
+ this.state.token?.quantity?.decimals
156
+ ) {
157
+ await this.sendNativeToken({
158
+ receiverAddress: this.state.receiverAddress,
159
+ sendTokenAmount: this.state.sendTokenAmount,
160
+ decimals: this.state.token.quantity.decimals
161
+ });
162
+ }
163
+ },
164
+
165
+ async sendNativeToken(params: TxParams) {
166
+ const to = params.receiverAddress as `0x${string}`;
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(
176
+ params.sendTokenAmount.toString(),
177
+ Number(params.decimals)
178
+ );
179
+ const data = '0x';
180
+
181
+ await ConnectionsController.sendTransaction({
182
+ to,
183
+ address,
184
+ data,
185
+ value,
186
+ network
187
+ });
188
+ },
189
+
190
+ async sendERC20Token(params: ContractWriteParams) {
191
+ const network = ConnectionsController.state.activeNetwork;
192
+ const amount = ConnectionsController.parseUnits(
193
+ params.sendTokenAmount.toString(),
194
+ Number(params.decimals)
195
+ );
196
+
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');
212
+ }
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');
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();
260
+ },
261
+
262
+ resetState() {
263
+ state.token = undefined;
264
+ state.sendTokenAmount = undefined;
265
+ state.receiverAddress = undefined;
266
+ state.receiverProfileImageUrl = undefined;
267
+ state.receiverProfileName = undefined;
268
+ state.loading = false;
269
+ }
270
+ };
@@ -0,0 +1,95 @@
1
+ import { proxy } from 'valtio';
2
+ import { OptionsController } from './OptionsController';
3
+
4
+ // -- Types --------------------------------------------- //
5
+ interface Message {
6
+ shortMessage: string;
7
+ longMessage?: string;
8
+ }
9
+
10
+ export interface SnackControllerState {
11
+ message: string;
12
+ variant: 'error' | 'success' | 'loading';
13
+ open: boolean;
14
+ long: boolean;
15
+ }
16
+
17
+ // -- State --------------------------------------------- //
18
+ const state = proxy<SnackControllerState>({
19
+ message: '',
20
+ variant: 'success',
21
+ open: false,
22
+ long: false
23
+ });
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
+
45
+ // -- Controller ---------------------------------------- //
46
+ export const SnackController = {
47
+ state,
48
+
49
+ showSuccess(message: SnackControllerState['message'], long = false) {
50
+ state.message = message;
51
+ state.variant = 'success';
52
+ state.open = true;
53
+ state.long = long;
54
+ scheduleAutoHide(long);
55
+ },
56
+
57
+ showError(message: SnackControllerState['message'], long = false) {
58
+ state.message = message;
59
+ state.variant = 'error';
60
+ state.open = true;
61
+ state.long = long;
62
+ scheduleAutoHide(long);
63
+ },
64
+
65
+ showLoading(message: SnackControllerState['message'], long = false) {
66
+ state.message = message;
67
+ state.variant = 'loading';
68
+ state.open = true;
69
+ state.long = long;
70
+ scheduleAutoHide(long);
71
+ },
72
+
73
+ showInternalError(error: Message) {
74
+ const { debug } = OptionsController.state;
75
+
76
+ if (debug) {
77
+ state.message = error.shortMessage;
78
+ state.variant = 'error';
79
+ state.open = true;
80
+ state.long = true;
81
+ scheduleAutoHide(true);
82
+ }
83
+
84
+ if (error.longMessage) {
85
+ // eslint-disable-next-line no-console
86
+ console.error(error.longMessage);
87
+ }
88
+ },
89
+
90
+ hide() {
91
+ clearHideTimeout();
92
+ state.open = false;
93
+ state.long = false;
94
+ }
95
+ };