-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: [CM-683][Sale Widget] Fallback token images (#1825)
- Loading branch information
1 parent
858d53c
commit 6ab1901
Showing
11 changed files
with
104 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/checkout/widgets-lib/src/components/TokenImage/TokenImage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useMemo, useState } from 'react'; | ||
import { Environment } from '@imtbl/config'; | ||
import { getDefaultTokenImage } from 'lib/utils'; | ||
import { WidgetTheme } from '@imtbl/checkout-sdk'; | ||
|
||
type ImageProps = { | ||
name?: string; | ||
src?: string; | ||
theme?: WidgetTheme; | ||
environment?: Environment; | ||
defaultImage?: string; | ||
} & ( | ||
| { defaultImage: string; theme?: WidgetTheme; environment?: Environment } | ||
| { defaultImage?: never; theme: WidgetTheme; environment: Environment } | ||
); | ||
|
||
export function TokenImage({ | ||
src, | ||
name, | ||
environment, | ||
theme, | ||
defaultImage, | ||
...forwardedProps | ||
}: ImageProps) { | ||
const [error, setError] = useState<boolean>(false); | ||
const url = useMemo( | ||
() => (!src || error | ||
? defaultImage | ||
|| (theme && getDefaultTokenImage(environment, theme)) | ||
|| '' | ||
: src), | ||
[src, error], | ||
); | ||
|
||
return ( | ||
<img | ||
src={url} | ||
alt={name} | ||
onError={() => setError(true)} | ||
{...forwardedProps} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters