Skip to content

Commit

Permalink
type filter
Browse files Browse the repository at this point in the history
  • Loading branch information
awojciak committed Oct 10, 2023
1 parent befb348 commit 89885a9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
21 changes: 9 additions & 12 deletions sdk/packages/selector-base/src/modal.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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

_anchor: HTMLElement
_networkData: NetworkData
_relay: string
_walletsList: IWalletListItem[]
_walletsList: IWalletListItem[] = []

_open = false

Expand All @@ -23,28 +24,24 @@ export class NightlyConnectSelectorModal {
stylesOverride?: string,
qrConfigOverride?: Partial<XMLOptions>
) {
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
}
}

Expand All @@ -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
})
}

Expand Down
15 changes: 6 additions & 9 deletions sdk/packages/selector-polkadot/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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() &&
Expand Down
8 changes: 6 additions & 2 deletions sdk/packages/selector-solana/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions sdk/packages/selector-sui/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 89885a9

Please sign in to comment.