From 24f53083ffedee8442b774f32c7198b0df09049f Mon Sep 17 00:00:00 2001 From: Jean Ribeiro Date: Fri, 26 Apr 2024 06:14:25 -0300 Subject: [PATCH 1/4] feat: adds CollectionGalleryView (#2371) * feat: adds CollectionGalleryView * refactor: remove routing logic --------- Co-authored-by: Nicole O'Brien --- .../desktop/features/collectibles.features.ts | 3 + .../collectibles/Collectibles.svelte | 9 ++- .../components/CollectiblesTabs.svelte | 13 ++++ .../collectibles/components/index.ts | 3 +- .../views/CollectiblesGalleryView.svelte | 30 ++++---- .../views/CollectionsGalleryView.svelte | 73 +++++++++++++++++++ .../dashboard/collectibles/views/index.ts | 1 + .../constants/collectibles-tabs.constant.ts | 7 ++ .../src/lib/core/nfts/constants/index.ts | 1 + .../shared/src/lib/core/nfts/stores/index.ts | 1 + .../selected-collectibles-tabs.store.ts | 5 ++ .../collectibles-features.interface.ts | 1 + packages/shared/src/locales/en.json | 6 ++ 13 files changed, 133 insertions(+), 20 deletions(-) create mode 100644 packages/desktop/views/dashboard/collectibles/components/CollectiblesTabs.svelte create mode 100644 packages/desktop/views/dashboard/collectibles/views/CollectionsGalleryView.svelte create mode 100644 packages/shared/src/lib/core/nfts/constants/collectibles-tabs.constant.ts create mode 100644 packages/shared/src/lib/core/nfts/stores/selected-collectibles-tabs.store.ts diff --git a/packages/desktop/features/collectibles.features.ts b/packages/desktop/features/collectibles.features.ts index f5d985a9d2..c2e5d8aaf0 100644 --- a/packages/desktop/features/collectibles.features.ts +++ b/packages/desktop/features/collectibles.features.ts @@ -8,6 +8,9 @@ const collectiblesFeatures: ICollectiblesFeatures = { erc721: { enabled: true, }, + collections: { + enabled: false, + }, } export default collectiblesFeatures diff --git a/packages/desktop/views/dashboard/collectibles/Collectibles.svelte b/packages/desktop/views/dashboard/collectibles/Collectibles.svelte index 12cbbb3240..eef514e153 100644 --- a/packages/desktop/views/dashboard/collectibles/Collectibles.svelte +++ b/packages/desktop/views/dashboard/collectibles/Collectibles.svelte @@ -3,7 +3,8 @@ import features from '@features/features' import { selectedAccountIndex } from '@core/account/stores' import { collectiblesRoute, CollectiblesRoute, collectiblesRouter } from '@core/router' - import { CollectiblesDetailsView, CollectiblesGalleryView } from './views' + import { CollectiblesDetailsView, CollectiblesGalleryView, CollectionsGalleryView } from './views' + import { selectedCollectiblesTab } from '@core/nfts/stores' $: $selectedAccountIndex !== undefined && $collectiblesRouter.reset() @@ -14,7 +15,11 @@
{#if $collectiblesRoute === CollectiblesRoute.Gallery} - + {#if $selectedCollectiblesTab?.key === 'collectibles'} + + {:else if $selectedCollectiblesTab?.key === 'collections'} + + {/if} {/if} {#if $collectiblesRoute === CollectiblesRoute.Details} diff --git a/packages/desktop/views/dashboard/collectibles/components/CollectiblesTabs.svelte b/packages/desktop/views/dashboard/collectibles/components/CollectiblesTabs.svelte new file mode 100644 index 0000000000..fb63733aa7 --- /dev/null +++ b/packages/desktop/views/dashboard/collectibles/components/CollectiblesTabs.svelte @@ -0,0 +1,13 @@ + + +{#if COLLECTIBLES_TABS.length > 1} +
+ +
+{/if} diff --git a/packages/desktop/views/dashboard/collectibles/components/index.ts b/packages/desktop/views/dashboard/collectibles/components/index.ts index 1c5cda5013..cb1cd98401 100644 --- a/packages/desktop/views/dashboard/collectibles/components/index.ts +++ b/packages/desktop/views/dashboard/collectibles/components/index.ts @@ -1,2 +1,3 @@ -export { default as Irc27CollectibleDetails } from './Irc27CollectibleDetails.svelte' +export { default as CollectiblesTabs } from './CollectiblesTabs.svelte' export { default as Erc721CollectibleDetails } from './Erc721CollectibleDetails.svelte' +export { default as Irc27CollectibleDetails } from './Irc27CollectibleDetails.svelte' diff --git a/packages/desktop/views/dashboard/collectibles/views/CollectiblesGalleryView.svelte b/packages/desktop/views/dashboard/collectibles/views/CollectiblesGalleryView.svelte index 6337ef2b74..1d4df5ec32 100644 --- a/packages/desktop/views/dashboard/collectibles/views/CollectiblesGalleryView.svelte +++ b/packages/desktop/views/dashboard/collectibles/views/CollectiblesGalleryView.svelte @@ -1,14 +1,15 @@ - -
-
+ +
+
{localize('views.collectibles.gallery.title')} {String(queriedNfts.length ?? '')}
-
+ +
{#if $ownedNfts.length} @@ -41,7 +43,7 @@ {/if}
-
+
{#if $ownedNfts.length} {#if queriedNfts.length} @@ -61,9 +63,3 @@
{/if} - - diff --git a/packages/desktop/views/dashboard/collectibles/views/CollectionsGalleryView.svelte b/packages/desktop/views/dashboard/collectibles/views/CollectionsGalleryView.svelte new file mode 100644 index 0000000000..e95024b661 --- /dev/null +++ b/packages/desktop/views/dashboard/collectibles/views/CollectionsGalleryView.svelte @@ -0,0 +1,73 @@ + + + +
+
+ {localize('views.collectibles.collectionsGallery.title')} + + {String(queriedCollections.length ?? '')} + +
+ +
+ {#if collections.length} + + + {/if} + {#if features.collectibles.erc721.enabled} + + {/if} +
+
+ {#if collections.length} + {#if queriedCollections.length} + + {:else} +
+ +
+ {/if} + {:else} +
+ +
+ {/if} +
diff --git a/packages/desktop/views/dashboard/collectibles/views/index.ts b/packages/desktop/views/dashboard/collectibles/views/index.ts index 26df406a4f..1cdf4af543 100644 --- a/packages/desktop/views/dashboard/collectibles/views/index.ts +++ b/packages/desktop/views/dashboard/collectibles/views/index.ts @@ -1,2 +1,3 @@ export { default as CollectiblesDetailsView } from './CollectiblesDetailsView.svelte' export { default as CollectiblesGalleryView } from './CollectiblesGalleryView.svelte' +export { default as CollectionsGalleryView } from './CollectionsGalleryView.svelte' diff --git a/packages/shared/src/lib/core/nfts/constants/collectibles-tabs.constant.ts b/packages/shared/src/lib/core/nfts/constants/collectibles-tabs.constant.ts new file mode 100644 index 0000000000..ca61211895 --- /dev/null +++ b/packages/shared/src/lib/core/nfts/constants/collectibles-tabs.constant.ts @@ -0,0 +1,7 @@ +import { KeyValue } from '@ui' +import features from '@features/features' + +export const COLLECTIBLES_TABS: KeyValue[] = [ + { key: 'collectibles', value: 'Collectibles' }, + ...(features.collectibles?.collections.enabled ? [{ key: 'collections', value: 'Collections' }] : []), +] diff --git a/packages/shared/src/lib/core/nfts/constants/index.ts b/packages/shared/src/lib/core/nfts/constants/index.ts index 0e1c3f468d..9461c813cf 100644 --- a/packages/shared/src/lib/core/nfts/constants/index.ts +++ b/packages/shared/src/lib/core/nfts/constants/index.ts @@ -1,3 +1,4 @@ +export * from './collectibles-tabs.constant' export * from './current-irc27-version.constant' export * from './default-nft-filter.constant' export * from './default-nft-name.constant' diff --git a/packages/shared/src/lib/core/nfts/stores/index.ts b/packages/shared/src/lib/core/nfts/stores/index.ts index 4561c3dfe4..34585e3cc5 100644 --- a/packages/shared/src/lib/core/nfts/stores/index.ts +++ b/packages/shared/src/lib/core/nfts/stores/index.ts @@ -4,4 +4,5 @@ export * from './nft-download-queue.store' export * from './nft-filter.store' export * from './persisted-nfts.store' export * from './selected-account-nfts.store' +export * from './selected-collectibles-tabs.store' export * from './selected-nft.store' diff --git a/packages/shared/src/lib/core/nfts/stores/selected-collectibles-tabs.store.ts b/packages/shared/src/lib/core/nfts/stores/selected-collectibles-tabs.store.ts new file mode 100644 index 0000000000..747434e270 --- /dev/null +++ b/packages/shared/src/lib/core/nfts/stores/selected-collectibles-tabs.store.ts @@ -0,0 +1,5 @@ +import { KeyValue } from '@ui' +import { Writable, writable } from 'svelte/store' +import { COLLECTIBLES_TABS } from '../constants' + +export const selectedCollectiblesTab: Writable> = writable(COLLECTIBLES_TABS[0]) diff --git a/packages/shared/src/lib/features/interfaces/collectibles-features.interface.ts b/packages/shared/src/lib/features/interfaces/collectibles-features.interface.ts index 52e2f15e8b..b6f19e5cd1 100644 --- a/packages/shared/src/lib/features/interfaces/collectibles-features.interface.ts +++ b/packages/shared/src/lib/features/interfaces/collectibles-features.interface.ts @@ -3,4 +3,5 @@ import { IFeatureFlag } from './feature-flag.interface' export interface ICollectiblesFeatures extends IFeatureFlag { useCaching: IFeatureFlag erc721: IFeatureFlag + collections: IFeatureFlag } diff --git a/packages/shared/src/locales/en.json b/packages/shared/src/locales/en.json index e65f3e091e..f4f8fb6bce 100644 --- a/packages/shared/src/locales/en.json +++ b/packages/shared/src/locales/en.json @@ -669,6 +669,12 @@ "unhide": "Unhide NFT", "burn": "Burn NFT" } + }, + "collectionsGallery": { + "title": "Collections", + "emptyTitle": "No collections found", + "noResults": "No results found", + "emptyDescription": "Deposit or receive your first collectible!" } }, "campaigns": { From 560cd08e5595ed666af787cdeacbba2bbe64d8f7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 26 Apr 2024 11:54:18 +0100 Subject: [PATCH 2/4] Generated diff for 2024-04-26 (#2378) Co-authored-by: GitHub Actions Co-authored-by: Nicole O'Brien --- firefly.diff | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/firefly.diff b/firefly.diff index 466eadaf59..8ce473caef 100644 --- a/firefly.diff +++ b/firefly.diff @@ -73,6 +73,7 @@ delete mode 100644 packages/desktop/components/buttons/popup-buttons/ImportErc20TokenButton.svelte delete mode 100644 packages/desktop/components/buttons/popup-buttons/RefreshTokenMetadataButton.svelte delete mode 100644 packages/desktop/components/drawers/network-config/NetworkConfigDrawerRouter.svelte + delete mode 100644 packages/desktop/components/drawers/network-config/drawers/AddChainDrawer.svelte delete mode 100644 packages/desktop/components/drawers/network-config/drawers/ChainDepositAddressDrawer.svelte delete mode 100644 packages/desktop/components/drawers/network-config/drawers/ChainInformationDrawer.svelte delete mode 100644 packages/desktop/components/drawers/network-config/drawers/ConfirmLedgerEvmAddressDrawer.svelte @@ -84,6 +85,7 @@ delete mode 100644 packages/desktop/components/drawers/network-config/drawers/components/AddIscpChainForm.svelte delete mode 100644 packages/desktop/components/drawers/network-config/drawers/components/EvmChainInformation.svelte delete mode 100644 packages/desktop/components/drawers/network-config/drawers/components/IscpChainInformation.svelte + delete mode 100644 packages/desktop/components/drawers/network-config/drawers/components/index.ts delete mode 100644 packages/desktop/components/drawers/network-config/drawers/index.ts rename packages/desktop/components/filter/{index.js => index.ts} (100%) delete mode 100644 packages/desktop/components/index.js @@ -95,7 +97,7 @@ delete mode 100644 packages/desktop/components/panes/ProposalInformationPane.svelte delete mode 100644 packages/desktop/components/panes/index.js rename packages/desktop/components/{ => popup}/popups/MintNativeTokenFormPopup.svelte (69%) - rename packages/desktop/components/{ => popup}/popups/MintNftFormPopup.svelte (80%) + rename packages/desktop/components/{ => popup}/popups/MintNftFormPopup.svelte (77%) delete mode 100644 packages/desktop/components/popups/AccountSwitcherPopup.svelte delete mode 100644 packages/desktop/components/popups/ActivityDetailsPopup.svelte delete mode 100644 packages/desktop/components/popups/AddNodePopup.svelte @@ -194,8 +196,6 @@ rename packages/desktop/views/dashboard/developer/{index.js => index.ts} (100%) rename packages/desktop/views/dashboard/{settings/views/network/index.js => drawers/network-config/components/index.ts} (54%) rename packages/desktop/{lib/routers/enums => views/dashboard/drawers/network-config}/network-config-route.enum.ts (86%) - rename packages/desktop/{components/drawers/network-config/drawers/AddChainDrawer.svelte => views/dashboard/drawers/network-config/views/AddNetworkDrawer.svelte} (55%) - rename packages/desktop/{components/drawers/network-config/drawers => views/dashboard/drawers/network-config/views}/components/index.ts (100%) rename packages/desktop/{components/menu-buttons/ProposalDetailsButton.svelte => views/dashboard/governance/components/ProposalDetailsMenu.svelte} (55%) rename packages/desktop/{components/Proposals.svelte => views/dashboard/governance/components/ProposalList.svelte} (52%) rename packages/desktop/{ => views/dashboard/governance}/components/ProposalQuestion.svelte (64%) @@ -980,6 +980,7 @@ delete mode 100644 packages/shared/lib/core/layer-2/utils/getErc20TokenMetadata.ts delete mode 100644 packages/shared/lib/core/layer-2/utils/getLayer2AssetAllowance.ts delete mode 100644 packages/shared/lib/core/layer-2/utils/getLayer2MetadataForTransfer.ts + delete mode 100644 packages/shared/lib/core/layer-2/utils/getLayer2NetworkFromAddress.ts delete mode 100644 packages/shared/lib/core/layer-2/utils/index.ts delete mode 100644 packages/shared/lib/core/layer-2/utils/parseLayer2MetadataForTransfer.ts delete mode 100644 packages/shared/lib/core/layer-2/utils/prepareErc20EvmTransactionData.ts @@ -1022,6 +1023,7 @@ delete mode 100644 packages/shared/lib/core/network/actions/showNetworkIssueNotification.ts delete mode 100644 packages/shared/lib/core/network/actions/toggleDisabledNodeInClientOptions.ts delete mode 100644 packages/shared/lib/core/network/actions/updateChainStatuses.ts + delete mode 100644 packages/shared/lib/core/network/classes/index.ts delete mode 100644 packages/shared/lib/core/network/classes/iscp-chain.class.ts delete mode 100644 packages/shared/lib/core/network/classes/stardust-network.class.ts delete mode 100644 packages/shared/lib/core/network/constants/coin-type.constant.ts @@ -1042,6 +1044,7 @@ delete mode 100644 packages/shared/lib/core/network/interfaces/chain-configuration.interface.ts delete mode 100644 packages/shared/lib/core/network/interfaces/chain-status.interface.ts delete mode 100644 packages/shared/lib/core/network/interfaces/chain.interface.ts + delete mode 100644 packages/shared/lib/core/network/interfaces/index.ts delete mode 100644 packages/shared/lib/core/network/interfaces/network-metadata.interface.ts delete mode 100644 packages/shared/lib/core/network/interfaces/network-status.interface.ts delete mode 100644 packages/shared/lib/core/network/interfaces/network.interface.ts @@ -1049,6 +1052,7 @@ delete mode 100644 packages/shared/lib/core/network/interfaces/node.interface.ts delete mode 100644 packages/shared/lib/core/network/interfaces/persisted-network.interface.ts delete mode 100644 packages/shared/lib/core/network/interfaces/rent-structure.interface.ts + delete mode 100644 packages/shared/lib/core/network/interfaces/stardust-network-metadata.interface.ts delete mode 100644 packages/shared/lib/core/network/interfaces/tracked-tokens.interface.ts delete mode 100644 packages/shared/lib/core/network/stores/chain-statuses.store.ts delete mode 100644 packages/shared/lib/core/network/stores/network.store.ts @@ -1056,6 +1060,7 @@ delete mode 100644 packages/shared/lib/core/network/tests/network.test.ts delete mode 100644 packages/shared/lib/core/network/types/chain-configuration.type.ts delete mode 100644 packages/shared/lib/core/network/types/chain-metadata.type.ts + delete mode 100644 packages/shared/lib/core/network/types/index.ts delete mode 100644 packages/shared/lib/core/network/utils/buildChainFromNetwork.ts delete mode 100644 packages/shared/lib/core/network/utils/buildPersistedNetworkFromNodeInfoResponse.ts delete mode 100644 packages/shared/lib/core/network/utils/checkNetworkId.ts @@ -1094,8 +1099,10 @@ delete mode 100644 packages/shared/lib/core/nfts/types/mime-type.type.ts delete mode 100644 packages/shared/lib/core/nfts/utils/buildNftFromNftOutput.ts delete mode 100644 packages/shared/lib/core/nfts/utils/checkIfNftShouldBeDownloaded.ts + delete mode 100644 packages/shared/lib/core/nfts/utils/composeUrlFromNftUri.ts delete mode 100644 packages/shared/lib/core/nfts/utils/convertAndFormatNftMetadata.ts delete mode 100644 packages/shared/lib/core/nfts/utils/fetchWithTimeout.ts + delete mode 100644 packages/shared/lib/core/nfts/utils/getSpendableStatusFromUnspentNftOutput.ts delete mode 100644 packages/shared/lib/core/nfts/utils/index.ts delete mode 100644 packages/shared/lib/core/nfts/utils/rewriteIpfsUri.ts delete mode 100644 packages/shared/lib/core/profile-manager/actions/events-handlers/handleNewOutputEvent.ts @@ -1157,6 +1164,7 @@ delete mode 100644 packages/shared/lib/core/utils/crypto/utils/validateAssetId.ts delete mode 100644 packages/shared/lib/core/utils/crypto/utils/validateEthereumAddress.ts delete mode 100644 packages/shared/lib/core/utils/encode.ts + delete mode 100644 packages/shared/lib/core/utils/format.ts delete mode 100644 packages/shared/lib/core/utils/function.ts delete mode 100644 packages/shared/lib/core/utils/interfaces/format-iota-unit-options.interface.ts delete mode 100644 packages/shared/lib/core/utils/interfaces/index.ts @@ -1621,7 +1629,7 @@ rename packages/shared/{ => src}/lib/contexts/onboarding/errors/unable-to-copy-stronghold-backup-file.error.ts (100%) rename packages/shared/{ => src}/lib/contexts/onboarding/errors/unable-to-restore-backup-for-profile-manager.error.ts (100%) rename packages/shared/{ => src}/lib/contexts/onboarding/helpers/buildInitialOnboardingProfile.ts (67%) - rename packages/shared/{ => src}/lib/contexts/onboarding/helpers/convertOnboardingProfileToPersistedProfile.ts (79%) + rename packages/shared/{ => src}/lib/contexts/onboarding/helpers/convertOnboardingProfileToPersistedProfile.ts (53%) rename packages/shared/{ => src}/lib/contexts/onboarding/helpers/copyStrongholdFileToProfileDirectory.ts (92%) rename packages/shared/{ => src}/lib/contexts/onboarding/helpers/deriveShimmerClaimingAccountState.ts (92%) rename packages/shared/{ => src}/lib/contexts/onboarding/helpers/getSortedRenamedBoundAccounts.ts (92%) @@ -1722,14 +1730,14 @@ rename packages/shared/{lib/core/wallet => src/lib/core/activity}/utils/outputs/index.ts (94%) rename packages/shared/{lib/core/wallet => src/lib/core/activity}/utils/outputs/preprocessGroupedOutputs.ts (65%) rename packages/shared/{lib/core/wallet => src/lib/core/activity}/utils/outputs/preprocessTransaction.ts (54%) - rename packages/shared/{ => src}/lib/core/app/actions/index.ts (83%) + rename packages/shared/{ => src}/lib/core/app/actions/index.ts (66%) rename packages/shared/{ => src}/lib/core/app/actions/registerAppEvents.ts (100%) rename packages/shared/{ => src}/lib/core/app/actions/registerAppUpdateEvents.ts (51%) rename packages/shared/{ => src}/lib/core/app/actions/registerNftDownloadEvents.ts (59%) rename packages/shared/{ => src}/lib/core/app/classes/index.ts (100%) rename packages/shared/{ => src}/lib/core/app/constants/default-app-settings.constant.ts (62%) rename packages/shared/{ => src}/lib/core/app/constants/external-allowed-links.constant.ts (51%) - rename packages/shared/{ => src}/lib/core/app/constants/index.ts (71%) + rename packages/shared/{ => src}/lib/core/app/constants/index.ts (61%) rename packages/shared/{ => src}/lib/core/app/constants/privacy-policy-version.constant.ts (100%) rename packages/shared/{ => src}/lib/core/app/constants/terms-of-service-version.constant.ts (67%) rename packages/shared/{ => src}/lib/core/app/enums/app-context.enum.ts (100%) @@ -1741,7 +1749,7 @@ rename packages/shared/{ => src}/lib/core/app/interfaces/app-settings.interface.ts (100%) rename packages/shared/{ => src}/lib/core/app/interfaces/app-update-download-progress.interface.ts (100%) rename packages/shared/{ => src}/lib/core/app/interfaces/app-version-details.interface.ts (100%) - rename packages/shared/{ => src}/lib/core/app/interfaces/index.ts (76%) + rename packages/shared/{ => src}/lib/core/app/interfaces/index.ts (69%) rename packages/shared/{ => src}/lib/core/app/interfaces/managers/deep-link-manager.interface.ts (75%) rename packages/shared/{ => src}/lib/core/app/interfaces/managers/index.ts (75%) rename packages/shared/{ => src}/lib/core/app/interfaces/managers/notification-manager.interface.ts (100%) @@ -1817,7 +1825,6 @@ rename packages/shared/{ => src}/lib/core/layer-2/abis/erc20.abi.ts (100%) rename packages/shared/{ => src}/lib/core/layer-2/abis/index.ts (68%) rename packages/shared/{ => src}/lib/core/layer-2/abis/isc-sandbox.abi.ts (100%) - rename packages/shared/{lib/core/layer-2/utils => src/lib/core/layer-2/actions}/getLayer2NetworkFromAddress.ts (52%) rename packages/shared/{ => src}/lib/core/layer-2/classes/simple-buffer.class.ts (100%) rename packages/shared/{ => src}/lib/core/layer-2/constants/accounts-contract.constant.ts (100%) rename packages/shared/{ => src}/lib/core/layer-2/constants/contract-functions.constant.ts (100%) @@ -1891,7 +1898,6 @@ rename packages/shared/{ => src}/lib/core/network/actions/toggleLocalPowInClientOptions.ts (84%) rename packages/shared/{ => src}/lib/core/network/actions/togglePrimaryNodeInClientOptions.ts (63%) rename packages/shared/{ => src}/lib/core/network/actions/updateClientOptions.ts (98%) - rename packages/shared/{ => src}/lib/core/network/classes/index.ts (100%) rename packages/shared/{ => src}/lib/core/network/constants/empty-node.constant.ts (54%) rename packages/shared/{ => src}/lib/core/network/constants/milestone-not-found.constant.ts (100%) rename packages/shared/{ => src}/lib/core/network/constants/network-status-poll-interval.constant.ts (100%) @@ -1906,22 +1912,19 @@ rename packages/shared/{ => src}/lib/core/network/interfaces/client-options.interface.ts (54%) rename packages/shared/{ => src}/lib/core/network/interfaces/connected-chain.interface.ts (100%) rename packages/shared/{ => src}/lib/core/network/interfaces/evm-addresses.interface.ts (100%) - rename packages/shared/{lib/core/network/interfaces/chain-metadata.interface.ts => src/lib/core/network/interfaces/evm-network-metadata.interface.ts} (92%) rename packages/shared/{ => src}/lib/core/network/interfaces/gas-fee-policy.interface.ts (100%) rename packages/shared/{ => src}/lib/core/network/interfaces/gas-limits.interface.ts (100%) - rename packages/shared/{ => src}/lib/core/network/interfaces/index.ts (54%) + rename packages/shared/{lib/core/network/interfaces/chain-metadata.interface.ts => src/lib/core/network/interfaces/isc-chain-metadata.interface.ts} (76%) rename packages/shared/{ => src}/lib/core/network/interfaces/node-info-response.interface.ts (62%) rename packages/shared/{ => src}/lib/core/network/interfaces/protocol.interface.ts (62%) - rename packages/shared/{ => src}/lib/core/network/interfaces/stardust-network-metadata.interface.ts (51%) rename packages/shared/{ => src}/lib/core/network/stores/index.ts (58%) rename packages/shared/{ => src}/lib/core/network/stores/network-status.store.ts (100%) rename packages/shared/{ => src}/lib/core/network/stores/node-info.store.ts (83%) - rename packages/shared/{ => src}/lib/core/network/types/index.ts (50%) rename packages/shared/{ => src}/lib/core/network/types/network-metadata.type.ts (100%) rename packages/shared/{ => src}/lib/core/network/types/web3-provider.type.ts (100%) rename packages/shared/{ => src}/lib/core/network/utils/checkNodeUrlValidity.ts (95%) rename packages/shared/{ => src}/lib/core/network/utils/doesNodeHavePlugin.ts (100%) - rename packages/shared/{ => src}/lib/core/network/utils/getDefaultPersistedNetwork.ts (56%) + rename packages/shared/{lib/core/network/utils/getDefaultPersistedNetwork.ts => src/lib/core/network/utils/getDefaultStardustNetwork.ts} (50%) rename packages/shared/{ => src}/lib/core/network/utils/getEvmTransactionOptions.ts (88%) rename packages/shared/{ => src}/lib/core/nfts/actions/getNftByIdFromAllAccountNfts.ts (61%) rename packages/shared/{ => src}/lib/core/nfts/actions/setAccountNftsInAllAccountNfts.ts (75%) @@ -1929,11 +1932,11 @@ rename packages/shared/{ => src}/lib/core/nfts/constants/default-max-nft-downloading-time-in-seconds.constant.ts (100%) rename packages/shared/{ => src}/lib/core/nfts/constants/default-max-nft-size-in-megabytes.constant.ts (100%) rename packages/shared/{ => src}/lib/core/nfts/constants/default-nft-name.constant.ts (100%) - rename packages/shared/{ => src}/lib/core/nfts/constants/index.ts (70%) + rename packages/shared/{ => src}/lib/core/nfts/constants/index.ts (77%) rename packages/shared/{ => src}/lib/core/nfts/constants/nft-id-byte-length.constant.ts (100%) rename packages/shared/{ => src}/lib/core/nfts/constants/nft-media-file-name.constant.ts (100%) - rename packages/shared/{ => src}/lib/core/nfts/enums/download-error-type.enum.ts (100%) - rename packages/shared/{ => src}/lib/core/nfts/enums/download-warning-type.enum.ts (52%) + rename packages/shared/{ => src}/lib/core/nfts/enums/download-error-type.enum.ts (78%) + rename packages/shared/{ => src}/lib/core/nfts/enums/download-warning-type.enum.ts (65%) rename packages/shared/{ => src}/lib/core/nfts/enums/index.ts (53%) rename packages/shared/{ => src}/lib/core/nfts/enums/parent-mime-type.enum.ts (100%) rename packages/shared/{lib/core/nfts/interfaces/nft-download-metadata.interface.ts => src/lib/core/nfts/interfaces/download-metadata.interface.ts} (51%) @@ -1942,8 +1945,6 @@ rename packages/shared/{ => src}/lib/core/nfts/interfaces/soonaverse-attributes.interface.ts (100%) rename packages/shared/{ => src}/lib/core/nfts/stores/index.ts (73%) rename packages/shared/{ => src}/lib/core/nfts/tests/buildNftFromNftOutput.test.ts (55%) - rename packages/shared/{ => src}/lib/core/nfts/utils/composeUrlFromNftUri.ts (76%) - rename packages/shared/{ => src}/lib/core/nfts/utils/getSpendableStatusFromUnspentNftOutput.ts (64%) rename packages/shared/{ => src}/lib/core/nfts/utils/isNftOwnedByAnyAccount.ts (57%) rename packages/shared/{ => src}/lib/core/nfts/utils/parseNftMetadata.ts (91%) rename packages/shared/{ => src}/lib/core/profile-manager/actions/changePasswordAndUnlockStronghold.ts (96%) @@ -2011,15 +2012,15 @@ rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/migrateStrongholdFromActiveProfile.ts (100%) rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/reflectLockedStronghold.ts (92%) rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/resetActiveProfile.ts (59%) - rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/saveActiveProfile.ts (67%) + rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/saveActiveProfile.ts (65%) rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/unlockStronghold.ts (81%) rename packages/shared/{ => src}/lib/core/profile/actions/index.ts (100%) rename packages/shared/{ => src}/lib/core/profile/actions/profiles/index.ts (67%) rename packages/shared/{ => src}/lib/core/profile/constants/default-account-recovery-configuration.constant.ts (89%) rename packages/shared/{ => src}/lib/core/profile/constants/default_stronghold_password_timeout_in_minutes.constant.ts (100%) rename packages/shared/{ => src}/lib/core/profile/constants/dev-storage-directory.constant.ts (100%) - rename packages/shared/{ => src}/lib/core/profile/constants/index.ts (100%) - rename packages/shared/{ => src}/lib/core/profile/constants/initial-active-profile.constant.ts (79%) + rename packages/shared/{ => src}/lib/core/profile/constants/index.ts (85%) + rename packages/shared/{ => src}/lib/core/profile/constants/initial-active-profile.constant.ts (77%) rename packages/shared/{ => src}/lib/core/profile/constants/max-profile-name-length.constant.ts (100%) rename packages/shared/{ => src}/lib/core/profile/constants/max-stronghold-password-length.constant.ts (100%) rename packages/shared/{ => src}/lib/core/profile/constants/profile-storage-directory.constant.ts (100%) @@ -2166,7 +2167,6 @@ rename packages/shared/{ => src}/lib/core/utils/enums/past-time-unit.enum.ts (100%) rename packages/shared/{ => src}/lib/core/utils/enums/time-period.enum.ts (100%) rename packages/shared/{ => src}/lib/core/utils/filter.ts (63%) - rename packages/shared/{ => src}/lib/core/utils/format.ts (75%) rename packages/shared/{ => src}/lib/core/utils/index.ts (85%) rename packages/shared/{ => src}/lib/core/utils/interfaces/date-difference.interface.ts (100%) rename packages/shared/{ => src}/lib/core/utils/interfaces/dropdown-item.interface.ts (100%) @@ -2177,14 +2177,14 @@ rename packages/shared/{ => src}/lib/core/utils/iter.ts (100%) rename packages/shared/{ => src}/lib/core/utils/math.ts (100%) rename packages/shared/{ => src}/lib/core/utils/os.ts (83%) - rename packages/shared/{ => src}/lib/core/utils/random.ts (100%) + rename packages/shared/{ => src}/lib/core/utils/random.ts (64%) rename packages/shared/{ => src}/lib/core/utils/sort.ts (100%) rename packages/shared/{ => src}/lib/core/utils/store.ts (100%) rename packages/shared/{ => src}/lib/core/utils/stores/currencies.store.ts (100%) rename packages/shared/{ => src}/lib/core/utils/stores/exchange-rates.store.ts (100%) rename packages/shared/{ => src}/lib/core/utils/stores/index.ts (100%) rename packages/shared/{ => src}/lib/core/utils/string.ts (60%) - rename packages/shared/{ => src}/lib/core/utils/tests/convert.test.ts (59%) + rename packages/shared/{ => src}/lib/core/utils/tests/convert.test.ts (60%) rename packages/shared/{ => src}/lib/core/utils/tests/crypto.test.ts (100%) rename packages/shared/{ => src}/lib/core/utils/tests/date.test.ts (100%) rename packages/shared/{ => src}/lib/core/utils/tests/format.test.ts (100%) @@ -2233,7 +2233,7 @@ rename packages/shared/{ => src}/lib/features/interfaces/features.interface.ts (56%) rename packages/shared/{ => src}/lib/features/interfaces/governance-features.interface.ts (100%) rename packages/shared/{ => src}/lib/features/interfaces/index.ts (64%) - rename packages/shared/{ => src}/lib/features/interfaces/network-features.interface.ts (100%) + rename packages/shared/{ => src}/lib/features/interfaces/network-features.interface.ts (87%) rename packages/shared/{ => src}/lib/features/interfaces/onboarding-features-for-network.interface.ts (84%) rename packages/shared/{ => src}/lib/features/interfaces/settings-features.interface.ts (88%) rename packages/shared/{ => src}/lib/features/interfaces/wallet-features.interface.ts (78%) From 6cb23435b3b36b1eee935c4ecf7a64ba3beffc1d Mon Sep 17 00:00:00 2001 From: Tuditi <45079109+Tuditi@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:58:30 +0200 Subject: [PATCH 3/4] chore: nest IscChains in StardusNetwork (#2375) * chore: nest IscChains in StardusNetwork * chore: remove unusde code * feat: remove network updated * fix: type --------- Co-authored-by: Mark Nardi --- ...vertOnboardingProfileToPersistedProfile.ts | 4 +- .../network/classes/stardust-network.class.ts | 38 ++++++++++--------- .../interfaces/stardust-network.interface.ts | 7 ++-- .../lib/core/network/stores/networks.store.ts | 29 +++++++------- ...ildPersistedNetworkFromNodeInfoResponse.ts | 2 +- 5 files changed, 42 insertions(+), 38 deletions(-) diff --git a/packages/shared/src/lib/contexts/onboarding/helpers/convertOnboardingProfileToPersistedProfile.ts b/packages/shared/src/lib/contexts/onboarding/helpers/convertOnboardingProfileToPersistedProfile.ts index 4084e39c4a..1e734047bb 100644 --- a/packages/shared/src/lib/contexts/onboarding/helpers/convertOnboardingProfileToPersistedProfile.ts +++ b/packages/shared/src/lib/contexts/onboarding/helpers/convertOnboardingProfileToPersistedProfile.ts @@ -4,7 +4,7 @@ import { DEFAULT_PERSISTED_PROFILE_OBJECT } from '@core/profile/constants' import { IOnboardingProfile } from '../interfaces' import { DEFAULT_L1_EVM_NETWORK_CONFIGURATION, SupportedNetworkId } from '@core/network/constants' import features from '@features/features' -import { IPureEvmNetworkConfiguration, IStardustNetwork } from '@core/network/interfaces' +import { IPureEvmNetworkConfiguration } from '@core/network/interfaces' export function convertOnboardingProfileToPersistedProfile( onboardingProfile?: Partial @@ -26,7 +26,7 @@ export function convertOnboardingProfileToPersistedProfile( return { ...structuredClone(DEFAULT_PERSISTED_PROFILE_OBJECT), - ...{ network: onboardingProfile?.network as IStardustNetwork }, + ...{ network }, ...(evmNetworks && { evmNetworks }), ...(onboardingProfile?.name && { name: onboardingProfile.name }), ...(onboardingProfile?.id && { id: onboardingProfile.id }), diff --git a/packages/shared/src/lib/core/network/classes/stardust-network.class.ts b/packages/shared/src/lib/core/network/classes/stardust-network.class.ts index 8f7397e7fa..4d992c015c 100644 --- a/packages/shared/src/lib/core/network/classes/stardust-network.class.ts +++ b/packages/shared/src/lib/core/network/classes/stardust-network.class.ts @@ -1,6 +1,5 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ - import { get } from 'svelte/store' +import { IBaseToken } from '@core/token/interfaces' import { activeProfile, updateActiveProfile } from '@core/profile/stores' import { NetworkNamespace } from '../enums' import { @@ -10,10 +9,9 @@ import { IStardustNetwork, IStardustNetworkMetadata, } from '../interfaces' -import { addNetwork, networkStatus } from '../stores' -import { NetworkId, StardustNetworkId } from '../types' - -import { IBaseToken } from '@core/token' +import { IscChain } from '../classes' +import { addChain, networkStatus, removeChain } from '../stores' +import { EvmNetworkId, StardustNetworkId } from '../types' export class StardustNetwork implements IStardustNetwork { public readonly id: StardustNetworkId @@ -24,7 +22,7 @@ export class StardustNetwork implements IStardustNetwork { public readonly bech32Hrp: string public readonly protocol: IProtocol public readonly baseToken: IBaseToken - public readonly chainConfigurations: IIscChainConfiguration[] + public iscChains: IscChain[] constructor(persistedNetwork: IStardustNetworkMetadata) { this.id = persistedNetwork.id @@ -35,7 +33,12 @@ export class StardustNetwork implements IStardustNetwork { this.networkName = persistedNetwork.protocol.networkName this.protocol = persistedNetwork.protocol this.baseToken = persistedNetwork.baseToken - this.chainConfigurations = persistedNetwork.chainConfigurations + + this.iscChains = persistedNetwork.chainConfigurations + .map((chainConfiguration) => { + return new IscChain(chainConfiguration) + }) + .filter(Boolean) } getStatus(): INetworkStatus { @@ -50,28 +53,27 @@ export class StardustNetwork implements IStardustNetwork { network.chainConfigurations.push(chainConfiguration) updateActiveProfile({ network }) - this.chainConfigurations.push(chainConfiguration) - addNetwork(chainConfiguration) + const iscChain = new IscChain(chainConfiguration) + this.iscChains.push(iscChain) + addChain(iscChain) } } private isChainAlreadyAdded(chainConfiguration: IIscChainConfiguration): boolean { - return this.chainConfigurations.some((evmNetwork) => { - const hasSameName = evmNetwork.name === chainConfiguration.name - const hasSameId = evmNetwork.id === chainConfiguration.id + return this.iscChains.some(({ name, id }) => { + const hasSameName = name === chainConfiguration.name + const hasSameId = id === chainConfiguration.id return hasSameName || hasSameId }) } - editChain(networkId: NetworkId, payload: Partial): Promise { - return Promise.resolve() - } - - removeChain(networkId: NetworkId): void { + removeChain(networkId: EvmNetworkId): void { const network = get(activeProfile).network const newChains = network.chainConfigurations.filter( (chainConfiguration) => chainConfiguration.id !== networkId ) + this.iscChains = this.iscChains.filter((chain) => chain.id === networkId) + removeChain(networkId) updateActiveProfile({ network: { ...network, chainConfigurations: newChains } }) } } diff --git a/packages/shared/src/lib/core/network/interfaces/stardust-network.interface.ts b/packages/shared/src/lib/core/network/interfaces/stardust-network.interface.ts index 0a544cd8e6..8af9db11bd 100644 --- a/packages/shared/src/lib/core/network/interfaces/stardust-network.interface.ts +++ b/packages/shared/src/lib/core/network/interfaces/stardust-network.interface.ts @@ -2,15 +2,16 @@ import { NetworkNamespace } from '../enums' import { NetworkId } from '../types' import { INetworkStatus } from './network-status.interface' import { IIscChainConfiguration } from './evm-network-configuration.interface' -import { IStardustNetworkMetadata } from '@core/network' +import { IscChain, IStardustNetworkMetadata } from '@core/network' -export interface IStardustNetwork extends IStardustNetworkMetadata { +export interface IStardustNetwork extends Omit { namespace: NetworkNamespace.Stardust bech32Hrp: string + iscChains: IscChain[] + getStatus(): INetworkStatus addChain(chainConfiguration: IIscChainConfiguration): void - editChain(networkId: NetworkId, payload: Partial): Promise removeChain(networkId: NetworkId): void } diff --git a/packages/shared/src/lib/core/network/stores/networks.store.ts b/packages/shared/src/lib/core/network/stores/networks.store.ts index 49d020f8aa..1e693c23f4 100644 --- a/packages/shared/src/lib/core/network/stores/networks.store.ts +++ b/packages/shared/src/lib/core/network/stores/networks.store.ts @@ -4,23 +4,18 @@ import { activeProfile } from '@core/profile/stores' import features from '@features/features' import { IscChain, EvmNetwork, StardustNetwork } from '../classes' -import { IEvmNetwork, IIscChainConfiguration, IStardustNetwork } from '../interfaces' -import { Network, NetworkId } from '../types' +import { IEvmNetwork, IIscChain, IStardustNetwork } from '../interfaces' +import { EvmNetworkId, Network, NetworkId } from '../types' import { EvmNetworkType, NetworkNamespace } from '../enums' export const networks: Writable = writable([]) export function initializeNetworks(): void { const profile = get(activeProfile) - let _networks: Network[] = [] + const _networks: Network[] = [] if (profile?.network) { const stardustNetwork = new StardustNetwork(profile.network) - const chains = profile.network.chainConfigurations - .map((chainConfiguration) => { - return new IscChain(chainConfiguration) - }) - .filter(Boolean) as IEvmNetwork[] - _networks = [stardustNetwork, ...chains] + _networks.push(stardustNetwork, ...stardustNetwork.iscChains) } if (features.network.evmNetworks.enabled) { @@ -32,20 +27,26 @@ export function initializeNetworks(): void { networks.set(_networks) } -export function addNetwork(chainConfiguration: IIscChainConfiguration): void { - const network = getNetwork(chainConfiguration.id) +export function getNetwork(networkId: NetworkId): Network | undefined { + return get(networks)?.find((network) => network.id === networkId) +} + +export function addChain(chain: IIscChain): void { + const network = getNetwork(chain.id) if (network) { return } networks.update((networks) => { - networks.push(new IscChain(chainConfiguration)) + networks.push(chain) return networks }) } -export function getNetwork(networkId: NetworkId): Network | undefined { - return get(networks)?.find((network) => network.id === networkId) +export function removeChain(chainId: EvmNetworkId): void { + networks.update((networks) => { + return networks.filter(({ id }) => id !== chainId) + }) } export function getL1Network(): IStardustNetwork { diff --git a/packages/shared/src/lib/core/network/utils/buildPersistedNetworkFromNodeInfoResponse.ts b/packages/shared/src/lib/core/network/utils/buildPersistedNetworkFromNodeInfoResponse.ts index 26082b1cd6..3df66fe98b 100644 --- a/packages/shared/src/lib/core/network/utils/buildPersistedNetworkFromNodeInfoResponse.ts +++ b/packages/shared/src/lib/core/network/utils/buildPersistedNetworkFromNodeInfoResponse.ts @@ -29,6 +29,6 @@ export function buildPersistedNetworkFromNodeInfoResponse( coinType: _coinType, protocol: nodeInfoResponse?.nodeInfo?.protocol, baseToken: { standard: TokenStandard.BaseToken, ...nodeInfoResponse?.nodeInfo?.baseToken }, - chainConfigurations: chainConfigurations, + chainConfigurations, } } From a9092a1adcf0868e869b1d7cf5f99a93106f843b Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Fri, 26 Apr 2024 18:26:46 +0100 Subject: [PATCH 4/4] refactor: move json file functions to json file manager (#2383) --- .../electron/managers/json-file.manager.ts | 29 +++++++++++++++ .../lib/electron/processes/main.process.ts | 35 ++++--------------- 2 files changed, 35 insertions(+), 29 deletions(-) create mode 100644 packages/desktop/lib/electron/managers/json-file.manager.ts diff --git a/packages/desktop/lib/electron/managers/json-file.manager.ts b/packages/desktop/lib/electron/managers/json-file.manager.ts new file mode 100644 index 0000000000..746cd42dc9 --- /dev/null +++ b/packages/desktop/lib/electron/managers/json-file.manager.ts @@ -0,0 +1,29 @@ +import { IError } from '@core/error/interfaces' +import { app } from 'electron' +import fs from 'fs' +import path from 'path' + +export class JsonFileManager { + public static saveJsonToFile(filename: string, data: object): void { + try { + fs.writeFileSync(JsonFileManager.getFilePath(filename), JSON.stringify(data)) + } catch (err) { + console.error(err) + } + } + + public static loadJsonFromFile(filename: string): object | undefined { + try { + return JSON.parse(fs.readFileSync(JsonFileManager.getFilePath(filename)).toString()) + } catch (err) { + if (!(err as IError).message?.includes('ENOENT')) { + console.error(err) + } + } + } + + private static getFilePath(filename: string): string { + const userDataPath = app.getPath('userData') + return path.join(userDataPath, filename) + } +} diff --git a/packages/desktop/lib/electron/processes/main.process.ts b/packages/desktop/lib/electron/processes/main.process.ts index 5ed9625924..dcc90c83fe 100644 --- a/packages/desktop/lib/electron/processes/main.process.ts +++ b/packages/desktop/lib/electron/processes/main.process.ts @@ -36,7 +36,7 @@ import { getMachineId } from '../utils/os.utils' import { registerPowerMonitorListeners } from '../listeners' import ThirdPartyAppManager from '../managers/third-party-profiles.manager' import { ITransakWindowData } from '@core/app/interfaces' -import { IError } from '@core/error' +import { JsonFileManager } from '../managers/json-file.manager' export let appIsReady = false @@ -652,7 +652,7 @@ function windowStateKeeper(windowName: string, settingsFilename: string): IAppSt } function setBounds(): void { - const settings = loadJsonConfig(settingsFilename) + const settings = JsonFileManager.loadJsonFromFile(settingsFilename) if (settings && settings.windowState && settings.windowState[windowName]) { windowState = settings.windowState[windowName] @@ -666,13 +666,13 @@ function windowStateKeeper(windowName: string, settingsFilename: string): IAppSt windowState = window.getBounds() as IAppState } - let settings = loadJsonConfig(settingsFilename) as ISettings + let settings = JsonFileManager.loadJsonFromFile(settingsFilename) as ISettings settings = settings || {} settings.windowState = settings.windowState || {} settings.windowState[windowName] = windowState - saveJsonConfig(settingsFilename, settings) + JsonFileManager.saveJsonToFile(settingsFilename, settings) } function track(win: BrowserWindow): void { @@ -712,37 +712,14 @@ interface IAppState { function updateSettings(data: object): void { const filename = 'settings.json' - const config = loadJsonConfig(filename) + const config = JsonFileManager.loadJsonFromFile(filename) /** * CAUTION: We must be careful saving properties to this file, as * once we decide to save it there then it will be there forever * even if the name changes later. */ - saveJsonConfig(filename, { ...config, ...data }) -} - -function saveJsonConfig(filename: string, data: object): void { - try { - fs.writeFileSync(getJsonConfig(filename), JSON.stringify(data)) - } catch (err) { - console.error(err) - } -} - -function loadJsonConfig(filename: string): object | undefined { - try { - return JSON.parse(fs.readFileSync(getJsonConfig(filename)).toString()) - } catch (err) { - if (!(err as IError).message?.includes('ENOENT')) { - console.error(err) - } - } -} - -function getJsonConfig(filename: string): string { - const userDataPath = app.getPath('userData') - return path.join(userDataPath, filename) + JsonFileManager.saveJsonToFile(filename, { ...config, ...data }) } export function updateAppVersionDetails(details: object): void {