From 6dd4a873731559d2643b2681bdab1361abf6e17e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rard=20Dethier?= Date: Fri, 12 Apr 2024 08:50:31 +0200 Subject: [PATCH] feat: upgrade logion deps. logion-network/logion-internal#1216 --- package.json | 4 +- src/__mocks__/@logion/node-api/index.ts | 2 + src/__mocks__/LogionClientMock.ts | 27 +- src/__mocks__/LogionMock.ts | 36 +- src/__snapshots__/Login.test.tsx.snap | 2 +- src/certificate/Authenticate.test.tsx | 19 +- src/certificate/Authenticate.tsx | 2 +- src/certificate/Certificate.test.tsx | 7 +- src/certificate/Certificate.tsx | 14 +- src/certificate/ClaimAssetButton.test.tsx | 4 +- src/certificate/ClaimAssetButton.tsx | 4 +- src/certificate/CollectionItemCellRow.tsx | 4 +- src/certificate/LegalOfficerRow.tsx | 2 +- src/certificate/TokensRecords.tsx | 6 +- src/common/AccountAddress.test.tsx | 4 +- src/common/CommonContext.tsx | 21 +- src/common/HandledVaultTransferRequests.tsx | 4 +- src/common/LegalOfficerNameCell.tsx | 3 +- src/common/Model.tsx | 8 +- src/common/PendingVaultTransferRequests.tsx | 4 +- src/common/RequestToCancel.tsx | 3 +- src/common/Storage.test.ts | 20 +- src/common/Storage.ts | 22 +- src/common/SubmitterName.test.tsx | 16 +- src/common/SubmitterName.tsx | 19 +- src/common/TestData.ts | 13 +- src/common/TransactionType.test.tsx | 7 +- src/common/TransactionType.tsx | 19 +- src/common/Transactions.test.tsx | 7 +- src/common/Transactions.tsx | 52 +- src/common/TransferAmountCell.tsx | 16 +- src/common/ViewFileButton.tsx | 5 +- src/common/WalletGauge.tsx | 12 +- .../AccountAddress.test.tsx.snap | 6 +- .../__snapshots__/AccountInfo.test.tsx.snap | 6 +- .../AddressSwitcher.test.tsx.snap | 20 +- .../__snapshots__/SubmitterName.test.tsx.snap | 9 +- .../__snapshots__/Transactions.test.tsx.snap | 27 +- src/common/types/Accounts.tsx | 2 +- src/components/itemfiles/ItemFiles.tsx | 2 +- src/legal-officer/LegalOfficerContext.tsx | 38 +- src/legal-officer/LegalOfficerDashboard.tsx | 4 +- src/legal-officer/LegalOfficerRouter.tsx | 4 +- .../LegalOfficerRouter.test.tsx.snap | 9 +- src/legal-officer/home/Home.tsx | 4 +- .../home/__snapshots__/Home.test.tsx.snap | 14 +- .../recovery/PendingRecoveryRequests.tsx | 6 +- .../recovery/RecoveryDetails.test.tsx | 6 +- .../recovery/RecoveryDetails.tsx | 25 +- .../LocRequestAcceptance.test.tsx | 5 +- .../LocRequestAcceptanceAndCreation.test.tsx | 10 +- .../vault/PendingVaultTransferRequests.tsx | 14 +- src/loc/AcceptRejectLocRequest.test.tsx | 15 +- src/loc/AcceptRejectLocRequest.tsx | 2 +- src/loc/CertificateAndDetailsButtons.tsx | 8 +- src/loc/CollectionLocItemChecker.tsx | 2 +- src/loc/CollectionLocRequestForm.tsx | 6 +- src/loc/CustomItemActions.test.tsx | 3 +- src/loc/DashboardCertificate.tsx | 2 +- src/loc/DataLocRequest.tsx | 4 +- src/loc/DocumentClaimHistory.tsx | 2 +- src/loc/FileModel.test.ts | 16 +- src/loc/FileModel.ts | 6 +- src/loc/IdentityLocRequest.tsx | 6 +- src/loc/ImportItems.test.tsx | 2 +- src/loc/LegalFeeAmount.test.tsx | 7 +- src/loc/LegalFeeAmount.tsx | 2 +- src/loc/LegalOfficerLocContext.tsx | 2 +- src/loc/LocContext.test.tsx | 13 +- src/loc/LocContext.tsx | 2 +- src/loc/LocCreationDialog.test.tsx | 4 +- src/loc/LocDetailsTab.tsx | 2 +- src/loc/LocItem.tsx | 24 +- src/loc/LocItems.test.tsx | 2 +- src/loc/LocItems.tsx | 2 +- src/loc/LocPublishButton.test.tsx | 6 +- src/loc/LocPublishLinkButton.test.tsx | 4 +- src/loc/LocPublishPrivateFileButton.test.tsx | 4 +- src/loc/LocPublishPublicDataButton.test.tsx | 4 +- src/loc/LocTemplateItems.tsx | 4 +- src/loc/RequesterOrLegalOfficer.test.tsx | 6 +- src/loc/RequesterOrLegalOfficer.tsx | 14 +- src/loc/TemplateItemActions.test.tsx | 3 +- src/loc/TestData.ts | 4 +- src/loc/TransactionLocRequestForm.tsx | 6 +- src/loc/UserContextualizedLocDetails.tsx | 4 +- src/loc/__mocks__/LocContextMock.tsx | 5 +- .../ContextualizedLocDetails.test.tsx.snap | 179 +++-- .../CustomItemActions.test.tsx.snap | 690 +++++++++--------- .../DashboardCertificate.test.tsx.snap | 10 +- .../IdentityLocRequest.test.tsx.snap | 14 +- .../LegalOfficerLocContext.test.tsx.snap | 9 +- src/loc/__snapshots__/LocItems.test.tsx.snap | 6 +- .../LocLinkDetails.test.tsx.snap | 4 +- .../LocPrivateFileDetails.test.tsx.snap | 8 +- .../LocPublicDataDetails.test.tsx.snap | 4 +- .../LocPublishLinkButton.test.tsx.snap | 10 +- .../LocPublishPrivateFileButton.test.tsx.snap | 10 +- .../LocPublishPublicDataButton.test.tsx.snap | 10 +- .../RequesterOrLegalOfficer.test.tsx.snap | 12 +- .../TemplateItemActions.test.tsx.snap | 690 +++++++++--------- ...UserContextualizedLocDetails.test.tsx.snap | 184 +++-- src/loc/archive/ArchiveButton.tsx | 2 +- src/loc/dashboard/CompletedLocs.test.tsx | 7 +- src/loc/dashboard/CompletedLocs.tsx | 2 +- src/loc/dashboard/WaitingLocs.test.tsx | 5 +- src/loc/dashboard/WaitingLocs.tsx | 2 +- src/loc/dashboard/WorkInProgress.test.tsx | 5 +- src/loc/dashboard/WorkInProgressLocs.tsx | 2 +- .../__snapshots__/CompletedLocs.test.tsx.snap | 14 +- .../__snapshots__/WaitingLocs.test.tsx.snap | 7 +- .../WorkInProgress.test.tsx.snap | 7 +- src/loc/fees/EstimatedFees.tsx | 2 +- .../InvitedContributorsFrame.test.tsx | 5 +- .../issuer/IssuerSelectionCheckbox.test.tsx | 3 +- src/loc/issuer/IssuerSelectionCheckbox.tsx | 2 +- src/loc/issuer/IssuerSelectionFrame.test.tsx | 5 +- src/loc/record/TokensRecordFiles.tsx | 2 +- src/loc/record/TokensRecordFrame.test.tsx | 3 +- src/loc/statement/StatementOfFactsButton.tsx | 18 +- src/loc/statement/StatementOfFactsSummary.tsx | 1 - src/logion-chain/LogionChainContext.test.tsx | 2 +- src/logion-chain/LogionChainContext.tsx | 44 +- src/logion-chain/Signature.tsx | 3 +- src/logion-chain/__mocks__/LogionChainMock.ts | 5 +- src/settings/ChainData.tsx | 10 +- src/settings/DirectoryData.tsx | 7 +- src/settings/SettingsPane.tsx | 5 +- src/settings/ValuesFiles.tsx | 4 +- src/vault/VaultApi.ts | 11 +- src/vault/VaultOutRequest.tsx | 18 +- src/wallet-user/TestData.ts | 6 +- src/wallet-user/UserContext.tsx | 6 +- src/wallet-user/UserDashboard.test.tsx | 5 +- src/wallet-user/UserRouter.tsx | 8 +- src/wallet-user/__mocks__/UserContextMock.tsx | 3 +- .../__snapshots__/UserRouter.test.tsx.snap | 10 +- src/wallet-user/home/Home.tsx | 4 +- .../issuer/IssuerClosedLocs.test.tsx | 9 +- src/wallet-user/issuer/IssuerClosedLocs.tsx | 2 +- .../issuer/IssuerOpenedLocs.test.tsx | 9 +- src/wallet-user/issuer/IssuerOpenedLocs.tsx | 2 +- .../CreateProtectionRequestForm.test.tsx | 12 +- .../CreateProtectionRequestForm.tsx | 10 +- src/wallet-user/protection/Officer.tsx | 2 +- .../ProtectionRecoveryRequest.test.tsx | 2 +- .../protection/ProtectionRecoveryRequest.tsx | 4 +- .../protection/SelectLegalOfficer.tsx | 19 +- .../protection/SelectLegalOfficerAndLoc.tsx | 2 +- src/wallet-user/protection/TestData.ts | 14 +- .../protection/TrustProtection.test.tsx | 2 +- .../ProtectionRecoveryRequest.test.tsx.snap | 426 +++++++++-- src/wallet-user/recovery/Recovery.test.tsx | 4 +- .../recovery/VaultRecoveryProcessTab.tsx | 18 +- .../WalletRecoveryProcessTab.test.tsx | 6 +- .../recovery/WalletRecoveryProcessTab.tsx | 2 +- yarn.lock | 518 +++---------- 157 files changed, 2066 insertions(+), 1879 deletions(-) diff --git a/package.json b/package.json index df5a8b0b..7fbc2c45 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,10 @@ "license": "Apache-2.0", "dependencies": { "@creativecommons/cc-assets": "^0.1.0", - "@logion/client": "^0.42.0", + "@logion/client": "^0.43.0-3", "@logion/client-browser": "^0.3.4", "@logion/crossmint": "^0.1.32", - "@logion/extension": "^0.7.8", + "@logion/extension": "^0.8.0-1", "@logion/multiversx": "^0.1.13", "@multiversx/sdk-extension-provider": "^2.0.7", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.3", diff --git a/src/__mocks__/@logion/node-api/index.ts b/src/__mocks__/@logion/node-api/index.ts index efc441e2..800c1566 100644 --- a/src/__mocks__/@logion/node-api/index.ts +++ b/src/__mocks__/@logion/node-api/index.ts @@ -9,6 +9,8 @@ export { Hash, Lgnt, LgntFormatter, + ValidAccountId, + AnyAccountId, } from "@logion/node-api"; export type { diff --git a/src/__mocks__/LogionClientMock.ts b/src/__mocks__/LogionClientMock.ts index b40c4766..1fd01590 100644 --- a/src/__mocks__/LogionClientMock.ts +++ b/src/__mocks__/LogionClientMock.ts @@ -4,7 +4,7 @@ import { TEST_WALLET_USER } from "../wallet-user/TestData"; export { toIsoString, fromIsoString } from "@logion/client/dist/DateTimeUtil.js"; import { api } from "./LogionMock"; import { VerifiedIssuerWithSelect } from "@logion/client/dist/Loc"; -import { Hash } from "@logion/node-api"; +import { Hash, ValidAccountId } from "@logion/node-api"; import { TokensRecord } from "@logion/client"; export const axiosMock = { @@ -22,18 +22,18 @@ export class LogionClient { return this; } - withCurrentAddress() { + withCurrentAccount() { return this; } tokens = new AccountTokens(); - isLegalOfficer(address: string) { - return address === PATRICK.address || address === GUILLAUME.address || address === ALAIN.address; + isLegalOfficer(address: ValidAccountId) { + return address.equals(PATRICK.account) || address.equals(GUILLAUME.account) || address.equals(ALAIN.account); } - isRegisteredLegalOfficer(address: string) { - return address === PATRICK.address || address === GUILLAUME.address || address === ALAIN.address; + isRegisteredLegalOfficer(address: ValidAccountId) { + return address.equals(PATRICK.account) || address.equals(GUILLAUME.account) || address.equals(ALAIN.account); } legalOfficers = threeLegalOfficers; @@ -68,16 +68,17 @@ export class LogionClient { }, findCollectionLocItemById: () => { isAuthenticatedTokenOwner: () => true }, }; - currentAddress = TEST_WALLET_USER; + + currentAccount = TEST_WALLET_USER; logionApi = api.object(); - getLegalOfficer(address: string) { - if(address === PATRICK.address) { + getLegalOfficer(address: ValidAccountId) { + if(address.equals(PATRICK.account)) { return threeLegalOfficers[0]; - } else if(address === GUILLAUME.address) { + } else if(address.equals(GUILLAUME.account)) { return threeLegalOfficers[1]; - } else if(address === ALAIN.address) { + } else if(address.equals(ALAIN.account)) { return threeLegalOfficers[2]; } else { throw new Error(); @@ -99,9 +100,9 @@ export class AccountTokens { return this; } - addresses = [ TEST_WALLET_USER ]; + accounts = [ TEST_WALLET_USER ]; - get(account: any) { + get(account: ValidAccountId) { return ({ value: `some-token-value-for-${account.address}`, expirationDateTime: DateTime.now().plus({hours: 1}) diff --git a/src/__mocks__/LogionMock.ts b/src/__mocks__/LogionMock.ts index b2fd5dc8..afbca8f1 100644 --- a/src/__mocks__/LogionMock.ts +++ b/src/__mocks__/LogionMock.ts @@ -1,31 +1,17 @@ -import { AccountType, ValidAccountId, LogionNodeApiClass, LegalOfficerCase, Hash, Lgnt } from "@logion/node-api"; +import { ValidAccountId, LogionNodeApiClass, LegalOfficerCase, Hash, Lgnt, AccountType, AnyAccountId } from "@logion/node-api"; import { H256 } from "@logion/node-api/dist/types/interfaces"; import { It, Mock } from "moq.ts"; import type { Text, Compact, u128 } from '@polkadot/types-codec'; import type { SubmittableExtrinsic } from '@polkadot/api/promise/types'; import { TEST_WALLET_USER } from "src/wallet-user/TestData"; -import { AccountId } from "@logion/node-api/dist/types/Types"; -export const DEFAULT_LEGAL_OFFICER = mockValidPolkadotAccountId("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"); // Alice -export const ANOTHER_LEGAL_OFFICER = mockValidPolkadotAccountId("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"); // Bob -export const A_THIRD_LEGAL_OFFICER = mockValidPolkadotAccountId("5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y"); // Charlie - -export function mockValidPolkadotAccountId(address: string): ValidAccountId { - return mockValidAccountId(address, "Polkadot"); -} - -export function mockValidAccountId(address: string, type: AccountType): ValidAccountId { - return { - address, - type, - toKey: () => `${type}:${address}`, - equals: (other: AccountId) => other.type === type && other.address === address, - } as ValidAccountId; -} +export const DEFAULT_LEGAL_OFFICER = ValidAccountId.polkadot("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"); // Alice +export const ANOTHER_LEGAL_OFFICER = ValidAccountId.polkadot("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"); // Bob +export const A_THIRD_LEGAL_OFFICER = ValidAccountId.polkadot("5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y"); // Charlie export const api = new Mock(); -api.setup(instance => instance.queries.getValidAccountId).returns((address: string, _type: string) => mockValidPolkadotAccountId(address)); +api.setup(instance => instance.queries.getValidAccountId).returns((address: string, type: AccountType) => new AnyAccountId(address, type).toValidAccountId()); const localPeerId = new Mock(); localPeerId.setup(instance => instance.toString()).returns("Mock peer ID"); @@ -50,8 +36,8 @@ export function mockSubmittable(): Mock { export const CLOSED_IDENTITY_LOC_ID = "85833363768713528858922097642089825569"; export const CLOSED_IDENTITY_LOC: LegalOfficerCase = { - owner: DEFAULT_LEGAL_OFFICER.address, - requesterAddress: mockValidPolkadotAccountId("5Ew3MyB15VprZrjQVkpQFj8okmc9xLDSEdNhqMMS5cXsqxoW"), + owner: DEFAULT_LEGAL_OFFICER, + requesterAccountId: ValidAccountId.polkadot("5Ew3MyB15VprZrjQVkpQFj8okmc9xLDSEdNhqMMS5cXsqxoW"), locType: 'Identity', closed: true, files: [ @@ -76,8 +62,8 @@ export const CLOSED_IDENTITY_LOC: LegalOfficerCase = { export const OPEN_IDENTITY_LOC_ID = "195914524858768213081425411950368569411"; export const OPEN_IDENTITY_LOC: LegalOfficerCase = { - owner: DEFAULT_LEGAL_OFFICER.address, - requesterAddress: mockValidPolkadotAccountId("5Ew3MyB15VprZrjQVkpQFj8okmc9xLDSEdNhqMMS5cXsqxoW"), + owner: DEFAULT_LEGAL_OFFICER, + requesterAccountId: ValidAccountId.polkadot("5Ew3MyB15VprZrjQVkpQFj8okmc9xLDSEdNhqMMS5cXsqxoW"), locType: 'Identity', closed: false, files: [], @@ -93,8 +79,8 @@ export const OPEN_IDENTITY_LOC: LegalOfficerCase = { export const CLOSED_COLLECTION_LOC_ID = "195914524858768213081425411950368569411"; export const CLOSED_COLLECTION_LOC: LegalOfficerCase = { - owner: DEFAULT_LEGAL_OFFICER.address, - requesterAddress: mockValidPolkadotAccountId("5Ew3MyB15VprZrjQVkpQFj8okmc9xLDSEdNhqMMS5cXsqxoW"), + owner: DEFAULT_LEGAL_OFFICER, + requesterAccountId: ValidAccountId.polkadot("5Ew3MyB15VprZrjQVkpQFj8okmc9xLDSEdNhqMMS5cXsqxoW"), locType: 'Collection', closed: true, files: [], diff --git a/src/__snapshots__/Login.test.tsx.snap b/src/__snapshots__/Login.test.tsx.snap index 9e7197b2..a7c3a7ca 100644 --- a/src/__snapshots__/Login.test.tsx.snap +++ b/src/__snapshots__/Login.test.tsx.snap @@ -53,7 +53,7 @@ exports[`Login renders 1`] = `
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY + vQx5kESPn8dWyX4KxMCKqUyCaWUwtui1isX6PVNcZh2Ghjitr
diff --git a/src/certificate/Authenticate.test.tsx b/src/certificate/Authenticate.test.tsx index b38817c2..3464a924 100644 --- a/src/certificate/Authenticate.test.tsx +++ b/src/certificate/Authenticate.test.tsx @@ -1,6 +1,6 @@ import { render, screen } from '@testing-library/react'; import { clickByName, shallowRender } from '../tests'; -import { UUID, Hash } from "@logion/node-api"; +import { UUID, Hash, AnyAccountId, ValidAccountId } from "@logion/node-api"; import { HashString, ClientToken } from "@logion/client"; import { DEFAULT_LEGAL_OFFICER } from "../common/TestData"; import { setMetamaskEnabled } from '../__mocks__/LogionExtensionMock'; @@ -8,7 +8,6 @@ import { setClientMock } from 'src/logion-chain/__mocks__/LogionChainMock'; import { CollectionItem, UploadableItemFile, Token, ItemTokenWithRestrictedType } from '@logion/client'; import Authenticate, { Props } from "./Authenticate"; import { LogionClient } from 'src/__mocks__/LogionClientMock'; -import { mockValidPolkadotAccountId } from 'src/__mocks__/LogionMock'; jest.mock('../logion-chain'); @@ -23,7 +22,7 @@ describe("Authenticate with Metamask", () => { it("gets token for rightful owner of item", () => testOwnershipCheckSuccess( metamaskAssetProps, { token: "some-token-value-for-0xa6db31d1aee06a3ad7e4e56de3775e80d2f5ea84" }, - "0xa6db31d1aee06a3ad7e4e56de3775e80d2f5ea84" + new AnyAccountId("0xa6db31d1aee06a3ad7e4e56de3775e80d2f5ea84", "Ethereum").toValidAccountId(), )); it("does not get token if anyone else", () => testOwnershipCheckFailure(metamaskAssetProps)); }) @@ -38,7 +37,7 @@ describe("Authenticate with Crossmint", () => { it("gets token for rightful owner of item", async () => testOwnershipCheckSuccess( crossmintAssetProps, { token: "some-token-value-for-0xa6db31d1aee06a3ad7e4e56de3775e80d2f5ea84" }, - "0xa6db31d1aee06a3ad7e4e56de3775e80d2f5ea84" + new AnyAccountId("0xa6db31d1aee06a3ad7e4e56de3775e80d2f5ea84", "Ethereum").toValidAccountId(), )); it("does not get token if anyone else", async () => testOwnershipCheckFailure(crossmintAssetProps)); }) @@ -52,8 +51,8 @@ describe("Authenticate with Polkadot", () => { it("renders button for restricted delivery of item asset", () => testRender(polkadotAssetProps)) it("gets token for rightful owner of item", async () => testOwnershipCheckSuccess( polkadotAssetProps, - { token: "some-token-value-for-5FniDvPw22DMW1TLee9N8zBjzwKXaKB2DcvZZCQU5tjmv1kb" }, - "5FniDvPw22DMW1TLee9N8zBjzwKXaKB2DcvZZCQU5tjmv1kb" + { token: "some-token-value-for-vQw1WXnZU4fCjzyXJqyrnojstSK4YFbtviVKRrBQeydk9je4F" }, + ValidAccountId.polkadot("vQw1WXnZU4fCjzyXJqyrnojstSK4YFbtviVKRrBQeydk9je4F"), )); it("does not get token if anyone else", async () => testOwnershipCheckFailure(crossmintAssetProps)); }) @@ -85,7 +84,7 @@ const item = { const ownerToken: ItemTokenWithRestrictedType = { type: "owner", - id: "5FniDvPw22DMW1TLee9N8zBjzwKXaKB2DcvZZCQU5tjmv1kb", + id: "vQw1WXnZU4fCjzyXJqyrnojstSK4YFbtviVKRrBQeydk9je4F", issuance: 1n, }; @@ -160,9 +159,9 @@ function expectTokenSet(value: string) { expect(tokenForDownload?.value).toEqual(value); } -function mockForCheckSuccess(address: string) { +function mockForCheckSuccess(address: ValidAccountId) { const clientMock = new LogionClient(); - clientMock.currentAddress = mockValidPolkadotAccountId(address); + clientMock.currentAccount = address; const item = { isAuthenticatedTokenOwner: () => true, }; @@ -185,7 +184,7 @@ async function testOwnershipCheckFailure(props: Props) { await expectOwnershipCheckFailure(); } -async function testOwnershipCheckSuccess(props: Props, params: { token: string }, address: string) { +async function testOwnershipCheckSuccess(props: Props, params: { token: string }, address: ValidAccountId) { mockForCheckSuccess(address); await renderAndClaim(props); if (props.walletType === 'POLKADOT') { diff --git a/src/certificate/Authenticate.tsx b/src/certificate/Authenticate.tsx index b0f6e99d..ba4fa6cc 100644 --- a/src/certificate/Authenticate.tsx +++ b/src/certificate/Authenticate.tsx @@ -46,7 +46,7 @@ export default function Authenticate(props: Props) { const newItem = await client.public.findCollectionLocItemById({ locId, itemId: item.id }); const isOwner = newItem && await newItem.isAuthenticatedTokenOwner(); if (isOwner) { - setTokenForDownload(client.tokens.get(client.currentAddress)); + setTokenForDownload(client.tokens.get(client.currentAccount)); setStatus('OWNER_OK'); } else { setStatus('OWNER_KO'); diff --git a/src/certificate/Certificate.test.tsx b/src/certificate/Certificate.test.tsx index 6b3ad35c..21477bed 100644 --- a/src/certificate/Certificate.test.tsx +++ b/src/certificate/Certificate.test.tsx @@ -10,6 +10,7 @@ import Certificate from './Certificate'; import { setClientMock } from 'src/logion-chain/__mocks__/LogionChainMock'; import { PATRICK } from 'src/common/TestData'; import { URLSearchParams } from 'url'; +import { TEST_WALLET_USER } from 'src/wallet-user/TestData'; jest.mock("react-router"); jest.mock("react-router-dom"); @@ -95,7 +96,7 @@ describe("Certificate", () => { await waitFor(() => expect(screen.getByText("Legal Officer Case")).toBeVisible()); expect(screen.getByText("Tokens record")).toBeVisible(); - expect(screen.getByText(mockTRCellContent(tokensRecord.issuer))).toBeVisible(); + expect(screen.getByText(mockTRCellContent(tokensRecord.issuer.address))).toBeVisible(); expect(screen.getByText(mockTRCellContent(tokensRecord.description.validValue()))).toBeVisible(); expect(screen.getByText(mockTRCellContent(tokensRecord.files[0].contentType.validValue()))).toBeVisible(); expect(screen.getByText(tokensRecord.files[0].name.validValue())).toBeVisible(); @@ -127,7 +128,7 @@ function mockPublicLoc(locId: UUID): PublicLoc { return { data: { id: locId, - ownerAddress: PATRICK.address, + ownerAccountId: PATRICK.account, files: [], metadata: [], links: [], @@ -205,7 +206,7 @@ function mockTokensRecord(): ClientTokensRecord { id: Hash.of("record-id"), description: HashString.fromValue("Record Description"), addedOn: "2022-08-23T07:27:46.128Z", - issuer: "record-issuer", + issuer: TEST_WALLET_USER, files: [ { name: HashString.fromValue("record-file-name.txt"), hash: Hash.of("record-file-content"), diff --git a/src/certificate/Certificate.tsx b/src/certificate/Certificate.tsx index be1f40a9..3040688c 100644 --- a/src/certificate/Certificate.tsx +++ b/src/certificate/Certificate.tsx @@ -112,7 +112,7 @@ export default function Certificate() { useEffect(() => { if (client !== null && legalOfficer === null && loc) { - setLegalOfficer(client.legalOfficers.find(legalOfficer => legalOfficer.address === loc.data.ownerAddress) || null); + setLegalOfficer(client.legalOfficers.find(legalOfficer => legalOfficer.account.equals(loc.data.ownerAccountId)) || null); } }, [ client, legalOfficer, setLegalOfficer, loc ]); @@ -188,7 +188,7 @@ export default function Certificate() { return (
{ locId.toDecimalString() } - { loc.data.ownerAddress } + { loc.data.ownerAccountId.address }
) } @@ -351,9 +351,9 @@ export default function Certificate() { - { loc.data.requesterAddress && + { loc.data.requesterAccountId && - { loc.data.requesterAddress.address } + { loc.data.requesterAccountId.address } } { loc.data.requesterLocId && @@ -386,7 +386,7 @@ export default function Certificate() { { collectionItem !== null && diff --git a/src/certificate/ClaimAssetButton.test.tsx b/src/certificate/ClaimAssetButton.test.tsx index 72e17028..f188d0fd 100644 --- a/src/certificate/ClaimAssetButton.test.tsx +++ b/src/certificate/ClaimAssetButton.test.tsx @@ -63,7 +63,7 @@ const TOKEN_FOR_DOWNLOAD: Token = { const assetProps = { locId, - owner: DEFAULT_LEGAL_OFFICER.address, + owner: DEFAULT_LEGAL_OFFICER, item, file: claimedAsset, }; @@ -76,7 +76,7 @@ const claimedCollectionFile: ClaimedFile = { const collectionFileProps = { locId, - owner: DEFAULT_LEGAL_OFFICER.address, + owner: DEFAULT_LEGAL_OFFICER, item, file: claimedCollectionFile, }; diff --git a/src/certificate/ClaimAssetButton.tsx b/src/certificate/ClaimAssetButton.tsx index a7d86cf8..178259d4 100644 --- a/src/certificate/ClaimAssetButton.tsx +++ b/src/certificate/ClaimAssetButton.tsx @@ -1,5 +1,5 @@ import { Token, CollectionItem, TokensRecord, TypedFile } from "@logion/client"; -import { UUID, Hash } from "@logion/node-api"; +import { UUID, Hash, ValidAccountId } from "@logion/node-api"; import { AxiosInstance } from "axios"; import { useState, useEffect } from "react"; import ViewFileButton from "../common/ViewFileButton"; @@ -24,7 +24,7 @@ export interface ClaimedFile { export interface Props { locId: UUID, - owner: string, + owner: ValidAccountId, item: CollectionItem, record?: TokensRecord, file: ClaimedFile, diff --git a/src/certificate/CollectionItemCellRow.tsx b/src/certificate/CollectionItemCellRow.tsx index 0dce687f..fcbdeb46 100644 --- a/src/certificate/CollectionItemCellRow.tsx +++ b/src/certificate/CollectionItemCellRow.tsx @@ -1,5 +1,5 @@ import { CheckHashResult, CollectionItem, Token } from "@logion/client"; -import { UUID } from "@logion/node-api"; +import { UUID, ValidAccountId } from "@logion/node-api"; import CertificateCell from "./CertificateCell"; import { Row } from "../common/Grid"; @@ -13,7 +13,7 @@ import { CertificateItemDetails } from "src/components/certificateitemdetails/Ce export interface Props { locId: UUID, - owner: string, + owner: ValidAccountId, item: CollectionItem; checkResult: CheckHashResult | undefined; isVoid: boolean; diff --git a/src/certificate/LegalOfficerRow.tsx b/src/certificate/LegalOfficerRow.tsx index 45cbcaae..74330e60 100644 --- a/src/certificate/LegalOfficerRow.tsx +++ b/src/certificate/LegalOfficerRow.tsx @@ -10,7 +10,7 @@ export default function LegalOfficerRow(props: { legalOfficer: LegalOfficer }) { return ( - { props.legalOfficer.address } + { props.legalOfficer.account.address } diff --git a/src/certificate/TokensRecords.tsx b/src/certificate/TokensRecords.tsx index c4408d60..81e63de3 100644 --- a/src/certificate/TokensRecords.tsx +++ b/src/certificate/TokensRecords.tsx @@ -1,8 +1,8 @@ import { TokensRecord, UploadableItemFile, Token, CollectionItem, CheckHashResult } from "@logion/client"; +import { UUID, ValidAccountId } from "@logion/node-api"; import MenuIcon from "../common/MenuIcon"; import InlineDateTime from "../common/InlineDateTime"; import "./TokensRecords.css"; -import { UUID } from "@logion/node-api"; import ClaimAssetButton from "./ClaimAssetButton"; import { Row } from "../common/Grid"; import { Col } from "react-bootstrap"; @@ -10,7 +10,7 @@ import { customClassName } from "src/common/types/Helpers"; export interface TokensRecordsProps { locId: UUID, - owner: string, + owner: ValidAccountId, collectionItem: CollectionItem, tokenForDownload: Token | undefined, tokensRecords: TokensRecord[]; @@ -59,7 +59,7 @@ function TokensRecordCell(props: TokensRecordCellProps) { - { tokensRecord.issuer } + { tokensRecord.issuer.address } { tokensRecord.files.map(tokensRecordFile => ( )) } diff --git a/src/common/AccountAddress.test.tsx b/src/common/AccountAddress.test.tsx index 17028b67..d2881b94 100644 --- a/src/common/AccountAddress.test.tsx +++ b/src/common/AccountAddress.test.tsx @@ -1,8 +1,8 @@ import { Numbers } from "@logion/node-api"; -import { mockValidPolkadotAccountId } from 'src/__mocks__/LogionMock'; import { shallowRender } from '../tests'; import AccountAddress from './AccountAddress'; +import { TEST_WALLET_USER } from "src/wallet-user/TestData"; describe("AccountAddress", () => { @@ -21,7 +21,7 @@ describe("AccountAddress", () => { }} account={{ name: "Name 1", - accountId: mockValidPolkadotAccountId("address1"), + accountId: TEST_WALLET_USER, isLegalOfficer: false, }} disabled={ false } diff --git a/src/common/CommonContext.tsx b/src/common/CommonContext.tsx index 744a50a8..82d19301 100644 --- a/src/common/CommonContext.tsx +++ b/src/common/CommonContext.tsx @@ -2,6 +2,7 @@ import React, { useContext, useEffect, useReducer, Reducer, useCallback } from " import { DateTime } from 'luxon'; import { LegalOfficerClass, BalanceState, LogionClient, Endpoint } from "@logion/client"; import { InjectedAccount } from "@logion/extension"; +import { ValidAccountId } from "@logion/node-api"; import { useLogionChain } from '../logion-chain'; import { Children } from './types/Helpers'; @@ -27,13 +28,13 @@ export interface CommonContext { colorTheme: ColorTheme; setColorTheme: ((colorTheme: ColorTheme) => void) | null; refresh: (clearOnRefresh: boolean) => void; - nodesUp: Endpoint[]; - nodesDown: Endpoint[]; + nodesUp: LegalOfficerEndpoint[]; + nodesDown: LegalOfficerEndpoint[]; availableLegalOfficers: LegalOfficerClass[] | undefined; mutateBalanceState: (mutator: ((state: BalanceState) => Promise)) => Promise, viewer: Viewer; setViewer: ((viewer: Viewer) => void) | null; - backendConfig: ((legalOfficerAddress: string | undefined) => BackendConfig); + backendConfig: ((legalOfficerAddress: ValidAccountId | undefined) => BackendConfig); expectNewTransactionState: ExpectNewTransactionState; expectNewTransaction: () => void; stopExpectNewTransaction: () => void; @@ -123,14 +124,14 @@ interface Action { refresh?: (clearOnRefresh?: boolean) => void; refreshAddress?: string; clearOnRefresh?: boolean; - nodesUp?: Endpoint[]; - nodesDown?: Endpoint[]; + nodesUp?: LegalOfficerEndpoint[]; + nodesDown?: LegalOfficerEndpoint[]; availableLegalOfficers?: LegalOfficerClass[]; mutateBalanceState?: (mutator: ((state: BalanceState) => Promise)) => Promise; client?: LogionClient; viewer?: Viewer; setViewer?: (viewer: Viewer) => void; - backendConfig?: ((legalOfficerAddress: string | undefined) => BackendConfig); + backendConfig?: ((legalOfficerAddress: ValidAccountId | undefined) => BackendConfig); expectNewTransaction?: () => void; stopExpectNewTransaction?: () => void; notificationText?: string; @@ -319,15 +320,15 @@ export function CommonContextProvider(props: Props) { for(let i = 0; i < configPromises.length; ++i) { const promiseResult = configPromises[i]; if(promiseResult.status === 'fulfilled') { - backendConfigs[client.legalOfficers[i].address] = promiseResult.value; + backendConfigs[client.legalOfficers[i].account.address] = promiseResult.value; } } - const backendConfig = (legalOfficerAddress: string | undefined) => { - if(!legalOfficerAddress || !(legalOfficerAddress in backendConfigs)) { + const backendConfig = (legalOfficerAddress: ValidAccountId | undefined) => { + if(!legalOfficerAddress || !(legalOfficerAddress.address in backendConfigs)) { return DEFAULT_BACKEND_CONFIG; } else { - return backendConfigs[legalOfficerAddress]; + return backendConfigs[legalOfficerAddress.address]; } }; diff --git a/src/common/HandledVaultTransferRequests.tsx b/src/common/HandledVaultTransferRequests.tsx index 75250dd6..03971f17 100644 --- a/src/common/HandledVaultTransferRequests.tsx +++ b/src/common/HandledVaultTransferRequests.tsx @@ -1,4 +1,4 @@ -import { Lgnt } from "@logion/node-api"; +import { Lgnt, ValidAccountId } from "@logion/node-api"; import { useUserContext } from "../wallet-user/UserContext"; import AmountCell from "./AmountCell"; @@ -22,7 +22,7 @@ export default function HandledVaultTransferRequests() { columns={[ { header: "Legal Officer", - render: request => , + render: request => , align: 'left', renderDetails: request => , }, diff --git a/src/common/LegalOfficerNameCell.tsx b/src/common/LegalOfficerNameCell.tsx index b09990c2..95f630af 100644 --- a/src/common/LegalOfficerNameCell.tsx +++ b/src/common/LegalOfficerNameCell.tsx @@ -1,8 +1,9 @@ +import { ValidAccountId } from "@logion/node-api"; import { useLogionChain } from '../logion-chain'; import { Cell } from './Table'; export interface Props { - address: string; + address: ValidAccountId; } export default function LegalOfficerName(props: Props) { diff --git a/src/common/Model.tsx b/src/common/Model.tsx index f5814fe8..383c1234 100644 --- a/src/common/Model.tsx +++ b/src/common/Model.tsx @@ -1,6 +1,6 @@ import { AxiosInstance } from 'axios'; -import { LocData } from '@logion/client'; -import { ProtectionRequest, ProtectionRequestStatus } from '@logion/client/dist/RecoveryClient.js'; +import { LocData, ProtectionRequest, ProtectionRequestStatus } from '@logion/client'; +import { ValidAccountId } from "@logion/node-api"; export type ProtectionRequestKind = 'RECOVERY' | 'PROTECTION_ONLY' | 'ANY'; @@ -18,6 +18,6 @@ export async function fetchProtectionRequests( return response.data.requests; } -export function isGrantedAccess(address: string | undefined, loc: LocData): boolean { - return loc.ownerAddress === address || loc.requesterAddress === address; +export function isGrantedAccess(address: ValidAccountId | undefined, loc: LocData): boolean { + return loc.ownerAccountId.equals(address) || (loc.requesterAccountId?.equals(address) || false); } diff --git a/src/common/PendingVaultTransferRequests.tsx b/src/common/PendingVaultTransferRequests.tsx index 63b6a1f6..38deeedf 100644 --- a/src/common/PendingVaultTransferRequests.tsx +++ b/src/common/PendingVaultTransferRequests.tsx @@ -1,5 +1,5 @@ import { useMemo, useState } from "react"; -import { Lgnt } from "@logion/node-api"; +import { Lgnt, ValidAccountId } from "@logion/node-api"; import { VaultTransferRequest } from "@logion/client"; import AmountCell from "./AmountCell"; @@ -35,7 +35,7 @@ export default function PendingVaultTransferRequests() { columns={[ { header: "Legal Officer", - render: request => , + render: request => , align: 'left', renderDetails: request => , }, diff --git a/src/common/RequestToCancel.tsx b/src/common/RequestToCancel.tsx index 88d93eba..f998211e 100644 --- a/src/common/RequestToCancel.tsx +++ b/src/common/RequestToCancel.tsx @@ -1,5 +1,6 @@ import React, { useCallback } from "react"; import { VaultState, VaultTransferRequest } from "@logion/client"; +import { ValidAccountId } from "@logion/node-api"; import Dialog from "./Dialog"; import ExtrinsicSubmissionStateView from "src/ExtrinsicSubmissionStateView"; @@ -24,7 +25,7 @@ export default function RequestToCancel(props: Props) { await mutateVaultState(async (vaultState: VaultState) => { if(client && props.requestToCancel !== null && signer) { return vaultState.cancelVaultTransferRequest( - client.getLegalOfficer(props.requestToCancel.legalOfficerAddress), + client.getLegalOfficer(ValidAccountId.polkadot(props.requestToCancel.legalOfficerAddress)), props.requestToCancel, signer, callback diff --git a/src/common/Storage.test.ts b/src/common/Storage.test.ts index 073ce90a..1ce1f97a 100644 --- a/src/common/Storage.test.ts +++ b/src/common/Storage.test.ts @@ -17,8 +17,8 @@ describe("Tokens storage", () => { const tokens = new AccountTokens( api.object(), { - "Polkadot:abc": { - value: "token-abc", + "Polkadot:vQxHAE33LeJYV69GCB4o4YcCgnDu8y99u5hy2751fRdxjX9kz": { + value: "token-vQxHAE33LeJYV69GCB4o4YcCgnDu8y99u5hy2751fRdxjX9kz", expirationDateTime: DateTime.fromISO(expirationDateTime, {zone: 'utc'}) } } @@ -26,8 +26,8 @@ describe("Tokens storage", () => { storeTokens(tokens); - expect(JSON.parse(window.localStorage["token.Polkadot:abc"])).toEqual({ - value: "token-abc", + expect(JSON.parse(window.localStorage["token.Polkadot:vQxHAE33LeJYV69GCB4o4YcCgnDu8y99u5hy2751fRdxjX9kz"])).toEqual({ + value: "token-vQxHAE33LeJYV69GCB4o4YcCgnDu8y99u5hy2751fRdxjX9kz", expirationDateTime }); }); @@ -37,8 +37,8 @@ describe("Tokens storage", () => { const tokens = new AccountTokens( api.object(), { - "Polkadot:abc": { - value: "token-abc", + "Polkadot:vQxHAE33LeJYV69GCB4o4YcCgnDu8y99u5hy2751fRdxjX9kz": { + value: "token-vQxHAE33LeJYV69GCB4o4YcCgnDu8y99u5hy2751fRdxjX9kz", expirationDateTime: DateTime.fromISO(expirationDateTime, {zone: 'utc'}) } } @@ -55,8 +55,8 @@ describe("Tokens storage", () => { const tokens = new AccountTokens( api.object(), { - "Polkadot:abc": { - value: "token-abc", + "Polkadot:vQxHAE33LeJYV69GCB4o4YcCgnDu8y99u5hy2751fRdxjX9kz": { + value: "token-vQxHAE33LeJYV69GCB4o4YcCgnDu8y99u5hy2751fRdxjX9kz", expirationDateTime: DateTime.fromISO(expirationDateTime) } } @@ -73,8 +73,8 @@ describe("Tokens storage", () => { const tokens = new AccountTokens( api.object(), { - "Polkadot:abc": { - value: "token-abc", + "Polkadot:vQxHAE33LeJYV69GCB4o4YcCgnDu8y99u5hy2751fRdxjX9kz": { + value: "token-vQxHAE33LeJYV69GCB4o4YcCgnDu8y99u5hy2751fRdxjX9kz", expirationDateTime: DateTime.fromISO(expirationDateTime) } } diff --git a/src/common/Storage.ts b/src/common/Storage.ts index 6017357d..43af1713 100644 --- a/src/common/Storage.ts +++ b/src/common/Storage.ts @@ -33,7 +33,7 @@ const token: MultiStorable = { export function storeTokens(tokens: AccountTokens) { clearTokens(); - for (const address of tokens.addresses) { + for (const address of tokens.accounts) { storeMulti(token, address.toKey(), tokens.get(address)) } } @@ -50,14 +50,8 @@ export function loadTokens(api: LogionNodeApiClass): AccountTokens { class CurrentAddressStorable implements SingleStorable { key = "currentAddress"; - constructor(api: LogionNodeApiClass) { - this.api = api; - } - - private api: LogionNodeApiClass; - fromValue(value: string) { - return ValidAccountId.parseKey(this.api.polkadot, value); + return ValidAccountId.parseKey(value); } toValue(obj: ValidAccountId): string { @@ -65,16 +59,16 @@ class CurrentAddressStorable implements SingleStorable { } } -export function storeCurrentAddress(api: LogionNodeApiClass, address: ValidAccountId) { - storeSingle(new CurrentAddressStorable(api), address) +export function storeCurrentAddress(address: ValidAccountId) { + storeSingle(new CurrentAddressStorable(), address) } -export function clearCurrentAddress(api: LogionNodeApiClass) { - clearSingle(new CurrentAddressStorable(api)); +export function clearCurrentAddress() { + clearSingle(new CurrentAddressStorable()); } -export function loadCurrentAddress(api: LogionNodeApiClass): ValidAccountId | undefined { - return loadSingle(new CurrentAddressStorable(api)); +export function loadCurrentAddress(): ValidAccountId | undefined { + return loadSingle(new CurrentAddressStorable()); } const sofParams: SingleStorable = newSingleJsonStorable("SofParams") diff --git a/src/common/SubmitterName.test.tsx b/src/common/SubmitterName.test.tsx index e2281b42..a4ee179a 100644 --- a/src/common/SubmitterName.test.tsx +++ b/src/common/SubmitterName.test.tsx @@ -1,33 +1,33 @@ import { shallowRender } from "../tests"; import SubmitterName from "./SubmitterName"; import { DEFAULT_LEGAL_OFFICER, DEFAULT_IDENTITY } from "./TestData"; -import { mockValidPolkadotAccountId } from 'src/__mocks__/LogionMock'; import { LocData } from "@logion/client"; +import { ValidAccountId } from "@logion/node-api"; jest.mock('../logion-chain'); describe("SubmitterName", () => { - const REQUESTER = mockValidPolkadotAccountId("5H17oaxYsRpV18tYjMMbozN84JAVgG6MH5pNWjisGYDtc9WR"); - const ISSUER = "5DtGNqi7yp5TqRcPckYVZh5XqdaSKE9rsDur5xur4tkmBAhB"; + const REQUESTER = ValidAccountId.polkadot("5H17oaxYsRpV18tYjMMbozN84JAVgG6MH5pNWjisGYDtc9WR"); + const ISSUER = ValidAccountId.polkadot("5DtGNqi7yp5TqRcPckYVZh5XqdaSKE9rsDur5xur4tkmBAhB"); const loc = { - ownerAddress: DEFAULT_LEGAL_OFFICER.address, - requesterAddress: REQUESTER, + ownerAccountId: DEFAULT_LEGAL_OFFICER, + requesterAccountId: REQUESTER, userIdentity: DEFAULT_IDENTITY, issuers: [ { - address: ISSUER, + account: ISSUER, firstName: "Scott", lastName: "Tiger", } ] } as unknown as LocData; it("renders when submitter is Legal Officer", () => { - const tree = shallowRender(); + const tree = shallowRender(); expect(tree).toMatchSnapshot() }) it("renders when submitter is Requester", () => { - const tree = shallowRender(); + const tree = shallowRender(); expect(tree).toMatchSnapshot() }) diff --git a/src/common/SubmitterName.tsx b/src/common/SubmitterName.tsx index 994ba90d..210e1594 100644 --- a/src/common/SubmitterName.tsx +++ b/src/common/SubmitterName.tsx @@ -1,4 +1,5 @@ import { LocData, VerifiedIssuer } from "@logion/client"; +import { ValidAccountId } from "@logion/node-api"; import { Cell } from "./Table"; import LegalOfficerName from "./LegalOfficerNameCell"; import Icon from "./Icon"; @@ -7,7 +8,7 @@ import Tooltip from "react-bootstrap/Tooltip"; export interface Props { loc: LocData - submitter: string | undefined; + submitter: ValidAccountId | undefined; } interface Identity { @@ -15,17 +16,17 @@ interface Identity { lastName: string; } -function format(identity: Identity | undefined, address: string | undefined): string { - return identity ? identity.firstName + " " + identity.lastName : address || "-"; +function format(identity: Identity | undefined, account: ValidAccountId | undefined): string { + return identity ? identity.firstName + " " + identity.lastName : account?.address || "-"; } -function findIssuer(loc: LocData, address: string): VerifiedIssuer | undefined { - return loc.issuers.find(issuer => issuer.address === address); +function findIssuer(loc: LocData, account: ValidAccountId): VerifiedIssuer | undefined { + return loc.issuers.find(issuer => issuer.account.equals(account)); } export default function SubmitterName(props: Props) { const { loc, submitter } = props; - if (submitter === loc.ownerAddress) { + if (submitter && loc.ownerAccountId.equals(submitter)) { return ( ) @@ -36,7 +37,7 @@ export default function SubmitterName(props: Props) {
{ format(identity, submitter) } { - submitter && submitter !== loc.requesterAddress?.address && + submitter && !submitter.equals(loc.requesterAccountId) && }
@@ -46,8 +47,8 @@ export default function SubmitterName(props: Props) { } } -function getIdentity(submitter: string | undefined, loc: LocData): Identity | undefined { - if(submitter === loc.requesterAddress?.address) { +function getIdentity(submitter: ValidAccountId | undefined, loc: LocData): Identity | undefined { + if(submitter?.equals(loc.requesterAccountId)) { return loc.userIdentity; } else if(submitter) { return findIssuer(loc, submitter); diff --git a/src/common/TestData.ts b/src/common/TestData.ts index 5df34a7a..6628b5d9 100644 --- a/src/common/TestData.ts +++ b/src/common/TestData.ts @@ -1,11 +1,12 @@ import { LegalOfficer, PostalAddress, UserIdentity } from '@logion/client'; import { LegalOfficerClass } from "@logion/client/dist/Types.js"; -import { Transaction } from '@logion/client/dist/TransactionClient.js'; +import { Transaction } from '@logion/client'; import { Coin, CoinBalance, Numbers, Lgnt } from '@logion/node-api'; import { ColorTheme, rgbaToHex } from './ColorTheme'; import { DEFAULT_LEGAL_OFFICER, ANOTHER_LEGAL_OFFICER, A_THIRD_LEGAL_OFFICER } from "../__mocks__/LogionMock"; +import { TEST_WALLET_USER, TEST_WALLET_USER2 } from 'src/wallet-user/TestData'; export { DEFAULT_LEGAL_OFFICER, ANOTHER_LEGAL_OFFICER, A_THIRD_LEGAL_OFFICER }; export const DEFAULT_IDENTITY: UserIdentity = { @@ -135,8 +136,8 @@ export const DEFAULT_COIN_BALANCE: CoinBalance = { export const DEFAULT_TRANSACTION: Transaction = { id: "id", - from: "from", - to: "to", + from: TEST_WALLET_USER, + to: TEST_WALLET_USER2, pallet: "pallet", method: "method", transferValue: "420", @@ -165,7 +166,7 @@ export const DEFAULT_FAILED_TRANSACTION:Transaction = { export const PATRICK: LegalOfficer = { name: "Patrick Gielen", - address: DEFAULT_LEGAL_OFFICER.address, + account: DEFAULT_LEGAL_OFFICER, additionalDetails: "", userIdentity: { firstName: "Patrick", @@ -188,7 +189,7 @@ export const PATRICK: LegalOfficer = { export const GUILLAUME: LegalOfficer = { name: "Guillaume Grain", - address: ANOTHER_LEGAL_OFFICER.address, + account: ANOTHER_LEGAL_OFFICER, additionalDetails: "", userIdentity: { firstName: "Patrick", @@ -211,7 +212,7 @@ export const GUILLAUME: LegalOfficer = { export const ALAIN: LegalOfficer = { name: "Alain Barland", - address: A_THIRD_LEGAL_OFFICER.address, + account: A_THIRD_LEGAL_OFFICER, additionalDetails: "", userIdentity: { firstName: "Patrick", diff --git a/src/common/TransactionType.test.tsx b/src/common/TransactionType.test.tsx index e5097892..100afd3d 100644 --- a/src/common/TransactionType.test.tsx +++ b/src/common/TransactionType.test.tsx @@ -1,6 +1,7 @@ +import { TEST_WALLET_USER } from "src/wallet-user/TestData"; import { shallowRender } from "../tests"; import TransactionType from "./TransactionType"; -import { Transaction } from "@logion/client/dist/TransactionClient.js"; +import { Transaction } from "@logion/client"; describe("TransactionType", () => { @@ -10,7 +11,7 @@ describe("TransactionType", () => { method: "addCollectionItem", type: "EXTRINSIC", } as Transaction; - const result = shallowRender(); + const result = shallowRender(); expect(result).toMatchSnapshot(); }) @@ -20,7 +21,7 @@ describe("TransactionType", () => { method: "unknownMethod", type: "EXTRINSIC", } as Transaction; - const result = shallowRender(); + const result = shallowRender(); expect(result).toMatchSnapshot(); }) }) diff --git a/src/common/TransactionType.tsx b/src/common/TransactionType.tsx index ded1b2a0..92774438 100644 --- a/src/common/TransactionType.tsx +++ b/src/common/TransactionType.tsx @@ -1,4 +1,5 @@ import { Transaction } from "@logion/client"; +import { ValidAccountId } from "@logion/node-api"; import { Cell } from "./Table"; import { @@ -14,8 +15,8 @@ import { WalletType } from "./Transactions"; export interface Props { transaction: Transaction; walletType: WalletType; - vaultAddress?: string; - address: string; + vaultAccount?: ValidAccountId; + account?: ValidAccountId; } type FormerLogionLocMethod = "createLoc"; @@ -111,9 +112,9 @@ export default function TransactionType(props: Props) { export function buildTransactionType(props: Props): string { let baseType; if(props.walletType === "Wallet") { - baseType = enrichTransactionType(props.transaction, props.address, props.vaultAddress); + baseType = enrichTransactionType(props.transaction, props.account, props.vaultAccount); } else { - baseType = transactionType(props.transaction, props.address); + baseType = transactionType(props.transaction, props.account); } if(props.transaction.type === "EXTRINSIC" || props.transaction.type === "VAULT_OUT") { return baseType; @@ -126,22 +127,22 @@ export function buildTransactionType(props: Props): string { } } -function enrichTransactionType(transaction: Transaction, address: string, vaultAddress?: string): string { - if (transaction.transferDirection === 'Sent' && transaction.to === vaultAddress) { +function enrichTransactionType(transaction: Transaction, account?: ValidAccountId, vaultAccount?: ValidAccountId): string { + if (transaction.transferDirection === 'Sent' && transaction.to === vaultAccount?.address) { return "Sent to my vault" } else { - return transactionType(transaction, address); + return transactionType(transaction, account); } } -export function transactionType(transaction: Transaction, address: string): string { +export function transactionType(transaction: Transaction, account?: ValidAccountId): string { const palletMethods = allMethods[transaction.pallet]; if (palletMethods !== undefined && palletMethods[transaction.method] !== undefined) { return palletMethods[transaction.method] } else { if (transaction.pallet === "balances") { if (transaction.method.startsWith("transfer")) { - if (transaction.from === address) { + if (transaction.from.equals(account)) { return "Sent"; } else { return "Received"; diff --git a/src/common/Transactions.test.tsx b/src/common/Transactions.test.tsx index 7046dc1d..9eb8d1ef 100644 --- a/src/common/Transactions.test.tsx +++ b/src/common/Transactions.test.tsx @@ -8,10 +8,11 @@ import { setBalanceState } from './__mocks__/CommonContextMock'; import { setParams } from '../__mocks__/ReactRouterMock'; import { DEFAULT_COIN_BALANCE, DEFAULT_TRANSACTION, DEFAULT_FAILED_TRANSACTION } from './TestData'; import { BalanceState } from '@logion/client/dist/Balance.js'; +import { TEST_WALLET_USER } from 'src/wallet-user/TestData'; test('renders null with missing data', () => { const result = shallowRender( { transactions: [ DEFAULT_TRANSACTION ], } as BalanceState); const result = shallowRender( { transactions: [ DEFAULT_FAILED_TRANSACTION ], } as BalanceState); const result = shallowRender( - + ); } interface ContentProps { - address: string, + account?: ValidAccountId, balances: CoinBalance[], transactions: Transaction[], type: WalletType, - vaultAddress?: string, + vaultAccount?: ValidAccountId, } function Content(props: ContentProps) { - const { address, balances, transactions, type, vaultAddress } = props; + const { account, balances, transactions, type, vaultAccount } = props; const { coinId } = useParams<"coinId">(); const { width } = useResponsiveContext(); @@ -108,11 +108,11 @@ function Content(props: ContentProps) { { header: , render: transaction => , + to={ transaction.to || null } />, }, { header: "Transaction type", - render: transaction => , + render: transaction => , width: width({ onSmallScreen: "180px", otherwise: "250px" @@ -120,7 +120,7 @@ function Content(props: ContentProps) { }, { header: "Amount", - render: transaction => , + render: transaction => , align: 'right', width: width({ onSmallScreen: "100px", @@ -132,7 +132,7 @@ function Content(props: ContentProps) { if(props.type === 'Wallet') { columns.push({ header: "Paid fees", - render: transaction => , + render: transaction => , align: 'right', width: width({ onSmallScreen: "80px", @@ -152,8 +152,8 @@ function Content(props: ContentProps) {

- { props.address } - + { props.account?.address || "" } +

@@ -181,10 +181,10 @@ function Content(props: ContentProps) { > @@ -228,8 +228,8 @@ function FromToHeader() { } interface FromToCellProps { - from: string, - to: string | null, + from: ValidAccountId, + to: ValidAccountId | null, } function FromToCell(props: FromToCellProps) { @@ -239,23 +239,23 @@ function FromToCell(props: FromToCellProps) { placement="bottom" delay={ 500 } overlay={ - - { props.from } + + { props.from.address } } > - { props.from } + { props.from.address } - { props.to } + + { props.to?.address } } > - { props.to !== null ? props.to : "-" } + { props.to !== null ? props.to.address : "-" } ); diff --git a/src/common/TransferAmountCell.tsx b/src/common/TransferAmountCell.tsx index 26cd6092..3402b082 100644 --- a/src/common/TransferAmountCell.tsx +++ b/src/common/TransferAmountCell.tsx @@ -1,5 +1,5 @@ -import { Transaction } from "@logion/client/dist/TransactionClient.js"; -import { Lgnt, LgntFormatter } from "@logion/node-api"; +import { Transaction } from "@logion/client"; +import { Lgnt, LgntFormatter, ValidAccountId } from "@logion/node-api"; import { GREEN, RED } from "./ColorTheme"; import Icon from "./Icon"; @@ -46,27 +46,27 @@ export default function TransferAmountCell(props: Props) { } } -export function transferBalance(address: string, transaction: Transaction): Lgnt { +export function transferBalance(account: ValidAccountId | undefined, transaction: Transaction): Lgnt { const amount = Lgnt.fromCanonical(BigInt(transaction.transferValue)); - if(transaction.from === address) { + if(transaction.from.equals(account)) { return amount.negate(); } else { return amount; } } -export function fees(address: string, transaction: Transaction): Lgnt { +export function fees(account: ValidAccountId | undefined, transaction: Transaction): Lgnt { const amount = toFeesClass(transaction.fees)?.totalFee || Lgnt.zero(); - if(transaction.from === address) { + if(transaction.from.equals(account)) { return amount; } else { return Lgnt.zero(); } } -export function deposit(address: string, transaction: Transaction): Lgnt { +export function deposit(account: ValidAccountId | undefined, transaction: Transaction): Lgnt { const amount = Lgnt.fromCanonical(BigInt(transaction.reserved)); - if(transaction.from === address) { + if(transaction.from.equals(account)) { return amount; } else { return Lgnt.zero(); diff --git a/src/common/ViewFileButton.tsx b/src/common/ViewFileButton.tsx index 9c4a60cd..5a0044fb 100644 --- a/src/common/ViewFileButton.tsx +++ b/src/common/ViewFileButton.tsx @@ -8,6 +8,7 @@ import './ViewFileButton.css'; import { Children, customClassName } from "./types/Helpers"; import { useLogionChain, AxiosFactory } from "../logion-chain"; import { MimeType, Token, TypedFile } from "@logion/client"; +import { ValidAccountId } from "@logion/node-api"; import { useCallback, useMemo, useState } from "react"; import { OverlayTrigger, Tooltip } from "react-bootstrap"; @@ -17,7 +18,7 @@ export interface FileInfo { } export interface ViewFileProps extends FileInfo { - nodeOwner: string; + nodeOwner: ValidAccountId; token?: Token; children?: Children; limitIconSize?: boolean; @@ -105,7 +106,7 @@ export default function ViewFileButton(props: ViewFileProps) { } export interface DownloadFilesParams { - nodeOwner: string; + nodeOwner: ValidAccountId; files: FileInfo[]; axiosFactory: AxiosFactory } diff --git a/src/common/WalletGauge.tsx b/src/common/WalletGauge.tsx index 89d7703a..6d57671e 100644 --- a/src/common/WalletGauge.tsx +++ b/src/common/WalletGauge.tsx @@ -1,7 +1,7 @@ import { useState, useCallback, useMemo, useEffect } from 'react'; import { Form, Spinner, InputGroup, DropdownButton, Dropdown } from 'react-bootstrap'; import { BalanceState } from '@logion/client'; -import { Numbers, CoinBalance, Lgnt } from '@logion/node-api'; +import { Numbers, CoinBalance, Lgnt, ValidAccountId } from '@logion/node-api'; import { CallCallback, useLogionChain } from '../logion-chain'; @@ -20,7 +20,7 @@ import VaultOutRequest from 'src/vault/VaultOutRequest'; export interface Props { balance: CoinBalance, - vaultAddress?: string, + vaultAccount?: ValidAccountId, sendButton: boolean, sendToVault: boolean, withdrawFromVault: boolean, @@ -45,14 +45,14 @@ export default function WalletGauge(props: Props) { const [ amount, setAmount ] = useState(""); const [ unit, setUnit ] = useState(Numbers.NONE); const [ transferDialogState, setTransferDialogState ] = useState(HIDDEN_DIALOG); - const { vaultAddress, sendButton } = props; + const { vaultAccount, sendButton } = props; const transfer = useMemo(() => { return async (callback: CallCallback) => { await mutateBalanceState(async (state: BalanceState) => { return await state.transfer({ amount: Lgnt.fromPrefixedNumber(new Numbers.PrefixedNumber(amount, unit)), - destination, + destination: ValidAccountId.polkadot(destination), callback, signer: signer! }); @@ -115,9 +115,9 @@ export default function WalletGauge(props: Props) { } { - props.sendToVault && vaultAddress !== undefined && + props.sendToVault && vaultAccount !== undefined &&