diff --git a/client/src/app/components/stardust/Input.tsx b/client/src/app/components/stardust/Input.tsx index 9010c4b96..593d9a33a 100644 --- a/client/src/app/components/stardust/Input.tsx +++ b/client/src/app/components/stardust/Input.tsx @@ -15,7 +15,7 @@ interface InputProps { /** * The inputs. */ - readonly input: IInput & { unlockConditionOpenedIndexes?: number[]; }; + readonly input: IInput & { unlockConditionOpenedIndexes?: number[] }; /** * The network in context. */ diff --git a/client/src/app/components/stardust/Output.tsx b/client/src/app/components/stardust/Output.tsx index 2e50b98ec..6a72deee7 100644 --- a/client/src/app/components/stardust/Output.tsx +++ b/client/src/app/components/stardust/Output.tsx @@ -225,8 +225,8 @@ class Output extends Component { {output.type !== OutputType.Treasury && ( {(output as CommonOutput).unlockConditions.map((unlockCondition, idx) => { - - const isExpandedByCondition = this.props.unlockConditionOpenedIndexes && this.props.unlockConditionOpenedIndexes.includes(idx); + const isExpandedByCondition = + this.props.unlockConditionOpenedIndexes && this.props.unlockConditionOpenedIndexes.includes(idx); return ( { ); } - - /** * Build bech32 address. * @returns The bech32 address. diff --git a/client/src/app/components/stardust/UnlockCondition.tsx b/client/src/app/components/stardust/UnlockCondition.tsx index 2d0a4c5ed..459c7d0e3 100644 --- a/client/src/app/components/stardust/UnlockCondition.tsx +++ b/client/src/app/components/stardust/UnlockCondition.tsx @@ -10,7 +10,7 @@ import { UnlockConditionType, } from "@iota/sdk-wasm/web"; import classNames from "classnames"; -import React, { ReactNode, Component, useContext, useState, useEffect } from "react"; +import React, { useContext, useState, useEffect } from "react"; import DropdownIcon from "~assets/dropdown-arrow.svg?react"; import Address from "./address/Address"; import { UnlockConditionProps } from "./UnlockConditionProps"; @@ -58,8 +58,8 @@ function UnlockCondition(props: UnlockConditionProps) { */ // public render(): ReactNode { const [state, setState] = useState({ - isFormattedBalance: true, - isExpanded: props.isPreExpanded ?? false, + isFormattedBalance: true, + isExpanded: props.isPreExpanded ?? false, }); const context = useContext(NetworkContext); const { isFormattedBalance, isExpanded } = state; @@ -72,16 +72,19 @@ function UnlockCondition(props: UnlockConditionProps) { // while maintaining its own internal state. useEffect(() => { if (props.isPreExpanded !== undefined && props.isPreExpanded !== null) { - setState(prevState => ({ + setState((prevState) => ({ ...prevState, - isExpanded: props.isPreExpanded ?? false + isExpanded: props.isPreExpanded ?? false, })); } }, [props.isPreExpanded]); return (
-
setState((p) => ({ ...p, isExpanded: !isExpanded }))}> +
setState((p) => ({ ...p, isExpanded: !isExpanded }))} + >
diff --git a/client/src/app/components/stardust/block/payload/TransactionPayload.tsx b/client/src/app/components/stardust/block/payload/TransactionPayload.tsx index 2ca9e4286..bcfbc0b45 100644 --- a/client/src/app/components/stardust/block/payload/TransactionPayload.tsx +++ b/client/src/app/components/stardust/block/payload/TransactionPayload.tsx @@ -9,26 +9,6 @@ import Input from "../../Input"; import Output from "../../Output"; import Unlocks from "../../Unlocks"; import "./TransactionPayload.scss"; -import { DateHelper } from "~helpers/dateHelper"; -import { - // AddressType, - // AliasAddress, - // AliasOutput, - // CommonOutput, - ExpirationUnlockCondition, - // FoundryOutput, - // ImmutableAliasAddressUnlockCondition, - // INodeInfoBaseToken, - // NftOutput, - // OutputType, - // SimpleTokenScheme, - // StorageDepositReturnUnlockCondition, - // TimelockUnlockCondition, - // TokenSchemeType, - UnlockCondition as IUnlockCondition, - UnlockConditionType, - // Utils, -} from "@iota/sdk-wasm/web"; /** * Component which will display a transaction payload. @@ -123,24 +103,4 @@ class TransactionPayload extends AsyncComponent cond.type === UnlockConditionType.Expiration, - ) as ExpirationUnlockCondition; - const isExpirationConditionPresent = !!expirationUnlockCondition; - const isExpirationConditionExpired = - isExpirationConditionPresent && DateHelper.isExpired(expirationUnlockCondition.unixTime * 1000); - - switch (unlockCondition.type) { - case UnlockConditionType.Address: - return !isExpirationConditionPresent || (isExpirationConditionPresent && !isExpirationConditionExpired); - case UnlockConditionType.Expiration: - return isExpirationConditionExpired; - default: - return false; - } -} - export default TransactionPayload; diff --git a/client/src/app/components/stardust/block/payload/TransactionPayloadProps.tsx b/client/src/app/components/stardust/block/payload/TransactionPayloadProps.tsx index 9fae3a02f..d5d8b4623 100644 --- a/client/src/app/components/stardust/block/payload/TransactionPayloadProps.tsx +++ b/client/src/app/components/stardust/block/payload/TransactionPayloadProps.tsx @@ -11,7 +11,7 @@ export interface TransactionPayloadProps { /** * The inputs. */ - inputs: (IInput & { unlockConditionOpenedIndexes?: number[]; })[]; + inputs: (IInput & { unlockConditionOpenedIndexes?: number[] })[]; /** * The unlocks of the transaction. diff --git a/client/src/app/routes/stardust/TransactionPage.tsx b/client/src/app/routes/stardust/TransactionPage.tsx index 1e5e1a21a..3f6008b12 100644 --- a/client/src/app/routes/stardust/TransactionPage.tsx +++ b/client/src/app/routes/stardust/TransactionPage.tsx @@ -1,5 +1,12 @@ /* eslint-disable react/jsx-no-useless-fragment */ -import { PayloadType, RegularTransactionEssence, TransactionPayload as ITransactionPayload, Utils, UnlockConditionType, CommonOutput } from "@iota/sdk-wasm/web"; +import { + PayloadType, + RegularTransactionEssence, + TransactionPayload as ITransactionPayload, + Utils, + UnlockConditionType, + CommonOutput, +} from "@iota/sdk-wasm/web"; import React, { useContext, useEffect, useState } from "react"; import { RouteComponentProps } from "react-router-dom"; import { TransactionPageProps } from "./TransactionPageProps"; @@ -52,10 +59,7 @@ const TransactionPage: React.FC> = ({ const [blockChildren] = useBlockChildren(network, includedBlockId); const [blockMetadata, isBlockMetadataLoading] = useBlockMetadata(network, includedBlockId); const [isFormattedBalance, setIsFormattedBalance] = useState(true); - const [inputsExtraInfo, setInputsExtraInfo] = useState<{ [outputId: string]: {unlockConditionOpenedIndexes?: number[];} }>({ - - }); - + const [inputsExtraInfo, setInputsExtraInfo] = useState<{ [outputId: string]: { unlockConditionOpenedIndexes?: number[] } }>({}); const inputsWithExtraInfo = React.useMemo(() => { if (!inputs) return null; @@ -102,7 +106,6 @@ const TransactionPage: React.FC> = ({ unlockConditionOpenedIndexes: indexes, }, })); - } else { const expirationUnlockCondition = getUnlockCondition(input, UnlockConditionType.Expiration) as ExpirationUnlockCondition; const isExpired = expirationUnlockCondition && DateHelper.isExpired(expirationUnlockCondition.unixTime * 1000); @@ -129,17 +132,18 @@ const TransactionPage: React.FC> = ({ }, })); } - } + }; useEffect(() => { (async () => { if (!inputs) return; - await Promise.all(inputs.map(input => { - updateInputExtraInfo(input); - })); + await Promise.all( + inputs.map((input) => { + updateInputExtraInfo(input); + }), + ); })(); - }, [inputs, setInputsExtraInfo]); const { metadata, metadataError, conflictReason, blockTangleStatus } = blockMetadata; @@ -328,8 +332,6 @@ const TransactionPage: React.FC> = ({ ); }; - - function isOutputSpent(input: IInput) { const output = input.output as OutputResponse; return output.metadata.isSpent; @@ -339,26 +341,27 @@ function getUnlockCondition(input: IInput, type: UnlockConditionType) { const output = input.output?.output as CommonOutput; if (!output?.unlockConditions) return null; - return output.unlockConditions.find(i => i.type === type); + return output.unlockConditions.find((i) => i.type === type); } function getUnlockConditionIndexes(input: IInput, type: UnlockConditionType) { const output = input.output?.output as CommonOutput; if (!output?.unlockConditions) return []; - return output.unlockConditions.map((i, idx) => { - if (i.type === type) { - return idx; - } - }).filter(i => i !== undefined) as number[]; + return output.unlockConditions + .map((i, idx) => { + if (i.type === type) { + return idx; + } + }) + .filter((i) => i !== undefined) as number[]; } -// If expiration unlock condition exists - return true. function isExpirationExists(input: IInput) { const output = input.output?.output as CommonOutput; if (!output?.unlockConditions) return false; - return output.unlockConditions.some(i => i.type === UnlockConditionType.Expiration); + return output.unlockConditions.some((i) => i.type === UnlockConditionType.Expiration); } async function getTransactionTimestamp(transactionId: string, apiClient: StardustApiClient, network: string) { @@ -383,5 +386,4 @@ async function getTransactionTimestamp(transactionId: string, apiClient: Stardus return DateHelper.milliseconds(milestoneResp.milestone.timestamp); } - export default TransactionPage;