-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: request details if has unlock condition expiration
Signed-off-by: Eugene Panteleymonchuk <[email protected]>
- Loading branch information
1 parent
049cffb
commit 3a1898f
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
@@ -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); | ||
|
@@ -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; | ||
|
@@ -55,6 +62,59 @@ const TransactionPage: React.FC<RouteComponentProps<TransactionPageProps>> = ({ | |
} | ||
}, [block]); | ||
|
||
const requestOutputDetails = async (outputId: string): Promise<OutputResponse | null> => { | ||
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 GitHub Actions / build-check (client)
|
||
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 GitHub Actions / build-check (client)
|
||
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 GitHub Actions / build-check (client)
|
||
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); | ||
|