@reown/appkit-ethers-react-native 0.0.0-fix-approved-networks-20250822000414 → 0.0.0-fix-ui-changes-20250828183750

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 (44) hide show
  1. package/lib/commonjs/adapter.js +81 -0
  2. package/lib/commonjs/adapter.js.map +1 -0
  3. package/lib/commonjs/helpers.js +33 -0
  4. package/lib/commonjs/helpers.js.map +1 -0
  5. package/lib/commonjs/index.js +3 -174
  6. package/lib/commonjs/index.js.map +1 -1
  7. package/lib/commonjs/package.json +1 -0
  8. package/lib/module/adapter.js +76 -0
  9. package/lib/module/adapter.js.map +1 -0
  10. package/lib/module/helpers.js +27 -0
  11. package/lib/module/helpers.js.map +1 -0
  12. package/lib/module/index.js +3 -132
  13. package/lib/module/index.js.map +1 -1
  14. package/lib/typescript/adapter.d.ts +11 -0
  15. package/lib/typescript/adapter.d.ts.map +1 -0
  16. package/lib/typescript/helpers.d.ts +3 -0
  17. package/lib/typescript/helpers.d.ts.map +1 -0
  18. package/lib/typescript/index.d.ts +2 -39
  19. package/lib/typescript/index.d.ts.map +1 -1
  20. package/package.json +7 -13
  21. package/src/adapter.ts +100 -0
  22. package/src/helpers.ts +25 -0
  23. package/src/index.tsx +2 -164
  24. package/lib/commonjs/client.js +0 -862
  25. package/lib/commonjs/client.js.map +0 -1
  26. package/lib/commonjs/utils/defaultConfig.js +0 -18
  27. package/lib/commonjs/utils/defaultConfig.js.map +0 -1
  28. package/lib/commonjs/utils/helpers.js +0 -27
  29. package/lib/commonjs/utils/helpers.js.map +0 -1
  30. package/lib/module/client.js +0 -854
  31. package/lib/module/client.js.map +0 -1
  32. package/lib/module/utils/defaultConfig.js +0 -12
  33. package/lib/module/utils/defaultConfig.js.map +0 -1
  34. package/lib/module/utils/helpers.js +0 -20
  35. package/lib/module/utils/helpers.js.map +0 -1
  36. package/lib/typescript/client.d.ts +0 -65
  37. package/lib/typescript/client.d.ts.map +0 -1
  38. package/lib/typescript/utils/defaultConfig.d.ts +0 -7
  39. package/lib/typescript/utils/defaultConfig.d.ts.map +0 -1
  40. package/lib/typescript/utils/helpers.d.ts +0 -10
  41. package/lib/typescript/utils/helpers.d.ts.map +0 -1
  42. package/src/client.ts +0 -1078
  43. package/src/utils/defaultConfig.ts +0 -19
  44. package/src/utils/helpers.ts +0 -27
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,2CAA2C,CAAC;AAE3F,OAAO,EACL,aAAa,EACb,YAAY,EACZ,aAAa,EACb,aAAa,EACb,MAAM,EACP,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAE5F,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAGtD,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,KAAK,WAAW,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAKjD,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,UASlD;AAGD,wBAAgB,SAAS;qBAKO,WAAW;;EAS1C;AAED,wBAAgB,cAAc;;;EAkB7B;AAED,wBAAgB,iBAAiB;;;EAUhC;AAED,wBAAgB,aAAa;;EAQ5B;AAED,wBAAgB,gBAAgB;;;;EAQ/B;AAED,wBAAgB,aAAa;;EAY5B;AAED,wBAAgB,cAAc;;EAM7B;AAED,wBAAgB,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,qBAAqB,KAAK,IAAI;;;EAmBnF;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,CAAC,QAAQ,EAAE,qBAAqB,KAAK,IAAI,QAapD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reown/appkit-ethers-react-native",
3
- "version": "0.0.0-fix-approved-networks-20250822000414",
3
+ "version": "0.0.0-fix-ui-changes-20250828183750",
4
4
  "main": "lib/commonjs/index.js",
5
5
  "types": "lib/typescript/index.d.ts",
6
6
  "module": "lib/module/index.js",
@@ -38,23 +38,17 @@
38
38
  "access": "public"
39
39
  },
40
40
  "dependencies": {
41
- "@reown/appkit-common-react-native": "0.0.0-fix-approved-networks-20250822000414",
42
- "@reown/appkit-scaffold-react-native": "0.0.0-fix-approved-networks-20250822000414",
43
- "@reown/appkit-scaffold-utils-react-native": "0.0.0-fix-approved-networks-20250822000414",
44
- "@reown/appkit-siwe-react-native": "0.0.0-fix-approved-networks-20250822000414",
41
+ "@reown/appkit-common-react-native": "0.0.0-fix-ui-changes-20250828183750",
42
+ "@reown/appkit-react-native": "0.0.0-fix-ui-changes-20250828183750",
43
+ "@reown/appkit-siwe-react-native": "0.0.0-fix-ui-changes-20250828183750",
45
44
  "@walletconnect/ethereum-provider": "2.21.5"
46
45
  },
47
46
  "peerDependencies": {
48
- "@react-native-async-storage/async-storage": ">=1.17.0",
49
47
  "@react-native-community/netinfo": "*",
50
- "@walletconnect/react-native-compat": ">=2.13.1",
51
- "ethers": ">=6.0.0",
52
- "react": ">=17",
53
- "react-native": ">=0.68.5",
48
+ "@walletconnect/react-native-compat": ">=2.16.1",
49
+ "react": ">=18",
50
+ "react-native": ">=0.72",
54
51
  "react-native-get-random-values": "*"
55
52
  },
56
- "devDependencies": {
57
- "ethers": "6.10.0"
58
- },
59
53
  "react-native": "src/index.tsx"
60
54
  }
package/src/adapter.ts ADDED
@@ -0,0 +1,100 @@
1
+ import {
2
+ EVMAdapter,
3
+ type AppKitNetwork,
4
+ type CaipAddress,
5
+ type ChainNamespace,
6
+ type GetBalanceParams,
7
+ type GetBalanceResponse,
8
+ NumberUtil
9
+ } from '@reown/appkit-common-react-native';
10
+ import { formatEther, getEthBalance } from './helpers';
11
+
12
+ export class EthersAdapter extends EVMAdapter {
13
+ private static supportedNamespace: ChainNamespace = 'eip155';
14
+
15
+ constructor() {
16
+ super({
17
+ supportedNamespace: EthersAdapter.supportedNamespace,
18
+ adapterType: 'ethers'
19
+ });
20
+ }
21
+
22
+ async getBalance(params: GetBalanceParams): Promise<GetBalanceResponse> {
23
+ const { network, address } = params;
24
+
25
+ if (!this.connector) throw new Error('No active connector');
26
+ if (!network) throw new Error('No network provided');
27
+
28
+ const balanceAddress =
29
+ address || this.getAccounts()?.find(account => account.includes(network.id.toString()));
30
+
31
+ const balance: GetBalanceResponse = {
32
+ amount: '0.00',
33
+ symbol: network.nativeCurrency.symbol || 'ETH'
34
+ };
35
+
36
+ if (!balanceAddress) return balance;
37
+
38
+ const account = balanceAddress.split(':')[2];
39
+ const rpcUrl = network.rpcUrls.default.http?.[0];
40
+ if (!rpcUrl || !account) return balance;
41
+
42
+ try {
43
+ const wei = await getEthBalance(rpcUrl, account);
44
+ balance.amount = formatEther(wei);
45
+
46
+ this.emit('balanceChanged', {
47
+ address: balanceAddress,
48
+ balance: {
49
+ amount: balance.amount,
50
+ symbol: balance.symbol
51
+ }
52
+ });
53
+
54
+ return balance;
55
+ } catch {
56
+ return balance;
57
+ }
58
+ }
59
+
60
+ async switchNetwork(network: AppKitNetwork): Promise<void> {
61
+ if (!this.connector) throw new Error('No active connector');
62
+
63
+ const provider = this.connector.getProvider('eip155');
64
+ if (!provider) throw new Error('No active provider');
65
+
66
+ try {
67
+ await provider.request(
68
+ {
69
+ method: 'wallet_switchEthereumChain',
70
+ params: [{ chainId: NumberUtil.convertNumericToHexString(network.id) }]
71
+ },
72
+ `${EthersAdapter.supportedNamespace}:${network.id}`
73
+ );
74
+ } catch (switchError: any) {
75
+ const message = switchError?.message as string;
76
+ if (/(?<temp1>user rejected)/u.test(message?.toLowerCase())) {
77
+ throw new Error('Chain is not supported');
78
+ }
79
+
80
+ throw switchError;
81
+ }
82
+ }
83
+
84
+ getAccounts(): CaipAddress[] | undefined {
85
+ if (!this.connector) throw new Error('No active connector');
86
+ const namespaces = this.connector.getNamespaces();
87
+
88
+ return namespaces[this.getSupportedNamespace()]?.accounts;
89
+ }
90
+
91
+ disconnect(): Promise<void> {
92
+ if (!this.connector) throw new Error('EthersAdapter:disconnect - No active connector');
93
+
94
+ return this.connector.disconnect();
95
+ }
96
+
97
+ getSupportedNamespace(): ChainNamespace {
98
+ return EthersAdapter.supportedNamespace;
99
+ }
100
+ }
package/src/helpers.ts ADDED
@@ -0,0 +1,25 @@
1
+ // Helper to convert Wei (as string or bigint) to ETH
2
+ export const formatEther = (wei: bigint): string => {
3
+ return (Number(wei) / 1e18).toString();
4
+ };
5
+
6
+ // Raw JSON-RPC for balance lookup
7
+ export async function getEthBalance(rpcUrl: string, address: string): Promise<bigint> {
8
+ const body = {
9
+ jsonrpc: '2.0',
10
+ method: 'eth_getBalance',
11
+ params: [address, 'latest'],
12
+ id: 1
13
+ };
14
+
15
+ const response = await fetch(rpcUrl, {
16
+ method: 'POST',
17
+ headers: { 'Content-Type': 'application/json' },
18
+ body: JSON.stringify(body)
19
+ });
20
+
21
+ const json = await response.json();
22
+ if (json.error) throw new Error(json.error.message);
23
+
24
+ return BigInt(json.result); // result is hex string
25
+ }
package/src/index.tsx CHANGED
@@ -1,164 +1,2 @@
1
- import { useEffect, useState, useSyncExternalStore } from 'react';
2
- import { useSnapshot } from 'valtio';
3
- import { EthersStoreUtil, type Provider } from '@reown/appkit-scaffold-utils-react-native';
4
-
5
- export {
6
- AccountButton,
7
- AppKitButton,
8
- ConnectButton,
9
- NetworkButton,
10
- AppKit
11
- } from '@reown/appkit-scaffold-react-native';
12
- import type { EventName, EventsControllerState } from '@reown/appkit-scaffold-react-native';
13
- import { ConstantsUtil } from '@reown/appkit-common-react-native';
14
- export { defaultConfig } from './utils/defaultConfig';
15
-
16
- import { AppKit, type AppKitOptions } from './client';
17
-
18
- // -- Types -------------------------------------------------------------------
19
- export type { AppKitOptions } from './client';
20
-
21
- type OpenOptions = Parameters<AppKit['open']>[0];
22
-
23
- // -- Setup -------------------------------------------------------------------
24
- let modal: AppKit | undefined;
25
-
26
- export function createAppKit(options: AppKitOptions) {
27
- if (!modal) {
28
- modal = new AppKit({
29
- ...options,
30
- _sdkVersion: `react-native-ethers-${ConstantsUtil.VERSION}`
31
- });
32
- }
33
-
34
- return modal;
35
- }
36
-
37
- // -- Hooks -------------------------------------------------------------------
38
- export function useAppKit() {
39
- if (!modal) {
40
- throw new Error('Please call "createAppKit" before using "useAppKit" hook');
41
- }
42
-
43
- async function open(options?: OpenOptions) {
44
- await modal?.open(options);
45
- }
46
-
47
- async function close() {
48
- await modal?.close();
49
- }
50
-
51
- return { open, close };
52
- }
53
-
54
- export function useAppKitState() {
55
- if (!modal) {
56
- throw new Error('Please call "createAppKit" before using "useAppKitState" hook');
57
- }
58
-
59
- const [state, setState] = useState(modal.getState());
60
-
61
- useEffect(() => {
62
- const unsubscribe = modal?.subscribeState(newState => {
63
- if (newState) setState({ ...newState });
64
- });
65
-
66
- return () => {
67
- unsubscribe?.();
68
- };
69
- }, []);
70
-
71
- return state;
72
- }
73
-
74
- export function useAppKitProvider() {
75
- const { provider, providerType } = useSnapshot(EthersStoreUtil.state);
76
-
77
- const walletProvider = provider as Provider | undefined;
78
- const walletProviderType = providerType;
79
-
80
- return {
81
- walletProvider,
82
- walletProviderType
83
- };
84
- }
85
-
86
- export function useDisconnect() {
87
- async function disconnect() {
88
- await modal?.disconnect();
89
- }
90
-
91
- return {
92
- disconnect
93
- };
94
- }
95
-
96
- export function useAppKitAccount() {
97
- const { address, isConnected, chainId } = useSnapshot(EthersStoreUtil.state);
98
-
99
- return {
100
- address,
101
- isConnected,
102
- chainId
103
- };
104
- }
105
-
106
- export function useWalletInfo() {
107
- if (!modal) {
108
- throw new Error('Please call "createAppKit" before using "useWalletInfo" hook');
109
- }
110
-
111
- const walletInfo = useSyncExternalStore(
112
- modal.subscribeWalletInfo,
113
- modal.getWalletInfo,
114
- modal.getWalletInfo
115
- );
116
-
117
- return { walletInfo };
118
- }
119
-
120
- export function useAppKitError() {
121
- const { error } = useSnapshot(EthersStoreUtil.state);
122
-
123
- return {
124
- error
125
- };
126
- }
127
-
128
- export function useAppKitEvents(callback?: (newEvent: EventsControllerState) => void) {
129
- if (!modal) {
130
- throw new Error('Please call "createAppKit" before using "useAppKitEvents" hook');
131
- }
132
-
133
- const [event, setEvents] = useState(modal.getEvent());
134
-
135
- useEffect(() => {
136
- const unsubscribe = modal?.subscribeEvents(newEvent => {
137
- setEvents({ ...newEvent });
138
- callback?.(newEvent);
139
- });
140
-
141
- return () => {
142
- unsubscribe?.();
143
- };
144
- }, [callback]);
145
-
146
- return event;
147
- }
148
-
149
- export function useAppKitEventSubscription(
150
- event: EventName,
151
- callback: (newEvent: EventsControllerState) => void
152
- ) {
153
- if (!modal) {
154
- throw new Error('Please call "createAppKit" before using "useAppKitEventSubscription" hook');
155
- }
156
-
157
- useEffect(() => {
158
- const unsubscribe = modal?.subscribeEvent(event, callback);
159
-
160
- return () => {
161
- unsubscribe?.();
162
- };
163
- }, [callback, event]);
164
- }
1
+ import { EthersAdapter } from './adapter';
2
+ export { EthersAdapter };