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 new method to dialogs snap #3173

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './custom';
export * from './require-scroll-content';
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
Box,
Button,
Container,
Footer,
Text,
type SnapComponent,
} from '@metamask/snaps-sdk/jsx';

/**
* Long content that requires scrolling.
*
* @returns The long content component.
*/
export const RequireScrollContent: SnapComponent = () => (
<Container>
<Box>
<Text>Lorem ipsum dolor sit amet.</Text>
<Text>Lorem ipsum dolor sit amet.</Text>
<Text>Lorem ipsum dolor sit amet.</Text>
<Text>Lorem ipsum dolor sit amet.</Text>
<Text>Lorem ipsum dolor sit amet.</Text>
<Text>Lorem ipsum dolor sit amet.</Text>
<Text>Lorem ipsum dolor sit amet.</Text>
<Text>Lorem ipsum dolor sit amet.</Text>
<Text>Lorem ipsum dolor sit amet.</Text>
<Text>Lorem ipsum dolor sit amet.</Text>
<Text>Lorem ipsum dolor sit amet.</Text>
<Text>Lorem ipsum dolor sit amet.</Text>
<Text>Lorem ipsum dolor sit amet.</Text>
<Text>Lorem ipsum dolor sit amet.</Text>
</Box>
<Footer>
<Button name="reject">Reject</Button>
<Button name="accept">Yes</Button>
Comment on lines +34 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these buttons actually close the dialog?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, you want me to hook them up?

</Footer>
</Container>
);
12 changes: 9 additions & 3 deletions packages/examples/packages/dialogs/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import {
UserInputEventType,
} from '@metamask/snaps-sdk';

import { CustomDialog } from './components';
import { CustomDialog, RequireScrollContent } from './components';

/**
* Handle incoming JSON-RPC requests from the dapp, sent through the
* `wallet_invokeSnap` method. This handler handles three methods, one for each
* type of dialog:
* `wallet_invokeSnap` method. This handler handles four methods:
*
* - `showAlert`: Show an alert dialog.
* - `showConfirmation`: Show a confirmation dialog.
* - `showPrompt`: Show a prompt dialog.
* - `showCustom`: Show a custom dialog with the resolution handled by the snap.
* - `showRequireScrollContent`: Show a custom dialog with content that requires scrolling.
*
* The dialogs are shown using the [`snap_dialog`](https://docs.metamask.io/snaps/reference/rpc-api/#snap_dialog)
* method.
Expand Down Expand Up @@ -90,6 +90,12 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
},
});

case 'showRequireScrollContent':
return snap.request({
method: 'snap_dialog',
params: { content: <RequireScrollContent /> },
});

default:
throw new MethodNotFoundError({ method: request.method });
}
Expand Down
13 changes: 13 additions & 0 deletions packages/test-snaps/src/features/snaps/dialogs/Dialogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export const Dialogs: FunctionComponent = () => {
}).catch(logError);
};

const handleSubmitRequireScrollContent = () => {
invokeSnap({
snapId,
method: 'showRequireScrollContent',
}).catch(logError);
};
return (
<Snap
name="Dialogs Snap"
Expand Down Expand Up @@ -80,6 +86,13 @@ export const Dialogs: FunctionComponent = () => {
>
Custom
</Button>
<Button
id="triggerRequireScrollContentButton"
onClick={handleSubmitRequireScrollContent}
disabled={isLoading}
>
Require Scroll Content
</Button>
</ButtonGroup>

<Result>
Expand Down
Loading