From cd62b956e88637d140cdd538fe3e782776b97242 Mon Sep 17 00:00:00 2001 From: sstefdev Date: Fri, 6 Dec 2024 13:27:53 +0100 Subject: [PATCH 1/3] feat: changed the initCurrencyManager --- .../src/lib/view-requests.svelte | 2 +- shared/utils/initCurrencyManager.ts | 32 ++++--------------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/packages/invoice-dashboard/src/lib/view-requests.svelte b/packages/invoice-dashboard/src/lib/view-requests.svelte index 83d65312..32060f03 100644 --- a/packages/invoice-dashboard/src/lib/view-requests.svelte +++ b/packages/invoice-dashboard/src/lib/view-requests.svelte @@ -324,7 +324,7 @@ BigInt(request.expectedAmount), currencyInfo?.decimals ?? 18 ), - currencySymbol: currencyInfo!.symbol, + currencySymbol: currencyInfo?.symbol ?? "-", paymentCurrencies, }; } diff --git a/shared/utils/initCurrencyManager.ts b/shared/utils/initCurrencyManager.ts index 7a11f226..e11048a6 100644 --- a/shared/utils/initCurrencyManager.ts +++ b/shared/utils/initCurrencyManager.ts @@ -67,37 +67,17 @@ import { formattedCurrencyConversionPairs } from './currencyConversionPairs' export function initializeCurrencyManager( customCurrencies: CurrencyTypes.CurrencyInput[] = [] ): CurrencyManager { - let currenciesToUse: any[]; - - const defaultCurrencies = CurrencyManager.getDefaultList().filter( - (currency) => defaultCurrencyIds.includes(currency.id) - ); - - currenciesToUse = defaultCurrencies; - + // If customCurrencies is provided, use only those if (customCurrencies?.length > 0) { - currenciesToUse.push(...customCurrencies); + return new CurrencyManager(customCurrencies, {}, formattedCurrencyConversionPairs); } - // Filter out duplicates based on a unique identifier - currenciesToUse = currenciesToUse.filter( - (currency, index, self) => - index === - self.findIndex((t) => { - if (currency.type === Types.RequestLogic.CURRENCY.ETH) { - return t.type === currency.type && t.network === currency.network; - } else if (currency.type === Types.RequestLogic.CURRENCY.ERC20) { - return ( - t.network === currency.network && - t.address?.toLowerCase() === currency.address?.toLowerCase() - ); - } else if (currency.type === Types.RequestLogic.CURRENCY.ISO4217) { - return t.type === currency.type && t.symbol === currency.symbol; - } - }) + // Otherwise, use default currencies + const defaultCurrencies = CurrencyManager.getDefaultList().filter( + (currency) => defaultCurrencyIds.includes(currency.id) ); - return new CurrencyManager(currenciesToUse, {}, formattedCurrencyConversionPairs); + return new CurrencyManager(defaultCurrencies, {}, formattedCurrencyConversionPairs); } export function initializeCurrencyManagerWithCurrencyIDS( From 800734eca345dd1c6f78b296bd7ee7651ff42af4 Mon Sep 17 00:00:00 2001 From: sstefdev Date: Tue, 10 Dec 2024 09:08:26 +0100 Subject: [PATCH 2/3] fix: added unknown network fallback --- shared/icons/network/network-icon.svelte | 2 +- shared/icons/unkown.svelte | 22 ++++++++++++++++++++++ shared/utils/getNetworkIcon.ts | 4 ++-- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 shared/icons/unkown.svelte diff --git a/shared/icons/network/network-icon.svelte b/shared/icons/network/network-icon.svelte index a2eaab02..27714e1c 100644 --- a/shared/icons/network/network-icon.svelte +++ b/shared/icons/network/network-icon.svelte @@ -10,7 +10,7 @@ {#if icon}
- {capitalize(network)} + {capitalize(network) || "Unknown"}
{/if} diff --git a/shared/icons/unkown.svelte b/shared/icons/unkown.svelte new file mode 100644 index 00000000..04d8d09e --- /dev/null +++ b/shared/icons/unkown.svelte @@ -0,0 +1,22 @@ + diff --git a/shared/utils/getNetworkIcon.ts b/shared/utils/getNetworkIcon.ts index c7548a25..a77c6f55 100644 --- a/shared/utils/getNetworkIcon.ts +++ b/shared/utils/getNetworkIcon.ts @@ -14,7 +14,7 @@ import OptimismIcon from "../icons/network/optimism.svelte"; import ArbitrumIcon from "../icons/network/arbitrum.svelte"; import MoonbeamIcon from "../icons/network/moonbeam.svelte"; import FantomIcon from "../icons/network/fantom.svelte"; - +import Unkown from "../icons/unkown.svelte"; export const getNetworkIcon = (network: string) => { const icons = { bsc: BscIcon, @@ -35,5 +35,5 @@ export const getNetworkIcon = (network: string) => { moonbeam: MoonbeamIcon, }; - return icons[network] || EthereumIcon; + return icons[network] || Unkown; }; From cc70506b9a2cc4eb9ab3e1e164f71bdaf519ff24 Mon Sep 17 00:00:00 2001 From: sstefdev Date: Tue, 10 Dec 2024 13:17:36 +0100 Subject: [PATCH 3/3] chore: fix typos --- shared/utils/getNetworkIcon.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shared/utils/getNetworkIcon.ts b/shared/utils/getNetworkIcon.ts index a77c6f55..a1c86560 100644 --- a/shared/utils/getNetworkIcon.ts +++ b/shared/utils/getNetworkIcon.ts @@ -14,7 +14,8 @@ import OptimismIcon from "../icons/network/optimism.svelte"; import ArbitrumIcon from "../icons/network/arbitrum.svelte"; import MoonbeamIcon from "../icons/network/moonbeam.svelte"; import FantomIcon from "../icons/network/fantom.svelte"; -import Unkown from "../icons/unkown.svelte"; +import Unknown from "../icons/unkown.svelte"; + export const getNetworkIcon = (network: string) => { const icons = { bsc: BscIcon, @@ -35,5 +36,5 @@ export const getNetworkIcon = (network: string) => { moonbeam: MoonbeamIcon, }; - return icons[network] || Unkown; + return icons[network] || Unknown; };