From 9587a5a31d3bbab37c85256ab4c5b7c7978b5e42 Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Thu, 20 Jul 2023 15:30:24 -0400 Subject: [PATCH] fix(transfer): transfer-tracker --- .../get-transfer-data.ts | 45 ++++++++----------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/packages/apps/transfer/src/services/cross-chain-transfer-finish/get-transfer-data.ts b/packages/apps/transfer/src/services/cross-chain-transfer-finish/get-transfer-data.ts index 3d4c0bd377c..3a1c944323a 100644 --- a/packages/apps/transfer/src/services/cross-chain-transfer-finish/get-transfer-data.ts +++ b/packages/apps/transfer/src/services/cross-chain-transfer-finish/get-transfer-data.ts @@ -1,9 +1,8 @@ import { ChainwebChainId, ICommandResult, - IPollResponse, } from '@kadena/chainweb-node-client'; -import { Pact } from '@kadena/client'; +import { getClient } from '@kadena/client'; import { IPactEvent, IPactExec, PactValue } from '@kadena/types'; import { getKadenaConstantByNetwork, Network } from '@/constants/kadena'; @@ -63,52 +62,44 @@ export async function getTransferData({ return { error: t('Invalid length of request key') }; } - const pactCommand = Pact.builder.createTransaction(); - - pactCommand.requestKey = requestKey; - try { const chainInfoPromises = Array.from(new Array(20)).map((item, chainId) => { const host = getKadenaConstantByNetwork(network).apiHost({ networkId: chainNetwork[network].network, chainId: convertIntToChainId(chainId), }); - return pactCommand.poll(host); + const { getStatus } = getClient(host); + return getStatus(requestKey); }); const chainInfos = await Promise.all(chainInfoPromises); - const found: { chainId: number; tx: ICommandResult } | undefined = - chainInfos.reduce( - ( - acc: { chainId: number; tx: ICommandResult } | undefined, - curr: IPollResponse, - chain: number, - array: IPollResponse[], - ) => { - array.splice(chain - 1); - if (curr[requestKey] !== undefined) { - return { chainId: chain, tx: curr[validatedRequestKey] }; - } - }, - undefined, - ); + const request = chainInfos.find(chainInfo => requestKey in chainInfo); - if (found === undefined) { + if (!request) { return { error: t('No request key found') }; } + const found = request[requestKey]; + + const { events, result } = found; + + const errorMessage = result.error?.message; + + if (errorMessage) { + return { error: errorMessage }; + } + const [senderAccount, receiverAccount, guard, targetChain, amount] = // eslint-disable-next-line @typescript-eslint/no-explicit-any - found.tx?.continuation?.continuation.args as Array; + found?.continuation?.continuation.args as Array; - const { step, stepHasRollback, pactId } = found.tx + const { step, stepHasRollback, pactId } = found ?.continuation as IPactExec; - const { events, result } = found.tx; return { tx: { sender: { - chain: found.chainId.toString() as ChainwebChainId, + chain: "1", // todo: fix typing. // found.chainId.toString() as ChainwebChainId, account: senderAccount, }, receiver: {