Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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 packages/examples/packages/dialogs/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "fCeqfbW1isFwXBPuM3RaAEtcR3J0Lv31fQ57rFNRwfs=",
"shasum": "1ulFPvHJ5MZY1FhkQjie7usEyduFBbxDXglDXTceFa8=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
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>
</Footer>
</Container>
);
26 changes: 23 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':
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
case 'showRequireScrollContent':
case 'showLongContent':

Copy link
Member

Choose a reason for hiding this comment

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

Need to update the JSDoc too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use this naming instead ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, updated: 98d4964

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

default:
throw new MethodNotFoundError({ method: request.method });
}
Expand Down Expand Up @@ -136,6 +142,20 @@ export const onUserInput: OnUserInputHandler = async ({ id, event }) => {
break;
}

case 'accept':
await snap.request({
method: 'snap_resolveInterface',
params: { id, value: true },
});
break;

case 'reject':
await snap.request({
method: 'snap_resolveInterface',
params: { id, value: false },
});
break;

default:
break;
}
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