@reown/appkit-core-react-native 2.0.0-alpha.4 → 2.0.0-alpha.6

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 (113) hide show
  1. package/lib/commonjs/controllers/ApiController.js +102 -84
  2. package/lib/commonjs/controllers/ApiController.js.map +1 -1
  3. package/lib/commonjs/controllers/BlockchainApiController.js +1 -1
  4. package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
  5. package/lib/commonjs/controllers/ConnectionsController.js +34 -21
  6. package/lib/commonjs/controllers/ConnectionsController.js.map +1 -1
  7. package/lib/commonjs/controllers/ModalController.js +4 -1
  8. package/lib/commonjs/controllers/ModalController.js.map +1 -1
  9. package/lib/commonjs/controllers/OnRampController.js +4 -1
  10. package/lib/commonjs/controllers/OnRampController.js.map +1 -1
  11. package/lib/commonjs/controllers/OptionsController.js +6 -3
  12. package/lib/commonjs/controllers/OptionsController.js.map +1 -1
  13. package/lib/commonjs/controllers/SendController.js +15 -1
  14. package/lib/commonjs/controllers/SendController.js.map +1 -1
  15. package/lib/commonjs/controllers/ThemeController.js +5 -0
  16. package/lib/commonjs/controllers/ThemeController.js.map +1 -1
  17. package/lib/commonjs/features/reown-authentication/ReownAuthentication.js +264 -0
  18. package/lib/commonjs/features/reown-authentication/ReownAuthentication.js.map +1 -0
  19. package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js +48 -0
  20. package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
  21. package/lib/commonjs/features/reown-authentication/index.js +28 -0
  22. package/lib/commonjs/features/reown-authentication/index.js.map +1 -0
  23. package/lib/commonjs/index.js +12 -5
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/utils/ConstantsUtil.js +1 -5
  26. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
  27. package/lib/commonjs/utils/CoreHelperUtil.js +13 -2
  28. package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
  29. package/lib/commonjs/utils/FetchUtil.js.map +1 -1
  30. package/lib/commonjs/utils/StorageUtil.js +27 -27
  31. package/lib/commonjs/utils/StorageUtil.js.map +1 -1
  32. package/lib/module/controllers/ApiController.js +102 -84
  33. package/lib/module/controllers/ApiController.js.map +1 -1
  34. package/lib/module/controllers/BlockchainApiController.js +1 -1
  35. package/lib/module/controllers/BlockchainApiController.js.map +1 -1
  36. package/lib/module/controllers/ConnectionsController.js +35 -22
  37. package/lib/module/controllers/ConnectionsController.js.map +1 -1
  38. package/lib/module/controllers/ModalController.js +4 -1
  39. package/lib/module/controllers/ModalController.js.map +1 -1
  40. package/lib/module/controllers/OnRampController.js +4 -1
  41. package/lib/module/controllers/OnRampController.js.map +1 -1
  42. package/lib/module/controllers/OptionsController.js +6 -3
  43. package/lib/module/controllers/OptionsController.js.map +1 -1
  44. package/lib/module/controllers/SendController.js +15 -1
  45. package/lib/module/controllers/SendController.js.map +1 -1
  46. package/lib/module/controllers/ThemeController.js +5 -0
  47. package/lib/module/controllers/ThemeController.js.map +1 -1
  48. package/lib/module/features/reown-authentication/ReownAuthentication.js +260 -0
  49. package/lib/module/features/reown-authentication/ReownAuthentication.js.map +1 -0
  50. package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js +43 -0
  51. package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
  52. package/lib/module/features/reown-authentication/index.js +5 -0
  53. package/lib/module/features/reown-authentication/index.js.map +1 -0
  54. package/lib/module/index.js +4 -1
  55. package/lib/module/index.js.map +1 -1
  56. package/lib/module/utils/ConstantsUtil.js +1 -5
  57. package/lib/module/utils/ConstantsUtil.js.map +1 -1
  58. package/lib/module/utils/CoreHelperUtil.js +13 -2
  59. package/lib/module/utils/CoreHelperUtil.js.map +1 -1
  60. package/lib/module/utils/FetchUtil.js.map +1 -1
  61. package/lib/module/utils/StorageUtil.js +28 -28
  62. package/lib/module/utils/StorageUtil.js.map +1 -1
  63. package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
  64. package/lib/typescript/controllers/ConnectionsController.d.ts +3 -2
  65. package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -1
  66. package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
  67. package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
  68. package/lib/typescript/controllers/OptionsController.d.ts +3 -3
  69. package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
  70. package/lib/typescript/controllers/RouterController.d.ts +1 -1
  71. package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
  72. package/lib/typescript/controllers/SendController.d.ts.map +1 -1
  73. package/lib/typescript/controllers/ThemeController.d.ts +2 -0
  74. package/lib/typescript/controllers/ThemeController.d.ts.map +1 -1
  75. package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts +174 -0
  76. package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts.map +1 -0
  77. package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts +16 -0
  78. package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts.map +1 -0
  79. package/lib/typescript/features/reown-authentication/index.d.ts +3 -0
  80. package/lib/typescript/features/reown-authentication/index.d.ts.map +1 -0
  81. package/lib/typescript/index.d.ts +2 -1
  82. package/lib/typescript/index.d.ts.map +1 -1
  83. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
  84. package/lib/typescript/utils/CoreHelperUtil.d.ts +2 -1
  85. package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
  86. package/lib/typescript/utils/FetchUtil.d.ts +1 -1
  87. package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
  88. package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
  89. package/package.json +6 -5
  90. package/src/controllers/ApiController.ts +93 -73
  91. package/src/controllers/BlockchainApiController.ts +1 -1
  92. package/src/controllers/ConnectionsController.ts +60 -20
  93. package/src/controllers/ModalController.ts +5 -1
  94. package/src/controllers/OnRampController.ts +5 -1
  95. package/src/controllers/OptionsController.ts +11 -6
  96. package/src/controllers/RouterController.ts +3 -3
  97. package/src/controllers/SendController.ts +22 -2
  98. package/src/controllers/ThemeController.ts +7 -0
  99. package/src/features/reown-authentication/ReownAuthentication.ts +470 -0
  100. package/src/features/reown-authentication/ReownAuthenticationMessenger.ts +80 -0
  101. package/src/features/reown-authentication/index.ts +2 -0
  102. package/src/index.ts +4 -1
  103. package/src/utils/ConstantsUtil.ts +1 -5
  104. package/src/utils/CoreHelperUtil.ts +20 -2
  105. package/src/utils/FetchUtil.ts +1 -1
  106. package/src/utils/StorageUtil.ts +37 -53
  107. package/lib/commonjs/utils/RouterUtil.js +0 -25
  108. package/lib/commonjs/utils/RouterUtil.js.map +0 -1
  109. package/lib/module/utils/RouterUtil.js +0 -21
  110. package/lib/module/utils/RouterUtil.js.map +0 -1
  111. package/lib/typescript/utils/RouterUtil.d.ts +0 -5
  112. package/lib/typescript/utils/RouterUtil.d.ts.map +0 -1
  113. package/src/utils/RouterUtil.ts +0 -21
@@ -13,6 +13,7 @@ import {
13
13
  type AccountType,
14
14
  type Connection,
15
15
  SolanaBaseAdapter,
16
+ BitcoinBaseAdapter,
16
17
  type Identity
17
18
  } from '@reown/appkit-common-react-native';
18
19
  import { StorageUtil } from '../utils/StorageUtil';
@@ -80,11 +81,13 @@ const updateConnection = (
80
81
  namespace: ChainNamespace,
81
82
  connection: Connection,
82
83
  updates: Partial<Connection>
83
- ) => {
84
- if (!connection) return;
84
+ ): Connection => {
85
85
  const newConnectionsMap = new Map(baseState.connections);
86
- newConnectionsMap.set(namespace, { ...connection, ...updates });
86
+ const newConnection = { ...connection, ...updates };
87
+ newConnectionsMap.set(namespace, newConnection);
87
88
  baseState.connections = newConnectionsMap;
89
+
90
+ return newConnection;
88
91
  };
89
92
 
90
93
  const getActiveIdentity = (connection: Connection): Identity | undefined => {
@@ -206,6 +209,10 @@ export const ConnectionsController = {
206
209
  state: derivedState,
207
210
 
208
211
  setActiveNamespace(namespace?: ChainNamespace) {
212
+ if (baseState.activeNamespace === namespace) {
213
+ return;
214
+ }
215
+
209
216
  baseState.activeNamespace = namespace;
210
217
  StorageUtil.setActiveNamespace(namespace);
211
218
  },
@@ -247,16 +254,19 @@ export const ConnectionsController = {
247
254
  baseState.connections = newConnectionsMap;
248
255
  },
249
256
 
250
- updateAccounts(namespace: ChainNamespace, accounts: CaipAddress[]) {
257
+ updateAccounts(namespace: ChainNamespace, accounts: CaipAddress[]): boolean {
251
258
  const connection = baseState.connections.get(namespace);
252
259
  if (!connection) {
253
- return;
260
+ return false;
254
261
  }
255
262
 
256
- const newConnectionsMap = new Map(baseState.connections);
257
- const updatedConnection = { ...connection, accounts };
258
- newConnectionsMap.set(namespace, updatedConnection);
259
- baseState.connections = newConnectionsMap;
263
+ if (connection.accounts.toString() === accounts.toString()) {
264
+ return false;
265
+ }
266
+
267
+ updateConnection(namespace, connection, { accounts });
268
+
269
+ return true;
260
270
  },
261
271
 
262
272
  updateBalance(namespace: ChainNamespace, address: CaipAddress, balance: Balance) {
@@ -270,8 +280,11 @@ export const ConnectionsController = {
270
280
  const existingBalances = connection.balances.get(address) || [];
271
281
  // Check if this token already exists by contract address or symbol
272
282
  const existingIndex = existingBalances.findIndex(existingBalance => {
273
- if (balance.address) {
274
- return existingBalance.address === balance.address;
283
+ if (balance.address && existingBalance.address) {
284
+ return (
285
+ CoreHelperUtil.getPlainAddress(existingBalance.address) ===
286
+ CoreHelperUtil.getPlainAddress(balance.address)
287
+ );
275
288
  }
276
289
 
277
290
  return existingBalance.symbol === balance.symbol;
@@ -327,10 +340,9 @@ export const ConnectionsController = {
327
340
  return;
328
341
  }
329
342
 
330
- baseState.connections.set(namespace, {
331
- ...connection,
332
- caipNetwork: networkId
333
- });
343
+ updateConnection(namespace, connection, { caipNetwork: networkId });
344
+
345
+ this.setActiveNamespace(namespace);
334
346
  },
335
347
 
336
348
  setNetworks(networks: AppKitNetwork[]) {
@@ -338,6 +350,11 @@ export const ConnectionsController = {
338
350
  },
339
351
 
340
352
  getConnectedNetworks() {
353
+ const connection = getActiveConnection(baseState);
354
+ if (!connection) {
355
+ return [];
356
+ }
357
+
341
358
  return baseState.networks.filter(
342
359
  network =>
343
360
  baseState.connections
@@ -346,14 +363,31 @@ export const ConnectionsController = {
346
363
  );
347
364
  },
348
365
 
366
+ getAvailableNetworks() {
367
+ const connection = getActiveConnection(baseState);
368
+
369
+ if (!connection) {
370
+ return baseState.networks;
371
+ }
372
+
373
+ const canAddEvmChain = connection.properties?.canAddEvmChain;
374
+
375
+ return baseState.networks.filter(
376
+ network =>
377
+ baseState.connections
378
+ .get(network.chainNamespace)
379
+ ?.accounts.some(account => account.startsWith(network.caipNetworkId)) ||
380
+ (canAddEvmChain && network.chainNamespace === 'eip155')
381
+ );
382
+ },
383
+
349
384
  setAccountType(namespace: ChainNamespace, type: AccountType) {
350
385
  const connection = baseState.connections.get(namespace);
351
386
  if (!connection) return;
352
387
 
353
- const newConnectionsMap = new Map(baseState.connections);
354
- const newConnection = { ...connection, type };
355
- newConnectionsMap.set(namespace, newConnection);
356
- baseState.connections = newConnectionsMap;
388
+ const newConnection = updateConnection(namespace, connection, { type });
389
+
390
+ return getActiveAddress(newConnection);
357
391
  },
358
392
 
359
393
  async disconnect(namespace: ChainNamespace, isInternal = true) {
@@ -419,7 +453,13 @@ export const ConnectionsController = {
419
453
 
420
454
  const adapter = baseState.connections.get(baseState.activeNamespace)?.adapter;
421
455
 
422
- if (adapter instanceof EVMAdapter && plainAddress && chainId) {
456
+ if (
457
+ (adapter instanceof EVMAdapter ||
458
+ adapter instanceof SolanaBaseAdapter ||
459
+ adapter instanceof BitcoinBaseAdapter) &&
460
+ plainAddress &&
461
+ chainId
462
+ ) {
423
463
  return adapter.signMessage(plainAddress, message, chainId);
424
464
  }
425
465
 
@@ -30,10 +30,14 @@ export const ModalController = {
30
30
  async open(options?: ModalControllerArguments['open']) {
31
31
  await ApiController.state.prefetchPromise;
32
32
  const isConnected = ConnectionsController.state.isConnected;
33
+ const isUniversalWallet = !!ConnectionsController.state.connection?.properties?.provider;
33
34
  if (options?.view) {
35
+ if (options.view === 'Account' && !isUniversalWallet) {
36
+ options.view = 'AccountDefault';
37
+ }
38
+
34
39
  RouterController.reset(options.view);
35
40
  } else if (isConnected) {
36
- const isUniversalWallet = !!ConnectionsController.state.connection?.properties?.provider;
37
41
  RouterController.reset(isUniversalWallet ? 'Account' : 'AccountDefault');
38
42
  } else {
39
43
  RouterController.reset('Connect');
@@ -124,7 +124,11 @@ export const OnRampController = {
124
124
  state.countriesDefaults?.find(d => d.countryCode === country.countryCode)
125
125
  ?.defaultCurrencyCode || 'USD';
126
126
 
127
- const currency = state.paymentCurrencies?.find(c => c.currencyCode === currencyCode);
127
+ let currency = state.paymentCurrencies?.find(c => c.currencyCode === currencyCode);
128
+
129
+ if (!currency) {
130
+ currency = state.paymentCurrencies?.find(c => c.currencyCode === 'USD');
131
+ }
128
132
 
129
133
  if (currency) {
130
134
  this.setPaymentCurrency(currency);
@@ -7,7 +7,8 @@ import type {
7
7
  Features,
8
8
  ProjectId,
9
9
  SdkType,
10
- SdkVersion
10
+ SdkVersion,
11
+ SIWXConfig
11
12
  } from '@reown/appkit-common-react-native';
12
13
 
13
14
  import { ConstantsUtil } from '../utils/ConstantsUtil';
@@ -29,7 +30,7 @@ export interface OptionsControllerState {
29
30
  sdkType: SdkType;
30
31
  sdkVersion: SdkVersion;
31
32
  metadata?: Metadata;
32
- isSiweEnabled?: boolean;
33
+ siwx?: SIWXConfig;
33
34
  isOnRampEnabled?: boolean;
34
35
  features?: Features;
35
36
  debug?: boolean;
@@ -87,10 +88,6 @@ export const OptionsController = {
87
88
  state.metadata = metadata;
88
89
  },
89
90
 
90
- setIsSiweEnabled(isSiweEnabled: OptionsControllerState['isSiweEnabled']) {
91
- state.isSiweEnabled = isSiweEnabled;
92
- },
93
-
94
91
  setFeatures(features: OptionsControllerState['features']) {
95
92
  state.features = { ...ConstantsUtil.DEFAULT_FEATURES, ...features };
96
93
  },
@@ -117,6 +114,14 @@ export const OptionsController = {
117
114
  state.requestedNetworks = requestedNetworks;
118
115
  },
119
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
+
120
125
  isClipboardAvailable() {
121
126
  return !!state.clipboardClient;
122
127
  },
@@ -15,9 +15,7 @@ export interface RouterControllerState {
15
15
  | 'Connect'
16
16
  | 'ConnectSocials'
17
17
  | 'ConnectingExternal'
18
- | 'ConnectingSiwe'
19
18
  | 'ConnectingSocial'
20
- | 'ConnectingWalletConnect'
21
19
  | 'GetWallet'
22
20
  | 'Networks'
23
21
  | 'OnRamp'
@@ -25,13 +23,15 @@ export interface RouterControllerState {
25
23
  | 'OnRampLoading'
26
24
  | 'OnRampSettings'
27
25
  | 'OnRampTransaction'
28
- | 'SwitchNetwork'
26
+ | 'SIWXSignMessage'
29
27
  | 'Swap'
30
28
  | 'SwapPreview'
29
+ | 'SwitchNetwork'
31
30
  | 'Transactions'
32
31
  | 'UnsupportedChain'
33
32
  | 'UpgradeEmailWallet'
34
33
  | 'WalletCompatibleNetworks'
34
+ | 'WalletConnect'
35
35
  | 'WalletReceive'
36
36
  | 'WalletSend'
37
37
  | 'WalletSendPreview'
@@ -8,6 +8,7 @@ import { EventsController } from './EventsController';
8
8
  import { RouterController } from './RouterController';
9
9
  import { ConnectionsController } from './ConnectionsController';
10
10
  import { SwapController } from './SwapController';
11
+ import { ConstantsUtil as CoreConstantsUtil } from '../utils/ConstantsUtil';
11
12
 
12
13
  // -- Types --------------------------------------------- //
13
14
  export interface TxParams {
@@ -118,13 +119,18 @@ export const SendController = {
118
119
  });
119
120
  RouterController.reset(isAuth ? 'Account' : 'AccountDefault');
120
121
  this.resetState();
121
- } catch (error) {
122
+ } catch (error: any) {
122
123
  EventsController.sendEvent({
123
124
  type: 'track',
124
125
  event: 'SEND_ERROR',
125
126
  properties: eventProperties
126
127
  });
127
- SnackController.showError('Something went wrong');
128
+
129
+ if (error?.message && error?.message.includes('user rejected')) {
130
+ SnackController.showError('Transaction cancelled');
131
+ } else {
132
+ SnackController.showError('Something went wrong');
133
+ }
128
134
  } finally {
129
135
  this.state.loading = false;
130
136
  }
@@ -222,7 +228,21 @@ export const SendController = {
222
228
  throw new Error('Invalid address');
223
229
  }
224
230
 
231
+ let tokenMint: string | undefined;
232
+
233
+ if (
234
+ SendController.state.token &&
235
+ SendController.state.token.address !== CoreConstantsUtil.NATIVE_TOKEN_ADDRESS.solana
236
+ ) {
237
+ if (CoreHelperUtil.isCaipAddress(SendController.state.token.address)) {
238
+ tokenMint = CoreHelperUtil.getPlainAddress(SendController.state.token.address);
239
+ } else {
240
+ tokenMint = SendController.state.token.address;
241
+ }
242
+ }
243
+
225
244
  await ConnectionsController.sendTransaction({
245
+ tokenMint,
226
246
  fromAddress: plainAddress,
227
247
  toAddress: this.state.receiverAddress,
228
248
  amount: this.state.sendTokenAmount,
@@ -5,12 +5,14 @@ import type { ThemeMode, ThemeVariables } from '@reown/appkit-common-react-nativ
5
5
  // -- Types --------------------------------------------- //
6
6
  export interface ThemeControllerState {
7
7
  themeMode?: ThemeMode;
8
+ defaultThemeMode?: ThemeMode;
8
9
  themeVariables?: ThemeVariables;
9
10
  }
10
11
 
11
12
  // -- State --------------------------------------------- //
12
13
  const state = proxy<ThemeControllerState>({
13
14
  themeMode: undefined,
15
+ defaultThemeMode: undefined,
14
16
  themeVariables: {}
15
17
  });
16
18
 
@@ -30,6 +32,11 @@ export const ThemeController = {
30
32
  }
31
33
  },
32
34
 
35
+ setDefaultThemeMode(themeMode: ThemeControllerState['defaultThemeMode']) {
36
+ state.defaultThemeMode = themeMode;
37
+ this.setThemeMode(themeMode);
38
+ },
39
+
33
40
  setThemeVariables(themeVariables: ThemeControllerState['themeVariables']) {
34
41
  if (!themeVariables) {
35
42
  state.themeVariables = {};