From 89885a9d2d96a46e219030c92e021da4c3d2b829 Mon Sep 17 00:00:00 2001 From: Adrian Date: Tue, 10 Oct 2023 22:13:38 +0200 Subject: [PATCH] type filter --- sdk/packages/selector-base/src/modal.ts | 21 ++++++++----------- sdk/packages/selector-polkadot/src/adapter.ts | 15 ++++++------- sdk/packages/selector-solana/src/adapter.ts | 8 +++++-- sdk/packages/selector-sui/src/adapter.ts | 8 +++++-- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/sdk/packages/selector-base/src/modal.ts b/sdk/packages/selector-base/src/modal.ts index c94591df..36d3f3c3 100644 --- a/sdk/packages/selector-base/src/modal.ts +++ b/sdk/packages/selector-base/src/modal.ts @@ -1,5 +1,6 @@ import { type XMLOptions, type NightlySelector } from '@nightlylabs/wallet-selector-modal' import { type IWalletListItem, type NetworkData } from './types' +import { isMobileBrowser } from './utils' export class NightlyConnectSelectorModal { _modal: NightlySelector | undefined @@ -7,7 +8,7 @@ export class NightlyConnectSelectorModal { _anchor: HTMLElement _networkData: NetworkData _relay: string - _walletsList: IWalletListItem[] + _walletsList: IWalletListItem[] = [] _open = false @@ -23,28 +24,24 @@ export class NightlyConnectSelectorModal { stylesOverride?: string, qrConfigOverride?: Partial ) { - this._walletsList = walletsList + this.walletsList = walletsList this._relay = relay this._networkData = networkData this._anchor = anchorRef ?? document.body this.createSelectorElement(variablesOverride, stylesOverride, qrConfigOverride) } - // if (isMobileBrowser()) { - // this._modal._walletsList = this.walletsList.filter( - // (w) => w.walletType !== 'extension' - // ) - // } else { - // this._modal._walletsList = this.walletsList.filter((w) => w.walletType !== 'mobile') - // } get walletsList() { return this._walletsList } set walletsList(list: IWalletListItem[]) { - this._walletsList = list + const filtered = list.filter((w) => + isMobileBrowser() ? w.walletType !== 'extension' : w.walletType !== 'mobile' + ) + this._walletsList = filtered if (this._modal) { - this._modal.selectorItems = list + this._modal.selectorItems = filtered } } @@ -60,7 +57,7 @@ export class NightlyConnectSelectorModal { this._modal.relay = this._relay this._modal.chainIcon = this._networkData.icon this._modal.chainName = this._networkData.name - this._modal.selectorItems = this._walletsList + this._modal.selectorItems = this.walletsList }) } diff --git a/sdk/packages/selector-polkadot/src/adapter.ts b/sdk/packages/selector-polkadot/src/adapter.ts index 7328ed1d..ba41f715 100644 --- a/sdk/packages/selector-polkadot/src/adapter.ts +++ b/sdk/packages/selector-polkadot/src/adapter.ts @@ -121,7 +121,9 @@ export class NightlyConnectAdapter implements Injected { try { return await Promise.all([ AppPolkadot.build(appInitData), - AppPolkadot.getWalletsMetadata(`${appInitData.url}/get_wallets_metadata`) + AppPolkadot.getWalletsMetadata( + `${appInitData.url ?? 'https://nc2.nightly.app'}/get_wallets_metadata` + ) .then((list) => list.map((wallet) => ({ name: wallet.name, @@ -137,7 +139,9 @@ export class NightlyConnectAdapter implements Injected { clearSessionIdForNetwork(appInitData.network) return await Promise.all([ AppPolkadot.build(appInitData), - AppPolkadot.getWalletsMetadata(`${appInitData.url}/get_wallets_metadata`) + AppPolkadot.getWalletsMetadata( + `${appInitData.url ?? 'https://nc2.nightly.app'}/get_wallets_metadata` + ) .then((list) => list.map((wallet) => ({ name: wallet.name, @@ -548,13 +552,6 @@ export class NightlyConnectAdapter implements Injected { reject(error) } } - // if (isMobileBrowser()) { - // this._modal._walletsList = this.walletsList.filter( - // (w) => w.walletType !== 'extension' - // ) - // } else { - // this._modal._walletsList = this.walletsList.filter((w) => w.walletType !== 'mobile') - // } this._modal.openModal(this._app.sessionId, (walletName) => { if ( isMobileBrowser() && diff --git a/sdk/packages/selector-solana/src/adapter.ts b/sdk/packages/selector-solana/src/adapter.ts index ac903834..25baabac 100644 --- a/sdk/packages/selector-solana/src/adapter.ts +++ b/sdk/packages/selector-solana/src/adapter.ts @@ -115,7 +115,9 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { try { return await Promise.all([ AppSolana.build(appInitData), - AppSolana.getWalletsMetadata(`${appInitData.url}/get_wallets_metadata`) + AppSolana.getWalletsMetadata( + `${appInitData.url ?? 'https://nc2.nightly.app'}/get_wallets_metadata` + ) .then((list) => list.map((wallet) => ({ name: wallet.name, @@ -131,7 +133,9 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { clearSessionIdForNetwork(SOLANA_NETWORK) return await Promise.all([ AppSolana.build(appInitData), - AppSolana.getWalletsMetadata(`${appInitData.url}/get_wallets_metadata`) + AppSolana.getWalletsMetadata( + `${appInitData.url ?? 'https://nc2.nightly.app'}/get_wallets_metadata` + ) .then((list) => list.map((wallet) => ({ name: wallet.name, diff --git a/sdk/packages/selector-sui/src/adapter.ts b/sdk/packages/selector-sui/src/adapter.ts index bc43c758..9a7918d9 100644 --- a/sdk/packages/selector-sui/src/adapter.ts +++ b/sdk/packages/selector-sui/src/adapter.ts @@ -97,7 +97,9 @@ export class NightlyConnectSuiAdapter { try { return await Promise.all([ AppSui.build(appInitData), - AppSui.getWalletsMetadata(`${appInitData.url}/get_wallets_metadata`) + AppSui.getWalletsMetadata( + `${appInitData.url ?? 'https://nc2.nightly.app'}/get_wallets_metadata` + ) .then((list) => list.map((wallet) => ({ name: wallet.name, @@ -113,7 +115,9 @@ export class NightlyConnectSuiAdapter { clearSessionIdForNetwork(SUI_NETWORK) return await Promise.all([ AppSui.build(appInitData), - AppSui.getWalletsMetadata(`${appInitData.url}/get_wallets_metadata`) + AppSui.getWalletsMetadata( + `${appInitData.url ?? 'https://nc2.nightly.app'}/get_wallets_metadata` + ) .then((list) => list.map((wallet) => ({ name: wallet.name,