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 movement to docs #174

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion sdk/apps/docs/docs/customization/external_modal.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sdk/apps/docs/docs/customization/ui_overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
:::
7 changes: 6 additions & 1 deletion sdk/apps/docs/docs/for_wallets/connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ await client.connect(message)
<TabItem value="Aptos" label="Aptos">

```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
Expand All @@ -140,6 +140,11 @@ const message: Connect = {
await client.connect(message)
```

</TabItem>

<TabItem value="Movement" label="Movement">
The Build & Connect process mirrors that of Aptos.

</TabItem>
</Tabs>

Expand Down
4 changes: 4 additions & 0 deletions sdk/apps/docs/docs/for_wallets/sign_message.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,9 @@ client.on('signMessage', async (e) => {
})
```

</TabItem>

<TabItem value="Movement" label="Movement">
The process mirrors that of Aptos.
</TabItem>
</Tabs>
4 changes: 4 additions & 0 deletions sdk/apps/docs/docs/for_wallets/sign_transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,9 @@ client.on('signTransaction', async (e) => {
})
```

</TabItem>

<TabItem value="Movement" label="Movement">
The process mirrors that of Aptos.
</TabItem>
</Tabs>
93 changes: 93 additions & 0 deletions sdk/apps/docs/docs/movement/connect.md
Original file line number Diff line number Diff line change
@@ -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.
:::
41 changes: 41 additions & 0 deletions sdk/apps/docs/docs/movement/events.md
Original file line number Diff line number Diff line change
@@ -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) => {
...
})
```
77 changes: 77 additions & 0 deletions sdk/apps/docs/docs/movement/sign_transaction.md
Original file line number Diff line number Diff line change
@@ -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)
```
42 changes: 42 additions & 0 deletions sdk/apps/docs/docs/movement/start.md
Original file line number Diff line number Diff line change
@@ -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.
:::

<div class='highlight-template'>

**To get started with movement, use the source code of the template below, and follow the installation instructions.**

<br/>

> #### Preview: https://movement-web3-template.vercel.app

<br/>

> #### Source code: https://github.com/nightly-labs/movement-web3-template

</div>

<hr/>

### 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
```

:::
6 changes: 5 additions & 1 deletion sdk/apps/docs/docs/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ slug: /start
Substrate
</a>
<a href="/docs/aptos/aptos/start" class="card">
<img src="https://aptosfoundation.org/brandbook/logomark/PNG/Aptos_mark_WHT.png"/>
<img src="https://registry.nightly.app/networks/aptos.png"/>
Aptos
</a>
<a href="./movement/movement/start" class="card">
<img src="https://registry.nightly.app/networks/movement.svg"/>
Movement M1
</a>
</div>
36 changes: 7 additions & 29 deletions sdk/apps/docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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' }
]
},
{
Expand Down
7 changes: 7 additions & 0 deletions sdk/apps/docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading
Loading