@reown/appkit-core-react-native 0.0.0-feat-multi-social-20250701185040 → 0.0.0-feat-multi-social-20250708154835

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 (68) hide show
  1. package/lib/commonjs/controllers/AccountController.js +20 -17
  2. package/lib/commonjs/controllers/AccountController.js.map +1 -1
  3. package/lib/commonjs/controllers/BlockchainApiController.js +8 -4
  4. package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
  5. package/lib/commonjs/controllers/ConnectionsController.js +208 -46
  6. package/lib/commonjs/controllers/ConnectionsController.js.map +1 -1
  7. package/lib/commonjs/controllers/ModalController.js +2 -2
  8. package/lib/commonjs/controllers/ModalController.js.map +1 -1
  9. package/lib/commonjs/controllers/RouterController.js.map +1 -1
  10. package/lib/commonjs/controllers/SendController.js +20 -15
  11. package/lib/commonjs/controllers/SendController.js.map +1 -1
  12. package/lib/commonjs/controllers/SwapController.js +22 -54
  13. package/lib/commonjs/controllers/SwapController.js.map +1 -1
  14. package/lib/commonjs/controllers/TransactionsController.js +19 -15
  15. package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
  16. package/lib/commonjs/utils/CoreHelperUtil.js +1 -1
  17. package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
  18. package/lib/commonjs/utils/SwapApiUtil.js +1 -16
  19. package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
  20. package/lib/module/controllers/AccountController.js +20 -17
  21. package/lib/module/controllers/AccountController.js.map +1 -1
  22. package/lib/module/controllers/BlockchainApiController.js +8 -4
  23. package/lib/module/controllers/BlockchainApiController.js.map +1 -1
  24. package/lib/module/controllers/ConnectionsController.js +208 -46
  25. package/lib/module/controllers/ConnectionsController.js.map +1 -1
  26. package/lib/module/controllers/ModalController.js +2 -2
  27. package/lib/module/controllers/ModalController.js.map +1 -1
  28. package/lib/module/controllers/RouterController.js.map +1 -1
  29. package/lib/module/controllers/SendController.js +20 -15
  30. package/lib/module/controllers/SendController.js.map +1 -1
  31. package/lib/module/controllers/SwapController.js +22 -54
  32. package/lib/module/controllers/SwapController.js.map +1 -1
  33. package/lib/module/controllers/TransactionsController.js +19 -15
  34. package/lib/module/controllers/TransactionsController.js.map +1 -1
  35. package/lib/module/utils/CoreHelperUtil.js +1 -1
  36. package/lib/module/utils/CoreHelperUtil.js.map +1 -1
  37. package/lib/module/utils/SwapApiUtil.js +1 -16
  38. package/lib/module/utils/SwapApiUtil.js.map +1 -1
  39. package/lib/typescript/controllers/AccountController.d.ts +3 -3
  40. package/lib/typescript/controllers/AccountController.d.ts.map +1 -1
  41. package/lib/typescript/controllers/BlockchainApiController.d.ts +2 -2
  42. package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
  43. package/lib/typescript/controllers/ConnectionsController.d.ts +16 -10
  44. package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -1
  45. package/lib/typescript/controllers/RouterController.d.ts +1 -1
  46. package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
  47. package/lib/typescript/controllers/SendController.d.ts.map +1 -1
  48. package/lib/typescript/controllers/SwapController.d.ts +2 -2
  49. package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
  50. package/lib/typescript/controllers/TransactionsController.d.ts +2 -2
  51. package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -1
  52. package/lib/typescript/utils/SwapApiUtil.d.ts +3 -3
  53. package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
  54. package/lib/typescript/utils/TypeUtil.d.ts +15 -2
  55. package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
  56. package/package.json +2 -2
  57. package/src/controllers/AccountController.ts +26 -26
  58. package/src/controllers/BlockchainApiController.ts +11 -5
  59. package/src/controllers/ConnectionController.ts +1 -1
  60. package/src/controllers/ConnectionsController.ts +251 -67
  61. package/src/controllers/ModalController.ts +2 -2
  62. package/src/controllers/RouterController.ts +0 -1
  63. package/src/controllers/SendController.ts +28 -15
  64. package/src/controllers/SwapController.ts +28 -66
  65. package/src/controllers/TransactionsController.ts +22 -16
  66. package/src/utils/CoreHelperUtil.ts +1 -1
  67. package/src/utils/SwapApiUtil.ts +4 -29
  68. package/src/utils/TypeUtil.ts +15 -2
@@ -10,8 +10,6 @@ import { SwapCalculationUtil } from '../utils/SwapCalculationUtil';
10
10
  import { SnackController } from './SnackController';
11
11
  import { RouterController } from './RouterController';
12
12
  import type { SwapInputTarget, SwapTokenWithBalance } from '../utils/TypeUtil';
13
- import { ConnectorController } from './ConnectorController';
14
- import { AccountController } from './AccountController';
15
13
  import { CoreHelperUtil } from '../utils/CoreHelperUtil';
16
14
  import { TransactionsController } from './TransactionsController';
17
15
  import { EventsController } from './EventsController';
@@ -67,7 +65,6 @@ export interface SwapControllerState {
67
65
  toTokenAmount: string;
68
66
  toTokenPriceInUSD: number;
69
67
  networkPrice: string;
70
- networkBalanceInUSD: string;
71
68
  networkTokenSymbol: string;
72
69
  inputError: string | undefined;
73
70
 
@@ -119,7 +116,6 @@ const initialState: SwapControllerState = {
119
116
  toTokenAmount: '',
120
117
  toTokenPriceInUSD: 0,
121
118
  networkPrice: '0',
122
- networkBalanceInUSD: '0',
123
119
  networkTokenSymbol: '',
124
120
  inputError: undefined,
125
121
 
@@ -157,7 +153,8 @@ export const SwapController = {
157
153
  },
158
154
 
159
155
  getParams() {
160
- const { activeAddress, activeNamespace, activeNetwork } = ConnectionsController.state;
156
+ const { activeAddress, activeNamespace, activeNetwork, connection } =
157
+ ConnectionsController.state;
161
158
  const address = CoreHelperUtil.getPlainAddress(activeAddress);
162
159
 
163
160
  if (!activeNamespace || !activeNetwork) {
@@ -166,8 +163,6 @@ export const SwapController = {
166
163
 
167
164
  const networkAddress: CaipAddress = `${activeNetwork.caipNetworkId}:${ConstantsUtil.NATIVE_TOKEN_ADDRESS[activeNamespace]}`;
168
165
 
169
- const type = ConnectorController.state.connectedConnector;
170
-
171
166
  if (!address) {
172
167
  throw new Error('No address found to swap the tokens from.');
173
168
  }
@@ -195,7 +190,7 @@ export const SwapController = {
195
190
  invalidSourceTokenAmount,
196
191
  availableToSwap:
197
192
  activeAddress && !invalidToToken && !invalidSourceToken && !invalidSourceTokenAmount,
198
- isAuthConnector: type === 'AUTH'
193
+ isAuthConnector: !!connection?.properties?.provider
199
194
  };
200
195
  },
201
196
 
@@ -237,7 +232,6 @@ export const SwapController = {
237
232
  state.toTokenPriceInUSD = initialState.toTokenPriceInUSD;
238
233
  state.networkPrice = initialState.networkPrice;
239
234
  state.networkTokenSymbol = initialState.networkTokenSymbol;
240
- state.networkBalanceInUSD = initialState.networkBalanceInUSD;
241
235
  state.inputError = initialState.inputError;
242
236
  },
243
237
 
@@ -285,14 +279,15 @@ export const SwapController = {
285
279
  }, {});
286
280
  },
287
281
 
288
- async getMyTokensWithBalance(forceUpdate?: string) {
289
- const balances = await SwapApiUtil.getMyTokensWithBalance(forceUpdate);
290
- if (!balances) {
282
+ async getMyTokensWithBalance(forceUpdate?: CaipAddress[]) {
283
+ await ConnectionsController.fetchBalance(forceUpdate);
284
+ const swapBalances = SwapApiUtil.mapBalancesToSwapTokens(ConnectionsController.state.balances);
285
+ if (!swapBalances) {
291
286
  return;
292
287
  }
293
288
 
294
289
  await this.getInitialGasPrice();
295
- this.setBalances(balances);
290
+ this.setBalances(swapBalances);
296
291
  },
297
292
 
298
293
  getFilteredPopularTokens() {
@@ -404,26 +399,11 @@ export const SwapController = {
404
399
  },
405
400
 
406
401
  setBalances(balances: SwapTokenWithBalance[]) {
407
- const { networkAddress } = this.getParams();
408
- const caipNetwork = ConnectionsController.state.activeNetwork;
409
-
410
- if (!caipNetwork) {
411
- return;
412
- }
413
-
414
- const networkToken = balances.find(token => token.address === networkAddress);
402
+ state.myTokensWithBalance = balances;
415
403
 
416
404
  balances.forEach(token => {
417
405
  state.tokensPriceMap[token.address] = token.price || 0;
418
406
  });
419
-
420
- state.myTokensWithBalance = balances.filter(
421
- token => token.address?.startsWith(caipNetwork.caipNetworkId)
422
- );
423
-
424
- state.networkBalanceInUSD = networkToken
425
- ? NumberUtil.multiply(networkToken.quantity.numeric, networkToken.price).toString()
426
- : '0';
427
407
  },
428
408
 
429
409
  setToToken(toToken: SwapTokenWithBalance | undefined) {
@@ -694,22 +674,10 @@ export const SwapController = {
694
674
  },
695
675
 
696
676
  async sendTransactionForApproval(data: TransactionParams) {
697
- const { fromAddress, isAuthConnector } = this.getParams();
698
-
677
+ const { fromAddress } = this.getParams();
699
678
  state.loadingApprovalTransaction = true;
700
- const approveLimitMessage = `Approve limit increase in your wallet`;
701
-
702
- if (isAuthConnector) {
703
- RouterController.pushTransactionStack({
704
- view: null,
705
- goBack: true,
706
- onSuccess() {
707
- SnackController.showLoading(approveLimitMessage);
708
- }
709
- });
710
- } else {
711
- SnackController.showLoading(approveLimitMessage);
712
- }
679
+
680
+ SnackController.showLoading('Approve limit increase in your wallet');
713
681
 
714
682
  try {
715
683
  await ConnectionsController.sendTransaction({
@@ -741,28 +709,17 @@ export const SwapController = {
741
709
 
742
710
  state.loadingTransaction = true;
743
711
 
744
- const snackbarPendingMessage = `Swapping ${state.sourceToken
745
- ?.symbol} to ${NumberUtil.formatNumberToLocalString(toTokenAmount, 3)} ${state.toToken
746
- ?.symbol}`;
747
712
  const snackbarSuccessMessage = `Swapped ${state.sourceToken
748
713
  ?.symbol} to ${NumberUtil.formatNumberToLocalString(toTokenAmount, 3)} ${state.toToken
749
714
  ?.symbol}`;
750
715
 
751
- if (isAuthConnector) {
752
- RouterController.pushTransactionStack({
753
- view: 'Account',
754
- goBack: false,
755
- onSuccess() {
756
- SnackController.showLoading(snackbarPendingMessage);
757
- SwapController.resetState();
758
- }
759
- });
760
- } else {
761
- SnackController.showLoading('Confirm transaction in your wallet');
762
- }
716
+ SnackController.showLoading('Confirm transaction in your wallet');
763
717
 
764
718
  try {
765
- const forceUpdateAddresses = [state.sourceToken?.address, state.toToken?.address].join(',');
719
+ const forceUpdateAddresses = [state.sourceToken?.address, state.toToken?.address].filter(
720
+ Boolean
721
+ ) as CaipAddress[];
722
+
766
723
  const transactionHash = await ConnectionsController.sendTransaction({
767
724
  address: fromAddress as `0x${string}`,
768
725
  to: data.to as `0x${string}`,
@@ -784,7 +741,7 @@ export const SwapController = {
784
741
  swapToToken: this.state.toToken?.symbol || '',
785
742
  swapFromAmount: this.state.sourceTokenAmount || '',
786
743
  swapToAmount: this.state.toTokenAmount || '',
787
- isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount'
744
+ isSmartAccount: ConnectionsController.state.accountType === 'smartAccount'
788
745
  }
789
746
  });
790
747
  SwapController.resetState();
@@ -794,10 +751,9 @@ export const SwapController = {
794
751
  }
795
752
 
796
753
  SwapController.getMyTokensWithBalance(forceUpdateAddresses);
797
- AccountController.fetchTokenBalance();
798
754
 
799
755
  setTimeout(() => {
800
- TransactionsController.fetchTransactions(AccountController.state.address, true);
756
+ TransactionsController.fetchTransactions(ConnectionsController.state.activeAddress, true);
801
757
  }, 5000);
802
758
 
803
759
  return transactionHash;
@@ -816,7 +772,7 @@ export const SwapController = {
816
772
  swapToToken: this.state.toToken?.symbol || '',
817
773
  swapFromAmount: this.state.sourceTokenAmount || '',
818
774
  swapToAmount: this.state.toTokenAmount || '',
819
- isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount'
775
+ isSmartAccount: ConnectionsController.state.accountType === 'smartAccount'
820
776
  }
821
777
  });
822
778
 
@@ -826,6 +782,12 @@ export const SwapController = {
826
782
 
827
783
  // -- Checks -------------------------------------------- //
828
784
  hasInsufficientToken(sourceTokenAmount: string, sourceTokenAddress: string) {
785
+ const { balances } = ConnectionsController.state;
786
+ const networkToken = balances?.find(t => t.address === undefined);
787
+ const networkBalanceInUSD = networkToken
788
+ ? NumberUtil.multiply(networkToken.quantity?.numeric ?? '0', networkToken.price).toString()
789
+ : '0';
790
+
829
791
  const isInsufficientSourceTokenForSwap = SwapCalculationUtil.isInsufficientSourceTokenForSwap(
830
792
  sourceTokenAmount,
831
793
  sourceTokenAddress,
@@ -833,12 +795,12 @@ export const SwapController = {
833
795
  );
834
796
 
835
797
  let insufficientNetworkTokenForGas = true;
836
- if (AccountController.state.preferredAccountType === 'smartAccount') {
798
+ if (ConnectionsController.state.accountType === 'smartAccount') {
837
799
  // Smart Accounts may pay gas in any ERC20 token
838
800
  insufficientNetworkTokenForGas = false;
839
801
  } else {
840
802
  insufficientNetworkTokenForGas = SwapCalculationUtil.isInsufficientNetworkTokenForGas(
841
- state.networkBalanceInUSD,
803
+ networkBalanceInUSD,
842
804
  state.gasPriceInUSD
843
805
  );
844
806
  }
@@ -1,10 +1,9 @@
1
- import type { Transaction } from '@reown/appkit-common-react-native';
1
+ import type { CaipAddress, Transaction } from '@reown/appkit-common-react-native';
2
2
  import { proxy, subscribe as sub } from 'valtio/vanilla';
3
3
  import { OptionsController } from './OptionsController';
4
4
  import { EventsController } from './EventsController';
5
5
  import { SnackController } from './SnackController';
6
6
  import { BlockchainApiController } from './BlockchainApiController';
7
- import { AccountController } from './AccountController';
8
7
  import { ConnectionsController } from './ConnectionsController';
9
8
 
10
9
  // -- Types --------------------------------------------- //
@@ -34,22 +33,29 @@ export const TransactionsController = {
34
33
  return sub(state, () => callback(state));
35
34
  },
36
35
 
37
- async fetchTransactions(accountAddress?: string, reset?: boolean) {
38
- const { projectId } = OptionsController.state;
36
+ async fetchTransactions(accountAddress?: CaipAddress, reset?: boolean) {
37
+ try {
38
+ const { projectId } = OptionsController.state;
39
39
 
40
- if (!projectId || !accountAddress) {
41
- throw new Error("Transactions can't be fetched without a projectId and an accountAddress");
42
- }
40
+ if (!projectId || !accountAddress) {
41
+ throw new Error("Transactions can't be fetched without a projectId and an accountAddress");
42
+ }
43
43
 
44
- state.loading = true;
44
+ state.loading = true;
45
45
 
46
- if (reset) {
47
- state.next = undefined;
48
- }
46
+ if (reset) {
47
+ state.next = undefined;
48
+ }
49
+
50
+ const [namespace, chain, address] = accountAddress?.split(':') ?? [];
51
+
52
+ if (!namespace || !chain || !address) {
53
+ throw new Error('Invalid address');
54
+ }
49
55
 
50
- try {
51
56
  const response = await BlockchainApiController.fetchTransactions({
52
- account: accountAddress,
57
+ account: address,
58
+ chainId: `${namespace}:${chain}`,
53
59
  projectId,
54
60
  cursor: state.next
55
61
  });
@@ -72,10 +78,10 @@ export const TransactionsController = {
72
78
  type: 'track',
73
79
  event: 'ERROR_FETCH_TRANSACTIONS',
74
80
  properties: {
75
- address: accountAddress,
76
- projectId,
81
+ address: accountAddress ?? '',
82
+ projectId: OptionsController.state.projectId,
77
83
  cursor: state.next,
78
- isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount'
84
+ isSmartAccount: ConnectionsController.state.accountType === 'smartAccount'
79
85
  }
80
86
  });
81
87
  SnackController.showError('Failed to fetch transactions');
@@ -285,7 +285,7 @@ export const CoreHelperUtil = {
285
285
 
286
286
  let sum = 0;
287
287
  for (const item of array) {
288
- sum += item.value ?? 0;
288
+ sum += item?.value ?? 0;
289
289
  }
290
290
 
291
291
  const roundedNumber = sum.toFixed(2);
@@ -1,13 +1,8 @@
1
+ import type { Balance, CaipNetworkId } from '@reown/appkit-common-react-native';
1
2
  import { BlockchainApiController } from '../controllers/BlockchainApiController';
2
3
  import { OptionsController } from '../controllers/OptionsController';
3
- import type {
4
- BlockchainApiBalanceResponse,
5
- BlockchainApiSwapAllowanceRequest,
6
- SwapTokenWithBalance
7
- } from './TypeUtil';
8
- import { AccountController } from '../controllers/AccountController';
4
+ import type { BlockchainApiSwapAllowanceRequest, SwapTokenWithBalance } from './TypeUtil';
9
5
  import { ConnectionsController } from '../controllers/ConnectionsController';
10
- import type { CaipNetworkId } from '@reown/appkit-common-react-native';
11
6
  import { ConstantsUtil } from './ConstantsUtil';
12
7
 
13
8
  export const SwapApiUtil = {
@@ -64,27 +59,7 @@ export const SwapApiUtil = {
64
59
  return false;
65
60
  },
66
61
 
67
- async getMyTokensWithBalance(forceUpdate?: string) {
68
- const { activeAddress, activeNetwork: network } = ConnectionsController.state;
69
- const address = activeAddress?.split(':')[2];
70
-
71
- if (!address) {
72
- return [];
73
- }
74
-
75
- const response = await BlockchainApiController.getBalance(
76
- address,
77
- network?.caipNetworkId,
78
- forceUpdate
79
- );
80
- const balances = response?.balances.filter(balance => balance.quantity.decimals !== '0');
81
-
82
- AccountController.setTokenBalance(balances);
83
-
84
- return this.mapBalancesToSwapTokens(balances);
85
- },
86
-
87
- mapBalancesToSwapTokens(balances?: BlockchainApiBalanceResponse['balances']) {
62
+ mapBalancesToSwapTokens(balances?: Balance[]) {
88
63
  const { activeNamespace, activeCaipNetworkId } = ConnectionsController.state;
89
64
  const address = activeNamespace
90
65
  ? ConstantsUtil.NATIVE_TOKEN_ADDRESS[activeNamespace]
@@ -96,7 +71,7 @@ export const SwapApiUtil = {
96
71
  ({
97
72
  ...token,
98
73
  address: token?.address ?? `${token?.chainId ?? activeCaipNetworkId}:${address}`,
99
- decimals: parseInt(token.quantity.decimals, 10),
74
+ decimals: parseInt(token.quantity?.decimals ?? '0', 10),
100
75
  logoUri: token.iconUrl,
101
76
  eip2612: false
102
77
  }) as SwapTokenWithBalance
@@ -2,7 +2,6 @@ import { type EventEmitter } from 'events';
2
2
  import type { CaipAddress, CaipNetworkId } from '@reown/appkit-common-react-native';
3
3
 
4
4
  import type {
5
- Balance,
6
5
  SocialProvider,
7
6
  ThemeMode,
8
7
  Transaction,
@@ -157,8 +156,22 @@ export interface BlockchainApiIdentityResponse {
157
156
  name: string;
158
157
  }
159
158
 
159
+ export interface BlockchainApiBalance {
160
+ name: string;
161
+ symbol: string;
162
+ chainId: string;
163
+ address?: CaipAddress;
164
+ value?: number;
165
+ price: number;
166
+ quantity: {
167
+ decimals: string;
168
+ numeric: string;
169
+ };
170
+ iconUrl: string;
171
+ }
172
+
160
173
  export interface BlockchainApiBalanceResponse {
161
- balances: Balance[];
174
+ balances: BlockchainApiBalance[];
162
175
  }
163
176
 
164
177
  export interface BlockchainApiTransactionsRequest {