1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-09 07:25:19 +02:00

fix json parsing issue in image-loader

This commit is contained in:
Tyler Myracle 2024-01-13 15:19:58 -06:00
parent 9ebc9face6
commit 7267c30fc9
2 changed files with 19 additions and 1 deletions

View file

@ -59,6 +59,8 @@ export function AddFirstAccount({ title, onNext }: StepProps) {
loader={BrowserUtil.enhancerizerLoader} loader={BrowserUtil.enhancerizerLoader}
src={`financial-institutions/white/${src}.svg`} src={`financial-institutions/white/${src}.svg`}
alt={name} alt={name}
height={96}
width={96}
/> />
</div> </div>
))} ))}

View file

@ -1,7 +1,23 @@
import type { ImageLoaderProps } from 'next/legacy/image' import type { ImageLoaderProps } from 'next/legacy/image'
function isJSON(str: string): boolean {
try {
JSON.parse(str)
return true
} catch (e) {
return false
}
}
export function enhancerizerLoader({ src, width }: ImageLoaderProps): string { export function enhancerizerLoader({ src, width }: ImageLoaderProps): string {
const parsed = JSON.parse(src) as { [key: string]: string | number } let parsed: { [key: string]: string | number }
if (isJSON(src)) {
parsed = JSON.parse(src)
} else {
parsed = { src }
}
parsed.width ??= width parsed.width ??= width
parsed.height ??= width parsed.height ??= width