From 10d32b7d0d41a62a3d27d5aa74340afac523c2a8 Mon Sep 17 00:00:00 2001
From: Mikhala <122326421+imx-mikhala@users.noreply.github.com>
Date: Wed, 21 Feb 2024 14:32:11 +0800
Subject: [PATCH] fix: WT-2132 Use default token images for tokens without
icons (#1501)
---
.../components/CoinSelector/CoinSelector.tsx | 4 +-
.../CoinSelector/CoinSelectorOption.tsx | 4 +-
.../SelectForm/SelectForm.cy.tsx | 11 ++++
.../FormComponents/SelectForm/SelectForm.tsx | 5 ++
.../SelectInput/SelectInput.tsx | 3 +
.../Transactions/TransactionItem.tsx | 4 +-
.../TransactionItemWithdrawPending.tsx | 4 +-
.../Transactions/TransactionList.tsx | 4 ++
.../components/Transactions/Transactions.tsx | 4 +-
.../checkout/widgets-lib/src/lib/utils.ts | 11 +++-
.../src/widgets/bridge/BridgeWidget.tsx | 7 ++-
.../widgets/bridge/components/BridgeForm.tsx | 3 +
.../src/widgets/bridge/views/Bridge.tsx | 4 +-
.../widgets/swap/components/SwapForm.cy.tsx | 56 +++++++++++--------
.../src/widgets/swap/components/SwapForm.tsx | 10 +++-
.../src/widgets/swap/views/SwapCoins.tsx | 14 +++--
.../src/widgets/wallet/WalletWidget.tsx | 3 +-
.../components/BalanceItem/BalanceItem.cy.tsx | 13 +++++
.../components/BalanceItem/BalanceItem.tsx | 9 ++-
.../TokenBalanceList/TokenBalanceList.cy.tsx | 4 ++
.../TokenBalanceList/TokenBalanceList.tsx | 4 ++
.../wallet/views/WalletBalances.cy.tsx | 14 ++---
.../widgets/wallet/views/WalletBalances.tsx | 5 +-
23 files changed, 149 insertions(+), 51 deletions(-)
diff --git a/packages/checkout/widgets-lib/src/components/CoinSelector/CoinSelector.tsx b/packages/checkout/widgets-lib/src/components/CoinSelector/CoinSelector.tsx
index 57fb2f2208..b1769d17e1 100644
--- a/packages/checkout/widgets-lib/src/components/CoinSelector/CoinSelector.tsx
+++ b/packages/checkout/widgets-lib/src/components/CoinSelector/CoinSelector.tsx
@@ -12,13 +12,14 @@ type CoinSelectorProps = {
onCloseDrawer?: () => void;
heading: string;
options: CoinSelectorOptionProps[];
+ defaultTokenImage: string;
optionsLoading?: boolean;
children?: any;
visible?: boolean;
};
export function CoinSelector({
- heading, options, optionsLoading, children, onCloseDrawer, visible,
+ heading, options, defaultTokenImage, optionsLoading, children, onCloseDrawer, visible,
}: CoinSelectorProps) {
const { t } = useTranslation();
return (
@@ -52,6 +53,7 @@ export function CoinSelector({
name={name}
symbol={symbol}
balance={balance}
+ defaultTokenImage={defaultTokenImage}
/>
))}
diff --git a/packages/checkout/widgets-lib/src/components/CoinSelector/CoinSelectorOption.tsx b/packages/checkout/widgets-lib/src/components/CoinSelector/CoinSelectorOption.tsx
index 807e76b19e..117d81f4b1 100644
--- a/packages/checkout/widgets-lib/src/components/CoinSelector/CoinSelectorOption.tsx
+++ b/packages/checkout/widgets-lib/src/components/CoinSelector/CoinSelectorOption.tsx
@@ -6,6 +6,7 @@ export interface CoinSelectorOptionProps {
id: string;
name: string;
icon?: AllIconKeys | string;
+ defaultTokenImage: string;
symbol: string;
onClick?: () => void
balance?: {
@@ -15,7 +16,7 @@ export interface CoinSelectorOptionProps {
}
export function CoinSelectorOption({
- onClick, icon, name, symbol, balance, testId, id,
+ onClick, icon, name, symbol, balance, defaultTokenImage, testId, id,
}: CoinSelectorOptionProps) {
const { t } = useTranslation();
@@ -26,6 +27,7 @@ export function CoinSelectorOption({
)}
diff --git a/packages/checkout/widgets-lib/src/components/FormComponents/SelectForm/SelectForm.cy.tsx b/packages/checkout/widgets-lib/src/components/FormComponents/SelectForm/SelectForm.cy.tsx
index b87f036670..03b047e537 100644
--- a/packages/checkout/widgets-lib/src/components/FormComponents/SelectForm/SelectForm.cy.tsx
+++ b/packages/checkout/widgets-lib/src/components/FormComponents/SelectForm/SelectForm.cy.tsx
@@ -15,16 +15,19 @@ describe('SelectForm', () => {
id: 'imx',
name: 'ImmutableX',
symbol: 'IMX',
+ defaultTokenImage: 'default-token-image',
},
{
id: 'eth',
name: 'Ethereum',
symbol: 'ETH',
+ defaultTokenImage: 'default-token-image',
},
]}
onSelectChange={() => {}}
coinSelectorHeading="Select coin"
selectedOption="imx"
+ defaultTokenImage="default-token-image"
/>
,
);
@@ -41,15 +44,18 @@ describe('SelectForm', () => {
id: 'imx',
name: 'ImmutableX',
symbol: 'IMX',
+ defaultTokenImage: 'default-token-image',
},
{
id: 'eth',
name: 'Ethereum',
symbol: 'ETH',
+ defaultTokenImage: 'default-token-image',
},
]}
onSelectChange={() => {}}
coinSelectorHeading="Select coin"
+ defaultTokenImage="default-token-image"
/>
,
);
@@ -68,15 +74,18 @@ describe('SelectForm', () => {
id: 'imx',
name: 'ImmutableX',
symbol: 'IMX',
+ defaultTokenImage: 'default-token-image',
},
{
id: 'eth',
name: 'Ethereum',
symbol: 'ETH',
+ defaultTokenImage: 'default-token-image',
},
]}
onSelectChange={() => {}}
coinSelectorHeading="Select coin"
+ defaultTokenImage="default-token-image"
/>
,
);
@@ -91,6 +100,7 @@ describe('SelectForm', () => {
options={[]}
onSelectChange={() => {}}
coinSelectorHeading="Select coin"
+ defaultTokenImage="default-token-image"
/>
,
);
@@ -106,6 +116,7 @@ describe('SelectForm', () => {
onSelectChange={() => {}}
coinSelectorHeading="Select coin"
selectedOption="imx"
+ defaultTokenImage="default-token-image"
/>
,
);
diff --git a/packages/checkout/widgets-lib/src/components/FormComponents/SelectForm/SelectForm.tsx b/packages/checkout/widgets-lib/src/components/FormComponents/SelectForm/SelectForm.tsx
index 34f1702fe3..a280ce8fdc 100644
--- a/packages/checkout/widgets-lib/src/components/FormComponents/SelectForm/SelectForm.tsx
+++ b/packages/checkout/widgets-lib/src/components/FormComponents/SelectForm/SelectForm.tsx
@@ -17,6 +17,7 @@ interface SelectFormProps {
disabled?: boolean;
onSelectChange: (value: string) => void;
coinSelectorHeading: string;
+ defaultTokenImage: string;
}
export function SelectForm({
@@ -30,6 +31,7 @@ export function SelectForm({
disabled,
selectedOption,
coinSelectorHeading,
+ defaultTokenImage,
}: SelectFormProps) {
const [coinSelectorOpen, setCoinSelectorOpen] = useState(false);
@@ -54,6 +56,7 @@ export function SelectForm({
setCoinSelectorOpen(false)}
@@ -97,6 +100,8 @@ export function SelectForm({
)}
{option.symbol}
diff --git a/packages/checkout/widgets-lib/src/components/FormComponents/SelectInput/SelectInput.tsx b/packages/checkout/widgets-lib/src/components/FormComponents/SelectInput/SelectInput.tsx
index b98ccdfa65..56b2decaa9 100644
--- a/packages/checkout/widgets-lib/src/components/FormComponents/SelectInput/SelectInput.tsx
+++ b/packages/checkout/widgets-lib/src/components/FormComponents/SelectInput/SelectInput.tsx
@@ -30,6 +30,7 @@ interface SelectInputProps {
textInputMaxButtonClick?: () => void;
onSelectChange: (value: OptionKey) => void;
selectedOption?: OptionKey;
+ defaultTokenImage: string;
}
export function SelectInput({
@@ -54,6 +55,7 @@ export function SelectInput({
selectInputDisabled,
selectedOption,
coinSelectorHeading,
+ defaultTokenImage,
}: SelectInputProps) {
return (
@@ -68,6 +70,7 @@ export function SelectInput({
disabled={selectInputDisabled}
selectedOption={selectedOption}
coinSelectorHeading={coinSelectorHeading}
+ defaultTokenImage={defaultTokenImage}
/>
diff --git a/packages/checkout/widgets-lib/src/components/Transactions/TransactionItem.tsx b/packages/checkout/widgets-lib/src/components/Transactions/TransactionItem.tsx
index c268c45f8a..64d52c3280 100644
--- a/packages/checkout/widgets-lib/src/components/Transactions/TransactionItem.tsx
+++ b/packages/checkout/widgets-lib/src/components/Transactions/TransactionItem.tsx
@@ -22,6 +22,7 @@ type TransactionItemProps = {
fiatAmount: string,
amount: string,
icon: string,
+ defaultTokenImage: string,
};
export function TransactionItem({
@@ -31,6 +32,7 @@ export function TransactionItem({
fiatAmount,
amount,
icon,
+ defaultTokenImage,
}: TransactionItemProps) {
const { track } = useAnalytics();
@@ -77,7 +79,7 @@ export function TransactionItem({
>
@@ -786,6 +789,7 @@ export function SwapForm({ data }: SwapFromProps) {
? formatTokenOptionsId(toToken.symbol, toToken.address)
: undefined}
coinSelectorHeading={t('views.SWAP.swapForm.to.selectorTitle')}
+ defaultTokenImage={defaultTokenImage}
/>
diff --git a/packages/checkout/widgets-lib/src/widgets/swap/views/SwapCoins.tsx b/packages/checkout/widgets-lib/src/widgets/swap/views/SwapCoins.tsx
index 8171445aa6..bd80a26eac 100644
--- a/packages/checkout/widgets-lib/src/widgets/swap/views/SwapCoins.tsx
+++ b/packages/checkout/widgets-lib/src/widgets/swap/views/SwapCoins.tsx
@@ -93,12 +93,14 @@ export function SwapCoins({
justifyContent: 'space-between',
}}
>
-
)}
{viewState.view.type === WalletWidgetViews.WALLET_BALANCES && (
-
+
)}
{viewState.view.type === WalletWidgetViews.SETTINGS && }
{viewState.view.type === WalletWidgetViews.COIN_INFO && (
diff --git a/packages/checkout/widgets-lib/src/widgets/wallet/components/BalanceItem/BalanceItem.cy.tsx b/packages/checkout/widgets-lib/src/widgets/wallet/components/BalanceItem/BalanceItem.cy.tsx
index c25cd3a921..f41e86c834 100644
--- a/packages/checkout/widgets-lib/src/widgets/wallet/components/BalanceItem/BalanceItem.cy.tsx
+++ b/packages/checkout/widgets-lib/src/widgets/wallet/components/BalanceItem/BalanceItem.cy.tsx
@@ -7,6 +7,7 @@ import {
WalletProviderName,
IMTBLWidgetEvents,
GetBalanceResult,
+ WidgetTheme,
} from '@imtbl/checkout-sdk';
import { cy } from 'local-cypress';
import { Environment } from '@imtbl/config';
@@ -77,6 +78,7 @@ describe('BalanceItem', () => {
{}}
+ theme={WidgetTheme.DARK}
/>
,
@@ -120,6 +122,7 @@ describe('BalanceItem', () => {
{}}
+ theme={WidgetTheme.DARK}
/>
,
@@ -156,6 +159,7 @@ describe('BalanceItem', () => {
{}}
+ theme={WidgetTheme.DARK}
/>
,
@@ -196,6 +200,7 @@ describe('BalanceItem', () => {
{}}
+ theme={WidgetTheme.DARK}
/>
,
@@ -236,6 +241,7 @@ describe('BalanceItem', () => {
{}}
+ theme={WidgetTheme.DARK}
/>
,
@@ -286,6 +292,7 @@ describe('BalanceItem', () => {
{}}
+ theme={WidgetTheme.DARK}
/>
,
@@ -347,6 +354,7 @@ describe('BalanceItem', () => {
{}}
+ theme={WidgetTheme.DARK}
/>
,
@@ -388,6 +396,7 @@ describe('BalanceItem', () => {
{}}
+ theme={WidgetTheme.DARK}
/>
,
@@ -428,6 +437,7 @@ describe('BalanceItem', () => {
{}}
+ theme={WidgetTheme.DARK}
/>
,
@@ -455,6 +465,7 @@ describe('BalanceItem', () => {
{}}
+ theme={WidgetTheme.DARK}
/>
,
@@ -506,6 +517,7 @@ describe('BalanceItem', () => {
{}}
+ theme={WidgetTheme.DARK}
/>
,
@@ -534,6 +546,7 @@ describe('BalanceItem', () => {
{}}
+ theme={WidgetTheme.DARK}
/>
,
diff --git a/packages/checkout/widgets-lib/src/widgets/wallet/components/BalanceItem/BalanceItem.tsx b/packages/checkout/widgets-lib/src/widgets/wallet/components/BalanceItem/BalanceItem.tsx
index 55035d3e98..f8e8f9dc6d 100644
--- a/packages/checkout/widgets-lib/src/widgets/wallet/components/BalanceItem/BalanceItem.tsx
+++ b/packages/checkout/widgets-lib/src/widgets/wallet/components/BalanceItem/BalanceItem.tsx
@@ -2,13 +2,15 @@ import { Heading, MenuItem } from '@biom3/react';
import {
useContext, useEffect, useMemo, useState,
} from 'react';
-import { IMTBLWidgetEvents, TokenFilterTypes, TokenInfo } from '@imtbl/checkout-sdk';
+import {
+ IMTBLWidgetEvents, TokenFilterTypes, TokenInfo, WidgetTheme,
+} from '@imtbl/checkout-sdk';
import { ShowMenuItem } from './BalanceItemStyles';
import { BalanceInfo } from '../../functions/tokenBalances';
import { WalletContext } from '../../context/WalletContext';
import { orchestrationEvents } from '../../../../lib/orchestrationEvents';
import { getL1ChainId, getL2ChainId } from '../../../../lib/networkUtils';
-import { formatZeroAmount, tokenValueFormat } from '../../../../lib/utils';
+import { formatZeroAmount, getDefaultTokenImage, tokenValueFormat } from '../../../../lib/utils';
import { ConnectLoaderContext } from '../../../../context/connect-loader-context/ConnectLoaderContext';
import { isPassportProvider } from '../../../../lib/providerUtils';
import { EventTargetContext } from '../../../../context/event-target-context/EventTargetContext';
@@ -16,11 +18,13 @@ import { UserJourney, useAnalytics } from '../../../../context/analytics-provide
export interface BalanceItemProps {
balanceInfo: BalanceInfo;
+ theme: WidgetTheme;
bridgeToL2OnClick: (address?: string) => void;
}
export function BalanceItem({
balanceInfo,
+ theme,
bridgeToL2OnClick,
}: BalanceItemProps) {
const { connectLoaderState } = useContext(ConnectLoaderContext);
@@ -86,6 +90,7 @@ export function BalanceItem({
{balanceInfo.symbol}
diff --git a/packages/checkout/widgets-lib/src/widgets/wallet/components/TokenBalanceList/TokenBalanceList.cy.tsx b/packages/checkout/widgets-lib/src/widgets/wallet/components/TokenBalanceList/TokenBalanceList.cy.tsx
index 4e26db16ee..8031b1fd20 100644
--- a/packages/checkout/widgets-lib/src/widgets/wallet/components/TokenBalanceList/TokenBalanceList.cy.tsx
+++ b/packages/checkout/widgets-lib/src/widgets/wallet/components/TokenBalanceList/TokenBalanceList.cy.tsx
@@ -1,6 +1,7 @@
import { describe, it, cy } from 'local-cypress';
import { mount } from 'cypress/react18';
import { ViewContextTestComponent } from 'context/view-context/test-components/ViewContextTestComponent';
+import { WidgetTheme } from '@imtbl/checkout-sdk';
import { TokenBalanceList } from './TokenBalanceList';
import { cyIntercept, cySmartGet } from '../../../../lib/testUtils';
import { ZERO_BALANCE_STRING } from '../../../../lib';
@@ -17,6 +18,7 @@ describe('TokenBalanceList', () => {
{}}
+ theme={WidgetTheme.DARK}
/>
,
);
@@ -37,6 +39,7 @@ describe('TokenBalanceList', () => {
},
]}
bridgeToL2OnClick={() => {}}
+ theme={WidgetTheme.DARK}
/>
,
);
@@ -71,6 +74,7 @@ describe('TokenBalanceList', () => {
},
]}
bridgeToL2OnClick={() => {}}
+ theme={WidgetTheme.DARK}
/>
,
);
diff --git a/packages/checkout/widgets-lib/src/widgets/wallet/components/TokenBalanceList/TokenBalanceList.tsx b/packages/checkout/widgets-lib/src/widgets/wallet/components/TokenBalanceList/TokenBalanceList.tsx
index d3b209a9b8..5ae2b3e8c0 100644
--- a/packages/checkout/widgets-lib/src/widgets/wallet/components/TokenBalanceList/TokenBalanceList.tsx
+++ b/packages/checkout/widgets-lib/src/widgets/wallet/components/TokenBalanceList/TokenBalanceList.tsx
@@ -1,5 +1,6 @@
import { Body, Box } from '@biom3/react';
import { useTranslation } from 'react-i18next';
+import { WidgetTheme } from '@imtbl/checkout-sdk';
import { BalanceItem } from '../BalanceItem/BalanceItem';
import { tokenBalanceListStyle, noTokensStyle } from './TokenBalanceListStyles';
import { BalanceInfo } from '../../functions/tokenBalances';
@@ -12,11 +13,13 @@ const filterZeroBalances = (balanceInfoItems: BalanceInfo[]) => balanceInfoItems
interface TokenBalanceListProps {
balanceInfoItems: BalanceInfo[];
+ theme: WidgetTheme;
bridgeToL2OnClick: (address?: string) => void;
}
export function TokenBalanceList({
balanceInfoItems,
+ theme,
bridgeToL2OnClick,
}: TokenBalanceListProps) {
const { t } = useTranslation();
@@ -35,6 +38,7 @@ export function TokenBalanceList({
key={balance.id}
balanceInfo={balance}
bridgeToL2OnClick={bridgeToL2OnClick}
+ theme={theme}
/>
))}
diff --git a/packages/checkout/widgets-lib/src/widgets/wallet/views/WalletBalances.cy.tsx b/packages/checkout/widgets-lib/src/widgets/wallet/views/WalletBalances.cy.tsx
index a7929e8d89..70c096de0a 100644
--- a/packages/checkout/widgets-lib/src/widgets/wallet/views/WalletBalances.cy.tsx
+++ b/packages/checkout/widgets-lib/src/widgets/wallet/views/WalletBalances.cy.tsx
@@ -101,7 +101,7 @@ describe('WalletBalances', () => {
initialStateOverride={baseWalletState}
cryptoConversionsOverride={cryptoConversions}
>
-
+
,
@@ -121,7 +121,7 @@ describe('WalletBalances', () => {
initialStateOverride={baseWalletState}
cryptoConversionsOverride={cryptoConversions}
>
-
+
,
@@ -143,7 +143,7 @@ describe('WalletBalances', () => {
initialStateOverride={baseWalletState}
cryptoConversionsOverride={cryptoConversions}
>
-
+
,
@@ -165,7 +165,7 @@ describe('WalletBalances', () => {
initialStateOverride={{ ...baseWalletState, tokenBalances: [] }}
cryptoConversionsOverride={cryptoConversions}
>
-
+
,
@@ -222,7 +222,7 @@ describe('WalletBalances', () => {
{} }}
>
-
+
@@ -250,7 +250,7 @@ describe('WalletBalances', () => {
{} }}
>
-
+
@@ -284,7 +284,7 @@ describe('WalletBalances', () => {
{} }}
>
-
+
diff --git a/packages/checkout/widgets-lib/src/widgets/wallet/views/WalletBalances.tsx b/packages/checkout/widgets-lib/src/widgets/wallet/views/WalletBalances.tsx
index ffdcece2bf..6d6050656c 100644
--- a/packages/checkout/widgets-lib/src/widgets/wallet/views/WalletBalances.tsx
+++ b/packages/checkout/widgets-lib/src/widgets/wallet/views/WalletBalances.tsx
@@ -2,7 +2,7 @@ import { Box, ButtCon, MenuItem } from '@biom3/react';
import {
useContext, useEffect, useMemo, useState,
} from 'react';
-import { IMTBLWidgetEvents } from '@imtbl/checkout-sdk';
+import { IMTBLWidgetEvents, WidgetTheme } from '@imtbl/checkout-sdk';
import { fetchTokenSymbols } from 'lib/fetchTokenSymbols';
import { CryptoFiatActions, CryptoFiatContext } from 'context/crypto-fiat-context/CryptoFiatContext';
import { ButtonNavigationStyles } from 'components/Header/HeaderStyles';
@@ -37,9 +37,11 @@ import { BalanceInfo, mapTokenBalancesWithConversions } from '../functions/token
type WalletBalancesProps = {
balancesLoading: boolean;
+ theme: WidgetTheme;
};
export function WalletBalances({
balancesLoading,
+ theme,
}: WalletBalancesProps) {
const { t } = useTranslation();
const { connectLoaderState } = useContext(ConnectLoaderContext);
@@ -188,6 +190,7 @@ export function WalletBalances({
)}