Skip to content

Commit c93188e

Browse files
chore: typed event hook callback, added optional callback to useAppKitEvents
1 parent cdc1af3 commit c93188e

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

packages/ethers/src/index.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export {
1313
NetworkButton,
1414
AppKit
1515
} from '@reown/appkit-scaffold-react-native';
16-
import type { EventName } from '@reown/appkit-scaffold-react-native';
16+
import type { EventName, EventsControllerState } from '@reown/appkit-scaffold-react-native';
1717

1818
export { defaultConfig } from './utils/defaultConfig';
1919

@@ -130,7 +130,7 @@ export function useAppKitError() {
130130
};
131131
}
132132

133-
export function useAppKitEvents() {
133+
export function useAppKitEvents(callback?: (newEvent: EventsControllerState) => void) {
134134
if (!modal) {
135135
throw new Error('Please call "createAppKit" before using "useAppKitEvents" hook');
136136
}
@@ -140,17 +140,21 @@ export function useAppKitEvents() {
140140
useEffect(() => {
141141
const unsubscribe = modal?.subscribeEvents(newEvent => {
142142
setEvents({ ...newEvent });
143+
callback?.(newEvent);
143144
});
144145

145146
return () => {
146147
unsubscribe?.();
147148
};
148-
}, []);
149+
}, [callback]);
149150

150151
return event;
151152
}
152153

153-
export function useAppKitEventSubscription(event: EventName, callback: () => void) {
154+
export function useAppKitEventSubscription(
155+
event: EventName,
156+
callback: (newEvent: EventsControllerState) => void
157+
) {
154158
if (!modal) {
155159
throw new Error('Please call "createAppKit" before using "useAppKitEventSubscription" hook');
156160
}
@@ -162,6 +166,4 @@ export function useAppKitEventSubscription(event: EventName, callback: () => voi
162166
unsubscribe?.();
163167
};
164168
}, [callback, event]);
165-
166-
return event;
167169
}

packages/ethers5/src/index.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export {
66
NetworkButton,
77
AppKit
88
} from '@reown/appkit-scaffold-react-native';
9-
import type { EventName } from '@reown/appkit-scaffold-react-native';
9+
import type { EventName, EventsControllerState } from '@reown/appkit-scaffold-react-native';
1010
import {
1111
ConstantsUtil,
1212
EthersStoreUtil,
@@ -127,7 +127,7 @@ export function useAppKitError() {
127127
};
128128
}
129129

130-
export function useAppKitEvents() {
130+
export function useAppKitEvents(callback?: (newEvent: EventsControllerState) => void) {
131131
if (!modal) {
132132
throw new Error('Please call "createAppKit" before using "useAppKitEvents" hook');
133133
}
@@ -137,17 +137,21 @@ export function useAppKitEvents() {
137137
useEffect(() => {
138138
const unsubscribe = modal?.subscribeEvents(newEvent => {
139139
setEvents({ ...newEvent });
140+
callback?.(newEvent);
140141
});
141142

142143
return () => {
143144
unsubscribe?.();
144145
};
145-
}, []);
146+
}, [callback]);
146147

147148
return event;
148149
}
149150

150-
export function useAppKitEventSubscription(event: EventName, callback: () => void) {
151+
export function useAppKitEventSubscription(
152+
event: EventName,
153+
callback: (newEvent: EventsControllerState) => void
154+
) {
151155
if (!modal) {
152156
throw new Error('Please call "createAppKit" before using "useAppKitEventSubscription" hook');
153157
}
@@ -159,6 +163,4 @@ export function useAppKitEventSubscription(event: EventName, callback: () => voi
159163
unsubscribe?.();
160164
};
161165
}, [callback, event]);
162-
163-
return event;
164166
}

packages/wagmi/src/index.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export {
66
NetworkButton,
77
AppKit
88
} from '@reown/appkit-scaffold-react-native';
9-
import type { EventName } from '@reown/appkit-scaffold-react-native';
9+
import type { EventName, EventsControllerState } from '@reown/appkit-scaffold-react-native';
1010
import { ConstantsUtil } from '@reown/appkit-scaffold-utils-react-native';
1111
export { defaultWagmiConfig } from './utils/defaultWagmiConfig';
1212
import { useEffect, useState, useSyncExternalStore } from 'react';
@@ -83,7 +83,7 @@ export function useWalletInfo() {
8383
return { walletInfo };
8484
}
8585

86-
export function useAppKitEvents() {
86+
export function useAppKitEvents(callback?: (newEvent: EventsControllerState) => void) {
8787
if (!modal) {
8888
throw new Error('Please call "createAppKit" before using "useAppKitEvents" hook');
8989
}
@@ -93,17 +93,21 @@ export function useAppKitEvents() {
9393
useEffect(() => {
9494
const unsubscribe = modal?.subscribeEvents(newEvent => {
9595
setEvents({ ...newEvent });
96+
callback?.(newEvent);
9697
});
9798

9899
return () => {
99100
unsubscribe?.();
100101
};
101-
}, []);
102+
}, [callback]);
102103

103104
return event;
104105
}
105106

106-
export function useAppKitEventSubscription(event: EventName, callback: () => void) {
107+
export function useAppKitEventSubscription(
108+
event: EventName,
109+
callback: (newEvent: EventsControllerState) => void
110+
) {
107111
if (!modal) {
108112
throw new Error('Please call "createAppKit" before using "useAppKitEventSubscription" hook');
109113
}
@@ -115,6 +119,4 @@ export function useAppKitEventSubscription(event: EventName, callback: () => voi
115119
unsubscribe?.();
116120
};
117121
}, [callback, event]);
118-
119-
return event;
120122
}

0 commit comments

Comments
 (0)