From 6b464c8c995a49386238d2a735f0d9bd397e7d63 Mon Sep 17 00:00:00 2001 From: evavirseda Date: Mon, 20 Jan 2025 12:43:57 +0100 Subject: [PATCH 01/40] feat: update buttons and title --- .../manage/accounts-finder/AccountsFinderPage.tsx | 6 +----- .../manage/accounts-finder/AccountsFinderView.tsx | 15 ++++----------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderPage.tsx b/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderPage.tsx index b49e66ba0d9..4b461fd5b5f 100644 --- a/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderPage.tsx +++ b/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderPage.tsx @@ -11,11 +11,7 @@ export function AccountsFinderPage() { useInitializedGuard(true); return ( - navigate('/accounts/manage')} - > + navigate('/accounts/manage')}> ); diff --git a/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx b/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx index 87a74dea45d..ef19ac63212 100644 --- a/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx +++ b/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx @@ -20,7 +20,7 @@ import { getKey, getLedgerConnectionErrorMessage } from '_src/ui/app/helpers'; import { useAccountSources, useAccounts, useUnlockMutation, useAccountsFinder } from '_hooks'; import { useMemo, useState } from 'react'; import toast from 'react-hot-toast'; -import { useParams } from 'react-router-dom'; +import { useNavigate, useParams } from 'react-router-dom'; function getAccountSourceType( accountSource?: AccountSourceSerializedUI, @@ -42,6 +42,7 @@ enum SearchPhase { } export function AccountsFinderView(): JSX.Element { + const navigate = useNavigate(); const { accountSourceId } = useParams(); const { data: accountSources } = useAccountSources(); const { data: accounts } = useAccounts(); @@ -126,7 +127,6 @@ export function AccountsFinderView(): JSX.Element {
{isLedgerLocked ? (
)} From da7e22d68fe97bae62f185a6557dc505de14b38a Mon Sep 17 00:00:00 2001 From: evavirseda Date: Tue, 21 Jan 2025 11:24:51 +0100 Subject: [PATCH 02/40] fix accordion --- apps/core/src/components/collapsible/Collapsible.tsx | 1 - .../src/components/ui/collapsible/CollapsibleCard.tsx | 1 - apps/explorer/src/pages/transaction-result/Events.tsx | 7 +------ .../transaction-summary/ObjectChanges.tsx | 2 +- .../src/lib/components/organisms/accordion/Accordion.tsx | 8 +++----- 5 files changed, 5 insertions(+), 14 deletions(-) diff --git a/apps/core/src/components/collapsible/Collapsible.tsx b/apps/core/src/components/collapsible/Collapsible.tsx index 5201d170aae..fccc93fe977 100644 --- a/apps/core/src/components/collapsible/Collapsible.tsx +++ b/apps/core/src/components/collapsible/Collapsible.tsx @@ -37,7 +37,6 @@ export function Collapsible({ return ( handleOpenChange(!open)} diff --git a/apps/explorer/src/components/ui/collapsible/CollapsibleCard.tsx b/apps/explorer/src/components/ui/collapsible/CollapsibleCard.tsx index 9c2fe974472..53a66daab17 100644 --- a/apps/explorer/src/components/ui/collapsible/CollapsibleCard.tsx +++ b/apps/explorer/src/components/ui/collapsible/CollapsibleCard.tsx @@ -46,7 +46,6 @@ export function CollapsibleCard({
setOpen(!open)} diff --git a/apps/explorer/src/pages/transaction-result/Events.tsx b/apps/explorer/src/pages/transaction-result/Events.tsx index 936a34f962e..6d83f4777e3 100644 --- a/apps/explorer/src/pages/transaction-result/Events.tsx +++ b/apps/explorer/src/pages/transaction-result/Events.tsx @@ -47,12 +47,7 @@ function Event({ event, divider }: { event: IotaEvent; divider: boolean }): JSX. isTruncated /> - setOpen(!open)} - > + setOpen(!open)}>
{open ? 'Hide' : 'View'} Event Data diff --git a/apps/explorer/src/pages/transaction-result/transaction-summary/ObjectChanges.tsx b/apps/explorer/src/pages/transaction-result/transaction-summary/ObjectChanges.tsx index 7b7c83838a1..18da9964adc 100644 --- a/apps/explorer/src/pages/transaction-result/transaction-summary/ObjectChanges.tsx +++ b/apps/explorer/src/pages/transaction-result/transaction-summary/ObjectChanges.tsx @@ -95,7 +95,7 @@ function ObjectDetailPanel({ panelContent, headerContent }: ObjectDetailPanelPro const [open, setOpen] = useState(false); return ( - setOpen(!open)}> + setOpen(!open)}>
Object diff --git a/apps/ui-kit/src/lib/components/organisms/accordion/Accordion.tsx b/apps/ui-kit/src/lib/components/organisms/accordion/Accordion.tsx index 47768f08b73..529f7127c02 100644 --- a/apps/ui-kit/src/lib/components/organisms/accordion/Accordion.tsx +++ b/apps/ui-kit/src/lib/components/organisms/accordion/Accordion.tsx @@ -44,16 +44,14 @@ export function AccordionHeader({ children, isExpanded, hideArrow, - hideBorder, }: PropsWithChildren) { return (
@@ -100,8 +98,8 @@ export function Accordion({ }): React.JSX.Element { return (
From c5e8e7b95bbf38c529b9e5deb1ff00457304918c Mon Sep 17 00:00:00 2001 From: evavirseda Date: Tue, 21 Jan 2025 11:35:21 +0100 Subject: [PATCH 03/40] feat: update styles --- .../accounts/AccountBalanceItem.tsx | 94 +++++++++++++------ .../accounts-finder/AccountsFinderView.tsx | 10 +- 2 files changed, 70 insertions(+), 34 deletions(-) diff --git a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx index 9508becfd5d..fc655ff95c9 100644 --- a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx +++ b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx @@ -1,46 +1,82 @@ // Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { formatAddress } from '@iota/iota-sdk/utils'; -import { useCopyToClipboard } from '_hooks'; import { type SerializedUIAccount } from '_src/background/accounts/account'; -import { useBalance, useFormatCoin } from '@iota/core'; -import { Copy } from '@iota/apps-ui-icons'; -import { Panel, ButtonUnstyled } from '@iota/apps-ui-kit'; +import { Collapsible } from '@iota/core'; +import { TriangleDown } from '@iota/apps-ui-icons'; +import clsx from 'clsx'; +import { Badge, BadgeType } from '@iota/apps-ui-kit'; interface AccountBalanceItemProps { account: SerializedUIAccount; } export function AccountBalanceItem({ account }: AccountBalanceItemProps): JSX.Element { - const copyAddress = useCopyToClipboard(account.address, { - copySuccessMessage: 'Address copied', - }); - const { data: balance } = useBalance(account.address, { - refetchInterval: false, - }); - - const totalBalance = balance?.totalBalance || '0'; - const coinType = balance?.coinType; - const [formatted, symbol] = useFormatCoin(BigInt(totalBalance), coinType); + // Replace the following mocked data with the actual data + const MOCKED_DATA = { + walletName: 'Wallet X', + totalBalance: '10.99 IOTA', + addresses: [ + { + address: '0x5e93…5928', + balance: '1.99 IOTA', + }, + { + address: '0x4d93…3679', + balance: '2.99 IOTA', + }, + { + address: '0x510…8898', + balance: '3.99 IOTA', + }, + { + address: '0x5e20…5990', + balance: '2.99 IOTA', + }, + ], + pills: ['Assets', 'Legacy', 'Vesting'], + }; return ( - -
-
-
- {formatAddress(account.address)} -
- - - + ( +
+
+ +
+
{MOCKED_DATA.walletName}
+ + {MOCKED_DATA.addresses.length} addresses + +
+
+
+ {MOCKED_DATA.totalBalance} +
+ {MOCKED_DATA.pills.map((pill) => ( + + ))}
- - - {formatted} {symbol} -
+ )} + > +
+ {MOCKED_DATA.addresses.map(({ address, balance }) => ( +
+ {address} + {balance} +
+ ))}
- +
); } diff --git a/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx b/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx index ef19ac63212..fde0bcd1d83 100644 --- a/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx +++ b/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { Search } from '@iota/apps-ui-icons'; -import { Button, ButtonType, ButtonSize, LoadingIndicator } from '@iota/apps-ui-kit'; +import { Button, ButtonType, LoadingIndicator } from '@iota/apps-ui-kit'; import { AccountBalanceItem, VerifyPasswordModal, @@ -118,13 +118,13 @@ export function AccountsFinderView(): JSX.Element { return ( <> -
-
+
+
{persistedAccounts?.map((account) => { return ; })}
-
+
{isLedgerLocked ? (
- {MOCKED_DATA.totalBalance} + {getSumOfBalances()}
- {MOCKED_DATA.pills.map((pill) => ( - - ))} + {hasAccountAssets() && ( + + )} + {hasSupplyIncreaseVestingObjects() && ( + + )} + {hasMigrationObjects() && ( + + )}
)} >
- {MOCKED_DATA.addresses.map(({ address, balance }) => ( + {accounts.map(({ address }) => (
- {address} - {balance} + {formatAddress(address)} + {getAddressBalance(address)}
))}
diff --git a/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx b/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx index fde0bcd1d83..8b312bd1815 100644 --- a/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx +++ b/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx @@ -13,7 +13,7 @@ import { AccountSourceType, type AccountSourceSerializedUI, } from '_src/background/account-sources/accountSource'; -import { AccountType } from '_src/background/accounts/account'; +import { AccountType, type SerializedUIAccount } from '_src/background/accounts/account'; import { type SourceStrategyToFind } from '_src/shared/messaging/messages/payloads/accounts-finder'; import { AllowedAccountSourceTypes } from '_src/ui/app/accounts-finder'; import { getKey, getLedgerConnectionErrorMessage } from '_src/ui/app/helpers'; @@ -21,6 +21,9 @@ import { useAccountSources, useAccounts, useUnlockMutation, useAccountsFinder } import { useMemo, useState } from 'react'; import toast from 'react-hot-toast'; import { useNavigate, useParams } from 'react-router-dom'; +import { makeDerivationPath, parseDerivationPath } from '_src/background/account-sources/bip44Path'; +import { isMnemonicSerializedUiAccount } from '_src/background/accounts/mnemonicAccount'; +import { isSeedSerializedUiAccount } from '_src/background/accounts/seedAccount'; function getAccountSourceType( accountSource?: AccountSourceSerializedUI, @@ -116,12 +119,35 @@ export function AccountsFinderView(): JSX.Element { const isSearchOngoing = searchPhase === SearchPhase.Ongoing; + function groupAccountsByAccountIndex( + accounts: SerializedUIAccount[], + ): Record { + const groupedAccounts: Record = {}; + accounts.forEach((account) => { + if (isMnemonicSerializedUiAccount(account) || isSeedSerializedUiAccount(account)) { + const { accountIndex } = parseDerivationPath(account.derivationPath); + if (!groupedAccounts[accountIndex]) { + groupedAccounts[accountIndex] = []; + } + groupedAccounts[accountIndex].push(account); + } + }); + return groupedAccounts; + } + const groupedAccounts = persistedAccounts && groupAccountsByAccountIndex(persistedAccounts); + return ( <>
- {persistedAccounts?.map((account) => { - return ; + {Object.entries(groupedAccounts || {}).map(([accountIndex, accounts]) => { + return ( + + ); })}
From 303563e0e8f30279d44c01962aecc359c466619d Mon Sep 17 00:00:00 2001 From: Panteleymonchuk Date: Tue, 28 Jan 2025 14:53:10 +0200 Subject: [PATCH 20/40] refactor(core): update StardustIndexerClient methods and rename hook for clarity --- apps/core/src/api/StardustIndexerClient.ts | 24 ++----------- ...s.ts => useGetAllStardustSharedObjects.ts} | 35 ++++++++++--------- .../hooks/useGetStardustMigratableObjects.ts | 4 +-- sdk/.env.defaults | 5 +-- 4 files changed, 23 insertions(+), 45 deletions(-) rename apps/wallet-dashboard/hooks/{useGetStardustIndexerOutputs.ts => useGetAllStardustSharedObjects.ts} (69%) diff --git a/apps/core/src/api/StardustIndexerClient.ts b/apps/core/src/api/StardustIndexerClient.ts index 1fc1a907f5a..69238ed403f 100644 --- a/apps/core/src/api/StardustIndexerClient.ts +++ b/apps/core/src/api/StardustIndexerClient.ts @@ -50,31 +50,11 @@ export class StardustIndexerClient { return response.json(); } - public getBasicOutputs = async ( - address: string, - params?: PageParams, - ): Promise => { - return this.request(`/basic/${address}`, undefined, { - page: params?.page, - page_size: params?.pageSize, - }); - }; - public getBasicResolvedOutputs = async ( address: string, params?: PageParams, ): Promise => { - return this.request(`/basic/resolved/${address}`, undefined, { - page: params?.page, - page_size: params?.pageSize, - }); - }; - - public getNftOutputs = async ( - address: string, - params?: PageParams, - ): Promise => { - return this.request(`/nft/resolved/${address}`, undefined, { + return this.request(`/v1/basic/resolved/${address}`, undefined, { page: params?.page, page_size: params?.pageSize, }); @@ -84,7 +64,7 @@ export class StardustIndexerClient { address: string, params?: PageParams, ): Promise => { - return this.request(`/nft/resolved/${address}`, undefined, { + return this.request(`/v1/nft/resolved/${address}`, undefined, { page: params?.page, page_size: params?.pageSize, }); diff --git a/apps/wallet-dashboard/hooks/useGetStardustIndexerOutputs.ts b/apps/wallet-dashboard/hooks/useGetAllStardustSharedObjects.ts similarity index 69% rename from apps/wallet-dashboard/hooks/useGetStardustIndexerOutputs.ts rename to apps/wallet-dashboard/hooks/useGetAllStardustSharedObjects.ts index 771fac9e744..86125950b07 100644 --- a/apps/wallet-dashboard/hooks/useGetStardustIndexerOutputs.ts +++ b/apps/wallet-dashboard/hooks/useGetAllStardustSharedObjects.ts @@ -15,34 +15,35 @@ import { IotaObjectData } from '@iota/iota-sdk/client'; const LIMIT_PER_REQ = 50; -export function useGetStardustIndexerOutputs(address: string) { +export function useGetAllStardustSharedObjects(address: string) { const { data: currentEpochMs } = useGetCurrentEpochStartTimestamp(); const { stardustIndexerClient } = useStardustIndexerClientContext(); - const fetchPaginatedOutputs = async ( + const fetchPaginatedStardustSharedObjects = async ( mapFn: (output: StardustIndexerOutput) => IotaObjectData, fetchFn: (address: string, params: PageParams) => Promise, ) => { - const allOutputs = []; + const allData: StardustIndexerOutput[] = []; let page = 1; - let hasMoreData = true; + const hasMoreData = true; try { - while (hasMoreData) { - const outputs = await fetchFn(address, { page, pageSize: LIMIT_PER_REQ }); + do { + const data = await fetchFn(address, { page, pageSize: LIMIT_PER_REQ }); - if (!outputs || outputs.length === 0) { - hasMoreData = false; - } else { - allOutputs.push(...outputs); - page++; + if (!data || !data.length) { + break; } - } + + allData.push(...data); + page++; + } while (page); + while (hasMoreData); } catch (e) { console.error(e); } - return allOutputs.map(mapFn); + return allData.map(mapFn); }; return useQuery({ @@ -55,19 +56,19 @@ export function useGetStardustIndexerOutputs(address: string) { }; } - const basicObjects = await fetchPaginatedOutputs( + const basicOutputs = await fetchPaginatedStardustSharedObjects( mapStardustBasicOutputs, stardustIndexerClient.getBasicResolvedOutputs, ); - const nftObjects = await fetchPaginatedOutputs( + const nftOutputs = await fetchPaginatedStardustSharedObjects( mapStardustNftOutputs, stardustIndexerClient.getNftResolvedOutputs, ); return { - basic: basicObjects, - nfts: nftObjects, + basic: basicOutputs, + nfts: nftOutputs, }; }, enabled: !!address && currentEpochMs !== undefined, diff --git a/apps/wallet-dashboard/hooks/useGetStardustMigratableObjects.ts b/apps/wallet-dashboard/hooks/useGetStardustMigratableObjects.ts index b676d624dcc..ad564d0e3bd 100644 --- a/apps/wallet-dashboard/hooks/useGetStardustMigratableObjects.ts +++ b/apps/wallet-dashboard/hooks/useGetStardustMigratableObjects.ts @@ -10,12 +10,12 @@ import { TimeUnit, useGetAllOwnedObjects, } from '@iota/core'; -import { useGetStardustIndexerOutputs } from './useGetStardustIndexerOutputs'; +import { useGetAllStardustSharedObjects } from './useGetAllStardustSharedObjects'; export function useGetStardustMigratableObjects(address: string) { const { data: currentEpochMs } = useGetCurrentEpochStartTimestamp(); const { data: stardustIndexerData, isPending: stardustIndexerPending } = - useGetStardustIndexerOutputs(address); + useGetAllStardustSharedObjects(address); const { data: basicOutputObjects } = useGetAllOwnedObjects(address, { StructType: STARDUST_BASIC_OUTPUT_TYPE, }); diff --git a/sdk/.env.defaults b/sdk/.env.defaults index 370319d955e..e876e2d7a9b 100644 --- a/sdk/.env.defaults +++ b/sdk/.env.defaults @@ -32,10 +32,7 @@ IOTA_NETWORKS = ' "url": "http://localhost:9000", "explorer": "http://localhost:3000", "chain": "iota:local", - "faucet": "http://localhost:9123", - "metadata": { - "stardustIndexer": "" - } + "faucet": "http://localhost:9123" } } ' From 9bdab66bfbcad15a5319ae2377705ef4bd52ac0b Mon Sep 17 00:00:00 2001 From: Panteleymonchuk Date: Tue, 28 Jan 2025 14:59:59 +0200 Subject: [PATCH 21/40] refactor(dashboard): remove unused variables in useGetAllStardustSharedObjects hook --- apps/wallet-dashboard/hooks/useGetAllStardustSharedObjects.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/wallet-dashboard/hooks/useGetAllStardustSharedObjects.ts b/apps/wallet-dashboard/hooks/useGetAllStardustSharedObjects.ts index 86125950b07..c329b04cf26 100644 --- a/apps/wallet-dashboard/hooks/useGetAllStardustSharedObjects.ts +++ b/apps/wallet-dashboard/hooks/useGetAllStardustSharedObjects.ts @@ -25,7 +25,6 @@ export function useGetAllStardustSharedObjects(address: string) { ) => { const allData: StardustIndexerOutput[] = []; let page = 1; - const hasMoreData = true; try { do { @@ -38,7 +37,6 @@ export function useGetAllStardustSharedObjects(address: string) { allData.push(...data); page++; } while (page); - while (hasMoreData); } catch (e) { console.error(e); } From 234c459665c9d9ed206bf7ac997c51d7c5d6b67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bego=C3=B1a=20Alvarez?= Date: Tue, 28 Jan 2025 16:19:35 +0100 Subject: [PATCH 22/40] fix: add missing 0x to stardust package id --- apps/core/src/constants/migration.constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/core/src/constants/migration.constants.ts b/apps/core/src/constants/migration.constants.ts index dc14721052d..4e1491da228 100644 --- a/apps/core/src/constants/migration.constants.ts +++ b/apps/core/src/constants/migration.constants.ts @@ -4,7 +4,7 @@ import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils'; export const STARDUST_PACKAGE_ID = - '000000000000000000000000000000000000000000000000000000000000107a'; + '0x000000000000000000000000000000000000000000000000000000000000107a'; export const STARDUST_BASIC_OUTPUT_TYPE = `${STARDUST_PACKAGE_ID}::basic_output::BasicOutput<${IOTA_TYPE_ARG}>`; export const STARDUST_NFT_OUTPUT_TYPE = `${STARDUST_PACKAGE_ID}::nft_output::NftOutput<${IOTA_TYPE_ARG}>`; export const STARDUST_EXPIRATION_UNLOCK_CONDITION_TYPE = `${STARDUST_PACKAGE_ID}::expiration_unlock_condition::ExpirationUnlockCondition`; From 3d502071b664174193ac78d1a7b47422bb85cbf0 Mon Sep 17 00:00:00 2001 From: Panteleymonchuk Date: Tue, 28 Jan 2025 18:40:26 +0200 Subject: [PATCH 23/40] refactor(core, dashboard): update Stardust package ID format, improve metadata handling in hooks, rename variables. --- .../utils/migration/mapStardustIndexerOutputs.ts | 2 +- apps/core/src/utils/migration/types.ts | 2 +- .../app/(protected)/migrations/page.tsx | 14 +++++++++++--- .../hooks/useGetAllStardustSharedObjects.ts | 10 ++-------- .../hooks/useGetStardustMigratableObjects.ts | 16 ++++++++-------- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/apps/core/src/utils/migration/mapStardustIndexerOutputs.ts b/apps/core/src/utils/migration/mapStardustIndexerOutputs.ts index b7410a1cf94..3a7338a3189 100644 --- a/apps/core/src/utils/migration/mapStardustIndexerOutputs.ts +++ b/apps/core/src/utils/migration/mapStardustIndexerOutputs.ts @@ -48,7 +48,7 @@ const mapStardustOutput: MapStardustOutput = function ( id: { id: output.id, }, - metadata: [], + metadata: output.metadata, native_tokens: { type: '0x2::bag::Bag', fields: { diff --git a/apps/core/src/utils/migration/types.ts b/apps/core/src/utils/migration/types.ts index ab3868af00d..a812341134f 100644 --- a/apps/core/src/utils/migration/types.ts +++ b/apps/core/src/utils/migration/types.ts @@ -85,7 +85,7 @@ const StardustIndexerOutputSchema = z.object({ unix_time: z.number(), }) .nullable(), - metadata: z.string().nullable(), + metadata: z.array(z.number()).nullable(), tag: z.string().nullable(), sender: z.string().nullable(), }); diff --git a/apps/wallet-dashboard/app/(protected)/migrations/page.tsx b/apps/wallet-dashboard/app/(protected)/migrations/page.tsx index e9215b53f13..885aca68270 100644 --- a/apps/wallet-dashboard/app/(protected)/migrations/page.tsx +++ b/apps/wallet-dashboard/app/(protected)/migrations/page.tsx @@ -21,7 +21,12 @@ import { } from '@iota/apps-ui-kit'; import { Assets, IotaLogoMark, Tokens } from '@iota/apps-ui-icons'; import { useCurrentAccount, useIotaClient } from '@iota/dapp-kit'; -import { STARDUST_BASIC_OUTPUT_TYPE, STARDUST_NFT_OUTPUT_TYPE, useFormatCoin } from '@iota/core'; +import { + STARDUST_BASIC_OUTPUT_TYPE, + STARDUST_NFT_OUTPUT_TYPE, + useFormatCoin, + useStardustIndexerClientContext, +} from '@iota/core'; import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils'; import { StardustOutputMigrationStatus } from '@/lib/enums'; import { MigrationObjectsPanel, MigrationDialog } from '@/components'; @@ -37,7 +42,7 @@ function MigrationDashboardPage(): JSX.Element { const [selectedStardustObjectsCategory, setSelectedStardustObjectsCategory] = useState< StardustOutputMigrationStatus | undefined >(undefined); - + const { stardustIndexerClient } = useStardustIndexerClientContext(); const { data: stardustMigrationObjects, isPlaceholderData } = useGetStardustMigratableObjects(address); const { @@ -111,9 +116,12 @@ function MigrationDashboardPage(): JSX.Element { queryClient.invalidateQueries({ queryKey: ['migration-transaction', address], }); + queryClient.invalidateQueries({ + queryKey: ['stardust-shared-objects', address, stardustIndexerClient], + }); }); }, - [iotaClient, queryClient, address], + [iotaClient, queryClient, address, stardustIndexerClient], ); const MIGRATION_CARDS: MigrationDisplayCardProps[] = [ diff --git a/apps/wallet-dashboard/hooks/useGetAllStardustSharedObjects.ts b/apps/wallet-dashboard/hooks/useGetAllStardustSharedObjects.ts index c329b04cf26..1e15fe9e510 100644 --- a/apps/wallet-dashboard/hooks/useGetAllStardustSharedObjects.ts +++ b/apps/wallet-dashboard/hooks/useGetAllStardustSharedObjects.ts @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 import { useQuery } from '@tanstack/react-query'; -import { useGetCurrentEpochStartTimestamp } from '@/hooks'; import { mapStardustBasicOutputs, mapStardustNftOutputs, @@ -16,7 +15,6 @@ import { IotaObjectData } from '@iota/iota-sdk/client'; const LIMIT_PER_REQ = 50; export function useGetAllStardustSharedObjects(address: string) { - const { data: currentEpochMs } = useGetCurrentEpochStartTimestamp(); const { stardustIndexerClient } = useStardustIndexerClientContext(); const fetchPaginatedStardustSharedObjects = async ( @@ -45,7 +43,7 @@ export function useGetAllStardustSharedObjects(address: string) { }; return useQuery({ - queryKey: ['stardust-indexer-outputs', address, currentEpochMs, stardustIndexerClient], + queryKey: ['stardust-shared-objects', address, stardustIndexerClient], queryFn: async () => { if (!stardustIndexerClient) { return { @@ -69,12 +67,8 @@ export function useGetAllStardustSharedObjects(address: string) { nfts: nftOutputs, }; }, - enabled: !!address && currentEpochMs !== undefined, + enabled: !!address, staleTime: TimeUnit.ONE_SECOND * TimeUnit.ONE_MINUTE * 5, - initialData: { - basic: [], - nfts: [], - }, placeholderData: { basic: [], nfts: [], diff --git a/apps/wallet-dashboard/hooks/useGetStardustMigratableObjects.ts b/apps/wallet-dashboard/hooks/useGetStardustMigratableObjects.ts index ad564d0e3bd..cbbbeb1d6a8 100644 --- a/apps/wallet-dashboard/hooks/useGetStardustMigratableObjects.ts +++ b/apps/wallet-dashboard/hooks/useGetStardustMigratableObjects.ts @@ -14,7 +14,7 @@ import { useGetAllStardustSharedObjects } from './useGetAllStardustSharedObjects export function useGetStardustMigratableObjects(address: string) { const { data: currentEpochMs } = useGetCurrentEpochStartTimestamp(); - const { data: stardustIndexerData, isPending: stardustIndexerPending } = + const { data: stardustSharedObjectsData, isPending: stardustSharedObjectsPending } = useGetAllStardustSharedObjects(address); const { data: basicOutputObjects } = useGetAllOwnedObjects(address, { StructType: STARDUST_BASIC_OUTPUT_TYPE, @@ -23,8 +23,8 @@ export function useGetStardustMigratableObjects(address: string) { StructType: STARDUST_NFT_OUTPUT_TYPE, }); - const stardustIndexerBasics = stardustIndexerData.basic; - const stardustIndexerNfts = stardustIndexerData.nfts; + const sharedBasicOutputObjects = stardustSharedObjectsData!.basic; + const sharedNftOutputObjects = stardustSharedObjectsData!.nfts; return useQuery({ queryKey: [ @@ -33,22 +33,22 @@ export function useGetStardustMigratableObjects(address: string) { currentEpochMs, basicOutputObjects, nftOutputObjects, - stardustIndexerBasics, - stardustIndexerNfts, + sharedBasicOutputObjects, + sharedNftOutputObjects, ], queryFn: () => { const epochMs = Number(currentEpochMs) || 0; const { migratable: migratableBasicOutputs, timelocked: timelockedBasicOutputs } = groupStardustObjectsByMigrationStatus( - [...(basicOutputObjects ?? []), ...stardustIndexerBasics], + [...(basicOutputObjects ?? []), ...sharedBasicOutputObjects], epochMs, address, ); const { migratable: migratableNftOutputs, timelocked: timelockedNftOutputs } = groupStardustObjectsByMigrationStatus( - [...(nftOutputObjects ?? []), ...stardustIndexerNfts], + [...(nftOutputObjects ?? []), ...sharedNftOutputObjects], epochMs, address, ); @@ -65,7 +65,7 @@ export function useGetStardustMigratableObjects(address: string) { currentEpochMs !== undefined && basicOutputObjects !== undefined && nftOutputObjects !== undefined && - !stardustIndexerPending, + !stardustSharedObjectsPending, staleTime: TimeUnit.ONE_SECOND * TimeUnit.ONE_MINUTE * 5, placeholderData: { migratableBasicOutputs: [], From 2e9c439c5ade983d6dfcdc7f39a65f301493bdf8 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Tue, 28 Jan 2025 19:10:53 +0100 Subject: [PATCH 24/40] fix(wallet): flagged as address to import --- .../src/ui/app/accounts-finder/accountsFinder.ts | 16 +++++----------- apps/wallet/src/ui/app/accounts-finder/utils.ts | 11 ++++++++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/apps/wallet/src/ui/app/accounts-finder/accountsFinder.ts b/apps/wallet/src/ui/app/accounts-finder/accountsFinder.ts index 4590b4958f2..dc9a0b1a35b 100644 --- a/apps/wallet/src/ui/app/accounts-finder/accountsFinder.ts +++ b/apps/wallet/src/ui/app/accounts-finder/accountsFinder.ts @@ -246,25 +246,19 @@ export class AccountsFinder { if (!hasMigrationObject && this.stardustIndexerClient) { // Fetch Basic Outputs from Stardust Indexer let sharedStardustObjects = - (await this.stardustIndexerClient?.getBasicOutputs(address, { - page: 1, - limit: 1, + (await this.stardustIndexerClient?.getBasicResolvedOutputs(address, { + pageSize: 1, })) ?? []; if (sharedStardustObjects.length === 0) { // Fetch Nft Outputs from Stardust Indexer sharedStardustObjects = - (await this.stardustIndexerClient?.getNftOutputs(address, { - page: 1, - limit: 1, - })) ?? []; + (await this.stardustIndexerClient?.getNftResolvedOutputs(address, { + pageSize: 1, + })) ?? []; } hasMigrationObject = sharedStardustObjects.length > 0; } - console.log('ownedAsset', ownedAsset); - console.log('hasTimelockedObject', hasTimelockedObject); - console.log('hasMigrationObject', hasMigrationObject); - return { publicKey: publicKeyB64, balance: foundBalance || emptyBalance, diff --git a/apps/wallet/src/ui/app/accounts-finder/utils.ts b/apps/wallet/src/ui/app/accounts-finder/utils.ts index f59f9b0aedc..2b3ffb1b963 100644 --- a/apps/wallet/src/ui/app/accounts-finder/utils.ts +++ b/apps/wallet/src/ui/app/accounts-finder/utils.ts @@ -225,8 +225,8 @@ export function mergeAccounts(accounts1: AccountFromFinder[], accounts2: Account return transformFromBipMap(bipMap); } -// Diff the found and persisted accounts so we know -// what addresses have not persisted yet and have balance. +// Diff the found and persisted accounts so we know +// what addresses have not persisted yet and have relevant assets or balance. export function diffAddressesBipPaths( foundAccounts: AccountFromFinder[], persistedAccounts: AccountFromFinder[], @@ -237,7 +237,12 @@ export function diffAddressesBipPaths( const foundBipMapKeys = Object.entries(foundBipMap); const persistedBipMapKeys = Object.keys(persistedBipMap); const diffBipPaths = foundBipMapKeys.filter( - ([key, address]) => !persistedBipMapKeys.includes(key) && hasBalance(address.balance), + ([key, address]) => + !persistedBipMapKeys.includes(key) && + (hasBalance(address.balance) || + address.hasAsset || + address.hasTimelockedObject || + address.hasMigrationObject), ); return diffBipPaths.map(([_, account]) => account); From c0ad98c0fbb273aa800fd02b6e3e8f06c9255c21 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Wed, 29 Jan 2025 19:24:55 +0100 Subject: [PATCH 25/40] fix(wallet): add constant to set a limiit of the objects to fetch in the balance finder --- .../src/ui/app/accounts-finder/accountsFinder.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/wallet/src/ui/app/accounts-finder/accountsFinder.ts b/apps/wallet/src/ui/app/accounts-finder/accountsFinder.ts index dc9a0b1a35b..1ae3ca1e107 100644 --- a/apps/wallet/src/ui/app/accounts-finder/accountsFinder.ts +++ b/apps/wallet/src/ui/app/accounts-finder/accountsFinder.ts @@ -80,6 +80,8 @@ const CHANGE_INDEXES: { [key in AllowedBip44CoinTypes]: number[] } = { [AllowedBip44CoinTypes.IOTA]: [0, 1], }; +const NUMBER_OF_OBJECTS_TO_FETCH = 1; + export class AccountsFinder { private accountGapLimit: number = 0; private addressGapLimit: number = 0; @@ -215,7 +217,7 @@ export class AccountsFinder { { StructType: STARDUST_NFT_OUTPUT_TYPE }, ], }, - limit: 1, + limit: NUMBER_OF_OBJECTS_TO_FETCH, }); const ownedTimelockedObject = await this.client.getOwnedObjects({ @@ -226,7 +228,7 @@ export class AccountsFinder { { StructType: TIMELOCK_STAKED_TYPE }, ], }, - limit: 1, + limit: NUMBER_OF_OBJECTS_TO_FETCH, }); const hasTimelockedObject = ownedTimelockedObject.data.length > 0; @@ -239,7 +241,7 @@ export class AccountsFinder { { StructType: STARDUST_NFT_OUTPUT_TYPE }, ], }, - limit: 1, + limit: NUMBER_OF_OBJECTS_TO_FETCH, }); let hasMigrationObject = ownedStardustObjects.data.length > 0; @@ -247,13 +249,13 @@ export class AccountsFinder { // Fetch Basic Outputs from Stardust Indexer let sharedStardustObjects = (await this.stardustIndexerClient?.getBasicResolvedOutputs(address, { - pageSize: 1, + pageSize: NUMBER_OF_OBJECTS_TO_FETCH, })) ?? []; if (sharedStardustObjects.length === 0) { // Fetch Nft Outputs from Stardust Indexer sharedStardustObjects = (await this.stardustIndexerClient?.getNftResolvedOutputs(address, { - pageSize: 1, + pageSize: NUMBER_OF_OBJECTS_TO_FETCH, })) ?? []; } hasMigrationObject = sharedStardustObjects.length > 0; From 6204e2f03f08a9cce704b5dac60dd011fb315ced Mon Sep 17 00:00:00 2001 From: evavirseda Date: Thu, 30 Jan 2025 09:51:13 +0100 Subject: [PATCH 26/40] fix build --- apps/wallet-dashboard/providers/AppProviders.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/wallet-dashboard/providers/AppProviders.tsx b/apps/wallet-dashboard/providers/AppProviders.tsx index 09407fa8b24..549c2d3908c 100644 --- a/apps/wallet-dashboard/providers/AppProviders.tsx +++ b/apps/wallet-dashboard/providers/AppProviders.tsx @@ -13,7 +13,6 @@ import { useState } from 'react'; import { KioskClientProvider, StardustIndexerClientProvider, useLocalStorage } from '@iota/core'; import { growthbook } from '@/lib/utils'; import { ThemeProvider } from '@iota/core'; -import { StardustIndexerClientProvider } from './StardustIndexerClientProvider'; import { createIotaClient } from '@/lib/utils/defaultRpcClient'; growthbook.init(); From 89160760754bd0c87904b1c8eb24aecc5ae3e34a Mon Sep 17 00:00:00 2001 From: evavirseda Date: Thu, 30 Jan 2025 09:51:53 +0100 Subject: [PATCH 27/40] remove debris --- .../StardustIndexerClientProvider.tsx | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 apps/wallet-dashboard/providers/StardustIndexerClientProvider.tsx diff --git a/apps/wallet-dashboard/providers/StardustIndexerClientProvider.tsx b/apps/wallet-dashboard/providers/StardustIndexerClientProvider.tsx deleted file mode 100644 index e1e85e5bf81..00000000000 --- a/apps/wallet-dashboard/providers/StardustIndexerClientProvider.tsx +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2024 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -'use client'; - -import { useIotaClientContext } from '@iota/dapp-kit'; -import { StardustIndexerClientContext, useStardustIndexerClient } from '@iota/core'; - -export const StardustIndexerClientProvider: React.FC = ({ children }) => { - const { network } = useIotaClientContext(); - const { stardustIndexerClient } = useStardustIndexerClient(network); - - return ( - - {children} - - ); -}; From a7b1bd1f39e5556eb7dc99a802253b39be032ef3 Mon Sep 17 00:00:00 2001 From: evavirseda Date: Thu, 30 Jan 2025 13:52:38 +0100 Subject: [PATCH 28/40] fixes --- .../accounts/AccountBalanceItem.tsx | 37 ++++++++++--------- .../accounts-finder/AccountsFinderView.tsx | 8 ++-- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx index a1e5a531c3b..db5966486b3 100644 --- a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx +++ b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx @@ -12,7 +12,8 @@ import { useBalance, useFormatCoin, useGetOwnedObjects, - useStardustIndexerClientContext, + useGetStardustSharedBasicObjects, + useGetStardustSharedNftObjects, } from '@iota/core'; import { TriangleDown } from '@iota/apps-ui-icons'; import clsx from 'clsx'; @@ -28,7 +29,6 @@ export function AccountBalanceItem({ accounts, accountIndex, }: AccountBalanceItemProps): JSX.Element { - function getAddressBalance(address: string): string { const { data: balance } = useBalance(address, { refetchInterval: false, @@ -58,7 +58,7 @@ export function AccountBalanceItem({ const { data: ownedAssets } = useGetOwnedObjects( address, { - MatchAny: [ + MatchNone: [ { StructType: COIN_TYPE }, { StructType: TIMELOCK_IOTA_TYPE }, { StructType: TIMELOCK_STAKED_TYPE }, @@ -93,8 +93,18 @@ export function AccountBalanceItem({ } function hasMigrationObjects(): boolean { + const OBJECT_PER_REQ = 1; let containsMigrationObjects = false; return accounts.some(({ address }) => { + const { data: stardustSharedBasicObjects } = useGetStardustSharedBasicObjects( + address || '', + OBJECT_PER_REQ, + ); + const { data: stardustSharedNftObjects } = useGetStardustSharedNftObjects( + address || '', + OBJECT_PER_REQ, + ); + const { data: legacyObjects } = useGetOwnedObjects( address, { @@ -106,18 +116,9 @@ export function AccountBalanceItem({ 1, ); containsMigrationObjects = !!legacyObjects?.pages?.[0]?.data?.length; - if (!legacyObjects || legacyObjects?.pages?.[0]?.data?.length === 0) { - const { stardustIndexerClient } = useStardustIndexerClientContext(); - - const indexedBasicOutputs = stardustIndexerClient?.getBasicOutputs(address, { - limit: 1, - }); - - const indexedNftOutputs = stardustIndexerClient?.getNftOutputs(address, { - limit: 1, - }); - - containsMigrationObjects = !!indexedBasicOutputs || !!indexedNftOutputs; + if (!legacyObjects || !containsMigrationObjects) { + containsMigrationObjects = + !!stardustSharedBasicObjects?.length || !!stardustSharedNftObjects?.length; } return containsMigrationObjects; @@ -142,7 +143,7 @@ export function AccountBalanceItem({
Wallet {Number(accountIndex) + 1}
- {accounts.length} addresses + {accounts.length} {accounts.length > 1 ? 'addresses' : 'address'}
@@ -164,8 +165,8 @@ export function AccountBalanceItem({ )} >
- {accounts.map(({ address }) => ( -
+ {accounts.map(({ address, id }) => ( +
{formatAddress(address)} {getAddressBalance(address)}
diff --git a/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx b/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx index 8b312bd1815..0fa319e6f15 100644 --- a/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx +++ b/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx @@ -21,7 +21,7 @@ import { useAccountSources, useAccounts, useUnlockMutation, useAccountsFinder } import { useMemo, useState } from 'react'; import toast from 'react-hot-toast'; import { useNavigate, useParams } from 'react-router-dom'; -import { makeDerivationPath, parseDerivationPath } from '_src/background/account-sources/bip44Path'; +import { parseDerivationPath } from '_src/background/account-sources/bip44Path'; import { isMnemonicSerializedUiAccount } from '_src/background/accounts/mnemonicAccount'; import { isSeedSerializedUiAccount } from '_src/background/accounts/seedAccount'; @@ -179,13 +179,11 @@ export function AccountsFinderView(): JSX.Element {
)} From 774ccd6f2b1be8a96e0745f428b120954c16755c Mon Sep 17 00:00:00 2001 From: cpl121 Date: Thu, 30 Jan 2025 16:10:03 +0100 Subject: [PATCH 29/40] fix(wallet): rename boolean objects --- apps/wallet/src/shared/accounts.ts | 6 +++--- .../ui/app/accounts-finder/accounts-finder.test.ts | 12 ++++++------ .../src/ui/app/accounts-finder/accountsFinder.ts | 14 +++++++------- apps/wallet/src/ui/app/accounts-finder/types.ts | 6 +++--- apps/wallet/src/ui/app/accounts-finder/utils.ts | 12 ++++++------ 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/apps/wallet/src/shared/accounts.ts b/apps/wallet/src/shared/accounts.ts index 934d2ea5b0c..89794a3d01b 100644 --- a/apps/wallet/src/shared/accounts.ts +++ b/apps/wallet/src/shared/accounts.ts @@ -6,9 +6,9 @@ import { type CoinBalance } from '@iota/iota-sdk/client'; export interface AddressFromFinder { publicKey: string; bipPath: Bip44Path; - hasTimelockedObject: boolean; - hasMigrationObject: boolean; - hasAsset: boolean; + hasTimelockedObjects: boolean; + hasStardustObjects: boolean; + hasAssets: boolean; balance: CoinBalance; } diff --git a/apps/wallet/src/ui/app/accounts-finder/accounts-finder.test.ts b/apps/wallet/src/ui/app/accounts-finder/accounts-finder.test.ts index 2f6d3cde49d..20dcb82ee61 100644 --- a/apps/wallet/src/ui/app/accounts-finder/accounts-finder.test.ts +++ b/apps/wallet/src/ui/app/accounts-finder/accounts-finder.test.ts @@ -23,9 +23,9 @@ const findBalanceFactory = ( coinObjectCount: 2, coinType: '0x2::iota::IOTA', }, - hasAsset: false, - hasMigrationObject: false, - hasTimelockedObject: false, + hasAssets: false, + hasStardustObjects: false, + hasTimelockedObjects: false, }); } @@ -36,9 +36,9 @@ const findBalanceFactory = ( coinObjectCount: 0, coinType: '0x2::iota::IOTA', }, - hasAsset: false, - hasMigrationObject: false, - hasTimelockedObject: false, + hasAssets: false, + hasStardustObjects: false, + hasTimelockedObjects: false, }); }; }; diff --git a/apps/wallet/src/ui/app/accounts-finder/accountsFinder.ts b/apps/wallet/src/ui/app/accounts-finder/accountsFinder.ts index 1ae3ca1e107..ef3b7423c49 100644 --- a/apps/wallet/src/ui/app/accounts-finder/accountsFinder.ts +++ b/apps/wallet/src/ui/app/accounts-finder/accountsFinder.ts @@ -231,7 +231,7 @@ export class AccountsFinder { limit: NUMBER_OF_OBJECTS_TO_FETCH, }); - const hasTimelockedObject = ownedTimelockedObject.data.length > 0; + const hasTimelockedObjects = ownedTimelockedObject.data.length > 0; const ownedStardustObjects = await this.client.getOwnedObjects({ owner: address, @@ -244,8 +244,8 @@ export class AccountsFinder { limit: NUMBER_OF_OBJECTS_TO_FETCH, }); - let hasMigrationObject = ownedStardustObjects.data.length > 0; - if (!hasMigrationObject && this.stardustIndexerClient) { + let hasStardustObjects = ownedStardustObjects.data.length > 0; + if (!hasStardustObjects && this.stardustIndexerClient) { // Fetch Basic Outputs from Stardust Indexer let sharedStardustObjects = (await this.stardustIndexerClient?.getBasicResolvedOutputs(address, { @@ -258,15 +258,15 @@ export class AccountsFinder { pageSize: NUMBER_OF_OBJECTS_TO_FETCH, })) ?? []; } - hasMigrationObject = sharedStardustObjects.length > 0; + hasStardustObjects = sharedStardustObjects.length > 0; } return { publicKey: publicKeyB64, balance: foundBalance || emptyBalance, - hasAsset: ownedAsset.data.length > 0, - hasTimelockedObject, - hasMigrationObject, + hasAssets: ownedAsset.data.length > 0, + hasTimelockedObjects, + hasStardustObjects, }; }; } diff --git a/apps/wallet/src/ui/app/accounts-finder/types.ts b/apps/wallet/src/ui/app/accounts-finder/types.ts index 713d358313a..fc9efa43d3b 100644 --- a/apps/wallet/src/ui/app/accounts-finder/types.ts +++ b/apps/wallet/src/ui/app/accounts-finder/types.ts @@ -10,7 +10,7 @@ export type FindBalance = (params: { }) => Promise<{ publicKey: string; balance: CoinBalance; - hasAsset: boolean; - hasTimelockedObject: boolean; - hasMigrationObject: boolean; + hasAssets: boolean; + hasTimelockedObjects: boolean; + hasStardustObjects: boolean; }>; diff --git a/apps/wallet/src/ui/app/accounts-finder/utils.ts b/apps/wallet/src/ui/app/accounts-finder/utils.ts index 2b3ffb1b963..7c3c0c28cbf 100644 --- a/apps/wallet/src/ui/app/accounts-finder/utils.ts +++ b/apps/wallet/src/ui/app/accounts-finder/utils.ts @@ -158,9 +158,9 @@ async function searchBalances({ accountIndex, changeIndex, }, - hasTimelockedObject: foundBalance.hasAsset, - hasMigrationObject: foundBalance.hasTimelockedObject, - hasAsset: foundBalance.hasMigrationObject, + hasTimelockedObjects: foundBalance.hasAssets, + hasStardustObjects: foundBalance.hasTimelockedObjects, + hasAssets: foundBalance.hasStardustObjects, }); } return { @@ -240,9 +240,9 @@ export function diffAddressesBipPaths( ([key, address]) => !persistedBipMapKeys.includes(key) && (hasBalance(address.balance) || - address.hasAsset || - address.hasTimelockedObject || - address.hasMigrationObject), + address.hasAssets || + address.hasTimelockedObjects || + address.hasStardustObjects), ); return diffBipPaths.map(([_, account]) => account); From 8fb4e5fbd65beac2864a6472a7694fa4870efa01 Mon Sep 17 00:00:00 2001 From: evavirseda Date: Thu, 30 Jan 2025 17:21:01 +0100 Subject: [PATCH 30/40] rename constants and use object per request constant --- .../accounts/AccountBalanceItem.tsx | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx index db5966486b3..35a52bc83e2 100644 --- a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx +++ b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx @@ -25,6 +25,8 @@ interface AccountBalanceItemProps { accountIndex: string; } +const OBJECT_PER_REQ = 1; + export function AccountBalanceItem({ accounts, accountIndex, @@ -66,15 +68,15 @@ export function AccountBalanceItem({ { StructType: STARDUST_NFT_OUTPUT_TYPE }, ], }, - 1, + OBJECT_PER_REQ, ); return (ownedAssets && ownedAssets?.pages?.[0]?.data?.length > 0) ?? false; }); } - function hasSupplyIncreaseVestingObjects(): boolean { + function hasVestingObjects(): boolean { return accounts.some(({ address }) => { - const { data: supplyIncreaseVestingObjects } = useGetOwnedObjects( + const { data: vestingObjects } = useGetOwnedObjects( address, { MatchAny: [ @@ -82,18 +84,13 @@ export function AccountBalanceItem({ { StructType: TIMELOCK_STAKED_TYPE }, ], }, - 1, - ); - return ( - (supplyIncreaseVestingObjects && - supplyIncreaseVestingObjects?.pages?.[0]?.data?.length > 0) ?? - false + OBJECT_PER_REQ, ); + return (vestingObjects && vestingObjects?.pages?.[0]?.data?.length > 0) ?? false; }); } function hasMigrationObjects(): boolean { - const OBJECT_PER_REQ = 1; let containsMigrationObjects = false; return accounts.some(({ address }) => { const { data: stardustSharedBasicObjects } = useGetStardustSharedBasicObjects( @@ -113,7 +110,7 @@ export function AccountBalanceItem({ { StructType: STARDUST_NFT_OUTPUT_TYPE }, ], }, - 1, + OBJECT_PER_REQ, ); containsMigrationObjects = !!legacyObjects?.pages?.[0]?.data?.length; if (!legacyObjects || !containsMigrationObjects) { @@ -153,7 +150,7 @@ export function AccountBalanceItem({ {hasAccountAssets() && ( )} - {hasSupplyIncreaseVestingObjects() && ( + {hasVestingObjects() && ( )} {hasMigrationObjects() && ( From 37ccd0ca69a84e49cfad8456610815594c0753bd Mon Sep 17 00:00:00 2001 From: evavirseda Date: Fri, 31 Jan 2025 09:41:46 +0100 Subject: [PATCH 31/40] fix hooks error --- .../accounts/AccountBalanceItem.tsx | 122 +++++++++--------- 1 file changed, 58 insertions(+), 64 deletions(-) diff --git a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx index 35a52bc83e2..3eed74a4887 100644 --- a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx +++ b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx @@ -31,33 +31,14 @@ export function AccountBalanceItem({ accounts, accountIndex, }: AccountBalanceItemProps): JSX.Element { - function getAddressBalance(address: string): string { - const { data: balance } = useBalance(address, { - refetchInterval: false, - }); - const totalBalance = balance?.totalBalance || '0'; - const coinType = balance?.coinType; - const [formatted, symbol] = useFormatCoin(BigInt(totalBalance), coinType); - return `${formatted} ${symbol}`; - } + const balances = accounts.map(({ address }) => ({ + address, + balance: useBalance(address, { refetchInterval: false }).data, + })); - function getSumOfBalances(): string { - let coinType = ''; - const balance = accounts.reduce((acc, { address }) => { - const { data: balance } = useBalance(address, { - refetchInterval: false, - }); - const totalBalance = balance?.totalBalance || '0'; - coinType = balance?.coinType || ''; - return (BigInt(acc) + BigInt(totalBalance)).toString(); - }, '0'); - const [formatted, symbol] = useFormatCoin(BigInt(balance), coinType); - return `${formatted} ${symbol}`; - } - - function hasAccountAssets(): boolean { - return accounts.some(({ address }) => { - const { data: ownedAssets } = useGetOwnedObjects( + const ownedObjects = accounts.map( + ({ address }) => + useGetOwnedObjects( address, { MatchNone: [ @@ -69,14 +50,12 @@ export function AccountBalanceItem({ ], }, OBJECT_PER_REQ, - ); - return (ownedAssets && ownedAssets?.pages?.[0]?.data?.length > 0) ?? false; - }); - } + ).data, + ); - function hasVestingObjects(): boolean { - return accounts.some(({ address }) => { - const { data: vestingObjects } = useGetOwnedObjects( + const vestingObjects = accounts.map( + ({ address }) => + useGetOwnedObjects( address, { MatchAny: [ @@ -85,41 +64,56 @@ export function AccountBalanceItem({ ], }, OBJECT_PER_REQ, - ); - return (vestingObjects && vestingObjects?.pages?.[0]?.data?.length > 0) ?? false; - }); + ).data, + ); + + const migrationObjects = accounts.map(({ address }) => { + const stardustBasic = useGetStardustSharedBasicObjects(address, OBJECT_PER_REQ).data; + const stardustNft = useGetStardustSharedNftObjects(address, OBJECT_PER_REQ).data; + const legacy = useGetOwnedObjects( + address, + { + MatchAny: [ + { StructType: STARDUST_BASIC_OUTPUT_TYPE }, + { StructType: STARDUST_NFT_OUTPUT_TYPE }, + ], + }, + OBJECT_PER_REQ, + ).data; + return ( + !!legacy?.pages?.[0]?.data?.length || !!stardustBasic?.length || !!stardustNft?.length + ); + }); + + function getAddressBalance(address: string): string { + const balanceData = balances.find((b) => b.address === address)?.balance; + const totalBalance = balanceData?.totalBalance || '0'; + const coinType = balanceData?.coinType || ''; + const [formatted, symbol] = useFormatCoin(BigInt(totalBalance), coinType); + return `${formatted} ${symbol}`; } - function hasMigrationObjects(): boolean { - let containsMigrationObjects = false; - return accounts.some(({ address }) => { - const { data: stardustSharedBasicObjects } = useGetStardustSharedBasicObjects( - address || '', - OBJECT_PER_REQ, - ); - const { data: stardustSharedNftObjects } = useGetStardustSharedNftObjects( - address || '', - OBJECT_PER_REQ, - ); + function getSumOfBalances(): string { + let coinType = ''; + const balance = balances.reduce((acc, { balance }) => { + const totalBalance = balance?.totalBalance || '0'; + coinType = balance?.coinType || ''; + return (BigInt(acc) + BigInt(totalBalance)).toString(); + }, '0'); + const [formatted, symbol] = useFormatCoin(BigInt(balance), coinType); + return `${formatted} ${symbol}`; + } - const { data: legacyObjects } = useGetOwnedObjects( - address, - { - MatchAny: [ - { StructType: STARDUST_BASIC_OUTPUT_TYPE }, - { StructType: STARDUST_NFT_OUTPUT_TYPE }, - ], - }, - OBJECT_PER_REQ, - ); - containsMigrationObjects = !!legacyObjects?.pages?.[0]?.data?.length; - if (!legacyObjects || !containsMigrationObjects) { - containsMigrationObjects = - !!stardustSharedBasicObjects?.length || !!stardustSharedNftObjects?.length; - } + function hasAccountAssets(): boolean { + return ownedObjects.some((obj) => Boolean(obj?.pages?.[0]?.data?.length)); + } + + function hasVestingObjects(): boolean { + return vestingObjects.some((obj) => Boolean(obj?.pages?.[0]?.data?.length)); + } - return containsMigrationObjects; - }); + function hasMigrationObjects(): boolean { + return migrationObjects.some((mig) => mig); } return ( From 6eecee48dbdef07b05010eec6429c2082a9375a4 Mon Sep 17 00:00:00 2001 From: evavirseda Date: Fri, 31 Jan 2025 15:07:46 +0100 Subject: [PATCH 32/40] fixes --- .../accounts/AccountBalanceItem.tsx | 21 +++++++++---------- .../accounts-finder/AccountsFinderView.tsx | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx index 3eed74a4887..f3b87553953 100644 --- a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx +++ b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx @@ -19,6 +19,7 @@ import { TriangleDown } from '@iota/apps-ui-icons'; import clsx from 'clsx'; import { Badge, BadgeType } from '@iota/apps-ui-kit'; import { formatAddress } from '@iota/iota-sdk/utils'; +import { useMemo } from 'react'; interface AccountBalanceItemProps { accounts: SerializedUIAccount[]; @@ -104,17 +105,17 @@ export function AccountBalanceItem({ return `${formatted} ${symbol}`; } - function hasAccountAssets(): boolean { + const hasAccountAssets = useMemo(() => { return ownedObjects.some((obj) => Boolean(obj?.pages?.[0]?.data?.length)); - } + }, [ownedObjects]); - function hasVestingObjects(): boolean { + const hasVestingObjects = useMemo(() => { return vestingObjects.some((obj) => Boolean(obj?.pages?.[0]?.data?.length)); - } + }, [vestingObjects]); - function hasMigrationObjects(): boolean { + const hasMigrationObjects = useMemo(() => { return migrationObjects.some((mig) => mig); - } + }, [migrationObjects]); return ( {getSumOfBalances()}
- {hasAccountAssets() && ( - - )} - {hasVestingObjects() && ( + {hasAccountAssets && } + {hasVestingObjects && ( )} - {hasMigrationObjects() && ( + {hasMigrationObjects && ( )}
diff --git a/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx b/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx index 0fa319e6f15..e27f03a2278 100644 --- a/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx +++ b/apps/wallet/src/ui/app/pages/accounts/manage/accounts-finder/AccountsFinderView.tsx @@ -182,7 +182,7 @@ export function AccountsFinderView(): JSX.Element { text="Finish" disabled={isSearchOngoing} fullWidth - onClick={() => navigate('/')} + onClick={() => navigate('/tokens')} />
From d3a4e9a8178e7fc8947a310790e9b8487e1267f4 Mon Sep 17 00:00:00 2001 From: evavirseda Date: Mon, 3 Feb 2025 11:14:33 +0100 Subject: [PATCH 33/40] feat: add useGetOwnedObjectsMultipleAddr hook --- .../accounts/AccountBalanceItem.tsx | 80 ++++++++----------- apps/wallet/src/ui/app/hooks/index.ts | 1 + .../useGetOwnedObjectsMultipleAddresses.ts | 49 ++++++++++++ 3 files changed, 83 insertions(+), 47 deletions(-) create mode 100644 apps/wallet/src/ui/app/hooks/useGetOwnedObjectsMultipleAddresses.ts diff --git a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx index f3b87553953..9bfb6fcb865 100644 --- a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx +++ b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx @@ -11,7 +11,6 @@ import { TIMELOCK_STAKED_TYPE, useBalance, useFormatCoin, - useGetOwnedObjects, useGetStardustSharedBasicObjects, useGetStardustSharedNftObjects, } from '@iota/core'; @@ -20,6 +19,7 @@ import clsx from 'clsx'; import { Badge, BadgeType } from '@iota/apps-ui-kit'; import { formatAddress } from '@iota/iota-sdk/utils'; import { useMemo } from 'react'; +import { useGetOwnedObjectsMultipleAddresses } from '../../hooks'; interface AccountBalanceItemProps { accounts: SerializedUIAccount[]; @@ -32,59 +32,45 @@ export function AccountBalanceItem({ accounts, accountIndex, }: AccountBalanceItemProps): JSX.Element { + const addresses = accounts.map(({ address }) => address); + const balances = accounts.map(({ address }) => ({ address, balance: useBalance(address, { refetchInterval: false }).data, })); - const ownedObjects = accounts.map( - ({ address }) => - useGetOwnedObjects( - address, - { - MatchNone: [ - { StructType: COIN_TYPE }, - { StructType: TIMELOCK_IOTA_TYPE }, - { StructType: TIMELOCK_STAKED_TYPE }, - { StructType: STARDUST_BASIC_OUTPUT_TYPE }, - { StructType: STARDUST_NFT_OUTPUT_TYPE }, - ], - }, - OBJECT_PER_REQ, - ).data, + const { data: ownedObjects } = useGetOwnedObjectsMultipleAddresses( + addresses, + { + MatchNone: [ + { StructType: COIN_TYPE }, + { StructType: TIMELOCK_IOTA_TYPE }, + { StructType: TIMELOCK_STAKED_TYPE }, + { StructType: STARDUST_BASIC_OUTPUT_TYPE }, + { StructType: STARDUST_NFT_OUTPUT_TYPE }, + ], + }, + OBJECT_PER_REQ, ); - const vestingObjects = accounts.map( - ({ address }) => - useGetOwnedObjects( - address, - { - MatchAny: [ - { StructType: TIMELOCK_IOTA_TYPE }, - { StructType: TIMELOCK_STAKED_TYPE }, - ], - }, - OBJECT_PER_REQ, - ).data, + const { data: vestingObjects } = useGetOwnedObjectsMultipleAddresses( + addresses, + { + MatchAny: [{ StructType: TIMELOCK_IOTA_TYPE }, { StructType: TIMELOCK_STAKED_TYPE }], + }, + OBJECT_PER_REQ, ); - const migrationObjects = accounts.map(({ address }) => { - const stardustBasic = useGetStardustSharedBasicObjects(address, OBJECT_PER_REQ).data; - const stardustNft = useGetStardustSharedNftObjects(address, OBJECT_PER_REQ).data; - const legacy = useGetOwnedObjects( - address, - { - MatchAny: [ - { StructType: STARDUST_BASIC_OUTPUT_TYPE }, - { StructType: STARDUST_NFT_OUTPUT_TYPE }, - ], - }, - OBJECT_PER_REQ, - ).data; - return ( - !!legacy?.pages?.[0]?.data?.length || !!stardustBasic?.length || !!stardustNft?.length - ); - }); + const migrationObjects = useMemo(() => { + return addresses.map((address) => { + const stardustBasic = useGetStardustSharedBasicObjects(address, OBJECT_PER_REQ).data; + const stardustNft = useGetStardustSharedNftObjects(address, OBJECT_PER_REQ).data; + const legacy = ownedObjects?.pages?.some( + (obj) => obj[0]?.data[0]?.data?.owner === address, + ); + return !!legacy || !!stardustBasic?.length || !!stardustNft?.length; + }); + }, [addresses, ownedObjects]); function getAddressBalance(address: string): string { const balanceData = balances.find((b) => b.address === address)?.balance; @@ -106,11 +92,11 @@ export function AccountBalanceItem({ } const hasAccountAssets = useMemo(() => { - return ownedObjects.some((obj) => Boolean(obj?.pages?.[0]?.data?.length)); + return ownedObjects?.pages.some((obj) => Boolean(obj[0]?.data?.length)); }, [ownedObjects]); const hasVestingObjects = useMemo(() => { - return vestingObjects.some((obj) => Boolean(obj?.pages?.[0]?.data?.length)); + return vestingObjects?.pages.some((obj) => Boolean(obj[0]?.data?.length)); }, [vestingObjects]); const hasMigrationObjects = useMemo(() => { diff --git a/apps/wallet/src/ui/app/hooks/index.ts b/apps/wallet/src/ui/app/hooks/index.ts index 6ac1ac8378d..11f7bf6aaeb 100644 --- a/apps/wallet/src/ui/app/hooks/index.ts +++ b/apps/wallet/src/ui/app/hooks/index.ts @@ -37,3 +37,4 @@ export * from './useSigner'; export * from './useStorageMigrationStatus'; export * from './useUnlockMutation'; export * from './useUnlockedGuard'; +export * from './useGetOwnedObjectsMultipleAddresses'; diff --git a/apps/wallet/src/ui/app/hooks/useGetOwnedObjectsMultipleAddresses.ts b/apps/wallet/src/ui/app/hooks/useGetOwnedObjectsMultipleAddresses.ts new file mode 100644 index 00000000000..4919864882d --- /dev/null +++ b/apps/wallet/src/ui/app/hooks/useGetOwnedObjectsMultipleAddresses.ts @@ -0,0 +1,49 @@ +// Copyright (c) 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { useIotaClient } from '@iota/dapp-kit'; +import { type PaginatedObjectsResponse, type IotaObjectDataFilter } from '@iota/iota-sdk/client'; +import { useInfiniteQuery } from '@tanstack/react-query'; + +const MAX_OBJECTS_PER_REQ = 6; + +export function useGetOwnedObjectsMultipleAddresses( + addresses: string[], + filter?: IotaObjectDataFilter, + maxObjectRequests = MAX_OBJECTS_PER_REQ, +) { + const client = useIotaClient(); + + return useInfiniteQuery({ + initialPageParam: null, + queryKey: ['get-owned-objects', addresses, filter, maxObjectRequests], + queryFn: async ({ pageParam }) => { + try { + const responses = await Promise.all( + addresses.map((address) => + client.getOwnedObjects({ + owner: address, + filter, + options: { + showType: true, + showContent: true, + showDisplay: true, + }, + limit: maxObjectRequests, + cursor: pageParam as string | null, + }), + ), + ); + return responses.flat(); + } catch (error) { + return []; + } + }, + staleTime: 10 * 1000, + enabled: addresses.length > 0, + getNextPageParam: (lastPage) => { + const nextCursor = lastPage.find((res) => res.hasNextPage)?.nextCursor; + return nextCursor || null; + }, + }); +} From fa62fc220986df03889270984ab2c27bed66a45a Mon Sep 17 00:00:00 2001 From: evavirseda Date: Mon, 3 Feb 2025 15:11:23 +0100 Subject: [PATCH 34/40] fix error --- .../components/accounts/AccountBalanceItem.tsx | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx index 9bfb6fcb865..5bfc1d83155 100644 --- a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx +++ b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx @@ -61,16 +61,12 @@ export function AccountBalanceItem({ OBJECT_PER_REQ, ); - const migrationObjects = useMemo(() => { - return addresses.map((address) => { - const stardustBasic = useGetStardustSharedBasicObjects(address, OBJECT_PER_REQ).data; - const stardustNft = useGetStardustSharedNftObjects(address, OBJECT_PER_REQ).data; - const legacy = ownedObjects?.pages?.some( - (obj) => obj[0]?.data[0]?.data?.owner === address, - ); - return !!legacy || !!stardustBasic?.length || !!stardustNft?.length; - }); - }, [addresses, ownedObjects]); + const migrationObjects = addresses.map((address) => { + const stardustBasic = useGetStardustSharedBasicObjects(address, OBJECT_PER_REQ).data; + const stardustNft = useGetStardustSharedNftObjects(address, OBJECT_PER_REQ).data; + const legacy = ownedObjects?.pages?.some((obj) => obj[0]?.data[0]?.data?.owner === address); + return !!legacy || !!stardustBasic?.length || !!stardustNft?.length; + }); function getAddressBalance(address: string): string { const balanceData = balances.find((b) => b.address === address)?.balance; From 5536015273ac5371c4da522865ddb113ccb1eb6d Mon Sep 17 00:00:00 2001 From: evavirseda Date: Mon, 3 Feb 2025 17:16:53 +0100 Subject: [PATCH 35/40] fixes --- .../accounts/AccountBalanceItem.tsx | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx index 5bfc1d83155..50354eaf89c 100644 --- a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx +++ b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx @@ -61,11 +61,25 @@ export function AccountBalanceItem({ OBJECT_PER_REQ, ); + const { data: stardustOwnedObjects } = useGetOwnedObjectsMultipleAddresses( + addresses, + { + MatchAny: [ + { StructType: STARDUST_BASIC_OUTPUT_TYPE }, + { StructType: STARDUST_NFT_OUTPUT_TYPE }, + ], + }, + OBJECT_PER_REQ, + ); + const migrationObjects = addresses.map((address) => { - const stardustBasic = useGetStardustSharedBasicObjects(address, OBJECT_PER_REQ).data; - const stardustNft = useGetStardustSharedNftObjects(address, OBJECT_PER_REQ).data; - const legacy = ownedObjects?.pages?.some((obj) => obj[0]?.data[0]?.data?.owner === address); - return !!legacy || !!stardustBasic?.length || !!stardustNft?.length; + const stardustSharedBasic = useGetStardustSharedBasicObjects(address, OBJECT_PER_REQ).data; + const stardustSharedNft = useGetStardustSharedNftObjects(address, OBJECT_PER_REQ).data; + return ( + !!stardustOwnedObjects?.pages[0][0].data?.length || + !!stardustSharedBasic?.length || + !!stardustSharedNft?.length + ); }); function getAddressBalance(address: string): string { @@ -96,6 +110,7 @@ export function AccountBalanceItem({ }, [vestingObjects]); const hasMigrationObjects = useMemo(() => { + console.log('migrationObjects', migrationObjects); return migrationObjects.some((mig) => mig); }, [migrationObjects]); From c038748fcca5bb48f637954c92bc76193062a07a Mon Sep 17 00:00:00 2001 From: evavirseda Date: Mon, 3 Feb 2025 17:19:52 +0100 Subject: [PATCH 36/40] cleanup --- .../wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx index 50354eaf89c..e2b1a6bec98 100644 --- a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx +++ b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx @@ -110,7 +110,6 @@ export function AccountBalanceItem({ }, [vestingObjects]); const hasMigrationObjects = useMemo(() => { - console.log('migrationObjects', migrationObjects); return migrationObjects.some((mig) => mig); }, [migrationObjects]); From 2f469b5d2c8560f881790d800c6d520483823846 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Mon, 3 Feb 2025 17:21:35 +0100 Subject: [PATCH 37/40] fix(dashboard): add a optional chaining --- .../src/ui/app/components/accounts/AccountBalanceItem.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx index 50354eaf89c..23899ce87a1 100644 --- a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx +++ b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx @@ -76,7 +76,7 @@ export function AccountBalanceItem({ const stardustSharedBasic = useGetStardustSharedBasicObjects(address, OBJECT_PER_REQ).data; const stardustSharedNft = useGetStardustSharedNftObjects(address, OBJECT_PER_REQ).data; return ( - !!stardustOwnedObjects?.pages[0][0].data?.length || + !!stardustOwnedObjects?.pages?.[0]?.[0]?.data?.length || !!stardustSharedBasic?.length || !!stardustSharedNft?.length ); From 662b8623addcc47652a559c394f46de5a4625e60 Mon Sep 17 00:00:00 2001 From: evavirseda Date: Tue, 4 Feb 2025 12:28:22 +0100 Subject: [PATCH 38/40] feat: add new hook to get sharedobjects --- .../accounts/AccountBalanceItem.tsx | 100 ++++++++---------- apps/wallet/src/ui/app/hooks/index.ts | 1 + .../useGetSharedObjectsMultipleAddresses.ts | 64 +++++++++++ 3 files changed, 112 insertions(+), 53 deletions(-) create mode 100644 apps/wallet/src/ui/app/hooks/useGetSharedObjectsMultipleAddresses.ts diff --git a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx index 4d7c24c4204..915b1d78390 100644 --- a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx +++ b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx @@ -11,15 +11,15 @@ import { TIMELOCK_STAKED_TYPE, useBalance, useFormatCoin, - useGetStardustSharedBasicObjects, - useGetStardustSharedNftObjects, } from '@iota/core'; import { TriangleDown } from '@iota/apps-ui-icons'; import clsx from 'clsx'; import { Badge, BadgeType } from '@iota/apps-ui-kit'; import { formatAddress } from '@iota/iota-sdk/utils'; -import { useMemo } from 'react'; -import { useGetOwnedObjectsMultipleAddresses } from '../../hooks'; +import { + useGetOwnedObjectsMultipleAddresses, + useGetSharedObjectsMultipleAddresses, +} from '../../hooks'; interface AccountBalanceItemProps { accounts: SerializedUIAccount[]; @@ -34,10 +34,10 @@ export function AccountBalanceItem({ }: AccountBalanceItemProps): JSX.Element { const addresses = accounts.map(({ address }) => address); - const balances = accounts.map(({ address }) => ({ - address, - balance: useBalance(address, { refetchInterval: false }).data, - })); + // const balances = accounts.map(({ address }) => ({ + // address, + // balance: useBalance(address, { refetchInterval: false }).data, + // })); const { data: ownedObjects } = useGetOwnedObjectsMultipleAddresses( addresses, @@ -72,46 +72,29 @@ export function AccountBalanceItem({ OBJECT_PER_REQ, ); - const migrationObjects = addresses.map((address) => { - const stardustSharedBasic = useGetStardustSharedBasicObjects(address, OBJECT_PER_REQ).data; - const stardustSharedNft = useGetStardustSharedNftObjects(address, OBJECT_PER_REQ).data; - return ( - !!stardustOwnedObjects?.pages?.[0]?.[0]?.data?.length || - !!stardustSharedBasic?.length || - !!stardustSharedNft?.length - ); - }); - - function getAddressBalance(address: string): string { - const balanceData = balances.find((b) => b.address === address)?.balance; - const totalBalance = balanceData?.totalBalance || '0'; - const coinType = balanceData?.coinType || ''; - const [formatted, symbol] = useFormatCoin(BigInt(totalBalance), coinType); - return `${formatted} ${symbol}`; - } - - function getSumOfBalances(): string { - let coinType = ''; - const balance = balances.reduce((acc, { balance }) => { - const totalBalance = balance?.totalBalance || '0'; - coinType = balance?.coinType || ''; - return (BigInt(acc) + BigInt(totalBalance)).toString(); - }, '0'); - const [formatted, symbol] = useFormatCoin(BigInt(balance), coinType); - return `${formatted} ${symbol}`; - } - - const hasAccountAssets = useMemo(() => { - return ownedObjects?.pages.some((obj) => Boolean(obj[0]?.data?.length)); - }, [ownedObjects]); - - const hasVestingObjects = useMemo(() => { - return vestingObjects?.pages.some((obj) => Boolean(obj[0]?.data?.length)); - }, [vestingObjects]); - - const hasMigrationObjects = useMemo(() => { - return migrationObjects.some((mig) => mig); - }, [migrationObjects]); + const { data: stardustSharedObjects } = useGetSharedObjectsMultipleAddresses( + addresses, + OBJECT_PER_REQ, + ); + + const hasMigrationObjects = + !!stardustOwnedObjects?.pages?.[0]?.[0]?.data?.length || + !!stardustSharedObjects?.pages?.[0]?.length; + + const hasAccountAssets = !!ownedObjects?.pages?.[0]?.[0]?.data?.length; + + const hasVestingObjects = !!vestingObjects?.pages?.[0]?.[0]?.data?.length; + + // function getSumOfBalances(): string { + // let coinType = ''; + // const balance = balances.reduce((acc, { balance }) => { + // const totalBalance = balance?.totalBalance || '0'; + // coinType = balance?.coinType || ''; + // return (BigInt(acc) + BigInt(totalBalance)).toString(); + // }, '0'); + // const [formatted, symbol] = useFormatCoin(BigInt(balance), coinType); + // return `${formatted} ${symbol}`; + // } return (
- {getSumOfBalances()} + {/* {getSumOfBalances()} */}
{hasAccountAssets && } {hasVestingObjects && ( @@ -152,12 +135,23 @@ export function AccountBalanceItem({ >
{accounts.map(({ address, id }) => ( -
- {formatAddress(address)} - {getAddressBalance(address)} -
+ ))}
); } + +export function AddressItem({ address }: { address: string }): JSX.Element { + const { data: balance } = useBalance(address!); + const totalBalance = balance?.totalBalance || '0'; + const coinType = balance?.coinType || ''; + const [formatted, symbol] = useFormatCoin(BigInt(totalBalance), coinType); + + return ( +
+ {formatAddress(address)} + {`${formatted} ${symbol}`} +
+ ); +} diff --git a/apps/wallet/src/ui/app/hooks/index.ts b/apps/wallet/src/ui/app/hooks/index.ts index 11f7bf6aaeb..21291016385 100644 --- a/apps/wallet/src/ui/app/hooks/index.ts +++ b/apps/wallet/src/ui/app/hooks/index.ts @@ -38,3 +38,4 @@ export * from './useStorageMigrationStatus'; export * from './useUnlockMutation'; export * from './useUnlockedGuard'; export * from './useGetOwnedObjectsMultipleAddresses'; +export * from './useGetSharedObjectsMultipleAddresses'; diff --git a/apps/wallet/src/ui/app/hooks/useGetSharedObjectsMultipleAddresses.ts b/apps/wallet/src/ui/app/hooks/useGetSharedObjectsMultipleAddresses.ts new file mode 100644 index 00000000000..626f84f4c74 --- /dev/null +++ b/apps/wallet/src/ui/app/hooks/useGetSharedObjectsMultipleAddresses.ts @@ -0,0 +1,64 @@ +// Copyright (c) 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { useInfiniteQuery } from '@tanstack/react-query'; +import { + mapStardustBasicOutputs, + mapStardustNftOutputs, + useStardustIndexerClientContext, +} from '@iota/core'; + +const MAX_OBJECTS_PER_REQ = 6; + +export function useGetSharedObjectsMultipleAddresses( + addresses: string[], + pageSize: number = MAX_OBJECTS_PER_REQ, +) { + const { stardustIndexerClient } = useStardustIndexerClientContext(); + + return useInfiniteQuery({ + initialPageParam: { page: 1 }, + queryKey: ['get-shared-objects', addresses, pageSize, stardustIndexerClient?.baseUrl], + queryFn: async ({ pageParam }) => { + try { + const responses = await Promise.all( + addresses.map(async (address) => { + const nftOutputs = await stardustIndexerClient?.getNftResolvedOutputs( + address, + { + page: pageParam?.page, + pageSize, + }, + ); + + const basicOutputs = await stardustIndexerClient?.getBasicResolvedOutputs( + address, + { + page: pageParam?.page, + pageSize, + }, + ); + + return { + address, + nftOutputs: nftOutputs ? nftOutputs.map(mapStardustNftOutputs) : [], + basicOutputs: basicOutputs + ? basicOutputs.map(mapStardustBasicOutputs) + : [], + }; + }), + ); + + return responses; + } catch (error) { + return []; + } + }, + staleTime: 10 * 1000, + enabled: addresses.length > 0, + getNextPageParam: (lastPage) => { + const nextPage = lastPage.find((res) => res.nftOutputs.length === pageSize); + return nextPage ? { page: lastPage.length + 1 } : null; + }, + }); +} From da0fc6adc3a5b7942edbc7b901e33e37928fb607 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Tue, 4 Feb 2025 16:17:27 +0100 Subject: [PATCH 39/40] refactor: Grouped fetch of addresses balances --- apps/core/src/hooks/useFormatCoin.ts | 18 ++++--- .../accounts/AccountBalanceItem.tsx | 52 +++++++++++++------ 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/apps/core/src/hooks/useFormatCoin.ts b/apps/core/src/hooks/useFormatCoin.ts index 49e713d4608..70214573632 100644 --- a/apps/core/src/hooks/useFormatCoin.ts +++ b/apps/core/src/hooks/useFormatCoin.ts @@ -64,14 +64,7 @@ export function useCoinMetadata(coinType?: string | null) { // Optimize the known case of IOTA to avoid a network call: if (coinType === IOTA_TYPE_ARG) { - const metadata: CoinMetadata = { - id: null, - decimals: 9, - description: '', - iconUrl: null, - name: 'IOTA', - symbol: 'IOTA', - }; + const metadata: CoinMetadata = IOTA_COIN_METADATA; return metadata; } @@ -100,6 +93,15 @@ export function useCoinMetadata(coinType?: string | null) { }); } +export const IOTA_COIN_METADATA: CoinMetadata = { + id: null, + decimals: 9, + description: '', + iconUrl: null, + name: 'IOTA', + symbol: 'IOTA', +}; + // TODO #1: This handles undefined values to make it easier to integrate with // the reset of the app as it is today, but it really shouldn't in a perfect world. export function useFormatCoin( diff --git a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx index 915b1d78390..e39fc70e23f 100644 --- a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx +++ b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx @@ -5,6 +5,8 @@ import { type SerializedUIAccount } from '_src/background/accounts/account'; import { COIN_TYPE, Collapsible, + formatBalance, + IOTA_COIN_METADATA, STARDUST_BASIC_OUTPUT_TYPE, STARDUST_NFT_OUTPUT_TYPE, TIMELOCK_IOTA_TYPE, @@ -15,11 +17,13 @@ import { import { TriangleDown } from '@iota/apps-ui-icons'; import clsx from 'clsx'; import { Badge, BadgeType } from '@iota/apps-ui-kit'; -import { formatAddress } from '@iota/iota-sdk/utils'; +import { formatAddress, IOTA_TYPE_ARG } from '@iota/iota-sdk/utils'; import { useGetOwnedObjectsMultipleAddresses, useGetSharedObjectsMultipleAddresses, } from '../../hooks'; +import { useQuery, useQueryClient } from '@tanstack/react-query'; +import { useIotaClientContext } from '@iota/dapp-kit'; interface AccountBalanceItemProps { accounts: SerializedUIAccount[]; @@ -34,10 +38,35 @@ export function AccountBalanceItem({ }: AccountBalanceItemProps): JSX.Element { const addresses = accounts.map(({ address }) => address); - // const balances = accounts.map(({ address }) => ({ - // address, - // balance: useBalance(address, { refetchInterval: false }).data, - // })); + const queryClient = useQueryClient(); + const iotaContext = useIotaClientContext(); + + const { data: getSumOfBalances } = useQuery({ + queryKey: ['getBalance', ...addresses], + async queryFn() { + return await Promise.all( + addresses.map(async (address) => { + const params = { + coinType: IOTA_TYPE_ARG, + owner: address!, + }; + return queryClient.ensureQueryData({ + queryKey: [iotaContext.network, 'getBalance'], + queryFn: () => iotaContext.client.getBalance(params), + }); + }), + ); + }, + select(balances) { + const balance = balances.reduce((acc, { totalBalance }) => { + return BigInt(acc) + BigInt(totalBalance); + }, BigInt(0)); + const [formatted, symbol] = formatBalance(balance, IOTA_COIN_METADATA.decimals); + return `${formatted} ${symbol}`; + }, + gcTime: 0, + staleTime: 0, + }); const { data: ownedObjects } = useGetOwnedObjectsMultipleAddresses( addresses, @@ -85,17 +114,6 @@ export function AccountBalanceItem({ const hasVestingObjects = !!vestingObjects?.pages?.[0]?.[0]?.data?.length; - // function getSumOfBalances(): string { - // let coinType = ''; - // const balance = balances.reduce((acc, { balance }) => { - // const totalBalance = balance?.totalBalance || '0'; - // coinType = balance?.coinType || ''; - // return (BigInt(acc) + BigInt(totalBalance)).toString(); - // }, '0'); - // const [formatted, symbol] = useFormatCoin(BigInt(balance), coinType); - // return `${formatted} ${symbol}`; - // } - return (
- {/* {getSumOfBalances()} */} + {getSumOfBalances}
{hasAccountAssets && } {hasVestingObjects && ( From 37dd82d581a0bb2f2925b655c5efc9d3e1920df9 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Tue, 4 Feb 2025 16:24:41 +0100 Subject: [PATCH 40/40] rename var --- .../src/ui/app/components/accounts/AccountBalanceItem.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx index e39fc70e23f..12065187e25 100644 --- a/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx +++ b/apps/wallet/src/ui/app/components/accounts/AccountBalanceItem.tsx @@ -41,7 +41,7 @@ export function AccountBalanceItem({ const queryClient = useQueryClient(); const iotaContext = useIotaClientContext(); - const { data: getSumOfBalances } = useQuery({ + const { data: sumOfBalances } = useQuery({ queryKey: ['getBalance', ...addresses], async queryFn() { return await Promise.all( @@ -137,7 +137,7 @@ export function AccountBalanceItem({
- {getSumOfBalances} + {sumOfBalances}
{hasAccountAssets && } {hasVestingObjects && (