From 1b66742d6f08f7871a6a1a5331c6171cfcb18057 Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Wed, 12 Jul 2023 09:49:09 +0200 Subject: [PATCH 01/48] feat: Point iota/wallet dependency to iota/sdk --- packages/shared/package.json | 2 +- yarn.lock | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/shared/package.json b/packages/shared/package.json index ede6849c055..3ab753d6654 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -11,7 +11,7 @@ "@iota/transaction-converter": "^1.0.0-beta.30", "@iota/unit-converter": "^1.0.0-beta.30", "@iota/util.js": "^2.0.0-rc.1", - "@iota/wallet": "2.0.3-rc.42", + "@iota/wallet": "npm:@iota/sdk@1.0.0-rc.2", "@sveltejs/svelte-virtual-list": "^3.0.1", "big-integer": "^1.6.51", "big.js": "^6.0.3", diff --git a/yarn.lock b/yarn.lock index 748d1666adb..27b99538c45 100644 --- a/yarn.lock +++ b/yarn.lock @@ -888,7 +888,7 @@ resolved "https://registry.yarnpkg.com/@iota/types/-/types-2.0.0-rc.2.tgz#a4b8e5c3423a2afd322fc05ebfaa6b27587d9a96" integrity sha512-huL+171zMQgGYV4/zhHLFcE8heTLRJhtlqLEJaM1Q+klb2KxNqFX0EySU8pxZ/nslh0Dem3QQ+Jmwv1FdBmpFQ== -"@iota/types@^1.0.0-beta.15", "@iota/types@^1.0.0-beta.9": +"@iota/types@^1.0.0-beta.9": version "1.0.0-beta.15" resolved "https://registry.yarnpkg.com/@iota/types/-/types-1.0.0-beta.15.tgz#1a1f5722ef176a45d03e92f4cb5bd9a4ea74ec27" integrity sha512-67DrzDO5bl2c7RIMpOdtjdOa27Bv1EmX/BHPTQD8c3RtPPAzJpSIpuI8JsIDl3U6Qe4zdLX3kRv9zGBXcr0fZA== @@ -915,14 +915,16 @@ dependencies: big-integer "^1.6.51" -"@iota/wallet@2.0.3-rc.42": - version "2.0.3-rc.42" - resolved "https://registry.yarnpkg.com/@iota/wallet/-/wallet-2.0.3-rc.42.tgz#62373ba2dca09a9d6a0358ae2580e89f88d1f353" - integrity sha512-w3M0B/KLDYyYP0C72rHgc1KQ+WN21RDdFldapVbGDgtWyDuQN/XiXC90hPDvr8G8++V9d2nQ0gnxfSvpfsgOPQ== +"@iota/wallet@npm:@iota/sdk@1.0.0-rc.2": + version "1.0.0-rc.2" + resolved "https://registry.yarnpkg.com/@iota/sdk/-/sdk-1.0.0-rc.2.tgz#e776b5c9f54c211403399f32f6b456976e0251b6" + integrity sha512-xu4zMjPQFITX5ewoixuYBcn551C/G0DvBn0gl/K7UJMMUK5GfXp6BpwmhR1AcW7py654mgGzL4JX1xfORAtrTg== dependencies: - "@iota/types" "^1.0.0-beta.15" + "@types/node" "^18.15.12" cargo-cp-artifact "^0.1.6" + class-transformer "^0.5.1" prebuild-install "^7.1.1" + reflect-metadata "^0.1.13" typescript "^4.9.4" "@isaacs/cliui@^8.0.2": @@ -1800,7 +1802,7 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.38.tgz#1dcdb6c54d02b323f621213745f2e44af30c73e6" integrity sha512-6sfo1qTulpVbkxECP+AVrHV9OoJqhzCsfTNp5NIG+enM4HyM3HvZCO798WShIXBN0+QtDIcutJCjsVYnQP5rIQ== -"@types/node@^18.15.11": +"@types/node@^18.15.11", "@types/node@^18.15.12": version "18.16.19" resolved "https://registry.yarnpkg.com/@types/node/-/node-18.16.19.tgz#cb03fca8910fdeb7595b755126a8a78144714eea" integrity sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA== @@ -2944,6 +2946,11 @@ cjs-module-lexer@^1.0.0: resolved "https://registry.yarnpkg.com/cjs-module-lexer/-/cjs-module-lexer-1.2.3.tgz#6c370ab19f8a3394e318fe682686ec0ac684d107" integrity sha512-0TNiGstbQmCFwt4akjjBg5pLRTSyj/PkWQ1ZoO2zntmg9yLqSRxwEa4iCfQLGjqhiqBfOJa7W/E8wfGrTDmlZQ== +class-transformer@^0.5.1: + version "0.5.1" + resolved "https://registry.yarnpkg.com/class-transformer/-/class-transformer-0.5.1.tgz#24147d5dffd2a6cea930a3250a677addf96ab336" + integrity sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw== + clean-stack@^2.0.0: version "2.2.0" resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b" @@ -7318,6 +7325,11 @@ rechoir@^0.8.0: dependencies: resolve "^1.20.0" +reflect-metadata@^0.1.13: + version "0.1.13" + resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.13.tgz#67ae3ca57c972a2aa1642b10fe363fe32d49dc08" + integrity sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg== + regexp-tree@~0.1.1: version "0.1.27" resolved "https://registry.yarnpkg.com/regexp-tree/-/regexp-tree-0.1.27.tgz#2198f0ef54518ffa743fe74d983b56ffd631b6cd" From fbd06170b3f9f4e2850da74f202966c01837ae7c Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Wed, 12 Jul 2023 10:53:31 +0200 Subject: [PATCH 02/48] chore: Fix AddressBalance -> Balance & MintNativeTokenParams -> CreateNativeTokenParams --- .../governance/actions/registerParticipationEvent.ts | 4 ++-- .../onboarding/helpers/restoreBackupByCopyingFile.ts | 4 ++-- .../account/interfaces/account-state.interface.ts | 2 +- .../lib/core/account/interfaces/account.interface.ts | 11 ++--------- .../lib/tests/__mocks__/account-balance.mock.ts | 1 + 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/packages/shared/lib/contexts/governance/actions/registerParticipationEvent.ts b/packages/shared/lib/contexts/governance/actions/registerParticipationEvent.ts index 80e6b3c5255..4526c61a804 100644 --- a/packages/shared/lib/contexts/governance/actions/registerParticipationEvent.ts +++ b/packages/shared/lib/contexts/governance/actions/registerParticipationEvent.ts @@ -1,5 +1,5 @@ import type { - Node, + INode, ParticipationEventWithNodes, ParticipationEventId, ParticipationEventRegistrationOptions, @@ -10,7 +10,7 @@ import { createProposalFromEvent } from '@contexts/governance' export async function registerParticipationEvent( eventId: ParticipationEventId, - node: Node, + node: INode, account: IAccountState ): Promise { const options: ParticipationEventRegistrationOptions = { diff --git a/packages/shared/lib/contexts/onboarding/helpers/restoreBackupByCopyingFile.ts b/packages/shared/lib/contexts/onboarding/helpers/restoreBackupByCopyingFile.ts index 319512469b2..0797d4fbfd4 100644 --- a/packages/shared/lib/contexts/onboarding/helpers/restoreBackupByCopyingFile.ts +++ b/packages/shared/lib/contexts/onboarding/helpers/restoreBackupByCopyingFile.ts @@ -1,6 +1,6 @@ import { get, Writable } from 'svelte/store' -import { ClientOptions } from '@iota/wallet' +import { IClientOptions } from '@iota/wallet' import { ClientError, CLIENT_ERROR_REGEXES } from '@core/error' import { IProfileManager } from '@core/profile-manager' @@ -12,7 +12,7 @@ export async function restoreBackupByCopyingFile( importFilePath: string, storageDirectory: string, strongholdPassword: string, - clientOptions: ClientOptions, + clientOptions: IClientOptions, manager: Writable ): Promise { try { diff --git a/packages/shared/lib/core/account/interfaces/account-state.interface.ts b/packages/shared/lib/core/account/interfaces/account-state.interface.ts index 52b36e258d4..2874660e2b4 100644 --- a/packages/shared/lib/core/account/interfaces/account-state.interface.ts +++ b/packages/shared/lib/core/account/interfaces/account-state.interface.ts @@ -1,6 +1,6 @@ import { Balance } from '@iota/wallet' -import { IAccount } from './account.interface' import { IPersistedAccountData } from './persisted-account-data.interface' +import { IAccount } from './account.interface' export interface IAccountState extends IAccount, IPersistedAccountData { index: number diff --git a/packages/shared/lib/core/account/interfaces/account.interface.ts b/packages/shared/lib/core/account/interfaces/account.interface.ts index 701d2abae96..ddb86206769 100644 --- a/packages/shared/lib/core/account/interfaces/account.interface.ts +++ b/packages/shared/lib/core/account/interfaces/account.interface.ts @@ -1,12 +1,3 @@ -import type { - HexEncodedAmount, - HexEncodedString, - IAliasOutput, - IBasicOutput, - IFoundryOutput, - INftOutput, - OutputTypes, -} from '@iota/types' import type { AccountMetadata, Address, @@ -23,7 +14,9 @@ import type { Ed25519Signature, FilterOptions, GenerateAddressOptions, + CreateNativeTokenParams, MintNftParams, + MintTokenTransaction, Node, OutputData, OutputParams, diff --git a/packages/shared/lib/tests/__mocks__/account-balance.mock.ts b/packages/shared/lib/tests/__mocks__/account-balance.mock.ts index c0e0a84660c..ee61b8d40da 100644 --- a/packages/shared/lib/tests/__mocks__/account-balance.mock.ts +++ b/packages/shared/lib/tests/__mocks__/account-balance.mock.ts @@ -4,6 +4,7 @@ export const MOCK_ACCOUNT_BALANCE: Balance = { baseCoin: { total: '10000', available: '9000', + votingPower: '0', }, aliases: [], foundries: [], From f74a531df4349b11ef3befdec72f6336373f0251 Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Wed, 12 Jul 2023 11:02:04 +0200 Subject: [PATCH 03/48] chore: Migrate Node > INode, MintTokenTransaction > CreateNativeTokenTransaction, SendAmountParams > SendParams --- .../shared/lib/core/account/interfaces/account.interface.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/shared/lib/core/account/interfaces/account.interface.ts b/packages/shared/lib/core/account/interfaces/account.interface.ts index ddb86206769..9a8244b21e0 100644 --- a/packages/shared/lib/core/account/interfaces/account.interface.ts +++ b/packages/shared/lib/core/account/interfaces/account.interface.ts @@ -16,8 +16,8 @@ import type { GenerateAddressOptions, CreateNativeTokenParams, MintNftParams, - MintTokenTransaction, - Node, + CreateNativeTokenTransaction, + INode, OutputData, OutputParams, OutputsToClaim, From d6b6fdc7f6815980b6996223e75cae42dad6be6f Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Wed, 12 Jul 2023 11:32:47 +0200 Subject: [PATCH 04/48] chore: Fix a couple of type sources --- .../core/account/interfaces/persisted-account-data.interface.ts | 2 +- packages/shared/lib/core/account/utils/sumTotalFromOutputs.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/shared/lib/core/account/interfaces/persisted-account-data.interface.ts b/packages/shared/lib/core/account/interfaces/persisted-account-data.interface.ts index b03dd4cd773..f11719b4651 100644 --- a/packages/shared/lib/core/account/interfaces/persisted-account-data.interface.ts +++ b/packages/shared/lib/core/account/interfaces/persisted-account-data.interface.ts @@ -1,4 +1,4 @@ -import { ParticipationEventId } from '@iota/wallet/types' +import { ParticipationEventId } from '@iota/wallet' export interface IPersistedAccountData { name: string diff --git a/packages/shared/lib/core/account/utils/sumTotalFromOutputs.ts b/packages/shared/lib/core/account/utils/sumTotalFromOutputs.ts index 0618ef97d75..f2146e2d6e1 100644 --- a/packages/shared/lib/core/account/utils/sumTotalFromOutputs.ts +++ b/packages/shared/lib/core/account/utils/sumTotalFromOutputs.ts @@ -1,4 +1,4 @@ -import { OutputData } from '@iota/wallet/types/output' +import { OutputData } from '@iota/wallet' export function sumTotalFromOutputs(outputs: OutputData[]): number { return outputs?.reduce((total: number, outputData: OutputData) => (total += Number(outputData?.output?.amount)), 0) From 17402665bbd9859f0c247d67a49de4b25c499f1e Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Wed, 12 Jul 2023 11:43:06 +0200 Subject: [PATCH 05/48] chore: Fix ClientOptions > IClientOptions (rename firefly IClientOptions > ClientOptions to fix collision) --- .../shared/lib/core/network/actions/updateClientOptions.ts | 6 +++--- .../lib/core/network/interfaces/client-options.interface.ts | 4 ++-- .../lib/core/network/utils/getDefaultClientOptions.ts | 4 ++-- .../shared/lib/core/profile-manager/api/setClientOptions.ts | 4 ++-- .../profile-manager/types/profile-manager-options.type.ts | 4 ++-- .../core/profile/interfaces/persisted-profile.interface.ts | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/shared/lib/core/network/actions/updateClientOptions.ts b/packages/shared/lib/core/network/actions/updateClientOptions.ts index 42f90ace47e..0647626765c 100644 --- a/packages/shared/lib/core/network/actions/updateClientOptions.ts +++ b/packages/shared/lib/core/network/actions/updateClientOptions.ts @@ -1,4 +1,4 @@ -import { IClientOptions } from '@core/network' +import { ClientOptions } from '@core/network' import { activeProfile, updateActiveProfile } from '@core/profile' import { setClientOptions } from '@core/profile-manager' import { get } from 'svelte/store' @@ -8,12 +8,12 @@ import { get } from 'svelte/store' * * @method updateClientOptions * - * @param {Partial} clientOptions + * @param {Partial} clientOptions * * @returns {void} */ -export function updateClientOptions(clientOptionsToUpdate: Partial): Promise { +export function updateClientOptions(clientOptionsToUpdate: Partial): Promise { const currentClientOptions = get(activeProfile)?.clientOptions const clientOptions = { ...currentClientOptions, ...clientOptionsToUpdate } if (clientOptions?.nodes || clientOptions?.primaryNode) { diff --git a/packages/shared/lib/core/network/interfaces/client-options.interface.ts b/packages/shared/lib/core/network/interfaces/client-options.interface.ts index 1b1dac4693c..0635b14cc94 100644 --- a/packages/shared/lib/core/network/interfaces/client-options.interface.ts +++ b/packages/shared/lib/core/network/interfaces/client-options.interface.ts @@ -1,8 +1,8 @@ -import { ClientOptions } from '@iota/wallet' +import { IClientOptions } from '@iota/wallet' import { INode } from './node.interface' -export interface IClientOptions extends Omit { +export interface ClientOptions extends Omit { primaryNode?: INode nodes?: INode[] localPow?: boolean diff --git a/packages/shared/lib/core/network/utils/getDefaultClientOptions.ts b/packages/shared/lib/core/network/utils/getDefaultClientOptions.ts index 6fa41f6c2ab..ae006a9dea7 100644 --- a/packages/shared/lib/core/network/utils/getDefaultClientOptions.ts +++ b/packages/shared/lib/core/network/utils/getDefaultClientOptions.ts @@ -1,8 +1,8 @@ import { NetworkId } from '../enums' -import { IClientOptions } from '../interfaces' +import { ClientOptions } from '../interfaces' import { getOfficialNodes } from './getOfficialNodes' -export function getDefaultClientOptions(networkId: NetworkId): IClientOptions { +export function getDefaultClientOptions(networkId: NetworkId): ClientOptions { const nodes = getOfficialNodes(networkId) return { nodes } } diff --git a/packages/shared/lib/core/profile-manager/api/setClientOptions.ts b/packages/shared/lib/core/profile-manager/api/setClientOptions.ts index 4dccfb6f2fa..2ff3c51c82f 100644 --- a/packages/shared/lib/core/profile-manager/api/setClientOptions.ts +++ b/packages/shared/lib/core/profile-manager/api/setClientOptions.ts @@ -1,8 +1,8 @@ -import { IClientOptions } from '@core/network' +import { ClientOptions } from '@core/network' import { get } from 'svelte/store' import { profileManager } from '../stores' -export async function setClientOptions(clientOptions: Partial): Promise { +export async function setClientOptions(clientOptions: Partial): Promise { const manager = get(profileManager) await manager.setClientOptions(clientOptions) } diff --git a/packages/shared/lib/core/profile-manager/types/profile-manager-options.type.ts b/packages/shared/lib/core/profile-manager/types/profile-manager-options.type.ts index 86fceb914ef..427ea5bc3d6 100644 --- a/packages/shared/lib/core/profile-manager/types/profile-manager-options.type.ts +++ b/packages/shared/lib/core/profile-manager/types/profile-manager-options.type.ts @@ -1,6 +1,6 @@ -import { IClientOptions } from '@core/network/interfaces' +import { ClientOptions } from '@core/network/interfaces' import { AccountManagerOptions } from '@iota/wallet' export type ProfileManagerOptions = Omit & { - clientOptions: IClientOptions + clientOptions: ClientOptions } diff --git a/packages/shared/lib/core/profile/interfaces/persisted-profile.interface.ts b/packages/shared/lib/core/profile/interfaces/persisted-profile.interface.ts index 272c1184058..ee765dc2627 100644 --- a/packages/shared/lib/core/profile/interfaces/persisted-profile.interface.ts +++ b/packages/shared/lib/core/profile/interfaces/persisted-profile.interface.ts @@ -1,5 +1,5 @@ import { IPersistedAccountData } from '@core/account' -import { IClientOptions, IPersistedNetwork } from '@core/network' +import { ClientOptions, IPersistedNetwork } from '@core/network' import { INft } from '@core/nfts' import { StrongholdVersion } from '@core/stronghold/enums' import { ProfileType } from '../enums' @@ -18,7 +18,7 @@ export interface IPersistedProfile { isDeveloperProfile: boolean hasVisitedDashboard?: boolean lastUsedAccountIndex?: number - clientOptions: IClientOptions + clientOptions: ClientOptions forceAssetRefresh: boolean strongholdVersion: StrongholdVersion pfp?: INft From 26fe1f69eb77a864684394a3276188fc294d26e4 Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Wed, 12 Jul 2023 12:05:00 +0200 Subject: [PATCH 06/48] chore: Migrate EventType > WalletEventType --- packages/shared/lib/tests/__mocks__/profile-manager.mock.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/shared/lib/tests/__mocks__/profile-manager.mock.ts b/packages/shared/lib/tests/__mocks__/profile-manager.mock.ts index eaf2e94cbbd..237fb91a124 100644 --- a/packages/shared/lib/tests/__mocks__/profile-manager.mock.ts +++ b/packages/shared/lib/tests/__mocks__/profile-manager.mock.ts @@ -8,6 +8,7 @@ import type { WalletEvent, LedgerNanoStatus, GenerateAddressOptions, + INode, } from '@iota/wallet' import { WalletEventType } from '@iota/wallet/out/types' From 37143417db47eb881c46a4ee220caef0526e2ece Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Wed, 12 Jul 2023 12:18:08 +0200 Subject: [PATCH 07/48] chore: Migrate AccountManagerOptions > WalletOptions --- .../actions/initialiseProfileManager.ts | 12 ++++++++---- .../core/profile-manager/interfaces/api.interface.ts | 5 +++-- .../types/profile-manager-options.type.ts | 4 ++-- packages/shared/lib/tests/__mocks__/api.mock.ts | 4 ++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/shared/lib/core/profile-manager/actions/initialiseProfileManager.ts b/packages/shared/lib/core/profile-manager/actions/initialiseProfileManager.ts index 0b2d30e2731..18f8548606f 100644 --- a/packages/shared/lib/core/profile-manager/actions/initialiseProfileManager.ts +++ b/packages/shared/lib/core/profile-manager/actions/initialiseProfileManager.ts @@ -1,4 +1,4 @@ -import { ClientOptions, CoinType, SecretManager } from '@iota/wallet' +import { IClientOptions, CoinType, SecretManager } from '@iota/wallet' import { generateRandomId } from '@core/utils' @@ -8,7 +8,7 @@ import { IProfileManager } from '../interfaces' export async function initialiseProfileManager( storagePath: string, coinType: CoinType, - clientOptions?: ClientOptions, + clientOptions?: IClientOptions, secretManager?: SecretManager, id?: string ): Promise { @@ -16,9 +16,13 @@ export async function initialiseProfileManager( const profileManager = await api.createAccountManager(id, { storagePath, - ...(clientOptions && (clientOptions?.nodes?.length > 0 || clientOptions?.primaryNode) && { clientOptions }), + // TODO-sdk is this the right fix for the line ? + // ...(clientOptions && (clientOptions?.nodes?.length > 0 || clientOptions?.primaryNode) && { clientOptions }), + ...clientOptions, coinType, - ...(secretManager && { secretManager }), + // TODO-sdk is this the right fix for the line ? + // ...(secretManager && { secretManager }), + ...secretManager, }) return profileManager } diff --git a/packages/shared/lib/core/profile-manager/interfaces/api.interface.ts b/packages/shared/lib/core/profile-manager/interfaces/api.interface.ts index d71c417506c..18cd3915c64 100644 --- a/packages/shared/lib/core/profile-manager/interfaces/api.interface.ts +++ b/packages/shared/lib/core/profile-manager/interfaces/api.interface.ts @@ -1,4 +1,4 @@ -import { AccountManagerOptions, CreateAccountPayload } from '@iota/wallet' +import { WalletOptions, CreateAccountPayload } from '@iota/wallet' import { IAccount } from '@core/account' @@ -6,7 +6,8 @@ import { IProfileManager } from './profile-manager.interface' import { RecoverAccountsPayload } from './recover-account-payload.interface' export interface IApi { - createAccountManager(id: string, options: AccountManagerOptions): Promise + // TODO-sdk: These should be renamed to createWallet etc... to match naming in sdk + createAccountManager(id: string, options: WalletOptions): Promise createAccount(managerId: string, payload: CreateAccountPayload): Promise deleteAccountManager(id: string): void getAccount(profileManagerId: string, index: number): Promise diff --git a/packages/shared/lib/core/profile-manager/types/profile-manager-options.type.ts b/packages/shared/lib/core/profile-manager/types/profile-manager-options.type.ts index 427ea5bc3d6..73ff0b5818d 100644 --- a/packages/shared/lib/core/profile-manager/types/profile-manager-options.type.ts +++ b/packages/shared/lib/core/profile-manager/types/profile-manager-options.type.ts @@ -1,6 +1,6 @@ import { ClientOptions } from '@core/network/interfaces' -import { AccountManagerOptions } from '@iota/wallet' +import { WalletOptions } from '@iota/wallet' -export type ProfileManagerOptions = Omit & { +export type ProfileManagerOptions = Omit & { clientOptions: ClientOptions } diff --git a/packages/shared/lib/tests/__mocks__/api.mock.ts b/packages/shared/lib/tests/__mocks__/api.mock.ts index 58b97ff7504..7c17f8d9842 100644 --- a/packages/shared/lib/tests/__mocks__/api.mock.ts +++ b/packages/shared/lib/tests/__mocks__/api.mock.ts @@ -1,7 +1,7 @@ import { AccountMock } from './account.mock' import { ProfileManagerMock } from './profile-manager.mock' -import { AccountManagerOptions, CreateAccountPayload } from '@iota/wallet' +import { WalletOptions, CreateAccountPayload } from '@iota/wallet' import { IApi, RecoverAccountsPayload } from '@core/profile-manager' import { IAccount } from '@core/account' @@ -9,7 +9,7 @@ import { IAccount } from '@core/account' const profileManagers = {} const api: IApi = { - async createAccountManager(id: string, _: AccountManagerOptions): Promise { + async createAccountManager(id: string, _: WalletOptions): Promise { const manager = new ProfileManagerMock(id) profileManagers[id] = manager From 29c6593507b482ff6cb7de0f414ed9ab914233f8 Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Wed, 12 Jul 2023 15:46:54 +0200 Subject: [PATCH 08/48] chore: Migrate to iota/sdk models (remove @iota/types) pass 1 --- .../governance/utils/isParticipationOutput.ts | 16 ++++++---- .../lib/core/nfts/interfaces/nft.interface.ts | 4 +-- .../core/nfts/utils/buildNftFromNftOutput.ts | 10 +++--- .../getSpendableStatusFromUnspentNftOutput.ts | 12 +++---- packages/shared/lib/core/utils/filter.ts | 13 +++----- .../setOutgoingAsyncActivitiesToClaimed.ts | 5 ++- .../wallet/constants/output-type.constants.ts | 1 + .../constants/unlock-condition.constants.ts | 1 + .../interfaces/wrapped-output.interface.ts | 3 +- .../shared/lib/core/wallet/types/index.ts | 1 - .../lib/core/wallet/types/output.type.ts | 3 -- .../generateActivity/generateActivities.ts | 16 +++------- .../generateActivitiesFromBasicOutputs.ts | 30 +++++++++-------- .../generateActivitiesFromNftOutputs.ts | 12 +++---- .../generateSingleAliasActivity.ts | 10 +++--- .../generateSingleBasicActivity.ts | 6 ++-- .../generateSingleConsolidationActivity.ts | 7 ++-- .../generateSingleGovernanceActivity.ts | 4 +-- .../generateSingleNftActivity.ts | 6 ++-- .../helper/getActivityTypeFromOutput.ts | 12 +++---- .../helper/getGovernanceInfo.ts | 2 +- .../getGovernorAddressFromAliasOutput.ts | 15 +++++---- .../helper/getMetadataFromOutput.ts | 16 ++++++---- ...etStateControllerAddressFromAliasOutput.ts | 15 +++++---- .../helper/getStorageDepositFromOutput.ts | 13 ++++---- .../helper/getTimelockDateFromOutput.ts | 12 ++++--- .../utils/getBech32AddressFromAddressTypes.ts | 19 ++++++----- .../utils/getMetadataFromFoundryOutput.ts | 16 +++++----- .../core/wallet/utils/outputs/getFoundryId.ts | 32 +++++++++---------- .../utils/outputs/getIssuerFromNftOutput.ts | 11 ++++--- .../utils/outputs/getMetadataFromNftOutput.ts | 13 ++++---- .../utils/outputs/preprocessGroupedOutputs.ts | 29 ++++++++--------- .../activityOutputContainsValue.ts | 4 +-- 33 files changed, 181 insertions(+), 188 deletions(-) delete mode 100644 packages/shared/lib/core/wallet/types/output.type.ts diff --git a/packages/shared/lib/contexts/governance/utils/isParticipationOutput.ts b/packages/shared/lib/contexts/governance/utils/isParticipationOutput.ts index 03c7c7d161d..89dea20179b 100644 --- a/packages/shared/lib/contexts/governance/utils/isParticipationOutput.ts +++ b/packages/shared/lib/contexts/governance/utils/isParticipationOutput.ts @@ -1,10 +1,14 @@ -import type { ITagFeature } from '@iota/types' - -import { FEATURE_TYPE_TAG, Output } from '@core/wallet' - import { PARTICIPATE_TAG_HEX } from '../constants' +import { CommonOutput, FeatureType, Output, OutputType, TagFeature } from '@iota/wallet' export function isParticipationOutput(output: Output): boolean { - const outputFeature = output?.features?.find((feature) => feature.type === FEATURE_TYPE_TAG) - return outputFeature?.tag === PARTICIPATE_TAG_HEX + if (output.getType() === OutputType.Treasury) { + return false + } + + const commonOutput = output as CommonOutput + const outputFeature = ( + commonOutput?.getFeatures()?.find((feature) => feature.getType() === FeatureType.Tag) + ) + return outputFeature?.getTag() === PARTICIPATE_TAG_HEX } diff --git a/packages/shared/lib/core/nfts/interfaces/nft.interface.ts b/packages/shared/lib/core/nfts/interfaces/nft.interface.ts index e2de874d300..b3378724937 100644 --- a/packages/shared/lib/core/nfts/interfaces/nft.interface.ts +++ b/packages/shared/lib/core/nfts/interfaces/nft.interface.ts @@ -1,4 +1,4 @@ -import { AddressTypes } from '@iota/types' +import { Address } from '@iota/wallet' import { NftDownloadMetadata, IIrc27Metadata } from '../interfaces' export interface INft { @@ -6,7 +6,7 @@ export interface INft { address: string name: string metadata?: string - issuer?: AddressTypes + issuer?: Address parsedMetadata?: IIrc27Metadata isSpendable: boolean timelockTime: number diff --git a/packages/shared/lib/core/nfts/utils/buildNftFromNftOutput.ts b/packages/shared/lib/core/nfts/utils/buildNftFromNftOutput.ts index 5f20f24f313..a44b1f86680 100644 --- a/packages/shared/lib/core/nfts/utils/buildNftFromNftOutput.ts +++ b/packages/shared/lib/core/nfts/utils/buildNftFromNftOutput.ts @@ -6,7 +6,6 @@ import { getNftId, } from '@core/wallet/utils' import { IWrappedOutput } from '@core/wallet/interfaces' -import type { INftOutput } from '@iota/types' import { get } from 'svelte/store' import { DEFAULT_NFT_NAME } from '../constants' import { INft } from '../interfaces' @@ -14,16 +13,17 @@ import { parseNftMetadata } from './parseNftMetadata' import { composeUrlFromNftUri } from './composeUrlFromNftUri' import { getSpendableStatusFromUnspentNftOutput } from './getSpendableStatusFromUnspentNftOutput' import { ADDRESS_TYPE_NFT } from '@core/wallet/constants' +import { NftOutput } from '@iota/wallet' export function buildNftFromNftOutput( wrappedOutput: IWrappedOutput, accountAddress: string, calculateStatus: boolean = true ): INft { - const nftOutput = wrappedOutput.output as INftOutput + const nftOutput = wrappedOutput.output as NftOutput let isSpendable = false - let timeLockTime = undefined + let timeLockTime: number | undefined = undefined if (calculateStatus) { const status = getSpendableStatusFromUnspentNftOutput(accountAddress, nftOutput) @@ -31,14 +31,14 @@ export function buildNftFromNftOutput( timeLockTime = status.timeLockTime } - const id = getNftId(nftOutput.nftId, wrappedOutput.outputId) + const id = getNftId(nftOutput.getNftId(), wrappedOutput.outputId) const address = getBech32AddressFromAddressTypes({ type: ADDRESS_TYPE_NFT, nftId: id }) const issuer = getIssuerFromNftOutput(nftOutput) const metadata = getMetadataFromNftOutput(nftOutput) const parsedMetadata = parseNftMetadata(metadata) const composedUrl = composeUrlFromNftUri(parsedMetadata?.uri) const filePath = `${get(activeProfileId)}/nfts/${id}` - const storageDeposit = Number(nftOutput.amount) + const storageDeposit = Number(nftOutput.getAmount()) return { id, diff --git a/packages/shared/lib/core/nfts/utils/getSpendableStatusFromUnspentNftOutput.ts b/packages/shared/lib/core/nfts/utils/getSpendableStatusFromUnspentNftOutput.ts index 6ee62732f71..345f48d1355 100644 --- a/packages/shared/lib/core/nfts/utils/getSpendableStatusFromUnspentNftOutput.ts +++ b/packages/shared/lib/core/nfts/utils/getSpendableStatusFromUnspentNftOutput.ts @@ -1,12 +1,12 @@ import { UNLOCK_CONDITION_STORAGE_DEPOSIT_RETURN } from '@core/wallet/constants' import { getExpirationUnixTimeFromOutput, getRecipientAddressFromOutput, isOutputAsync } from '@core/wallet/utils' import { getTimelockDateFromOutput } from '@core/wallet/utils/generateActivity/helper' -import { INftOutput } from '@iota/types' +import { NftOutput } from '@iota/wallet' export function getSpendableStatusFromUnspentNftOutput( accountAddress: string, - nftOutput: INftOutput -): { isSpendable: boolean; timeLockTime: string } { + nftOutput: NftOutput +): { isSpendable: boolean; timeLockTime: number | undefined } { let isSpendable = true let timeLockTime = undefined @@ -15,9 +15,9 @@ export function getSpendableStatusFromUnspentNftOutput( const expirationUnixTime = getExpirationUnixTimeFromOutput(nftOutput) const timeLockUnixTime = getTimelockDateFromOutput(nftOutput)?.getTime() const isRecipient = getRecipientAddressFromOutput(nftOutput) === accountAddress - const hasStorageDepositReturnUnlockCondition = nftOutput.unlockConditions.some( - (unlockCondition) => unlockCondition?.type === UNLOCK_CONDITION_STORAGE_DEPOSIT_RETURN - ) + const hasStorageDepositReturnUnlockCondition = nftOutput + .getUnlockConditions() + .some((unlockCondition) => unlockCondition?.getType() === UNLOCK_CONDITION_STORAGE_DEPOSIT_RETURN) if (expirationUnixTime) { if (isRecipient) { isSpendable = false diff --git a/packages/shared/lib/core/utils/filter.ts b/packages/shared/lib/core/utils/filter.ts index 19291f1cdb6..3e1b2457ac8 100644 --- a/packages/shared/lib/core/utils/filter.ts +++ b/packages/shared/lib/core/utils/filter.ts @@ -1,18 +1,15 @@ -import { OutputData } from '@iota/wallet/types/output' -import { IBasicOutput } from '@iota/types' - -import { OUTPUT_TYPE_BASIC } from '@core/wallet' +import { BasicOutput, OutputData, OutputType } from '@iota/wallet' export function filterBasicOutput(outputData: OutputData): boolean { - return outputData?.output?.type === OUTPUT_TYPE_BASIC + return outputData?.output?.getType() === OutputType.Basic } export function filterShimmerClaimingOutputs(outputData: OutputData): boolean { - const output = outputData?.output as IBasicOutput + const output = outputData?.output as BasicOutput const isBasicOutput = filterBasicOutput(outputData) - const hasOneUnlockCondition = output?.unlockConditions?.length === 1 - const hasNoNativeTokens = !output?.nativeTokens || output?.nativeTokens?.length === 0 + const hasOneUnlockCondition = output?.getUnlockConditions()?.length === 1 + const hasNoNativeTokens = !output?.getNativeTokens() || output?.getNativeTokens()?.length === 0 return isBasicOutput && hasOneUnlockCondition && hasNoNativeTokens } diff --git a/packages/shared/lib/core/wallet/actions/setOutgoingAsyncActivitiesToClaimed.ts b/packages/shared/lib/core/wallet/actions/setOutgoingAsyncActivitiesToClaimed.ts index f944f857bd7..c02b6d2a07c 100644 --- a/packages/shared/lib/core/wallet/actions/setOutgoingAsyncActivitiesToClaimed.ts +++ b/packages/shared/lib/core/wallet/actions/setOutgoingAsyncActivitiesToClaimed.ts @@ -1,6 +1,5 @@ import { IAccountState } from '@core/account' -import { IBasicOutput } from '@iota/types' -import { OutputData } from '@iota/wallet' +import { BasicOutput, OutputData } from '@iota/wallet' import { MILLISECONDS_PER_SECOND } from '@core/utils' import { get } from 'svelte/store' import { ActivityAsyncStatus, ActivityDirection } from '../enums' @@ -31,7 +30,7 @@ export async function setOutgoingAsyncActivitiesToClaimed(account: IAccountState } function isOutputClaimed(output: OutputData): boolean { - const expirationDate = getExpirationDateFromOutput(output?.output as IBasicOutput) + const expirationDate = getExpirationDateFromOutput(output?.output as BasicOutput) if (expirationDate) { return ( diff --git a/packages/shared/lib/core/wallet/constants/output-type.constants.ts b/packages/shared/lib/core/wallet/constants/output-type.constants.ts index 234587b7dea..aa45c344ead 100644 --- a/packages/shared/lib/core/wallet/constants/output-type.constants.ts +++ b/packages/shared/lib/core/wallet/constants/output-type.constants.ts @@ -1,3 +1,4 @@ +// TODO-sdk this should be gone (switch to OutputTypes.Basic etc...) export const OUTPUT_TYPE_TREASURY = 2 export const OUTPUT_TYPE_BASIC = 3 export const OUTPUT_TYPE_ALIAS = 4 diff --git a/packages/shared/lib/core/wallet/constants/unlock-condition.constants.ts b/packages/shared/lib/core/wallet/constants/unlock-condition.constants.ts index 9cb9608640c..9936de35334 100644 --- a/packages/shared/lib/core/wallet/constants/unlock-condition.constants.ts +++ b/packages/shared/lib/core/wallet/constants/unlock-condition.constants.ts @@ -1,3 +1,4 @@ +// TODO-sdk this should be gone (switch to iota/sdk etc...) export const UNLOCK_CONDITION_ADDRESS = 0 export const UNLOCK_CONDITION_STORAGE_DEPOSIT_RETURN = 1 export const UNLOCK_CONDITION_TIMELOCK = 2 diff --git a/packages/shared/lib/core/wallet/interfaces/wrapped-output.interface.ts b/packages/shared/lib/core/wallet/interfaces/wrapped-output.interface.ts index e769028dfc0..cf856286ddc 100644 --- a/packages/shared/lib/core/wallet/interfaces/wrapped-output.interface.ts +++ b/packages/shared/lib/core/wallet/interfaces/wrapped-output.interface.ts @@ -1,5 +1,4 @@ -import { OutputData } from '@iota/wallet' -import { Output } from '../types' +import { Output, OutputData } from '@iota/wallet' export interface IWrappedOutput extends Omit, 'output'> { outputId: string diff --git a/packages/shared/lib/core/wallet/types/index.ts b/packages/shared/lib/core/wallet/types/index.ts index 7d5f6c7136d..44340de0211 100644 --- a/packages/shared/lib/core/wallet/types/index.ts +++ b/packages/shared/lib/core/wallet/types/index.ts @@ -1,6 +1,5 @@ export * from './activity.type' export * from './asset-verification.type' -export * from './output.type' export * from './sender-info.type' export * from './subject.type' export * from './activities' diff --git a/packages/shared/lib/core/wallet/types/output.type.ts b/packages/shared/lib/core/wallet/types/output.type.ts deleted file mode 100644 index bebe6303b72..00000000000 --- a/packages/shared/lib/core/wallet/types/output.type.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { IAliasOutput, IBasicOutput, IFoundryOutput, INftOutput } from '@iota/types' - -export type Output = IBasicOutput | INftOutput | IAliasOutput | IFoundryOutput diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/generateActivities.ts b/packages/shared/lib/core/wallet/utils/generateActivity/generateActivities.ts index 594795327dc..10f80fd9424 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/generateActivities.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/generateActivities.ts @@ -1,12 +1,5 @@ import { IAccountState } from '@core/account' -import { - ActivityAction, - ActivityType, - IProcessedTransaction, - OUTPUT_TYPE_ALIAS, - OUTPUT_TYPE_FOUNDRY, - OUTPUT_TYPE_NFT, -} from '@core/wallet' +import { ActivityAction, ActivityType, IProcessedTransaction } from '@core/wallet' import { Activity } from '@core/wallet/types' import { isParticipationOutput } from '@contexts/governance/utils' import { generateSingleAliasActivity } from './generateSingleAliasActivity' @@ -19,6 +12,7 @@ import { generateActivitiesFromNftOutputs } from './generateActivitiesFromNftOut import { generateActivitiesFromAliasOutputs } from './generateActivitiesFromAliasOutputs' import { generateActivitiesFromFoundryOutputs } from './generateActivitiesFromFoundryOutputs' import { generateActivitiesFromBasicOutputs } from './generateActivitiesFromBasicOutputs' +import { OutputType } from '@iota/wallet' export async function generateActivities( processedTransaction: IProcessedTransaction, @@ -38,20 +32,20 @@ async function generateActivitiesFromProcessedTransactionsWithInputs( const { outputs, wrappedInputs } = processedTransaction const activities: Activity[] = [] - const containsFoundryActivity = outputs.some((output) => output.output.type === OUTPUT_TYPE_FOUNDRY) + const containsFoundryActivity = outputs.some((output) => output.output.getType() === OutputType.Foundry) if (containsFoundryActivity) { const foundryActivities = await generateActivitiesFromFoundryOutputs(processedTransaction, account) activities.push(...foundryActivities) } - const containsNftActivity = outputs.some((output) => output.output.type === OUTPUT_TYPE_NFT) + const containsNftActivity = outputs.some((output) => output.output.getType() === OutputType.Nft) if (containsNftActivity) { const nftActivities = await generateActivitiesFromNftOutputs(processedTransaction, account) activities.push(...nftActivities) } const containsAliasActivity = - outputs.some((output) => output.output.type === OUTPUT_TYPE_ALIAS) && !containsFoundryActivity + outputs.some((output) => output.output.getType() === OutputType.Alias) && !containsFoundryActivity if (containsAliasActivity) { const aliasActivities = await generateActivitiesFromAliasOutputs(processedTransaction, account) activities.push(...aliasActivities) diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/generateActivitiesFromBasicOutputs.ts b/packages/shared/lib/core/wallet/utils/generateActivity/generateActivitiesFromBasicOutputs.ts index 67782b88799..00665aa57fb 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/generateActivitiesFromBasicOutputs.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/generateActivitiesFromBasicOutputs.ts @@ -7,14 +7,12 @@ import { getNonRemainderBasicOutputsFromTransaction, IProcessedTransaction, IWrappedOutput, - OUTPUT_TYPE_BASIC, - OUTPUT_TYPE_NFT, } from '@core/wallet' import { Activity } from '@core/wallet/types' -import { INftOutput } from '@iota/types' import { generateSingleBasicActivity } from './generateSingleBasicActivity' import { generateSingleConsolidationActivity } from './generateSingleConsolidationActivity' import { generateSingleNftActivity } from './generateSingleNftActivity' +import { NftOutput, OutputType } from '@iota/wallet' export async function generateActivitiesFromBasicOutputs( processedTransaction: IProcessedTransaction, @@ -33,14 +31,14 @@ export async function generateActivitiesFromBasicOutputs( const isSelfTransaction = processedTransaction.direction === ActivityDirection.SelfTransaction const burnedNftInputIndex = burnedNftInputs.findIndex( - (input) => input.output.amount === basicOutput.output.amount + (input) => input.output.getAmount() === basicOutput.output.getAmount() ) const burnedNativeToken = burnedNftInputIndex < 0 ? getBurnedNativeTokens(basicOutput, processedTransaction) : undefined if (isSelfTransaction && burnedNftInputIndex >= 0) { const wrappedInput = burnedNftInputs[burnedNftInputIndex] - const nftInput = wrappedInput.output as INftOutput + const nftInput = wrappedInput.output as NftOutput activity = await generateSingleNftActivity( account, { @@ -48,7 +46,7 @@ export async function generateActivitiesFromBasicOutputs( processedTransaction, wrappedOutput: basicOutput, }, - getNftId(nftInput.nftId, wrappedInput.outputId) + getNftId(nftInput.getNftId(), wrappedInput.outputId) ) const nft = buildNftFromNftOutput(wrappedInput, account.depositAddress, false) addOrUpdateNftInAllAccountNfts(account.index, nft) @@ -86,12 +84,14 @@ export async function generateActivitiesFromBasicOutputs( function getBurnedNftInputs(processedTransaction: IProcessedTransaction): IWrappedOutput[] { return processedTransaction.wrappedInputs.filter((wrappedInput) => { const input = wrappedInput.output - if (input.type === OUTPUT_TYPE_NFT) { - const nftId = getNftId(input.nftId, wrappedInput.outputId) + if (input.getType() === OutputType.Nft) { + const nftInput = input as NftOutput + const nftId = getNftId(nftInput.getNftId(), wrappedInput.outputId) const isIncludedInOutputs = processedTransaction.outputs.some((output) => { - if (output.output.type === OUTPUT_TYPE_NFT) { - return getNftId(output.output.nftId, output.outputId) === nftId + if (output.output.getType() === OutputType.Nft) { + const nftOutput = output.output as NftOutput + return getNftId(nftOutput.getNftId(), output.outputId) === nftId } else { return false } @@ -131,7 +131,7 @@ function getBurnedNativeTokens( function getAllNativeTokensFromOutputs(outputs: IWrappedOutput[]): { [key: string]: number } { const nativeTokens: { [key: string]: number } = {} for (const output of outputs) { - for (const nativeToken of output.output.nativeTokens ?? []) { + for (const nativeToken of output.output.getNativeTokens() ?? []) { if (!nativeTokens[nativeToken.id]) { nativeTokens[nativeToken.id] = 0 } @@ -142,11 +142,13 @@ function getAllNativeTokensFromOutputs(outputs: IWrappedOutput[]): { [key: strin } function isConsolidation(output: IWrappedOutput, processedTransaction: IProcessedTransaction): boolean { - const allBasicInputs = processedTransaction.wrappedInputs.every((input) => input.output.type === OUTPUT_TYPE_BASIC) + const allBasicInputs = processedTransaction.wrappedInputs.every( + (input) => input.output.getType() === OutputType.Basic + ) const isSelfTransaction = processedTransaction.direction === ActivityDirection.SelfTransaction const isSameAmount = - processedTransaction.wrappedInputs.reduce((sum, input) => sum + Number(input.output.amount), 0) === - Number(output.output.amount) + processedTransaction.wrappedInputs.reduce((sum, input) => sum + Number(input.output.getAmount()), 0) === + Number(output.output.getAmount()) return allBasicInputs && isSelfTransaction && isSameAmount } diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/generateActivitiesFromNftOutputs.ts b/packages/shared/lib/core/wallet/utils/generateActivity/generateActivitiesFromNftOutputs.ts index 5c6c109e15c..1dc29452397 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/generateActivitiesFromNftOutputs.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/generateActivitiesFromNftOutputs.ts @@ -1,8 +1,8 @@ import { IAccountState } from '@core/account' -import { ActivityAction, EMPTY_HEX_ID, IProcessedTransaction, OUTPUT_TYPE_NFT } from '@core/wallet' -import { Activity } from '@core/wallet/types' -import type { INftOutput } from '@iota/types' +import { ActivityAction, EMPTY_HEX_ID, IProcessedTransaction } from '@core/wallet' +import { Activity } from '@core/wallet' import { generateSingleNftActivity } from './generateSingleNftActivity' +import { NftOutput, OutputType } from '@iota/wallet' export async function generateActivitiesFromNftOutputs( processedTransaction: IProcessedTransaction, @@ -11,11 +11,11 @@ export async function generateActivitiesFromNftOutputs( const outputs = processedTransaction.outputs const activities = [] - const nftOutputs = outputs.filter((output) => output.output.type === OUTPUT_TYPE_NFT) + const nftOutputs = outputs.filter((output) => output.output.getType() === OutputType.Nft) for (const nftOutput of nftOutputs) { - const output = nftOutput.output as INftOutput + const output = nftOutput.output as NftOutput const activity = await generateSingleNftActivity(account, { - action: output.nftId === EMPTY_HEX_ID ? ActivityAction.Mint : ActivityAction.Send, + action: output.getNftId() === EMPTY_HEX_ID ? ActivityAction.Mint : ActivityAction.Send, processedTransaction, wrappedOutput: nftOutput, }) diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleAliasActivity.ts b/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleAliasActivity.ts index a509f315504..f3cef75ddd9 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleAliasActivity.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleAliasActivity.ts @@ -3,7 +3,6 @@ import { ADDRESS_TYPE_ALIAS, EMPTY_HEX_ID } from '@core/wallet/constants' import { ActivityType } from '@core/wallet/enums' import { IActivityGenerationParameters } from '@core/wallet/interfaces' import { AliasActivity } from '@core/wallet/types' -import { IAliasOutput } from '@iota/types' import { convertHexAddressToBech32, hashOutputId } from '..' import { getAmountFromOutput, @@ -15,6 +14,7 @@ import { getStorageDepositFromOutput, getTagFromOutput, } from './helper' +import { AliasOutput } from '@iota/wallet' export async function generateSingleAliasActivity( account: IAccountState, @@ -22,7 +22,7 @@ export async function generateSingleAliasActivity( ): Promise { const { transactionId, claimingData, direction, time, inclusionState } = processedTransaction - const output = wrappedOutput.output as IAliasOutput + const output = wrappedOutput.output as AliasOutput const outputId = wrappedOutput.outputId const id = outputId || transactionId @@ -65,8 +65,8 @@ export async function generateSingleAliasActivity( } } -function getAliasId(output: IAliasOutput, outputId: string): string { - const isNewAlias = output.aliasId === EMPTY_HEX_ID - const aliasId = isNewAlias ? hashOutputId(outputId) : output.aliasId +function getAliasId(output: AliasOutput, outputId: string): string { + const isNewAlias = output.getAliasId() === EMPTY_HEX_ID + const aliasId = isNewAlias ? hashOutputId(outputId) : output.getAliasId() return convertHexAddressToBech32(ADDRESS_TYPE_ALIAS, aliasId) } diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleBasicActivity.ts b/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleBasicActivity.ts index d95ff0c6092..32ed0b6c1bf 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleBasicActivity.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleBasicActivity.ts @@ -3,7 +3,6 @@ import { IAccountState } from '@core/account' import { activeProfileId, getCoinType } from '@core/profile' import { IActivityGenerationParameters } from '@core/wallet/interfaces' import { TransactionActivity } from '@core/wallet/types' -import { IBasicOutput } from '@iota/types' import { get } from 'svelte/store' import { activityOutputContainsValue, getNativeTokenFromOutput } from '..' import { ActivityAction, ActivityType } from '../../enums' @@ -16,6 +15,7 @@ import { getStorageDepositFromOutput, getTagFromOutput, } from './helper' +import { BasicOutput } from '@iota/wallet' export async function generateSingleBasicActivity( account: IAccountState, @@ -32,7 +32,7 @@ export async function generateSingleBasicActivity( const outputId = wrappedOutput.outputId const id = outputId || transactionId - const output = wrappedOutput.output as IBasicOutput + const output = wrappedOutput.output as BasicOutput const isShimmerClaiming = isShimmerClaimingTransaction(transactionId, get(activeProfileId)) @@ -58,7 +58,7 @@ export async function generateSingleBasicActivity( let surplus: number | undefined = undefined if (nativeToken) { const storageDepositToDeduct = (storageDeposit > 0 ? storageDeposit : giftedStorageDeposit) ?? 0 - surplus = Number(output.amount) - storageDepositToDeduct + surplus = Number(output.getAmount()) - storageDepositToDeduct } let rawAmount: number diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleConsolidationActivity.ts b/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleConsolidationActivity.ts index 06dd9e35899..d786d0a05df 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleConsolidationActivity.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleConsolidationActivity.ts @@ -1,7 +1,6 @@ import { IAccountState } from '@core/account' import { IActivityGenerationParameters, IWrappedOutput } from '@core/wallet/interfaces' import { ConsolidationActivity } from '@core/wallet/types' -import { IBasicOutput } from '@iota/types' import { ActivityType } from '../../enums' import { activityOutputContainsValue } from '..' import { @@ -11,7 +10,7 @@ import { getStorageDepositFromOutput, getTagFromOutput, } from './helper' -import { OUTPUT_TYPE_BASIC } from '@core/wallet/constants' +import { BasicOutput, OutputType } from '@iota/wallet' export async function generateSingleConsolidationActivity( account: IAccountState, @@ -26,7 +25,7 @@ export async function generateSingleConsolidationActivity( const outputId = wrappedOutput.outputId const id = outputId || transactionId - const output = wrappedOutput.output as IBasicOutput + const output = wrappedOutput.output as BasicOutput const amountConsolidatedInputs = getAmountOfConsolidationInputs(wrappedInputs) @@ -60,5 +59,5 @@ export async function generateSingleConsolidationActivity( } function getAmountOfConsolidationInputs(inputs: IWrappedOutput[]): number { - return inputs.filter((input) => input.output.type === OUTPUT_TYPE_BASIC).length + return inputs.filter((input) => input.output.getType() === OutputType.Basic).length } diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleGovernanceActivity.ts b/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleGovernanceActivity.ts index b5b5f3e0d83..a2be0c8ac48 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleGovernanceActivity.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleGovernanceActivity.ts @@ -1,7 +1,6 @@ import { IAccountState } from '@core/account' import { IActivityGenerationParameters } from '@core/wallet/interfaces' import { GovernanceActivity } from '@core/wallet/types' -import type { IBasicOutput } from '@iota/types' import { ActivityType } from '../../enums' import { activityOutputContainsValue } from '..' import { @@ -12,6 +11,7 @@ import { getStorageDepositFromOutput, getTagFromOutput, } from './helper' +import { BasicOutput } from '@iota/wallet' export async function generateSingleGovernanceActivity( account: IAccountState, @@ -26,7 +26,7 @@ export async function generateSingleGovernanceActivity( const outputId = wrappedOutput.outputId const id = outputId || transactionId - const output = wrappedOutput.output as IBasicOutput + const output = wrappedOutput.output as BasicOutput const tag = getTagFromOutput(output) const metadata = getMetadataFromOutput(output) diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleNftActivity.ts b/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleNftActivity.ts index 62f27efa24b..70912605d3a 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleNftActivity.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/generateSingleNftActivity.ts @@ -3,7 +3,6 @@ import { handleError } from '@core/error/handlers' import { ActivityAction, ActivityType } from '@core/wallet/enums' import { IActivityGenerationParameters } from '@core/wallet/interfaces' import { NftActivity } from '@core/wallet/types' -import type { INftOutput } from '@iota/types' import { getNftId } from '../outputs/getNftId' import { getAsyncDataFromOutput, @@ -13,6 +12,7 @@ import { getStorageDepositFromOutput, getTagFromOutput, } from './helper' +import { NftOutput } from '@iota/wallet' export async function generateSingleNftActivity( account: IAccountState, @@ -21,14 +21,14 @@ export async function generateSingleNftActivity( ): Promise { const { claimingData, time, inclusionState, transactionId, direction } = processedTransaction const outputId = wrappedOutput.outputId - const output = wrappedOutput.output as INftOutput + const output = wrappedOutput.output as NftOutput const id = outputId || transactionId const isHidden = false const isAssetHidden = false const containsValue = true - const nftId = nftIdFromInput ? nftIdFromInput : getNftId(output.nftId, outputId) + const nftId = nftIdFromInput ? nftIdFromInput : getNftId(output.getNftId(), outputId) const metadata = getMetadataFromOutput(output) const tag = getTagFromOutput(output) diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getActivityTypeFromOutput.ts b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getActivityTypeFromOutput.ts index 2a5a04d89ad..f26e925fdc6 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getActivityTypeFromOutput.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getActivityTypeFromOutput.ts @@ -1,17 +1,17 @@ import { isParticipationOutput } from '@contexts/governance/utils' -import { OUTPUT_TYPE_ALIAS, OUTPUT_TYPE_BASIC, OUTPUT_TYPE_FOUNDRY, OUTPUT_TYPE_NFT } from '@core/wallet/constants' import { ActivityType } from '@core/wallet/enums' import { IWrappedOutput } from '@core/wallet/interfaces' +import { OutputType } from '@iota/wallet' export function getActivityTypeFromOutput(output: IWrappedOutput): ActivityType { - switch (output.output.type) { - case OUTPUT_TYPE_NFT: + switch (output.output.getType()) { + case OutputType.Nft: return ActivityType.Nft - case OUTPUT_TYPE_ALIAS: + case OutputType.Alias: return ActivityType.Alias - case OUTPUT_TYPE_FOUNDRY: + case OutputType.Foundry: return ActivityType.Foundry - case OUTPUT_TYPE_BASIC: + case OutputType.Basic: if (isParticipationOutput(output.output)) { return ActivityType.Governance } else { diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getGovernanceInfo.ts b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getGovernanceInfo.ts index 501565d5c9e..c29800a9b2f 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getGovernanceInfo.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getGovernanceInfo.ts @@ -1,10 +1,10 @@ import { isParticipationOutput } from '@contexts/governance/utils' import { GovernanceAction } from '@core/wallet/enums' import { IParticipation, IWrappedOutput } from '@core/wallet/interfaces' -import { Output } from '@core/wallet/types' import { parseGovernanceMetadata } from '../../parseGovernanceMetadata' import { getAmountFromOutput } from './getAmountFromOutput' import { getMetadataFromOutput } from './getMetadataFromOutput' +import { Output } from '@iota/wallet' interface IGovernanceInfo { governanceAction: GovernanceAction diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getGovernorAddressFromAliasOutput.ts b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getGovernorAddressFromAliasOutput.ts index fc738d6585c..cd36df72b0d 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getGovernorAddressFromAliasOutput.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getGovernorAddressFromAliasOutput.ts @@ -1,10 +1,11 @@ -import { UNLOCK_CONDITION_GOVERNOR_ADDRESS } from '@core/wallet/constants' -import { IGovernorAddressUnlockCondition, IAliasOutput } from '@iota/types' import { getBech32AddressFromAddressTypes } from '../../getBech32AddressFromAddressTypes' +import { AliasOutput, GovernorAddressUnlockCondition, UnlockConditionType } from '@iota/wallet' -export function getGovernorAddressFromAliasOutput(output: IAliasOutput): string { - const governorUnlockCondition = output.unlockConditions.find( - (unlockCondition) => unlockCondition.type === UNLOCK_CONDITION_GOVERNOR_ADDRESS - ) as IGovernorAddressUnlockCondition - return getBech32AddressFromAddressTypes(governorUnlockCondition.address) +export function getGovernorAddressFromAliasOutput(output: AliasOutput): string { + const governorUnlockCondition = output + .getUnlockConditions() + .find( + (unlockCondition) => unlockCondition.getType() === UnlockConditionType.GovernorAddress + ) as GovernorAddressUnlockCondition + return getBech32AddressFromAddressTypes(governorUnlockCondition.getAddress()) } diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getMetadataFromOutput.ts b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getMetadataFromOutput.ts index 5378a9d2903..bad1abd4fdc 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getMetadataFromOutput.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getMetadataFromOutput.ts @@ -1,16 +1,20 @@ import type { IMetadataFeature } from '@iota/types' import { isParticipationOutput } from '@contexts/governance/utils' import { EXTERNALLY_OWNED_ACCOUNT } from '@core/layer-2/constants' -import { containsControlCharacters, Converter } from '@core/utils' -import type { Output } from '@core/wallet/types' - -import { FEATURE_TYPE_METADATA } from '../../../constants' import { parseLayer2MetadataForTransfer } from '@core/layer-2/utils' +import { containsControlCharacters, Converter } from '@core/utils' +import { CommonOutput, FeatureType, MetadataFeature, Output, OutputType } from '@iota/wallet' export function getMetadataFromOutput(output: Output): string | undefined { - const { data } = output?.features?.find((feature) => feature.type === FEATURE_TYPE_METADATA) ?? { - data: undefined, + if (output.getType() === OutputType.Treasury) { + return undefined } + + const commonOutput = output as CommonOutput + const feature = commonOutput?.getFeatures()?.find((feature) => feature.getType() === FeatureType.Metadata) + const metadataFeature = feature as MetadataFeature + const data = metadataFeature.getData() ?? undefined + if (data) { const isVotingOutput = isParticipationOutput(output) const metadataBytes = Converter.hexToBytes(data) diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getStateControllerAddressFromAliasOutput.ts b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getStateControllerAddressFromAliasOutput.ts index 032a2a66ab1..5f44d45291a 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getStateControllerAddressFromAliasOutput.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getStateControllerAddressFromAliasOutput.ts @@ -1,10 +1,11 @@ -import { UNLOCK_CONDITION_STATE_CONTROLLER_ADDRESS } from '@core/wallet/constants' -import { IStateControllerAddressUnlockCondition, IAliasOutput } from '@iota/types' +import { AliasOutput, StateControllerAddressUnlockCondition, UnlockConditionType } from '@iota/wallet' import { getBech32AddressFromAddressTypes } from '../../getBech32AddressFromAddressTypes' -export function getStateControllerAddressFromAliasOutput(output: IAliasOutput): string { - const stateControllerUnlockCondition = output.unlockConditions.find( - (unlockCondition) => unlockCondition.type === UNLOCK_CONDITION_STATE_CONTROLLER_ADDRESS - ) as IStateControllerAddressUnlockCondition - return getBech32AddressFromAddressTypes(stateControllerUnlockCondition.address) +export function getStateControllerAddressFromAliasOutput(output: AliasOutput): string { + const stateControllerUnlockCondition = output + .getUnlockConditions() + .find( + (unlockCondition) => unlockCondition.getType() === UnlockConditionType.StateControllerAddress + ) as StateControllerAddressUnlockCondition + return getBech32AddressFromAddressTypes(stateControllerUnlockCondition.getAddress()) } diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getStorageDepositFromOutput.ts b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getStorageDepositFromOutput.ts index 47484ff895f..b1dced44ad5 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getStorageDepositFromOutput.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getStorageDepositFromOutput.ts @@ -1,7 +1,6 @@ import { IAccountState } from '@core/account/interfaces' import { Output } from '@core/wallet/types' -import { IStorageDepositReturnUnlockCondition } from '@iota/types' -import { UNLOCK_CONDITION_STORAGE_DEPOSIT_RETURN } from '../../../constants' +import { StorageDepositReturnUnlockCondition, UnlockConditionType } from '@iota/wallet' export async function getStorageDepositFromOutput( account: IAccountState, @@ -13,13 +12,13 @@ export async function getStorageDepositFromOutput( if (!(account?.index >= 0)) { return { storageDeposit: 0, giftedStorageDeposit: 0 } } - const storageDepositReturnUnlockCondition = ( - output?.unlockConditions?.find( - (unlockCondition) => unlockCondition?.type === UNLOCK_CONDITION_STORAGE_DEPOSIT_RETURN - ) + const storageDepositReturnUnlockCondition = ( + output + ?.getUnlockConditions() + ?.find((unlockCondition) => unlockCondition?.getType() === UnlockConditionType.StorageDepositReturn) ) if (storageDepositReturnUnlockCondition) { - return { storageDeposit: Number(storageDepositReturnUnlockCondition.amount), giftedStorageDeposit: 0 } + return { storageDeposit: Number(storageDepositReturnUnlockCondition.getAmount()), giftedStorageDeposit: 0 } } else { const minimumRequiredStorageDeposit = await account.minimumRequiredStorageDeposit(output) let minimumRequiredStorageDepositNumber = Number(minimumRequiredStorageDeposit) diff --git a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getTimelockDateFromOutput.ts b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getTimelockDateFromOutput.ts index b70b22da08e..c25312279f7 100644 --- a/packages/shared/lib/core/wallet/utils/generateActivity/helper/getTimelockDateFromOutput.ts +++ b/packages/shared/lib/core/wallet/utils/generateActivity/helper/getTimelockDateFromOutput.ts @@ -1,11 +1,13 @@ import { MILLISECONDS_PER_SECOND } from '@core/utils' import { Output } from '@core/wallet/types' -import { UNLOCK_CONDITION_TIMELOCK } from '../../../constants' +import { TimelockUnlockCondition, UnlockConditionType } from '@iota/wallet' -export function getTimelockDateFromOutput(output: Output): Date { - for (const unlockCondition of output.unlockConditions) { - if (unlockCondition?.type === UNLOCK_CONDITION_TIMELOCK) { - return unlockCondition?.unixTime ? new Date(unlockCondition?.unixTime * MILLISECONDS_PER_SECOND) : undefined +export function getTimelockDateFromOutput(output: Output): Date | undefined { + for (const unlockCondition of output.getUnlockConditions()) { + if (unlockCondition?.getType() === UnlockConditionType.Timelock) { + const timelockUnlockCondition = unlockCondition as TimelockUnlockCondition + const unixTime = timelockUnlockCondition?.getUnixTime() + return unixTime ? new Date(unixTime * MILLISECONDS_PER_SECOND) : undefined } } } diff --git a/packages/shared/lib/core/wallet/utils/getBech32AddressFromAddressTypes.ts b/packages/shared/lib/core/wallet/utils/getBech32AddressFromAddressTypes.ts index e1cbe4ccbb9..edf904a7041 100644 --- a/packages/shared/lib/core/wallet/utils/getBech32AddressFromAddressTypes.ts +++ b/packages/shared/lib/core/wallet/utils/getBech32AddressFromAddressTypes.ts @@ -1,15 +1,14 @@ -import type { AddressTypes } from '@iota/types' - import { convertHexAddressToBech32 } from './convertHexAddressToBech32' import { ADDRESS_TYPE_ALIAS, ADDRESS_TYPE_ED25519, ADDRESS_TYPE_NFT } from '../constants' +import { Address, AddressType, AliasAddress, Ed25519Address, NftAddress } from '@iota/wallet' -export function getBech32AddressFromAddressTypes(address: AddressTypes): string { - switch (address?.type) { - case ADDRESS_TYPE_ED25519: - return convertHexAddressToBech32(ADDRESS_TYPE_ED25519, address.pubKeyHash) - case ADDRESS_TYPE_ALIAS: - return convertHexAddressToBech32(ADDRESS_TYPE_ALIAS, address.aliasId) - case ADDRESS_TYPE_NFT: - return convertHexAddressToBech32(ADDRESS_TYPE_NFT, address.nftId) +export function getBech32AddressFromAddressTypes(address: Address): string { + switch (address?.getType()) { + case AddressType.Ed25519: + return convertHexAddressToBech32(ADDRESS_TYPE_ED25519, (address as Ed25519Address).getPubKeyHash()) + case AddressType.Alias: + return convertHexAddressToBech32(ADDRESS_TYPE_ALIAS, (address as AliasAddress).getAliasId()) + case AddressType.Nft: + return convertHexAddressToBech32(ADDRESS_TYPE_NFT, (address as NftAddress).getNftId()) } } diff --git a/packages/shared/lib/core/wallet/utils/getMetadataFromFoundryOutput.ts b/packages/shared/lib/core/wallet/utils/getMetadataFromFoundryOutput.ts index 924ae7e61c9..7ac2f611947 100644 --- a/packages/shared/lib/core/wallet/utils/getMetadataFromFoundryOutput.ts +++ b/packages/shared/lib/core/wallet/utils/getMetadataFromFoundryOutput.ts @@ -1,15 +1,15 @@ -import type { IFoundryOutput } from '@iota/types' +import { FeatureType, FoundryOutput, MetadataFeature } from '@iota/wallet' -export function getMetadataFromFoundryOutput(foundry: IFoundryOutput): string { - for (const feature of foundry?.immutableFeatures ?? []) { - if (feature?.type === 2) { - return feature.data +export function getMetadataFromFoundryOutput(foundry: FoundryOutput): string { + for (const feature of foundry?.getImmutableFeatures() ?? []) { + if (feature?.getType() === FeatureType.Metadata) { + return (feature as MetadataFeature).getData() } } - for (const feature of foundry?.features ?? []) { - if (feature.type === 2) { - return feature.data + for (const feature of foundry?.getFeatures() ?? []) { + if (feature?.getType() === FeatureType.Metadata) { + return (feature as MetadataFeature).getData() } } return undefined diff --git a/packages/shared/lib/core/wallet/utils/outputs/getFoundryId.ts b/packages/shared/lib/core/wallet/utils/outputs/getFoundryId.ts index 0efd11a9d0a..fd60772502d 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/getFoundryId.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/getFoundryId.ts @@ -1,22 +1,20 @@ -import { ADDRESS_TYPE_ALIAS } from '@core/wallet/constants' -import type { IFoundryOutput } from '@iota/types' -import { HexHelper, WriteStream } from '@iota/util.js' +import { + AddressType, + AliasAddress, + FoundryOutput, + ImmutableAliasAddressUnlockCondition, + UnlockConditionType, + Utils, +} from '@iota/wallet' -export function buildFoundryId(foundry: IFoundryOutput): string { - const immutableAliasUnlockCondition = foundry.unlockConditions[0] +export function buildFoundryId(foundry: FoundryOutput): string { + const unlockCondition = foundry.getUnlockConditions()[0] + // TODO-sdk Make this clearer without inline casts const aliasId = - immutableAliasUnlockCondition.type === 6 && immutableAliasUnlockCondition.address.type === ADDRESS_TYPE_ALIAS - ? immutableAliasUnlockCondition.address.aliasId + unlockCondition.getType() === UnlockConditionType.ImmutableAliasAddress && + (unlockCondition as ImmutableAliasAddressUnlockCondition).getAddress().getType() === AddressType.Alias + ? ((unlockCondition as ImmutableAliasAddressUnlockCondition).getAddress() as AliasAddress).getAliasId() : '' - const typeWS = new WriteStream() - typeWS.writeUInt8('alias address type', ADDRESS_TYPE_ALIAS) - const aliasAddress = HexHelper.addPrefix(`${typeWS.finalHex()}${HexHelper.stripPrefix(aliasId)}`) - const serialNumberWS = new WriteStream() - serialNumberWS.writeUInt32('serialNumber', foundry.serialNumber) - const serialNumberHex = serialNumberWS.finalHex() - const tokenSchemeTypeWS = new WriteStream() - tokenSchemeTypeWS.writeUInt8('tokenSchemeType', foundry.tokenScheme.type) - const tokenSchemeTypeHex = tokenSchemeTypeWS.finalHex() - return `${aliasAddress}${serialNumberHex}${tokenSchemeTypeHex}` + return Utils.computeFoundryId(aliasId, foundry.getSerialNumber(), foundry.getTokenScheme().getType()) } diff --git a/packages/shared/lib/core/wallet/utils/outputs/getIssuerFromNftOutput.ts b/packages/shared/lib/core/wallet/utils/outputs/getIssuerFromNftOutput.ts index ad1fa8d1bb6..21742e6beee 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/getIssuerFromNftOutput.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/getIssuerFromNftOutput.ts @@ -1,7 +1,8 @@ -import { FEATURE_TYPE_ISSUER } from '@core/wallet/constants' -import type { AddressTypes, IIssuerFeature, INftOutput } from '@iota/types' +import { Address, FeatureType, IssuerFeature, NftOutput } from '@iota/wallet' -export function getIssuerFromNftOutput(output: INftOutput): AddressTypes { - const metadata = output.immutableFeatures?.find((feature) => feature.type === FEATURE_TYPE_ISSUER) as IIssuerFeature - return metadata?.address +export function getIssuerFromNftOutput(output: NftOutput): Address { + const metadata = output + .getImmutableFeatures() + ?.find((feature) => feature.getType() === FeatureType.Issuer) as IssuerFeature + return metadata?.getIssuer() } diff --git a/packages/shared/lib/core/wallet/utils/outputs/getMetadataFromNftOutput.ts b/packages/shared/lib/core/wallet/utils/outputs/getMetadataFromNftOutput.ts index 7b3ae6c32df..4ff7a175380 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/getMetadataFromNftOutput.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/getMetadataFromNftOutput.ts @@ -1,9 +1,8 @@ -import { FEATURE_TYPE_METADATA } from '@core/wallet/constants' -import type { IMetadataFeature, INftOutput } from '@iota/types' +import { FeatureType, MetadataFeature, NftOutput } from '@iota/wallet' -export function getMetadataFromNftOutput(output: INftOutput): string { - const metadata = output.immutableFeatures?.find( - (feature) => feature.type === FEATURE_TYPE_METADATA - ) as IMetadataFeature - return metadata?.data +export function getMetadataFromNftOutput(output: NftOutput): string { + const metadata = output + .getImmutableFeatures() + ?.find((feature) => feature.getType() === FeatureType.Metadata) as MetadataFeature + return metadata?.getData() } diff --git a/packages/shared/lib/core/wallet/utils/outputs/preprocessGroupedOutputs.ts b/packages/shared/lib/core/wallet/utils/outputs/preprocessGroupedOutputs.ts index 444dc596926..666df326bf2 100644 --- a/packages/shared/lib/core/wallet/utils/outputs/preprocessGroupedOutputs.ts +++ b/packages/shared/lib/core/wallet/utils/outputs/preprocessGroupedOutputs.ts @@ -1,5 +1,4 @@ -import { OutputData } from '@iota/wallet' -import { IOutputResponse, IUTXOInput } from '@iota/types' +import { OutputData, OutputResponse, OutputType, UTXOInput } from '@iota/wallet' import { MILLISECONDS_PER_SECOND } from '@core/utils/constants' import { IAccountState } from '@core/account/interfaces' import { InclusionState, ActivityDirection } from '../../enums' @@ -11,7 +10,7 @@ import { getOutputIdFromTransactionIdAndIndex } from './getOutputIdFromTransacti export function preprocessGroupedOutputs( outputDatas: OutputData[], - transactionInputs: IOutputResponse[], + transactionInputs: OutputResponse[], account: IAccountState ): IProcessedTransaction { const transactionMetadata = outputDatas[0]?.metadata @@ -24,7 +23,7 @@ export function preprocessGroupedOutputs( const wrappedOutputs = outputDatas.map((outputData) => ({ outputId: outputData.outputId, remainder: outputData.remainder, - output: outputData.output.type !== OUTPUT_TYPE_TREASURY ? outputData.output : undefined, + output: outputData.output.getType() !== OutputType.Treasury ? outputData.output : undefined, })) return { @@ -64,7 +63,7 @@ function getDirectionForOutputs( function convertTransactionOutputResponsesToWrappedOutputs( transactionId: string, - outputResponses: IOutputResponse[] + outputResponses: OutputResponse[] ): IWrappedOutput[] { return outputResponses.map((outputResponse) => convertTransactionOutputResponseToWrappedOutput(transactionId, outputResponse) @@ -73,9 +72,9 @@ function convertTransactionOutputResponsesToWrappedOutputs( function convertTransactionOutputResponseToWrappedOutput( transactionId: string, - outputResponse: IOutputResponse + outputResponse: OutputResponse ): IWrappedOutput { - if (outputResponse.output.type === OUTPUT_TYPE_TREASURY) { + if (outputResponse.output.getType() === OutputType.Treasury) { return undefined } else { const outputId = getOutputIdFromTransactionIdAndIndex(transactionId, outputResponse.metadata.outputIndex) @@ -83,15 +82,13 @@ function convertTransactionOutputResponseToWrappedOutput( } } -function getUtxoInputsFromWrappedInputs(wrappedInputs: IWrappedOutput[]): IUTXOInput[] { +function getUtxoInputsFromWrappedInputs(wrappedInputs: IWrappedOutput[]): UTXOInput[] { + // TODO-sdk This won't work probably return ( - wrappedInputs?.map( - (input) => - ({ - type: 0, - transactionId: input.metadata?.transactionId, - transactionOutputIndex: input.metadata.outputIndex, - } as IUTXOInput) - ) ?? [] + wrappedInputs?.map((input) => ({ + type: 0, + transactionId: input.metadata?.transactionId, + transactionInputIndex: input.metadata?.outputIndex, + })) ?? [] ) } diff --git a/packages/shared/lib/core/wallet/utils/transactions/activityOutputContainsValue.ts b/packages/shared/lib/core/wallet/utils/transactions/activityOutputContainsValue.ts index d2b319a4565..394014f256e 100644 --- a/packages/shared/lib/core/wallet/utils/transactions/activityOutputContainsValue.ts +++ b/packages/shared/lib/core/wallet/utils/transactions/activityOutputContainsValue.ts @@ -1,9 +1,9 @@ import { IAccountState } from '@core/account/interfaces' import { ActivityType } from '@core/wallet/enums' -import { IBasicOutput } from '@iota/types' import { getNativeTokenFromOutput, isOutputAsync } from '..' import { IWrappedOutput } from '../../interfaces' import { getActivityTypeFromOutput, getAmountFromOutput, getStorageDepositFromOutput } from '../generateActivity/helper' +import { BasicOutput } from '@iota/wallet' export async function activityOutputContainsValue( account: IAccountState, @@ -12,7 +12,7 @@ export async function activityOutputContainsValue( const type = getActivityTypeFromOutput(wrappedOutput) const typesToCheck = [ActivityType.Basic] if (typesToCheck.includes(type)) { - const output = wrappedOutput.output as IBasicOutput + const output = wrappedOutput.output as BasicOutput const isAsync = isOutputAsync(output) const nativeToken = getNativeTokenFromOutput(output) From fb1c7cf74d8890576393fab1c60ab111fa1e845d Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Thu, 13 Jul 2023 17:45:15 +0200 Subject: [PATCH 09/48] chore: Migrate to iota/sdk models (remove @iota/types) pass 2 --- .../popups/BalanceBreakdownPopup.svelte | 30 ++++++++-------- .../drawers/BalanceBreakdownDrawer.svelte | 34 +++++++++---------- .../utils/sumTotalClaimedRewards.ts | 9 +++-- .../account/interfaces/account.interface.ts | 14 +++++--- .../helpers/getNetworkStatusFromNodeInfo.ts | 4 +-- .../lib/core/network/interfaces/index.ts | 1 - .../node-info-response.interface.ts | 2 +- .../network/interfaces/node-info.interface.ts | 3 -- .../core/network/stores/node-info.store.ts | 2 +- .../activities/preprocessOutputsForAccount.ts | 5 ++- .../core/wallet/utils/buildNftOutputData.ts | 26 +++++--------- .../helper/getStorageDepositFromOutput.ts | 5 ++- .../helper/getTagFromOutput.ts | 12 +++---- .../utils/getHexAddressFromAddressTypes.ts | 20 +++++------ .../lib/tests/__mocks__/account.mock.ts | 24 +++++++------ 15 files changed, 90 insertions(+), 101 deletions(-) diff --git a/packages/desktop/components/popups/BalanceBreakdownPopup.svelte b/packages/desktop/components/popups/BalanceBreakdownPopup.svelte index 883c0dd9767..e7ff8f3a2fa 100644 --- a/packages/desktop/components/popups/BalanceBreakdownPopup.svelte +++ b/packages/desktop/components/popups/BalanceBreakdownPopup.svelte @@ -3,15 +3,9 @@ import { selectedAccount } from '@core/account' import { localize } from '@core/i18n' import { checkActiveProfileAuth } from '@core/profile' - import { - OUTPUT_TYPE_TREASURY, - UNLOCK_CONDITION_EXPIRATION, - UNLOCK_CONDITION_STORAGE_DEPOSIT_RETURN, - UNLOCK_CONDITION_TIMELOCK, - } from '@core/wallet' import { consolidateOutputs } from '@core/wallet/actions/consolidateOutputs' import { getStorageDepositFromOutput } from '@core/wallet/utils/generateActivity/helper' - import type { UnlockConditionTypes } from '@iota/types' + import { UnlockCondition, UnlockConditionType, OutputType, CommonOutput } from '@iota/wallet' import { BalanceSummarySection, Button, FontWeight, Text, TextType } from 'shared/components' interface BalanceBreakdown { @@ -57,18 +51,24 @@ let type: string let amount: number - if (output.type !== OUTPUT_TYPE_TREASURY) { - if (containsUnlockCondition(output.unlockConditions, UNLOCK_CONDITION_EXPIRATION)) { + if (output.getType() !== OutputType.Treasury) { + const commonOutput = output as CommonOutput + if (containsUnlockCondition(commonOutput.getUnlockConditions(), UnlockConditionType.Expiration)) { type = PendingFundsType.Unclaimed - amount = Number(output.amount) + amount = Number(output.getAmount()) } else if ( - containsUnlockCondition(output.unlockConditions, UNLOCK_CONDITION_STORAGE_DEPOSIT_RETURN) + containsUnlockCondition( + commonOutput.getUnlockConditions(), + UnlockConditionType.StorageDepositReturn + ) ) { type = PendingFundsType.StorageDepositReturn amount = (await getStorageDepositFromOutput($selectedAccount, output))?.storageDeposit - } else if (containsUnlockCondition(output.unlockConditions, UNLOCK_CONDITION_TIMELOCK)) { + } else if ( + containsUnlockCondition(commonOutput.getUnlockConditions(), UnlockConditionType.Timelock) + ) { type = PendingFundsType.Timelock - amount = Number(output.amount) + amount = Number(output.getAmount()) } } @@ -114,8 +114,8 @@ return { amount: totalStorageDeposit, subBreakdown } } - function containsUnlockCondition(unlockConditions: UnlockConditionTypes[], unlockConditionId: number) { - return unlockConditions.some((unlockCondition) => unlockCondition.type === unlockConditionId) + function containsUnlockCondition(unlockConditions: UnlockCondition[], unlockConditionId: number): boolean { + return unlockConditions.some((unlockCondition) => unlockCondition.getType() === unlockConditionId) } function onConsolidationClick(): void { diff --git a/packages/mobile/components/drawers/BalanceBreakdownDrawer.svelte b/packages/mobile/components/drawers/BalanceBreakdownDrawer.svelte index fb5dfbfc4e9..93c8703e5d4 100644 --- a/packages/mobile/components/drawers/BalanceBreakdownDrawer.svelte +++ b/packages/mobile/components/drawers/BalanceBreakdownDrawer.svelte @@ -1,17 +1,10 @@