Skip to content

Commit

Permalink
Add onHomePage export
Browse files Browse the repository at this point in the history
  • Loading branch information
Montoya committed Jan 5, 2024
1 parent e398532 commit b7f0b93
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions snaps/reference/exports.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,61 @@ module.exports.onCronjob = async ({ request }) => {
```

<!--/tabs-->

## onHomePage

:::flaskOnly
:::

To build an embedded UI in MetaMask that any user can access via the Snaps menu, a Snap must export `onHomePage`.
This method is called when the user clicks the Snap name in the Snaps menu.

:::note
For MetaMask to call the Snap's `onHomePage` method, you must request the
[`endowment:page-home`](permissions.md#endowmentpage-home) permission.
:::

#### Parameters

None.

#### Returns

A content object displayed using [custom UI](../how-to/use-custom-ui.md).

#### Example

<!--tabs-->

# TypeScript

```typescript
import type { OnHomePageHandler } from '@metamask/snaps-sdk';
import { panel, text, heading } from '@metamask/snaps-sdk';

export const onHomePage: OnHomePageHandler = async () => {
return {
content: panel([
heading('Hello world!'),
text('Welcome to my Snap home page!'),
]),
};
};
```

# JavaScript

```js
import { panel, text, heading } from '@metamask/snaps-sdk';

module.exports.onHomePage = async () => {
return {
content: panel([
heading('Hello world!'),
text('Welcome to my Snap home page!'),
]),
};
};
```

<!--/tabs-->

0 comments on commit b7f0b93

Please sign in to comment.