File tree Expand file tree Collapse file tree 4 files changed +34
-2
lines changed
dapp-kit-react/src/DAppKitProvider Expand file tree Collapse file tree 4 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,7 @@ export const DAppKitProvider = ({
151151 connectionCertificate : connectionCertificateData ,
152152 allowedWallets,
153153 v2Api,
154+ alwaysShowConnect,
154155} : DAppKitProviderOptions ) : React . ReactElement | null => {
155156 const [ dAppKit , setDAppKit ] = useState < DAppKit | null > ( null ) ;
156157 useEffect ( ( ) => {
@@ -169,6 +170,7 @@ export const DAppKitProvider = ({
169170 connectionCertificate : connectionCertificateData ,
170171 allowedWallets,
171172 v2Api,
173+ alwaysShowConnect,
172174 } ) ;
173175 setDAppKit ( kit ) ;
174176 } , [
@@ -186,6 +188,7 @@ export const DAppKitProvider = ({
186188 connectionCertificateData ,
187189 allowedWallets ,
188190 v2Api . enabled ,
191+ alwaysShowConnect ,
189192 ] ) ;
190193
191194 if ( ! dAppKit ) {
Original file line number Diff line number Diff line change @@ -66,6 +66,12 @@ export type DAppKitUIOptions = DAppKitOptions & {
6666 modalParent ?: HTMLElement ;
6767 onSourceClick ?: ( source ?: SourceInfo ) => void ;
6868 v2Api : DappKitUIV2ApiOptions ;
69+ /**
70+ * Always show the connect Modal, even if the user is connected.
71+ * **This feature should not be used unless you really know what you need it for**
72+ * @default false
73+ */
74+ alwaysShowConnect ?: boolean ;
6975} ;
7076
7177export const DAppKitUI = {
@@ -83,6 +89,8 @@ export const DAppKitUI = {
8389 options . v2Api . onConnectResponse = ( ) => Promise . resolve ( ) ;
8490 if ( options . v2Api . autoInitialize === undefined )
8591 options . v2Api . autoInitialize = true ;
92+ if ( options . alwaysShowConnect === undefined )
93+ options . alwaysShowConnect = false ;
8694 dappKitOptions = options as ParsedOptions ;
8795 dappKit = new DAppKit ( options ) ;
8896
Original file line number Diff line number Diff line change @@ -137,6 +137,10 @@ export class ConnectModal extends LitElement {
137137 return DAppKitUI . get ( ) . options . v2Api . enabled ?? false ;
138138 }
139139
140+ private get alwaysShowConnect ( ) : boolean {
141+ return DAppKitUI . configuration ?. alwaysShowConnect ?? false ;
142+ }
143+
140144 @property ( { type : Function } )
141145 onSourceClick = ( source ?: SourceInfo ) : void => {
142146 if ( ! source ) return ;
@@ -169,7 +173,15 @@ export class ConnectModal extends LitElement {
169173 result ,
170174 ) ;
171175 } )
172- . then ( ( ) => this . requestUpdate ( ) )
176+ . then ( ( ) => {
177+ if ( this . alwaysShowConnect ) {
178+ this . setWaitingForTheSignature ( false ) ;
179+ this . requestForConnectionCertificate = false ;
180+ DAppKitUI . modal . close ( ) ;
181+ }
182+
183+ this . requestUpdate ( ) ;
184+ } )
173185 . catch ( ( err ) : void => {
174186 DAppKitLogger . error (
175187 'Connection Attempt' ,
@@ -184,6 +196,11 @@ export class ConnectModal extends LitElement {
184196 this . wallet
185197 . connect ( )
186198 . then ( ( ) => {
199+ if ( this . alwaysShowConnect ) {
200+ this . setWaitingForTheSignature ( false ) ;
201+ this . requestForConnectionCertificate = false ;
202+ DAppKitUI . modal . close ( ) ;
203+ }
187204 this . requestUpdate ( ) ;
188205 } )
189206 . catch ( ( err ) : void => {
Original file line number Diff line number Diff line change @@ -72,6 +72,10 @@ export class Modal extends LitElement {
7272 ) ;
7373 }
7474
75+ private get alwaysShowConnect ( ) : boolean {
76+ return DAppKitUI . configuration ?. alwaysShowConnect ?? false ;
77+ }
78+
7579 @property ( )
7680 address = DAppKitUI . wallet . state . address ?? '' ;
7781
@@ -112,7 +116,7 @@ export class Modal extends LitElement {
112116
113117 return html `
114118 < div >
115- ${ this . address
119+ ${ this . address && ! this . alwaysShowConnect
116120 ? html ` < vdk-address-modal
117121 .mode =${ this . mode }
118122 .i18n =${ this . i18n }
You can’t perform that action at this time.
0 commit comments