From 5daf4b183f77a95f3f2b64df12674c37294fb970 Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Fri, 21 Jul 2023 05:47:35 -0400 Subject: [PATCH] chore(transfer): fix build --- .../apps/transfer/src/constants/client.ts | 5 + .../src/pages/faucet/existing/index.tsx | 2 +- .../transfer/account-transactions/index.tsx | 2 +- .../cross-chain-transfer-finisher/index.tsx | 24 ++-- .../pages/transfer/module-explorer/index.tsx | 25 +--- .../chains/[chain]/modules/[module]/index.tsx | 4 +- .../finish-xchain-transfer.ts | 60 +++++---- .../get-transfer-data.ts | 7 +- .../src/services/modules/describe-module.ts | 22 +--- .../src/services/modules/list-module.ts | 6 +- .../transfer-tracker/get-transfer-status.ts | 124 +++++++++--------- .../example-contract/crosschain-transfer.ts | 2 +- 12 files changed, 128 insertions(+), 155 deletions(-) create mode 100644 packages/apps/transfer/src/constants/client.ts diff --git a/packages/apps/transfer/src/constants/client.ts b/packages/apps/transfer/src/constants/client.ts new file mode 100644 index 00000000000..7bddf180ee4 --- /dev/null +++ b/packages/apps/transfer/src/constants/client.ts @@ -0,0 +1,5 @@ +import { getClient } from "@kadena/client"; + +const client = getClient(); + +export default client; diff --git a/packages/apps/transfer/src/pages/faucet/existing/index.tsx b/packages/apps/transfer/src/pages/faucet/existing/index.tsx index fd4bd6fbaca..98a17488cb0 100644 --- a/packages/apps/transfer/src/pages/faucet/existing/index.tsx +++ b/packages/apps/transfer/src/pages/faucet/existing/index.tsx @@ -119,7 +119,7 @@ const ExistingAccountFaucetPage: FC = () => { leftIcon: SystemIcon.KIcon, }} /> - + {
- + { return; } - const host = getKadenaConstantByNetwork(network).apiHost({ + const proof = await client.pollCreateSpv(requestKey, pollResults.tx.receiver.chain, { networkId: chainNetwork[network].network, - chainId: pollResults.tx.receiver.chain, + chainId: pollResults.tx.sender.chain, }); - const contCommand = await finishXChainTransfer( - requestKey, - pollResults.tx.step, - pollResults.tx.rollback, - network, - pollResults.tx.receiver.chain, - kadenaXChainGas, - ); + console.log(proof); + + // const contCommand = await finishXChainTransfer( + // requestKey, + // pollResults.tx.step, + // pollResults.tx.rollback, + // network, + // pollResults.tx.receiver.chain, + // kadenaXChainGas, + // ); // if (!(contCommand instanceof ContCommand) && contCommand.error) { // setTxError(contCommand.error); diff --git a/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx b/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx index 72c724b0c76..5d13397f86d 100644 --- a/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx +++ b/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx @@ -58,27 +58,6 @@ const ModuleExplorer: FC = () => { [modules, moduleSearch], ); - useEffect(() => { - if (!moduleName) { - return; - } - - const fetchModule = async (): Promise => { - const data = await describeModule( - moduleName, - chainID, - network, - kadenaConstants.DEFAULT_SENDER, - kadenaConstants.GAS_PRICE, - 1000, - ); - - setResults(data); - }; - - fetchModule().catch(console.error); - }, [chainID, moduleName, network]); - const onModuleNameChange = useCallback>( (e) => { setModuleSearch(e.target.value); @@ -94,7 +73,7 @@ const ModuleExplorer: FC = () => { - + { {filteredModules?.map((module) => ( {module} diff --git a/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/index.tsx b/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/index.tsx index 98c03051ce2..19e98d338a3 100644 --- a/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/index.tsx +++ b/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/index.tsx @@ -62,8 +62,8 @@ const ModulePage = () => { console.log(pactModule); - setCapabilities(pactModule._raw[moduleName].defcaps); - setFunctions(pactModule._raw[moduleName].defuns); + // setCapabilities(pactModule._raw[moduleName].defcaps); + // setFunctions(pactModule._raw[moduleName].defuns); }; fetchModule().catch(console.error); diff --git a/packages/apps/transfer/src/services/cross-chain-transfer-finish/finish-xchain-transfer.ts b/packages/apps/transfer/src/services/cross-chain-transfer-finish/finish-xchain-transfer.ts index 202948f2dd2..ce4e593d452 100644 --- a/packages/apps/transfer/src/services/cross-chain-transfer-finish/finish-xchain-transfer.ts +++ b/packages/apps/transfer/src/services/cross-chain-transfer-finish/finish-xchain-transfer.ts @@ -2,7 +2,7 @@ import { ChainwebChainId, ChainwebNetworkId, } from '@kadena/chainweb-node-client'; -import { ContCommand, getContCommand } from '@kadena/client'; +import { getClient, Pact } from '@kadena/client'; import { getKadenaConstantByNetwork, @@ -28,47 +28,49 @@ export async function finishXChainTransfer( network: Network, chainId: ChainwebChainId, sender: string, -): Promise { +): Promise { debug(finishXChainTransfer.name); const host = getKadenaConstantByNetwork(network).apiHost({ networkId: chainNetwork[network].network, chainId, }); + const { pollStatus } = getClient(); + try { - const contCommand = await getContCommand( - requestKey, - chainId, - host, - step + 1, - rollback, - ); + // const contCommand = await getContCommand( + // chainId, + // host, + // step + 1, + // rollback, + // ); - contCommand.setMeta( - { - chainId, - sender, - gasLimit, - gasPrice, - }, - chainNetwork[network].network as ChainwebNetworkId, - ); + // contCommand.setMeta( + // { + // chainId, + // sender, + // gasLimit, + // gasPrice, + // }, + // chainNetwork[network].network as ChainwebNetworkId, + // ); - contCommand.createCommand(); + // contCommand.createCommand(); - const localResult = await contCommand.local(host, { - preflight: false, - signatureVerification: false, - }); + // const localResult = await contCommand.local(host, { + // preflight: false, + // signatureVerification: false, + // }); - if (localResult.result.status !== 'success') { - debug(localResult.result.error.message); - return { error: localResult.result.error.message }; - } + // if (localResult.result.status !== 'success') { + // debug(localResult.result.error.message); + // return { error: localResult.result.error.message }; + // } - await contCommand.send(host); + // await contCommand.send(host); - return contCommand; + // return contCommand; + throw new Error('testing'); } catch (e) { debug(e.message); return { error: e.message }; 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 ed6212db6af..b77d1015afa 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 @@ -80,10 +80,9 @@ export async function getTransferData({ const { events, result } = found; - const errorMessage = result.error?.message; - - if (errorMessage) { - return { error: errorMessage }; + if ('error' in result) { + return result.error; + // return { error: ('message' in result.error ? (result.error.message as string) : 'An error occurred.' }; } const [senderAccount, receiverAccount, guard, targetChain, amount] = diff --git a/packages/apps/transfer/src/services/modules/describe-module.ts b/packages/apps/transfer/src/services/modules/describe-module.ts index 4045f5d7014..b3bf003624e 100644 --- a/packages/apps/transfer/src/services/modules/describe-module.ts +++ b/packages/apps/transfer/src/services/modules/describe-module.ts @@ -36,8 +36,10 @@ export const describeModule = async ( }), ); + const modules: any = Pact.modules; + const describe: any = modules['describe-module']; const transaction = Pact.builder - .execution(Pact.modules['describe-module'](moduleName)) + .execution(describe(moduleName)) .setMeta({ gasLimit, gasPrice, ttl, sender, chainId }) .setNetworkId(networkId) .createTransaction(); @@ -47,27 +49,11 @@ export const describeModule = async ( signatureVerification: false, }); - // const pactCommand = new PactCommand(); - // pactCommand.code = createExp(`describe-module "${moduleName}"`); - - // pactCommand.setMeta({ gasLimit, gasPrice, ttl, sender, chainId }); - - // const response = await pactCommand.local( - // getKadenaConstantByNetwork(network).apiHost({ - // networkId: chainNetwork[network].network, - // chainId, - // }), - // { - // signatureVerification: false, - // preflight: false, - // }, - // ); - const { reqKey, result } = response; return { reqKey, status: result.status, - code: result.data?.code, + code: ('data' in result) ? (result.data as string) : '', }; }; diff --git a/packages/apps/transfer/src/services/modules/list-module.ts b/packages/apps/transfer/src/services/modules/list-module.ts index e0107b287f7..92d354c5818 100644 --- a/packages/apps/transfer/src/services/modules/list-module.ts +++ b/packages/apps/transfer/src/services/modules/list-module.ts @@ -1,6 +1,5 @@ import { ChainwebChainId } from '@kadena/chainweb-node-client'; import { getClient, Pact } from '@kadena/client'; -import { createExp } from '@kadena/pactjs'; import { getKadenaConstantByNetwork, @@ -34,8 +33,9 @@ export const listModules = async ( }), ); + const modules: any = Pact.modules; const transaction = Pact.builder - .execution(Pact.modules['list-modules']()) + .execution(modules['list-modules']()) .setMeta({ gasLimit, gasPrice, ttl, sender, chainId }) .setNetworkId(networkId) .createTransaction(); @@ -49,6 +49,6 @@ export const listModules = async ( return { status: result.status, - data: result.data, + data: 'data' in result ? (result.data as string[]) : [], }; }; diff --git a/packages/apps/transfer/src/services/transfer-tracker/get-transfer-status.ts b/packages/apps/transfer/src/services/transfer-tracker/get-transfer-status.ts index 3c9f2842704..d5f23be2c48 100644 --- a/packages/apps/transfer/src/services/transfer-tracker/get-transfer-status.ts +++ b/packages/apps/transfer/src/services/transfer-tracker/get-transfer-status.ts @@ -2,7 +2,6 @@ import { ChainwebChainId, ChainwebNetworkId, } from '@kadena/chainweb-node-client'; -import { getContCommand, pollSpvProof } from '@kadena/client'; import { getTransferData } from '../cross-chain-transfer-finish/get-transfer-data'; @@ -181,53 +180,53 @@ export async function getXChainTransferInfo({ const gasLimit: number = kadenaConstants.GAS_LIMIT; const gasPrice: number = kadenaConstants.GAS_PRICE; - const contCommand = await getContCommand( - requestKey, - receiverChain, - proofApiHost, - 1, - false, - ); + // const contCommand = await getContCommand( + // requestKey, + // receiverChain, + // proofApiHost, + // 1, + // false, + // ); - contCommand - .setMeta( - { - chainId: receiverChain, - sender: senderAccount, - gasLimit, - gasPrice, - }, - chainNetwork[network].network as ChainwebNetworkId, - ) - .createCommand(); + // contCommand + // .setMeta( + // { + // chainId: receiverChain, + // sender: senderAccount, + // gasLimit, + // gasPrice, + // }, + // chainNetwork[network].network as ChainwebNetworkId, + // ) + // .createCommand(); - const response = await contCommand.local(apiHost, { - preflight: false, - signatureVerification: false, - }); + // const response = await contCommand.local(apiHost, { + // preflight: false, + // signatureVerification: false, + // }); - if ( - String(response?.result?.error?.type) === 'EvalError' && - String(response?.result?.error?.message).includes('pact completed') - ) { - return { - id: StatusId.Success, - status: t('Success'), - description: t('Transfer completed successfully'), - senderAccount: senderAccount, - receiverChain: receiverChain, - }; - } + // if ( + // String(response?.result?.error?.type) === 'EvalError' && + // String(response?.result?.error?.message).includes('pact completed') + // ) { + // return { + // id: StatusId.Success, + // status: t('Success'), + // description: t('Transfer completed successfully'), + // senderAccount: senderAccount, + // receiverChain: receiverChain, + // }; + // } - if (response?.result?.status === 'success') { - return { - id: StatusId.Pending, - status: t('Pending'), - description: t('Transfer pending - waiting for continuation command'), - senderAccount: senderAccount, - receiverChain: receiverChain, - }; - } + // if (response?.result?.status === 'success') { + // return { + // id: StatusId.Pending, + // status: t('Pending'), + // description: t('Transfer pending - waiting for continuation command'), + // senderAccount: senderAccount, + // receiverChain: receiverChain, + // }; + // } return { id: StatusId.Error, @@ -278,24 +277,25 @@ export async function checkForProof({ }); let count = 0; - return await pollSpvProof(requestKey, receiverChain, apiHost, { - onPoll: () => { - // Avoid status update on first two polls (to avoid flickering) - if (count > 1) { - onPoll({ - id: StatusId.Pending, - status: t('Pending'), - description: t('Transfer pending - waiting for proof'), - senderAccount, - senderChain, - receiverAccount, - receiverChain, - amount, - }); - } - count++; - }, - }); + // return await pollSpvProof(requestKey, receiverChain, apiHost, { + // onPoll: () => { + // // Avoid status update on first two polls (to avoid flickering) + // if (count > 1) { + // onPoll({ + // id: StatusId.Pending, + // status: t('Pending'), + // description: t('Transfer pending - waiting for proof'), + // senderAccount, + // senderChain, + // receiverAccount, + // receiverChain, + // amount, + // }); + // } + // count++; + // }, + // }); + return new Promise(() => undefined) } catch (error) { debug(error); onPoll({ diff --git a/packages/libs/client-examples/src/example-contract/crosschain-transfer.ts b/packages/libs/client-examples/src/example-contract/crosschain-transfer.ts index 029d0861c8e..8a389a4dc16 100644 --- a/packages/libs/client-examples/src/example-contract/crosschain-transfer.ts +++ b/packages/libs/client-examples/src/example-contract/crosschain-transfer.ts @@ -89,7 +89,7 @@ export async function doCrossChainTransfer( pactId: status.continuation?.pactId, proof, rollback: false, - step: '1', + step: 1, }, to.chainId, ),