Skip to content

Commit 821de05

Browse files
Merge pull request #7796 from iotaledger/refactor/dashboard-component
refactor: Fix Dashboard component
2 parents a758ef1 + 630f862 commit 821de05

12 files changed

+43
-43
lines changed

packages/desktop/views/dashboard/Dashboard.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
$: if (features.analytics.dashboardRoute.enabled && $dashboardRoute)
5656
Platform.trackEvent('dashboard-route', { route: $dashboardRoute })
5757
58-
function addselectedWalletNftsToDownloadQueue(accountIndex: number): void {
58+
function addselectedWalletNftsToDownloadQueue(walletId: string): void {
5959
resetNftDownloadQueue()
60-
void addNftsToDownloadQueue(accountIndex, $selectedWalletNfts)
60+
void addNftsToDownloadQueue(walletId, $selectedWalletNfts)
6161
}
6262
6363
function handleDeepLinkRequest(data: string): void {
@@ -103,7 +103,7 @@
103103
developerProfileNotificationId = showAppNotification({
104104
type: 'warning',
105105
message: localize('indicators.developerProfileIndicator.warningText', {
106-
values: { networkName: $nodeInfo.protocol.networkName },
106+
values: { networkName: $nodeInfo.protocolParameters[0].parameters.networkName },
107107
}),
108108
})
109109
}

packages/shared/lib/core/app/actions/registerNftDownloadEvents.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { downloadingNftId, removeNftFromDownloadQueue, updateNftInAllAccountNfts } from '@core/nfts'
1+
import { downloadingNftId, removeNftFromDownloadQueue, updateNftInAllWalletNfts } from '@core/nfts'
22
import { Platform } from '../classes'
33

44
/**
55
* Registers all event handlers for nft downloads.
66
*/
77
export function registerNftDownloadEvents(): void {
88
Platform.onEvent('nft-download-done', ({ nftId, accountIndex }) => {
9-
updateNftInAllAccountNfts(accountIndex, nftId, { downloadMetadata: { isLoaded: true } })
9+
updateNftInAllWalletNfts(accountIndex, nftId, { downloadMetadata: { isLoaded: true } })
1010
downloadingNftId.set(undefined)
1111
removeNftFromDownloadQueue(nftId)
1212
})

packages/shared/lib/core/nfts/actions/addNftsToDownloadQueue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { updateNftInAllAccountNfts } from '.'
1+
import { updateNftInAllWalletNfts } from '.'
22
import { INft } from '../interfaces'
33
import { addNftToDownloadQueue } from '../stores'
44
import { checkIfNftShouldBeDownloaded } from '../utils/checkIfNftShouldBeDownloaded'
@@ -21,7 +21,7 @@ async function validateNftThenAddToQueue(walletId: string, nft: INft): Promise<v
2121
const { shouldDownload, downloadMetadata, downloadUrl } = await checkIfNftShouldBeDownloaded(nft)
2222
nft.downloadMetadata = downloadMetadata
2323
nft.downloadUrl = downloadUrl
24-
updateNftInAllAccountNfts(walletId, nft.id, { downloadMetadata })
24+
updateNftInAllWalletNfts(walletId, nft.id, { downloadMetadata })
2525

2626
if (shouldDownload) {
2727
addNftToDownloadQueue({ nft: nft, downloadUrl, path: nft.filePath, walletId })

packages/shared/lib/core/nfts/actions/interruptNftDownloadAfterTimeout.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { MILLISECONDS_PER_SECOND, sleep } from '@core/utils'
33
import { get } from 'svelte/store'
44
import { DownloadWarningType } from '../enums'
55
import { downloadingNftId } from '../stores'
6-
import { updateNftInAllAccountNfts } from './updateNftInAllAccountNfts'
6+
import { updateNftInAllWalletNfts } from './updateNftInAllAccountNfts'
77
import { activeProfile } from '@core/profile/stores'
88

9-
export async function interruptNftDownloadAfterTimeout(accountIndex: number): Promise<void> {
9+
export async function interruptNftDownloadAfterTimeout(walletId: string): Promise<void> {
1010
const currentlyDownloadingNft = get(downloadingNftId)
1111

1212
const downloadTimeout = get(activeProfile).settings.maxMediaDownloadTimeInSeconds * MILLISECONDS_PER_SECOND
@@ -15,7 +15,7 @@ export async function interruptNftDownloadAfterTimeout(accountIndex: number): Pr
1515

1616
if (currentlyDownloadingNft && currentlyDownloadingNft === updatedDownloadingNft) {
1717
await Platform.cancelNftDownload(currentlyDownloadingNft)
18-
updateNftInAllAccountNfts(accountIndex, currentlyDownloadingNft, {
18+
updateNftInAllWalletNfts(walletId, currentlyDownloadingNft, {
1919
downloadMetadata: { isLoaded: false, warning: { type: DownloadWarningType.DownloadTooLong } },
2020
})
2121
}

packages/shared/lib/core/nfts/actions/updateNftInAllAccountNfts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { allWalletNfts } from '../stores'
22
import { INft } from '../interfaces'
33

44
// TODO(2.0) Fix usages
5-
export function updateNftInAllAccountNfts(walletId: string, nftId: string, partialNft: Partial<INft>): void {
5+
export function updateNftInAllWalletNfts(walletId: string, nftId: string, partialNft: Partial<INft>): void {
66
allWalletNfts.update((state) => {
77
if (!state[walletId]) {
88
state[walletId] = []

packages/shared/lib/core/wallet/actions/activities/hideActivitiesForFoundries.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { IWalletState } from '@core/wallet/interfaces'
22
import { updateActivityFromPartialActivity } from '@core/wallet/utils/generateActivity/helper'
33
import { get } from 'svelte/store'
44
import { ActivityType } from '../../enums'
5-
import { allAccountActivities } from '../../stores'
5+
import { allWalletActivities } from '../../stores'
66

7-
export function hideActivitiesForFoundries(account: IWalletState): void {
8-
const accountActivities = get(allAccountActivities)[account.index]
7+
export function hideActivitiesForFoundries(wallet: IWalletState): void {
8+
const walletActivities = get(allWalletActivities)[wallet.id]
99

10-
const activities = accountActivities.filter((activity) => activity.type === ActivityType.Foundry)
10+
const activities = walletActivities.filter((activity) => activity.type === ActivityType.Foundry)
1111

1212
for (const activity of activities) {
13-
for (const candidate of accountActivities.filter(
13+
for (const candidate of walletActivities.filter(
1414
(_activity) => _activity?.transactionId === activity?.transactionId && _activity.id !== activity.id
1515
)) {
1616
updateActivityFromPartialActivity(candidate, { isHidden: true })

packages/shared/lib/core/wallet/actions/activities/setAsyncStatusOfAccountActivities.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { syncBalance } from 'shared/lib/core/wallet/actions/syncBalance'
2-
import { updateNftInAllAccountNfts } from '@core/nfts'
2+
import { updateNftInAllWalletNfts } from '@core/nfts'
33
import { ActivityAsyncStatus, ActivityDirection, ActivityType } from '@core/wallet/enums'
4-
import { allAccountActivities } from '../../stores'
4+
import { allWalletActivities } from '../../stores'
55
import { refreshWalletAssetsForActiveProfile } from '../refreshWalletAssetsForActiveProfile'
66
import { getAsyncStatus } from '@core/wallet/utils/generateActivity/helper'
77

88
export function setAsyncStatusOfAccountActivities(time: Date): void {
9-
const balancesToUpdate: number[] = []
10-
allAccountActivities.update((state) => {
11-
state.forEach((accountActivities, accountIndex) => {
12-
for (const activity of accountActivities.filter((_activity) => _activity.asyncData)) {
9+
const balancesToUpdate: string[] = []
10+
allWalletActivities.update((state) => {
11+
Object.entries(state).forEach(([walletId, walletActivies]) => {
12+
for (const activity of walletActivies.filter((_activity) => _activity.asyncData)) {
1313
const oldAsyncStatus = activity.asyncData.asyncStatus
1414
if (oldAsyncStatus === ActivityAsyncStatus.Claimed || oldAsyncStatus === ActivityAsyncStatus.Expired) {
1515
continue
@@ -22,24 +22,24 @@ export function setAsyncStatusOfAccountActivities(time: Date): void {
2222
time.getTime()
2323
)
2424
if (oldAsyncStatus !== null && oldAsyncStatus !== activity.asyncData.asyncStatus) {
25-
if (!balancesToUpdate.includes(accountIndex)) {
26-
balancesToUpdate.push(accountIndex)
25+
if (!balancesToUpdate.includes(walletId)) {
26+
balancesToUpdate.push(walletId)
2727
}
2828

2929
if (
3030
activity.type === ActivityType.Nft &&
3131
activity.asyncData.asyncStatus === ActivityAsyncStatus.Expired &&
3232
activity.direction === ActivityDirection.Outgoing
3333
) {
34-
updateNftInAllAccountNfts(accountIndex, activity.nftId, { isSpendable: true })
34+
updateNftInAllWalletNfts(walletId, activity.nftId, { isSpendable: true })
3535
}
3636
}
3737
}
3838
})
3939
return state
4040
})
41-
for (const accountIndex of balancesToUpdate) {
42-
syncBalance(accountIndex)
41+
for (const walletId of balancesToUpdate) {
42+
syncBalance(walletId)
4343
}
4444
if (balancesToUpdate.length) {
4545
void refreshWalletAssetsForActiveProfile()

packages/shared/lib/core/wallet/actions/burnNft.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { plainToInstance } from 'class-transformer'
44
import { showAppNotification } from '@auxiliary/notification'
55
import { getSelectedWallet, updateSelectedWallet } from '@core/wallet/stores/selected-wallet.store'
66
import { localize } from '@core/i18n'
7-
import { updateNftInAllAccountNfts } from '@core/nfts'
7+
import { updateNftInAllWalletNfts } from '@core/nfts'
88
import { handleError } from '@core/error/handlers'
99
import { processAndAddToActivities } from '../utils'
1010

@@ -21,7 +21,7 @@ export async function burnNft(nftId: string): Promise<void> {
2121
await processAndAddToActivities(burnNftTransaction, wallet)
2222

2323
// Update NFT
24-
updateNftInAllAccountNfts(wallet.id, nftId, { isSpendable: false })
24+
updateNftInAllWalletNfts(wallet.id, nftId, { isSpendable: false })
2525

2626
showAppNotification({
2727
type: 'success',

packages/shared/lib/core/wallet/actions/events-handlers/handleSpentOutputEvent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { Event, SpentOutputWalletEvent, WalletEventType } from '@iota/sdk/out/types'
44

5-
import { getNftByIdFromAllAccountNfts, updateNftInAllAccountNfts } from '@core/nfts'
5+
import { getNftByIdFromAllAccountNfts, updateNftInAllWalletNfts } from '@core/nfts'
66
import { syncBalance, ActivityAsyncStatus, ActivityType, validateWalletApiEvent, updateAsyncDataByTransactionId, allWalletActivities} from '@core/wallet'
77
import { get } from 'svelte/store'
88
import { activeWallets, updateActiveWallet } from '@core/profile'
@@ -42,7 +42,7 @@ export async function handleSpentOutputEventInternal(
4242
const previousOutputId = getNftByIdFromAllAccountNfts(walletId, activity.nftId)?.latestOutputId
4343
const previousOutput = await wallet.getOutput(previousOutputId)
4444
if (output.metadata.milestoneTimestampBooked > previousOutput.metadata.milestoneTimestampBooked) {
45-
updateNftInAllAccountNfts(walletId, activity.nftId, { isSpendable: false })
45+
updateNftInAllWalletNfts(walletId, activity.nftId, { isSpendable: false })
4646
}
4747
}
4848
}

packages/shared/lib/core/wallet/actions/events-handlers/handleTransactionInclusionEvent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Event, TransactionInclusionWalletEvent, WalletEventType } from '@iota/s
33

44
import { updateParticipationOverview } from '@contexts/governance/stores'
55
import { isWalletVoting } from 'shared/lib/contexts/governance/utils/isWalletVoting'
6-
import { updateNftInAllAccountNfts } from '@core/nfts'
6+
import { updateNftInAllWalletNfts } from '@core/nfts'
77
import { updateActiveWalletPersistedData } from '@core/profile/actions'
88
import { syncVotingPower, getActivityByTransactionId,
99
updateActivityByTransactionId, validateWalletApiEvent, updateClaimingTransactionInclusion, ActivityAction, ActivityDirection, ActivityType, GovernanceActivity, InclusionState } from '@core/wallet'
@@ -32,7 +32,7 @@ export function handleTransactionInclusionEventInternal(
3232
(activity.direction === ActivityDirection.Incoming ||
3333
activity.direction === ActivityDirection.SelfTransaction) &&
3434
activity.action !== ActivityAction.Burn
35-
updateNftInAllAccountNfts(walletId, activity.nftId, { isSpendable })
35+
updateNftInAllWalletNfts(walletId, activity.nftId, { isSpendable })
3636
}
3737

3838
if (activity?.type === ActivityType.Governance) {

packages/shared/lib/core/wallet/actions/sendOutput.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { updateNftInAllAccountNfts } from '@core/nfts/actions'
1+
import { updateNftInAllWalletNfts } from '@core/nfts/actions'
22
import { getSelectedWallet, resetNewTokenTransactionDetails, updateSelectedWallet } from '../stores'
33
import { getDefaultTransactionOptions, processAndAddToActivities } from '../utils'
44
import { NftOutput, Output, OutputType } from '@iota/sdk/out/types'
@@ -12,7 +12,7 @@ export async function sendOutput(output: Output): Promise<void> {
1212
// Reset transaction details state, since the transaction has been sent
1313
if (output.type === OutputType.Nft) {
1414
const nftId = (output as NftOutput).nftId
15-
updateNftInAllAccountNfts(wallet.id, nftId, { isSpendable: false })
15+
updateNftInAllWalletNfts(wallet.id, nftId, { isSpendable: false })
1616
}
1717

1818
resetNewTokenTransactionDetails()

packages/shared/lib/core/wallet/actions/setOutgoingAsyncActivitiesToClaimed.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ import { BasicOutput, OutputData } from '@iota/sdk/out/types'
33
import { MILLISECONDS_PER_SECOND } from '@core/utils'
44
import { get } from 'svelte/store'
55
import { ActivityAsyncStatus, ActivityDirection } from '../enums'
6-
import { allAccountActivities, updateAsyncDataByActivityId } from '../stores'
6+
import { allWalletActivities, updateAsyncDataByActivityId } from '../stores'
77
import { getExpirationDateFromOutput } from '../utils'
88

9-
export async function setOutgoingAsyncActivitiesToClaimed(account: IWalletState): Promise<void> {
10-
const accountActivities = get(allAccountActivities)[account.index]
9+
export async function setOutgoingAsyncActivitiesToClaimed(wallet: IWalletState): Promise<void> {
10+
const walletActivities = get(allWalletActivities)[wallet.id]
1111

12-
const activities = accountActivities.filter(
12+
const activities = walletActivities.filter(
1313
(activity) => activity.direction === ActivityDirection.Outgoing && activity.asyncData
1414
)
1515

1616
for (const activity of activities) {
1717
try {
18-
const detailedOutput = await account.getOutput(activity.outputId)
18+
const detailedOutput = await wallet.getOutput(activity.outputId)
1919
const isClaimed = detailedOutput && isOutputClaimed(detailedOutput)
2020
if (isClaimed) {
21-
updateAsyncDataByActivityId(account.index, activity.id, {
21+
updateAsyncDataByActivityId(wallet.id, activity.id, {
2222
asyncStatus: ActivityAsyncStatus.Claimed,
23-
claimedDate: new Date(detailedOutput.metadata.milestoneTimestampSpent * MILLISECONDS_PER_SECOND),
23+
claimedDate: new Date() // TODO(2.0) Fix and use: new Date(detailedOutput.metadata.milestoneTimestampSpent * MILLISECONDS_PER_SECOND),
2424
})
2525
}
2626
} catch (err) {
@@ -35,7 +35,7 @@ function isOutputClaimed(output: OutputData): boolean {
3535
if (expirationDate) {
3636
return (
3737
output.isSpent &&
38-
output.metadata.milestoneTimestampSpent * MILLISECONDS_PER_SECOND < expirationDate.getTime()
38+
new Date().getTime() /* TODO(2.0) Fix and use: output.metadata.milestoneTimestampSpent * MILLISECONDS_PER_SECOND */ < expirationDate.getTime()
3939
)
4040
} else {
4141
return output?.isSpent

0 commit comments

Comments
 (0)