Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: lazy loading modal solana selector #98

Merged
merged 29 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9395c69
add: lazy loading modal solana selector
LukassF Feb 21, 2024
5678d3c
add: fetch all wallets and change type
LukassF Feb 22, 2024
5bab9f5
fix: version
LukassF Feb 22, 2024
bb51fc0
add: solana change event listener and emitter
LukassF Feb 22, 2024
bba5a77
fix: listeners
LukassF Feb 22, 2024
f26cbb6
Merge branch 'main' into solana_selector_lazy
LukassF Feb 22, 2024
bd6a67e
fix; pull main
LukassF Feb 22, 2024
de1f563
fix: decoupling types
LukassF Feb 22, 2024
11fce53
fix: partial and moved getSolanaWalletsList method to dedicated file
LukassF Feb 23, 2024
e012fc4
fix: remove partial
LukassF Feb 23, 2024
ae9b42a
remove redundant imports
LukassF Feb 23, 2024
7cff49a
add: showing error in modal
LukassF Feb 23, 2024
cdd47df
add: polkadot event emitter
LukassF Feb 23, 2024
6f25b32
fix type on connect emit
NorbertBodziony Feb 23, 2024
dad6ed4
fix hooks on connect
NorbertBodziony Feb 23, 2024
492aeb3
fix: modal display error
LukassF Feb 26, 2024
d7ecc4c
fix: linter errors
LukassF Feb 26, 2024
01004bd
fix: hooks in solana selector
LukassF Feb 26, 2024
532d76c
Merge branch 'main' into solana_selector_lazy
LukassF Feb 26, 2024
3024c96
fix: reject rather than throw error
LukassF Feb 26, 2024
0790def
remove: console log
LukassF Feb 26, 2024
cf5764e
add: external modal for solana
LukassF Feb 26, 2024
3bb97c4
fix: added listener to the newly created app when disconnecting
LukassF Feb 27, 2024
44295fb
fix: update wallets list on disconnect
LukassF Feb 27, 2024
262958d
add try catch and remove filter on modal
NorbertBodziony Feb 27, 2024
d4c6d5b
fix solana
NorbertBodziony Feb 27, 2024
8953340
add try catch blocks
LukassF Feb 27, 2024
299798c
fix: polkadot detection
LukassF Feb 27, 2024
64474f3
fix: polkadot detection v2
LukassF Feb 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/apps/modal-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@mysten/sui.js": "^0.42.0",
"@mysten/wallet-adapter-wallet-standard": "^0.8.0",
"@nightlylabs/wallet-selector-solana": "0.2.7",
"@nightlylabs/wallet-selector-solana": "0.3.0",
"@nightlylabs/nightly-connect-solana": "0.0.29",
"@nightlylabs/nightly-connect-sui": "0.0.29",
"@nightlylabs/wallet-selector-sui": "0.2.7",
Expand All @@ -38,4 +38,4 @@
"engines": {
"node": ">=16.8"
}
}
}
1 change: 0 additions & 1 deletion sdk/apps/modal-example/src/routes/aleph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export default function Polkadot() {
)

adapter.canEagerConnect().then((canEagerConnect: boolean) => {
console.log('canEagerConnect', canEagerConnect)
setEager(canEagerConnect)
})
setAdapter(adapter)
Expand Down
2 changes: 1 addition & 1 deletion sdk/apps/modal-example/src/routes/alephCustom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function Polkadot() {
},
network: 'AlephZero'
},
true, // change this to false to test disabling eager connect
{}, // change this to false to test disabling eager connect
document.getElementById('modalAnchor'),
{
variablesOverride: {
Expand Down
4 changes: 2 additions & 2 deletions sdk/apps/modal-example/src/routes/alephInitOnConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function Polkadot() {
const provider = new WsProvider('wss://ws.test.azero.dev/')

onMount(async () => {
const adapter = NightlyConnectAdapter.buildWithInitOnConnect(
const adapter = NightlyConnectAdapter.buildLazy(
{
appMetadata: {
name: 'NC TEST AlephZero',
Expand All @@ -23,7 +23,7 @@ export default function Polkadot() {
},
network: 'AlephZero'
},
true, // change this to false to test disabling eager connect
{ initOnConnect: true }, // change this to false to test disabling eager connect
document.getElementById('modalAnchor')
)

Expand Down
2 changes: 1 addition & 1 deletion sdk/apps/modal-example/src/routes/solana.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function Solana() {
additionalInfo: 'Courtesy of Nightly Connect team'
}
},
true,
{},
document.getElementById('modalAnchor')
).then((adapter) => {
adapter.on('connect', (pk) => {
Expand Down
4 changes: 2 additions & 2 deletions sdk/apps/modal-example/src/routes/solanaInitOnConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function SolanaLazy() {
const [adapter, setAdapter] = createSignal<NightlyConnectAdapter>()
const [publicKey, setPublicKey] = createSignal<PublicKey>()
onMount(() => {
const adapter = NightlyConnectAdapter.buildWithInitOnConnect(
const adapter = NightlyConnectAdapter.buildLazy(
{
appMetadata: {
name: 'NCTestSolana',
Expand All @@ -20,7 +20,7 @@ export default function SolanaLazy() {
},
url: 'https://nc2.nightly.app'
},
true,
{ initOnConnect: true },
document.getElementById('modalAnchor')
)

Expand Down
2 changes: 1 addition & 1 deletion sdk/apps/modal-example/src/routes/solanaLazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function SolanaLazy() {
},
url: 'https://nc2.nightly.app'
},
true,
{},
document.getElementById('modalAnchor')
)

Expand Down
28 changes: 21 additions & 7 deletions sdk/bindings/WalletMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Deeplink } from "./Deeplink";
import type { Images } from "./Images";
import type { Network } from "./Network";
import type { Platform } from "./Platform";
import type { Version } from "./Version";
import type { WalletType } from "./WalletType";
import type { Deeplink } from './Deeplink'
import type { Images } from './Images'
import type { Network } from './Network'
import type { Platform } from './Platform'
import type { Version } from './Version'
import type { WalletType } from './WalletType'

export interface WalletMetadata { slug: string, name: string, description: string, homepage: string, chains: Array<Network>, version: Version, walletType: WalletType, mobile: Deeplink | null, desktop: Deeplink | null, image: Images, app: Record<Platform, string>, injectPath: Record<Network, string>, lastUpdatedTimestamp: bigint, }
export interface WalletMetadata {
slug: string
name: string
description?: string
homepage?: string
chains?: Array<Network>
version?: Version
walletType: WalletType
mobile: Deeplink | null
desktop: Deeplink | null
image: Images
app?: Record<Platform, string>
injectPath?: Record<Network, string>
lastUpdatedTimestamp?: bigint
}
2 changes: 1 addition & 1 deletion sdk/packages/selector-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
"tslib": "^2.5.3",
"typescript": "^5.1.3"
}
}
}
4 changes: 2 additions & 2 deletions sdk/packages/selector-base/src/detection.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Wallet, getWallets } from '@wallet-standard/core'
import { type IWalletListItem, type MetadataWallet } from './types'
import { WalletMetadata, type IWalletListItem, type MetadataWallet } from './types'

export const getWalletsList = (
presetList: MetadataWallet[],
presetList: WalletMetadata[],
walletsFilterCb: (wallet: Wallet) => boolean,
recentWalletName?: string
) => {
Expand Down
18 changes: 15 additions & 3 deletions sdk/packages/selector-base/src/modal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { type XMLOptions, type NightlySelector } from '@nightlylabs/wallet-selector-modal'
import {
type XMLOptions,
type NightlySelector,
WalletSelectorItem
} from '@nightlylabs/wallet-selector-modal'
import { type IWalletListItem, type NetworkData } from './types'
import { isMobileBrowser } from './utils'

Expand Down Expand Up @@ -45,7 +49,11 @@ export class NightlyConnectSelectorModal {
)
this._walletsList = filtered
if (this._modal) {
this._modal.selectorItems = filtered
this._modal.selectorItems = filtered.map((item) => ({
...item,
icon: item.image.default,
link: item.homepage
})) as WalletSelectorItem[]
}
}

Expand All @@ -65,7 +73,11 @@ 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.map((item) => ({
...item,
icon: item.image.default,
link: item.homepage
})) as WalletSelectorItem[]
})
}

Expand Down
4 changes: 3 additions & 1 deletion sdk/packages/selector-base/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ 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'
import { type WalletMetadata } from '../../../bindings/WalletMetadata'
export { type WalletMetadata } from '../../../bindings/WalletMetadata'

export interface Adapter {
connect: () => Promise<void>
Expand All @@ -17,7 +19,7 @@ export interface MetadataWallet {
walletType: WalletType
}

export interface IWalletListItem extends MetadataWallet {
export interface IWalletListItem extends WalletMetadata {
recent?: boolean
detected?: boolean
standardWallet?: Wallet
Expand Down
2 changes: 1 addition & 1 deletion sdk/packages/selector-polkadot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
"tslib": "^2.5.3",
"typescript": "^5.1.3"
}
}
}
25 changes: 13 additions & 12 deletions sdk/packages/selector-polkadot/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import {
ConnectionOptions,
ConnectionType,
IWalletListItem,
NightlyConnectSelectorModal,
XMLOptions,
clearRecentWalletForNetwork,
Expand Down Expand Up @@ -163,7 +164,7 @@ export class NightlyConnectAdapter implements Injected {
)
if (!adapter._connectionOptions.disableModal) {
adapter._modal = new NightlyConnectSelectorModal(
adapter.walletsList,
adapter.walletsList as IWalletListItem[],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need as also
why us IWalletListItem

appInitData.url ?? 'https://nc2.nightly.app',
networkToData(adapter.network),
anchorRef,
Expand Down Expand Up @@ -212,7 +213,7 @@ export class NightlyConnectAdapter implements Injected {

if (!adapter._connectionOptions.disableModal) {
adapter._modal = new NightlyConnectSelectorModal(
adapter.walletsList,
adapter.walletsList as IWalletListItem[],
appInitData.url ?? 'https://nc2.nightly.app',
networkToData(adapter.network),
anchorRef,
Expand Down Expand Up @@ -309,47 +310,47 @@ export class NightlyConnectAdapter implements Injected {
throw new Error('Wallet not found')
}

if (wallet.deeplink === null) {
if (wallet.mobile === null) {
throw new Error('Deeplink not found')
}

// If we have a native deeplink, we should use it
if (wallet.deeplink.native !== null) {
if (wallet.mobile.native !== null) {
this._app.connectDeeplink({
walletName: wallet.name,
url: wallet.deeplink.native
url: wallet.mobile.native
})

this._chosenMobileWalletName = walletName

triggerConnect(
wallet.deeplink.native,
wallet.mobile.native,
this._app.sessionId,
this._appInitData.url ?? 'https://nc2.nightly.app'
)
return
}

// If we have a universal deeplink, we should use it
if (wallet.deeplink.universal !== null) {
if (wallet.mobile.universal !== null) {
this._app.connectDeeplink({
walletName: wallet.name,
url: wallet.deeplink.universal
url: wallet.mobile.universal
})

this._chosenMobileWalletName = walletName

triggerConnect(
wallet.deeplink.universal,
wallet.mobile.universal,
this._app.sessionId,
this._appInitData.url ?? 'https://nc2.nightly.app'
)
return
}
// Fallback to redirecting to app browser
// aka browser inside the app
if (!wallet.deeplink.redirectToAppBrowser) {
const redirectToAppBrowser = wallet.deeplink.redirectToAppBrowser
if (!wallet.mobile.redirectToAppBrowser) {
const redirectToAppBrowser = wallet.mobile.redirectToAppBrowser
if (redirectToAppBrowser !== null && redirectToAppBrowser.indexOf('{{url}}') > -1) {
const url = redirectToAppBrowser.replace(
'{{url}}',
Expand Down Expand Up @@ -599,7 +600,7 @@ export class NightlyConnectAdapter implements Injected {
getRecentWalletForNetwork(this.network)?.walletName ?? undefined
)
if (this._modal) {
this._modal.walletsList = this.walletsList
this._modal.walletsList = this.walletsList as IWalletListItem[]
}
this._connected = false
} finally {
Expand Down
18 changes: 9 additions & 9 deletions sdk/packages/selector-polkadot/src/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ export const getPolkadotWalletsList = (presetList: WalletMetadata[], recentWalle

presetList.forEach((wallet) => {
walletsData[wallet.slug.toLocaleLowerCase()] = {
slug: wallet.slug,
name: wallet.name,
icon: wallet.image.default,
deeplink: wallet.mobile,
link: wallet.homepage,
walletType: wallet.walletType,
...wallet,
recent: recentWalletName === wallet.name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is recent part of api ?

}
})
Expand Down Expand Up @@ -91,9 +86,14 @@ export const getPolkadotWalletsList = (presetList: WalletMetadata[], recentWalle
walletsData[wallet.name.toLocaleLowerCase()] = {
slug: wallet.name,
name: wallet.name,
icon: wallet.icon as string,
link: '',
deeplink: null,
image: {
default: wallet.icon as string,
sm: wallet.icon as string,
md: wallet.icon as string,
lg: wallet.icon as string
},
desktop: null,
mobile: null,
recent: recentWalletName === wallet.name,
detected: true,
injectedWallet: wallet,
Expand Down
6 changes: 3 additions & 3 deletions sdk/packages/selector-solana/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nightlylabs/wallet-selector-solana",
"version": "0.2.7",
"version": "0.3.0",
"description": "",
"type": "module",
"exports": {
Expand All @@ -25,7 +25,7 @@
"license": "ISC",
"dependencies": {
"@nightlylabs/nightly-connect-solana": "^0.0.29",
"@nightlylabs/wallet-selector-base": "^0.2.4",
"@nightlylabs/wallet-selector-base": "^0.3.1",
"@solana/wallet-adapter-base": "^0.9.22",
"@solana/wallet-standard": "^1.0.2",
"@solana/web3.js": "^1.77.2",
Expand All @@ -41,4 +41,4 @@
"tslib": "^2.5.3",
"typescript": "^5.1.3"
}
}
}
Loading
Loading