File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed
Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -23,15 +23,18 @@ export type ConnectorData = {
2323}
2424
2525/** Connector events. */
26- export interface ConnectorEvents {
26+ export interface BaseConnectorEvents {
2727 /** Emitted when account or network changes. */
2828 change ( data : ConnectorData ) : void
2929 /** Emitted when connection is established. */
3030 connect ( data : ConnectorData ) : void
3131 /** Emitted when connection is lost. */
3232 disconnect ( ) : void
33+ }
34+
35+ interface ConnectorEvents extends BaseConnectorEvents {
3336 /** Emitted when `shouldEmit` is true, used for StarknetReactWrapper */
34- connectionStatus ( s : "init" | "success" | "fail" | "fallback" ) : void
37+ connectionStatus ? ( s : "init" | "success" | "fail" | "fallback" ) : void
3538}
3639
3740export type ConnectArgs = {
@@ -65,6 +68,10 @@ export abstract class Connector extends EventEmitter<ConnectorEvents> {
6568 abstract request < T extends RpcMessage [ "type" ] > (
6669 call : RequestFnCall < T > ,
6770 ) : Promise < RpcTypeToMessageMap [ T ] [ "result" ] >
71+ /** Handle starknet-react type compatibility */
72+ eventNames ( ) : ( keyof BaseConnectorEvents ) [ ] {
73+ return [ "change" , "connect" , "disconnect" ]
74+ }
6875}
6976
7077export abstract class StarknetkitConnector extends Connector {
Original file line number Diff line number Diff line change @@ -62,7 +62,13 @@ function StarknetReactWrapper({
6262
6363 useEffect ( ( ) => {
6464 if ( mainConnector && isCompound ) {
65- mainConnector . on ( "connectionStatus" , function ( newStatus ) {
65+ const onConnectionStatus = (
66+ cb : ( status : "init" | "success" | "fail" | "fallback" ) => void ,
67+ ) => {
68+ mainConnector ?. on ( "connectionStatus" , cb as any )
69+ }
70+
71+ onConnectionStatus ( function ( newStatus ) {
6672 if ( newStatus !== "fallback" ) {
6773 setStatus ( ( prevStatus ) => {
6874 if ( prevStatus === "none" && newStatus === "fail" ) {
@@ -97,7 +103,13 @@ function StarknetReactWrapper({
97103 resolve = res
98104 reject = rej
99105
100- mainConnector ?. on ( "connectionStatus" , async ( status ) => {
106+ const onConnectionStatus = (
107+ cb : ( status : "init" | "success" | "fail" | "fallback" ) => void ,
108+ ) => {
109+ mainConnector ?. on ( "connectionStatus" , cb as any )
110+ }
111+
112+ onConnectionStatus ( ( status ) => {
101113 if ( status === "fallback" ) {
102114 reject ( { message : ERROR_MAPPING [ "0001" ] } )
103115 }
You can’t perform that action at this time.
0 commit comments