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 3 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
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
}
44 changes: 2 additions & 42 deletions 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,48 +19,6 @@ export interface MetadataWallet {
walletType: WalletType
}

interface Images {
default: string
sm: string
md: string
lg: string
}

type Network = string

type Platform =
| 'browser'
| 'ios'
| 'android'
| 'macos'
| 'windows'
| 'linux'
| 'chrome'
| 'firefox'
| 'opera'
| 'edge'
| 'brave'
| 'safari'
| 'other'

type Version = string

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 IWalletListItem extends WalletMetadata {
recent?: boolean
detected?: boolean
Expand Down
2 changes: 1 addition & 1 deletion sdk/packages/selector-polkadot/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class NightlyConnectAdapter implements Injected {
set walletsList(list: IPolkadotWalletListItem[]) {
this._walletsList = list
if (this._modal) {
this._modal.walletsList = list as IWalletListItem[]
this._modal.walletsList = list
}
}

Expand Down
6 changes: 4 additions & 2 deletions sdk/packages/selector-polkadot/src/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export const getPolkadotWalletsList = (presetList: WalletMetadata[], recentWalle
const walletsData: Record<string, IPolkadotWalletListItem> = {}

presetList.forEach((wallet) => {
walletsData[wallet.slug.toLocaleLowerCase()] = wallet
walletsData[wallet.slug.toLocaleLowerCase()] = {
...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 ?

}
})
for (const wallet of windowWallets) {
// Check if wallet is already in the list
Expand Down Expand Up @@ -94,7 +97,6 @@ export const getPolkadotWalletsList = (presetList: WalletMetadata[], recentWalle
recent: recentWalletName === wallet.name,
detected: true,
injectedWallet: wallet,
homepage: '',
walletType: 'hybrid'
}
}
Expand Down
29 changes: 17 additions & 12 deletions sdk/packages/selector-solana/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
BaseMessageSignerWalletAdapter,
WalletAdapterCompatibleStandardWallet,
WalletAdapterEvents,
WalletError,
WalletName,
WalletNotConnectedError,
WalletNotReadyError,
Expand All @@ -36,14 +37,6 @@ import { PublicKey, Transaction, TransactionVersion, VersionedTransaction } from
import { solanaWalletsFilter } from './detection'
import { StandardEventsChangeProperties } from '@wallet-standard/core'

type ArgumentMap<T extends object> = {
[K in keyof T]: T[K] extends (...args: any[]) => void
? Parameters<T[K]>
: T[K] extends any[]
? T[K]
: any[]
}

type NightlyConnectAdapterEvents = WalletAdapterEvents & {
change(properties: StandardEventsChangeProperties): void
}
Expand Down Expand Up @@ -154,16 +147,28 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter {

on<T extends keyof NightlyConnectAdapterEvents>(
event: T,
fn: (...args: ArgumentMap<NightlyConnectAdapterEvents>[T]) => void,
fn: NightlyConnectAdapterEvents[T] extends (...args: infer Args) => void
? (...args: Args) => void
: never,
context?: any
): this {
return this
if (event === 'change') {
// TODO implement on change listener
return this
} else {
return super.on(event, fn, context)
}
}

emit<T extends keyof NightlyConnectAdapterEvents>(
event: T,
...args: ArgumentMap<NightlyConnectAdapterEvents>[Extract<T, keyof WalletAdapterEvents>]
...args: [publicKey: PublicKey] | [] | [error: WalletError] | [readyState: WalletReadyState]
): boolean {
if (event === 'change') {
// TODO implement change event emitter
} else {
super.emit(event, ...args)
}
return true
}

Expand Down Expand Up @@ -244,7 +249,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter {
adapter._metadataWallets = metadataWallets

adapter.walletsList = getWalletsList(
[],
metadataWallets,
solanaWalletsFilter,
getRecentWalletForNetwork(SOLANA_NETWORK)?.walletName ?? undefined
)
Expand Down
70 changes: 67 additions & 3 deletions sdk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading