Skip to content

Commit

Permalink
try to fix asset cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridel1e committed Jan 5, 2024
1 parent c7ea97d commit fc5dfc0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/common/constants/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fractionsToNum } from '../../utils/math';
import { makeId } from '../utils/makeId.ts';
import { DEFAULT_MINER_FEE, ERG_DECIMALS, MIN_EX_FEE } from './erg';

export const defaultMinerFee = fractionsToNum(DEFAULT_MINER_FEE, ERG_DECIMALS);
Expand All @@ -15,3 +16,5 @@ export const SlippageDecimals = 2;
export const PoolFeeMax = 0.25;

export const UI_REWARD_ADDRESS = '';

export const appId = makeId(10);
19 changes: 14 additions & 5 deletions src/components/AssetIcon/AssetIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react';
import * as React from 'react';

import { appId } from '../../common/constants/settings.ts';
import { AssetInfo } from '../../common/models/AssetInfo';
import { UnknownTokenIcon } from '../UnknownTokenIcon/UnknownTokenIcon';

Expand Down Expand Up @@ -46,15 +47,23 @@ const AssetIcon: React.FC<TokenIconProps> = ({
const [errorState, setErrorState] = useState<ErrorState | undefined>(
undefined,
);
const [assetLogoUrl, setAssetLogoUrl] = useState(asset?.icon);
const [assetLogoAltUrl, setAssetLogoAltUrl] = useState(asset?.url);
const [assetLogoUrl, setAssetLogoUrl] = useState(
asset?.icon ? `${asset?.icon}?${appId}` : asset?.icon,
);
const [assetLogoAltUrl, setAssetLogoAltUrl] = useState(
asset?.url ? `${asset?.url}?${appId}` : asset?.url,
);

useEffect(() => {
setAssetLogoUrl((prev) => {
return prev === asset?.icon ? prev : asset?.icon;
return prev === `${asset?.icon}?${appId}`
? prev
: `${asset?.icon}?${appId}`;
});
setAssetLogoAltUrl((prev) => {
return prev === asset?.url ? prev : asset?.url;
return prev === `${asset?.url}?${appId}`
? prev
: `${asset?.url}?${appId}`;
});
if (asset) {
setErrorState(undefined);
Expand Down Expand Up @@ -82,7 +91,7 @@ const AssetIcon: React.FC<TokenIconProps> = ({
}}
{...rest}
>
{errorState === ErrorState.ICON_NOT_FOUND ? (
{errorState === ErrorState.ICON_NOT_FOUND || !assetLogoAltUrl ? (
<UnknownTokenIcon asset={asset} size={MAP_SIZE_TO_NUMBER[size]} />
) : errorState === ErrorState.ALT_ICON ? (
<img
Expand Down

0 comments on commit fc5dfc0

Please sign in to comment.