@reown/appkit-core-react-native 0.0.0-refactor-modal-migration-20241004184043 → 1.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 (157) hide show
  1. package/lib/commonjs/controllers/AccountController.js +1 -25
  2. package/lib/commonjs/controllers/AccountController.js.map +1 -1
  3. package/lib/commonjs/controllers/ApiController.js +3 -3
  4. package/lib/commonjs/controllers/ApiController.js.map +1 -1
  5. package/lib/commonjs/controllers/BlockchainApiController.js +0 -84
  6. package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
  7. package/lib/commonjs/controllers/ConnectionController.js +0 -29
  8. package/lib/commonjs/controllers/ConnectionController.js.map +1 -1
  9. package/lib/commonjs/controllers/EventsController.js +15 -1
  10. package/lib/commonjs/controllers/EventsController.js.map +1 -1
  11. package/lib/commonjs/controllers/ModalController.js +1 -3
  12. package/lib/commonjs/controllers/ModalController.js.map +1 -1
  13. package/lib/commonjs/controllers/NetworkController.js +0 -3
  14. package/lib/commonjs/controllers/NetworkController.js.map +1 -1
  15. package/lib/commonjs/controllers/OptionsController.js +2 -10
  16. package/lib/commonjs/controllers/OptionsController.js.map +1 -1
  17. package/lib/commonjs/controllers/RouterController.js +1 -22
  18. package/lib/commonjs/controllers/RouterController.js.map +1 -1
  19. package/lib/commonjs/index.js +0 -42
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/commonjs/utils/ConstantsUtil.js +1 -8
  22. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
  23. package/lib/commonjs/utils/CoreHelperUtil.js +0 -33
  24. package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
  25. package/lib/commonjs/utils/FetchUtil.js.map +1 -1
  26. package/lib/commonjs/utils/StorageUtil.js +0 -24
  27. package/lib/commonjs/utils/StorageUtil.js.map +1 -1
  28. package/lib/commonjs/utils/TypeUtil.js +0 -4
  29. package/lib/module/controllers/AccountController.js +1 -25
  30. package/lib/module/controllers/AccountController.js.map +1 -1
  31. package/lib/module/controllers/ApiController.js +3 -3
  32. package/lib/module/controllers/ApiController.js.map +1 -1
  33. package/lib/module/controllers/BlockchainApiController.js +0 -84
  34. package/lib/module/controllers/BlockchainApiController.js.map +1 -1
  35. package/lib/module/controllers/ConnectionController.js +0 -29
  36. package/lib/module/controllers/ConnectionController.js.map +1 -1
  37. package/lib/module/controllers/EventsController.js +15 -1
  38. package/lib/module/controllers/EventsController.js.map +1 -1
  39. package/lib/module/controllers/ModalController.js +1 -3
  40. package/lib/module/controllers/ModalController.js.map +1 -1
  41. package/lib/module/controllers/NetworkController.js +0 -3
  42. package/lib/module/controllers/NetworkController.js.map +1 -1
  43. package/lib/module/controllers/OptionsController.js +2 -10
  44. package/lib/module/controllers/OptionsController.js.map +1 -1
  45. package/lib/module/controllers/RouterController.js +1 -22
  46. package/lib/module/controllers/RouterController.js.map +1 -1
  47. package/lib/module/index.js +0 -7
  48. package/lib/module/index.js.map +1 -1
  49. package/lib/module/utils/ConstantsUtil.js +1 -8
  50. package/lib/module/utils/ConstantsUtil.js.map +1 -1
  51. package/lib/module/utils/CoreHelperUtil.js +0 -33
  52. package/lib/module/utils/CoreHelperUtil.js.map +1 -1
  53. package/lib/module/utils/FetchUtil.js.map +1 -1
  54. package/lib/module/utils/StorageUtil.js +0 -24
  55. package/lib/module/utils/StorageUtil.js.map +1 -1
  56. package/lib/module/utils/TypeUtil.js +1 -1
  57. package/lib/typescript/controllers/AccountController.d.ts +0 -4
  58. package/lib/typescript/controllers/AccountController.d.ts.map +1 -1
  59. package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
  60. package/lib/typescript/controllers/BlockchainApiController.d.ts +1 -6
  61. package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
  62. package/lib/typescript/controllers/ConnectionController.d.ts +1 -16
  63. package/lib/typescript/controllers/ConnectionController.d.ts.map +1 -1
  64. package/lib/typescript/controllers/EventsController.d.ts +6 -0
  65. package/lib/typescript/controllers/EventsController.d.ts.map +1 -1
  66. package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
  67. package/lib/typescript/controllers/NetworkController.d.ts +0 -1
  68. package/lib/typescript/controllers/NetworkController.d.ts.map +1 -1
  69. package/lib/typescript/controllers/OptionsController.d.ts +1 -3
  70. package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
  71. package/lib/typescript/controllers/RouterController.d.ts +1 -15
  72. package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
  73. package/lib/typescript/index.d.ts +26 -19
  74. package/lib/typescript/index.d.ts.map +1 -1
  75. package/lib/typescript/utils/ConstantsUtil.d.ts +0 -3
  76. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
  77. package/lib/typescript/utils/CoreHelperUtil.d.ts +0 -6
  78. package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
  79. package/lib/typescript/utils/FetchUtil.d.ts +0 -3
  80. package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
  81. package/lib/typescript/utils/StorageUtil.d.ts +0 -4
  82. package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
  83. package/lib/typescript/utils/TypeUtil.d.ts +2 -178
  84. package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
  85. package/package.json +5 -5
  86. package/readme.md +1 -1
  87. package/src/controllers/AccountController.ts +1 -35
  88. package/src/controllers/ApiController.ts +7 -3
  89. package/src/controllers/BlockchainApiController.ts +1 -88
  90. package/src/controllers/ConnectionController.ts +1 -51
  91. package/src/controllers/EventsController.ts +13 -1
  92. package/src/controllers/ModalController.ts +1 -3
  93. package/src/controllers/NetworkController.ts +0 -6
  94. package/src/controllers/OptionsController.ts +3 -17
  95. package/src/controllers/RouterController.ts +10 -57
  96. package/src/index.ts +30 -43
  97. package/src/utils/ConstantsUtil.ts +1 -13
  98. package/src/utils/CoreHelperUtil.ts +1 -38
  99. package/src/utils/FetchUtil.ts +0 -4
  100. package/src/utils/StorageUtil.ts +0 -30
  101. package/src/utils/TypeUtil.ts +2 -207
  102. package/lib/commonjs/controllers/EnsController.js +0 -35
  103. package/lib/commonjs/controllers/EnsController.js.map +0 -1
  104. package/lib/commonjs/controllers/SendController.js +0 -176
  105. package/lib/commonjs/controllers/SendController.js.map +0 -1
  106. package/lib/commonjs/controllers/SwapController.js +0 -91
  107. package/lib/commonjs/controllers/SwapController.js.map +0 -1
  108. package/lib/commonjs/controllers/TransactionsController.js +0 -111
  109. package/lib/commonjs/controllers/TransactionsController.js.map +0 -1
  110. package/lib/commonjs/controllers/WebviewController.js +0 -40
  111. package/lib/commonjs/controllers/WebviewController.js.map +0 -1
  112. package/lib/commonjs/utils/ApiUtil.js +0 -18
  113. package/lib/commonjs/utils/ApiUtil.js.map +0 -1
  114. package/lib/commonjs/utils/SwapApiUtil.js +0 -23
  115. package/lib/commonjs/utils/SwapApiUtil.js.map +0 -1
  116. package/lib/commonjs/utils/SwapCalculationUtil.js +0 -24
  117. package/lib/commonjs/utils/SwapCalculationUtil.js.map +0 -1
  118. package/lib/module/controllers/EnsController.js +0 -30
  119. package/lib/module/controllers/EnsController.js.map +0 -1
  120. package/lib/module/controllers/SendController.js +0 -171
  121. package/lib/module/controllers/SendController.js.map +0 -1
  122. package/lib/module/controllers/SwapController.js +0 -86
  123. package/lib/module/controllers/SwapController.js.map +0 -1
  124. package/lib/module/controllers/TransactionsController.js +0 -106
  125. package/lib/module/controllers/TransactionsController.js.map +0 -1
  126. package/lib/module/controllers/WebviewController.js +0 -35
  127. package/lib/module/controllers/WebviewController.js.map +0 -1
  128. package/lib/module/utils/ApiUtil.js +0 -12
  129. package/lib/module/utils/ApiUtil.js.map +0 -1
  130. package/lib/module/utils/SwapApiUtil.js +0 -17
  131. package/lib/module/utils/SwapApiUtil.js.map +0 -1
  132. package/lib/module/utils/SwapCalculationUtil.js +0 -19
  133. package/lib/module/utils/SwapCalculationUtil.js.map +0 -1
  134. package/lib/typescript/controllers/EnsController.d.ts +0 -10
  135. package/lib/typescript/controllers/EnsController.d.ts.map +0 -1
  136. package/lib/typescript/controllers/SendController.d.ts +0 -41
  137. package/lib/typescript/controllers/SendController.d.ts.map +0 -1
  138. package/lib/typescript/controllers/SwapController.d.ts +0 -29
  139. package/lib/typescript/controllers/SwapController.d.ts.map +0 -1
  140. package/lib/typescript/controllers/TransactionsController.d.ts +0 -21
  141. package/lib/typescript/controllers/TransactionsController.d.ts.map +0 -1
  142. package/lib/typescript/controllers/WebviewController.d.ts +0 -18
  143. package/lib/typescript/controllers/WebviewController.d.ts.map +0 -1
  144. package/lib/typescript/utils/ApiUtil.d.ts +0 -5
  145. package/lib/typescript/utils/ApiUtil.d.ts.map +0 -1
  146. package/lib/typescript/utils/SwapApiUtil.d.ts +0 -4
  147. package/lib/typescript/utils/SwapApiUtil.d.ts.map +0 -1
  148. package/lib/typescript/utils/SwapCalculationUtil.d.ts +0 -5
  149. package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +0 -1
  150. package/src/controllers/EnsController.ts +0 -39
  151. package/src/controllers/SendController.ts +0 -234
  152. package/src/controllers/SwapController.ts +0 -108
  153. package/src/controllers/TransactionsController.ts +0 -141
  154. package/src/controllers/WebviewController.ts +0 -48
  155. package/src/utils/ApiUtil.ts +0 -18
  156. package/src/utils/SwapApiUtil.ts +0 -19
  157. package/src/utils/SwapCalculationUtil.ts +0 -21
@@ -1,234 +0,0 @@
1
- import { subscribeKey as subKey } from 'valtio/vanilla/utils';
2
- import { proxy, ref, subscribe as sub } from 'valtio/vanilla';
3
- import { ContractUtil, type Balance } from '@reown/appkit-common-react-native';
4
- import { AccountController } from './AccountController';
5
- import { ConnectionController } from './ConnectionController';
6
- import { SnackController } from './SnackController';
7
- import { CoreHelperUtil } from '../utils/CoreHelperUtil';
8
- import { EventsController } from './EventsController';
9
- import { NetworkController } from './NetworkController';
10
- import { RouterController } from './RouterController';
11
-
12
- // -- Types --------------------------------------------- //
13
- export interface TxParams {
14
- receiverAddress: string;
15
- sendTokenAmount: number;
16
- gasPrice: bigint;
17
- decimals: string;
18
- }
19
-
20
- export interface ContractWriteParams {
21
- receiverAddress: string;
22
- tokenAddress: string;
23
- sendTokenAmount: number;
24
- decimals: string;
25
- }
26
-
27
- export interface SendControllerState {
28
- token?: Balance;
29
- sendTokenAmount?: number;
30
- receiverAddress?: string;
31
- receiverProfileName?: string;
32
- receiverProfileImageUrl?: string;
33
- gasPrice?: bigint;
34
- gasPriceInUSD?: number;
35
- loading: boolean;
36
- }
37
-
38
- type StateKey = keyof SendControllerState;
39
-
40
- // -- State --------------------------------------------- //
41
- const state = proxy<SendControllerState>({
42
- loading: false
43
- });
44
-
45
- // -- Controller ---------------------------------------- //
46
- export const SendController = {
47
- state,
48
-
49
- subscribe(callback: (newState: SendControllerState) => void) {
50
- return sub(state, () => callback(state));
51
- },
52
-
53
- subscribeKey<K extends StateKey>(key: K, callback: (value: SendControllerState[K]) => void) {
54
- return subKey(state, key, callback);
55
- },
56
-
57
- setToken(token: SendControllerState['token']) {
58
- if (token) {
59
- state.token = ref(token);
60
- }
61
- },
62
-
63
- setTokenAmount(sendTokenAmount: SendControllerState['sendTokenAmount']) {
64
- state.sendTokenAmount = sendTokenAmount;
65
- },
66
-
67
- setReceiverAddress(receiverAddress: SendControllerState['receiverAddress']) {
68
- state.receiverAddress = receiverAddress;
69
- },
70
-
71
- setReceiverProfileImageUrl(
72
- receiverProfileImageUrl: SendControllerState['receiverProfileImageUrl']
73
- ) {
74
- state.receiverProfileImageUrl = receiverProfileImageUrl;
75
- },
76
-
77
- setReceiverProfileName(receiverProfileName: SendControllerState['receiverProfileName']) {
78
- state.receiverProfileName = receiverProfileName;
79
- },
80
-
81
- setGasPrice(gasPrice: SendControllerState['gasPrice']) {
82
- state.gasPrice = gasPrice;
83
- },
84
-
85
- setGasPriceInUsd(gasPriceInUSD: SendControllerState['gasPriceInUSD']) {
86
- state.gasPriceInUSD = gasPriceInUSD;
87
- },
88
-
89
- setLoading(loading: SendControllerState['loading']) {
90
- state.loading = loading;
91
- },
92
-
93
- sendToken() {
94
- if (this.state.token?.address && this.state.sendTokenAmount && this.state.receiverAddress) {
95
- state.loading = true;
96
- EventsController.sendEvent({
97
- type: 'track',
98
- event: 'SEND_INITIATED',
99
- properties: {
100
- isSmartAccount: false,
101
- token: this.state.token.address,
102
- amount: this.state.sendTokenAmount,
103
- network: NetworkController.state.caipNetwork?.id || ''
104
- }
105
- });
106
- this.sendERC20Token({
107
- receiverAddress: this.state.receiverAddress,
108
- tokenAddress: this.state.token.address,
109
- sendTokenAmount: this.state.sendTokenAmount,
110
- decimals: this.state.token.quantity.decimals
111
- });
112
- } else if (
113
- this.state.receiverAddress &&
114
- this.state.sendTokenAmount &&
115
- this.state.gasPrice &&
116
- this.state.token?.quantity.decimals
117
- ) {
118
- state.loading = true;
119
- EventsController.sendEvent({
120
- type: 'track',
121
- event: 'SEND_INITIATED',
122
- properties: {
123
- isSmartAccount: false,
124
- token: this.state.token?.symbol,
125
- amount: this.state.sendTokenAmount,
126
- network: NetworkController.state.caipNetwork?.id || ''
127
- }
128
- });
129
- this.sendNativeToken({
130
- receiverAddress: this.state.receiverAddress,
131
- sendTokenAmount: this.state.sendTokenAmount,
132
- gasPrice: this.state.gasPrice,
133
- decimals: this.state.token.quantity.decimals
134
- });
135
- }
136
- },
137
-
138
- async sendNativeToken(params: TxParams) {
139
- RouterController.pushTransactionStack({
140
- view: 'Account',
141
- goBack: false
142
- });
143
-
144
- const to = params.receiverAddress as `0x${string}`;
145
- const address = AccountController.state.address as `0x${string}`;
146
- const value = ConnectionController.parseUnits(
147
- params.sendTokenAmount.toString(),
148
- Number(params.decimals)
149
- );
150
- const data = '0x';
151
-
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: false,
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: false,
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
- }
186
- },
187
-
188
- async sendERC20Token(params: ContractWriteParams) {
189
- RouterController.pushTransactionStack({
190
- view: 'Account',
191
- goBack: false
192
- });
193
-
194
- const amount = ConnectionController.parseUnits(
195
- params.sendTokenAmount.toString(),
196
- Number(params.decimals)
197
- );
198
-
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();
219
- }
220
- } catch (error) {
221
- state.loading = false;
222
- SnackController.showError('Something went wrong');
223
- }
224
- },
225
-
226
- resetSend() {
227
- state.token = undefined;
228
- state.sendTokenAmount = undefined;
229
- state.receiverAddress = undefined;
230
- state.receiverProfileImageUrl = undefined;
231
- state.receiverProfileName = undefined;
232
- state.loading = false;
233
- }
234
- };
@@ -1,108 +0,0 @@
1
- import { subscribeKey as subKey } from 'valtio/utils';
2
- import { proxy, subscribe as sub } from 'valtio';
3
-
4
- import { ConstantsUtil } from '../utils/ConstantsUtil';
5
- import { SwapApiUtil } from '../utils/SwapApiUtil';
6
- import { NetworkController } from './NetworkController';
7
- import { BlockchainApiController } from './BlockchainApiController';
8
- import { OptionsController } from './OptionsController';
9
- import { SwapCalculationUtil } from '../utils/SwapCalculationUtil';
10
-
11
- // -- Constants ---------------------------------------- //
12
- export const INITIAL_GAS_LIMIT = 150000;
13
- export const TO_AMOUNT_DECIMALS = 6;
14
-
15
- // -- Types --------------------------------------------- //
16
-
17
- export interface SwapControllerState {
18
- // Input values
19
- networkPrice: string;
20
- networkTokenSymbol: string;
21
-
22
- // Tokens
23
- tokensPriceMap: Record<string, number>;
24
-
25
- // Calculations
26
- gasFee: string;
27
- gasPriceInUSD?: number;
28
- }
29
-
30
- type StateKey = keyof SwapControllerState;
31
-
32
- // -- State --------------------------------------------- //
33
- const initialState: SwapControllerState = {
34
- // Input values
35
- networkPrice: '0',
36
- networkTokenSymbol: '',
37
-
38
- // Tokens
39
- tokensPriceMap: {},
40
-
41
- // Calculations
42
- gasFee: '0',
43
- gasPriceInUSD: 0
44
- };
45
-
46
- const state = proxy<SwapControllerState>(initialState);
47
-
48
- // -- Controller ---------------------------------------- //
49
- export const SwapController = {
50
- state,
51
-
52
- subscribe(callback: (newState: SwapControllerState) => void) {
53
- return sub(state, () => callback(state));
54
- },
55
-
56
- subscribeKey<K extends StateKey>(key: K, callback: (value: SwapControllerState[K]) => void) {
57
- return subKey(state, key, callback);
58
- },
59
-
60
- getParams() {
61
- const caipNetwork = NetworkController.state.caipNetwork;
62
- const networkAddress = `${caipNetwork?.id}:${ConstantsUtil.NATIVE_TOKEN_ADDRESS}`;
63
-
64
- return {
65
- networkAddress
66
- };
67
- },
68
-
69
- resetState() {
70
- state.tokensPriceMap = initialState.tokensPriceMap;
71
- state.networkPrice = initialState.networkPrice;
72
- state.networkTokenSymbol = initialState.networkTokenSymbol;
73
- },
74
-
75
- //this
76
- async getNetworkTokenPrice() {
77
- const { networkAddress } = this.getParams();
78
-
79
- const response = await BlockchainApiController.fetchTokenPrice({
80
- projectId: OptionsController.state.projectId,
81
- addresses: [networkAddress]
82
- });
83
- const token = response?.fungibles?.[0];
84
- const price = token?.price.toString() || '0';
85
- state.tokensPriceMap[networkAddress] = parseFloat(price);
86
- state.networkTokenSymbol = token?.symbol || '';
87
- state.networkPrice = price;
88
- },
89
-
90
- //this
91
- async getInitialGasPrice() {
92
- const res = await SwapApiUtil.fetchGasPrice();
93
-
94
- if (!res) {
95
- return { gasPrice: null, gasPriceInUsd: null };
96
- }
97
-
98
- const value = res.standard;
99
- const gasFee = BigInt(value);
100
- const gasLimit = BigInt(INITIAL_GAS_LIMIT);
101
- const gasPrice = SwapCalculationUtil.getGasPriceInUSD(state.networkPrice, gasLimit, gasFee);
102
-
103
- state.gasFee = value;
104
- state.gasPriceInUSD = gasPrice;
105
-
106
- return { gasPrice: gasFee, gasPriceInUSD: state.gasPriceInUSD };
107
- }
108
- };
@@ -1,141 +0,0 @@
1
- import type { Transaction } from '@reown/appkit-common-react-native';
2
- import { proxy, subscribe as sub } from 'valtio/vanilla';
3
- import { OptionsController } from './OptionsController';
4
- import { EventsController } from './EventsController';
5
- import { SnackController } from './SnackController';
6
- import { NetworkController } from './NetworkController';
7
- import { BlockchainApiController } from './BlockchainApiController';
8
-
9
- // -- Types --------------------------------------------- //
10
- type TransactionByMonthMap = Record<string, Transaction[]>;
11
- type TransactionByYearMap = Record<string, TransactionByMonthMap>;
12
-
13
- export interface TransactionsControllerState {
14
- transactions: Transaction[];
15
- loading: boolean;
16
- empty: boolean;
17
- next: string | undefined;
18
- }
19
-
20
- // -- State --------------------------------------------- //
21
- const state = proxy<TransactionsControllerState>({
22
- transactions: [],
23
- loading: false,
24
- empty: false,
25
- next: undefined
26
- });
27
-
28
- // -- Controller ---------------------------------------- //
29
- export const TransactionsController = {
30
- state,
31
-
32
- subscribe(callback: (newState: TransactionsControllerState) => void) {
33
- return sub(state, () => callback(state));
34
- },
35
-
36
- async fetchTransactions(accountAddress?: string, reset?: boolean) {
37
- const { projectId } = OptionsController.state;
38
-
39
- if (!projectId || !accountAddress) {
40
- throw new Error("Transactions can't be fetched without a projectId and an accountAddress");
41
- }
42
-
43
- state.loading = true;
44
-
45
- if (reset) {
46
- state.next = undefined;
47
- }
48
-
49
- try {
50
- const response = await BlockchainApiController.fetchTransactions({
51
- account: accountAddress,
52
- projectId,
53
- cursor: state.next
54
- });
55
-
56
- const nonSpamTransactions = this.filterSpamTransactions(response?.data ?? []);
57
- let filteredTransactions = [...state.transactions, ...nonSpamTransactions];
58
-
59
- if (reset) {
60
- filteredTransactions = nonSpamTransactions;
61
- }
62
-
63
- state.loading = false;
64
-
65
- state.transactions = filteredTransactions;
66
-
67
- state.empty = nonSpamTransactions.length === 0;
68
- state.next = response?.next ? response.next : undefined;
69
- } catch (error) {
70
- EventsController.sendEvent({
71
- type: 'track',
72
- event: 'ERROR_FETCH_TRANSACTIONS',
73
- properties: {
74
- address: accountAddress,
75
- projectId,
76
- cursor: state.next,
77
- isSmartAccount: false
78
- }
79
- });
80
- SnackController.showError('Failed to fetch transactions');
81
- state.loading = false;
82
- state.empty = true;
83
- state.next = undefined;
84
- }
85
- },
86
-
87
- getTransactionsByYearAndMonth(transactions: Transaction[]) {
88
- const grouped: TransactionByYearMap = {};
89
- let filteredTransactions = this.filterByConnectedChain(transactions);
90
-
91
- filteredTransactions.forEach(transaction => {
92
- const year = new Date(transaction.metadata.minedAt).getFullYear();
93
- const month = new Date(transaction.metadata.minedAt).getMonth();
94
-
95
- const yearTransactions = grouped[year] ?? {};
96
- const monthTransactions = yearTransactions[month] ?? [];
97
-
98
- // If there's a transaction with the same id, remove the old one
99
- const newMonthTransactions = monthTransactions.filter(tx => tx.id !== transaction.id);
100
-
101
- grouped[year] = {
102
- ...yearTransactions,
103
- [month]: [...newMonthTransactions, transaction].sort(
104
- (a, b) => new Date(b.metadata.minedAt).getTime() - new Date(a.metadata.minedAt).getTime()
105
- )
106
- };
107
- });
108
-
109
- return grouped;
110
- },
111
-
112
- filterSpamTransactions(transactions: Transaction[]) {
113
- return transactions.filter(transaction => {
114
- const isAllSpam = transaction.transfers.every(
115
- transfer => transfer.nft_info?.flags.is_spam === true
116
- );
117
-
118
- return !isAllSpam;
119
- });
120
- },
121
-
122
- filterByConnectedChain(transactions: Transaction[]) {
123
- const chainId = NetworkController.state.caipNetwork?.id;
124
- const filteredTransactions = transactions.filter(
125
- transaction => transaction.metadata.chain === chainId
126
- );
127
-
128
- return filteredTransactions;
129
- },
130
-
131
- clearCursor() {
132
- state.next = undefined;
133
- },
134
-
135
- resetTransactions() {
136
- state.transactions = [];
137
- state.loading = false;
138
- state.empty = false;
139
- state.next = undefined;
140
- }
141
- };
@@ -1,48 +0,0 @@
1
- import type { SocialProvider } from '@reown/appkit-common-react-native';
2
- import { proxy, subscribe as sub } from 'valtio';
3
-
4
- // -- Types --------------------------------------------- //
5
- export interface WebviewControllerState {
6
- frameViewVisible: boolean;
7
- webviewVisible: boolean;
8
- webviewUrl?: string;
9
- connecting?: boolean;
10
- connectingProvider?: SocialProvider;
11
- }
12
-
13
- // -- State --------------------------------------------- //
14
- const state = proxy<WebviewControllerState>({
15
- frameViewVisible: false,
16
- webviewVisible: false,
17
- connecting: false,
18
- connectingProvider: undefined
19
- });
20
-
21
- // -- Controller ---------------------------------------- //
22
- export const WebviewController = {
23
- state,
24
-
25
- subscribe(callback: (newState: WebviewControllerState) => void) {
26
- return sub(state, () => callback(state));
27
- },
28
-
29
- setFrameViewVisible(frameViewVisible: WebviewControllerState['frameViewVisible']) {
30
- state.frameViewVisible = frameViewVisible;
31
- },
32
-
33
- setWebviewVisible(visible: WebviewControllerState['webviewVisible']) {
34
- state.webviewVisible = visible;
35
- },
36
-
37
- setWebviewUrl(url: WebviewControllerState['webviewUrl']) {
38
- state.webviewUrl = url;
39
- },
40
-
41
- setConnecting(connecting: WebviewControllerState['connecting']) {
42
- state.connecting = connecting;
43
- },
44
-
45
- setConnectingProvider(provider: WebviewControllerState['connectingProvider']) {
46
- state.connectingProvider = provider;
47
- }
48
- };
@@ -1,18 +0,0 @@
1
- import { Platform } from 'react-native';
2
- import { CoreHelperUtil } from './CoreHelperUtil';
3
-
4
- export const ApiUtil = {
5
- getOrigin() {
6
- return CoreHelperUtil.getBundleId();
7
- },
8
-
9
- getUserAgent() {
10
- const reactNativeVersion = [
11
- Platform.constants.reactNativeVersion.major,
12
- Platform.constants.reactNativeVersion.minor,
13
- Platform.constants.reactNativeVersion.patch
14
- ].join('.');
15
-
16
- return `${Platform.OS}-${Platform.Version}@rn-${reactNativeVersion}`;
17
- }
18
- };
@@ -1,19 +0,0 @@
1
- import { BlockchainApiController } from '../controllers/BlockchainApiController';
2
- import { OptionsController } from '../controllers/OptionsController';
3
- import { NetworkController } from '../controllers/NetworkController';
4
-
5
- export const SwapApiUtil = {
6
- async fetchGasPrice() {
7
- const projectId = OptionsController.state.projectId;
8
- const caipNetwork = NetworkController.state.caipNetwork;
9
-
10
- if (!caipNetwork) {
11
- return null;
12
- }
13
-
14
- return await BlockchainApiController.fetchGasPrice({
15
- projectId,
16
- chainId: caipNetwork.id
17
- });
18
- }
19
- };
@@ -1,21 +0,0 @@
1
- // -- Types --------------------------------------------- //
2
-
3
- import { NumberUtil } from '@reown/appkit-common-react-native';
4
-
5
- // -- Util ---------------------------------------- //
6
- export const SwapCalculationUtil = {
7
- getGasPriceInEther(gas: bigint, gasPrice: bigint) {
8
- const totalGasCostInWei = gasPrice * gas;
9
- const totalGasCostInEther = Number(totalGasCostInWei) / 1e18;
10
-
11
- return totalGasCostInEther;
12
- },
13
-
14
- getGasPriceInUSD(networkPrice: string, gas: bigint, gasPrice: bigint) {
15
- const totalGasCostInEther = SwapCalculationUtil.getGasPriceInEther(gas, gasPrice);
16
- const networkPriceInUSD = NumberUtil.bigNumber(networkPrice);
17
- const gasCostInUSD = networkPriceInUSD.multipliedBy(totalGasCostInEther);
18
-
19
- return gasCostInUSD.toNumber();
20
- }
21
- };