Skip to content

Commit 2b8e872

Browse files
committed
simplify selectiveUnions
1 parent eb16618 commit 2b8e872

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
CaipAccountIdStruct,
1818
CaipAssetTypeOrIdStruct,
1919
assert,
20-
hasProperty,
2120
isObject,
2221
} from '@metamask/utils';
2322
import type { CaipAssetTypeOrId } from '@metamask/utils';
@@ -80,11 +79,7 @@ export const NonFungibleAssetMetadataStruct = object({
8079
});
8180

8281
export const AssetMetadataStruct = selectiveUnion((metadata) => {
83-
if (!isObject(metadata) || !hasProperty(metadata, 'fungible')) {
84-
return union([FungibleAssetMetadataStruct, NonFungibleAssetMetadataStruct]);
85-
}
86-
87-
if (metadata.fungible) {
82+
if (isObject(metadata) && metadata.fungible) {
8883
return FungibleAssetMetadataStruct;
8984
}
9085

packages/snaps-utils/src/handlers/assets-market-data.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
import {
1313
CaipAssetTypeOrIdStruct,
1414
CaipAssetTypeStruct,
15-
hasProperty,
1615
isObject,
1716
} from '@metamask/utils';
1817

@@ -72,14 +71,7 @@ export const NonFungibleAssetMarketDataStruct = object({
7271
* A struct representing the market data for an asset, which can be either fungible or non-fungible.
7372
*/
7473
export const AssetMarketDataStruct = selectiveUnion((marketData) => {
75-
if (!isObject(marketData) || !hasProperty(marketData, 'fungible')) {
76-
return union([
77-
FungibleAssetMarketDataStruct,
78-
NonFungibleAssetMarketDataStruct,
79-
]);
80-
}
81-
82-
if (marketData.fungible) {
74+
if (isObject(marketData) && marketData.fungible) {
8375
return FungibleAssetMarketDataStruct;
8476
}
8577

0 commit comments

Comments
 (0)