From 4db889db34e24f1e23116c52acc31b17f67edebf Mon Sep 17 00:00:00 2001 From: JCNoguera <88061365+VmMad@users.noreply.github.com> Date: Tue, 12 Sep 2023 19:29:17 +0200 Subject: [PATCH] fix: avoid crash on empty NFT details (#7398) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: avoid crash when clicking empty NFT * clean up * fixes --------- Co-authored-by: marc2332 Co-authored-by: Begoña Álvarez de la Cruz --- .../collectibles/views/CollectiblesDetailsView.svelte | 4 ++-- .../components/activity-info/NftActivityInformation.svelte | 6 +++--- .../actions/events-handlers/handleNewOutputEvent.ts | 2 +- .../core/wallet/utils/getBech32AddressFromAddressTypes.ts | 2 +- .../lib/core/wallet/utils/getHexAddressFromAddressTypes.ts | 2 +- .../lib/core/wallet/utils/outputs/getSenderFromOutput.ts | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/desktop/views/dashboard/collectibles/views/CollectiblesDetailsView.svelte b/packages/desktop/views/dashboard/collectibles/views/CollectiblesDetailsView.svelte index 2617a29d04f..05bb72e35b5 100644 --- a/packages/desktop/views/dashboard/collectibles/views/CollectiblesDetailsView.svelte +++ b/packages/desktop/views/dashboard/collectibles/views/CollectiblesDetailsView.svelte @@ -49,8 +49,8 @@ const { standard, version, type, uri, description, issuerName, collectionName, attributes, soonaverseAttributes } = nft?.parsedMetadata || {} - const issuerAddress = getBech32AddressFromAddressTypes(issuer) - const collectionId = getHexAddressFromAddressTypes(issuer) + const issuerAddress = issuer ? getBech32AddressFromAddressTypes(issuer) : undefined + const collectionId = issuer ? getHexAddressFromAddressTypes(issuer) : undefined let detailsList: { [key in string]: { diff --git a/packages/shared/components/activity-info/NftActivityInformation.svelte b/packages/shared/components/activity-info/NftActivityInformation.svelte index f88fc3d3d75..23d0f7c7bda 100644 --- a/packages/shared/components/activity-info/NftActivityInformation.svelte +++ b/packages/shared/components/activity-info/NftActivityInformation.svelte @@ -15,9 +15,9 @@ export let activity: NftActivity - $: nft = getNftByIdFromAllAccountNfts($selectedAccountIndex, activity?.nftId) - $: issuerAddress = getBech32AddressFromAddressTypes(nft?.issuer) - $: collectionId = getHexAddressFromAddressTypes(nft?.issuer) + $: nft = getNftByIdFromAllAccountNfts($selectedAccountIndex, activity.nftId) + $: issuerAddress = nft?.issuer && getBech32AddressFromAddressTypes(nft.issuer) + $: collectionId = nft?.issuer && getHexAddressFromAddressTypes(nft.issuer) let detailsList: IKeyValueBoxList $: detailsList = { diff --git a/packages/shared/lib/core/profile-manager/actions/events-handlers/handleNewOutputEvent.ts b/packages/shared/lib/core/profile-manager/actions/events-handlers/handleNewOutputEvent.ts index 7c88bd3c1d3..66dc52a1ba7 100644 --- a/packages/shared/lib/core/profile-manager/actions/events-handlers/handleNewOutputEvent.ts +++ b/packages/shared/lib/core/profile-manager/actions/events-handlers/handleNewOutputEvent.ts @@ -36,7 +36,7 @@ export async function handleNewOutputEventInternal(accountIndex: number, payload const output = outputData.output as AliasOutput - const address = getBech32AddressFromAddressTypes(outputData?.address) + const address = getBech32AddressFromAddressTypes(outputData.address) const isNewAliasOutput = output.type === OutputType.Alias && output.stateIndex === 0 && diff --git a/packages/shared/lib/core/wallet/utils/getBech32AddressFromAddressTypes.ts b/packages/shared/lib/core/wallet/utils/getBech32AddressFromAddressTypes.ts index be0ec2603bc..5675b966516 100644 --- a/packages/shared/lib/core/wallet/utils/getBech32AddressFromAddressTypes.ts +++ b/packages/shared/lib/core/wallet/utils/getBech32AddressFromAddressTypes.ts @@ -2,7 +2,7 @@ import { api } from '@core/profile-manager' import { Address, AddressType, AliasAddress, Ed25519Address, NftAddress } from '@iota/sdk/out/types' import { getNetworkHrp } from '@core/profile' -export function getBech32AddressFromAddressTypes(address: Address): string | undefined { +export function getBech32AddressFromAddressTypes(address: Address): string { const hrp = getNetworkHrp() switch (address.type) { case AddressType.Ed25519: diff --git a/packages/shared/lib/core/wallet/utils/getHexAddressFromAddressTypes.ts b/packages/shared/lib/core/wallet/utils/getHexAddressFromAddressTypes.ts index 996dc789418..3cf830f98ff 100644 --- a/packages/shared/lib/core/wallet/utils/getHexAddressFromAddressTypes.ts +++ b/packages/shared/lib/core/wallet/utils/getHexAddressFromAddressTypes.ts @@ -1,7 +1,7 @@ import { Address, AddressType, AliasAddress, Ed25519Address, NftAddress } from '@iota/sdk/out/types' export function getHexAddressFromAddressTypes(address: Address): string { - switch (address?.type) { + switch (address.type) { case AddressType.Ed25519: return (address as Ed25519Address).pubKeyHash case AddressType.Alias: diff --git a/packages/shared/lib/core/wallet/utils/outputs/getSenderFromOutput.ts b/packages/shared/lib/core/wallet/utils/outputs/getSenderFromOutput.ts index f19feb95303..9128b000ee4 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/getSenderFromOutput.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/getSenderFromOutput.ts @@ -17,7 +17,7 @@ export function getSenderFromOutput(output: CommonOutput): Subject | undefined { const storageOrExpirationUnlockCondition = unlockCondition as | StorageDepositReturnUnlockCondition | ExpirationUnlockCondition - const address = getBech32AddressFromAddressTypes(storageOrExpirationUnlockCondition?.returnAddress) + const address = getBech32AddressFromAddressTypes(storageOrExpirationUnlockCondition.returnAddress) if (address) { return getSubjectFromAddress(address) }