|
1 | 1 | import FS from "fs";
|
| 2 | +import sizeOf from "image-size"; |
2 | 3 | import { CW20TokenScheme } from "../scheme";
|
3 |
| -import { getChainBaseMap } from "../utils"; |
| 4 | +import { getChainBaseMap, validateImageUrl } from "../utils"; |
4 | 5 | import Path from "path";
|
5 |
| -import { Bech32Address } from "@keplr-wallet/cosmos"; |
| 6 | +import { Bech32Address, ChainIdHelper } from "@keplr-wallet/cosmos"; |
6 | 7 | import { fetchTokenMetadata } from "../query";
|
7 | 8 | import { sortedJsonByKeyStringify } from "@keplr-wallet/common";
|
8 | 9 |
|
@@ -67,6 +68,29 @@ import { sortedJsonByKeyStringify } from "@keplr-wallet/common";
|
67 | 68 | )}), contract: ${validated.value.contractAddress}, chain: ${chain})`
|
68 | 69 | );
|
69 | 70 | }
|
| 71 | + |
| 72 | + if (validated.value.imageUrl) { |
| 73 | + const chainIdentifier = ChainIdHelper.parse(base.chainId).identifier; |
| 74 | + const tokenImageUrl = validateImageUrl( |
| 75 | + chainIdentifier, |
| 76 | + validated.value.imageUrl |
| 77 | + ); |
| 78 | + |
| 79 | + const dimensions = sizeOf( |
| 80 | + `images/${chainIdentifier}/${tokenImageUrl}` |
| 81 | + ); |
| 82 | + |
| 83 | + if (dimensions.type === "png") { |
| 84 | + const width = dimensions.width ?? 0; |
| 85 | + const height = dimensions.height ?? 0; |
| 86 | + |
| 87 | + if (width > 512 || height > 512) { |
| 88 | + throw new Error( |
| 89 | + `Reduce image size to 512x512 or smaller (expected: 512x512, actual: ${width}x${height})` |
| 90 | + ); |
| 91 | + } |
| 92 | + } |
| 93 | + } |
70 | 94 | } else {
|
71 | 95 | throw new Error(`Invalid path: ${path}`);
|
72 | 96 | }
|
|
0 commit comments