Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch token prices & history using new Explorer BE endpoints (rebased and fixed) #322

Merged
merged 34 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
98916f1
Port work - fetch token prices (wip)
mvaivre Nov 17, 2023
2ecc943
New endpoints work, init new prices storage
mvaivre Nov 20, 2023
4e44bf2
WIP: Dedicated slices
mvaivre Jan 2, 2024
8eb05e2
selectAlphPrice selector + lint
mvaivre Jan 2, 2024
2c59a1d
Mention that total value is only about ALPH for now
mvaivre Jan 3, 2024
212403d
Remove unused code while we wait for explorer-be amount history endpo…
mvaivre Jan 3, 2024
a0f950b
Start migrating price history from coingecko to own service
mvaivre Jan 3, 2024
4652961
History properly fetched and shown
mvaivre Jan 3, 2024
d2636e9
Add changeset
mvaivre Jan 3, 2024
a460bc5
Better naming
mvaivre Jan 9, 2024
69010c2
price => value
mvaivre Jan 9, 2024
0d112f7
More efficient selectors
mvaivre Jan 9, 2024
a29e363
Fix rebase merge issues
nop33 Jan 23, 2024
d1e8d6a
Update web3 packages to 0.29.1
nop33 Jan 23, 2024
b227159
Update licence headers
nop33 Jan 29, 2024
a886c41
Rename for clarity
nop33 Jan 29, 2024
7cc0dce
Fix loading indication of worth and charts
nop33 Jan 29, 2024
6d67be6
Rename asset info to fungible token
nop33 Jan 29, 2024
1bf54bb
Append "balances" for clarity
nop33 Jan 29, 2024
d1242be
Get rid of useless loadingStarted
nop33 Jan 29, 2024
00e613f
Fetch ALPH historic balances earlier
nop33 Jan 29, 2024
f6af0fe
Flush price history when currency changes
nop33 Jan 29, 2024
00bbca3
Simplify ALPH price selectors
nop33 Jan 29, 2024
d150ad2
Fix price rendering in tokens table
nop33 Jan 29, 2024
7884e32
Rename and fix greeting message
nop33 Jan 29, 2024
8247702
Improve loading speed (by a lot)
nop33 Jan 30, 2024
22a7ee7
Reimplement polling mechanism
nop33 Jan 30, 2024
8d653e1
Fix greeting message animation
nop33 Jan 30, 2024
4c65e46
Rename for clarity
nop33 Jan 30, 2024
6bb9058
Use token prices status instead of loading
nop33 Jan 30, 2024
65f9b8b
Fix verified tokens initialization
nop33 Jan 30, 2024
bd02a50
Calculate total worth including tokens
nop33 Feb 1, 2024
af533a9
Create PRICES_REFRESH_INTERVAL const
nop33 Feb 5, 2024
c04f2cf
Merge branch 'master' into fetch-token-prices-rebased
nop33 Feb 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/young-zoos-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'alephium-desktop-wallet': patch
---

Fetch token prices & ALPH history using new Explorer BE endpoints
2 changes: 1 addition & 1 deletion apps/desktop-wallet/locales/bg-BG/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"Use max amount": "Използване на максимална сума",
"Use optional passphrase": "Use optional passphrase",
"Useful for miners or DeFi use.": "Полезно за копачи или DeFi употреба.",
"Value today": "Value today",
"Value today (ALPH)": "Value today (ALPH)",
"Version": "Версия",
"Version {{ newVersion }} is available. Click \"Update\" to avoid any issues with the wallet.": "Налична е версия {{ newVersion }}. Кликнете върху \"Актуализиране\" за да избегнете проблеми с портфейла.",
"Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.": "Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-wallet/locales/de-DE/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"Use max amount": "Maximalbetrag verwenden",
"Use optional passphrase": "Optionale Passphrase verwenden",
"Useful for miners or DeFi use.": "Nützlich für Miner oder DeFi.",
"Value today": "Value today",
"Value today (ALPH)": "Value today (ALPH)",
"Version": "Version",
"Version {{ newVersion }} is available. Click \"Update\" to avoid any issues with the wallet.": "Version {{ newVersion }} ist verfügbar. Bitte laden Sie sie herunter und installieren Sie diese, um Probleme mit der Wallet zu vermeiden.",
"Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.": "Version {{ newVersion }} ist verfügbar. Bitte laden Sie sie herunter und installieren Sie sie, um Probleme mit der Brieftasche zu vermeiden.",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-wallet/locales/en-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@
"Use max amount": "Use max amount",
"Use optional passphrase": "Use optional passphrase",
"Useful for miners or DeFi use.": "Useful for miners or DeFi use.",
"Value today": "Value today",
"Value today (ALPH)": "Value today (ALPH)",
"Version": "Version",
"Version {{ newVersion }} is available. Click \"Update\" to avoid any issues with the wallet.": "Version {{ newVersion }} is available. Click \"Update\" to avoid any issues with the wallet.",
"Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.": "Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-wallet/locales/es-ES/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"Use max amount": "Utilizar la cantidad máxima",
"Use optional passphrase": "Use optional passphrase",
"Useful for miners or DeFi use.": "Útil para mineros o uso DeFi.",
"Value today": "Value today",
"Value today (ALPH)": "Value today (ALPH)",
"Version": "Versión",
"Version {{ newVersion }} is available. Click \"Update\" to avoid any issues with the wallet.": "La versión {{ newVersion }} está disponible. Haga clic en \"Actualizar\" para evitar problemas con la billetera.",
"Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.": "Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-wallet/locales/fr-FR/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"Use max amount": "Utiliser le montant max",
"Use optional passphrase": "Utiliser la phrase de passe optionnelle",
"Useful for miners or DeFi use.": "Utile pour les mineurs ou l'usage DeFi.",
"Value today": "Valeur aujourd'hui",
"Value today (ALPH)": "Valeur aujourd'hui (ALPH)",
"Version": "Version",
"Version {{ newVersion }} is available. Click \"Update\" to avoid any issues with the wallet.": "La version {{ newVersion }} est disponible. Cliquez sur \"Mettre à jour\" afin d'éviter tout problème de fonctionnement.",
"Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.": "La version {{ newVersion }} est disponible. Téléchargez et installez la afin d'éviter tout problème de fonctionnement.",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-wallet/locales/id-ID/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"Use max amount": "Gunakan jumlah maksimum",
"Use optional passphrase": "Gunakan frasa sandi opsional",
"Useful for miners or DeFi use.": "Berguna untuk penambang atau penggunaan DeFi.",
"Value today": "Nilai hari ini",
"Value today (ALPH)": "Nilai hari ini (ALPH)",
"Version": "Versi",
"Version {{ newVersion }} is available. Click \"Update\" to avoid any issues with the wallet.": "Versi {{ newVersion }} telah tersedia. Klik \"Perbarui\" untuk menghindari masalah dompet.",
"Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.": "Versi {{ newVersion }} telah tersedia. Silakan, unduh dan instal untuk menghindari masalah dompet.",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-wallet/locales/it-IT/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@
"Use max amount": "Usa l'importo massimo",
"Use optional passphrase": "Usa passphrase opzionale",
"Useful for miners or DeFi use.": "Utile per minatori o uso DeFi.",
"Value today": "Valore oggi",
"Value today (ALPH)": "Valore oggi (ALPH)",
"Version": "Versione",
"Version {{ newVersion }} is available. Click \"Update\" to avoid any issues with the wallet.": "Versione {{ newVersion }} è disponibile. Clic \"Update\" per evitare qualsiasi problema con il portafoglio.",
"Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.": "Versione {{ newVersion }} è disponibile. Per favore, scaricalo e installalo per evitare qualsiasi problema con il portafoglio.",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-wallet/locales/pt-PT/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"Use max amount": "Usar o montante máximo",
"Use optional passphrase": "Use optional passphrase",
"Useful for miners or DeFi use.": "Útil para os mineradores ou uso DeFi.",
"Value today": "Value today",
"Value today (ALPH)": "Value today (ALPH)",
"Version": "Versão",
"Version {{ newVersion }} is available. Click \"Update\" to avoid any issues with the wallet.": "A versão {{ newVersion }} está disponível. Clique em \"Atualizar\" para evitar qualquer problema com a carteira.",
"Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.": "Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-wallet/locales/ru-RU/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"Use max amount": "Использовать максимальную сумму",
"Use optional passphrase": "Использовать дополнительную парольную фразу",
"Useful for miners or DeFi use.": "Пригодится для майнеров или для использования в DeFi.",
"Value today": "Стоимость на сегодня",
"Value today (ALPH)": "Стоимость на сегодня (ALPH)",
"Version": "Версия",
"Version {{ newVersion }} is available. Click \"Update\" to avoid any issues with the wallet.": "Версия {{ newVersion }} уже доступна. Нажмите, \"Обновить\", чтобы избежать проблем с кошельком.",
"Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.": "Доступна версия {{ newVersion }}. Пожалуйста, скачайте и установите ее, чтобы избежать проблем с кошельком.",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-wallet/locales/tr-TR/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"Use max amount": "Tüm miktarı kullan",
"Use optional passphrase": "Use optional passphrase",
"Useful for miners or DeFi use.": "Madenciler ya da DeFi kullanımı için faydalıdır.",
"Value today": "Value today",
"Value today (ALPH)": "Value today (ALPH)",
"Version": "Sürüm",
"Version {{ newVersion }} is available. Click \"Update\" to avoid any issues with the wallet.": "{{ newVersion }} sürümü mevcut. Cüzdan ile ilgili sorun yaşamamak için \"Güncelle\" kısmına tıklayın.",
"Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.": "Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-wallet/locales/vi-VN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
"Use max amount": "Sử dụng tất cả số dư",
"Use optional passphrase": "Sử dụng cụm từ khôi phục tuỳ chỉnh",
"Useful for miners or DeFi use.": "Hữu ích cho thợ đào (miner) hoặc sử dụng DeFi.",
"Value today": "Giá trị hôm nay",
"Value today (ALPH)": "Giá trị hôm nay (ALPH)",
"Version": "Phiên bản",
"Version {{ newVersion }} is available. Click \"Update\" to avoid any issues with the wallet.": "Phiên bản {{ newVersion }} vừa mới được phát hành. Vui lòng nhấn \"Cập nhật\" để khắc phục những lỗi đang hiện có.",
"Version {{ newVersion }} is available. Please, download it and install it to avoid any issues with the wallet.": "Phiên bản {{ newVersion }} vừa mới được phát hành. Vui lòng tải về và cài đặt để khắc phục các lỗi hiện đang có.",
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"@alephium/shared": "workspace:*",
"@alephium/token-list": "^0.0.12",
"@alephium/typescript-config": "workspace:*",
"@alephium/walletconnect-provider": "0.28.1",
"@alephium/web3": "0.28.1",
"@alephium/walletconnect-provider": "0.29.1",
"@alephium/web3": "0.29.1",
"@electron/notarize": "^1.2.3",
"@json-rpc-tools/utils": "^1.7.6",
"@reduxjs/toolkit": "^1.9.1",
Expand Down
87 changes: 71 additions & 16 deletions apps/desktop-wallet/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
*/

import { AddressHash } from '@alephium/shared'
import { ALPH } from '@alephium/token-list'
import { AnimatePresence } from 'framer-motion'
import { difference } from 'lodash'
import { usePostHog } from 'posthog-js/react'
Expand All @@ -34,15 +35,20 @@ import { WalletConnectContextProvider } from '@/contexts/walletconnect'
import { useAppDispatch, useAppSelector } from '@/hooks/redux'
import UpdateWalletModal from '@/modals/UpdateWalletModal'
import Router from '@/routes'
import { syncAddressesData, syncAddressesHistoricBalances } from '@/storage/addresses/addressesActions'
import { makeSelectAddressesUnknownTokens, selectAddressIds } from '@/storage/addresses/addressesSelectors'
import { syncNetworkTokensInfo, syncUnknownTokensInfo } from '@/storage/assets/assetsActions'
import { selectIsTokensMetadataUninitialized } from '@/storage/assets/assetsSelectors'
import { syncAddressesAlphHistoricBalances, syncAddressesData } from '@/storage/addresses/addressesActions'
import {
makeSelectAddressesUnknownTokens,
selectAddressIds,
selectAllAddressVerifiedFungibleTokenSymbols
} from '@/storage/addresses/addressesSelectors'
import { syncUnknownTokensInfo, syncVerifiedFungibleTokens } from '@/storage/assets/assetsActions'
import { selectAreVerifiedFungibleTokensInitialized } from '@/storage/assets/assetsSelectors'
nop33 marked this conversation as resolved.
Show resolved Hide resolved
import {
devModeShortcutDetected,
localStorageDataMigrated,
localStorageDataMigrationFailed
} from '@/storage/global/globalActions'
import { syncTokenCurrentPrices, syncTokenPriceHistories } from '@/storage/prices/pricesActions'
import { apiClientInitFailed, apiClientInitSucceeded } from '@/storage/settings/networkActions'
import { systemLanguageMatchFailed, systemLanguageMatchSucceeded } from '@/storage/settings/settingsActions'
import { makeSelectAddressesHashesWithPendingTransactions } from '@/storage/transactions/transactionsSelectors'
Expand All @@ -65,7 +71,7 @@ const App = () => {
const addressesWithPendingTxs = useAppSelector(selectAddressesHashesWithPendingTransactions)
const network = useAppSelector((s) => s.network)
const theme = useAppSelector((s) => s.global.theme)
const assetsInfo = useAppSelector((s) => s.assetsInfo)
const fungibleTokens = useAppSelector((s) => s.fungibleTokens)
const loading = useAppSelector((s) => s.global.loading)
const settings = useAppSelector((s) => s.settings)
const wallets = useAppSelector((s) => s.global.wallets)
Expand All @@ -74,12 +80,14 @@ const App = () => {

const addressesStatus = useAppSelector((s) => s.addresses.status)
const isSyncingAddressData = useAppSelector((s) => s.addresses.syncingAddressData)
const isTokensMetadataUninitialized = useAppSelector(selectIsTokensMetadataUninitialized)
const isLoadingTokensMetadata = useAppSelector((s) => s.assetsInfo.loading)
const areVerifiedFungibleTokensInitialized = useAppSelector(selectAreVerifiedFungibleTokensInitialized)
const isLoadingVerifiedFungibleTokens = useAppSelector((s) => s.fungibleTokens.loadingVerified)
const isLoadingUnverifiedFungibleTokens = useAppSelector((s) => s.fungibleTokens.loadingUnverified)
const verifiedFungibleTokenSymbols = useAppSelector(selectAllAddressVerifiedFungibleTokenSymbols)

const selectAddressesUnknownTokens = useMemo(makeSelectAddressesUnknownTokens, [])
const unknownTokens = useAppSelector(selectAddressesUnknownTokens)
const checkedUnknownTokenIds = useAppSelector((s) => s.assetsInfo.checkedUnknownTokenIds)
const checkedUnknownTokenIds = useAppSelector((s) => s.fungibleTokens.checkedUnknownTokenIds)
const unknownTokenIds = unknownTokens.map((token) => token.id)
const newUnknownTokens = difference(unknownTokenIds, checkedUnknownTokenIds)

Expand Down Expand Up @@ -175,9 +183,6 @@ const App = () => {

useEffect(() => {
if (network.status === 'online') {
if (assetsInfo.status === 'uninitialized' && !isLoadingTokensMetadata) {
dispatch(syncNetworkTokensInfo())
}
if (addressesStatus === 'uninitialized') {
if (!isSyncingAddressData && addressHashes.length > 0) {
const storedPendingTxs = getStoredPendingTransactions()
Expand All @@ -189,26 +194,76 @@ const App = () => {

restorePendingTransactions(mempoolTxHashes, storedPendingTxs)
})
dispatch(syncAddressesHistoricBalances())

dispatch(syncAddressesAlphHistoricBalances())
}
} else if (addressesStatus === 'initialized') {
if (!isTokensMetadataUninitialized && !isLoadingTokensMetadata && newUnknownTokens.length > 0) {
if (areVerifiedFungibleTokensInitialized && !isLoadingUnverifiedFungibleTokens && newUnknownTokens.length > 0) {
dispatch(syncUnknownTokensInfo(newUnknownTokens))
}
}
}
}, [
addressHashes.length,
addressesStatus,
assetsInfo.status,
areVerifiedFungibleTokensInitialized,
dispatch,
isLoadingUnverifiedFungibleTokens,
isSyncingAddressData,
isLoadingTokensMetadata,
isTokensMetadataUninitialized,
network.status,
newUnknownTokens
])

// Fetch verified tokens from GitHub token-list and sync current and historical prices for each verified fungible
// token found in each address
useEffect(() => {
if (network.status === 'online' && !isLoadingVerifiedFungibleTokens) {
if (fungibleTokens.status === 'uninitialized') {
dispatch(syncVerifiedFungibleTokens())
} else if (verifiedFungibleTokenSymbols.uninitialized.length > 0) {
const symbols = verifiedFungibleTokenSymbols.uninitialized

dispatch(syncTokenCurrentPrices({ verifiedFungibleTokenSymbols: symbols, currency: settings.fiatCurrency }))
dispatch(syncTokenPriceHistories({ verifiedFungibleTokenSymbols: symbols, currency: settings.fiatCurrency }))
}
}
}, [
dispatch,
fungibleTokens.status,
isLoadingVerifiedFungibleTokens,
network.status,
settings.fiatCurrency,
verifiedFungibleTokenSymbols.uninitialized
])

useEffect(() => {
if (
network.status === 'online' &&
!isLoadingVerifiedFungibleTokens &&
verifiedFungibleTokenSymbols.uninitialized.length > 1
) {
console.log(
'TODO: Sync address verified tokens balance histories for',
verifiedFungibleTokenSymbols.uninitialized.filter((symbol) => symbol !== ALPH.symbol)
)
}
}, [isLoadingVerifiedFungibleTokens, network.status, verifiedFungibleTokenSymbols.uninitialized])
nop33 marked this conversation as resolved.
Show resolved Hide resolved

const refreshTokensLatestPrice = useCallback(() => {
dispatch(
syncTokenCurrentPrices({
verifiedFungibleTokenSymbols: verifiedFungibleTokenSymbols.withPriceHistory,
currency: settings.fiatCurrency
})
)
}, [dispatch, settings.fiatCurrency, verifiedFungibleTokenSymbols.withPriceHistory])

useInterval(
refreshTokensLatestPrice,
60000,
network.status !== 'online' || verifiedFungibleTokenSymbols.withPriceHistory.length === 0
)
nop33 marked this conversation as resolved.
Show resolved Hide resolved

const refreshAddressesData = useCallback(() => {
dispatch(syncAddressesData(addressesWithPendingTxs))
}, [dispatch, addressesWithPendingTxs])
Expand Down
4 changes: 3 additions & 1 deletion apps/desktop-wallet/src/api/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import {

const PAGE_LIMIT = 100
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not directly linked to this PR but this could be extracted as well (I actually thought it was already). WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be discussed later:

  • For maintainability sake, we could use comments to describe what each constant does.
  • Some constants would be in SHRD, those ones should IMO be imported and re-declared in each sub-package for clarity, instead of being imported directly in the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, why should we re-declare them? We can easily click on the constant in our IDEs and navigate to the source where we could have the comments that you mentioned.

Copy link
Member

@mvaivre mvaivre Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it pretty useful to see the list of constants actually in use in the project, makes it easier to know what can be tweaked. But yeah, it's a bit more maintenance involved.


export const fetchAddressesTokens = async (addressHashes: AddressHash[]): Promise<AddressTokensSyncResult[]> => {
export const fetchAddressesTokensBalances = async (
addressHashes: AddressHash[]
): Promise<AddressTokensSyncResult[]> => {
const results = []

for (const hash of addressHashes) {
Expand Down
14 changes: 7 additions & 7 deletions apps/desktop-wallet/src/components/AssetBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import styled, { css } from 'styled-components'
import Amount from '@/components/Amount'
import AssetLogo from '@/components/AssetLogo'
import { useAppSelector } from '@/hooks/redux'
import { selectAssetInfoById, selectNFTById } from '@/storage/assets/assetsSelectors'
import { selectFungibleTokenById, selectNFTById } from '@/storage/assets/assetsSelectors'

interface AssetBadgeProps {
assetId: Asset['id']
Expand All @@ -34,28 +34,28 @@ interface AssetBadgeProps {
}

const AssetBadge = ({ assetId, amount, simple, className }: AssetBadgeProps) => {
const assetInfo = useAppSelector((s) => selectAssetInfoById(s, assetId))
const fungibleToken = useAppSelector((s) => selectFungibleTokenById(s, assetId))
const nftInfo = useAppSelector((s) => selectNFTById(s, assetId))

return (
<div
className={className}
data-tooltip-id="default"
data-tooltip-content={assetInfo?.name ?? nftInfo?.name ?? assetId}
data-tooltip-content={fungibleToken?.name ?? nftInfo?.name ?? assetId}
>
<AssetLogo
assetId={assetId}
assetImageUrl={assetInfo?.logoURI || nftInfo?.image}
assetImageUrl={fungibleToken?.logoURI || nftInfo?.image}
size={20}
assetName={assetInfo?.name}
assetName={fungibleToken?.name}
isNft={!!nftInfo}
/>
{nftInfo?.name ? (
<AssetSymbol>{nftInfo?.name}</AssetSymbol>
) : amount !== undefined ? (
<Amount value={amount} suffix={assetInfo?.symbol} decimals={assetInfo?.decimals} />
<Amount value={amount} suffix={fungibleToken?.symbol} decimals={fungibleToken?.decimals} />
) : (
!simple && assetInfo?.symbol && <AssetSymbol>{assetInfo.symbol}</AssetSymbol>
!simple && fungibleToken?.symbol && <AssetSymbol>{fungibleToken.symbol}</AssetSymbol>
)}
</div>
)
Expand Down
8 changes: 4 additions & 4 deletions apps/desktop-wallet/src/components/AssetLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ You should have received a copy of the GNU Lesser General Public License
along with the library. If not, see <http://www.gnu.org/licenses/>.
*/

import { AssetInfo, NFT } from '@alephium/shared'
import { FungibleToken, NFT } from '@alephium/shared'
import { ALPH } from '@alephium/token-list'
import { HelpCircle } from 'lucide-react'
import styled, { css } from 'styled-components'

import AlephiumLogoSVG from '@/images/alephium_logo_monochrome.svg'

interface AssetLogoProps {
assetId: AssetInfo['id']
assetImageUrl: AssetInfo['logoURI'] | NFT['image']
assetId: FungibleToken['id']
assetImageUrl: FungibleToken['logoURI'] | NFT['image']
size: number
assetName?: AssetInfo['name']
assetName?: FungibleToken['name']
isNft?: boolean
className?: string
}
Expand Down
Loading
Loading