Skip to content

Commit 27c0ade

Browse files
Remove usage of getImageComponent
1 parent d0dee92 commit 27c0ade

File tree

5 files changed

+7
-77
lines changed

5 files changed

+7
-77
lines changed

packages/examples/packages/images/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "JD232NPirmuJ0UTjZGtQx0so1T7yGKgxss+XdbqUDnA=",
10+
"shasum": "A2pzU53b9kEBkckTMFDxcPr9/lbaEsOvNUJK+rNx3/8=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/examples/packages/images/src/index.test.tsx

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect } from '@jest/globals';
22
import { installSnap, assertIsAlertDialog } from '@metamask/snaps-jest';
3-
import { DialogType } from '@metamask/snaps-sdk';
43
import { Box, Text, Image } from '@metamask/snaps-sdk/jsx';
54
import { renderSVG } from 'uqr';
65

@@ -53,49 +52,11 @@ describe('onRpcRequest', () => {
5352
});
5453

5554
describe('getCat', () => {
56-
// This test is flaky, so we disable it for now.
57-
// eslint-disable-next-line jest/no-disabled-tests
58-
it.skip('shows a cat', async () => {
59-
const { request } = await installSnap();
60-
61-
const response = request({
62-
method: 'getCat',
63-
});
64-
65-
const ui = await response.getInterface();
66-
assertIsAlertDialog(ui);
67-
68-
expect(ui).toStrictEqual(
69-
expect.objectContaining({
70-
type: DialogType.Alert,
71-
content: {
72-
type: 'panel',
73-
children: [
74-
{
75-
type: 'text',
76-
value: 'Enjoy your cat!',
77-
},
78-
{
79-
type: 'image',
80-
value: expect.any(String),
81-
},
82-
],
83-
},
84-
}),
85-
);
86-
87-
await ui.ok();
88-
89-
expect(await response).toRespondWith(null);
90-
});
91-
});
92-
93-
describe('getCatExternal', () => {
9455
it('shows a cat using an external URL', async () => {
9556
const { request } = await installSnap();
9657

9758
const response = request({
98-
method: 'getCatExternal',
59+
method: 'getCat',
9960
});
10061

10162
const ui = await response.getInterface();

packages/examples/packages/images/src/index.tsx

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import type { OnRpcRequestHandler } from '@metamask/snaps-sdk';
2-
import {
3-
DialogType,
4-
getImageComponent,
5-
MethodNotFoundError,
6-
} from '@metamask/snaps-sdk';
2+
import { DialogType, MethodNotFoundError } from '@metamask/snaps-sdk';
73
import { Box, Text, Image } from '@metamask/snaps-sdk/jsx';
84
import { renderSVG } from 'uqr';
95

@@ -24,10 +20,8 @@ type GetQrCodeParams = {
2420
* `wallet_invokeSnap` method. This handler handles two methods:
2521
*
2622
* - `getQrCode`: Show a QR code to the user. The QR code is generated using
27-
* the `uqr` library, and rendered using the `image` component.
28-
* - `getCat`: Show a cat to the user. The cat image is fetched using the
29-
* `getImageComponent` helper. The helper returns an `image` component, which
30-
* can be rendered in a Snap dialog, for example.
23+
* the `uqr` library, and rendered using the `Image` component.
24+
* - `getCat`: Show a cat to the user using an external image.
3125
*
3226
* @param params - The request parameters.
3327
* @param params.request - The JSON-RPC request object.
@@ -42,7 +36,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
4236
const { data } = request.params as GetQrCodeParams;
4337

4438
// `renderSVG` returns a `<svg>` element as a string, which can be
45-
// rendered using the `image` component.
39+
// rendered using the `Image` component.
4640
const qr = renderSVG(data);
4741

4842
return await snap.request({
@@ -60,31 +54,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
6054
}
6155

6256
case 'getCat': {
63-
return await snap.request({
64-
method: 'snap_dialog',
65-
params: {
66-
type: DialogType.Alert,
67-
content: (
68-
// The `getImageComponent` helper can also be used to fetch an image
69-
// from a URL and render it using the `Image` component.
70-
<Box>
71-
<Text>Enjoy your cat!</Text>
72-
<Image
73-
src={
74-
(
75-
await getImageComponent('https://cataas.com/cat', {
76-
width: 400,
77-
})
78-
).value
79-
}
80-
/>
81-
</Box>
82-
),
83-
},
84-
});
85-
}
86-
87-
case 'getCatExternal': {
8857
return await snap.request({
8958
method: 'snap_dialog',
9059
params: {

packages/snaps-sdk/src/images.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export type ImageOptions = {
105105
* @param options.request - The options to use when fetching the image data.
106106
* This is passed directly to `fetch`.
107107
* @returns A promise that resolves to the image data as an image component.
108+
* @deprecated Use `<Image src="external_url" />` instead. This function will be removed in a future release.
108109
*/
109110
export async function getImageComponent(
110111
url: string,

packages/test-snaps/src/features/snaps/images/Images.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export const Images: FunctionComponent = () => {
1414
testId="images"
1515
>
1616
<ShowImage name="Cat" method="getCat" />
17-
<ShowImage name="External Cat" method="getCatExternal" />
1817
<ShowImage name="SVG" method="getSvgIcon" />
1918
<ShowImage name="PNG" method="getPngIcon" />
2019
<ShowQr />

0 commit comments

Comments
 (0)