File tree Expand file tree Collapse file tree 7 files changed +129
-2
lines changed Expand file tree Collapse file tree 7 files changed +129
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @reown/appkit-scaffold-react-native ' : patch
3
+ ' @reown/appkit-ethers5-react-native ' : patch
4
+ ' @reown/appkit-ethers-react-native ' : patch
5
+ ' @reown/appkit-wagmi-react-native ' : patch
6
+ ' @reown/appkit-core-react-native ' : patch
7
+ ' @reown/appkit-auth-ethers-react-native ' : patch
8
+ ' @reown/appkit-auth-wagmi-react-native ' : patch
9
+ ' @reown/appkit-coinbase-ethers-react-native ' : patch
10
+ ' @reown/appkit-coinbase-wagmi-react-native ' : patch
11
+ ' @reown/appkit-common-react-native ' : patch
12
+ ' @reown/appkit-scaffold-utils-react-native ' : patch
13
+ ' @reown/appkit-siwe-react-native ' : patch
14
+ ' @reown/appkit-ui-react-native ' : patch
15
+ ' @reown/appkit-wallet-react-native ' : patch
16
+ ---
17
+
18
+ chore: added event subscription hook
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { ApiController } from './ApiController';
3
3
import { OptionsController } from './OptionsController' ;
4
4
import { CoreHelperUtil } from '../utils/CoreHelperUtil' ;
5
5
import { FetchUtil } from '../utils/FetchUtil' ;
6
- import type { Event } from '../utils/TypeUtil' ;
6
+ import type { Event , EventName } from '../utils/TypeUtil' ;
7
7
8
8
// -- Helpers ------------------------------------------- //
9
9
const baseUrl = CoreHelperUtil . getAnalyticsUrl ( ) ;
@@ -33,6 +33,14 @@ export const EventsController = {
33
33
return sub ( state , ( ) => callback ( state ) ) ;
34
34
} ,
35
35
36
+ subscribeEvent ( event : EventName , callback : ( newEvent : EventsControllerState ) => void ) {
37
+ return sub ( state , ( ) => {
38
+ if ( state . data . event === event ) {
39
+ callback ( state ) ;
40
+ }
41
+ } ) ;
42
+ } ,
43
+
36
44
async _sendAnalyticsEvent ( data : EventsControllerState [ 'data' ] , timestamp : number ) {
37
45
if ( excluded . includes ( data . event ) ) {
38
46
return ;
Original file line number Diff line number Diff line change @@ -343,6 +343,51 @@ export type CustomWallet = Pick<
343
343
> ;
344
344
345
345
// -- EventsController Types ----------------------------------------------------
346
+ export type EventName =
347
+ | 'MODAL_LOADED'
348
+ | 'MODAL_OPEN'
349
+ | 'MODAL_CLOSE'
350
+ | 'CLICK_ALL_WALLETS'
351
+ | 'CLICK_NETWORKS'
352
+ | 'SWITCH_NETWORK'
353
+ | 'SELECT_WALLET'
354
+ | 'CONNECT_SUCCESS'
355
+ | 'CONNECT_ERROR'
356
+ | 'DISCONNECT_SUCCESS'
357
+ | 'DISCONNECT_ERROR'
358
+ | 'CLICK_WALLET_HELP'
359
+ | 'CLICK_NETWORK_HELP'
360
+ | 'CLICK_GET_WALLET'
361
+ | 'EMAIL_LOGIN_SELECTED'
362
+ | 'EMAIL_SUBMITTED'
363
+ | 'DEVICE_REGISTERED_FOR_EMAIL'
364
+ | 'EMAIL_VERIFICATION_CODE_SENT'
365
+ | 'EMAIL_VERIFICATION_CODE_PASS'
366
+ | 'EMAIL_VERIFICATION_CODE_FAIL'
367
+ | 'EMAIL_EDIT'
368
+ | 'EMAIL_EDIT_COMPLETE'
369
+ | 'EMAIL_UPGRADE_FROM_MODAL'
370
+ | 'CLICK_SIGN_SIWE_MESSAGE'
371
+ | 'CLICK_CANCEL_SIWE'
372
+ | 'SIWE_AUTH_SUCCESS'
373
+ | 'SIWE_AUTH_ERROR'
374
+ | 'CLICK_TRANSACTIONS'
375
+ | 'ERROR_FETCH_TRANSACTIONS'
376
+ | 'LOAD_MORE_TRANSACTIONS'
377
+ | 'OPEN_SEND'
378
+ | 'OPEN_SWAP'
379
+ | 'INITIATE_SWAP'
380
+ | 'SWAP_SUCCESS'
381
+ | 'SWAP_ERROR'
382
+ | 'SEND_INITIATED'
383
+ | 'SEND_SUCCESS'
384
+ | 'SEND_ERROR'
385
+ | 'SOCIAL_LOGIN_STARTED'
386
+ | 'SOCIAL_LOGIN_SUCCESS'
387
+ | 'SOCIAL_LOGIN_REQUEST_USER_DATA'
388
+ | 'SOCIAL_LOGIN_CANCELED'
389
+ | 'SOCIAL_LOGIN_ERROR'
390
+ | 'SET_PREFERRED_ACCOUNT_TYPE' ;
346
391
347
392
export type Event =
348
393
| {
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ export {
13
13
NetworkButton ,
14
14
AppKit
15
15
} from '@reown/appkit-scaffold-react-native' ;
16
+ import type { EventName } from '@reown/appkit-scaffold-react-native' ;
16
17
17
18
export { defaultConfig } from './utils/defaultConfig' ;
18
19
@@ -148,3 +149,19 @@ export function useAppKitEvents() {
148
149
149
150
return event ;
150
151
}
152
+
153
+ export function useAppKitEventSubscription ( event : EventName , callback : ( ) => void ) {
154
+ if ( ! modal ) {
155
+ throw new Error ( 'Please call "createAppKit" before using "useAppKitEventSubscription" hook' ) ;
156
+ }
157
+
158
+ useEffect ( ( ) => {
159
+ const unsubscribe = modal ?. subscribeEvent ( event , callback ) ;
160
+
161
+ return ( ) => {
162
+ unsubscribe ?.( ) ;
163
+ } ;
164
+ } , [ callback , event ] ) ;
165
+
166
+ return event ;
167
+ }
Original file line number Diff line number Diff line change 6
6
NetworkButton ,
7
7
AppKit
8
8
} from '@reown/appkit-scaffold-react-native' ;
9
+ import type { EventName } from '@reown/appkit-scaffold-react-native' ;
9
10
import {
10
11
ConstantsUtil ,
11
12
EthersStoreUtil ,
@@ -145,3 +146,19 @@ export function useAppKitEvents() {
145
146
146
147
return event ;
147
148
}
149
+
150
+ export function useAppKitEventSubscription ( event : EventName , callback : ( ) => void ) {
151
+ if ( ! modal ) {
152
+ throw new Error ( 'Please call "createAppKit" before using "useAppKitEventSubscription" hook' ) ;
153
+ }
154
+
155
+ useEffect ( ( ) => {
156
+ const unsubscribe = modal ?. subscribeEvent ( event , callback ) ;
157
+
158
+ return ( ) => {
159
+ unsubscribe ?.( ) ;
160
+ } ;
161
+ } , [ callback , event ] ) ;
162
+
163
+ return event ;
164
+ }
Original file line number Diff line number Diff line change @@ -12,7 +12,8 @@ import type {
12
12
ThemeControllerState ,
13
13
Connector ,
14
14
ConnectedWalletInfo ,
15
- Features
15
+ Features ,
16
+ EventName
16
17
} from '@reown/appkit-core-react-native' ;
17
18
import { SIWEController , type SIWEControllerClient } from '@reown/appkit-siwe-react-native' ;
18
19
import {
@@ -145,6 +146,10 @@ export class AppKitScaffold {
145
146
return EventsController . subscribe ( callback ) ;
146
147
}
147
148
149
+ public subscribeEvent ( event : EventName , callback : ( newEvent : EventsControllerState ) => void ) {
150
+ return EventsController . subscribeEvent ( event , callback ) ;
151
+ }
152
+
148
153
public resolveReownName = async ( name : string ) => {
149
154
const wcNameAddress = await EnsController . resolveName ( name ) ;
150
155
const networkNameAddresses = wcNameAddress ?. addresses
Original file line number Diff line number Diff line change 6
6
NetworkButton ,
7
7
AppKit
8
8
} from '@reown/appkit-scaffold-react-native' ;
9
+ import type { EventName } from '@reown/appkit-scaffold-react-native' ;
9
10
import { ConstantsUtil } from '@reown/appkit-scaffold-utils-react-native' ;
10
11
export { defaultWagmiConfig } from './utils/defaultWagmiConfig' ;
11
12
import { useEffect , useState , useSyncExternalStore } from 'react' ;
@@ -101,3 +102,19 @@ export function useAppKitEvents() {
101
102
102
103
return event ;
103
104
}
105
+
106
+ export function useAppKitEventSubscription ( event : EventName , callback : ( ) => void ) {
107
+ if ( ! modal ) {
108
+ throw new Error ( 'Please call "createAppKit" before using "useAppKitEventSubscription" hook' ) ;
109
+ }
110
+
111
+ useEffect ( ( ) => {
112
+ const unsubscribe = modal ?. subscribeEvent ( event , callback ) ;
113
+
114
+ return ( ) => {
115
+ unsubscribe ?.( ) ;
116
+ } ;
117
+ } , [ callback , event ] ) ;
118
+
119
+ return event ;
120
+ }
You can’t perform that action at this time.
0 commit comments