mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-08 23:15:24 +02:00
fix json parsing issue in image-loader
This commit is contained in:
parent
9ebc9face6
commit
7267c30fc9
2 changed files with 19 additions and 1 deletions
|
@ -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>
|
||||||
))}
|
))}
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue