From a64c6517b481a270bf0be61ffc3acb6363e9e29a Mon Sep 17 00:00:00 2001 From: awojciak Date: Mon, 14 Aug 2023 13:00:20 +0200 Subject: [PATCH] should be done, at least on polkadot --- sdk/apps/modal-example/src/routes/aleph.tsx | 2 +- sdk/packages/selector-polkadot/src/adapter.ts | 29 +++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/sdk/apps/modal-example/src/routes/aleph.tsx b/sdk/apps/modal-example/src/routes/aleph.tsx index b6019a94..aa506d34 100644 --- a/sdk/apps/modal-example/src/routes/aleph.tsx +++ b/sdk/apps/modal-example/src/routes/aleph.tsx @@ -24,7 +24,7 @@ export default function Polkadot() { }, network: 'AlephZero' }, - true, + true, // change this to false to test disabling eager connect document.getElementById('modalAnchor') ) diff --git a/sdk/packages/selector-polkadot/src/adapter.ts b/sdk/packages/selector-polkadot/src/adapter.ts index c5924bd1..777949d3 100644 --- a/sdk/packages/selector-polkadot/src/adapter.ts +++ b/sdk/packages/selector-polkadot/src/adapter.ts @@ -37,7 +37,7 @@ export class NightlyConnectAdapter implements Injected { private _modal: NightlyConnectSelectorModal | undefined private _appInitData: AppSelectorInitialize - private _eagerConnectForStandardWallets: boolean + private _useEagerConnect: boolean private _metadataWallets: MetadataWallet[] = [] private _walletsList: IPolkadotWalletListItem[] = [] @@ -46,11 +46,11 @@ export class NightlyConnectAdapter implements Injected { private _loading: boolean - constructor(appInitData: AppSelectorInitialize, eagerConnectForStandardWallets?: boolean) { + constructor(appInitData: AppSelectorInitialize, useEagerConnect?: boolean) { this._connecting = false this._connected = false this._appInitData = appInitData - this._eagerConnectForStandardWallets = !!eagerConnectForStandardWallets + this._useEagerConnect = !!useEagerConnect this._appSessionActive = false this._loading = false } @@ -108,10 +108,14 @@ export class NightlyConnectAdapter implements Injected { } public static build = async ( appInitData: AppSelectorInitialize, - eagerConnectForStandardWallets?: boolean, + useEagerConnect?: boolean, anchorRef?: HTMLElement | null ) => { - const adapter = new NightlyConnectAdapter(appInitData, eagerConnectForStandardWallets) + if (!useEagerConnect) { + clearSessionIdForNetwork(appInitData.network) + } + + const adapter = new NightlyConnectAdapter(appInitData, useEagerConnect) adapter.walletsList = getPolkadotWalletsList( [], @@ -151,10 +155,14 @@ export class NightlyConnectAdapter implements Injected { public static buildLazy = ( appInitData: AppSelectorInitialize, - eagerConnectForStandardWallets?: boolean, + useEagerConnect?: boolean, anchorRef?: HTMLElement | null ) => { - const adapter = new NightlyConnectAdapter(appInitData, eagerConnectForStandardWallets) + if (!useEagerConnect) { + clearSessionIdForNetwork(appInitData.network) + } + + const adapter = new NightlyConnectAdapter(appInitData, useEagerConnect) adapter.walletsList = getPolkadotWalletsList( [], @@ -196,6 +204,10 @@ export class NightlyConnectAdapter implements Injected { } // ensureLoaded = async () => {} canEagerConnect = async () => { + if (!this._useEagerConnect) { + return false + } + // utility for case if somebody wants to fire connect asap, but doesn't want to show modal if e. g. there was no user connected on the device yet if (this._loading) { for (let i = 0; i < 200; i++) { @@ -216,7 +228,6 @@ export class NightlyConnectAdapter implements Injected { } if ( - this._eagerConnectForStandardWallets && getRecentStandardWalletForNetwork(this.network) !== null && isStandardConnectedForNetwork(this.network) ) { @@ -388,7 +399,7 @@ export class NightlyConnectAdapter implements Injected { const recentName = getRecentStandardWalletForNetwork(this.network) if ( - this._eagerConnectForStandardWallets && + this._useEagerConnect && recentName !== null && isStandardConnectedForNetwork(this.network) ) {