Skip to content

Commit

Permalink
fix: eslint + prettier.
Browse files Browse the repository at this point in the history
Signed-off-by: Eugene Panteleymonchuk <[email protected]>
  • Loading branch information
panteleymonchuk committed Jan 28, 2024
1 parent ed0d13b commit ecf421d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 74 deletions.
2 changes: 1 addition & 1 deletion client/src/app/components/stardust/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface InputProps {
/**
* The inputs.
*/
readonly input: IInput & { unlockConditionOpenedIndexes?: number[]; };
readonly input: IInput & { unlockConditionOpenedIndexes?: number[] };
/**
* The network in context.
*/
Expand Down
6 changes: 2 additions & 4 deletions client/src/app/components/stardust/Output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ class Output extends Component<OutputProps, OutputState> {
{output.type !== OutputType.Treasury && (
<React.Fragment>
{(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 (
<UnlockCondition
Expand Down Expand Up @@ -268,8 +268,6 @@ class Output extends Component<OutputProps, OutputState> {
);
}



/**
* Build bech32 address.
* @returns The bech32 address.
Expand Down
15 changes: 9 additions & 6 deletions client/src/app/components/stardust/UnlockCondition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -58,8 +58,8 @@ function UnlockCondition(props: UnlockConditionProps) {
*/
// public render(): ReactNode {
const [state, setState] = useState<UnlockConditionState>({
isFormattedBalance: true,
isExpanded: props.isPreExpanded ?? false,
isFormattedBalance: true,
isExpanded: props.isPreExpanded ?? false,
});
const context = useContext(NetworkContext);
const { isFormattedBalance, isExpanded } = state;
Expand All @@ -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 (
<div className="unlock-condition">
<div className="card--content__input card--value row middle" onClick={() => setState((p) => ({ ...p, isExpanded: !isExpanded }))}>
<div
className="card--content__input card--value row middle"
onClick={() => setState((p) => ({ ...p, isExpanded: !isExpanded }))}
>
<div className={classNames("margin-r-t", "card--content--dropdown", { opened: isExpanded })}>
<DropdownIcon />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -123,24 +103,4 @@ class TransactionPayload extends AsyncComponent<TransactionPayloadProps, Transac
}
}

function getExpandedStateInUnlockCondition(unlockCondition?: IUnlockCondition, unlockConditions?: IUnlockCondition[]): boolean {
if (!unlockCondition) return false;

const expirationUnlockCondition = unlockConditions?.find(
(cond) => 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;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface TransactionPayloadProps {
/**
* The inputs.
*/
inputs: (IInput & { unlockConditionOpenedIndexes?: number[]; })[];
inputs: (IInput & { unlockConditionOpenedIndexes?: number[] })[];

/**
* The unlocks of the transaction.
Expand Down
46 changes: 24 additions & 22 deletions client/src/app/routes/stardust/TransactionPage.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -52,10 +59,7 @@ const TransactionPage: React.FC<RouteComponentProps<TransactionPageProps>> = ({
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;
Expand Down Expand Up @@ -102,7 +106,6 @@ const TransactionPage: React.FC<RouteComponentProps<TransactionPageProps>> = ({
unlockConditionOpenedIndexes: indexes,
},
}));

} else {
const expirationUnlockCondition = getUnlockCondition(input, UnlockConditionType.Expiration) as ExpirationUnlockCondition;
const isExpired = expirationUnlockCondition && DateHelper.isExpired(expirationUnlockCondition.unixTime * 1000);
Expand All @@ -129,17 +132,18 @@ const TransactionPage: React.FC<RouteComponentProps<TransactionPageProps>> = ({
},
}));
}
}
};

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;
Expand Down Expand Up @@ -328,8 +332,6 @@ const TransactionPage: React.FC<RouteComponentProps<TransactionPageProps>> = ({
);
};



function isOutputSpent(input: IInput) {
const output = input.output as OutputResponse;
return output.metadata.isSpent;
Expand All @@ -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) {
Expand All @@ -383,5 +386,4 @@ async function getTransactionTimestamp(transactionId: string, apiClient: Stardus
return DateHelper.milliseconds(milestoneResp.milestone.timestamp);
}


export default TransactionPage;

0 comments on commit ecf421d

Please sign in to comment.