From 85e0497e15530f85e7ff3ceab58919ae090dde98 Mon Sep 17 00:00:00 2001 From: Branko Bosnic Date: Tue, 16 Jan 2024 11:33:08 +0100 Subject: [PATCH] fix: format --- api/src/routes/nova/block/get.ts | 5 +- api/src/routes/nova/block/metadata/get.ts | 5 +- client/src/app/components/nova/Input.tsx | 23 +--- client/src/app/components/nova/Unlocks.tsx | 102 +++++++-------- .../payload/SignedTransactionPayload.tsx | 11 +- .../nova/block/payload/TaggedDataPayload.tsx | 17 +-- .../block/section/BlockPayloadSection.tsx | 46 +++---- .../section/TransactionMetadataSection.tsx | 29 ++--- client/src/app/routes.tsx | 15 +-- client/src/app/routes/nova/Block.tsx | 123 +++++++----------- client/src/helpers/nova/hooks/useBlock.ts | 32 +++-- .../helpers/nova/hooks/useBlockMetadata.ts | 16 +-- .../helpers/nova/hooks/useInputsAndOutputs.ts | 21 +-- client/src/helpers/nova/transactionsHelper.ts | 91 +++++++------ client/src/models/api/nova/IInput.ts | 1 - client/src/models/api/nova/IOutput.ts | 1 - .../models/api/nova/block/IBlockMetadata.ts | 1 - .../models/api/nova/block/IBlockRequest.ts | 1 - .../models/api/nova/block/IBlockResponse.ts | 1 - 19 files changed, 219 insertions(+), 322 deletions(-) diff --git a/api/src/routes/nova/block/get.ts b/api/src/routes/nova/block/get.ts index 61e71b230..8fb82a0d3 100644 --- a/api/src/routes/nova/block/get.ts +++ b/api/src/routes/nova/block/get.ts @@ -13,10 +13,7 @@ import { ValidationHelper } from "../../../utils/validationHelper"; * @param request The request. * @returns The response. */ -export async function get( - _: IConfiguration, - request: IBlockRequest -): Promise { +export async function get(_: IConfiguration, request: IBlockRequest): Promise { const networkService = ServiceFactory.get("network"); const networks = networkService.networkNames(); ValidationHelper.oneOf(request.network, networks, "network"); diff --git a/api/src/routes/nova/block/metadata/get.ts b/api/src/routes/nova/block/metadata/get.ts index 2850ceb93..487aec349 100644 --- a/api/src/routes/nova/block/metadata/get.ts +++ b/api/src/routes/nova/block/metadata/get.ts @@ -13,10 +13,7 @@ import { ValidationHelper } from "../../../../utils/validationHelper"; * @param request The request. * @returns The response. */ -export async function get( - _: IConfiguration, - request: IBlockRequest -): Promise { +export async function get(_: IConfiguration, request: IBlockRequest): Promise { const networkService = ServiceFactory.get("network"); const networks = networkService.networkNames(); ValidationHelper.oneOf(request.network, networks, "network"); diff --git a/client/src/app/components/nova/Input.tsx b/client/src/app/components/nova/Input.tsx index 399f557e9..0b5a58600 100644 --- a/client/src/app/components/nova/Input.tsx +++ b/client/src/app/components/nova/Input.tsx @@ -33,10 +33,7 @@ const Input: React.FC = ({ input, network }) => { const fallbackInputView = ( -
setIsExpanded(!isExpanded)} - > +
setIsExpanded(!isExpanded)}>
@@ -45,7 +42,7 @@ const Input: React.FC = ({ input, network }) => {
{input.amount && ( { + onClick={(e) => { setIsFormattedBalance(!isFormattedBalance); e.stopPropagation(); }} @@ -72,26 +69,20 @@ const Input: React.FC = ({ input, network }) => {
Transaction Id
- + {input.transactionId}
Transaction Output Index
{input.transactionInputIndex}
-
)} + + )} ); - const outputId = Utils.computeOutputId( - input.transactionId, input.transactionInputIndex - ); + const outputId = Utils.computeOutputId(input.transactionId, input.transactionInputIndex); - return input.output ? - : fallbackInputView; + return input.output ? : fallbackInputView; }; export default Input; diff --git a/client/src/app/components/nova/Unlocks.tsx b/client/src/app/components/nova/Unlocks.tsx index 03899dd6d..38161f2c2 100644 --- a/client/src/app/components/nova/Unlocks.tsx +++ b/client/src/app/components/nova/Unlocks.tsx @@ -1,4 +1,14 @@ -import { AccountUnlock, AnchorUnlock, EmptyUnlock, MultiUnlock, NftUnlock, ReferenceUnlock, SignatureUnlock, Unlock, UnlockType } from "@iota/sdk-wasm-nova/web"; +import { + AccountUnlock, + AnchorUnlock, + EmptyUnlock, + MultiUnlock, + NftUnlock, + ReferenceUnlock, + SignatureUnlock, + Unlock, + UnlockType, +} from "@iota/sdk-wasm-nova/web"; import classNames from "classnames"; import React, { useState } from "react"; import DropdownIcon from "~assets/dropdown-arrow.svg?react"; @@ -39,75 +49,65 @@ const Unlocks: React.FC = ({ unlocks }) => { return (
-
setIsExpanded(!isExpanded)} - className="card--value card-header--wrapper" - > +
setIsExpanded(!isExpanded)} className="card--value card-header--wrapper">
- +
- { - isExpanded && ( -
- {unlocks.map((unlock, idx) => { - if (unlock.type === UnlockType.Signature) { + {isExpanded && ( +
+ {unlocks.map((unlock, idx) => { + if (unlock.type === UnlockType.Signature) { const signatureUnlock = unlock as SignatureUnlock; return (
- {displayUnlocksTypeAndIndex(unlock.type, idx)} -
- Public Key: -
- + {displayUnlocksTypeAndIndex(unlock.type, idx)} +
+ Public Key: +
+ +
-
-
- Signature: -
- +
+ Signature: +
+ +
-
); - } else if (unlock.type === UnlockType.Multi) { - const multiUnlock = unlock as MultiUnlock; + } else if (unlock.type === UnlockType.Multi) { + const multiUnlock = unlock as MultiUnlock; - return ; - } - else if (unlock.type === UnlockType.Empty) { - return ( -
- {displayUnlocksTypeAndIndex(unlock.type, idx)} -
- ); - } - else { - const referencedUnlock = unlock as UnlockTypeMap[typeof unlock.type]; + return ; + } else if (unlock.type === UnlockType.Empty) { + return ( +
+ {displayUnlocksTypeAndIndex(unlock.type, idx)} +
+ ); + } else { + const referencedUnlock = unlock as UnlockTypeMap[typeof unlock.type]; - return ( -
- {displayUnlocksTypeAndIndex(unlock.type, idx)} -
- References unlock at index: - {referencedUnlock.reference} -
+ return ( +
+ {displayUnlocksTypeAndIndex(unlock.type, idx)} +
+ References unlock at index: + {referencedUnlock.reference}
- ); - } - })} -
- ) - } +
+ ); + } + })} +
+ )}
); }; export default Unlocks; - diff --git a/client/src/app/components/nova/block/payload/SignedTransactionPayload.tsx b/client/src/app/components/nova/block/payload/SignedTransactionPayload.tsx index 5e93415bd..553ada80d 100644 --- a/client/src/app/components/nova/block/payload/SignedTransactionPayload.tsx +++ b/client/src/app/components/nova/block/payload/SignedTransactionPayload.tsx @@ -13,11 +13,9 @@ interface SignedTransactionPayloadProps { readonly header?: string; } -const SignedTransactionPayload: React.FC = ( - { payload, inputs, header } -) => { +const SignedTransactionPayload: React.FC = ({ payload, inputs, header }) => { const { networkId, outputs } = payload.transaction; - const transactionId = Utils.transactionId(payload) + const transactionId = Utils.transactionId(payload); return (
@@ -37,7 +35,9 @@ const SignedTransactionPayload: React.FC = ( {inputs.length}
- {inputs.map((input, idx) => )} + {inputs.map((input, idx) => ( + + ))}
@@ -71,4 +71,3 @@ SignedTransactionPayload.defaultProps = { }; export default SignedTransactionPayload; - diff --git a/client/src/app/components/nova/block/payload/TaggedDataPayload.tsx b/client/src/app/components/nova/block/payload/TaggedDataPayload.tsx index 8c893dc36..defb6b430 100644 --- a/client/src/app/components/nova/block/payload/TaggedDataPayload.tsx +++ b/client/src/app/components/nova/block/payload/TaggedDataPayload.tsx @@ -1,4 +1,4 @@ -import { TaggedDataPayload as ITaggedDataPayload} from "@iota/sdk-wasm-nova/web"; +import { TaggedDataPayload as ITaggedDataPayload } from "@iota/sdk-wasm-nova/web"; import React from "react"; import DataToggle from "~/app/components/DataToggle"; @@ -6,9 +6,7 @@ interface TaggedDataPayloadProps { readonly payload: ITaggedDataPayload; } -const TaggedDataPayload: React.FC = ( - { payload } -) => { +const TaggedDataPayload: React.FC = ({ payload }) => { const { tag, data } = payload; return ( @@ -19,10 +17,7 @@ const TaggedDataPayload: React.FC = (
Tag
- + )} {data && ( @@ -30,10 +25,7 @@ const TaggedDataPayload: React.FC = (
Data
- + )}
@@ -46,4 +38,3 @@ TaggedDataPayload.defaultProps = { }; export default TaggedDataPayload; - diff --git a/client/src/app/components/nova/block/section/BlockPayloadSection.tsx b/client/src/app/components/nova/block/section/BlockPayloadSection.tsx index 374de777d..4bfb2791b 100644 --- a/client/src/app/components/nova/block/section/BlockPayloadSection.tsx +++ b/client/src/app/components/nova/block/section/BlockPayloadSection.tsx @@ -1,7 +1,9 @@ import { - Block, PayloadType, SignedTransactionPayload as ISignedTransactionPayload, + Block, + PayloadType, + SignedTransactionPayload as ISignedTransactionPayload, TaggedDataPayload as ITaggedDataPayload, - BasicBlockBody + BasicBlockBody, } from "@iota/sdk-wasm-nova/web"; import React from "react"; import { IInput } from "~models/api/nova/IInput"; @@ -16,52 +18,35 @@ interface BlockPayloadSectionProps { readonly transferTotal?: number; } -const BlockPayloadSection: React.FC = ( - { block, inputs, outputs, transferTotal } -) => { - const payload = (block.body as BasicBlockBody).payload - if ( - payload?.type === PayloadType.SignedTransaction && - inputs && outputs && transferTotal !== undefined - ) { - const transactionPayload = payload as ISignedTransactionPayload; +const BlockPayloadSection: React.FC = ({ block, inputs, outputs, transferTotal }) => { + const payload = (block.body as BasicBlockBody).payload; + if (payload?.type === PayloadType.SignedTransaction && inputs && outputs && transferTotal !== undefined) { + const transactionPayload = payload as ISignedTransactionPayload; const transaction = transactionPayload.transaction; return (
- +
- { - transaction.payload?.type === PayloadType.TaggedData && + {transaction.payload?.type === PayloadType.TaggedData && (
- +
- } + )}
); - } else if ( - payload?.type === PayloadType.CandidacyAnnouncement - ) { + } else if (payload?.type === PayloadType.CandidacyAnnouncement) { return (
{/* todo */} CandidacyAnnouncement
); - } else if ( - payload?.type === PayloadType.TaggedData - ) { + } else if (payload?.type === PayloadType.TaggedData) { return (
- +
); } @@ -76,4 +61,3 @@ BlockPayloadSection.defaultProps = { }; export default BlockPayloadSection; - diff --git a/client/src/app/components/nova/block/section/TransactionMetadataSection.tsx b/client/src/app/components/nova/block/section/TransactionMetadataSection.tsx index 8ebfd18bd..7d3098f24 100644 --- a/client/src/app/components/nova/block/section/TransactionMetadataSection.tsx +++ b/client/src/app/components/nova/block/section/TransactionMetadataSection.tsx @@ -10,36 +10,26 @@ interface TransactionMetadataSectionProps { readonly isLinksDisabled: boolean; } -const TransactionMetadataSection: React.FC = ( - { network, metadata, metadataError, isLinksDisabled } -) => ( +const TransactionMetadataSection: React.FC = ({ network, metadata, metadataError, isLinksDisabled }) => (
- {!metadata && !metadataError && ()} - {metadataError && ( -

Failed to retrieve metadata. {metadataError}

- )} + {!metadata && !metadataError && } + {metadataError &&

Failed to retrieve metadata. {metadataError}

} {metadata && !metadataError && (
-
- Transaction Id -
+
Transaction Id
-
-
- Transaction Status -
-
- {metadata.transactionState} -
+
Transaction Status
+
{metadata.transactionState}
{metadata.transactionFailureReason && (
@@ -55,8 +45,7 @@ const TransactionMetadataSection: React.FC = ( TransactionMetadataSection.defaultProps = { metadata: undefined, - metadataError: undefined + metadataError: undefined, }; export default TransactionMetadataSection; - diff --git a/client/src/app/routes.tsx b/client/src/app/routes.tsx index edcb544b3..178b4c892 100644 --- a/client/src/app/routes.tsx +++ b/client/src/app/routes.tsx @@ -167,18 +167,9 @@ const buildAppRoutes = (protocolVersion: string, withNetworkContext: (wrappedCom ]; const novaRoutes = [ - , - , - , + , + , + , ]; return ( diff --git a/client/src/app/routes/nova/Block.tsx b/client/src/app/routes/nova/Block.tsx index 96cde4611..f22b92ad5 100644 --- a/client/src/app/routes/nova/Block.tsx +++ b/client/src/app/routes/nova/Block.tsx @@ -1,4 +1,3 @@ - import React, { useState } from "react"; import { RouteComponentProps } from "react-router-dom"; import mainHeaderMessage from "~assets/modals/stardust/block/main-header.json"; @@ -33,9 +32,12 @@ export interface BlockProps { blockId: string; } -const Block: React.FC> = ( - { history, match: { params: { network, blockId } } } -) => { +const Block: React.FC> = ({ + history, + match: { + params: { network, blockId }, + }, +}) => { const { networkInfo } = useNetworkInfoNova(); const [isFormattedBalance, setIsFormattedBalance] = useState(true); const [block, isLoading, blockError] = useBlock(network, blockId); @@ -45,18 +47,18 @@ const Block: React.FC> = ( function isBasicBlockBody(body: BasicBlockBody | ValidationBlockBody): body is BasicBlockBody { return body.type === BlockBodyType.Basic; } - let blockBody: BasicBlockBody | ValidationBlockBody | undefined + let blockBody: BasicBlockBody | ValidationBlockBody | undefined; let pageTitle = "Block"; switch (block?.body?.type) { case BlockBodyType.Basic: { pageTitle = `Basic ${pageTitle}`; - blockBody = block?.body as BasicBlockBody + blockBody = block?.body as BasicBlockBody; break; } case BlockBodyType.Validation: { pageTitle = `Validation ${pageTitle}`; - blockBody = block?.body as ValidationBlockBody + blockBody = block?.body as ValidationBlockBody; break; } default: { @@ -74,10 +76,10 @@ const Block: React.FC> = ( inputs={inputs ?? undefined} outputs={outputs ?? undefined} transferTotal={transferTotal ?? undefined} - /> + />, ); } - + if (blockMetadata.metadata?.transactionMetadata) { tabbedSections.push( > = ( network={network} metadata={blockMetadata.metadata?.transactionMetadata} isLinksDisabled={false} - /> + />, ); } - - + const blockContent = block ? (
@@ -98,51 +99,37 @@ const Block: React.FC> = (
-
- Block ID -
+
Block ID
-
- Issuing Time -
+
Issuing Time
{/* Convert nanoseconds to milliseconds */} {DateHelper.formatShort(Number(block.header.issuingTime) / 1000000)}
-
- Slot commitment -
+
Slot commitment
-
- Issuer -
+
Issuer
- +
{blockBody?.strongParents && (
-
- Strong Parents -
+
Strong Parents
{blockBody.strongParents.map((parent, idx) => ( -
+
> = ( )} {blockBody?.weakParents && (
-
- Weak Parents -
+
Weak Parents
{blockBody.weakParents.map((child, idx) => ( -
+
> = (
{blockBody && isBasicBlockBody(blockBody) && (
- {blockBody.payload?.type === PayloadType.SignedTransaction && - transferTotal !== null && ( + {blockBody.payload?.type === PayloadType.SignedTransaction && transferTotal !== null && (
-
- Amount transacted -
+
Amount transacted
- setIsFormattedBalance(!isFormattedBalance)} - className="pointer margin-r-5" - > - {formatAmount( - transferTotal, - networkInfo.tokenInfo, - !isFormattedBalance - )} + setIsFormattedBalance(!isFormattedBalance)} className="pointer margin-r-5"> + {formatAmount(transferTotal, networkInfo.tokenInfo, !isFormattedBalance)}
@@ -197,23 +168,25 @@ const Block: React.FC> = ( {tabbedSections} @@ -231,16 +204,11 @@ const Block: React.FC> = (
-

- {pageTitle} -

+

{pageTitle}

- +
@@ -268,4 +236,3 @@ const Block: React.FC> = ( }; export default Block; - diff --git a/client/src/helpers/nova/hooks/useBlock.ts b/client/src/helpers/nova/hooks/useBlock.ts index 177b16477..d94e63db4 100644 --- a/client/src/helpers/nova/hooks/useBlock.ts +++ b/client/src/helpers/nova/hooks/useBlock.ts @@ -12,12 +12,7 @@ import { HexHelper } from "~/helpers/stardust/hexHelper"; * @param blockId The block id * @returns The block, loading bool and an error message. */ -export function useBlock(network: string, blockId: string | null): - [ - Block | null, - boolean, - string? - ] { +export function useBlock(network: string, blockId: string | null): [Block | null, boolean, string?] { const isMounted = useIsMounted(); const [apiClient] = useState(ServiceFactory.get(`api-client-${NOVA}`)); const [block, setBlock] = useState(null); @@ -30,17 +25,20 @@ export function useBlock(network: string, blockId: string | null): if (blockId) { // eslint-disable-next-line no-void void (async () => { - apiClient.block({ - network, - blockId: HexHelper.addPrefix(blockId) - }).then(response => { - if (isMounted) { - setBlock(response.block ?? null); - setError(response.error); - } - }).finally(() => { - setIsLoading(false); - }); + apiClient + .block({ + network, + blockId: HexHelper.addPrefix(blockId), + }) + .then((response) => { + if (isMounted) { + setBlock(response.block ?? null); + setError(response.error); + } + }) + .finally(() => { + setIsLoading(false); + }); })(); } else { setIsLoading(false); diff --git a/client/src/helpers/nova/hooks/useBlockMetadata.ts b/client/src/helpers/nova/hooks/useBlockMetadata.ts index 7fe23bdcc..558d15cff 100644 --- a/client/src/helpers/nova/hooks/useBlockMetadata.ts +++ b/client/src/helpers/nova/hooks/useBlockMetadata.ts @@ -12,30 +12,26 @@ import { IBlockMetadata } from "~/models/api/nova/block/IBlockMetadata"; * @param blockId The block id * @returns The block metadata and loading bool. */ -export function useBlockMetadata(network: string, blockId: string | null): - [ - IBlockMetadata, - boolean - ] { +export function useBlockMetadata(network: string, blockId: string | null): [IBlockMetadata, boolean] { const isMounted = useIsMounted(); const [apiClient] = useState(ServiceFactory.get(`api-client-${NOVA}`)); - const [blockMetadata, setBlockMetadata] = useState({ metadata: { blockId: blockId ?? '', blockState: "pending"} }); + const [blockMetadata, setBlockMetadata] = useState({ metadata: { blockId: blockId ?? "", blockState: "pending" } }); const [isLoading, setIsLoading] = useState(true); useEffect(() => { let timerId: NodeJS.Timeout | undefined; setIsLoading(true); if (blockId) { - setBlockMetadata({ metadata: { blockId, blockState: "pending"} }); + setBlockMetadata({ metadata: { blockId, blockState: "pending" } }); const fetchMetadata = async () => { try { const details = await apiClient.blockDetails({ network, - blockId: HexHelper.addPrefix(blockId) + blockId: HexHelper.addPrefix(blockId), }); if (isMounted) { - setBlockMetadata({metadata: details?.metadata}); + setBlockMetadata({ metadata: details?.metadata }); if (!details?.metadata) { timerId = setTimeout(async () => { @@ -45,7 +41,7 @@ export function useBlockMetadata(network: string, blockId: string | null): } } catch (error) { if (error instanceof Error && isMounted) { - setBlockMetadata({ metadataError: error.message}); + setBlockMetadata({ metadataError: error.message }); } } finally { setIsLoading(false); diff --git a/client/src/helpers/nova/hooks/useInputsAndOutputs.ts b/client/src/helpers/nova/hooks/useInputsAndOutputs.ts index c655c6072..754f38fb1 100644 --- a/client/src/helpers/nova/hooks/useInputsAndOutputs.ts +++ b/client/src/helpers/nova/hooks/useInputsAndOutputs.ts @@ -15,13 +15,7 @@ import { useNetworkInfoNova } from "~/helpers/nova/networkInfo"; * @param block The block * @returns The inputs, unlocks, outputs, transfer total an a loading bool. */ -export function useInputsAndOutputs(network: string, block: Block | null): - [ - IInput[] | null, - IOutput[] | null, - number | null, - boolean - ] { +export function useInputsAndOutputs(network: string, block: Block | null): [IInput[] | null, IOutput[] | null, number | null, boolean] { const isMounted = useIsMounted(); const [apiClient] = useState(ServiceFactory.get(`api-client-${STARDUST}`)); const { networkInfo } = useNetworkInfoNova(); @@ -36,13 +30,12 @@ export function useInputsAndOutputs(network: string, block: Block | null): if (block && (block?.body as BasicBlockBody).payload?.type === PayloadType.SignedTransaction) { // eslint-disable-next-line no-void void (async () => { - const { inputs, outputs, transferTotal } = - await TransactionsHelper.getInputsAndOutputs( - block, - network, - networkInfo.bech32Hrp, - apiClient - ); + const { inputs, outputs, transferTotal } = await TransactionsHelper.getInputsAndOutputs( + block, + network, + networkInfo.bech32Hrp, + apiClient, + ); if (isMounted) { setInputs(inputs); setOutputs(outputs); diff --git a/client/src/helpers/nova/transactionsHelper.ts b/client/src/helpers/nova/transactionsHelper.ts index 7c98fa656..486d5bdf7 100644 --- a/client/src/helpers/nova/transactionsHelper.ts +++ b/client/src/helpers/nova/transactionsHelper.ts @@ -1,13 +1,23 @@ import { AddressUnlockCondition, BasicBlockBody, - Block, BlockBodyType, CommonOutput, DelegationOutput, GovernorAddressUnlockCondition, + Block, + BlockBodyType, + CommonOutput, + DelegationOutput, + GovernorAddressUnlockCondition, ImmutableAccountAddressUnlockCondition, - InputType,OutputType, PayloadType, + InputType, + OutputType, + PayloadType, SignatureUnlock, SignedTransactionPayload, StateControllerAddressUnlockCondition, - UnlockCondition, UnlockConditionType, UnlockType, Utils, UTXOInput + UnlockCondition, + UnlockConditionType, + UnlockType, + Utils, + UTXOInput, } from "@iota/sdk-wasm-nova/web"; import { IBech32AddressDetails } from "~/models/api/IBech32AddressDetails"; import { IInput } from "~/models/api/nova/IInput"; @@ -24,8 +34,11 @@ interface TransactionInputsAndOutputsResponse { } export class TransactionsHelper { - public static async getInputsAndOutputs(block: Block | undefined, network: string, - _bechHrp: string, apiClient: NovaApiClient + public static async getInputsAndOutputs( + block: Block | undefined, + network: string, + _bechHrp: string, + apiClient: NovaApiClient, ): Promise { const GENESIS_HASH = "0".repeat(64); const inputs: IInput[] = []; @@ -49,31 +62,29 @@ export class TransactionsHelper { if (unlock.type === UnlockType.Signature) { signatureUnlock = unlock as SignatureUnlock; - } - else { + } else { let refUnlockIdx = i; // unlock references can be transitive, // so we need to follow the path until we find the signature do { - const referencedUnlock = unlocks[refUnlockIdx] + const referencedUnlock = unlocks[refUnlockIdx]; if (referencedUnlock.type === UnlockType.Signature) { - signatureUnlock = referencedUnlock as SignatureUnlock + signatureUnlock = referencedUnlock as SignatureUnlock; } else if (referencedUnlock.type === UnlockType.Multi || referencedUnlock.type === UnlockType.Empty) { break; } else { // eslint-disable-next-line @typescript-eslint/no-explicit-any refUnlockIdx = (referencedUnlock as any).reference; } - } while (!signatureUnlock); } if (signatureUnlock) { unlockAddresses.push( Bech32AddressHelper.buildAddress( _bechHrp, - Utils.hexPublicKeyToBech32Address(signatureUnlock.signature.publicKey, _bechHrp) - ) + Utils.hexPublicKeyToBech32Address(signatureUnlock.signature.publicKey, _bechHrp), + ), ); } } @@ -92,10 +103,7 @@ export class TransactionsHelper { const utxoInput = input as UTXOInput; isGenesis = utxoInput.transactionId === GENESIS_HASH; - const outputId = Utils.computeOutputId( - utxoInput.transactionId, - utxoInput.transactionOutputIndex - ); + const outputId = Utils.computeOutputId(utxoInput.transactionId, utxoInput.transactionOutputIndex); const response = await apiClient.outputDetails({ network, outputId }); const details = response.output; @@ -103,7 +111,7 @@ export class TransactionsHelper { if (!response.error && details?.output && details?.metadata) { outputDetails = { output: details.output, - metadata: details.metadata + metadata: details.metadata, }; amount = Number(details.output.amount); } @@ -116,7 +124,7 @@ export class TransactionsHelper { isGenesis, outputId, output: outputDetails, - address + address, }); } } @@ -131,16 +139,18 @@ export class TransactionsHelper { outputs.push({ id: outputId, output, - amount: Number(transaction.outputs[i].amount) + amount: Number(transaction.outputs[i].amount), }); } else { const output = transaction.outputs[i] as CommonOutput; const address: IBech32AddressDetails = TransactionsHelper.bechAddressFromAddressUnlockCondition( - output.unlockConditions, _bechHrp, output.type + output.unlockConditions, + _bechHrp, + output.type, ); - const isRemainder = inputs.some(input => input.address.bech32 === address.bech32); + const isRemainder = inputs.some((input) => input.address.bech32 === address.bech32); if (isRemainder) { remainderOutputs.push({ @@ -148,7 +158,7 @@ export class TransactionsHelper { address, amount: Number(transaction.outputs[i].amount), isRemainder, - output + output, }); } else { outputs.push({ @@ -156,7 +166,7 @@ export class TransactionsHelper { address, amount: Number(transaction.outputs[i].amount), isRemainder, - output + output, }); } @@ -174,7 +184,6 @@ export class TransactionsHelper { return { inputs, outputs: sortedOutputs, unlockAddresses, transferTotal }; } - /** * Sort inputs and outputs in assending order by index. * @param items Inputs or Outputs. @@ -194,36 +203,36 @@ export class TransactionsHelper { private static bechAddressFromAddressUnlockCondition( unlockConditions: UnlockCondition[], _bechHrp: string, - outputType: number + outputType: number, ): IBech32AddressDetails { let address: IBech32AddressDetails = { bech32: "" }; let unlockCondition; if (outputType === OutputType.Basic || outputType === OutputType.Nft) { - unlockCondition = unlockConditions?.filter( - ot => ot.type === UnlockConditionType.Address - ).map(ot => ot as AddressUnlockCondition)[0]; + unlockCondition = unlockConditions + ?.filter((ot) => ot.type === UnlockConditionType.Address) + .map((ot) => ot as AddressUnlockCondition)[0]; } else if (outputType === OutputType.Account) { - if (unlockConditions.some(ot => ot.type === UnlockConditionType.StateControllerAddress)) { - unlockCondition = unlockConditions?.filter( - ot => ot.type === UnlockConditionType.StateControllerAddress - ).map(ot => ot as StateControllerAddressUnlockCondition)[0]; + if (unlockConditions.some((ot) => ot.type === UnlockConditionType.StateControllerAddress)) { + unlockCondition = unlockConditions + ?.filter((ot) => ot.type === UnlockConditionType.StateControllerAddress) + .map((ot) => ot as StateControllerAddressUnlockCondition)[0]; } - if (unlockConditions.some(ot => ot.type === UnlockConditionType.GovernorAddress)) { - unlockCondition = unlockConditions?.filter( - ot => ot.type === UnlockConditionType.GovernorAddress - ).map(ot => ot as GovernorAddressUnlockCondition)[0]; + if (unlockConditions.some((ot) => ot.type === UnlockConditionType.GovernorAddress)) { + unlockCondition = unlockConditions + ?.filter((ot) => ot.type === UnlockConditionType.GovernorAddress) + .map((ot) => ot as GovernorAddressUnlockCondition)[0]; } } else if (outputType === OutputType.Foundry) { - unlockCondition = unlockConditions?.filter( - ot => ot.type === UnlockConditionType.ImmutableAccountAddress - ).map(ot => ot as ImmutableAccountAddressUnlockCondition)[0]; + unlockCondition = unlockConditions + ?.filter((ot) => ot.type === UnlockConditionType.ImmutableAccountAddress) + .map((ot) => ot as ImmutableAccountAddressUnlockCondition)[0]; } if (unlockCondition?.address) { - address = { bech32: unlockCondition?.address.toString()}; + address = { bech32: unlockCondition?.address.toString() }; } return address; } -} \ No newline at end of file +} diff --git a/client/src/models/api/nova/IInput.ts b/client/src/models/api/nova/IInput.ts index 42e86006e..a9cd50399 100644 --- a/client/src/models/api/nova/IInput.ts +++ b/client/src/models/api/nova/IInput.ts @@ -31,4 +31,3 @@ export interface IInput { */ isGenesis: boolean; } - diff --git a/client/src/models/api/nova/IOutput.ts b/client/src/models/api/nova/IOutput.ts index 47765b354..59c34c61c 100644 --- a/client/src/models/api/nova/IOutput.ts +++ b/client/src/models/api/nova/IOutput.ts @@ -23,4 +23,3 @@ export interface IOutput { */ isRemainder?: boolean; } - diff --git a/client/src/models/api/nova/block/IBlockMetadata.ts b/client/src/models/api/nova/block/IBlockMetadata.ts index 81a0859cb..54c035144 100644 --- a/client/src/models/api/nova/block/IBlockMetadata.ts +++ b/client/src/models/api/nova/block/IBlockMetadata.ts @@ -11,4 +11,3 @@ export interface IBlockMetadata { */ metadataError?: string; } - diff --git a/client/src/models/api/nova/block/IBlockRequest.ts b/client/src/models/api/nova/block/IBlockRequest.ts index e22b99aab..781d93d64 100644 --- a/client/src/models/api/nova/block/IBlockRequest.ts +++ b/client/src/models/api/nova/block/IBlockRequest.ts @@ -9,4 +9,3 @@ export interface IBlockRequest { */ blockId: string; } - diff --git a/client/src/models/api/nova/block/IBlockResponse.ts b/client/src/models/api/nova/block/IBlockResponse.ts index a688d366d..f2239c888 100644 --- a/client/src/models/api/nova/block/IBlockResponse.ts +++ b/client/src/models/api/nova/block/IBlockResponse.ts @@ -7,4 +7,3 @@ export interface IBlockResponse extends IResponse { */ block: Block; } -