File tree Expand file tree Collapse file tree 7 files changed +141
-8
lines changed Expand file tree Collapse file tree 7 files changed +141
-8
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 , EventsControllerState } from '@reown/appkit-scaffold-react-native' ;
16
17
17
18
export { defaultConfig } from './utils/defaultConfig' ;
18
19
@@ -129,7 +130,7 @@ export function useAppKitError() {
129
130
} ;
130
131
}
131
132
132
- export function useAppKitEvents ( ) {
133
+ export function useAppKitEvents ( callback ?: ( newEvent : EventsControllerState ) => void ) {
133
134
if ( ! modal ) {
134
135
throw new Error ( 'Please call "createAppKit" before using "useAppKitEvents" hook' ) ;
135
136
}
@@ -139,12 +140,30 @@ export function useAppKitEvents() {
139
140
useEffect ( ( ) => {
140
141
const unsubscribe = modal ?. subscribeEvents ( newEvent => {
141
142
setEvents ( { ...newEvent } ) ;
143
+ callback ?.( newEvent ) ;
142
144
} ) ;
143
145
144
146
return ( ) => {
145
147
unsubscribe ?.( ) ;
146
148
} ;
147
- } , [ ] ) ;
149
+ } , [ callback ] ) ;
148
150
149
151
return event ;
150
152
}
153
+
154
+ export function useAppKitEventSubscription (
155
+ event : EventName ,
156
+ callback : ( newEvent : EventsControllerState ) => void
157
+ ) {
158
+ if ( ! modal ) {
159
+ throw new Error ( 'Please call "createAppKit" before using "useAppKitEventSubscription" hook' ) ;
160
+ }
161
+
162
+ useEffect ( ( ) => {
163
+ const unsubscribe = modal ?. subscribeEvent ( event , callback ) ;
164
+
165
+ return ( ) => {
166
+ unsubscribe ?.( ) ;
167
+ } ;
168
+ } , [ callback , event ] ) ;
169
+ }
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 , EventsControllerState } from '@reown/appkit-scaffold-react-native' ;
9
10
import {
10
11
ConstantsUtil ,
11
12
EthersStoreUtil ,
@@ -126,7 +127,7 @@ export function useAppKitError() {
126
127
} ;
127
128
}
128
129
129
- export function useAppKitEvents ( ) {
130
+ export function useAppKitEvents ( callback ?: ( newEvent : EventsControllerState ) => void ) {
130
131
if ( ! modal ) {
131
132
throw new Error ( 'Please call "createAppKit" before using "useAppKitEvents" hook' ) ;
132
133
}
@@ -136,12 +137,30 @@ export function useAppKitEvents() {
136
137
useEffect ( ( ) => {
137
138
const unsubscribe = modal ?. subscribeEvents ( newEvent => {
138
139
setEvents ( { ...newEvent } ) ;
140
+ callback ?.( newEvent ) ;
139
141
} ) ;
140
142
141
143
return ( ) => {
142
144
unsubscribe ?.( ) ;
143
145
} ;
144
- } , [ ] ) ;
146
+ } , [ callback ] ) ;
145
147
146
148
return event ;
147
149
}
150
+
151
+ export function useAppKitEventSubscription (
152
+ event : EventName ,
153
+ callback : ( newEvent : EventsControllerState ) => void
154
+ ) {
155
+ if ( ! modal ) {
156
+ throw new Error ( 'Please call "createAppKit" before using "useAppKitEventSubscription" hook' ) ;
157
+ }
158
+
159
+ useEffect ( ( ) => {
160
+ const unsubscribe = modal ?. subscribeEvent ( event , callback ) ;
161
+
162
+ return ( ) => {
163
+ unsubscribe ?.( ) ;
164
+ } ;
165
+ } , [ callback , event ] ) ;
166
+ }
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 , EventsControllerState } 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' ;
@@ -82,7 +83,7 @@ export function useWalletInfo() {
82
83
return { walletInfo } ;
83
84
}
84
85
85
- export function useAppKitEvents ( ) {
86
+ export function useAppKitEvents ( callback ?: ( newEvent : EventsControllerState ) => void ) {
86
87
if ( ! modal ) {
87
88
throw new Error ( 'Please call "createAppKit" before using "useAppKitEvents" hook' ) ;
88
89
}
@@ -92,12 +93,30 @@ export function useAppKitEvents() {
92
93
useEffect ( ( ) => {
93
94
const unsubscribe = modal ?. subscribeEvents ( newEvent => {
94
95
setEvents ( { ...newEvent } ) ;
96
+ callback ?.( newEvent ) ;
95
97
} ) ;
96
98
97
99
return ( ) => {
98
100
unsubscribe ?.( ) ;
99
101
} ;
100
- } , [ ] ) ;
102
+ } , [ callback ] ) ;
101
103
102
104
return event ;
103
105
}
106
+
107
+ export function useAppKitEventSubscription (
108
+ event : EventName ,
109
+ callback : ( newEvent : EventsControllerState ) => void
110
+ ) {
111
+ if ( ! modal ) {
112
+ throw new Error ( 'Please call "createAppKit" before using "useAppKitEventSubscription" hook' ) ;
113
+ }
114
+
115
+ useEffect ( ( ) => {
116
+ const unsubscribe = modal ?. subscribeEvent ( event , callback ) ;
117
+
118
+ return ( ) => {
119
+ unsubscribe ?.( ) ;
120
+ } ;
121
+ } , [ callback , event ] ) ;
122
+ }
You can’t perform that action at this time.
0 commit comments