diff --git a/sdk/apps/modal-example/package.json b/sdk/apps/modal-example/package.json index 6d1627e7..8475bafe 100644 --- a/sdk/apps/modal-example/package.json +++ b/sdk/apps/modal-example/package.json @@ -22,14 +22,11 @@ "@nightlylabs/nightly-connect-polkadot": "0.0.15", "@nightlylabs/nightly-connect-solana": "0.0.29", "@nightlylabs/nightly-connect-sui": "0.0.29", - "@nightlylabs/wallet-selector-aptos": "0.1.1", - - "@nightlylabs/wallet-selector-base": "^0.4.0", - - "@nightlylabs/wallet-selector-polkadot": "0.2.5", - "@nightlylabs/wallet-selector-solana": "0.3.1", - "@nightlylabs/wallet-selector-sui": "0.3.1", - + "@nightlylabs/wallet-selector-aptos": "0.1.2", + "@nightlylabs/wallet-selector-base": "^0.4.1", + "@nightlylabs/wallet-selector-polkadot": "0.2.6", + "@nightlylabs/wallet-selector-solana": "0.3.2", + "@nightlylabs/wallet-selector-sui": "0.3.2", "@polkadot/api": "^10.10.1", "@polkadot/extension-inject": "^0.46.5", "@solana/web3.js": "^1.77.2", diff --git a/sdk/packages/selector-aptos/package.json b/sdk/packages/selector-aptos/package.json index 2dbebff2..d345f4fe 100644 --- a/sdk/packages/selector-aptos/package.json +++ b/sdk/packages/selector-aptos/package.json @@ -1,6 +1,6 @@ { "name": "@nightlylabs/wallet-selector-aptos", - "version": "0.1.1", + "version": "0.1.2", "description": "", "type": "module", "exports": { @@ -27,7 +27,7 @@ "@aptos-labs/ts-sdk": "^1.9.1", "@aptos-labs/wallet-standard": "^0.0.11", "@nightlylabs/nightly-connect-aptos": "0.0.2", - "@nightlylabs/wallet-selector-base": "0.4.0", + "@nightlylabs/wallet-selector-base": "0.4.1", "@wallet-standard/core": "^1.0.3", "eventemitter3": "^5.0.1" }, diff --git a/sdk/packages/selector-aptos/src/adapter.ts b/sdk/packages/selector-aptos/src/adapter.ts index bd97a73b..d3481d08 100644 --- a/sdk/packages/selector-aptos/src/adapter.ts +++ b/sdk/packages/selector-aptos/src/adapter.ts @@ -23,6 +23,7 @@ import { ConnectionType, defaultConnectionOptions, getRecentWalletForNetwork, + ISelectedWallet, isMobileBrowser, IWalletListItem, logoBase64, @@ -69,6 +70,8 @@ export class NightlyConnectAptosAdapter extends EventEmitter private _detectionIntervalId: NodeJS.Timeout | undefined private _maxNumberOfChecks = 10 + private _selectedWallet: ISelectedWallet | undefined = undefined + get walletsList() { return this._walletsList } @@ -80,6 +83,10 @@ export class NightlyConnectAptosAdapter extends EventEmitter } } + get selectedWallet() { + return this._selectedWallet + } + get sessionId() { return this._app?.sessionId } @@ -180,6 +187,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter adapter.disconnect() return } + adapter.setSelectedWallet({ isRemote: true }) adapter._accountInfo = accountInfo adapter._networkInfo = networkInfo adapter.connected = true @@ -261,6 +269,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter adapter.disconnect() return } + adapter.setSelectedWallet({ isRemote: true }) adapter._accountInfo = accountInfo adapter._networkInfo = networkInfo adapter.connected = true @@ -350,6 +359,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter const { accountInfo, networkInfo } = deserializeConnectData( this._app.base.clientMetadata ) + this.setSelectedWallet({ isRemote: true }) this._accountInfo = accountInfo this._networkInfo = networkInfo this.connected = true @@ -405,7 +415,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter this.disconnect() return } - + this.setSelectedWallet({ isRemote: true }) this._accountInfo = accountInfo this._networkInfo = networkInfo this.connected = true @@ -529,6 +539,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter clearSessionIdForNetwork(APTOS_NETWORK) // Refresh app session this._app = await AppAptos.build(this._appInitData) + this._selectedWallet = undefined // Add event listener for userConnected this._app.on('userConnected', async (accountInfo, networkInfo) => { @@ -545,6 +556,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter this.disconnect() return } + this.setSelectedWallet({ isRemote: true }) this._accountInfo = accountInfo this._networkInfo = networkInfo this.connected = true @@ -703,6 +715,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter } const wallet = this.walletsList.find((w) => w.name === walletName) + this.setSelectedWallet({ wallet }) if (!this._app) { throw new Error('Wallet not ready') @@ -769,6 +782,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter } const wallet = this.walletsList.find((w) => w.name === walletName) + this.setSelectedWallet({ wallet }) if (typeof wallet?.standardWallet === 'undefined') { if (this._modal) { @@ -856,4 +870,26 @@ export class NightlyConnectAptosAdapter extends EventEmitter ) }, 500) } + + setSelectedWallet = ({ + wallet, + isRemote = false + }: { + wallet?: IWalletListItem + isRemote?: boolean + }) => { + if (!wallet) { + // Connecting to the nightly mobile app + wallet = this.walletsList.find((wallet) => wallet.name === 'Nightly') + } + + if (wallet) { + this._selectedWallet = { + name: wallet.name, + image: wallet.image, + homepage: wallet.homepage, + walletType: isRemote ? 'mobile' : wallet.walletType + } + } + } } diff --git a/sdk/packages/selector-base/package.json b/sdk/packages/selector-base/package.json index e53c51b9..9a18f593 100644 --- a/sdk/packages/selector-base/package.json +++ b/sdk/packages/selector-base/package.json @@ -1,6 +1,6 @@ { "name": "@nightlylabs/wallet-selector-base", - "version": "0.4.0", + "version": "0.4.1", "description": "", "type": "module", "exports": { diff --git a/sdk/packages/selector-base/src/types.ts b/sdk/packages/selector-base/src/types.ts index 39676310..0d0fc354 100644 --- a/sdk/packages/selector-base/src/types.ts +++ b/sdk/packages/selector-base/src/types.ts @@ -1,8 +1,9 @@ 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 Images } from '../../../bindings/Images' import { WalletMetadata } from '../../../bindings/WalletMetadata' +import { type WalletType } from '../../../bindings/WalletType' export { type WalletMetadata } from '../../../bindings/WalletMetadata' export interface Adapter { @@ -29,6 +30,13 @@ export interface IWalletListItem standardWallet?: Wallet } +export interface ISelectedWallet { + name: string + homepage: string + walletType: WalletType + image: Images +} + export interface NetworkData { name: string icon: string diff --git a/sdk/packages/selector-polkadot/package.json b/sdk/packages/selector-polkadot/package.json index 75e68411..d54bf132 100644 --- a/sdk/packages/selector-polkadot/package.json +++ b/sdk/packages/selector-polkadot/package.json @@ -1,6 +1,6 @@ { "name": "@nightlylabs/wallet-selector-polkadot", - "version": "0.2.5", + "version": "0.2.6", "description": "", "type": "module", "exports": { @@ -25,7 +25,7 @@ "license": "ISC", "dependencies": { "@nightlylabs/nightly-connect-polkadot": "^0.0.16", - "@nightlylabs/wallet-selector-base": "^0.4.0", + "@nightlylabs/wallet-selector-base": "^0.4.1", "@polkadot/api": "10.10.1", "@polkadot/extension-inject": "0.46.5", "@wallet-standard/core": "^1.0.3", diff --git a/sdk/packages/selector-polkadot/src/adapter.ts b/sdk/packages/selector-polkadot/src/adapter.ts index db5f36f6..aedf0fb1 100644 --- a/sdk/packages/selector-polkadot/src/adapter.ts +++ b/sdk/packages/selector-polkadot/src/adapter.ts @@ -3,6 +3,7 @@ import { AppPolkadot, AppPolkadotInitialize } from '@nightlylabs/nightly-connect import { ConnectionOptions, ConnectionType, + ISelectedWallet, IWalletListItem, NightlyConnectSelectorModal, WalletMetadata, @@ -20,9 +21,9 @@ import { import { type Signer as InjectedSigner } from '@polkadot/api/types' import { InjectedAccount, type Injected } from '@polkadot/extension-inject/types' -import { IPolkadotWalletListItem, getPolkadotWalletsList } from './detection' -import { networkToData, SupportedNetworks } from './utils' import EventEmitter from 'eventemitter3' +import { IPolkadotWalletListItem, getPolkadotWalletsList } from './detection' +import { SupportedNetworks, networkToData } from './utils' export type AppSelectorInitialize = Omit & { network: SupportedNetworks @@ -58,6 +59,8 @@ export class NightlyConnectAdapter private _loading: boolean + private _selectedWallet: ISelectedWallet | undefined = undefined + // interval used for checking for wallets with delayed detection private _detectionIntervalId: NodeJS.Timeout | undefined private _maxNumberOfChecks = 10 @@ -124,6 +127,10 @@ export class NightlyConnectAdapter return this._walletsList } + get selectedWallet() { + return this._selectedWallet + } + set walletsList(list: IPolkadotWalletListItem[]) { this._walletsList = list if (this._modal) { @@ -212,6 +219,7 @@ export class NightlyConnectAdapter adapter.disconnect() return } + adapter.setSelectedWallet({ isRemote: true }) adapter._connected = true adapter.emit('connect', await adapter.accounts.get()) } catch { @@ -287,6 +295,7 @@ export class NightlyConnectAdapter adapter.disconnect() return } + adapter.setSelectedWallet({ isRemote: true }) adapter._connected = true adapter.emit('connect', await adapter.accounts.get()) } catch { @@ -358,6 +367,7 @@ export class NightlyConnectAdapter } const wallet = this.walletsList.find((w) => w.name === walletName) + this.setSelectedWallet({ wallet }) if (!this._app) { throw new Error('Wallet not ready') @@ -434,7 +444,9 @@ export class NightlyConnectAdapter if (this._modal) { this._modal.setStandardWalletConnectProgress(true) } - const adapter = this.walletsList.find((w) => w.name === walletName)?.injectedWallet + const wallet = this.walletsList.find((w) => w.name === walletName) + const adapter = wallet?.injectedWallet + this.setSelectedWallet({ wallet }) if (typeof adapter === 'undefined') { if (this._modal) { this._modal.setStandardWalletConnectProgress(false) @@ -515,6 +527,7 @@ export class NightlyConnectAdapter if (this._app?.hasBeenRestored() && this._app.accounts.activeAccounts.length > 0) { // Try to eager connect if session is restored try { + this.setSelectedWallet({ isRemote: true }) this._connected = true this._connecting = false this.emit('connect', await this.accounts.get()) @@ -561,6 +574,7 @@ export class NightlyConnectAdapter this.disconnect() return } + this.setSelectedWallet({ isRemote: true }) this._connected = true this.emit('connect', await this.accounts.get()) } catch { @@ -688,6 +702,28 @@ export class NightlyConnectAdapter clearRecentWalletForNetwork(this.network) this._innerStandardAdapter = undefined this._app = await AppPolkadot.build(this._appInitData) + this._selectedWallet = undefined + + this._app.on('userConnected', async () => { + try { + persistRecentWalletForNetwork(this.network, { + walletName: this._chosenMobileWalletName || '', + walletType: ConnectionType.Nightly + }) + + if (!this._app || this._app.accounts.activeAccounts.length <= 0) { + this._connected = false + // If user does not pass any accounts, we should disconnect + this.disconnect() + return + } + this.setSelectedWallet({ isRemote: true }) + this._connected = true + this.emit('connect', await this.accounts.get()) + } catch { + this.disconnect() + } + }) // Update recent wallet this.walletsList = getPolkadotWalletsList( @@ -705,4 +741,26 @@ export class NightlyConnectAdapter clearInterval(this._detectionIntervalId) } } + + setSelectedWallet = ({ + wallet, + isRemote = false + }: { + wallet?: IWalletListItem + isRemote?: boolean + }) => { + if (!wallet) { + // Connecting to the nightly mobile app + wallet = this.walletsList.find((wallet) => wallet.name === 'Nightly') + } + + if (wallet) { + this._selectedWallet = { + name: wallet.name, + image: wallet.image, + homepage: wallet.homepage, + walletType: isRemote ? 'mobile' : wallet.walletType + } + } + } } diff --git a/sdk/packages/selector-solana/package.json b/sdk/packages/selector-solana/package.json index f045e51d..9507fb89 100644 --- a/sdk/packages/selector-solana/package.json +++ b/sdk/packages/selector-solana/package.json @@ -1,6 +1,6 @@ { "name": "@nightlylabs/wallet-selector-solana", - "version": "0.3.1", + "version": "0.3.2", "description": "", "type": "module", "exports": { @@ -25,7 +25,7 @@ "license": "ISC", "dependencies": { "@nightlylabs/nightly-connect-solana": "^0.0.29", - "@nightlylabs/wallet-selector-base": "^0.4.0", + "@nightlylabs/wallet-selector-base": "^0.4.1", "@solana/wallet-adapter-base": "^0.9.22", "@solana/wallet-standard": "^1.0.2", "@solana/web3.js": "^1.77.2", diff --git a/sdk/packages/selector-solana/src/adapter.ts b/sdk/packages/selector-solana/src/adapter.ts index 6cccc3cb..b95caad8 100644 --- a/sdk/packages/selector-solana/src/adapter.ts +++ b/sdk/packages/selector-solana/src/adapter.ts @@ -1,27 +1,27 @@ import { AppSolana, SOLANA_NETWORK } from '@nightlylabs/nightly-connect-solana' import { AppInitData, + ConnectionOptions, + ConnectionType, + ISelectedWallet, + IWalletListItem, + NightlyConnectSelectorModal, + WalletMetadata, + XMLOptions, clearRecentWalletForNetwork, clearSessionIdForNetwork, + defaultConnectionOptions, getRecentWalletForNetwork, isMobileBrowser, logoBase64, - NightlyConnectSelectorModal, persistRecentWalletForNetwork, - triggerConnect, sleep, - XMLOptions, - ConnectionType, - ConnectionOptions, - defaultConnectionOptions, - WalletMetadata, - IWalletListItem + triggerConnect } from '@nightlylabs/wallet-selector-base' import { BaseMessageSignerWalletAdapter, WalletAdapterCompatibleStandardWallet, WalletAdapterEvents, - WalletError, WalletName, WalletNotConnectedError, WalletNotReadyError, @@ -33,8 +33,8 @@ import { } from '@solana/wallet-adapter-base' import { StandardWalletAdapter } from '@solana/wallet-standard' import { PublicKey, Transaction, TransactionVersion, VersionedTransaction } from '@solana/web3.js' -import { getSolanaWalletsList } from './detection' import { StandardEventsChangeProperties } from '@wallet-standard/core' +import { getSolanaWalletsList } from './detection' type NightlyConnectAdapterEvents = WalletAdapterEvents & { change(properties: StandardEventsChangeProperties): void @@ -74,6 +74,8 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { private _detectionIntervalId: NodeJS.Timeout | undefined private _maxNumberOfChecks = 10 + private _selectedWallet: ISelectedWallet | undefined = undefined + private _connectionOptions: ConnectionOptions = defaultConnectionOptions // eslint-disable-next-line @typescript-eslint/no-explicit-any private _eventHandlers: Map void> = new Map() @@ -114,6 +116,10 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { return this._walletsList } + get selectedWallet() { + return this._selectedWallet + } + set walletsList(list: IWalletListItem[]) { this._walletsList = list if (this._modal) { @@ -240,6 +246,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { adapter.disconnect() return } + adapter.setSelectedWallet({ isRemote: true }) adapter._publicKey = adapter._app.connectedPublicKeys[0] adapter._connected = true adapter.emit('connect', adapter._publicKey) @@ -326,6 +333,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { adapter.disconnect() return } + adapter.setSelectedWallet({ isRemote: true }) adapter._publicKey = adapter._app.connectedPublicKeys[0] adapter._connected = true adapter.emit('connect', adapter._publicKey) @@ -399,6 +407,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { } const wallet = this.walletsList.find((w) => w.name === walletName) + this.setSelectedWallet({ wallet }) if (!this._app) { throw new Error('Wallet not ready') @@ -450,6 +459,8 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { if (this._modal) { this._modal.setStandardWalletConnectProgress(false) } + this._selectedWallet = undefined + throw err } } @@ -461,8 +472,11 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { this._modal.setStandardWalletConnectProgress(true) } - const wallet = this.walletsList.find((w) => w.name === walletName)?.standardWallet - if (typeof wallet === 'undefined') { + const wallet = this.walletsList.find((w) => w.name === walletName) + this.setSelectedWallet({ wallet }) + const standardWallet = wallet?.standardWallet + + if (typeof standardWallet === 'undefined') { if (this._modal) { this._modal.setStandardWalletConnectProgress(false) } @@ -470,7 +484,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { } const adapter = new StandardWalletAdapter({ - wallet: wallet as WalletAdapterCompatibleStandardWallet + wallet: standardWallet as WalletAdapterCompatibleStandardWallet }) await adapter.connect() @@ -497,6 +511,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { if (this._modal) { this._modal.setStandardWalletConnectProgress(false) } + this._selectedWallet = undefined throw err } @@ -544,6 +559,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { this._connected = true this._connecting = false this._appSessionActive = true + this.setSelectedWallet({ isRemote: true }) this.emit('connect', this._publicKey) resolve() return @@ -590,6 +606,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { this.disconnect() return } + this.setSelectedWallet({ isRemote: true }) this._publicKey = this._app.connectedPublicKeys[0] this._connected = true this.emit('connect', this._publicKey) @@ -720,6 +737,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { clearSessionIdForNetwork(SOLANA_NETWORK) this._appSessionActive = false this._loading = true + this._selectedWallet = undefined try { this._app = await AppSolana.build(this._appInitData) // Add event listener for userConnected @@ -736,6 +754,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { this.disconnect() return } + this.setSelectedWallet({ isRemote: true }) this._publicKey = this._app.connectedPublicKeys[0] this._connected = true this.emit('connect', this._publicKey) @@ -837,4 +856,26 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { throw error } } + + setSelectedWallet = ({ + wallet, + isRemote = false + }: { + wallet?: IWalletListItem + isRemote?: boolean + }) => { + if (!wallet) { + // Connecting to the nightly mobile app + wallet = this.walletsList.find((wallet) => wallet.name === 'Nightly') + } + + if (wallet) { + this._selectedWallet = { + name: wallet.name, + image: wallet.image, + homepage: wallet.homepage, + walletType: isRemote ? 'mobile' : wallet.walletType + } + } + } } diff --git a/sdk/packages/selector-sui/package.json b/sdk/packages/selector-sui/package.json index 7c23ca93..f3151d4c 100644 --- a/sdk/packages/selector-sui/package.json +++ b/sdk/packages/selector-sui/package.json @@ -1,6 +1,6 @@ { "name": "@nightlylabs/wallet-selector-sui", - "version": "0.3.1", + "version": "0.3.2", "description": "", "type": "module", "exports": { @@ -29,7 +29,7 @@ "@mysten/wallet-standard": "^0.8.0", "@mysten/wallet-adapter-base": "^0.9.0", "@nightlylabs/nightly-connect-sui": "0.0.29", - "@nightlylabs/wallet-selector-base": "0.4.0", + "@nightlylabs/wallet-selector-base": "0.4.1", "@wallet-standard/core": "^1.0.3", "bs58": "^4.0.1", "events": "^3.3.0", diff --git a/sdk/packages/selector-sui/src/adapter.ts b/sdk/packages/selector-sui/src/adapter.ts index ecd96adf..52b94a59 100644 --- a/sdk/packages/selector-sui/src/adapter.ts +++ b/sdk/packages/selector-sui/src/adapter.ts @@ -14,6 +14,7 @@ import { AppInitData, ConnectionOptions, ConnectionType, + ISelectedWallet, IWalletListItem, NightlyConnectSelectorModal, WalletMetadata, @@ -30,8 +31,8 @@ import { } from '@nightlylabs/wallet-selector-base' import type { StandardEventsChangeProperties, WalletAccount } from '@wallet-standard/core' import bs58 from 'bs58' -import { getSuiWalletsList } from './detection' import EventEmitter from 'eventemitter3' +import { getSuiWalletsList } from './detection' export const convertBase58toBase64 = (base58: string) => { const buffer = bs58.decode(base58) @@ -62,6 +63,7 @@ export class NightlyConnectSuiAdapter extends EventEmitter { private _accounts: WalletAccount[] = [] private _connectionType: ConnectionType | undefined private _metadataWallets: WalletMetadata[] = [] + private _selectedWallet: ISelectedWallet | undefined = undefined private _connectionOptions: ConnectionOptions = defaultConnectionOptions @@ -88,6 +90,10 @@ export class NightlyConnectSuiAdapter extends EventEmitter { return this._modal?.qrCode } + get selectedWallet() { + return this._selectedWallet + } + // We need internal _connecting since sui messes with connecting state private _connecting = false constructor(appInitData: AppInitData, connectionOptions?: ConnectionOptions) { @@ -181,6 +187,7 @@ export class NightlyConnectSuiAdapter extends EventEmitter { adapter.disconnect() return } + adapter.setSelectedWallet({ isRemote: true }) adapter._accounts = e.publicKeys.map((pk) => createSuiWalletAccountFromString(pk)) adapter.connected = true adapter.emit('connect', adapter._accounts) @@ -261,6 +268,7 @@ export class NightlyConnectSuiAdapter extends EventEmitter { adapter.disconnect() return } + adapter.setSelectedWallet({ isRemote: true }) adapter._accounts = e.publicKeys.map((pk) => createSuiWalletAccountFromString(pk)) adapter.connected = true adapter.emit('connect', adapter._accounts) @@ -316,6 +324,7 @@ export class NightlyConnectSuiAdapter extends EventEmitter { this._connecting = false this.connecting = false this._connectionType = ConnectionType.Nightly + this.setSelectedWallet({ isRemote: true }) this.emit('connect', this._accounts) resolve() return @@ -361,6 +370,7 @@ export class NightlyConnectSuiAdapter extends EventEmitter { this.disconnect() return } + this.setSelectedWallet({ isRemote: true }) this._accounts = e.publicKeys.map((pk) => createSuiWalletAccountFromString(pk)) this.connected = true this.emit('connect', this._accounts) @@ -486,6 +496,7 @@ export class NightlyConnectSuiAdapter extends EventEmitter { clearSessionIdForNetwork(SUI_NETWORK) // Refresh app session this._app = await AppSui.build(this._appInitData) + this._selectedWallet = undefined // Add event listener for userConnected this._app.on('userConnected', async (e) => { @@ -502,6 +513,7 @@ export class NightlyConnectSuiAdapter extends EventEmitter { this.disconnect() return } + this.setSelectedWallet({ isRemote: true }) this._accounts = e.publicKeys.map((pk) => createSuiWalletAccountFromString(pk)) this.connected = true this.emit('connect', this._accounts) @@ -659,6 +671,7 @@ export class NightlyConnectSuiAdapter extends EventEmitter { } const wallet = this.walletsList.find((w) => w.name === walletName) + this.setSelectedWallet({ wallet }) if (!this._app) { throw new Error('Wallet not ready') @@ -721,6 +734,7 @@ export class NightlyConnectSuiAdapter extends EventEmitter { } const wallet = this.walletsList.find((w) => w.name === walletName) + this.setSelectedWallet({ wallet }) if (typeof wallet?.standardWallet === 'undefined') { if (this._modal) { @@ -804,6 +818,28 @@ export class NightlyConnectSuiAdapter extends EventEmitter { ) }, 500) } + + setSelectedWallet = ({ + wallet, + isRemote = false + }: { + wallet?: IWalletListItem + isRemote?: boolean + }) => { + if (!wallet) { + // Connecting to the nightly mobile app + wallet = this.walletsList.find((wallet) => wallet.name === 'Nightly') + } + + if (wallet) { + this._selectedWallet = { + name: wallet.name, + image: wallet.image, + homepage: wallet.homepage, + walletType: isRemote ? 'mobile' : wallet.walletType + } + } + } } export const createSuiWalletAccountFromString = (publicKey: string): WalletAccount => { diff --git a/sdk/pnpm-lock.yaml b/sdk/pnpm-lock.yaml index adf802d2..08f8a51e 100644 --- a/sdk/pnpm-lock.yaml +++ b/sdk/pnpm-lock.yaml @@ -95,19 +95,19 @@ importers: specifier: 0.0.29 version: link:../../packages/sui '@nightlylabs/wallet-selector-aptos': - specifier: 0.1.0 + specifier: 0.1.2 version: link:../../packages/selector-aptos '@nightlylabs/wallet-selector-base': - specifier: ^0.4.0 + specifier: ^0.4.1 version: link:../../packages/selector-base '@nightlylabs/wallet-selector-polkadot': - specifier: 0.2.4 + specifier: 0.2.6 version: link:../../packages/selector-polkadot '@nightlylabs/wallet-selector-solana': - specifier: 0.3.0 + specifier: 0.3.2 version: link:../../packages/selector-solana '@nightlylabs/wallet-selector-sui': - specifier: 0.3.1 + specifier: 0.3.2 version: link:../../packages/selector-sui '@polkadot/api': specifier: ^10.10.1 @@ -540,7 +540,7 @@ importers: specifier: 0.0.2 version: link:../aptos '@nightlylabs/wallet-selector-base': - specifier: 0.4.0 + specifier: 0.4.1 version: link:../selector-base '@wallet-standard/core': specifier: ^1.0.3 @@ -620,7 +620,7 @@ importers: specifier: ^0.0.16 version: link:../polkadot '@nightlylabs/wallet-selector-base': - specifier: ^0.4.0 + specifier: ^0.4.1 version: link:../selector-base '@polkadot/api': specifier: 10.10.1 @@ -666,7 +666,7 @@ importers: specifier: ^0.0.29 version: link:../solana '@nightlylabs/wallet-selector-base': - specifier: ^0.4.0 + specifier: ^0.4.1 version: link:../selector-base '@solana/wallet-adapter-base': specifier: ^0.9.22 @@ -724,7 +724,7 @@ importers: specifier: 0.0.29 version: link:../sui '@nightlylabs/wallet-selector-base': - specifier: 0.4.0 + specifier: 0.4.1 version: link:../selector-base '@wallet-standard/core': specifier: ^1.0.3