From de2d8782dc4328f1198372760d289afbe1dd7cfc Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Thu, 2 May 2024 11:52:14 +0100 Subject: [PATCH] refactor: clean up all account nft stores (#2432) * refactor: rename `allAccountNfts` to `activeProfileNftsPerAccount` Co-authored-by: Mark Nardi * refactor: use dictionary for activeProfileNftsPerAccount by account index rather than array * refactor: replace `getNftByIdFromAllAccountNfts` with `getNftByIdForAccount` * refactor: replace `setAccountNftsInAllAccountNfts` with `setNftsForAccount` * refactor: remove superfluous `setNftInAllAccountNftsToUnspendable` function * refactor: replace `updateAllAccountNftsForAccount` with `addOrUpdateNftsForAccount` * refactor: replace `updateNftInAllAccountNftsForAccount` with `updateNftForAccount` refactor: replace `updateNftInAllAccountNfts` with `updateNftForAllAccounts` * refactor: selectedAccountNfts subscribed to selectedAccountIndex rather than selectedAccount * refactor: remove superfluous function `getAllAccountNfts` refactor: rename `clearAccountNfts` to `clearActiveProfileNftsPerAccount` * refactor: create PartialWithId type * refactor: fix name of store file * fix nfts for account 0 --------- Co-authored-by: Mark Nardi --- .../menus/CollectibleDetailsMenu.svelte | 8 +- .../popups/EvmActivityDetailsPopup.svelte | 7 +- .../popups/EvmTransactionFromDappPopup.svelte | 4 +- .../popups/ImportErc721TokenFormPopup.svelte | 10 +-- .../StardustActivityDetailsPopup.svelte | 5 +- .../views/CampaignDetailsView.svelte | 6 +- .../components/NftMediaAlert.svelte | 6 +- .../views/CollectiblesDetailsView.svelte | 13 ++- .../components/AssetPillsForActivity.svelte | 6 +- .../row-sections/ActivityAssetSection.svelte | 9 +-- .../DownloadNftPermissions.svelte | 4 +- .../views/collectibles/MaxMediaSize.svelte | 7 +- .../views/collectibles/RefreshNftMedia.svelte | 10 +-- .../evm/EvmActivityInformation.svelte | 4 +- .../StardustActivityInformation.svelte | 8 +- .../info/StardustNftInformation.svelte | 6 +- .../setAsyncStatusOfAccountActivities.ts | 4 +- .../activity/utils/convertActvitiesToCsv.ts | 8 +- .../activity/utils/getActivityTileAsset.ts | 6 +- .../activity/utils/getTransactionAssets.ts | 4 +- .../core/activity/utils/isVisibleActivity.ts | 4 +- .../generateActivitiesFromBasicOutputs.ts | 5 +- .../app/actions/registerNftDownloadEvents.ts | 5 +- .../layer-2/utils/fetchIscAssetsForAccount.ts | 25 +++--- .../nfts/actions/addNftsToDownloadQueue.ts | 5 +- .../nfts/actions/checkForUntrackedNfts.ts | 4 +- .../nfts/actions/downloadNextNftInQueue.ts | 11 ++- .../actions/getNftByIdFromAllAccountNfts.ts | 7 -- .../shared/src/lib/core/nfts/actions/index.ts | 5 -- .../interruptNftDownloadAfterTimeout.ts | 9 +-- .../nfts/actions/loadNftsForActiveProfile.ts | 4 +- .../actions/setAccountNftsInAllAccountNfts.ts | 9 --- .../setNftInAllAccountNftsToUnspendable.ts | 18 ----- .../core/nfts/actions/updateAllAccountNfts.ts | 19 ----- .../nfts/actions/updateErc721NftOwnership.ts | 12 ++- .../nfts/actions/updateNftInAllAccountNfts.ts | 31 -------- .../active-profile-nfts-per-account.store.ts | 79 +++++++++++++++++++ .../nfts/stores/all-account-nfts.store.ts | 13 --- .../shared/src/lib/core/nfts/stores/index.ts | 2 +- .../stores/selected-account-nfts.store.ts | 12 +-- .../core/nfts/utils/isNftOwnedByAnyAccount.ts | 6 +- .../events-handlers/handleNewOutputEvent.ts | 5 +- .../events-handlers/handleSpentOutputEvent.ts | 12 +-- .../handleTransactionInclusionEvent.ts | 10 +-- .../profile/actions/active-profile/logout.ts | 4 +- .../shared/src/lib/core/utils/types/index.ts | 1 + .../core/utils/types/partial-with-id.type.ts | 1 + .../src/lib/core/wallet/actions/burnNft.ts | 4 +- .../src/lib/core/wallet/actions/mintNft.ts | 5 +- .../send/signAndSendStardustTransaction.ts | 4 +- .../src/lib/core/wallet/actions/sendOutput.ts | 4 +- 51 files changed, 227 insertions(+), 243 deletions(-) delete mode 100644 packages/shared/src/lib/core/nfts/actions/getNftByIdFromAllAccountNfts.ts delete mode 100644 packages/shared/src/lib/core/nfts/actions/setAccountNftsInAllAccountNfts.ts delete mode 100644 packages/shared/src/lib/core/nfts/actions/setNftInAllAccountNftsToUnspendable.ts delete mode 100644 packages/shared/src/lib/core/nfts/actions/updateAllAccountNfts.ts delete mode 100644 packages/shared/src/lib/core/nfts/actions/updateNftInAllAccountNfts.ts create mode 100644 packages/shared/src/lib/core/nfts/stores/active-profile-nfts-per-account.store.ts delete mode 100644 packages/shared/src/lib/core/nfts/stores/all-account-nfts.store.ts create mode 100644 packages/shared/src/lib/core/utils/types/partial-with-id.type.ts diff --git a/packages/desktop/components/menus/CollectibleDetailsMenu.svelte b/packages/desktop/components/menus/CollectibleDetailsMenu.svelte index 66e4b72bab..18682e05fe 100644 --- a/packages/desktop/components/menus/CollectibleDetailsMenu.svelte +++ b/packages/desktop/components/menus/CollectibleDetailsMenu.svelte @@ -4,8 +4,8 @@ import { localize } from '@core/i18n' import { isEvmNetwork } from '@core/network' import { IIrc27Nft, Nft, getPrimaryNftUrl, isNftLocked, isValidNftUri } from '@core/nfts' - import { addNftsToDownloadQueue, updateNftInAllAccountNfts } from '@core/nfts/actions' - import { updatePersistedNft } from '@core/nfts/stores' + import { addNftsToDownloadQueue } from '@core/nfts/actions' + import { updateNftForAllAccounts, updatePersistedNft } from '@core/nfts/stores' import { activeProfile, updateActiveProfile } from '@core/profile/stores' import { Platform } from '@core/app' @@ -36,14 +36,14 @@ } updatePersistedNft(nft.id, { downloadMetadata: {} }) - updateNftInAllAccountNfts(nft.id, { downloadMetadata: {}, isLoaded: false }) + updateNftForAllAccounts({ id: nft.id, downloadMetadata: {}, isLoaded: false }) addNftsToDownloadQueue([nft]) menu?.close() } function onHideClick(): void { updatePersistedNft(nft.id, { hidden: !nft.hidden }) - updateNftInAllAccountNfts(nft.id, { hidden: !nft.hidden }) + updateNftForAllAccounts({ id: nft.id, hidden: !nft.hidden }) menu?.close() } diff --git a/packages/desktop/components/popup/popups/EvmActivityDetailsPopup.svelte b/packages/desktop/components/popup/popups/EvmActivityDetailsPopup.svelte index 65d6d3842f..7f5d79a2cb 100644 --- a/packages/desktop/components/popup/popups/EvmActivityDetailsPopup.svelte +++ b/packages/desktop/components/popup/popups/EvmActivityDetailsPopup.svelte @@ -8,9 +8,8 @@ import { ExplorerEndpoint } from '@core/network' import { getDefaultExplorerUrl } from '@core/network/utils' import { NftStandard } from '@core/nfts' - import { getNftByIdFromAllAccountNfts } from '@core/nfts/actions' import { Nft } from '@core/nfts/interfaces' - import { ownedNfts, selectedNftId } from '@core/nfts/stores' + import { ownedNfts, selectedNftId, getNftByIdForAccount } from '@core/nfts/stores' import { CollectiblesRoute, DashboardRoute, collectiblesRouter, dashboardRouter } from '@core/router' import { getTokenFromSelectedAccountTokens } from '@core/token/stores' import { buildUrl, setClipboard, truncateString } from '@core/utils' @@ -45,7 +44,7 @@ _activity.tokenTransfer.standard === NftStandard.Erc721 || _activity.tokenTransfer.standard === NftStandard.Irc27 ) { - return getNftByIdFromAllAccountNfts($selectedAccountIndex, _activity.tokenTransfer.tokenId) as Nft + return getNftByIdForAccount($selectedAccountIndex, _activity.tokenTransfer.tokenId) } } } @@ -62,7 +61,7 @@ const { tokenId, rawAmount, standard } = _activity.tokenTransfer if (standard === NftStandard.Erc721 || standard === NftStandard.Irc27) { return { - nft: getNftByIdFromAllAccountNfts($selectedAccountIndex, _activity.tokenTransfer.tokenId) as Nft, + nft: getNftByIdForAccount($selectedAccountIndex, _activity.tokenTransfer.tokenId) as Nft, } } else { const token = getTokenFromSelectedAccountTokens(tokenId, _activity.sourceNetworkId) diff --git a/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte b/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte index 27baa266ae..2ef6f026ba 100644 --- a/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte +++ b/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte @@ -20,7 +20,6 @@ import { getTransferInfoFromTransactionData } from '@core/layer-2/utils/getTransferInfoFromTransactionData' import { TokenTransferData } from '@core/wallet' import { Nft } from '@core/nfts' - import { getNftByIdFromAllAccountNfts } from '@core/nfts/actions' import { Alert, Link, Table, Text } from '@bloomwalletio/ui' import { PopupId, closePopup, modifyPopupState, openPopup } from '@desktop/auxiliary/popup' import { buildUrl, truncateString } from '@core/utils' @@ -33,6 +32,7 @@ import { LegacyTransaction } from '@ethereumjs/tx' import { getActiveProfileId } from '@core/profile/stores' import { IAccountState } from '@core/account' + import { getNftByIdForAccount } from '@core/nfts/stores' export let preparedTransaction: EvmTransactionData export let evmNetwork: IEvmNetwork @@ -77,7 +77,7 @@ break } case StardustActivityType.Nft: { - nft = getNftByIdFromAllAccountNfts($selectedAccount.index, transferInfo.nftId) + nft = getNftByIdForAccount($selectedAccount.index, transferInfo.nftId) break } case StardustActivityType.SmartContract: { diff --git a/packages/desktop/components/popup/popups/ImportErc721TokenFormPopup.svelte b/packages/desktop/components/popup/popups/ImportErc721TokenFormPopup.svelte index 779421b851..84a0aa5207 100644 --- a/packages/desktop/components/popup/popups/ImportErc721TokenFormPopup.svelte +++ b/packages/desktop/components/popup/popups/ImportErc721TokenFormPopup.svelte @@ -7,17 +7,13 @@ import PopupTemplate from '../PopupTemplate.svelte' import { closePopup } from '@desktop/auxiliary/popup' import { showNotification } from '@auxiliary/notification' - import { - addNftsToDownloadQueue, - addNewTrackedNftToActiveProfile, - persistErc721Nft, - updateAllAccountNftsForAccount, - } from '@core/nfts/actions' + import { addNftsToDownloadQueue, addNewTrackedNftToActiveProfile, persistErc721Nft } from '@core/nfts/actions' import { buildNftFromPersistedErc721Nft } from '@core/nfts/utils' import { activeAccounts } from '@core/profile/stores' import { getAddressFromAccountForNetwork } from '@core/account' import { TokenTrackingStatus } from '@core/token' import { selectedAccount } from '@core/account/stores' + import { addOrUpdateNftForAccount } from '@core/nfts/stores' let busy = false @@ -46,7 +42,7 @@ for (const account of $activeAccounts) { const l2Address = getAddressFromAccountForNetwork(account, networkId) const nft = buildNftFromPersistedErc721Nft(persistedNft, l2Address) - updateAllAccountNftsForAccount(account.index, nft) + addOrUpdateNftForAccount(account.index, nft) void addNftsToDownloadQueue([nft]) } diff --git a/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte b/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte index fd6a9f5224..37bc5c7a5e 100644 --- a/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte +++ b/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte @@ -13,8 +13,7 @@ import { localize } from '@core/i18n' import { ExplorerEndpoint } from '@core/network' import { getDefaultExplorerUrl } from '@core/network/utils' - import { getNftByIdFromAllAccountNfts } from '@core/nfts/actions' - import { ownedNfts, selectedNftId } from '@core/nfts/stores' + import { getNftByIdForAccount, ownedNfts, selectedNftId } from '@core/nfts/stores' import { CollectiblesRoute, DashboardRoute, collectiblesRouter, dashboardRouter } from '@core/router' import { buildUrl, setClipboard, truncateString } from '@core/utils' import { claimActivity, rejectActivity } from '@core/wallet' @@ -34,7 +33,7 @@ $: transactionAssets = getTransactionAssets(activity, $selectedAccountIndex) $: nft = activity.type === StardustActivityType.Nft - ? getNftByIdFromAllAccountNfts($selectedAccountIndex, activity.nftId) + ? getNftByIdForAccount($selectedAccountIndex, activity.nftId) : undefined $: nftIsOwned = nft ? $ownedNfts.some((_nft) => _nft.id === nft?.id) : false diff --git a/packages/desktop/views/dashboard/campaigns/views/CampaignDetailsView.svelte b/packages/desktop/views/dashboard/campaigns/views/CampaignDetailsView.svelte index aa560d3f4c..86e0474adb 100644 --- a/packages/desktop/views/dashboard/campaigns/views/CampaignDetailsView.svelte +++ b/packages/desktop/views/dashboard/campaigns/views/CampaignDetailsView.svelte @@ -11,9 +11,9 @@ import { handleError } from '@core/error/handlers' import { EvmNetworkId, NetworkNamespace, getEvmNetwork } from '@core/network' import { buildNftFromPersistedErc721Nft } from '@core/nfts' - import { addNftsToDownloadQueue, updateAllAccountNftsForAccount } from '@core/nfts/actions' + import { addNftsToDownloadQueue } from '@core/nfts/actions' import { persistErc721Nft } from '@core/nfts/actions/persistErc721Nft' - import { ownedNfts } from '@core/nfts/stores' + import { addOrUpdateNftForAccount, ownedNfts } from '@core/nfts/stores' import { TideApi } from '@core/tide/apis' import { onDestroy, onMount } from 'svelte' import Leaderboard from '../components/Leaderboard.svelte' @@ -79,7 +79,7 @@ if (persistedNft) { const nft = buildNftFromPersistedErc721Nft(persistedNft, accountAddress) void addNftsToDownloadQueue([nft]) - updateAllAccountNftsForAccount(index, nft) + addOrUpdateNftForAccount(index, nft) } } catch (_) { // Switching account too swiftly results in an error from persistErc721Nft. diff --git a/packages/desktop/views/dashboard/collectibles/components/NftMediaAlert.svelte b/packages/desktop/views/dashboard/collectibles/components/NftMediaAlert.svelte index b2917a2e7d..06ea0462ac 100644 --- a/packages/desktop/views/dashboard/collectibles/components/NftMediaAlert.svelte +++ b/packages/desktop/views/dashboard/collectibles/components/NftMediaAlert.svelte @@ -2,8 +2,9 @@ import { DownloadErrorType, DownloadWarningType, IDownloadMetadata, Nft, NftDownloadOptions } from '@core/nfts' import { Alert, Link, Text } from '@bloomwalletio/ui' import { localize } from '@core/i18n' - import { addNftsToDownloadQueue, updateNftInAllAccountNfts } from '@core/nfts/actions' + import { addNftsToDownloadQueue } from '@core/nfts/actions' import { getFormattedFileSize } from '@core/utils' + import { updateNftForAllAccounts } from '@core/nfts/stores' export let type: DownloadErrorType | DownloadWarningType | undefined export let message: string | undefined @@ -54,7 +55,8 @@ break } - updateNftInAllAccountNfts(nft.id, { + updateNftForAllAccounts({ + id: nft.id, isLoaded: false, downloadMetadata: { ...nft.downloadMetadata, warning: undefined, error: undefined }, }) diff --git a/packages/desktop/views/dashboard/collectibles/views/CollectiblesDetailsView.svelte b/packages/desktop/views/dashboard/collectibles/views/CollectiblesDetailsView.svelte index a229d8dd67..7731ce4675 100644 --- a/packages/desktop/views/dashboard/collectibles/views/CollectiblesDetailsView.svelte +++ b/packages/desktop/views/dashboard/collectibles/views/CollectiblesDetailsView.svelte @@ -1,9 +1,14 @@ diff --git a/packages/desktop/views/settings/views/collectibles/DownloadNftPermissions.svelte b/packages/desktop/views/settings/views/collectibles/DownloadNftPermissions.svelte index 5963c7e28e..2cf1657050 100644 --- a/packages/desktop/views/settings/views/collectibles/DownloadNftPermissions.svelte +++ b/packages/desktop/views/settings/views/collectibles/DownloadNftPermissions.svelte @@ -4,7 +4,7 @@ import { DownloadPermission } from '@core/nfts' import { activeProfile, updateActiveProfileSettings } from '@core/profile/stores' import SettingsSection from '../SettingsSection.svelte' - import { allAccountNfts } from '@core/nfts/stores' + import { getAllNftsForActiveProfile } from '@core/nfts/stores' import { addNftsToDownloadQueue } from '@core/nfts/actions' const options: IOption[] = [ @@ -40,7 +40,7 @@ }, }) - const allNfts = $allAccountNfts.flatMap((nfts) => nfts) + const allNfts = getAllNftsForActiveProfile() await addNftsToDownloadQueue(allNfts) } diff --git a/packages/desktop/views/settings/views/collectibles/MaxMediaSize.svelte b/packages/desktop/views/settings/views/collectibles/MaxMediaSize.svelte index 5a9e61b40b..734713fc30 100644 --- a/packages/desktop/views/settings/views/collectibles/MaxMediaSize.svelte +++ b/packages/desktop/views/settings/views/collectibles/MaxMediaSize.svelte @@ -3,8 +3,8 @@ import { Platform } from '@core/app' import { localize } from '@core/i18n' import { DownloadWarningType, Nft } from '@core/nfts' - import { addNftsToDownloadQueue, updateNftInAllAccountNfts } from '@core/nfts/actions' - import { persistedNftForActiveProfile, selectedAccountNfts } from '@core/nfts/stores' + import { addNftsToDownloadQueue } from '@core/nfts/actions' + import { persistedNftForActiveProfile, selectedAccountNfts, updateNftForAllAccounts } from '@core/nfts/stores' import { activeProfile, updateActiveProfileSettings } from '@core/profile/stores' import SettingsSection from '../SettingsSection.svelte' @@ -69,7 +69,8 @@ } await Platform.deleteFile(nft.downloadMetadata.filePath) - updateNftInAllAccountNfts(nft.id, { + updateNftForAllAccounts({ + id: nft.id, isLoaded: false, downloadMetadata: { ...nft.downloadMetadata, diff --git a/packages/desktop/views/settings/views/collectibles/RefreshNftMedia.svelte b/packages/desktop/views/settings/views/collectibles/RefreshNftMedia.svelte index c490a8d84e..415c35f9ef 100644 --- a/packages/desktop/views/settings/views/collectibles/RefreshNftMedia.svelte +++ b/packages/desktop/views/settings/views/collectibles/RefreshNftMedia.svelte @@ -2,12 +2,8 @@ import { Button } from '@bloomwalletio/ui' import { Platform } from '@core/app' import { localize } from '@core/i18n' - import { - addNftsToDownloadQueue, - stopDownloadingNftMediaFromQueue, - updateNftInAllAccountNfts, - } from '@core/nfts/actions' - import { selectedAccountNfts } from '@core/nfts/stores' + import { addNftsToDownloadQueue, stopDownloadingNftMediaFromQueue } from '@core/nfts/actions' + import { selectedAccountNfts, updateNftForAllAccounts } from '@core/nfts/stores' import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup' import SettingsSection from '../SettingsSection.svelte' @@ -34,7 +30,7 @@ await Promise.all( $selectedAccountNfts.map(async (nft) => { await Platform.deleteFile(nft.downloadMetadata?.filePath) - updateNftInAllAccountNfts(nft.id, { isLoaded: false }) + updateNftForAllAccounts({ id: nft.id, isLoaded: false }) }) ) void addNftsToDownloadQueue($selectedAccountNfts) diff --git a/packages/shared/src/components/activities/evm/EvmActivityInformation.svelte b/packages/shared/src/components/activities/evm/EvmActivityInformation.svelte index 774e6177c6..385aec6c3f 100644 --- a/packages/shared/src/components/activities/evm/EvmActivityInformation.svelte +++ b/packages/shared/src/components/activities/evm/EvmActivityInformation.svelte @@ -4,7 +4,7 @@ import { EvmActivity } from '@core/activity' import { EvmActivityType } from '@core/activity/enums/evm' import { Nft, NftStandard } from '@core/nfts' - import { getNftByIdFromAllAccountNfts } from '@core/nfts/actions' + import { getNftByIdForAccount } from '@core/nfts/stores' import { KeyValue, NftMetadataTable, PopupTab, getTabItems } from '@ui' import { EvmGenericInformation, EvmSmartContractInformation } from './info' import { localize } from '@core/i18n' @@ -27,7 +27,7 @@ activity.tokenTransfer.standard === NftStandard.Erc721 || activity.tokenTransfer.standard === NftStandard.Irc27 ) { - nft = getNftByIdFromAllAccountNfts($selectedAccountIndex, activity.tokenTransfer.tokenId) + nft = getNftByIdForAccount($selectedAccountIndex, activity.tokenTransfer.tokenId) tabs = getTabItems([PopupTab.Transaction, PopupTab.NftMetadata]) } else { tabs = getTabItems([PopupTab.Transaction]) diff --git a/packages/shared/src/components/activities/stardust/StardustActivityInformation.svelte b/packages/shared/src/components/activities/stardust/StardustActivityInformation.svelte index 40106c9a31..4dd2162b1e 100644 --- a/packages/shared/src/components/activities/stardust/StardustActivityInformation.svelte +++ b/packages/shared/src/components/activities/stardust/StardustActivityInformation.svelte @@ -2,8 +2,8 @@ import { Tabs } from '@bloomwalletio/ui' import { selectedAccountIndex } from '@core/account/stores' import { StardustActivity, StardustActivityType } from '@core/activity' - import { Nft } from '@core/nfts' - import { getNftByIdFromAllAccountNfts } from '@core/nfts/actions' + import { Nft } from '@core/nfts/interfaces' + import { getNftByIdForAccount } from '@core/nfts/stores' import { TokenMetadata } from '@core/token' import { getPersistedToken } from '@core/token/stores' import { KeyValue, NftMetadataTable, PopupTab, TokenMetadataTable, getTabItems } from '@ui' @@ -24,7 +24,7 @@ $: { const storedNft = activity.type === StardustActivityType.Nft - ? getNftByIdFromAllAccountNfts($selectedAccountIndex, activity.nftId) + ? getNftByIdForAccount($selectedAccountIndex, activity.nftId) : undefined hasMetadata = !!storedNft?.metadata } @@ -47,7 +47,7 @@ ...(hasMetadata ? [PopupTab.NftMetadata] : []), ...(activity.smartContract ? [PopupTab.SmartContract] : []), ]) - nft = getNftByIdFromAllAccountNfts($selectedAccountIndex, activity.nftId) + nft = getNftByIdForAccount($selectedAccountIndex, activity.nftId) break case StardustActivityType.Foundry: tabs = getTabItems([PopupTab.Transaction, PopupTab.Foundry, PopupTab.Token]) diff --git a/packages/shared/src/components/activities/stardust/info/StardustNftInformation.svelte b/packages/shared/src/components/activities/stardust/info/StardustNftInformation.svelte index 1f170fc3f8..6388824265 100644 --- a/packages/shared/src/components/activities/stardust/info/StardustNftInformation.svelte +++ b/packages/shared/src/components/activities/stardust/info/StardustNftInformation.svelte @@ -6,15 +6,15 @@ import { localize } from '@core/i18n' import { ExplorerEndpoint } from '@core/network/enums' import { getDefaultExplorerUrl } from '@core/network/utils' - import { NftStandard } from '@core/nfts' - import { getNftByIdFromAllAccountNfts } from '@core/nfts/actions' + import { NftStandard } from '@core/nfts/enums' + import { getNftByIdForAccount } from '@core/nfts/stores' import { buildUrl } from '@core/utils' import { getBech32AddressFromAddressTypes, getHexAddressFromAddressTypes } from '@core/wallet' import { type Address, AddressType } from '@iota/sdk/out/types' export let activity: StardustNftActivity - $: nft = getNftByIdFromAllAccountNfts($selectedAccountIndex, activity?.nftId) + $: nft = getNftByIdForAccount($selectedAccountIndex, activity?.nftId) $: issuer = nft?.standard === NftStandard.Irc27 ? nft?.issuer : undefined function onNftIdClick(nftId: string) { diff --git a/packages/shared/src/lib/core/activity/actions/setAsyncStatusOfAccountActivities.ts b/packages/shared/src/lib/core/activity/actions/setAsyncStatusOfAccountActivities.ts index 0c989eea6f..e1b2ca4ce2 100644 --- a/packages/shared/src/lib/core/activity/actions/setAsyncStatusOfAccountActivities.ts +++ b/packages/shared/src/lib/core/activity/actions/setAsyncStatusOfAccountActivities.ts @@ -1,11 +1,11 @@ import { syncBalance } from '@core/account/actions/syncBalance' -import { updateNftInAllAccountNftsForAccount } from '@core/nfts/actions' import { loadTokensForAllAccountBalances } from '@core/token/actions' import { StardustActivityAsyncStatus, ActivityDirection, StardustActivityType } from '../enums' import { allAccountActivities } from '../stores' import { getAsyncStatus } from '../utils/helper' import { NetworkNamespace } from '@core/network' import { StardustActivity } from '../types' +import { updateNftForAccount } from '@core/nfts/stores' export function setAsyncStatusOfAccountActivities(time: Date): void { const balancesToUpdate: number[] = [] @@ -44,7 +44,7 @@ export function setAsyncStatusOfAccountActivities(time: Date): void { activity.asyncData.asyncStatus === StardustActivityAsyncStatus.Expired && activity.direction === ActivityDirection.Outgoing ) { - updateNftInAllAccountNftsForAccount(accountIndex, activity.nftId, { isSpendable: true }) + updateNftForAccount(accountIndex, { id: activity.nftId, isSpendable: true }) } } } diff --git a/packages/shared/src/lib/core/activity/utils/convertActvitiesToCsv.ts b/packages/shared/src/lib/core/activity/utils/convertActvitiesToCsv.ts index bff52b030f..f68a31085f 100644 --- a/packages/shared/src/lib/core/activity/utils/convertActvitiesToCsv.ts +++ b/packages/shared/src/lib/core/activity/utils/convertActvitiesToCsv.ts @@ -23,8 +23,8 @@ import { TokenStandard, formatTokenAmountBestMatch, } from '@core/token' -import { NftStandard } from '@core/nfts' -import { getNftByIdFromAllAccountNfts } from '@core/nfts/actions' +import { NftStandard } from '@core/nfts/enums' +import { getNftByIdForAccount } from '@core/nfts/stores' import { isEvmTokenActivity } from './isEvmTokenActivity' const CSV_KEYS = [ @@ -132,7 +132,7 @@ function getRowForStardustActivity( assetTicker = baseCoinMetadata?.tickerSymbol } } else if (activity.type === StardustActivityType.Nft) { - const nft = getNftByIdFromAllAccountNfts(account.index, activity.nftId) + const nft = getNftByIdForAccount(account.index, activity.nftId) assetId = activity.nftId assetType = 'NFT' @@ -232,7 +232,7 @@ function getRowForEvmActivity( assetName = metadata?.name assetTicker = metadata?.symbol } else if (standard === NftStandard.Erc721 || standard === NftStandard.Irc27) { - const nft = getNftByIdFromAllAccountNfts(account.index, tokenId) + const nft = getNftByIdForAccount(account.index, tokenId) assetId = tokenId assetType = 'NFT' diff --git a/packages/shared/src/lib/core/activity/utils/getActivityTileAsset.ts b/packages/shared/src/lib/core/activity/utils/getActivityTileAsset.ts index cc79f16673..8a20778eef 100644 --- a/packages/shared/src/lib/core/activity/utils/getActivityTileAsset.ts +++ b/packages/shared/src/lib/core/activity/utils/getActivityTileAsset.ts @@ -1,6 +1,6 @@ import { StardustActivityType, StardustGovernanceAction } from '../enums' import { Activity } from '../types' -import { getNftByIdFromAllAccountNfts } from '@core/nfts/actions' +import { getNftByIdForAccount } from '@core/nfts/stores' import { getTokenFromActivity } from './getTokenFromActivity' import { get } from 'svelte/store' import { registeredProposalsForSelectedAccount } from '@contexts/governance' @@ -22,7 +22,7 @@ export function getActivityTileAsset(activity: Activity, accountIndex: number): return token.metadata?.name ? token.metadata.name : token.id } else if (activity.type === StardustActivityType.Nft) { - const nft = getNftByIdFromAllAccountNfts(accountIndex, activity.nftId) + const nft = getNftByIdForAccount(accountIndex, activity.nftId) return nft?.name ? nft.name : 'NFT' } else if (activity.type === StardustActivityType.Alias) { return 'Alias ' + activity.aliasId @@ -54,7 +54,7 @@ export function getActivityTileAsset(activity: Activity, accountIndex: number): activity.tokenTransfer.standard === NftStandard.Erc721 || activity.tokenTransfer.standard === NftStandard.Irc27 ) { - const nft = getNftByIdFromAllAccountNfts(accountIndex, activity.tokenTransfer.tokenId) + const nft = getNftByIdForAccount(accountIndex, activity.tokenTransfer.tokenId) return nft?.name ? nft.name : localize('general.nft') } else { const token = getTokenFromSelectedAccountTokens( diff --git a/packages/shared/src/lib/core/activity/utils/getTransactionAssets.ts b/packages/shared/src/lib/core/activity/utils/getTransactionAssets.ts index 2f23133cf8..323e67aa3e 100644 --- a/packages/shared/src/lib/core/activity/utils/getTransactionAssets.ts +++ b/packages/shared/src/lib/core/activity/utils/getTransactionAssets.ts @@ -1,5 +1,5 @@ import { Nft } from '@core/nfts' -import { getNftByIdFromAllAccountNfts } from '@core/nfts/actions' +import { getNftByIdForAccount } from '@core/nfts/stores' import { TokenTransferData } from '@core/wallet/types' import { ActivityAction, StardustActivityType, StardustGovernanceAction } from '../enums' import { StardustActivity } from '../types' @@ -35,7 +35,7 @@ export function getTransactionAssets( } if (activity.type === StardustActivityType.Nft) { - const nft = getNftByIdFromAllAccountNfts(accountIndex, activity.nftId) + const nft = getNftByIdForAccount(accountIndex, activity.nftId) return { nft, baseCoinTransfer, diff --git a/packages/shared/src/lib/core/activity/utils/isVisibleActivity.ts b/packages/shared/src/lib/core/activity/utils/isVisibleActivity.ts index baace0f120..f8b770428f 100644 --- a/packages/shared/src/lib/core/activity/utils/isVisibleActivity.ts +++ b/packages/shared/src/lib/core/activity/utils/isVisibleActivity.ts @@ -1,7 +1,7 @@ import { selectedAccountIndex } from '@core/account/stores' import { NetworkNamespace } from '@core/network' import { NftStandard } from '@core/nfts' -import { getNftByIdFromAllAccountNfts } from '@core/nfts/actions' +import { getNftByIdForAccount } from '@core/nfts/stores' import { BASE_TOKEN_ID, TokenStandard, convertToRawAmount } from '@core/token' import { getPersistedToken } from '@core/token/stores' import { dateIsAfterOtherDate, dateIsBeforeOtherDate, datesOnSameDay } from '@core/utils' @@ -69,7 +69,7 @@ function isVisibleWithActiveHiddenFilter(activity: Activity, filter: ActivityFil function doesActivityContainScamNft(activity: Activity): boolean { if (activity.type === StardustActivityType.Nft) { - const nft = getNftByIdFromAllAccountNfts(get(selectedAccountIndex), activity.nftId) + const nft = getNftByIdForAccount(get(selectedAccountIndex), activity.nftId) return nft?.isScam ?? false } else { return false diff --git a/packages/shared/src/lib/core/activity/utils/stardust/generateActivitiesFromBasicOutputs.ts b/packages/shared/src/lib/core/activity/utils/stardust/generateActivitiesFromBasicOutputs.ts index c31d3fe571..a79b18e0e1 100644 --- a/packages/shared/src/lib/core/activity/utils/stardust/generateActivitiesFromBasicOutputs.ts +++ b/packages/shared/src/lib/core/activity/utils/stardust/generateActivitiesFromBasicOutputs.ts @@ -1,5 +1,5 @@ import { IAccountState } from '@core/account' -import { updateAllAccountNftsForAccount, buildNftFromNftOutput } from '@core/nfts/actions' +import { buildNftFromNftOutput } from '@core/nfts/actions' import { IWrappedOutput } from '@core/wallet' import { NftOutput, OutputType } from '@iota/sdk/out/types' import { ActivityAction, ActivityDirection } from '../../enums' @@ -10,6 +10,7 @@ import { generateSingleNftActivity } from './generateSingleNftActivity' import { getNonRemainderBasicOutputsFromTransaction } from './getNonRemainderBasicOutputsFromTransaction' import { getNftId } from '../outputs' import { StardustNetworkId } from '@core/network/types' +import { addOrUpdateNftForAccount } from '@core/nfts/stores' export async function generateActivitiesFromBasicOutputs( processedTransaction: IProcessedTransaction, @@ -56,7 +57,7 @@ export async function generateActivitiesFromBasicOutputs( getNftId(nftInput.nftId, wrappedInput.outputId) ) const nft = buildNftFromNftOutput(wrappedInput, networkId, account.depositAddress, false) - updateAllAccountNftsForAccount(account.index, nft) + addOrUpdateNftForAccount(account.index, nft) burnedNftInputs.splice(burnedNftInputIndex, 1) } else if (isSelfTransaction && burnedNativeToken) { diff --git a/packages/shared/src/lib/core/app/actions/registerNftDownloadEvents.ts b/packages/shared/src/lib/core/app/actions/registerNftDownloadEvents.ts index 1c338ed078..f16371bf2b 100644 --- a/packages/shared/src/lib/core/app/actions/registerNftDownloadEvents.ts +++ b/packages/shared/src/lib/core/app/actions/registerNftDownloadEvents.ts @@ -1,5 +1,4 @@ -import { updateNftInAllAccountNfts } from '@core/nfts/actions' -import { downloadingNftId, removeNftFromDownloadQueue } from '@core/nfts/stores' +import { downloadingNftId, removeNftFromDownloadQueue, updateNftForAllAccounts } from '@core/nfts/stores' import { Platform } from '../classes' /** @@ -7,7 +6,7 @@ import { Platform } from '../classes' */ export function registerNftDownloadEvents(): void { Platform.onEvent('nft-download-done', ({ nftId }) => { - updateNftInAllAccountNfts(nftId, { isLoaded: true }) + updateNftForAllAccounts({ id: nftId, isLoaded: true }) removeNftFromDownloadQueue(nftId) downloadingNftId.set(undefined) }) diff --git a/packages/shared/src/lib/core/layer-2/utils/fetchIscAssetsForAccount.ts b/packages/shared/src/lib/core/layer-2/utils/fetchIscAssetsForAccount.ts index 3f0761411e..c1693198ef 100644 --- a/packages/shared/src/lib/core/layer-2/utils/fetchIscAssetsForAccount.ts +++ b/packages/shared/src/lib/core/layer-2/utils/fetchIscAssetsForAccount.ts @@ -4,16 +4,12 @@ import { ISC_MAGIC_CONTRACT_ADDRESS } from '@core/layer-2/constants' import { ContractType } from '@core/layer-2/enums' import { getSmartContractHexName, evmAddressToAgentId, getAgentBalanceParameters } from '@core/layer-2/helpers' import { IscChain } from '@core/network' -import { isIrc27Nft, getNftsFromNftIds } from '@core/nfts' -import { - updateAllAccountNftsForAccount, - setNftInAllAccountNftsToUnspendable, - addNftsToDownloadQueue, -} from '@core/nfts/actions' -import { selectedAccountNfts } from '@core/nfts/stores' +import { isIrc27Nft, getNftsFromNftIds, Nft } from '@core/nfts' +import { addNftsToDownloadQueue } from '@core/nfts/actions' +import { addOrUpdateNftsForAccount, selectedAccountNfts, updateNftsForAccount } from '@core/nfts/stores' import { BASE_TOKEN_ID, ITokenBalance } from '@core/token' import { getOrRequestTokenFromPersistedTokens } from '@core/token/actions' -import { Converter } from '@core/utils' +import { Converter, PartialWithId } from '@core/utils' import { KeyValue } from '@ui' import { get } from 'svelte/store' @@ -82,19 +78,20 @@ async function fetchL2Irc27Nfts( const newNftIds = nftIds.filter((nftId) => !nftsForChain.some((nft) => nft.id === nftId)) const nfts = await getNftsFromNftIds(newNftIds, networkId) - updateAllAccountNftsForAccount(account.index, ...nfts) + addOrUpdateNftsForAccount(account.index, nfts) - const unspendableNftIds: string[] = nftsForChain + const unspendableNfts = nftsForChain .filter((nft) => !nftIds.some((nftId) => nft.id === nftId)) - .map((nft) => nft.id) - setNftInAllAccountNftsToUnspendable(account.index, ...unspendableNftIds) + .map((nft) => ({ id: nft.id, isSpendable: false }) as PartialWithId) + + updateNftsForAccount(account.index, unspendableNfts) void addNftsToDownloadQueue(nfts) for (const nft of nfts) { calculateAndAddPersistedNftBalanceChange(profileId, account, networkId, nft.id, true) } - for (const nftId of unspendableNftIds) { - calculateAndAddPersistedNftBalanceChange(profileId, account, networkId, nftId, false) + for (const nft of unspendableNfts) { + calculateAndAddPersistedNftBalanceChange(profileId, account, networkId, nft.id, false) } } catch (err) { console.error(err) diff --git a/packages/shared/src/lib/core/nfts/actions/addNftsToDownloadQueue.ts b/packages/shared/src/lib/core/nfts/actions/addNftsToDownloadQueue.ts index 355044b7ba..7e5e273cab 100644 --- a/packages/shared/src/lib/core/nfts/actions/addNftsToDownloadQueue.ts +++ b/packages/shared/src/lib/core/nfts/actions/addNftsToDownloadQueue.ts @@ -1,7 +1,6 @@ import { get } from 'svelte/store' -import { updateNftInAllAccountNfts } from '.' import { Nft } from '../interfaces' -import { addNftToDownloadQueue, nftDownloadQueue, updatePersistedNft } from '../stores' +import { addNftToDownloadQueue, nftDownloadQueue, updateNftForAllAccounts, updatePersistedNft } from '../stores' import { checkIfNftShouldBeDownloaded } from '../utils/checkIfNftShouldBeDownloaded' import { NftDownloadOptions } from '../types' @@ -36,7 +35,7 @@ async function validateNft(nft: Nft, skipDownloadSettingsCheck: boolean): Promis skipDownloadSettingsCheck ) updatePersistedNft(nft.id, { downloadMetadata }) - updateNftInAllAccountNfts(nft.id, { downloadMetadata, isLoaded }) + updateNftForAllAccounts({ id: nft.id, downloadMetadata, isLoaded }) if (shouldDownload) { return nft diff --git a/packages/shared/src/lib/core/nfts/actions/checkForUntrackedNfts.ts b/packages/shared/src/lib/core/nfts/actions/checkForUntrackedNfts.ts index 0d4275572e..6e16d26464 100644 --- a/packages/shared/src/lib/core/nfts/actions/checkForUntrackedNfts.ts +++ b/packages/shared/src/lib/core/nfts/actions/checkForUntrackedNfts.ts @@ -6,7 +6,6 @@ import features from '@features/features' import { NftStandard } from '../enums' import { persistNftWithContractMetadata } from './persistNftWithContractMetadata' -import { updateAllAccountNftsForAccount } from './updateAllAccountNfts' import { buildNftFromPersistedErc721Nft } from '../utils' import { addNftsToDownloadQueue } from './addNftsToDownloadQueue' import { Nft } from '../interfaces' @@ -14,6 +13,7 @@ import { addNewTrackedNftToActiveProfile } from './addNewTrackedNftToActiveProfi import { TokenTrackingStatus } from '@core/token' import { IBlockscoutAsset } from '@auxiliary/blockscout/interfaces' import { BlockscoutApi } from '@auxiliary/blockscout/api' +import { addOrUpdateNftForAccount } from '../stores' export async function checkForUntrackedNfts(account: IAccountState): Promise { if (!features?.collectibles?.erc721?.enabled) { @@ -69,7 +69,7 @@ async function persistNftsFromExplorerAsset( addNewTrackedNftToActiveProfile(networkId, persistedNft.id, TokenTrackingStatus.AutomaticallyTracked) const nft = buildNftFromPersistedErc721Nft(persistedNft, evmAddress) - updateAllAccountNftsForAccount(account.index, nft) + addOrUpdateNftForAccount(account.index, nft) return nft } catch (err) { // If we don't have the tokenId we cannot persist the NFT. ERC-721 contracts should implement diff --git a/packages/shared/src/lib/core/nfts/actions/downloadNextNftInQueue.ts b/packages/shared/src/lib/core/nfts/actions/downloadNextNftInQueue.ts index 17da2a521f..406f893821 100644 --- a/packages/shared/src/lib/core/nfts/actions/downloadNextNftInQueue.ts +++ b/packages/shared/src/lib/core/nfts/actions/downloadNextNftInQueue.ts @@ -1,13 +1,18 @@ import { Platform } from '@core/app/classes' import { get } from 'svelte/store' -import { downloadingNftId, nftDownloadQueue, removeNftFromDownloadQueue, updatePersistedNft } from '../stores' +import { + downloadingNftId, + nftDownloadQueue, + removeNftFromDownloadQueue, + updateNftForAllAccounts, + updatePersistedNft, +} from '../stores' import { buildFilePath, fetchWithTimeout, getFetchableNftUrls, isIrc27Nft } from '../utils' import { activeProfile } from '@core/profile/stores' import { BYTES_PER_MEGABYTE, HttpHeader, sleep } from '@core/utils' import { IDownloadMetadata, Nft } from '../interfaces' import { StatusCodes, getReasonPhrase } from 'http-status-codes' import { DownloadErrorType, DownloadWarningType, NftStandard } from '../enums' -import { updateNftInAllAccountNfts } from './updateNftInAllAccountNfts' const HEAD_FETCH_TIMEOUT_SECONDS = 10 const DELAY_AFTER_DOWNLOAD_ERROR = 2000 @@ -45,7 +50,7 @@ export async function downloadNextNftInQueue(): Promise { throw new Error('Invalid download metadata') } updatePersistedNft(nft.id, { downloadMetadata }) - updateNftInAllAccountNfts(nft.id, { downloadMetadata }) + updateNftForAllAccounts({ id: nft.id, downloadMetadata }) if ( !downloadMetadata?.downloadUrl || diff --git a/packages/shared/src/lib/core/nfts/actions/getNftByIdFromAllAccountNfts.ts b/packages/shared/src/lib/core/nfts/actions/getNftByIdFromAllAccountNfts.ts deleted file mode 100644 index b634b83f87..0000000000 --- a/packages/shared/src/lib/core/nfts/actions/getNftByIdFromAllAccountNfts.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { get } from 'svelte/store' -import { Nft } from '../interfaces' -import { allAccountNfts } from '../stores' - -export function getNftByIdFromAllAccountNfts(accountIndex: number, nftId: string | undefined): Nft | undefined { - return get(allAccountNfts)[accountIndex]?.find((_nft) => _nft.id?.toLowerCase() === nftId?.toLowerCase()) -} diff --git a/packages/shared/src/lib/core/nfts/actions/index.ts b/packages/shared/src/lib/core/nfts/actions/index.ts index 7489b48b4f..6c161aabf6 100644 --- a/packages/shared/src/lib/core/nfts/actions/index.ts +++ b/packages/shared/src/lib/core/nfts/actions/index.ts @@ -3,16 +3,11 @@ export * from './addNftsToDownloadQueue' export * from './buildNftFromNftOutput' export * from './checkForUntrackedNfts' export * from './downloadNextNftInQueue' -export * from './getNftByIdFromAllAccountNfts' export * from './getPersistedErc721NftsForNetwork' export * from './interruptNftDownloadAfterTimeout' export * from './isNftPersisted' export * from './loadNftsForActiveProfile' export * from './persistErc721Nft' export * from './persistNftWithContractMetadata' -export * from './setAccountNftsInAllAccountNfts' -export * from './setNftInAllAccountNftsToUnspendable' export * from './stopDownloadingNftMediaFromQueue' -export * from './updateAllAccountNfts' export * from './updateErc721NftOwnership' -export * from './updateNftInAllAccountNfts' diff --git a/packages/shared/src/lib/core/nfts/actions/interruptNftDownloadAfterTimeout.ts b/packages/shared/src/lib/core/nfts/actions/interruptNftDownloadAfterTimeout.ts index 8ae18e88db..8deefaa3e7 100644 --- a/packages/shared/src/lib/core/nfts/actions/interruptNftDownloadAfterTimeout.ts +++ b/packages/shared/src/lib/core/nfts/actions/interruptNftDownloadAfterTimeout.ts @@ -2,10 +2,8 @@ import { Platform } from '@core/app/classes' import { MILLISECONDS_PER_SECOND, sleep } from '@core/utils' import { get } from 'svelte/store' import { DownloadWarningType } from '../enums' -import { downloadingNftId, removeNftFromDownloadQueue } from '../stores' -import { updateNftInAllAccountNfts } from './updateNftInAllAccountNfts' +import { downloadingNftId, getNftByIdForAccount, removeNftFromDownloadQueue, updateNftForAllAccounts } from '../stores' import { activeProfile } from '@core/profile/stores' -import { getNftByIdFromAllAccountNfts } from './getNftByIdFromAllAccountNfts' export async function interruptNftDownloadAfterTimeout( accountIndex: number, @@ -22,9 +20,10 @@ export async function interruptNftDownloadAfterTimeout( if (downloadingNftIdToInterrupt === updatedDownloadingNft) { removeNftFromDownloadQueue(downloadingNftIdToInterrupt) await Platform.cancelNftDownload(downloadingNftIdToInterrupt) - const nft = getNftByIdFromAllAccountNfts(accountIndex, downloadingNftIdToInterrupt) + const nft = getNftByIdForAccount(accountIndex, downloadingNftIdToInterrupt) if (nft) { - updateNftInAllAccountNfts(downloadingNftIdToInterrupt, { + updateNftForAllAccounts({ + id: downloadingNftIdToInterrupt, isLoaded: false, downloadMetadata: { ...nft.downloadMetadata, diff --git a/packages/shared/src/lib/core/nfts/actions/loadNftsForActiveProfile.ts b/packages/shared/src/lib/core/nfts/actions/loadNftsForActiveProfile.ts index 5e0e46c9e8..3fb1e9fd44 100644 --- a/packages/shared/src/lib/core/nfts/actions/loadNftsForActiveProfile.ts +++ b/packages/shared/src/lib/core/nfts/actions/loadNftsForActiveProfile.ts @@ -14,7 +14,7 @@ import { buildNftFromPersistedErc721Nft, getNftsFromNftIds } from '../utils' import { addNftsToDownloadQueue } from './addNftsToDownloadQueue' import { buildNftFromNftOutput } from './buildNftFromNftOutput' import { getPersistedErc721NftsForNetwork } from './getPersistedErc721NftsForNetwork' -import { setAccountNftsInAllAccountNfts } from './setAccountNftsInAllAccountNfts' +import { setNftsForAccount } from '../stores' export async function loadNftsForActiveProfile(): Promise { let nftsToDownload: Nft[] = [] @@ -93,7 +93,7 @@ export async function loadNftsForAccount(profileId: string, account: IAccountSta } } } - setAccountNftsInAllAccountNfts(account.index, accountNfts) + setNftsForAccount(account.index, accountNfts) return accountNfts } diff --git a/packages/shared/src/lib/core/nfts/actions/setAccountNftsInAllAccountNfts.ts b/packages/shared/src/lib/core/nfts/actions/setAccountNftsInAllAccountNfts.ts deleted file mode 100644 index 015908ff7c..0000000000 --- a/packages/shared/src/lib/core/nfts/actions/setAccountNftsInAllAccountNfts.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { allAccountNfts } from '../stores' -import { Nft } from '../interfaces' - -export function setAccountNftsInAllAccountNfts(accountIndex: number, accountNfts: Nft[]): void { - allAccountNfts.update((state) => { - state[accountIndex] = accountNfts - return state - }) -} diff --git a/packages/shared/src/lib/core/nfts/actions/setNftInAllAccountNftsToUnspendable.ts b/packages/shared/src/lib/core/nfts/actions/setNftInAllAccountNftsToUnspendable.ts deleted file mode 100644 index d428d25504..0000000000 --- a/packages/shared/src/lib/core/nfts/actions/setNftInAllAccountNftsToUnspendable.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { allAccountNfts } from '../stores' -import { isIrc27Nft } from '@core/nfts' - -export function setNftInAllAccountNftsToUnspendable(accountIndex: number, ...unspendableNftIds: string[]): void { - allAccountNfts.update((state) => { - if (!state[accountIndex]) { - state[accountIndex] = [] - } - for (const nftId of unspendableNftIds) { - const nft = state[accountIndex].find((_nft) => _nft.id === nftId) - if (nft && isIrc27Nft(nft)) { - nft.isSpendable = false - Object.assign(nft, nft) - } - } - return state - }) -} diff --git a/packages/shared/src/lib/core/nfts/actions/updateAllAccountNfts.ts b/packages/shared/src/lib/core/nfts/actions/updateAllAccountNfts.ts deleted file mode 100644 index 3f5035b33b..0000000000 --- a/packages/shared/src/lib/core/nfts/actions/updateAllAccountNfts.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { allAccountNfts } from '../stores' -import { Nft } from '../interfaces' - -export function updateAllAccountNftsForAccount(accountIndex: number, ...newNfts: Nft[]): void { - allAccountNfts.update((state) => { - if (!state[accountIndex]) { - state[accountIndex] = [] - } - for (const newNft of newNfts) { - const nft = state[accountIndex].find((_nft) => _nft.id === newNft.id) - if (nft) { - Object.assign(nft, newNft) - } else { - state[accountIndex].push(newNft) - } - } - return state - }) -} diff --git a/packages/shared/src/lib/core/nfts/actions/updateErc721NftOwnership.ts b/packages/shared/src/lib/core/nfts/actions/updateErc721NftOwnership.ts index b3c65cd83c..5b0df12b69 100644 --- a/packages/shared/src/lib/core/nfts/actions/updateErc721NftOwnership.ts +++ b/packages/shared/src/lib/core/nfts/actions/updateErc721NftOwnership.ts @@ -1,8 +1,12 @@ import { IAccountState, getAddressFromAccountForNetwork } from '@core/account' -import { updateAllAccountNftsForAccount } from './updateAllAccountNfts' import { NftStandard } from '../enums' import { IErc721Nft } from '../interfaces' -import { getAllAccountNfts, persistedNftForActiveProfile, updatePersistedNft } from '../stores' +import { + addOrUpdateNftForAccount, + getNftsForAccount, + persistedNftForActiveProfile, + updatePersistedNft, +} from '../stores' import { getOwnerOfErc721Nft } from '../utils' import { get } from 'svelte/store' import { NetworkId } from '@core/network' @@ -10,7 +14,7 @@ import { NetworkId } from '@core/network' export async function updateErc721NftsOwnership(account: IAccountState, networkId: NetworkId): Promise { try { const trackedErc721Nfts = - (getAllAccountNfts()[account.index]?.filter((nft) => { + (getNftsForAccount(account.index)?.filter((nft) => { return nft.standard === NftStandard.Erc721 && nft.networkId === networkId }) as IErc721Nft[]) ?? [] const promises = trackedErc721Nfts.map(async (nft) => { @@ -25,7 +29,7 @@ export async function updateErc721NftsOwnership(account: IAccountState, networkI } const l2Address = getAddressFromAccountForNetwork(account, nft.networkId) const isSpendable = updatedOwner === l2Address?.toLowerCase() - updateAllAccountNftsForAccount(account.index, { ...nft, isSpendable }) + addOrUpdateNftForAccount(account.index, { ...nft, isSpendable }) }) await Promise.allSettled(promises) } catch (error) { diff --git a/packages/shared/src/lib/core/nfts/actions/updateNftInAllAccountNfts.ts b/packages/shared/src/lib/core/nfts/actions/updateNftInAllAccountNfts.ts deleted file mode 100644 index ee4e1f6980..0000000000 --- a/packages/shared/src/lib/core/nfts/actions/updateNftInAllAccountNfts.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { allAccountNfts } from '../stores' -import { Nft } from '../interfaces' - -export function updateNftInAllAccountNftsForAccount( - accountIndex: number, - nftId: string, - partialNft: Partial -): void { - allAccountNfts.update((state) => { - if (!state[accountIndex]) { - state[accountIndex] = [] - } - const nft = state[accountIndex].find((_nft) => _nft.id === nftId) - if (nft) { - Object.assign(nft, { ...nft, ...partialNft }) - } - return state - }) -} - -export function updateNftInAllAccountNfts(nftId: string, partialNft: Partial): void { - allAccountNfts.update((state) => { - for (const accountNfts of Object.values(state)) { - const nft = accountNfts.find((_nft) => _nft.id === nftId) - if (nft) { - Object.assign(nft, { ...nft, ...partialNft }) - } - } - return state - }) -} diff --git a/packages/shared/src/lib/core/nfts/stores/active-profile-nfts-per-account.store.ts b/packages/shared/src/lib/core/nfts/stores/active-profile-nfts-per-account.store.ts new file mode 100644 index 0000000000..3302ad29c0 --- /dev/null +++ b/packages/shared/src/lib/core/nfts/stores/active-profile-nfts-per-account.store.ts @@ -0,0 +1,79 @@ +import { get, writable } from 'svelte/store' + +import { Nft } from '../interfaces' +import { PartialWithId } from '@core/utils' + +export const activeProfileNftsPerAccount = writable<{ [accountIndex: number]: Nft[] }>({}) + +export function clearActiveProfileNftsPerAccount(): void { + activeProfileNftsPerAccount.set({}) +} + +export function getAllNftsForActiveProfile(): Nft[] { + return Object.values(get(activeProfileNftsPerAccount)).flat() +} + +export function getNftsForAccount(accountIndex: number): Nft[] { + return get(activeProfileNftsPerAccount)[accountIndex] ?? [] +} + +export function setNftsForAccount(accountIndex: number, nfts: Nft[]): void { + activeProfileNftsPerAccount.update((state) => { + state[accountIndex] = nfts + return state + }) +} + +export function addOrUpdateNftsForAccount(accountIndex: number, nfts: Nft[]): void { + activeProfileNftsPerAccount.update((state) => { + if (!state[accountIndex]) { + state[accountIndex] = [] + } + + for (const nft of nfts) { + const existingNft = state[accountIndex].find((_nft) => _nft.id === nft.id) + if (existingNft) { + Object.assign(existingNft, nft) + } else { + state[accountIndex].push(nft) + } + } + return state + }) +} + +export function addOrUpdateNftForAccount(accountIndex: number, nft: Nft): void { + addOrUpdateNftsForAccount(accountIndex, [nft]) +} + +export function updateNftsForAccount(accountIndex: number, partialNfts: PartialWithId[]): void { + activeProfileNftsPerAccount.update((state) => { + if (!state[accountIndex]) { + state[accountIndex] = [] + } + + for (const partialNft of partialNfts) { + const existingNft = state[accountIndex].find((nft) => nft.id === partialNft.id) + if (existingNft) { + Object.assign(existingNft, partialNft) + } + } + return state + }) +} + +export function updateNftForAccount(accountIndex: number, partialNft: PartialWithId): void { + updateNftsForAccount(accountIndex, [partialNft]) +} + +export function updateNftForAllAccounts(partialNft: PartialWithId): void { + for (const accountIndex of Object.keys(get(activeProfileNftsPerAccount)) as unknown as number[]) { + updateNftForAccount(accountIndex, partialNft) + } +} + +export function getNftByIdForAccount(accountIndex: number | undefined, nftId: string): Nft | undefined { + return accountIndex + ? getNftsForAccount(accountIndex)?.find((nft) => nft.id?.toLowerCase() === nftId?.toLowerCase()) + : undefined +} diff --git a/packages/shared/src/lib/core/nfts/stores/all-account-nfts.store.ts b/packages/shared/src/lib/core/nfts/stores/all-account-nfts.store.ts deleted file mode 100644 index 8c930ff503..0000000000 --- a/packages/shared/src/lib/core/nfts/stores/all-account-nfts.store.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { get, writable } from 'svelte/store' - -import { Nft } from '../interfaces' - -export const allAccountNfts = writable([]) - -export function clearAccountNfts(): void { - allAccountNfts.set([]) -} - -export function getAllAccountNfts(): Nft[][] { - return get(allAccountNfts) -} diff --git a/packages/shared/src/lib/core/nfts/stores/index.ts b/packages/shared/src/lib/core/nfts/stores/index.ts index c0b7aa9faf..f7011e66b6 100644 --- a/packages/shared/src/lib/core/nfts/stores/index.ts +++ b/packages/shared/src/lib/core/nfts/stores/index.ts @@ -1,4 +1,4 @@ -export * from './all-account-nfts.store' +export * from './active-profile-nfts-per-account.store' export * from './downloading-nft.store' export * from './nft-download-queue.store' export * from './nft-filter.store' diff --git a/packages/shared/src/lib/core/nfts/stores/selected-account-nfts.store.ts b/packages/shared/src/lib/core/nfts/stores/selected-account-nfts.store.ts index c89e3aad01..60c8528428 100644 --- a/packages/shared/src/lib/core/nfts/stores/selected-account-nfts.store.ts +++ b/packages/shared/src/lib/core/nfts/stores/selected-account-nfts.store.ts @@ -1,15 +1,15 @@ import { derived, Readable, Writable, writable } from 'svelte/store' -import { selectedAccount } from '@core/account/stores' +import { selectedAccountIndex } from '@core/account/stores' import { IIrc27Nft, Nft } from '../interfaces' -import { allAccountNfts } from './all-account-nfts.store' +import { activeProfileNftsPerAccount } from './active-profile-nfts-per-account.store' import { time } from '@core/app/stores/time.store' import { NftStandard } from '@core/nfts' export const selectedAccountNfts: Readable = derived( - [selectedAccount, allAccountNfts], - ([$selectedAccount, $allAccountNfts]) => { - if ($selectedAccount) { - return $allAccountNfts[$selectedAccount.index] ?? [] + [selectedAccountIndex, activeProfileNftsPerAccount], + ([$selectedAccountIndex, $nftsPerAccount]) => { + if ($selectedAccountIndex !== undefined) { + return $nftsPerAccount[$selectedAccountIndex] ?? [] } else { return [] } diff --git a/packages/shared/src/lib/core/nfts/utils/isNftOwnedByAnyAccount.ts b/packages/shared/src/lib/core/nfts/utils/isNftOwnedByAnyAccount.ts index 6429521580..10fd7b7e57 100644 --- a/packages/shared/src/lib/core/nfts/utils/isNftOwnedByAnyAccount.ts +++ b/packages/shared/src/lib/core/nfts/utils/isNftOwnedByAnyAccount.ts @@ -1,9 +1,11 @@ import { get } from 'svelte/store' import { NftStandard } from '../enums' -import { allAccountNfts } from '../stores' +import { activeProfileNftsPerAccount } from '../stores' +// TODO: This function is not used an potentially needs to be removed +// Also its not working as expected because not spendable does not mean not owned export function isNftOwnedByAnyAccount(nftId: string): boolean { - for (const accountNfts of get(allAccountNfts) ?? []) { + for (const accountNfts of Object.values(get(activeProfileNftsPerAccount))) { const nft = accountNfts.find((nft) => nft.id === nftId) switch (nft?.standard) { case NftStandard.Erc721: diff --git a/packages/shared/src/lib/core/profile-manager/actions/events-handlers/handleNewOutputEvent.ts b/packages/shared/src/lib/core/profile-manager/actions/events-handlers/handleNewOutputEvent.ts index 85979c086d..577dbc9f7d 100644 --- a/packages/shared/src/lib/core/profile-manager/actions/events-handlers/handleNewOutputEvent.ts +++ b/packages/shared/src/lib/core/profile-manager/actions/events-handlers/handleNewOutputEvent.ts @@ -8,11 +8,12 @@ import { addAccountActivities, allAccountActivities } from '@core/activity/store import { generateActivitiesFromStardustNetwork } from '@core/activity/utils' import { preprocessGroupedOutputs } from '@core/activity/utils/outputs' import { getActiveNetworkId } from '@core/network' -import { addNftsToDownloadQueue, updateAllAccountNftsForAccount, buildNftFromNftOutput } from '@core/nfts/actions' +import { addNftsToDownloadQueue, buildNftFromNftOutput } from '@core/nfts/actions' import { getOrRequestTokenFromPersistedTokens } from '@core/token/actions' import { getBech32AddressFromAddressTypes } from '@core/wallet/utils/getBech32AddressFromAddressTypes' import { get } from 'svelte/store' import { validateWalletApiEvent } from '../../utils' +import { addOrUpdateNftForAccount } from '@core/nfts/stores' export function handleNewOutputEvent(error: Error, event: Event): void { const walletEvent = validateWalletApiEvent(error, event, WalletEventType.NewOutput) @@ -57,7 +58,7 @@ export async function handleNewOutputEventInternal( if (isNftOutput) { const nft = buildNftFromNftOutput(output as IWrappedOutput, networkId, account.depositAddress) - updateAllAccountNftsForAccount(account.index, nft) + addOrUpdateNftForAccount(account.index, nft) void addNftsToDownloadQueue([nft]) checkAndRemoveProfilePicture() diff --git a/packages/shared/src/lib/core/profile-manager/actions/events-handlers/handleSpentOutputEvent.ts b/packages/shared/src/lib/core/profile-manager/actions/events-handlers/handleSpentOutputEvent.ts index 780dd00d9f..2d10ac6469 100644 --- a/packages/shared/src/lib/core/profile-manager/actions/events-handlers/handleSpentOutputEvent.ts +++ b/packages/shared/src/lib/core/profile-manager/actions/events-handlers/handleSpentOutputEvent.ts @@ -4,13 +4,13 @@ import { allAccountActivities, updateAsyncDataByTransactionId, } from '@core/activity/stores/all-account-activities.store' -import { getNftByIdFromAllAccountNfts, updateNftInAllAccountNftsForAccount } from '@core/nfts/actions' +import { NetworkNamespace } from '@core/network' +import { IIrc27Nft } from '@core/nfts' +import { getNftByIdForAccount, updateNftForAccount } from '@core/nfts/stores' import { activeAccounts } from '@core/profile/stores' +import { Event, SpentOutputWalletEvent, WalletEventType } from '@iota/sdk/out/types' import { get } from 'svelte/store' import { validateWalletApiEvent } from '../../utils' -import { Event, SpentOutputWalletEvent, WalletEventType } from '@iota/sdk/out/types' -import { IIrc27Nft } from '@core/nfts' -import { NetworkNamespace } from '@core/network' export async function handleSpentOutputEvent(error: Error, event: Event): Promise { const walletEvent = validateWalletApiEvent(error, event, WalletEventType.SpentOutput) @@ -40,7 +40,7 @@ export async function handleSpentOutputEventInternal( } if (activity.type === StardustActivityType.Nft) { - const nft = getNftByIdFromAllAccountNfts(accountIndex, activity.nftId) as IIrc27Nft + const nft = getNftByIdForAccount(accountIndex, activity.nftId) as IIrc27Nft const previousOutputId = nft?.latestOutputId if (previousOutputId) { const previousOutput = await account?.getOutput(previousOutputId) @@ -48,7 +48,7 @@ export async function handleSpentOutputEventInternal( previousOutput && output.metadata.milestoneTimestampBooked > previousOutput.metadata.milestoneTimestampBooked ) { - updateNftInAllAccountNftsForAccount(accountIndex, activity.nftId, { isSpendable: false }) + updateNftForAccount(accountIndex, { id: activity.nftId, isSpendable: false }) } } else { throw new Error(`Unable to find latest output ID for NFT ${nft.id}`) diff --git a/packages/shared/src/lib/core/profile-manager/actions/events-handlers/handleTransactionInclusionEvent.ts b/packages/shared/src/lib/core/profile-manager/actions/events-handlers/handleTransactionInclusionEvent.ts index e1727e3a19..deff94dc2f 100644 --- a/packages/shared/src/lib/core/profile-manager/actions/events-handlers/handleTransactionInclusionEvent.ts +++ b/packages/shared/src/lib/core/profile-manager/actions/events-handlers/handleTransactionInclusionEvent.ts @@ -1,23 +1,23 @@ import { updateParticipationOverview } from '@contexts/governance/stores' import { isAccountVoting } from '@contexts/governance/utils/isAccountVoting' import { syncVotingPower } from '@core/account/actions' -import { get } from 'svelte/store' import { ActivityAction, ActivityDirection, - StardustActivityType, InclusionState, + StardustActivityType, getActivityByTransactionId, updateActivityByTransactionId, updateClaimingTransactionInclusion, } from '@core/activity' import { StardustGovernanceActivity } from '@core/activity/types' -import { updateNftInAllAccountNftsForAccount } from '@core/nfts/actions' +import { updateNftForAccount } from '@core/nfts/stores' import { updateActiveAccountPersistedData } from '@core/profile/actions' import { activeAccounts, updateActiveAccount } from '@core/profile/stores' +import { Event, TransactionInclusionWalletEvent, WalletEventType } from '@iota/sdk/out/types' +import { get } from 'svelte/store' import { PopupId, closePopup, openPopup } from '../../../../../../../desktop/lib/auxiliary/popup' import { validateWalletApiEvent } from '../../utils' -import { Event, TransactionInclusionWalletEvent, WalletEventType } from '@iota/sdk/out/types' export function handleTransactionInclusionEvent(error: Error, event: Event): void { const walletEvent = validateWalletApiEvent( @@ -42,7 +42,7 @@ export function handleTransactionInclusionEventInternal( (activity.direction === ActivityDirection.Incoming || activity.direction === ActivityDirection.SelfTransaction) && activity.action !== ActivityAction.Burn - updateNftInAllAccountNftsForAccount(accountIndex, activity.nftId, { isSpendable }) + updateNftForAccount(accountIndex, { id: activity.id, isSpendable }) } if (activity?.type === StardustActivityType.Governance) { diff --git a/packages/shared/src/lib/core/profile/actions/active-profile/logout.ts b/packages/shared/src/lib/core/profile/actions/active-profile/logout.ts index e61c26fbd3..616e821174 100644 --- a/packages/shared/src/lib/core/profile/actions/active-profile/logout.ts +++ b/packages/shared/src/lib/core/profile/actions/active-profile/logout.ts @@ -22,7 +22,7 @@ import { closePopup } from '../../../../../../../desktop/lib/auxiliary/popup' import { closeDrawer } from '../../../../../../../desktop/lib/auxiliary/drawer' import { closeSettings } from '@contexts/settings/stores' import { clearLayer2Balance } from '@core/layer-2/stores' -import { clearAccountNfts } from '@core/nfts/stores' +import { clearActiveProfileNftsPerAccount } from '@core/nfts/stores' import { clearAccountActivities } from '@core/activity/stores' import { destroyNetworks } from '@core/network/stores' @@ -42,7 +42,7 @@ export function logout(clearActiveProfile = true, _lockStronghold = true): void clearLayer2Balance() clearMarketPricesPoll() - clearAccountNfts() + clearActiveProfileNftsPerAccount() clearAccountActivities() destroyNetworks() diff --git a/packages/shared/src/lib/core/utils/types/index.ts b/packages/shared/src/lib/core/utils/types/index.ts index d5f5296cb2..7751a4ba4f 100644 --- a/packages/shared/src/lib/core/utils/types/index.ts +++ b/packages/shared/src/lib/core/utils/types/index.ts @@ -4,6 +4,7 @@ export * from './exchange-rates.type' export * from './filter.type' export * from './types.type' export * from './filter.type' +export * from './partial-with-id.type' export * from './query-parameters.type' export * from './ui-event-function.type' export * from './values-of.type' diff --git a/packages/shared/src/lib/core/utils/types/partial-with-id.type.ts b/packages/shared/src/lib/core/utils/types/partial-with-id.type.ts new file mode 100644 index 0000000000..9e4cab2ca2 --- /dev/null +++ b/packages/shared/src/lib/core/utils/types/partial-with-id.type.ts @@ -0,0 +1 @@ +export type PartialWithId = Partial & { id: string } diff --git a/packages/shared/src/lib/core/wallet/actions/burnNft.ts b/packages/shared/src/lib/core/wallet/actions/burnNft.ts index 9f6f5da54d..6ce051a481 100644 --- a/packages/shared/src/lib/core/wallet/actions/burnNft.ts +++ b/packages/shared/src/lib/core/wallet/actions/burnNft.ts @@ -4,7 +4,7 @@ import { processAndAddToActivities } from '@core/activity/actions' import { handleError } from '@core/error/handlers' import { localize } from '@core/i18n' import { getActiveNetworkId } from '@core/network' -import { updateNftInAllAccountNftsForAccount } from '@core/nfts/actions' +import { updateNftForAccount } from '@core/nfts/stores' import { checkActiveProfileAuth } from '@core/profile/actions' import { sendPreparedTransaction } from '@core/wallet/utils' @@ -23,7 +23,7 @@ export async function burnNft(nftId: string): Promise { await processAndAddToActivities(burnNftTransaction, account, networkId) // Update NFT - updateNftInAllAccountNftsForAccount(account.index, nftId, { isSpendable: false }) + updateNftForAccount(account.index, { id: nftId, isSpendable: false }) showNotification({ variant: 'success', diff --git a/packages/shared/src/lib/core/wallet/actions/mintNft.ts b/packages/shared/src/lib/core/wallet/actions/mintNft.ts index 226aec3f7d..834bfdf8b4 100644 --- a/packages/shared/src/lib/core/wallet/actions/mintNft.ts +++ b/packages/shared/src/lib/core/wallet/actions/mintNft.ts @@ -8,12 +8,13 @@ import { generateSingleNftActivity } from '@core/activity/utils/stardust/generat import { preprocessTransaction } from '@core/activity/utils/outputs' import { localize } from '@core/i18n' import { IIrc27Metadata } from '@core/nfts' -import { updateAllAccountNftsForAccount, buildNftFromNftOutput } from '@core/nfts/actions' +import { buildNftFromNftOutput } from '@core/nfts/actions' import { Converter } from '@core/utils' import { MintNftParams, OutputType } from '@iota/sdk/out/types' import { getTransactionOptions } from '../utils' import { resetMintNftDetails } from '../stores' import { getActiveNetworkId } from '@core/network' +import { addOrUpdateNftForAccount } from '@core/nfts/stores' export async function mintNft( metadata: IIrc27Metadata, @@ -71,7 +72,7 @@ export async function mintNft( // Store NFT metadata for each minted NFT const nft = buildNftFromNftOutput(output, networkId, account.depositAddress, false) - updateAllAccountNftsForAccount(account.index, nft) + addOrUpdateNftForAccount(account.index, nft) } } } catch (err) { diff --git a/packages/shared/src/lib/core/wallet/actions/send/signAndSendStardustTransaction.ts b/packages/shared/src/lib/core/wallet/actions/send/signAndSendStardustTransaction.ts index 954c8ef3b5..df48f5533f 100644 --- a/packages/shared/src/lib/core/wallet/actions/send/signAndSendStardustTransaction.ts +++ b/packages/shared/src/lib/core/wallet/actions/send/signAndSendStardustTransaction.ts @@ -1,10 +1,10 @@ import { NftOutput, OutputType } from '@iota/sdk/out/types' import { IAccountState } from '@core/account' import { processAndAddToActivities } from '@core/activity/actions' -import { updateNftInAllAccountNftsForAccount } from '@core/nfts/actions' import { Output } from '@core/wallet/types' import { getActiveNetworkId } from '@core/network' import { getTransactionOptions } from '@core/wallet/utils' +import { updateNftForAccount } from '@core/nfts/stores' export async function signAndSendStardustTransaction(output: Output, account: IAccountState): Promise { const networkId = getActiveNetworkId() @@ -12,7 +12,7 @@ export async function signAndSendStardustTransaction(output: Output, account: IA // Reset transaction details state, since the transaction has been sent if (output.type === OutputType.Nft) { const { nftId } = output as NftOutput - updateNftInAllAccountNftsForAccount(account.index, nftId, { isSpendable: false }) + updateNftForAccount(account.index, { id: nftId, isSpendable: false }) } await processAndAddToActivities(transaction, account, networkId) diff --git a/packages/shared/src/lib/core/wallet/actions/sendOutput.ts b/packages/shared/src/lib/core/wallet/actions/sendOutput.ts index 0bbea87581..dc99f5b826 100644 --- a/packages/shared/src/lib/core/wallet/actions/sendOutput.ts +++ b/packages/shared/src/lib/core/wallet/actions/sendOutput.ts @@ -1,6 +1,6 @@ import { NftOutput, OutputType } from '@iota/sdk/out/types' import { getSelectedAccount, updateSelectedAccount } from '@core/account/stores' -import { updateNftInAllAccountNftsForAccount } from '@core/nfts/actions' +import { updateNftForAccount } from '@core/nfts/stores' import { processAndAddToActivities } from '@core/activity/actions' import { getTransactionOptions } from '../utils' @@ -17,7 +17,7 @@ export async function sendOutput(output: Output): Promise { // Reset transaction details state, since the transaction has been sent if (output.type === OutputType.Nft) { const nftId = (output as NftOutput).nftId - updateNftInAllAccountNftsForAccount(account.index, nftId, { isSpendable: false }) + updateNftForAccount(account.index, { id: nftId, isSpendable: false }) } await processAndAddToActivities(transaction, account, networkId)