Skip to content

Commit 361cd5b

Browse files
authored
fix: Allow null in the endowment:assets handlers return value (#3056)
1 parent 8126f3b commit 361cd5b

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

packages/examples/packages/browserify-plugin/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": "GI7+exBM57/V+zc9afQYloOJkf31QC4QQ4J/FCjTkp0=",
10+
"shasum": "h2/tYCy6l8S2zP9EdqxHKc0WSftxxnkP60i8d58vbno=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/examples/packages/browserify/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": "kVPM+Ft1gxNWF59oCgW0MRN1DuA7kVyXwIdMbGec3aI=",
10+
"shasum": "5mzSECxLy9lFHEwzmvRpjs0xL2TG0kTR2QXIjjavRTo=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/snaps-controllers/src/snaps/SnapController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3689,7 +3689,7 @@ export class SnapController extends BaseController<
36893689
const { assets: requestedAssets } = requestedParams;
36903690

36913691
const filteredAssets = Object.keys(assets).reduce<
3692-
Record<CaipAssetType, FungibleAssetMetadata>
3692+
Record<CaipAssetType, FungibleAssetMetadata | null>
36933693
>((accumulator, assetType) => {
36943694
const castAssetType = assetType as CaipAssetType;
36953695
const isValid =

packages/snaps-sdk/src/types/handlers/assets-conversion.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
string,
66
optional,
77
record,
8+
nullable,
89
} from '@metamask/superstruct';
910
import { CaipAssetTypeStruct, type CaipAssetType } from '@metamask/utils';
1011

@@ -17,7 +18,7 @@ export const AssetConversionStruct = object({
1718
export const OnAssetsConversionResponseStruct = object({
1819
conversionRates: record(
1920
CaipAssetTypeStruct,
20-
record(CaipAssetTypeStruct, AssetConversionStruct),
21+
record(CaipAssetTypeStruct, nullable(AssetConversionStruct)),
2122
),
2223
});
2324

@@ -40,11 +41,11 @@ export type OnAssetsConversionHandler = (
4041
/**
4142
* The response from the conversion query, containing rates about each requested asset pair.
4243
*
43-
* @property conversionRates - A nested object with two CAIP-19 keys that contains a conversion rate between the two keys.
44+
* @property conversionRates - A nested object with two CAIP-19 keys that contains a conversion rate or null between the two keys.
4445
*/
4546
export type OnAssetsConversionResponse = {
4647
conversionRates: Record<
4748
CaipAssetType,
48-
Record<CaipAssetType, AssetConversion>
49+
Record<CaipAssetType, AssetConversion | null>
4950
>;
5051
};

packages/snaps-sdk/src/types/handlers/assets-lookup.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
refine,
99
string,
1010
record,
11+
nullable,
1112
} from '@metamask/superstruct';
1213
import {
1314
assert,
@@ -46,7 +47,7 @@ export const FungibleAssetMetadataStruct = object({
4647
});
4748

4849
export const OnAssetsLookupResponseStruct = object({
49-
assets: record(CaipAssetTypeStruct, FungibleAssetMetadataStruct),
50+
assets: record(CaipAssetTypeStruct, nullable(FungibleAssetMetadataStruct)),
5051
});
5152

5253
export type FungibleAssetMetadata = Infer<typeof FungibleAssetMetadataStruct>;
@@ -68,8 +69,8 @@ export type OnAssetsLookupHandler = (
6869
/**
6970
* The response from the query, containing metadata about each requested asset.
7071
*
71-
* @property assets - An object containing a mapping between the CAIP-19 key and a metadata object.
72+
* @property assets - An object containing a mapping between the CAIP-19 key and a metadata object or null.
7273
*/
7374
export type OnAssetsLookupResponse = {
74-
assets: Record<CaipAssetType, FungibleAssetMetadata>;
75+
assets: Record<CaipAssetType, FungibleAssetMetadata | null>;
7576
};

0 commit comments

Comments
 (0)