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:
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}
|
||||
src={`financial-institutions/white/${src}.svg`}
|
||||
alt={name}
|
||||
height={96}
|
||||
width={96}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
|
|
|
@ -1,7 +1,23 @@
|
|||
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 {
|
||||
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.height ??= width
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue