From 9711f05ceb5339360e9ad523b8d70700710341e4 Mon Sep 17 00:00:00 2001 From: Jean Ribeiro Date: Mon, 29 Apr 2024 15:20:54 -0300 Subject: [PATCH 1/3] feat: adds collection data in CollectionsGalleryView (#2391) * feat: adds collection data in CollectionsGalleryView * enhancement: getCollectionFromNft * chore: remove unnnecessary console errors * fix: not visible collections --- .../views/CollectionsGalleryView.svelte | 42 +++++++------- .../nfts/interfaces/collection.interface.ts | 10 ++++ .../src/lib/core/nfts/interfaces/index.ts | 1 + .../lib/core/nfts/interfaces/nft.interface.ts | 3 +- .../shared/src/lib/core/nfts/stores/index.ts | 1 + .../selected-account-collections.store.ts | 58 +++++++++++++++++++ .../lib/core/nfts/types/collections.type.ts | 3 + .../shared/src/lib/core/nfts/types/index.ts | 1 + .../core/nfts/utils/getCollectionFromNft.ts | 42 ++++++++++++++ .../shared/src/lib/core/nfts/utils/index.ts | 10 ++-- .../core/nfts/utils/isVisibleCollection.ts | 20 +++++++ 11 files changed, 164 insertions(+), 27 deletions(-) create mode 100644 packages/shared/src/lib/core/nfts/interfaces/collection.interface.ts create mode 100644 packages/shared/src/lib/core/nfts/stores/selected-account-collections.store.ts create mode 100644 packages/shared/src/lib/core/nfts/types/collections.type.ts create mode 100644 packages/shared/src/lib/core/nfts/utils/getCollectionFromNft.ts create mode 100644 packages/shared/src/lib/core/nfts/utils/isVisibleCollection.ts diff --git a/packages/desktop/views/dashboard/collectibles/views/CollectionsGalleryView.svelte b/packages/desktop/views/dashboard/collectibles/views/CollectionsGalleryView.svelte index e95024b661..28f84f689d 100644 --- a/packages/desktop/views/dashboard/collectibles/views/CollectionsGalleryView.svelte +++ b/packages/desktop/views/dashboard/collectibles/views/CollectionsGalleryView.svelte @@ -1,13 +1,13 @@ @@ -35,23 +33,25 @@
{localize('views.collectibles.collectionsGallery.title')} - {String(queriedCollections.length ?? '')} + {String(Object.keys($selectedAccountCollections).length ?? '')}
- {#if collections.length} - - + {#if hasCollections} + {/if} {#if features.collectibles.erc721.enabled} {/if}
- {#if collections.length} - {#if queriedCollections.length} + {#if hasCollections} + {#if Object.keys(queriedCollections).length > 0} + {#each Object.keys(queriedCollections) as collection} + {queriedCollections[collection].name} + {/each} {:else}
= writable({}) + +async function updateCollections(nfts: Nft[]): Promise { + const existingCollections = get(collectionsStore) + + if (nfts.length === 0) { + if (Object.keys(existingCollections).length > 0) { + collectionsStore.set({}) + } + return + } + + const collectionsUpdate = { ...existingCollections } + + await Promise.all( + nfts.map(async (nft) => { + if (nft.standard !== NftStandard.Irc27 || !nft.issuer) { + return + } + + const issuerId = nft.issuer.aliasId ?? nft.issuer.nftId + if (!issuerId) { + return + } + + if (!collectionsUpdate[issuerId]) { + const collection = await getCollectionFromNft(nft) + if (collection) { + collectionsUpdate[issuerId] = { ...collection, nfts: [nft] } + } + } else { + const existingNfts = collectionsUpdate[issuerId].nfts + if (!existingNfts.find((existingNft) => existingNft.id === nft.id)) { + collectionsUpdate[issuerId].nfts.push(nft) + } + } + }) + ) + collectionsStore.set(collectionsUpdate) +} + +selectedAccountNfts.subscribe((nfts) => { + void updateCollections(nfts) +}) + +export const selectedAccountCollections: Readable = derived( + collectionsStore, + ($collectionsStore) => $collectionsStore +) + +export const collectionsSearchTerm: Writable = writable('') diff --git a/packages/shared/src/lib/core/nfts/types/collections.type.ts b/packages/shared/src/lib/core/nfts/types/collections.type.ts new file mode 100644 index 0000000000..32dae6f7df --- /dev/null +++ b/packages/shared/src/lib/core/nfts/types/collections.type.ts @@ -0,0 +1,3 @@ +import { Collection } from '../interfaces' + +export type Collections = { [key: string]: Collection } diff --git a/packages/shared/src/lib/core/nfts/types/index.ts b/packages/shared/src/lib/core/nfts/types/index.ts index 3d34a70382..77e3cbecb6 100644 --- a/packages/shared/src/lib/core/nfts/types/index.ts +++ b/packages/shared/src/lib/core/nfts/types/index.ts @@ -1,2 +1,3 @@ +export * from './collections.type' export * from './nft-download-options.type' export * from './persisted-nft.type' diff --git a/packages/shared/src/lib/core/nfts/utils/getCollectionFromNft.ts b/packages/shared/src/lib/core/nfts/utils/getCollectionFromNft.ts new file mode 100644 index 0000000000..232f4d632e --- /dev/null +++ b/packages/shared/src/lib/core/nfts/utils/getCollectionFromNft.ts @@ -0,0 +1,42 @@ +import { NftStandard } from '../enums' +import { Collection, Nft } from '../interfaces' +import { Converter } from '@core/utils' +import { getClient } from '@core/profile-manager' +import type { AliasOutput, MetadataFeature, NftOutput } from '@iota/sdk' +import { FeatureType } from '@iota/sdk/out/types' + +export async function getCollectionFromNft(nft: Nft): Promise { + if (nft.standard !== NftStandard.Irc27) { + return + } + + const { aliasId = '', nftId = '' } = nft.issuer ?? {} + if (!aliasId && !nftId) { + return + } + + try { + const client = await getClient() + const outputId = aliasId ? await client.aliasOutputId(aliasId) : await client.nftOutputId(nftId) + if (!outputId) { + return + } + + const outputResponse = await client.getOutput(outputId) + const output = outputResponse.output as AliasOutput | NftOutput + + const metadataFeature = output.immutableFeatures?.find( + (feature) => feature.type === FeatureType.Metadata + ) as MetadataFeature + + if (!metadataFeature?.data) { + return + } + + const { standard, name, type, uri } = JSON.parse(Converter.hexToUtf8(metadataFeature.data)) + + return { standard, name, type, uri, nfts: [] } + } catch (error) { + console.error('Error retrieving collection from NFT:', error) + } +} diff --git a/packages/shared/src/lib/core/nfts/utils/index.ts b/packages/shared/src/lib/core/nfts/utils/index.ts index 93e479f6d5..f8305f6b34 100644 --- a/packages/shared/src/lib/core/nfts/utils/index.ts +++ b/packages/shared/src/lib/core/nfts/utils/index.ts @@ -1,17 +1,19 @@ export * from './buildNftFromPersistedErc721Nft' +export * from './buildPersistedErc721Nft' export * from './checkIfNftShouldBeDownloaded' +export * from './fetchWithTimeout' +export * from './getCollectionFromNft' +export * from './getFetchableNftUrls' export * from './getFilePathForNft' export * from './getNftsFromNftIds' export * from './getOwnerOfErc721Nft' -export * from './buildPersistedErc721Nft' -export * from './getFetchableNftUrls' export * from './getPrimaryNftUrl' export * from './getSpendableStatusFromUnspentNftOutput' -export * from './fetchWithTimeout' export * from './isIrc27Nft' -export * from './isNftOwnedByAnyAccount' export * from './isNftLocked' +export * from './isNftOwnedByAnyAccount' export * from './isScamIrc27Nft' export * from './isValidNftUri' +export * from './isVisibleCollection' export * from './isVisibleNft' export * from './parseNftMetadata' diff --git a/packages/shared/src/lib/core/nfts/utils/isVisibleCollection.ts b/packages/shared/src/lib/core/nfts/utils/isVisibleCollection.ts new file mode 100644 index 0000000000..6c367e4cbd --- /dev/null +++ b/packages/shared/src/lib/core/nfts/utils/isVisibleCollection.ts @@ -0,0 +1,20 @@ +import { get } from 'svelte/store' +import { collectionsSearchTerm } from '../stores' +import { Collection } from '../interfaces' + +export function isVisibleCollection(collection: Collection): boolean { + const searchTerm = get(collectionsSearchTerm) + + if (!isVisibleWithSearchTerm(collection, searchTerm)) { + return false + } + + return true +} + +function isVisibleWithSearchTerm(collection: Collection, searchTerm: string): boolean { + if (searchTerm) { + return collection.name.toLowerCase().includes(searchTerm.toLowerCase()) + } + return true +} From 04fa5bd7db55fc46cba8310112e60b2fcecfbeef Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Mon, 29 Apr 2024 20:34:12 +0200 Subject: [PATCH 2/3] chore: remove evm gas price poll (#2385) * remove evm gas price poll * remove remaininng store * fix types * PR fixes * chore: cleanup --------- Co-authored-by: Tuditi <45079109+Tuditi@users.noreply.github.com> Co-authored-by: Tuditi --- .../views/SelectRecipientView.svelte | 21 ++++++---- .../send-flow/views/SelectTokenView.svelte | 30 +++++++-------- .../actions/canAccountMakeEvmTransaction.ts | 15 ++++---- .../layer-2/actions/getGasPriceForNetwork.ts | 13 ------- .../src/lib/core/layer-2/actions/index.ts | 3 -- .../layer-2/actions/pollEvmChainGasPrices.ts | 38 ------------------- .../layer-2/actions/updateEvmChainGasPrice.ts | 21 ---------- .../stores/evm-chain-gas-prices.store.ts | 23 ----------- .../src/lib/core/layer-2/stores/index.ts | 1 - .../types/evm-chain-gas-prices.type.ts | 5 --- .../src/lib/core/layer-2/types/index.ts | 1 - .../network/classes/base-evm-network.class.ts | 9 +++++ .../interfaces/evm-network.interface.ts | 2 + .../canAccountMakeStardustTransaction.ts | 6 +-- .../profile/actions/active-profile/login.ts | 2 - .../wallet/tests/getOutputParameters.test.ts | 4 -- 16 files changed, 49 insertions(+), 145 deletions(-) delete mode 100644 packages/shared/src/lib/core/layer-2/actions/getGasPriceForNetwork.ts delete mode 100644 packages/shared/src/lib/core/layer-2/actions/pollEvmChainGasPrices.ts delete mode 100644 packages/shared/src/lib/core/layer-2/actions/updateEvmChainGasPrice.ts delete mode 100644 packages/shared/src/lib/core/layer-2/stores/evm-chain-gas-prices.store.ts delete mode 100644 packages/shared/src/lib/core/layer-2/types/evm-chain-gas-prices.type.ts diff --git a/packages/desktop/views/dashboard/send-flow/views/SelectRecipientView.svelte b/packages/desktop/views/dashboard/send-flow/views/SelectRecipientView.svelte index 3782b581c4..b6da55e5f0 100644 --- a/packages/desktop/views/dashboard/send-flow/views/SelectRecipientView.svelte +++ b/packages/desktop/views/dashboard/send-flow/views/SelectRecipientView.svelte @@ -42,17 +42,22 @@ $: selectedNetworkId = selectorOptions[selectedIndex]?.networkId $: selectedRecipient = selectorOptions[selectedIndex]?.selectedRecipient - let hasNetworkRecipientError: boolean = false - $: { + let hasInsufficientFunds = false + $: $sendFlowParameters, void checkFundsForGas() + async function checkFundsForGas(): Promise { + if (!$sendFlowParameters) { + return + } + const originNetworkId = getNetworkIdFromSendFlowParameters($sendFlowParameters) if (originNetworkId && isEvmNetwork(originNetworkId)) { - hasNetworkRecipientError = !canAccountMakeEvmTransaction( + hasInsufficientFunds = !(await canAccountMakeEvmTransaction( $selectedAccountIndex, originNetworkId, - $sendFlowParameters?.type - ) + $sendFlowParameters.type + )) } else { - hasNetworkRecipientError = false + hasInsufficientFunds = false } } @@ -247,13 +252,13 @@ >
- {#if hasNetworkRecipientError} + {#if hasInsufficientFunds} {/if} diff --git a/packages/desktop/views/dashboard/send-flow/views/SelectTokenView.svelte b/packages/desktop/views/dashboard/send-flow/views/SelectTokenView.svelte index a6828e77cd..f26236b463 100644 --- a/packages/desktop/views/dashboard/send-flow/views/SelectTokenView.svelte +++ b/packages/desktop/views/dashboard/send-flow/views/SelectTokenView.svelte @@ -31,21 +31,21 @@ $: $selectedAccountTokens, searchValue, selectedTab, setFilteredTokenList() - let tokenError: string = '' - $: if ( - selectedToken && - isEvmNetwork(selectedToken.networkId) && - !canAccountMakeEvmTransaction($selectedAccountIndex, selectedToken.networkId, $sendFlowParameters?.type) - ) { - tokenError = localize('error.send.insufficientFundsTransaction') - } else if ( - selectedToken && - isStardustNetwork(selectedToken.networkId) && - !canAccountMakeStardustTransaction($selectedAccountIndex, $sendFlowParameters?.type) - ) { - tokenError = localize('error.send.insufficientFundsTransaction') - } else { - tokenError = '' + let tokenError = '' + $: selectedToken, $sendFlowParameters, void setTokenError() + async function setTokenError(): Promise { + let hasEnoughFunds = true + if (selectedToken && isEvmNetwork(selectedToken.networkId)) { + hasEnoughFunds = await canAccountMakeEvmTransaction( + $selectedAccountIndex, + selectedToken.networkId, + $sendFlowParameters?.type + ) + } else if (selectedToken && isStardustNetwork(selectedToken.networkId)) { + hasEnoughFunds = canAccountMakeStardustTransaction($selectedAccountIndex, $sendFlowParameters?.type) + } + + tokenError = hasEnoughFunds ? '' : localize('error.send.insufficientFundsTransaction') } const tabs = [ diff --git a/packages/shared/src/lib/core/layer-2/actions/canAccountMakeEvmTransaction.ts b/packages/shared/src/lib/core/layer-2/actions/canAccountMakeEvmTransaction.ts index 1c60281914..0ec9b33882 100644 --- a/packages/shared/src/lib/core/layer-2/actions/canAccountMakeEvmTransaction.ts +++ b/packages/shared/src/lib/core/layer-2/actions/canAccountMakeEvmTransaction.ts @@ -1,23 +1,22 @@ import { EvmNetworkId } from '@core/network/types' import { SendFlowType } from '@core/wallet/enums' - -import { getEvmChainGasPrice, getLayer2AccountBalanceForToken } from '../stores' - +import { getLayer2AccountBalanceForToken } from '../stores' import { FALLBACK_ESTIMATED_GAS, GAS_LIMIT_MULTIPLIER } from '../constants' import { calculateGasFeeInGlow } from '../helpers' +import { getEvmNetwork } from '@core/network' -export function canAccountMakeEvmTransaction( +export async function canAccountMakeEvmTransaction( accountIndex: number, networkId: EvmNetworkId, - sendFlowType: SendFlowType -): boolean | undefined { + sendFlowType: SendFlowType | undefined +): Promise { const baseTokenAccountBalance = getLayer2AccountBalanceForToken(accountIndex, networkId) const gasLimit = Math.floor( FALLBACK_ESTIMATED_GAS[sendFlowType ?? SendFlowType.BaseCoinTransfer] * GAS_LIMIT_MULTIPLIER ) - const gasPrice = getEvmChainGasPrice(networkId) + const gasPrice = await getEvmNetwork(networkId)?.getGasPrice() if (gasPrice === undefined) { - return undefined + return false } const minimumGasFee = calculateGasFeeInGlow(gasLimit, gasPrice) return baseTokenAccountBalance > minimumGasFee diff --git a/packages/shared/src/lib/core/layer-2/actions/getGasPriceForNetwork.ts b/packages/shared/src/lib/core/layer-2/actions/getGasPriceForNetwork.ts deleted file mode 100644 index d7fc7e2ba7..0000000000 --- a/packages/shared/src/lib/core/layer-2/actions/getGasPriceForNetwork.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { getEvmNetwork } from '@core/network' -import { EvmNetworkId } from '@core/network/types' -import { Converter } from '@core/utils' - -export async function getGasPriceForNetwork(networkId: EvmNetworkId): Promise { - const evmNetwork = getEvmNetwork(networkId) - if (!evmNetwork) { - return undefined - } - - const gasPrice = await evmNetwork.provider.eth.getGasPrice() - return Converter.decimalToHex(Number(gasPrice), true) -} diff --git a/packages/shared/src/lib/core/layer-2/actions/index.ts b/packages/shared/src/lib/core/layer-2/actions/index.ts index 4d26c39bbf..3e38a7a390 100644 --- a/packages/shared/src/lib/core/layer-2/actions/index.ts +++ b/packages/shared/src/lib/core/layer-2/actions/index.ts @@ -5,12 +5,9 @@ export * from './checkForUntrackedTokens' export * from './fetchL2BalanceForAccount' export * from './getGasFeeForLayer1ToLayer2Transaction' export * from './generateAndStoreEvmAddressForAccounts' -export * from './getGasPriceForNetwork' export * from './getIscTransferSmartContractData' export * from './getLayer2MetadataForTransfer' export * from './getLayer2NetworkFromAddress' export * from './getNetworkFromAddress' -export * from './pollEvmChainGasPrices' export * from './pollL2BalanceForAccount' export * from './setGasFee' -export * from './updateEvmChainGasPrice' diff --git a/packages/shared/src/lib/core/layer-2/actions/pollEvmChainGasPrices.ts b/packages/shared/src/lib/core/layer-2/actions/pollEvmChainGasPrices.ts deleted file mode 100644 index 630ca5534c..0000000000 --- a/packages/shared/src/lib/core/layer-2/actions/pollEvmChainGasPrices.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { EvmNetworkId } from '@core/network/types' -import { MILLISECONDS_PER_SECOND } from '@core/utils' -import { updateEvmChainGasPrice } from './updateEvmChainGasPrice' - -const EVM_CHAIN_GAS_PRICE_POLLING_INTERVAL: number = 60 * MILLISECONDS_PER_SECOND - -const pollIntervalMap: { [id in EvmNetworkId]?: number } = {} - -export function pollEvmChainGasPrice(networkId: EvmNetworkId): void { - if (!networkId || isPollingEvmChainGasPrice(networkId)) { - return - } - void updateEvmChainGasPrice(networkId) - pollIntervalMap[networkId] = window.setInterval(() => { - void updateEvmChainGasPrice(networkId) - }, EVM_CHAIN_GAS_PRICE_POLLING_INTERVAL) -} - -export function pollEvmChainGasPrices(networkIds: EvmNetworkId[]): void { - stopPollingEvmChainGasPrices() - for (const networkId of networkIds) { - pollEvmChainGasPrice(networkId) - } -} - -export function stopPollingEvmChainGasPrices(networkIdsToIgnore?: EvmNetworkId[]): void { - for (const networkId of Object.keys(pollIntervalMap) as EvmNetworkId[]) { - if (!networkIdsToIgnore?.includes(networkId)) { - if (isPollingEvmChainGasPrice(networkId)) { - clearInterval(pollIntervalMap[networkId]) - } - } - } -} - -export function isPollingEvmChainGasPrice(networkId: EvmNetworkId): boolean { - return typeof pollIntervalMap[networkId] === 'number' -} diff --git a/packages/shared/src/lib/core/layer-2/actions/updateEvmChainGasPrice.ts b/packages/shared/src/lib/core/layer-2/actions/updateEvmChainGasPrice.ts deleted file mode 100644 index 0816471a16..0000000000 --- a/packages/shared/src/lib/core/layer-2/actions/updateEvmChainGasPrice.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { handleError } from '@core/error/handlers' -import { getEvmNetworks } from '@core/network/stores' -import { EvmNetworkId } from '@core/network/types' -import { setEvmChainGasPrice } from '../stores' -import { getGasPriceForNetwork } from './getGasPriceForNetwork' - -export async function updateEvmChainGasPrice(networkId: EvmNetworkId): Promise { - try { - const gasPrice = await getGasPriceForNetwork(networkId) - if (gasPrice) { - setEvmChainGasPrice(BigInt(gasPrice), networkId) - } - } catch (err) { - handleError(err) - } -} - -export async function updateEvmChainGasPrices(): Promise { - const networkIds = getEvmNetworks().map((evmNetwork) => evmNetwork.id) - await Promise.all(networkIds.map((networkId) => updateEvmChainGasPrice(networkId))) -} diff --git a/packages/shared/src/lib/core/layer-2/stores/evm-chain-gas-prices.store.ts b/packages/shared/src/lib/core/layer-2/stores/evm-chain-gas-prices.store.ts deleted file mode 100644 index 25227cc32b..0000000000 --- a/packages/shared/src/lib/core/layer-2/stores/evm-chain-gas-prices.store.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { get, writable } from 'svelte/store' -import { NetworkId } from '@core/network/types' -import { isEvmNetwork } from '@core/network/utils' -import { EvmChainGasPrices } from '../types' - -export const evmChainGasPrices = writable({}) - -export function getEvmChainGasPrice(networkId: NetworkId): bigint | undefined { - return get(evmChainGasPrices)[networkId] -} - -export function setEvmChainGasPrice(price: bigint, networkId: NetworkId): void { - evmChainGasPrices.update((state) => { - if (typeof price === 'bigint' && isEvmNetwork(networkId)) { - return { - ...state, - [networkId]: price, - } - } else { - return state - } - }) -} diff --git a/packages/shared/src/lib/core/layer-2/stores/index.ts b/packages/shared/src/lib/core/layer-2/stores/index.ts index 2c59ed1ce6..7c15aa4d3f 100644 --- a/packages/shared/src/lib/core/layer-2/stores/index.ts +++ b/packages/shared/src/lib/core/layer-2/stores/index.ts @@ -1,2 +1 @@ -export * from './evm-chain-gas-prices.store' export * from './layer2-balances.store' diff --git a/packages/shared/src/lib/core/layer-2/types/evm-chain-gas-prices.type.ts b/packages/shared/src/lib/core/layer-2/types/evm-chain-gas-prices.type.ts deleted file mode 100644 index 876a3c8e17..0000000000 --- a/packages/shared/src/lib/core/layer-2/types/evm-chain-gas-prices.type.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { NetworkId } from '@core/network/types' - -export type EvmChainGasPrices = { - [id in NetworkId]?: bigint -} diff --git a/packages/shared/src/lib/core/layer-2/types/index.ts b/packages/shared/src/lib/core/layer-2/types/index.ts index 9b525d20c3..797274a189 100644 --- a/packages/shared/src/lib/core/layer-2/types/index.ts +++ b/packages/shared/src/lib/core/layer-2/types/index.ts @@ -1,6 +1,5 @@ export * from './abi.type' export * from './contract.type' -export * from './evm-chain-gas-prices.type' export * from './evm-transaction-options.type' export * from './evm-transaction-data.type' export * from './layer-2-account-balance.type' diff --git a/packages/shared/src/lib/core/network/classes/base-evm-network.class.ts b/packages/shared/src/lib/core/network/classes/base-evm-network.class.ts index 631a6461ec..73d478db87 100644 --- a/packages/shared/src/lib/core/network/classes/base-evm-network.class.ts +++ b/packages/shared/src/lib/core/network/classes/base-evm-network.class.ts @@ -76,6 +76,15 @@ export class BaseEvmNetwork implements IEvmNetwork { return new this.provider.eth.Contract(abi, address) } + async getGasPrice(): Promise { + try { + const gasPrice = await this.provider.eth.getGasPrice() + return BigInt(gasPrice) + } catch { + return undefined + } + } + async getLatestBlock(): Promise { const number = await this.provider.eth.getBlockNumber() return this.provider.eth.getBlock(number) diff --git a/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts b/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts index 80cd3df1ef..28c71ccf55 100644 --- a/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts +++ b/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts @@ -25,6 +25,8 @@ export interface IEvmNetwork extends IBaseNetwork, IBaseNetworkMetadata { provider: Web3Provider + getGasPrice(): Promise + getContract(type: ContractType, address: string): Contract getLatestBlock(): Promise } diff --git a/packages/shared/src/lib/core/network/utils/canAccountMakeStardustTransaction.ts b/packages/shared/src/lib/core/network/utils/canAccountMakeStardustTransaction.ts index fb20ae08fc..2f9f87d92b 100644 --- a/packages/shared/src/lib/core/network/utils/canAccountMakeStardustTransaction.ts +++ b/packages/shared/src/lib/core/network/utils/canAccountMakeStardustTransaction.ts @@ -4,8 +4,8 @@ import { SendFlowType } from '@core/wallet/enums' export function canAccountMakeStardustTransaction( accountIndex: number, - sendFlowType: SendFlowType -): boolean | undefined { + sendFlowType: SendFlowType | undefined +): boolean { switch (sendFlowType) { case SendFlowType.BaseCoinTransfer: default: { @@ -14,7 +14,7 @@ export function canAccountMakeStardustTransaction( const baseTokenBalance = account?.balances.baseCoin return BigInt(baseTokenBalance?.available ?? 0) > BigInt(0) } else { - return undefined + return false } } } diff --git a/packages/shared/src/lib/core/profile/actions/active-profile/login.ts b/packages/shared/src/lib/core/profile/actions/active-profile/login.ts index e15d866799..5bcf7808e5 100644 --- a/packages/shared/src/lib/core/profile/actions/active-profile/login.ts +++ b/packages/shared/src/lib/core/profile/actions/active-profile/login.ts @@ -4,7 +4,6 @@ import { generateAndStoreActivitiesForAllAccounts } from '@core/activity/actions import { Platform } from '@core/app/classes' import { AppContext } from '@core/app/enums' import { handleError } from '@core/error/handlers' -import { updateEvmChainGasPrices } from '@core/layer-2/actions' import { fetchL2BalanceForAllAccounts } from '@core/layer-2/utils' import { pollLedgerDeviceState } from '@core/ledger/actions' import { pollMarketPrices } from '@core/market/actions' @@ -126,7 +125,6 @@ export async function login(loginOptions?: ILoginOptions): Promise { resetLoginProgress() }, 500) - void updateEvmChainGasPrices() void pollMarketPrices() void updateCirculatingSupplyForActiveProfile() if (Platform.isFeatureFlagEnabled('governance')) { diff --git a/packages/shared/src/lib/core/wallet/tests/getOutputParameters.test.ts b/packages/shared/src/lib/core/wallet/tests/getOutputParameters.test.ts index 2e131302ea..4d701d3538 100644 --- a/packages/shared/src/lib/core/wallet/tests/getOutputParameters.test.ts +++ b/packages/shared/src/lib/core/wallet/tests/getOutputParameters.test.ts @@ -96,10 +96,6 @@ jest.mock('../../network/stores/networks.store', () => ({ getIscChain: jest.fn((_) => destinationNetwork), })) -jest.mock('../../layer-2/actions/getGasPriceForNetwork', () => ({ - getGasPriceForNetwork: jest.fn((_) => 1_000_000_000_000n), -})) - jest.mock('../../layer-2/actions/getGasFeeForLayer1ToLayer2Transaction', () => ({ getGasFeeForLayer1ToLayer2Transaction: jest.fn(({ type }) => FALLBACK_ESTIMATED_GAS[type]), })) From 0c12d2a9107214e210718bf1f2108fc6c6fe52da Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Tue, 30 Apr 2024 09:59:30 +0200 Subject: [PATCH 3/3] fix: add fallback icon for networks (#2397) * add fallback icon for networks * fix network summary columns --- .../account-summary/AccountSummaryPane.svelte | 13 ++++++++----- .../components/avatars/NetworkAvatar.svelte | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/desktop/views/dashboard/wallet/panes/account-summary/AccountSummaryPane.svelte b/packages/desktop/views/dashboard/wallet/panes/account-summary/AccountSummaryPane.svelte index a437b160bf..5f1950b1c6 100644 --- a/packages/desktop/views/dashboard/wallet/panes/account-summary/AccountSummaryPane.svelte +++ b/packages/desktop/views/dashboard/wallet/panes/account-summary/AccountSummaryPane.svelte @@ -5,15 +5,18 @@ import { networks } from '@core/network' export let account: IAccountState + + const GRID_COLS = { + 0: 'grid-cols-1', + 1: 'grid-cols-2', + 2: 'grid-cols-3', + 3: 'grid-cols-4', + } import { DEFAULT_NETWORK_ICON } from '@auxiliary/icon' - import { Avatar, Tooltip } from '@bloomwalletio/ui' - import { NetworkId, SupportedNetworkId, getNameFromNetworkId, isSupportedNetworkId } from '@core/network' + import { Avatar, IconName, Tooltip } from '@bloomwalletio/ui' + import { NetworkId, SupportedNetworkId, getNameFromNetworkId } from '@core/network' export let networkId: NetworkId export let networkName: string | undefined = undefined @@ -26,17 +26,19 @@ } let anchor: HTMLElement - $: isSupported = isSupportedNetworkId(networkId) - $: backgroundColor = isSupported ? AVATAR_BACKGROUND_COLOR[networkId] : 'neutral-4' - $: customTextColor = isSupported ? AVATAR_TEXT_COLOR[networkId] : undefined - $: icon = isSupported ? DEFAULT_NETWORK_ICON[networkId] : undefined $: networkName = networkName ? networkName : networkId ? getNameFromNetworkId(networkId) ?? networkId : networkId $: magnify = Object.values(SupportedNetworkId).includes(networkId) - - + {#if showTooltip && networkName}