Skip to content

Commit

Permalink
feat: remove irrelevant data on network removal (#2742)
Browse files Browse the repository at this point in the history
* remove activities for network id

* remove NFTS for network
  • Loading branch information
MarkNerdi authored Jul 18, 2024
1 parent 746c846 commit 5eddbe8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { get, writable } from 'svelte/store'
import { AsyncData, BaseStardustActivity, Activity, EvmActivity, BaseEvmActivity } from '../types'
import { NetworkNamespace } from '@core/network'
import { NetworkId, NetworkNamespace } from '@core/network'

export const allAccountActivities = writable<{ [accountIndex: number]: Activity[] }>({})

Expand Down Expand Up @@ -140,3 +140,15 @@ export function updateAccountActivitiesInAllAccountActivities(accountActivitiesT
return state
})
}

export function removeAllActivitiesForNetworkId(networkId: NetworkId): void {
allAccountActivities.update((state) => {
const updatedState = {}
for (const accountIndex in state) {
updatedState[accountIndex] = state[accountIndex].filter(
(activity) => activity.sourceNetworkId !== networkId
)
}
return updatedState
})
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { removeEvmNetworkFromActiveProfile } from '@core/profile/stores'
import { IEvmNetwork } from '..'
import { removeEvmNetworkFromNetworks } from '../stores'
import { removeAllActivitiesForNetworkId } from '@core/activity'
import { removeAllNftsForNetworkId } from '@core/nfts/stores'

export function removeExistingEvmNetwork(evmNetwork: IEvmNetwork): void {
evmNetwork.destroy()
removeEvmNetworkFromNetworks(evmNetwork.id)
removeEvmNetworkFromActiveProfile(evmNetwork.id)

removeAllActivitiesForNetworkId(evmNetwork.id)
removeAllNftsForNetworkId(evmNetwork.id)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Writable, get, writable } from 'svelte/store'
import { activeProfile, removeEvmNetworkFromActiveProfile } from '@core/profile/stores'
import { activeProfile } from '@core/profile/stores'
import { IscChain, EvmNetwork, StardustNetwork } from '../classes'
import { IEvmNetwork, IIscChain, IStardustNetwork } from '../interfaces'
import { EvmNetworkId, Network, NetworkId } from '../types'
Expand Down Expand Up @@ -56,7 +56,6 @@ export function removeEvmNetworkFromNetworks(networkId: EvmNetworkId): void {
networks.update((networks) => {
return networks.filter(({ id }) => id !== networkId)
})
removeEvmNetworkFromActiveProfile(networkId)
}

export function getStardustNetwork(): IStardustNetwork {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { get, writable } from 'svelte/store'
import { Nft } from '../interfaces'
import { PartialWithId } from '@core/utils'
import { updatePersistedCollections } from '../actions'
import { NetworkId } from '@core/network'

export const activeProfileNftsPerAccount = writable<{ [accountIndex: number]: Nft[] }>({})

Expand Down Expand Up @@ -79,3 +80,13 @@ export function getNftByIdForAccount(accountIndex: number | undefined, nftId: st
return nft
}
}

export function removeAllNftsForNetworkId(networkId: NetworkId): void {
activeProfileNftsPerAccount.update((state) => {
const updatedState = {}
for (const accountIndex in state) {
updatedState[accountIndex] = state[accountIndex].filter((nft) => nft.networkId !== networkId)
}
return updatedState
})
}

0 comments on commit 5eddbe8

Please sign in to comment.