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 920c94c2..93b94a8b 100644 --- a/sdk/apps/docs/docs/for_wallets/sign_message.md +++ b/sdk/apps/docs/docs/for_wallets/sign_message.md @@ -90,5 +90,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 d9684e41..bafbb422 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..c75757f2 --- /dev/null +++ b/sdk/apps/docs/docs/movement/connect.md @@ -0,0 +1,93 @@ +--- +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 + { + networkDataOverride: { // it is used to change the metadata of the NC Modal's network tab + name: 'Movement', + icon: 'https://registry.nightly.app/networks/movement.svg' + } + + } +) + +// 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..3d3860b5 --- /dev/null +++ b/sdk/apps/docs/docs/movement/start.md @@ -0,0 +1,42 @@ +--- +title: Get started with Movement +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.** + +
+ +> #### 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 12ab2556..0586fe29 100644 --- a/sdk/apps/docs/docs/start.md +++ b/sdk/apps/docs/docs/start.md @@ -17,7 +17,11 @@ slug: /start Substrate - + Aptos + + + Movement M1 + diff --git a/sdk/apps/docs/docusaurus.config.js b/sdk/apps/docs/docusaurus.config.js index b23c686c..3968f2f9 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 M1', + 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 M1 template' } ] }, { diff --git a/sdk/apps/docs/sidebars.js b/sdk/apps/docs/sidebars.js index 5cc9e490..82bac2a8 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 M1', + 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..e546204d 100644 --- a/sdk/apps/docs/src/css/custom.css +++ b/sdk/apps/docs/src/css/custom.css @@ -102,6 +102,7 @@ img[src*='#connectImage'] { transition: background-position 250ms; } .card > img { + border-radius: 50%; width: 80px; } .card:hover { @@ -158,6 +159,10 @@ img[src*='#connectImage'] { background-image: url('https://registry.nightly.app/networks/aptos.png'); } +.movement-dropdown > div::before { + background-image: url('https://registry.nightly.app/networks/movement.svg'); +} + .highlight-template { padding: 30px; border-radius: 10px; @@ -200,38 +205,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%; +.movement_navlink::before { + background-image: url('https://registry.nightly.app/networks/movement.svg'); } -.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'); -} - -.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; diff --git a/sdk/apps/modal-example/src/routes/aptos.tsx b/sdk/apps/modal-example/src/routes/aptos.tsx index ba0cf633..d9b45302 100644 --- a/sdk/apps/modal-example/src/routes/aptos.tsx +++ b/sdk/apps/modal-example/src/routes/aptos.tsx @@ -1,4 +1,9 @@ -import { AccountAuthenticator, AccountAuthenticatorEd25519, Aptos } from '@aptos-labs/ts-sdk' +import { + AccountAuthenticator, + AccountAuthenticatorEd25519, + AnyRawTransaction, + Aptos +} from '@aptos-labs/ts-sdk' import { AccountInfo, AptosSignMessageInput, UserResponseStatus } from '@aptos-labs/wallet-standard' import { NightlyConnectAptosAdapter } from '@nightlylabs/wallet-selector-aptos' import { createEffect, createSignal, onMount, Show } from 'solid-js' @@ -98,9 +103,7 @@ export default function AptosPage() { ] } }) - const signedTx = await adapter()!.signAndSubmitTransaction({ - rawTransaction: transaction.rawTransaction - }) + const signedTx = await adapter()!.signAndSubmitTransaction(transaction) // Verify the transaction was signed if (signedTx.status !== UserResponseStatus.APPROVED) { toast.error('Transaction was not approved') diff --git a/sdk/apps/modal-example/src/routes/aptosCustom.tsx b/sdk/apps/modal-example/src/routes/aptosCustom.tsx index 91e37649..e964aafa 100644 --- a/sdk/apps/modal-example/src/routes/aptosCustom.tsx +++ b/sdk/apps/modal-example/src/routes/aptosCustom.tsx @@ -127,9 +127,7 @@ export default function AptosPage() { ] } }) - const signedTx = await adapter()!.signAndSubmitTransaction({ - rawTransaction: transaction.rawTransaction - }) + const signedTx = await adapter()!.signAndSubmitTransaction(transaction) // Verify the transaction was signed if (signedTx.status !== UserResponseStatus.APPROVED) { toast.error('Transaction was not approved') diff --git a/sdk/pnpm-lock.yaml b/sdk/pnpm-lock.yaml index 82be3caa..9313cc96 100644 --- a/sdk/pnpm-lock.yaml +++ b/sdk/pnpm-lock.yaml @@ -83,12 +83,12 @@ importers: '@mysten/sui': ^1.2.1 '@nightlylabs/nightly-connect-polkadot': 0.0.16 '@nightlylabs/nightly-connect-solana': 0.0.29 - '@nightlylabs/nightly-connect-sui': 0.0.29 + '@nightlylabs/nightly-connect-sui': 0.1.0 '@nightlylabs/wallet-selector-aptos': 0.1.6 '@nightlylabs/wallet-selector-base': ^0.4.1 '@nightlylabs/wallet-selector-polkadot': 0.2.7 '@nightlylabs/wallet-selector-solana': 0.3.2 - '@nightlylabs/wallet-selector-sui': 0.3.2 + '@nightlylabs/wallet-selector-sui': 0.4.0 '@polkadot/api': ^10.10.1 '@polkadot/extension-inject': ^0.46.5 '@solana/web3.js': ^1.77.2 @@ -510,7 +510,7 @@ importers: '@mysten/sui': ^1.2.1 '@mysten/wallet-adapter-wallet-standard': ^0.8.0 '@mysten/wallet-standard': ^0.12.12 - '@nightlylabs/nightly-connect-sui': 0.0.29 + '@nightlylabs/nightly-connect-sui': 0.1.0 '@nightlylabs/wallet-selector-base': 0.4.1 '@rollup/plugin-commonjs': ^25.0.0 '@rollup/plugin-node-resolve': ^15.1.0