From 7e7eff0e3ed38ca346e8acc87aee6e43681248d8 Mon Sep 17 00:00:00 2001 From: LukassF Date: Thu, 9 May 2024 09:50:27 +0200 Subject: [PATCH 1/4] add movement to docs --- .../docs/docs/customization/external_modal.md | 2 +- .../docs/docs/customization/ui_overrides.md | 2 +- sdk/apps/docs/docs/for_wallets/connect.md | 7 +- .../docs/docs/for_wallets/sign_message.md | 4 + .../docs/docs/for_wallets/sign_transaction.md | 4 + sdk/apps/docs/docs/movement/connect.md | 86 +++++++++++++++++++ sdk/apps/docs/docs/movement/events.md | 41 +++++++++ .../docs/docs/movement/sign_transaction.md | 77 +++++++++++++++++ sdk/apps/docs/docs/movement/start.md | 38 ++++++++ sdk/apps/docs/docs/start.md | 4 + sdk/apps/docs/docusaurus.config.js | 36 ++------ sdk/apps/docs/sidebars.js | 7 ++ sdk/apps/docs/src/css/custom.css | 35 ++------ 13 files changed, 282 insertions(+), 61 deletions(-) create mode 100644 sdk/apps/docs/docs/movement/connect.md create mode 100644 sdk/apps/docs/docs/movement/events.md create mode 100644 sdk/apps/docs/docs/movement/sign_transaction.md create mode 100644 sdk/apps/docs/docs/movement/start.md diff --git a/sdk/apps/docs/docs/customization/external_modal.md b/sdk/apps/docs/docs/customization/external_modal.md index 767e9d40..343abb1b 100644 --- a/sdk/apps/docs/docs/customization/external_modal.md +++ b/sdk/apps/docs/docs/customization/external_modal.md @@ -8,7 +8,7 @@ You may want to use your own design and/or change some logic for the modal. In t You can then use the modal connect function, instead of using the default one from the adapter. :::info -Example below is written for [Solana](../../solana/solana/start), but you can use it for [Sui](../../sui/sui/start), [Aptos](../../aptos/aptos/start) and [Substrate](../../substrate/substrate/start) as well. +Example below is written for [Solana](../../solana/solana/start), but you can use it for [Sui](../../sui/sui/start), [Aptos](../../aptos/aptos/start), [Movement](../../movement/movement/start) and [Substrate](../../substrate/substrate/start) as well. ::: ```js diff --git a/sdk/apps/docs/docs/customization/ui_overrides.md b/sdk/apps/docs/docs/customization/ui_overrides.md index 91a8ebf2..388e7caf 100644 --- a/sdk/apps/docs/docs/customization/ui_overrides.md +++ b/sdk/apps/docs/docs/customization/ui_overrides.md @@ -120,5 +120,5 @@ const adapter = NightlyConnectAdapter.buildLazy( ``` :::info -The example is built using [Substrate](../../substrate/substrate/start), but can be implemented using [Solana](../../solana/solana/start), [Aptos](../../aptos/aptos/start) and [Sui](../../sui/sui/start) as well. +The example is built using [Substrate](../../substrate/substrate/start), but can be implemented using [Solana](../../solana/solana/start), [Aptos](../../aptos/aptos/start), [Movement](../../movement/movement/start) and [Sui](../../sui/sui/start) as well. ::: diff --git a/sdk/apps/docs/docs/for_wallets/connect.md b/sdk/apps/docs/docs/for_wallets/connect.md index f866f8f6..fd1fa63d 100644 --- a/sdk/apps/docs/docs/for_wallets/connect.md +++ b/sdk/apps/docs/docs/for_wallets/connect.md @@ -117,7 +117,7 @@ await client.connect(message) ```js -import { ClientSui } from '@nightlylabs/nightly-connect-aptos' +import { ClientAptos } from '@nightlylabs/nightly-connect-aptos' const client: ClientAptos = await ClientAptos.create({ url: RELAY_ENDPOINT // default: https://nc2.nightly.app @@ -140,6 +140,11 @@ const message: Connect = { await client.connect(message) ``` + + + +The Build & Connect process mirrors that of Aptos. + diff --git a/sdk/apps/docs/docs/for_wallets/sign_message.md b/sdk/apps/docs/docs/for_wallets/sign_message.md index 57f7fc27..77c38ffd 100644 --- a/sdk/apps/docs/docs/for_wallets/sign_message.md +++ b/sdk/apps/docs/docs/for_wallets/sign_message.md @@ -96,5 +96,9 @@ client.on('signMessage', async (e) => { }) ``` + + + +The process mirrors that of Aptos. diff --git a/sdk/apps/docs/docs/for_wallets/sign_transaction.md b/sdk/apps/docs/docs/for_wallets/sign_transaction.md index 549c2dbc..5e2c8fdf 100644 --- a/sdk/apps/docs/docs/for_wallets/sign_transaction.md +++ b/sdk/apps/docs/docs/for_wallets/sign_transaction.md @@ -133,5 +133,9 @@ client.on('signTransaction', async (e) => { }) ``` + + + +The process mirrors that of Aptos. diff --git a/sdk/apps/docs/docs/movement/connect.md b/sdk/apps/docs/docs/movement/connect.md new file mode 100644 index 00000000..eb5f7695 --- /dev/null +++ b/sdk/apps/docs/docs/movement/connect.md @@ -0,0 +1,86 @@ +--- +title: Build & Connect +slug: movement/connect +--- + +:::info +This part of documentation is targeted to applications that want to implement nightly connect +as wallet interface. +::: + +To get started, we need to connect the user to the application. +In order to do so, application generates the sessionId, a unique id that identifies each connection. + +--- + +This process is initialized by one side displaying a sessionId through QR code (see the screenshot). +The other peer needs just to scan the QR code on its device. Extension wallets are auto detected so you are always up to date and don't need to upgrade your dapp. + +![ConnectImage](../../static/img/connect.png#connectImage) + +### Connect + +Application builds a connection using `build()` or `buildLazy()` function that returns interface to communicated with remote user. It is important to note, that the `buildLazy()` function allows for the modal to appear even when the sessionId is still undefined. App should define `AppMetadata` so wallets will be able to show it to user. + +To start sending request like `signTransaction` user first need to connect to session. +Once user establishes connection, application will get public key and the connection will be confirmed. + +API of application client is fit to match currently existing standards of corresponding blockchains + +```js +interface AppMetadata { + name: string; + url?: string; + description?: string; + icon?: string; // Url of app image + additionalInfo?: string; +} +``` + +You may also want to specify some additional connection options. This can be achieved by creating an object that implements the below interface, and using it inside the `build()` or `buildLazy()` function. Note, that the `disableModal` property can be used for implementing a custom [External modal](../../customization/customization/external_modal). + +```js +interface ConnectionOptions { + disableModal?: boolean // default: false + // Used for disabling modal in case you want to use your own + initOnConnect?: boolean // default: false + // Ensures that the app is only build upon running the connect function + disableEagerConnect?: boolean // default: false + // Do not connect eagerly, even if the previous session is saved +} +``` + +```js +import { NightlyConnectAptosAdapter } from '@nightlylabs/wallet-selector-aptos' + +const adapter = await NightlyConnectAptosAdapter.build( + { + appMetadata: { + name: 'Movement Template', + description: 'Movement Template', + icon: 'https://docs.nightly.app/img/logo.png' + } + // persistent: false - Add this if you want to make the session non-persistent + } + // { initOnConnect: true, disableModal: true, disableEagerConnect: true } - You may specify the connection options object here + // document.getElementById("modalAnchor") - You can pass an optional anchor element for the modal here +) + +// Trigger connection +await adapter.connect() +// After connection adapter turns into remote signer + +// Sign transaction +await adapter.signAndSubmitTransaction(transaction) + +// Disconnect client if you want to end session +await adapter.disconnect() +``` + +### Disconnect + +:::info +Both client and application can initiate disconnection. +User can force session termination in case of abuse. +Only when application disconnects and session is not persistent, session is completely removed. +::: diff --git a/sdk/apps/docs/docs/movement/events.md b/sdk/apps/docs/docs/movement/events.md new file mode 100644 index 00000000..d4b6e503 --- /dev/null +++ b/sdk/apps/docs/docs/movement/events.md @@ -0,0 +1,41 @@ +--- +title: Listening for events +slug: movement/events +--- + +An app can listen to events, subscribe to them and run some code whenever the particular event occurs. + +If you have created a connection you can listen for events using the `on()` function. + +```js +const adapter = NightlyConnectAptosAdapter.buildLazy( + { + appMetadata: { + name: 'Movement Template', + description: 'Movement Template', + icon: 'https://docs.nightly.app/img/logo.png', + }, + url: 'https://nc2.nightly.app' + } +) + +adapter.on('connect', (publicKey) => { + ... +}) + +adapter.on('accountChange', (accInfo) => { + ... +}) + +adapter.on('networkChange', (networkInfo) => { + ... +}) + +adapter.on('disconnect', () => { + ... +}) + +adapter.on('error', (error) => { + ... +}) +``` diff --git a/sdk/apps/docs/docs/movement/sign_transaction.md b/sdk/apps/docs/docs/movement/sign_transaction.md new file mode 100644 index 00000000..78a9883b --- /dev/null +++ b/sdk/apps/docs/docs/movement/sign_transaction.md @@ -0,0 +1,77 @@ +--- +title: Sign Transaction +slug: movement/sign_transaction +--- + +Sending a signTransaction requires established connection with user wallet. + +Transaction are sent to the client via wallet interface. Client can accept or reject the request. + +To create a transaction, first we have to establish a connection with an `Aptos` provider. + +```js +import { Aptos, AptosConfig, AptosSettings } from '@aptos-labs/ts-sdk' + +let _provider: Aptos | undefined +const endpoint = 'https://aptos.devnet.m1.movementlabs.xyz' + +export const getAptos = () => { + if (_provider) return _provider + const conf = new AptosConfig({ + fullnode: endpoint, + faucet: 'https://faucet.movementlabs.xyz' + }) + _provider = new Aptos(conf) // DEVNET + + const a = async () => { + const acc = await getAptos().account.getAccountResources({ + accountAddress: '0x975c0bad4ee36fcb48fe447647834b9c09ef44349ff593e90dd816dc5a3eccdc' + }) + console.log(acc) + const resp = await getAptos().faucet.fundAccount({ + accountAddress: '0x975c0bad4ee36fcb48fe447647834b9c09ef44349ff593e90dd816dc5a3eccdc', + amount: 10000 + }) + console.log(resp) + } + + a() + + return _provider +} +``` + +Then we can use the above function, to get Aptos provider instance for later use. + +```js +const aptos = getAptos() +``` + +And create the transaction as such. + +```js + +const userAccount = { + address: '' // Generated inside the onAccountChange event listener + ... +} + +const transaction = await aptos.transaction.build.simple({ + sender: userAccount.address.toString(), + data: { + function: '0x1::coin::transfer', + typeArguments: ['0x1::aptos_coin::AptosCoin'], + functionArguments: [ + '0x99881b6cdf90c9edb04e6b5912c236630b55587161dedc1fc05d53f72eec07e8', + 1_000_000, + ], + }, +}) + +``` + +Finally we can sign the created transaction using the `signAndSubmitTransaction()` method, which returns resolved promise with Signed Transaction. + +```js +const signedTx = await adapter.signAndSubmitTransaction(transaction) +``` diff --git a/sdk/apps/docs/docs/movement/start.md b/sdk/apps/docs/docs/movement/start.md new file mode 100644 index 00000000..9fd459bd --- /dev/null +++ b/sdk/apps/docs/docs/movement/start.md @@ -0,0 +1,38 @@ +--- +title: Get started with Movement +slug: movement/start +--- + +### Web template + +
+ +**To get started with movement, use the source code of the template below, and follow the installation instructions.** + +
+ +> #### Preview: https://movement-web3-template.vercel.app + +
+ +> #### Source code: https://github.com/nightly-labs/movement-web3-template + +
+ +
+ +### Manual installation + +If you want to opt for greater flexibility, install the package, as described below and then visit the [Movement Build & Connect](./connect). + +:::note +Simply integrate Nightly Connect to your application or wallet with our [Nightly Aptos Connect package](https://www.npmjs.com/package/@nightlylabs/wallet-selector-aptos). + +```bash +# Using NPM +npm i @nightlylabs/wallet-selector-aptos +# Using Yarn +yarn add @nightlylabs/wallet-selector-aptos +``` + +::: diff --git a/sdk/apps/docs/docs/start.md b/sdk/apps/docs/docs/start.md index 19089d63..2c8c83d1 100644 --- a/sdk/apps/docs/docs/start.md +++ b/sdk/apps/docs/docs/start.md @@ -20,4 +20,8 @@ slug: /start Aptos + + + Movement + diff --git a/sdk/apps/docs/docusaurus.config.js b/sdk/apps/docs/docusaurus.config.js index b23c686c..56d2cc9f 100644 --- a/sdk/apps/docs/docusaurus.config.js +++ b/sdk/apps/docs/docusaurus.config.js @@ -83,37 +83,14 @@ const config = { to: 'docs/aptos/aptos/start', label: 'Aptos', className: 'network_navlink aptos_navlink' + }, + { + to: 'docs/movement/movement/start', + label: 'Movement', + className: 'network_navlink movement_navlink' } ] }, - // { - // to: 'docs/solana/solana/start', - // className: 'solana_navlink navlink', - // activeBasePath: 'docs/solana/solana/start', - // label: 'Solana', - // position: 'left' - // }, - // { - // to: 'docs/sui/sui/start', - // className: 'sui_navlink navlink', - // activeBasePath: 'docs/sui/sui/start', - // label: 'Sui', - // position: 'left' - // }, - // { - // to: 'docs/substrate/substrate/start', - // className: 'substrate_navlink navlink', - // activeBasePath: 'docs/substrate/substrate/start', - // label: 'Substrate', - // position: 'left' - // }, - // { - // to: 'docs/aptos/aptos/start', - // className: 'aptos_navlink navlink', - // activeBasePath: 'docs/aptos/aptos/start', - // label: 'Aptos', - // position: 'left' - // }, { to: 'docs/customization/customization/ui_overrides', activeBasePath: 'docs/customization/customization/ui_overrides', @@ -134,7 +111,8 @@ const config = { { href: 'https://solana-web3-template.nightly.app', label: 'Solana template' }, { href: 'https://sui-web3-template.nightly.app', label: 'Sui template' }, { href: 'https://aleph-zero-web3-template.nightly.app', label: 'Substrate template' }, - { href: 'https://aptos-web3-template.vercel.app', label: 'Aptos template' } + { href: 'https://aptos-web3-template.vercel.app', label: 'Aptos template' }, + { href: 'https://movement-web3-template.vercel.app', label: 'Movement template' } ] }, { diff --git a/sdk/apps/docs/sidebars.js b/sdk/apps/docs/sidebars.js index 5cc9e490..50387c1a 100644 --- a/sdk/apps/docs/sidebars.js +++ b/sdk/apps/docs/sidebars.js @@ -45,6 +45,13 @@ const sidebars = { collapsed: true, items: ['aptos/start', 'aptos/connect', 'aptos/sign_transaction', 'aptos/events'] }, + { + type: 'category', + className: 'drop movement-dropdown', + label: 'Movement', + collapsed: true, + items: ['movement/start', 'movement/connect', 'movement/sign_transaction', 'movement/events'] + }, { type: 'category', label: 'Customization', diff --git a/sdk/apps/docs/src/css/custom.css b/sdk/apps/docs/src/css/custom.css index b7ce9cc3..ed05fb40 100644 --- a/sdk/apps/docs/src/css/custom.css +++ b/sdk/apps/docs/src/css/custom.css @@ -158,6 +158,10 @@ img[src*='#connectImage'] { background-image: url('https://registry.nightly.app/networks/aptos.png'); } +.movement-dropdown > div::before { + background-image: url('https://img.cryptorank.io/coins/movement_labs1694616517738.png'); +} + .highlight-template { padding: 30px; border-radius: 10px; @@ -200,38 +204,11 @@ img[src*='#connectImage'] { .aptos_navlink::before { background-image: url('https://registry.nightly.app/networks/aptos.png'); } -/* -.navbar__items > .navlink { - display: flex; - flex-direction: row; - align-items: center; - gap: 5px; -} - -.navbar__items > .navlink::before { - content: ''; - background-size: cover; - height: 20px; - aspect-ratio: 1/1; - border-radius: 50%; -} - -.navbar__items > .solana_navlink::before { - background-image: url('https://upload.wikimedia.org/wikipedia/en/b/b9/Solana_logo.png'); -} -.navbar__items > .sui_navlink::before { - background-image: url('https://registry.nightly.app/networks/sui.png'); +.movement_navlink::before { + background-image: url('https://img.cryptorank.io/coins/movement_labs1694616517738.png'); } -.navbar__items > .substrate_navlink::before { - background-image: url('https://registry.nightly.app/networks/polkadot.png'); -} - -.navbar__items > .aptos_navlink::before { - background-image: url('https://registry.nightly.app/networks/aptos.png'); -} */ - @media screen and (max-width: 996px) { .navlink { display: none !important; From 5b5b5c565c5b0d904789421d93828e9582d97d43 Mon Sep 17 00:00:00 2001 From: LukassF Date: Thu, 9 May 2024 10:49:59 +0200 Subject: [PATCH 2/4] update pnpm lock --- sdk/pnpm-lock.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/pnpm-lock.yaml b/sdk/pnpm-lock.yaml index adf802d2..1c353dd8 100644 --- a/sdk/pnpm-lock.yaml +++ b/sdk/pnpm-lock.yaml @@ -95,16 +95,16 @@ importers: specifier: 0.0.29 version: link:../../packages/sui '@nightlylabs/wallet-selector-aptos': - specifier: 0.1.0 + specifier: 0.1.1 version: link:../../packages/selector-aptos '@nightlylabs/wallet-selector-base': specifier: ^0.4.0 version: link:../../packages/selector-base '@nightlylabs/wallet-selector-polkadot': - specifier: 0.2.4 + specifier: 0.2.5 version: link:../../packages/selector-polkadot '@nightlylabs/wallet-selector-solana': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/selector-solana '@nightlylabs/wallet-selector-sui': specifier: 0.3.1 From d5d51c64f601ab39c52e095f1611f133476cba04 Mon Sep 17 00:00:00 2001 From: LukassF Date: Thu, 9 May 2024 11:10:40 +0200 Subject: [PATCH 3/4] fix naming --- sdk/apps/docs/docs/movement/start.md | 4 ++++ sdk/apps/docs/docs/start.md | 2 +- sdk/apps/docs/docusaurus.config.js | 4 ++-- sdk/apps/docs/sidebars.js | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sdk/apps/docs/docs/movement/start.md b/sdk/apps/docs/docs/movement/start.md index 9fd459bd..3d3860b5 100644 --- a/sdk/apps/docs/docs/movement/start.md +++ b/sdk/apps/docs/docs/movement/start.md @@ -5,6 +5,10 @@ slug: movement/start ### Web template +:::info +Movement M1 network relies heavily on the [Aptos](../../aptos/aptos/start) network, so many functionalities are shared. +::: +
**To get started with movement, use the source code of the template below, and follow the installation instructions.** diff --git a/sdk/apps/docs/docs/start.md b/sdk/apps/docs/docs/start.md index 2c8c83d1..968846b2 100644 --- a/sdk/apps/docs/docs/start.md +++ b/sdk/apps/docs/docs/start.md @@ -22,6 +22,6 @@ slug: /start - Movement + Movement M1
diff --git a/sdk/apps/docs/docusaurus.config.js b/sdk/apps/docs/docusaurus.config.js index 56d2cc9f..3968f2f9 100644 --- a/sdk/apps/docs/docusaurus.config.js +++ b/sdk/apps/docs/docusaurus.config.js @@ -86,7 +86,7 @@ const config = { }, { to: 'docs/movement/movement/start', - label: 'Movement', + label: 'Movement M1', className: 'network_navlink movement_navlink' } ] @@ -112,7 +112,7 @@ const config = { { href: 'https://sui-web3-template.nightly.app', label: 'Sui template' }, { href: 'https://aleph-zero-web3-template.nightly.app', label: 'Substrate template' }, { href: 'https://aptos-web3-template.vercel.app', label: 'Aptos template' }, - { href: 'https://movement-web3-template.vercel.app', label: 'Movement template' } + { href: 'https://movement-web3-template.vercel.app', label: 'Movement M1 template' } ] }, { diff --git a/sdk/apps/docs/sidebars.js b/sdk/apps/docs/sidebars.js index 50387c1a..82bac2a8 100644 --- a/sdk/apps/docs/sidebars.js +++ b/sdk/apps/docs/sidebars.js @@ -48,7 +48,7 @@ const sidebars = { { type: 'category', className: 'drop movement-dropdown', - label: 'Movement', + label: 'Movement M1', collapsed: true, items: ['movement/start', 'movement/connect', 'movement/sign_transaction', 'movement/events'] }, From b67b1dd7bb10c51b5823fc9d85bae40efc1db8d2 Mon Sep 17 00:00:00 2001 From: LukassF Date: Wed, 15 May 2024 13:41:32 +0200 Subject: [PATCH 4/4] add current wallet getter for solana --- sdk/packages/selector-base/src/types.ts | 5 +- sdk/packages/selector-solana/src/adapter.ts | 58 ++++++++++++++++----- 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/sdk/packages/selector-base/src/types.ts b/sdk/packages/selector-base/src/types.ts index 39676310..c745c859 100644 --- a/sdk/packages/selector-base/src/types.ts +++ b/sdk/packages/selector-base/src/types.ts @@ -1,8 +1,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 { WalletMetadata } from '../../../bindings/WalletMetadata' +import { type WalletType } from '../../../bindings/WalletType' export { type WalletMetadata } from '../../../bindings/WalletMetadata' export interface Adapter { @@ -29,6 +29,9 @@ export interface IWalletListItem standardWallet?: Wallet } +export interface ISelectedWallet + extends Pick {} + export interface NetworkData { name: string icon: string diff --git a/sdk/packages/selector-solana/src/adapter.ts b/sdk/packages/selector-solana/src/adapter.ts index 6cccc3cb..3b71ecfc 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({ walletName }) 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({ walletName }) + 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,17 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { throw error } } + + setSelectedWallet = ({ walletName = 'Nightly', isRemote = false }) => { + const wallet = this.walletsList.find((wallet) => wallet.name === walletName) + if (wallet) { + this._selectedWallet = { + name: wallet.name, + image: wallet.image, + homepage: wallet.homepage, + slug: wallet.slug, + walletType: isRemote ? 'mobile' : wallet.walletType + } + } + } }