Skip to content

Commit

Permalink
add: cache to SVG Address Activity (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenlejoe authored Jan 26, 2024
1 parent 7183472 commit 6ed023d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/components/Atoms/TokenAvatar/TokenAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useEffect, useMemo, useRef } from "react";
import { type TokenAvatarProps } from "@/utils/types/atoms.types";
import { GRK_SIZES } from "@/utils/constants/shared.constants";

const svgCache = new Map();

export const TokenAvatar: React.FC<TokenAvatarProps> = ({
token_url,
sub_url,
Expand Down Expand Up @@ -48,10 +50,17 @@ export const TokenAvatar: React.FC<TokenAvatarProps> = ({
useEffect(() => {
if (is_chain_logo) {
(async () => {
const response = await fetch(
token_url ?? "https://goldrush.vercel.app/icons/token.svg"
);
const data = await response.text();
let data;
if (svgCache.has(token_url)) {
data = svgCache.get(token_url);
} else {
const response = await fetch(
token_url ??
"https://goldrush.vercel.app/icons/token.svg"
);
data = await response.text();
svgCache.set(token_url, data);
}

const parser = new DOMParser();
const svg = parser.parseFromString(
Expand Down

0 comments on commit 6ed023d

Please sign in to comment.