Skip to content

Commit

Permalink
fix: listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
LukassF committed Feb 22, 2024
1 parent bb51fc0 commit bba5a77
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 64 deletions.
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
}
})
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

0 comments on commit bba5a77

Please sign in to comment.