Skip to content

Commit

Permalink
chore: request details if has unlock condition expiration
Browse files Browse the repository at this point in the history
Signed-off-by: Eugene Panteleymonchuk <[email protected]>
  • Loading branch information
panteleymonchuk committed Jan 23, 2024
1 parent 049cffb commit 3a1898f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/src/app/components/stardust/Output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Output extends Component<OutputProps, OutputState> {
*/
public render(): ReactNode {
const { outputId, output, amount, showCopyAmount, network, isPreExpanded, displayFullOutputId, isLinksDisabled } = this.props;
// console.log(output);
const { isExpanded, isFormattedBalance } = this.state;
const tokenInfo: INodeInfoBaseToken = this.context.tokenInfo;

Expand Down
60 changes: 60 additions & 0 deletions client/src/app/routes/stardust/TransactionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import InclusionState from "../../components/stardust/InclusionState";
import TruncatedId from "../../components/stardust/TruncatedId";
import NetworkContext from "../../context/NetworkContext";
import "./TransactionPage.scss";
import { ServiceFactory } from "~factories/serviceFactory";
import { StardustApiClient } from "~services/stardust/stardustApiClient";
import { STARDUST } from "~models/config/protocolVersion";
import { OutputResponse, UnlockConditionType } from "@iota/sdk-wasm/web";

enum TRANSACTION_PAGE_TABS {
Payload = "Payload",
Expand All @@ -36,6 +40,7 @@ const TransactionPage: React.FC<RouteComponentProps<TransactionPageProps>> = ({
},
}) => {
const { tokenInfo } = useContext(NetworkContext);
const [apiClient] = useState(() => ServiceFactory.get<StardustApiClient>(`api-client-${STARDUST}`));
const [block, isIncludedBlockLoading, blockError] = useTransactionIncludedBlock(network, transactionId);
const [inputs, unlocks, outputs, transferTotal, isInputsAndOutputsLoading] = useInputsAndOutputs(network, block);
const [includedBlockId, setIncludedBlockId] = useState<string | null>(null);
Expand All @@ -45,6 +50,8 @@ const TransactionPage: React.FC<RouteComponentProps<TransactionPageProps>> = ({
const [blockMetadata, isBlockMetadataLoading] = useBlockMetadata(network, includedBlockId);
const [isFormattedBalance, setIsFormattedBalance] = useState(true);

// console.log('--- inputs', inputs, outputs);

useEffect(() => {
if (block?.payload?.type === PayloadType.Transaction) {
const transactionPayload = block.payload as ITransactionPayload;
Expand All @@ -55,6 +62,59 @@ const TransactionPage: React.FC<RouteComponentProps<TransactionPageProps>> = ({
}
}, [block]);

const requestOutputDetails = async (outputId: string): Promise<OutputResponse | null> => {

Check failure on line 65 in client/src/app/routes/stardust/TransactionPage.tsx

View workflow job for this annotation

GitHub Actions / build-check (client)

'requestOutputDetails' is assigned a value but never used
if (!outputId) return null;

try {
const response = await apiClient.outputDetails({ network, outputId });
const details = response.output;

if (!response.error && details?.output && details?.metadata) {
return details;
}
return null;
} catch {
console.log("Failed loading transaction history details!");
return null;
}
};

useEffect(() => {
// request output details for unlocks with expiration
if (!inputs || !outputs) return;

(async () => {
const outputIdsWithUnlockConditions = [];

for (const input of inputs) {
// @ts-ignore

Check failure on line 90 in client/src/app/routes/stardust/TransactionPage.tsx

View workflow job for this annotation

GitHub Actions / build-check (client)

Do not use "@ts-ignore" because it alters compilation errors
const hasUnlockExpiration = input?.output?.output?.unlockConditions?.some(i => i.type === UnlockConditionType.Expiration);
// @ts-ignore

Check failure on line 92 in client/src/app/routes/stardust/TransactionPage.tsx

View workflow job for this annotation

GitHub Actions / build-check (client)

Do not use "@ts-ignore" because it alters compilation errors
if (hasUnlockExpiration) {
outputIdsWithUnlockConditions.push(input?.outputId);
}
}

for (const output of outputs) {

// @ts-ignore

Check failure on line 100 in client/src/app/routes/stardust/TransactionPage.tsx

View workflow job for this annotation

GitHub Actions / build-check (client)

Do not use "@ts-ignore" because it alters compilation errors
const hasUnlockExpiration = output?.output?.unlockConditions?.some(i => i.type === UnlockConditionType.Expiration);

if (hasUnlockExpiration) {
outputIdsWithUnlockConditions.push(output?.id);
}
}

if (outputIdsWithUnlockConditions.length > 0) {
const outputDetails = await Promise.all(outputIdsWithUnlockConditions.map((outputId) => {
return apiClient.outputDetails({ network, outputId });
}));
console.log('--- outputDetails', outputDetails);
}

})();
}, [inputs, outputs]);

const { metadata, metadataError, conflictReason, blockTangleStatus } = blockMetadata;
const isLinksDisabled = metadata?.ledgerInclusionState === "conflicting";
const isMarketed = isMarketedNetwork(network);
Expand Down

0 comments on commit 3a1898f

Please sign in to comment.