Skip to content

Commit

Permalink
Merge pull request #70 from nightly-labs/add-wallets-filtering
Browse files Browse the repository at this point in the history
Add wallets filtering
  • Loading branch information
awojciak authored Oct 11, 2023
2 parents 63c9166 + 89885a9 commit 195144a
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 39 deletions.
4 changes: 4 additions & 0 deletions sdk/apps/base/src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@ describe('Base App tests', () => {
const walletsMetadata = await BaseApp.getWalletsMetadata()
expect(walletsMetadata).toBeDefined()
assert(walletsMetadata.length > 0)

const filteredWalletsMetadata = await BaseApp.getWalletsMetadata(undefined, 'sui')
assert(filteredWalletsMetadata.length > 0)
assert(filteredWalletsMetadata.length < walletsMetadata.length)
})
})
7 changes: 5 additions & 2 deletions sdk/apps/base/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ export class BaseApp extends EventEmitter<BaseEvents> {
this.ws = ws
this.timeout = initializeData.timeout ?? 40000
}
public static getWalletsMetadata = async (url?: string): Promise<WalletMetadata[]> => {
return getWalletsMetadata(url)
public static getWalletsMetadata = async (
url?: string,
network?: string
): Promise<WalletMetadata[]> => {
return getWalletsMetadata(url, network)
}
public static build = async (baseInitialize: AppBaseInitialize): Promise<BaseApp> => {
return new Promise((resolve, reject) => {
Expand Down
15 changes: 11 additions & 4 deletions sdk/apps/base/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,25 @@ export const smartDelay = async (ms?: number) => {
}
}
}
export const getWalletsMetadata = async (url?: string): Promise<WalletMetadata[]> => {
export const getWalletsMetadata = async (
url?: string,
network?: string
): Promise<WalletMetadata[]> => {
const endpoint = url ?? RELAY_ENDPOINT + '/get_wallets_metadata'
const result = await (
const result = (await (
await fetch(endpoint, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
})
).json()
return result
).json()) as WalletMetadata[]
if (network) {
return result.filter((walletMetadata) => walletMetadata.chains.includes(network))
} else {
return result
}
}

let _localStorage: ILocalStorage | null = null
Expand Down
2 changes: 1 addition & 1 deletion sdk/apps/polkadot/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class AppPolkadot extends EventEmitter<PolkadotAppEvents> implements Inje
}

public static getWalletsMetadata = async (url?: string): Promise<WalletMetadata[]> => {
return getWalletsMetadata(url)
return getWalletsMetadata(url, 'polkadot')
}

public static build = async (initData: AppPolkadotInitialize): Promise<AppPolkadot> => {
Expand Down
2 changes: 1 addition & 1 deletion sdk/apps/solana/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class AppSolana extends EventEmitter<SolanaAppEvents> {
return this.base.connectedPublicKeys.map((pk) => new PublicKey(pk))
}
public static getWalletsMetadata = async (url?: string): Promise<WalletMetadata[]> => {
return getWalletsMetadata(url)
return getWalletsMetadata(url, 'solana')
}
public static build = async (initData: AppSolanaInitialize): Promise<AppSolana> => {
const base = await BaseApp.build({ ...initData, network: SOLANA_NETWORK })
Expand Down
2 changes: 1 addition & 1 deletion sdk/apps/sui/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class AppSui extends EventEmitter<SuiAppEvents> {
return this.base.connectedPublicKeys
}
public static getWalletsMetadata = async (url?: string): Promise<WalletMetadata[]> => {
return getWalletsMetadata(url)
return getWalletsMetadata(url, 'sui')
}
public static build = async (initData: AppSuiInitialize): Promise<AppSui> => {
const base = await BaseApp.build({ ...initData, network: SUI_NETWORK })
Expand Down
2 changes: 1 addition & 1 deletion sdk/packages/selector-base/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default [
]
},
{
input: 'dist/types/index.d.ts',
input: 'dist/types/packages/selector-base/src/index.d.ts',
output: [{ file: 'dist/index.d.ts', format: 'esm' }],
plugins: [dts()]
}
Expand Down
3 changes: 2 additions & 1 deletion sdk/packages/selector-base/src/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const getWalletsList = (
icon: wallet.icon,
link: '',
deeplink: null,
recent: recentWalletName === wallet.name
recent: recentWalletName === wallet.name,
walletType: 'hybrid'
}),
detected: true,
standardWallet: wallet
Expand Down
14 changes: 9 additions & 5 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,7 +24,7 @@ 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
Expand All @@ -35,9 +36,12 @@ export class NightlyConnectSelectorModal {
}

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 @@ -53,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
2 changes: 2 additions & 0 deletions sdk/packages/selector-base/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type AppBaseInitialize } from '@nightlylabs/nightly-connect-base'
import { type Deeplink } from '@nightlylabs/nightly-connect-base/dist/types/bindings/Deeplink'
import { type Wallet } from '@wallet-standard/core'
import { type WalletType } from '../../../bindings/WalletType'

export interface Adapter {
connect: () => Promise<void>
Expand All @@ -12,6 +13,7 @@ export interface MetadataWallet {
icon: string
deeplink: Deeplink | null
link: string
walletType: WalletType
}

export interface IWalletListItem extends MetadataWallet {
Expand Down
25 changes: 17 additions & 8 deletions sdk/packages/selector-base/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
{
"compilerOptions": {
"lib": ["es2015", "DOM"],
"target": "esnext",
"module": "ESNext",
"strict": true,
"esModuleInterop": true,
"moduleDetection": "force",
"resolveJsonModule": true,
"allowJs": true,
"baseUrl": ".",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"noImplicitAny": false,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"allowSyntheticDefaultImports": true,
"isolatedModules": true,
"noFallthroughCasesInSwitch": true,
"declaration": true,
"declarationDir": "types",
"emitDeclarationOnly": true
}
"emitDeclarationOnly": true,
"outDir": "dist",
"rootDir": "../.."
},
"include": ["../../bindings/*", "src/*"]
}
14 changes: 10 additions & 4 deletions sdk/packages/selector-polkadot/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,16 @@ export class NightlyConnectAdapter implements Injected {
try {
return await Promise.all([
AppPolkadot.build(appInitData),
AppPolkadot.getWalletsMetadata('https://nc2.nightly.app/get_wallets_metadata')
AppPolkadot.getWalletsMetadata(
`${appInitData.url ?? 'https://nc2.nightly.app'}/get_wallets_metadata`
)
.then((list) =>
list.map((wallet) => ({
name: wallet.name,
icon: wallet.image.default,
deeplink: wallet.mobile,
link: wallet.homepage
link: wallet.homepage,
walletType: wallet.walletType
}))
)
.catch(() => [] as MetadataWallet[])
Expand All @@ -136,13 +139,16 @@ export class NightlyConnectAdapter implements Injected {
clearSessionIdForNetwork(appInitData.network)
return await Promise.all([
AppPolkadot.build(appInitData),
AppPolkadot.getWalletsMetadata('https://nc2.nightly.app/get_wallets_metadata')
AppPolkadot.getWalletsMetadata(
`${appInitData.url ?? 'https://nc2.nightly.app'}/get_wallets_metadata`
)
.then((list) =>
list.map((wallet) => ({
name: wallet.name,
icon: wallet.image.default,
deeplink: wallet.mobile,
link: wallet.homepage
link: wallet.homepage,
walletType: wallet.walletType
}))
)
.catch(() => [] as MetadataWallet[])
Expand Down
3 changes: 2 additions & 1 deletion sdk/packages/selector-polkadot/src/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export const getPolkadotWalletsList = (presetList: MetadataWallet[], recentWalle
icon: wallet.icon,
link: '',
deeplink: null,
recent: recentWalletName === wallet.name
recent: recentWalletName === wallet.name,
walletType: 'hybrid'
}),
detected: true,
injectedWallet: wallet
Expand Down
14 changes: 10 additions & 4 deletions sdk/packages/selector-solana/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,16 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter {
try {
return await Promise.all([
AppSolana.build(appInitData),
AppSolana.getWalletsMetadata('https://nc2.nightly.app/get_wallets_metadata')
AppSolana.getWalletsMetadata(
`${appInitData.url ?? 'https://nc2.nightly.app'}/get_wallets_metadata`
)
.then((list) =>
list.map((wallet) => ({
name: wallet.name,
icon: wallet.image.default,
deeplink: wallet.mobile,
link: wallet.homepage
link: wallet.homepage,
walletType: wallet.walletType
}))
)
.catch(() => [] as MetadataWallet[])
Expand All @@ -130,13 +133,16 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter {
clearSessionIdForNetwork(SOLANA_NETWORK)
return await Promise.all([
AppSolana.build(appInitData),
AppSolana.getWalletsMetadata('https://nc2.nightly.app/get_wallets_metadata')
AppSolana.getWalletsMetadata(
`${appInitData.url ?? 'https://nc2.nightly.app'}/get_wallets_metadata`
)
.then((list) =>
list.map((wallet) => ({
name: wallet.name,
icon: wallet.image.default,
deeplink: wallet.mobile,
link: wallet.homepage
link: wallet.homepage,
walletType: wallet.walletType
}))
)
.catch(() => [] as MetadataWallet[])
Expand Down
14 changes: 10 additions & 4 deletions sdk/packages/selector-sui/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,16 @@ export class NightlyConnectSuiAdapter {
try {
return await Promise.all([
AppSui.build(appInitData),
AppSui.getWalletsMetadata('https://nc2.nightly.app/get_wallets_metadata')
AppSui.getWalletsMetadata(
`${appInitData.url ?? 'https://nc2.nightly.app'}/get_wallets_metadata`
)
.then((list) =>
list.map((wallet) => ({
name: wallet.name,
icon: wallet.image.default,
deeplink: wallet.mobile,
link: wallet.homepage
link: wallet.homepage,
walletType: wallet.walletType
}))
)
.catch(() => [] as MetadataWallet[])
Expand All @@ -112,13 +115,16 @@ export class NightlyConnectSuiAdapter {
clearSessionIdForNetwork(SUI_NETWORK)
return await Promise.all([
AppSui.build(appInitData),
AppSui.getWalletsMetadata('https://nc2.nightly.app/get_wallets_metadata')
AppSui.getWalletsMetadata(
`${appInitData.url ?? 'https://nc2.nightly.app'}/get_wallets_metadata`
)
.then((list) =>
list.map((wallet) => ({
name: wallet.name,
icon: wallet.image.default,
deeplink: wallet.mobile,
link: wallet.homepage
link: wallet.homepage,
walletType: wallet.walletType
}))
)
.catch(() => [] as MetadataWallet[])
Expand Down
57 changes: 55 additions & 2 deletions server/src/wallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub static WALLETS_METADATA: Lazy<Vec<WalletMetadata>> = Lazy::new(|| {
"https://apps.apple.com/pl/app/nightly-multichain-wallet/id6444768157".to_string(),
),
]),
chains: vec![Network::new("solana"), Network::new("near"), Network::new("sui"), Network::new("aptos")],
chains: vec![Network::new("solana"), Network::new("near"), Network::new("sui"), Network::new("aptos"), Network::new("polkadot")],
desktop: None,
mobile: Some(Deeplink {
native: Some("nightly".to_string()),
Expand All @@ -71,11 +71,64 @@ pub static WALLETS_METADATA: Lazy<Vec<WalletMetadata>> = Lazy::new(|| {
(Network::new("solana"),"window.nightly.solana".to_string()),
(Network::new("sui"),"window.nightly.sui".to_string()),
(Network::new("aptos"),"window.nightly.aptos".to_string()),
(Network::new("near"),"window.nightly.near".to_string())
(Network::new("near"),"window.nightly.near".to_string()),
(Network::new("polkadot"),"window.nightly.polkadot".to_string()),
]),
last_updated_timestamp: 1686303253,
version: Version("0.0.1".to_string()),
wallet_type: WalletType::hybrid,
},
// Aleph Zero Signer
WalletMetadata {
slug: "aleph-zero-signer".to_string(),
name: "Aleph Zero Signer".to_string(),
description: "Aleph Zero Signer".to_string(),
homepage: "https://alephzero.org/signer".to_string(),
app: HashMap::from([
(
Platform::chrome,
"https://chrome.google.com/webstore/detail/aleph-zero-signer/opbinaebpmphpefcimknblieddamhmol".to_string(),
),
(
Platform::edge,
"https://chrome.google.com/webstore/detail/aleph-zero-signer/opbinaebpmphpefcimknblieddamhmol".to_string(),
),
(
Platform::browser,
"https://chrome.google.com/webstore/detail/aleph-zero-signer/opbinaebpmphpefcimknblieddamhmol".to_string(),
),
(
Platform::brave,
"https://chrome.google.com/webstore/detail/aleph-zero-signer/opbinaebpmphpefcimknblieddamhmol".to_string(),
),
(
Platform::opera,
"https://chrome.google.com/webstore/detail/aleph-zero-signer/opbinaebpmphpefcimknblieddamhmol".to_string(),
),
(
Platform::opera,
"https://chrome.google.com/webstore/detail/aleph-zero-signer/opbinaebpmphpefcimknblieddamhmol".to_string(),
),
(
Platform::firefox,
"https://addons.mozilla.org/en-GB/firefox/addon/aleph-zero-signer/".to_string(),
),
]),
chains: vec![Network::new("polkadot")],
desktop: None,
mobile: None,
image: Images {
default: format!("https://registry.nightly.app/wallets/aleph-zero-signer/default.png"),
sm: format!("https://registry.nightly.app/wallets/aleph-zero-signer/default.png"),
md: format!("https://registry.nightly.app/wallets/aleph-zero-signer/default.png"),
lg: format!("https://registry.nightly.app/wallets/aleph-zero-signer/default.png"),
},
inject_path: HashMap::from([
(Network::new("polkadot"),"window.injectedWeb3.aleph-zero-signer".to_string()),
]),
last_updated_timestamp: 1696942859,
version: Version("0.1.0".to_string()),
wallet_type: WalletType::extension,
},
];
});

0 comments on commit 195144a

Please sign in to comment.